From 3b134ae5f29e9442681876950927caacedd339c8 Mon Sep 17 00:00:00 2001 From: Ceda EI Date: Tue, 19 Mar 2019 18:02:05 +0530 Subject: [PATCH] Avoid sending excess messages and unnecessary state drops --- bot.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index d75945b..ea24074 100755 --- a/bot.py +++ b/bot.py @@ -486,8 +486,8 @@ def message_handling(bot, update, db): delete_token(bot, update, player) else: - drop_state(bot, update, player) - send_status(bot, update, player) + if update.message.chat.type == "private": + send_status(bot, update, player) elif state["state"] == "aq": add_name(bot, update, player, "quest", state["extra"]) @@ -540,8 +540,9 @@ def message_handling(bot, update, db): prefix = f"Quest {quest.name} has been deleted\n\n" send_status(bot, update, player, prefix=prefix) else: - drop_state(bot, update, player) - send_status(bot, update, player) + if update.message.chat.type == "private": + drop_state(bot, update, player) + send_status(bot, update, player) elif state["state"] == "esq": if text == "back" or text == "⬅️ back": @@ -576,12 +577,14 @@ def message_handling(bot, update, db): prefix = f"Side Quest {sq.name} has been deleted\n\n" send_status(bot, update, player, prefix=prefix) else: - drop_state(bot, update, player) - send_status(bot, update, player) + if update.message.chat.type == "private": + drop_state(bot, update, player) + send_status(bot, update, player) elif state["state"] == "bo": - player.set_state('none', 0) - send_status(bot, update, player) + if text == "back" or update.message.chat.type == "private": + player.set_state('none', 0) + send_status(bot, update, player) elif state["state"] == "eqn": edit_quest(bot, update, player, state["extra"], "name", "quest") @@ -604,8 +607,9 @@ def message_handling(bot, update, db): elif state["state"] == "rt": delete_token_rt(bot, update, player) else: - drop_state(bot, update, player) - send_status(bot, update, player) + if update.message.chat.type == "private": + drop_state(bot, update, player) + send_status(bot, update, player) def sigterm_handler(signal, frame, db):