1
Fork 0
mirror of https://github.com/RYGhub/royalnet.git synced 2024-11-23 19:44:20 +00:00

And again

This commit is contained in:
Steffo 2019-02-15 22:21:41 +01:00
parent 5dcf88c613
commit 1d4497144b
3 changed files with 18 additions and 10 deletions

14
db.py
View file

@ -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))
}

View file

@ -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 = "☢ <b>ERRORE CRITICO!</b>\nIl bot ha ignorato il comando.\nUna segnalazione di errore è stata automaticamente mandata a @Steffo.\n\nDettagli dell'errore:\n<pre>{exc_info}</pre>"
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 <i>{group}</i>.\n@Steffo, aggiungimi al gruppo o concedimi i permessi!"

View file

@ -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": {