From 298e326de7c71488104cfd4ca6b29cf5c7896973 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 14 Jul 2018 14:39:49 +0300 Subject: [PATCH 1/2] Fix login command and add token login error handlers --- mautrix_telegram/commands/auth.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/mautrix_telegram/commands/auth.py b/mautrix_telegram/commands/auth.py index 8caf21a5..4c6b135c 100644 --- a/mautrix_telegram/commands/auth.py +++ b/mautrix_telegram/commands/auth.py @@ -174,7 +174,7 @@ async def enter_phone_or_token(evt: CommandEvent): # phone numbers don't contain colons but telegram bot auth tokens do if evt.args[0].find(":") > 0: try: - await sign_in(bot_token=evt.args[0]) + await sign_in(evt, bot_token=evt.args[0]) except Exception: evt.log.exception("Error sending auth token") return await evt.reply("Unhandled exception while sending auth token. " @@ -194,7 +194,7 @@ async def enter_code(evt: CommandEvent): return await evt.reply("This bridge instance does not allow in-Matrix login. " "Please use `$cmdprefix+sp login` to get login instructions") try: - await sign_in(code=evt.args[0]) + await sign_in(evt, code=evt.args[0]) except Exception: evt.log.exception("Error sending phone code") return await evt.reply("Unhandled exception while sending code. " @@ -209,12 +209,17 @@ async def enter_password(evt: CommandEvent): return await evt.reply("This bridge instance does not allow in-Matrix login. " "Please use `$cmdprefix+sp login` to get login instructions") try: - await sign_in(password=" ".join(evt.args)) + await sign_in(evt, password=" ".join(evt.args)) + except AccessTokenInvalidError: + return await evt.reply("That bot token is not valid.") + except AccessTokenExpiredError: + return await evt.reply("That bot token has expired.") except Exception: evt.log.exception("Error sending password") return await evt.reply("Unhandled exception while sending password. " "Check console for more details.") + async def sign_in(evt: CommandEvent, **sign_in_info): try: await evt.sender.ensure_started(even_if_no_session=True) @@ -236,6 +241,7 @@ async def sign_in(evt: CommandEvent, **sign_in_info): return await evt.reply("Your account has two-factor authentication. " "Please send your password here.") + @command_handler(needs_auth=True, help_section=SECTION_AUTH, help_text="Log out from Telegram.") From 6cef4d81c6385546819cdb0841fd8560f65b0b76 Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Sat, 14 Jul 2018 23:22:36 +0300 Subject: [PATCH 2/2] Add .codeclimate.yml --- .codeclimate.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .codeclimate.yml diff --git a/.codeclimate.yml b/.codeclimate.yml new file mode 100644 index 00000000..ad83e79a --- /dev/null +++ b/.codeclimate.yml @@ -0,0 +1,6 @@ +engines: + sonar-python: + enabled: true + checks: + python:S107: + enabled: false