Browse Source

Fix replies to non-chat messages by bot

master
Ceda EI 1 year 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):

# 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()

Loading…
Cancel
Save