mirror of
https://github.com/RYGhub/royalnet.git
synced 2024-11-24 03:54:20 +00:00
New status
This commit is contained in:
parent
bb9a5741bf
commit
9ceb8c1c3d
2 changed files with 50 additions and 20 deletions
12
db.py
12
db.py
|
@ -1249,10 +1249,14 @@ class Match(Base):
|
||||||
plist = f"Giocatori{minimum}:\n"
|
plist = f"Giocatori{minimum}:\n"
|
||||||
ignore_count = 0
|
ignore_count = 0
|
||||||
for player in player_list:
|
for player in player_list:
|
||||||
if player.status == MatchmakingStatus.WAIT_FOR_ME:
|
if player.status == MatchmakingStatus.READY:
|
||||||
icon = "🕒"
|
|
||||||
elif player.status == MatchmakingStatus.READY:
|
|
||||||
icon = "🔵"
|
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:
|
elif player.status == MatchmakingStatus.IGNORED:
|
||||||
ignore_count += 1
|
ignore_count += 1
|
||||||
continue
|
continue
|
||||||
|
@ -1282,6 +1286,8 @@ class Match(Base):
|
||||||
class MatchmakingStatus(enum.IntEnum):
|
class MatchmakingStatus(enum.IntEnum):
|
||||||
WAIT_FOR_ME = 1
|
WAIT_FOR_ME = 1
|
||||||
READY = 2
|
READY = 2
|
||||||
|
MAYBE = 3
|
||||||
|
SOMEONE_ELSE = 4
|
||||||
IGNORED = -1
|
IGNORED = -1
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -313,10 +313,20 @@ def cmd_mm(bot: Bot, update: Update):
|
||||||
creator=user)
|
creator=user)
|
||||||
session.add(db_match)
|
session.add(db_match)
|
||||||
session.flush()
|
session.flush()
|
||||||
inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🔵 Ci sono!", callback_data="match_ready")],
|
inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🔵 Possiamo iniziare!",
|
||||||
[InlineKeyboardButton("🕒 Sto arrivando, aspettatemi!", callback_data="match_wait_for_me")],
|
callback_data="match_ready")],
|
||||||
[InlineKeyboardButton("❌ Non vengo.", callback_data="match_ignore")],
|
[InlineKeyboardButton("🕒 Ci sarò, aspettatemi!",
|
||||||
[InlineKeyboardButton("🚩 [termina la ricerca]", callback_data="match_close")]])
|
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),
|
message = bot.send_message(config["Telegram"]["announcement_group"], db_match.generate_text(session=session),
|
||||||
parse_mode="HTML",
|
parse_mode="HTML",
|
||||||
reply_markup=inline_keyboard)
|
reply_markup=inline_keyboard)
|
||||||
|
@ -398,19 +408,26 @@ def on_callback_query(bot: Bot, update: Update):
|
||||||
elif update.callback_query.data == "match_ignore":
|
elif update.callback_query.data == "match_ignore":
|
||||||
status = db.MatchmakingStatus.IGNORED
|
status = db.MatchmakingStatus.IGNORED
|
||||||
text = "❌ Non ti interessa questa partita."
|
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
|
status = None
|
||||||
if match.creator == user:
|
if match.creator == user:
|
||||||
match.closed = True
|
match.closed = True
|
||||||
text = "🚩 Matchmaking chiuso!"
|
text = "🚩 Matchmaking chiuso!"
|
||||||
for player in match.players:
|
if update.callback_query.data == "match_close":
|
||||||
if player.status == db.MatchmakingStatus.READY or player.status == db.MatchmakingStatus.WAIT_FOR_ME:
|
for player in match.players:
|
||||||
try:
|
if player.status == db.MatchmakingStatus.READY or player.status == db.MatchmakingStatus.WAIT_FOR_ME:
|
||||||
bot.send_message(player.user.telegram_id,
|
try:
|
||||||
f"🚩 Sei pronto? <b>{match.match_title}</b> sta iniziando!",
|
bot.send_message(player.user.telegram_id,
|
||||||
parse_mode="HTML")
|
f"🚩 Sei pronto? <b>{match.match_title}</b> sta iniziando!",
|
||||||
except Exception as e:
|
parse_mode="HTML")
|
||||||
logger.warning(f"Failed to notify {player.user.username}: {e}")
|
except Exception as e:
|
||||||
|
logger.warning(f"Failed to notify {player.user.username}: {e}")
|
||||||
else:
|
else:
|
||||||
bot.answer_callback_query(update.callback_query.id, show_alert=True,
|
bot.answer_callback_query(update.callback_query.id, show_alert=True,
|
||||||
text="⚠ Non sei il creatore di questo match!")
|
text="⚠ Non sei il creatore di questo match!")
|
||||||
|
@ -435,12 +452,19 @@ def on_callback_query(bot: Bot, update: Update):
|
||||||
session.commit()
|
session.commit()
|
||||||
bot.answer_callback_query(update.callback_query.id, text=text, cache_time=1)
|
bot.answer_callback_query(update.callback_query.id, text=text, cache_time=1)
|
||||||
if not match.closed:
|
if not match.closed:
|
||||||
inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🔵 Ci sono!", callback_data="match_ready")],
|
inline_keyboard = InlineKeyboardMarkup([[InlineKeyboardButton("🔵 Possiamo iniziare!",
|
||||||
[InlineKeyboardButton("🕒 Sto arrivando, aspettatemi!",
|
callback_data="match_ready")],
|
||||||
|
[InlineKeyboardButton("🕒 Ci sarò, aspettatemi!",
|
||||||
callback_data="match_wait_for_me")],
|
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")],
|
callback_data="match_ignore")],
|
||||||
[InlineKeyboardButton("🚩 [termina la ricerca]",
|
[InlineKeyboardButton("🗑 [annulla la partita]",
|
||||||
|
callback_data="match_delete")],
|
||||||
|
[InlineKeyboardButton("🚩 [avvia la partita]",
|
||||||
callback_data="match_close")]])
|
callback_data="match_close")]])
|
||||||
else:
|
else:
|
||||||
inline_keyboard = None
|
inline_keyboard = None
|
||||||
|
|
Loading…
Reference in a new issue