summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/home/bot/wrapper.py4
-rwxr-xr-xsrc/polaris_kettle_bot.py19
2 files changed, 18 insertions, 5 deletions
diff --git a/src/home/bot/wrapper.py b/src/home/bot/wrapper.py
index 5f399ce..df7175e 100644
--- a/src/home/bot/wrapper.py
+++ b/src/home/bot/wrapper.py
@@ -286,10 +286,10 @@ class Wrapper:
text=text,
parse_mode='HTML')
- def notify_user(self, user_id: int, text: Union[str, Exception]) -> None:
+ def notify_user(self, user_id: int, text: Union[str, Exception], **kwargs) -> None:
if isinstance(text, Exception):
text = exc2text(text)
- self.updater.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML')
+ self.updater.bot.send_message(chat_id=user_id, text=text, parse_mode='HTML', **kwargs)
def send_photo(self, user_id, **kwargs):
self.updater.bot.send_photo(chat_id=user_id, **kwargs)
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")