From 17eb4e8bdd4dd1503847978ea513c03ba812472f Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 29 Jan 2019 10:19:56 +0530 Subject: [PATCH] Fix replies to non-chat messages by bot --- bot/bot.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/bot/bot.py b/bot/bot.py index 66dba24..6c92c29 100644 --- a/bot/bot.py +++ b/bot/bot.py @@ -16,7 +16,8 @@ def get_text_or_type(msg, bot, truncate=False): # Set message contents if msg.text: - if msg.from_user.username == bot.username: + if msg.from_user.username == bot.username and re.match('<.*?>(.*)', + msg.text): x = re.compile('(<.*?>)(.*)') y = x.search(msg.text) z = y.group(2) @@ -59,7 +60,8 @@ def get_text_or_type(msg, bot, truncate=False): # Set sender return_message = "" for i in message.strip().split("\n"): - if msg.from_user.username != bot.username: + if msg.from_user.username != bot.username or not re.match('<.*?>(.*)', + msg.text): if msg.from_user.username: return_message += f"@{msg.from_user.username}: " else: @@ -96,7 +98,9 @@ def direct_cmd(bot, update, text): updater = Updater(token=config.api_key) dispatcher = updater.dispatcher -dispatcher.add_handler(CommandHandler('list', lambda x, y: direct_cmd(x, y, "list"))) -dispatcher.add_handler(CommandHandler('time', lambda x, y: direct_cmd(x, y, "time"))) +dispatcher.add_handler(CommandHandler('list', lambda x, y: direct_cmd(x, y, + "list"))) +dispatcher.add_handler(CommandHandler('time', lambda x, y: direct_cmd(x, y, + "time"))) dispatcher.add_handler(MessageHandler(Filters.all, message_handling)) updater.start_polling()