From 32e023231d15317406ef0ac96fa23db4dac81b2d Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 5 Mar 2022 20:16:04 +0200 Subject: [PATCH] Catch invalid integers passed to !tg create --- mautrix_telegram/commands/portal/bridge.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/mautrix_telegram/commands/portal/bridge.py b/mautrix_telegram/commands/portal/bridge.py index 89f6f625..70d69522 100644 --- a/mautrix_telegram/commands/portal/bridge.py +++ b/mautrix_telegram/commands/portal/bridge.py @@ -59,13 +59,18 @@ async def bridge(evt: CommandEvent) -> EventID: # The /id bot command provides the prefixed ID, so we assume tgid_str = evt.args[0] - if tgid_str.startswith("-100"): - tgid = TelegramID(int(tgid_str[4:])) - peer_type = "channel" - elif tgid_str.startswith("-"): - tgid = TelegramID(-int(tgid_str)) - peer_type = "chat" - else: + tgid = None + try: + if tgid_str.startswith("-100"): + tgid = TelegramID(int(tgid_str[4:])) + peer_type = "channel" + elif tgid_str.startswith("-"): + tgid = TelegramID(-int(tgid_str)) + peer_type = "chat" + except ValueError: + # Invalid integer + pass + if not tgid: return await evt.reply( "That doesn't seem like a prefixed Telegram chat ID.\n\n" "If you did not get the ID using the `/id` bot command, please "