Browse Source

Fix replies to non-chat messages by bot

master
Ceda EI 10 months ago
parent
commit
17eb4e8bdd
1 changed files with 8 additions and 4 deletions
  1. 8
    4
      bot/bot.py

+ 8
- 4
bot/bot.py View File

@@ -16,7 +16,8 @@ def get_text_or_type(msg, bot, truncate=False):
16 16
 
17 17
     # Set message contents
18 18
     if msg.text:
19
-        if msg.from_user.username == bot.username:
19
+        if msg.from_user.username == bot.username and re.match('<.*?>(.*)',
20
+                                                               msg.text):
20 21
             x = re.compile('(<.*?>)(.*)')
21 22
             y = x.search(msg.text)
22 23
             z = y.group(2)
@@ -59,7 +60,8 @@ def get_text_or_type(msg, bot, truncate=False):
59 60
     # Set sender
60 61
     return_message = ""
61 62
     for i in message.strip().split("\n"):
62
-        if msg.from_user.username != bot.username:
63
+        if msg.from_user.username != bot.username or not re.match('<.*?>(.*)',
64
+                                                                  msg.text):
63 65
             if msg.from_user.username:
64 66
                 return_message += f"@{msg.from_user.username}: "
65 67
             else:
@@ -96,7 +98,9 @@ def direct_cmd(bot, update, text):
96 98
 
97 99
 updater = Updater(token=config.api_key)
98 100
 dispatcher = updater.dispatcher
99
-dispatcher.add_handler(CommandHandler('list', lambda x, y: direct_cmd(x, y, "list")))
100
-dispatcher.add_handler(CommandHandler('time', lambda x, y: direct_cmd(x, y, "time")))
101
+dispatcher.add_handler(CommandHandler('list', lambda x, y: direct_cmd(x, y,
102
+                                                                      "list")))
103
+dispatcher.add_handler(CommandHandler('time', lambda x, y: direct_cmd(x, y,
104
+                                                                      "time")))
101 105
 dispatcher.add_handler(MessageHandler(Filters.all, message_handling))
102 106
 updater.start_polling()

Loading…
Cancel
Save