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

Unauthorized

This commit is contained in:
Steffo 2019-01-25 21:27:51 +01:00
parent b72352dde8
commit 0b8f3d5e25
2 changed files with 15 additions and 6 deletions

View file

@ -45,6 +45,7 @@ class MATCHMAKING:
}
class ERRORS:
INVALID_SYNTAX = "⚠ Sintassi del comando errata.\n Sintassi: `/mm [minplayers-][maxplayers] per <gamename> \\n [descrizione]`"
INVALID_SYNTAX = "⚠ Sintassi del comando errata.\n Sintassi: `/mm [minplayers-][maxplayers] per <gamename> \\n[descrizione]`"
NOT_ADMIN = "⚠ Non sei il creatore di questo match!"
MATCH_CLOSED = "⚠ Il matchmaking per questa partita è terminato!"
UNAUTHORIZED = "⚠ Non sono autorizzato a inviare messaggi a {mention}. \nPer piacere, {mention}, inviami un messaggio in privata!"

View file

@ -9,7 +9,7 @@ import stagismo
from telegram import Bot, Update, InlineKeyboardMarkup, InlineKeyboardButton
# noinspection PyPackageRequirements
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from telegram.error import TimedOut
from telegram.error import TimedOut, Unauthorized
import dice
import sys
import os
@ -396,11 +396,19 @@ def on_callback_query(bot: Bot, update: Update):
text=strings.MATCHMAKING.ERRORS.NOT_ADMIN)
return
match.closed = True
failed_send = []
for player in match.players:
if player.status >= 1:
bot.send_message(player.user.telegram_id,
s(strings.MATCHMAKING.GAME_START[player.status],
**match.format_dict()))
try:
bot.send_message(player.user.telegram_id,
s(strings.MATCHMAKING.GAME_START[player.status],
**match.format_dict()))
except Unauthorized:
failed_send.append(player)
if failed_send:
for player in match.players:
bot.send_message(int(config["Telegram"]["main_group"]),
s(strings.MATCHMAKING.ERRORS.UNAUTHORIZED, mention=player.user.mention()))
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,
@ -431,7 +439,7 @@ def on_callback_query(bot: Bot, update: Update):
player.status = status.value
session.commit()
bot.answer_callback_query(update.callback_query.id,
text=s(strings.MATCHMAKING.TICKER_TEXT[update.callback_query.data]),
text=strings.MATCHMAKING.TICKER_TEXT[update.callback_query.data],
cache_time=1)
if not match.closed:
inline_keyboard = InlineKeyboardMarkup([([InlineKeyboardButton(strings.MATCHMAKING.BUTTONS[key],