e-caste / boggle-telegram-bot

A Telegram bot to play boggle (ITA: il paroliere) with friends
https://t.me/boggle_paroliere_bot
GNU General Public License v3.0
1 stars 0 forks source link

Fix KeyError in kill #46

Open e-caste opened 4 years ago

e-caste commented 4 years ago

When the bot is restarted, an error like the following can be raised when a user tries to kill a game for which there is no timer left:

2020-04-29 14:29:02,358 - __main__ - INFO - User <user> (<user_id>) killed a game in group <group> - <group_id>
2020-04-29 14:29:02,360 - telegram.ext.dispatcher - ERROR - An error was raised while processing the update and an uncaught error was raised while handling the error with an error_handler
Traceback (most recent call last):
  File "/path/venvpypy/site-packages/telegram/ext/dispatcher.py", line 403, in process_update
    self.dispatch_error(update, e)
  File "/path/venvpypy/site-packages/telegram/ext/dispatcher.py", line 528, in dispatch_error
    callback(update, CallbackContext.from_error(update, error, self))
  File "/pathvenvpypy/site-packages/telegram/ext/dispatcher.py", line 390, in process_update
    handler.handle_update(update, self, check, context)
  File "/path/venvpypy/site-packages/telegram/ext/handler.py", line 117, in handle_update
    return self.callback(update, context)
  File "/path/boggle_telegram_bot.py", line 920, in kill
    timers['newgame'][group_id]()
KeyError: <group_id>

This fix should either be implemented in the kill() function or in the __check_bot_was_restarted() function.