From 9ceb8c1c3d2c2dbce0d1010c8dd0d4231222ca73 Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Thu, 24 Jan 2019 21:31:01 +0100 Subject: [PATCH] New status --- db.py | 12 ++++++++--- telegrambot.py | 58 +++++++++++++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 20 deletions(-) diff --git a/db.py b/db.py index 742dd22e..af32d39c 100644 --- a/db.py +++ b/db.py @@ -1249,10 +1249,14 @@ class Match(Base): plist = f"Giocatori{minimum}:\n" ignore_count = 0 for player in player_list: - if player.status == MatchmakingStatus.WAIT_FOR_ME: - icon = "πŸ•’" - elif player.status == MatchmakingStatus.READY: + if player.status == MatchmakingStatus.READY: icon = "πŸ”΅" + elif player.status == MatchmakingStatus.WAIT_FOR_ME: + icon = "πŸ•’" + elif player.status == MatchmakingStatus.MAYBE: + icon = "❔" + elif player.status == MatchmakingStatus.SOMEONE_ELSE: + icon = "πŸ’¬" elif player.status == MatchmakingStatus.IGNORED: ignore_count += 1 continue @@ -1282,6 +1286,8 @@ class Match(Base): class MatchmakingStatus(enum.IntEnum): WAIT_FOR_ME = 1 READY = 2 + MAYBE = 3 + SOMEONE_ELSE = 4 IGNORED = -1 diff --git a/telegrambot.py b/telegrambot.py index 534274b2..5b49cd58 100644 --- a/telegrambot.py +++ b/telegrambot.py @@ -313,10 +313,20 @@ def cmd_mm(bot: Bot, update: Update): creator=user) session.add(db_match) session.flush() - inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("πŸ”΅ Ci sono!", callback_data="match_ready")], - [InlineKeyboardButton("πŸ•’ Sto arrivando, aspettatemi!", callback_data="match_wait_for_me")], - [InlineKeyboardButton("❌ Non vengo.", callback_data="match_ignore")], - [InlineKeyboardButton("🚩 [termina la ricerca]", callback_data="match_close")]]) + inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("πŸ”΅ Possiamo iniziare!", + callback_data="match_ready")], + [InlineKeyboardButton("πŸ•’ Ci sarΓ², aspettatemi!", + callback_data="match_wait_for_me")], + [InlineKeyboardButton("❔ Forse vengo, se non ci sono fate senza di me.", + callback_data="match_maybe")], + [InlineKeyboardButton("πŸ’¬ Solo se viene anche qualcun altro...", + callback_data="match_someone_else")], + [InlineKeyboardButton("❌ Non ci sarΓ².", + callback_data="match_ignore")], + [InlineKeyboardButton("πŸ—‘ [annulla la partita]", + callback_data="match_delete")], + [InlineKeyboardButton("🚩 [avvia la partita]", + callback_data="match_close")]]) message = bot.send_message(config["Telegram"]["announcement_group"], db_match.generate_text(session=session), parse_mode="HTML", reply_markup=inline_keyboard) @@ -398,19 +408,26 @@ def on_callback_query(bot: Bot, update: Update): elif update.callback_query.data == "match_ignore": status = db.MatchmakingStatus.IGNORED text = "❌ Non ti interessa questa partita." - elif update.callback_query.data == "match_close": + elif update.callback_query.data == "match_maybe": + status = db.MatchmakingStatus.MAYBE + text = "❔ Hai detto che forse ci sarai." + elif update.callback_query.data == "match_someone_else": + status = db.MatchmakingStatus.SOMEONE_ELSE + text = "πŸ’¬ Hai detto che vuoi aspettare che venga qualcun altro." + elif update.callback_query.data == "match_close" or update.callback_query.data == "match_delete": status = None if match.creator == user: match.closed = True text = "🚩 Matchmaking chiuso!" - for player in match.players: - if player.status == db.MatchmakingStatus.READY or player.status == db.MatchmakingStatus.WAIT_FOR_ME: - try: - bot.send_message(player.user.telegram_id, - f"🚩 Sei pronto? {match.match_title} sta iniziando!", - parse_mode="HTML") - except Exception as e: - logger.warning(f"Failed to notify {player.user.username}: {e}") + if update.callback_query.data == "match_close": + for player in match.players: + if player.status == db.MatchmakingStatus.READY or player.status == db.MatchmakingStatus.WAIT_FOR_ME: + try: + bot.send_message(player.user.telegram_id, + f"🚩 Sei pronto? {match.match_title} sta iniziando!", + parse_mode="HTML") + except Exception as e: + logger.warning(f"Failed to notify {player.user.username}: {e}") else: bot.answer_callback_query(update.callback_query.id, show_alert=True, text="⚠ Non sei il creatore di questo match!") @@ -435,12 +452,19 @@ def on_callback_query(bot: Bot, update: Update): session.commit() bot.answer_callback_query(update.callback_query.id, text=text, cache_time=1) if not match.closed: - inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("πŸ”΅ Ci sono!", callback_data="match_ready")], - [InlineKeyboardButton("πŸ•’ Sto arrivando, aspettatemi!", + inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("πŸ”΅ Possiamo iniziare!", + callback_data="match_ready")], + [InlineKeyboardButton("πŸ•’ Ci sarΓ², aspettatemi!", callback_data="match_wait_for_me")], - [InlineKeyboardButton("❌ Non vengo.", + [InlineKeyboardButton("❔ Forse vengo, se non ci sono fate senza di me.", + callback_data="match_maybe")], + [InlineKeyboardButton("πŸ’¬ Solo se viene anche qualcun altro...", + callback_data="match_someone_else")], + [InlineKeyboardButton("❌ Non ci sarΓ².", callback_data="match_ignore")], - [InlineKeyboardButton("🚩 [termina la ricerca]", + [InlineKeyboardButton("πŸ—‘ [annulla la partita]", + callback_data="match_delete")], + [InlineKeyboardButton("🚩 [avvia la partita]", callback_data="match_close")]]) else: inline_keyboard = None