diff --git a/db.py b/db.py index 12008aa7..519dfe3b 100644 --- a/db.py +++ b/db.py @@ -1279,16 +1279,16 @@ class Match(Base): def format_dict(self) -> typing.Dict[str, str]: return { - "id": self.id, + "id": str(self.id), "timestamp": self.timestamp.isoformat(), - "creator_id": self.creator_id, + "creator_id": str(self.creator_id), "creator_name": self.creator.mention(), "match_title": self.match_title, - "match_desc": self.match_desc, - "min_players": self.min_players, - "max_players": self.max_players, - "active_players": self.active_players_count(), - "players": len(self.players) + "match_desc": self.match_desc if self.match_desc is not None else "", + "min_players": str(self.min_players) if self.min_players is not None else "", + "max_players": str(self.max_players) if self.max_players is not None else "", + "active_players": str(self.active_players_count()), + "players": str(len(self.players)) } diff --git a/strings.py b/strings.py index 830b9614..3ccedb63 100644 --- a/strings.py +++ b/strings.py @@ -5,7 +5,7 @@ import typing class SafeDict(dict): def __missing__(self, key): - return key + return "{" + key + "}" def safely_format_string(string: str, words: typing.Dict[str, str] = None, ignore_escaping=False) -> str: @@ -26,6 +26,7 @@ class TELEGRAM: class ERRORS: CRITICAL_ERROR = "☢ ERRORE CRITICO!\nIl bot ha ignorato il comando.\nUna segnalazione di errore è stata automaticamente mandata a @Steffo.\n\nDettagli dell'errore:\n
{exc_info}" + CRITICAL_ERROR_QUERY = "☢ ERRORE CRITICO!" UNAUTHORIZED_USER = "⚠ Non sono autorizzato a inviare messaggi a {mention}.\nPer piacere, {mention}, inviami un messaggio in privata!" UNAUTHORIZED_GROUP = "⚠ Non sono autorizzato a inviare messaggi in {group}.\n@Steffo, aggiungimi al gruppo o concedimi i permessi!" diff --git a/telegrambot.py b/telegrambot.py index 45205277..e461ee9f 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -434,8 +434,8 @@ def on_callback_query(bot: telegram.Bot, update: telegram.Update): return match.closed = True for player in match.players: - if player.status >= 1: - reply_msg(bot, player.user.telegram_id, strings.MATCHMAKING.GAME_START[player.status], **match.format_dict()) + if int(player.status) >= 1: + reply_msg(bot, player.user.telegram_id, strings.MATCHMAKING.GAME_START[int(player.status)], **match.format_dict()) elif update.callback_query.data == "match_cancel": if not (match.creator == user or user.telegram_id == 25167391): bot.answer_callback_query(update.callback_query.id, @@ -480,6 +480,13 @@ def on_callback_query(bot: telegram.Bot, update: telegram.Update): except BadRequest: pass except Exception: + try: + bot.answer_callback_query(update.callback_query.id, + show_alert=True, + text=strings.TELEGRAM.ERRORS.CRITICAL_ERROR_QUERY) + except Exception: + pass + logger.error(f"Critical error: {sys.exc_info()}") sentry.user_context({ "id": update.effective_user.id, "telegram": {