summaryrefslogtreecommitdiff
path: root/src/polaris_kettle_bot.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/polaris_kettle_bot.py')
-rwxr-xr-xsrc/polaris_kettle_bot.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/polaris_kettle_bot.py b/src/polaris_kettle_bot.py
index a512bf7..ac9ee11 100755
--- a/src/polaris_kettle_bot.py
+++ b/src/polaris_kettle_bot.py
@@ -236,9 +236,22 @@ class KettleController(threading.Thread,
for mut, upd in updates:
self._logger.debug(f'loop: got update: {upd}')
try:
- bot.edit_message_text(upd.user_id, upd.message_id,
- text=upd.html,
- reply_markup=upd.markup)
+ do_edit = True
+ if upd.finished:
+ # try to delete the old message and send a new one, to notify user more effectively
+ try:
+ bot.delete_message(upd.user_id, upd.message_id)
+ do_edit = False
+ except TelegramError as exc:
+ self._logger.error(f'loop: failed to delete old message (in order to send a new one)')
+ self._logger.exception(exc)
+
+ if do_edit:
+ bot.edit_message_text(upd.user_id, upd.message_id,
+ text=upd.html,
+ reply_markup=upd.markup)
+ else:
+ bot.notify_user(upd.user_id, upd.html, reply_markup=upd.markup)
except TelegramError as exc:
if "Message can't be edited" in exc.message:
self._logger.warning("message can't be edited, adding it to forget list")