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

New status

This commit is contained in:
Steffo 2019-01-24 21:31:01 +01:00
parent bb9a5741bf
commit 9ceb8c1c3d
2 changed files with 50 additions and 20 deletions

12
db.py
View file

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

View file

@ -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,11 +408,18 @@ 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!"
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:
@ -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