From 1b987be5622b33da8336916689f87200ac75162c Mon Sep 17 00:00:00 2001 From: Daniele Rogora Date: Wed, 2 Oct 2019 19:37:53 +0200 Subject: [PATCH 1/2] Fixes parentheses when checking for bots, which was causing AttributeError --- mautrix_telegram/portal/base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mautrix_telegram/portal/base.py b/mautrix_telegram/portal/base.py index 52a98edb..56c18313 100644 --- a/mautrix_telegram/portal/base.py +++ b/mautrix_telegram/portal/base.py @@ -147,8 +147,8 @@ class BasePortal(ABC): @property def has_bot(self) -> bool: - return ((bool(self.bot) and self.bot.is_in_chat(self.tgid)) - or (self.peer_type == "user" and self.tg_receiver == self.bot.tgid)) + return (bool(self.bot) and (self.bot.is_in_chat(self.tgid) + or (self.peer_type == "user" and self.tg_receiver == self.bot.tgid))) @property def main_intent(self) -> IntentAPI: From 6c312efc9ad3340691c360c7ff3445cdeb025edc Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 2 Oct 2019 23:24:19 +0300 Subject: [PATCH 2/2] Fix sending relaybot private chat message --- mautrix_telegram/bot.py | 10 +++++----- mautrix_telegram/portal/base.py | 5 +++-- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py index ca0ac393..de2c1143 100644 --- a/mautrix_telegram/bot.py +++ b/mautrix_telegram/bot.py @@ -226,7 +226,7 @@ class Bot(AbstractUser): return False - async def handle_command(self, message: Message) -> None: + async def handle_command(self, message: Message) -> Optional[bool]: def reply(reply_text: str) -> Awaitable[Message]: return self.client.send_message(message.chat_id, reply_text, reply_to=message.id) @@ -234,8 +234,9 @@ class Bot(AbstractUser): if self.match_command(text, "start"): pcm = config["bridge.relaybot.private_chat.message"] - if pcm: - await reply(pcm) + if not pcm: + return True + await reply(pcm) return elif self.match_command(text, "id"): await self.handle_command_id(message, reply) @@ -289,8 +290,7 @@ class Bot(AbstractUser): and update.message.entities and len(update.message.entities) > 0 and isinstance(update.message.entities[0], MessageEntityBotCommand)) if is_command: - await self.handle_command(update.message) - return True + return not await self.handle_command(update.message) return False def is_in_chat(self, peer_id) -> bool: diff --git a/mautrix_telegram/portal/base.py b/mautrix_telegram/portal/base.py index 56c18313..522b8e79 100644 --- a/mautrix_telegram/portal/base.py +++ b/mautrix_telegram/portal/base.py @@ -147,8 +147,9 @@ class BasePortal(ABC): @property def has_bot(self) -> bool: - return (bool(self.bot) and (self.bot.is_in_chat(self.tgid) - or (self.peer_type == "user" and self.tg_receiver == self.bot.tgid))) + return (bool(self.bot) + and (self.bot.is_in_chat(self.tgid) + or (self.peer_type == "user" and self.tg_receiver == self.bot.tgid))) @property def main_intent(self) -> IntentAPI: