nmlorg / metabot

Modularized, multi-account bot.
https://metabot.readthedocs.io/
5 stars 0 forks source link

Don't update the reminders cache if an edit fails #108

Closed nmlorg closed 3 months ago

nmlorg commented 3 months ago
2024-08-09 00:10:00,473 INFO reminders.py:44] Running periodic.
2024-08-09 00:10:06,885 INFO reminders.py:185] Editing reminder -1001xxx/1991.
2024-08-09 00:10:07,641 INFO reminders.py:185] Editing reminder -1001xxx/588813.
2024-08-09 00:10:08,448 INFO reminders.py:185] Editing reminder -1001xxx/103827.
2024-08-09 00:10:09,294 INFO reminders.py:185] Editing reminder -1001xxx/678634.
2024-08-09 00:10:10,017 INFO reminders.py:185] Editing reminder -40xxx/3209.
2024-08-09 00:20:01,642 INFO reminders.py:44] Running periodic.
2024-08-09 00:20:12,006 INFO reminders.py:185] Editing reminder -1001xxx/1991.
2024-08-09 00:20:14,872 ERROR reminders.py:199] While editing 1991 in -1001xxx:
There are a bunch of events coming up:

⋮
Traceback (most recent call last):
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 188, in reminder_edit
    return bot.edit_message_caption(chat_id=groupid,
  File "lib/python3.10/site-packages/ntelebot/bot.py", line 71, in __call__
    raise ntelebot.errors.Error(data)
ntelebot.errors.Error: {'ok': False, 'error_code': 400, 'description': 'Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message'}
2024-08-09 00:30:04,334 INFO reminders.py:44] Running periodic.
2024-08-09 00:30:12,429 ERROR loop.py:72] Ignoring uncaught error while dispatching:
Traceback (most recent call last):
  File "lib/python3.10/site-packages/ntelebot/loop.py", line 70, in run
    callback()
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 47, in periodic
    _daily_messages(multibot, records)
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 152, in _daily_messages
    message = reminder_edit(bot, groupid, last.message['message_id'], newtext,
TypeError: 'NoneType' object is not subscriptable
2024-08-09 00:40:04,992 INFO reminders.py:44] Running periodic.
2024-08-09 00:40:10,887 ERROR loop.py:72] Ignoring uncaught error while dispatching:
Traceback (most recent call last):
  File "lib/python3.10/site-packages/ntelebot/loop.py", line 70, in run
    callback()
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 47, in periodic
    _daily_messages(multibot, records)
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 152, in _daily_messages
    message = reminder_edit(bot, groupid, last.message['message_id'], newtext,
TypeError: 'NoneType' object is not subscriptable

⋮

2024-08-09 07:00:00,618 INFO reminders.py:44] Running periodic.
2024-08-09 07:00:13,345 INFO reminders.py:161] Sending reminder to -1001xxx.
2024-08-09 07:00:14,305 ERROR loop.py:72] Ignoring uncaught error while dispatching:
Traceback (most recent call last):
  File "lib/python3.10/site-packages/ntelebot/loop.py", line 70, in run
    callback()
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 47, in periodic
    _daily_messages(multibot, records)
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 119, in _daily_messages
    reminder_edit(bot, groupid, last.message['message_id'], text,
TypeError: 'NoneType' object is not subscriptable
2024-08-09 07:10:03,276 INFO reminders.py:44] Running periodic.
2024-08-09 07:10:09,633 INFO reminders.py:185] Editing reminder -1001xxx/1992.
2024-08-09 07:10:10,412 INFO reminders.py:161] Sending reminder to -1001xxx.
2024-08-09 07:10:14,742 INFO reminders.py:185] Editing reminder -1001xxx/588813.
2024-08-09 07:10:15,620 INFO reminders.py:161] Sending reminder to -1001xxx.
2024-08-09 07:10:16,417 INFO reminders.py:185] Editing reminder -1001xxx/103827.
2024-08-09 07:10:22,358 INFO reminders.py:185] Editing reminder -1001xxx/678634.

https://github.com/nmlorg/metabot/blob/b37dc23c20f6172d7d376f475eb84fc51100bfa8/metabot/modules/reminders.py#L158-L161

If editMessageText/editMessageCaption fails, reminder_edit returns None, which gets written into config/daily.pickle, then all future attempts to dereference last.message['message_id'] will fail.

This used to be prevented by simply checking if message is truthy before updating config/daily.pickle:

https://github.com/nmlorg/metabot/blob/72645ad9f6b7c1833a4929fe14d4866b0e723c06/metabot/modules/reminders.py#L158-L160