From 887411df6dca99f968b94740abdd214c54ea00aa Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 27 Apr 2020 00:26:57 +0200 Subject: [PATCH] Fiorygi may drop when answering mmevents --- royalpack/commands/matchmaking.py | 8 +++++--- royalpack/tables/fiorygitransactions.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/royalpack/commands/matchmaking.py b/royalpack/commands/matchmaking.py index 0beec996..8ad3dfd9 100644 --- a/royalpack/commands/matchmaking.py +++ b/royalpack/commands/matchmaking.py @@ -2,7 +2,7 @@ import datetime import re import dateparser import typing -import asyncio +import random from telegram import Bot as PTBBot from telegram import Message as PTBMessage from telegram import InlineKeyboardMarkup as InKM @@ -13,7 +13,7 @@ from royalnet.serf.telegram import TelegramSerf as TelegramBot from royalnet.serf.telegram import escape as telegram_escape from royalnet.utils import asyncify, sleep_until, sentry_async_wrap from royalnet.backpack.tables import User -from ..tables import MMEvent, MMResponse +from ..tables import MMEvent, MMResponse, FiorygiTransaction from ..types import MMChoice, MMInterfaceDataTelegram @@ -127,7 +127,7 @@ class MatchmakingCommand(Command): parse_mode="HTML", disable_web_page_preview=True, reply_markup=self._gen_telegram_keyboard(mmevent)) - except BadRequest: + except TelegramError: pass def _gen_mm_telegram_callback(self, client: PTBBot, mmid: int, choice: MMChoice): @@ -140,6 +140,8 @@ class MatchmakingCommand(Command): if mmresponse is None: mmresponse = self.alchemy.get(MMResponse)(user=author, mmevent=mmevent, choice=choice) data.session.add(mmresponse) + if random.randrange(14) == 0: + await FiorygiTransaction.spawn_fiorygi(data, author, 1, "aver risposto a un matchmaking") else: mmresponse.choice = choice await data.session_commit() diff --git a/royalpack/tables/fiorygitransactions.py b/royalpack/tables/fiorygitransactions.py index 41b1f6c7..47c0cb94 100644 --- a/royalpack/tables/fiorygitransactions.py +++ b/royalpack/tables/fiorygitransactions.py @@ -68,7 +68,8 @@ class FiorygiTransaction: if qty > 0: msg = f"💰 [b]{user_str}[/b] ha ottenuto [b]{qty}[/b] fioryg{'i' if qty != 1 else ''} per [i]{reason}[/i]!" elif qty == 0: - msg = f"❓ [b]{user_str}[/b] ha ottenuto [b]{qty}[/b] fioryg{'i' if qty != 1 else ''}...? Per [i]{reason}[/i]...? Cosa?" + msg = f"❓ [b]{user_str}[/b] ha ottenuto [b]{qty}[/b] fioryg{'i' if qty != 1 else ''}...? " \ + f"Per [i]{reason}[/i]...? Cosa?" else: msg = f"💸 [b]{user_str}[/b] ha perso [b]{-qty}[/b] fioryg{'i' if qty != -1 else ''} per [i]{reason}[/i]."