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

@ -48,3 +48,4 @@ class MATCHMAKING:
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!" NOT_ADMIN = "⚠ Non sei il creatore di questo match!"
MATCH_CLOSED = "⚠ Il matchmaking per questa partita è terminato!" 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 from telegram import Bot, Update, InlineKeyboardMarkup, InlineKeyboardButton
# noinspection PyPackageRequirements # noinspection PyPackageRequirements
from telegram.ext import Updater, CommandHandler, CallbackQueryHandler from telegram.ext import Updater, CommandHandler, CallbackQueryHandler
from telegram.error import TimedOut from telegram.error import TimedOut, Unauthorized
import dice import dice
import sys import sys
import os import os
@ -396,11 +396,19 @@ def on_callback_query(bot: Bot, update: Update):
text=strings.MATCHMAKING.ERRORS.NOT_ADMIN) text=strings.MATCHMAKING.ERRORS.NOT_ADMIN)
return return
match.closed = True match.closed = True
failed_send = []
for player in match.players: for player in match.players:
if player.status >= 1: if player.status >= 1:
try:
bot.send_message(player.user.telegram_id, bot.send_message(player.user.telegram_id,
s(strings.MATCHMAKING.GAME_START[player.status], s(strings.MATCHMAKING.GAME_START[player.status],
**match.format_dict())) **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": elif update.callback_query.data == "match_cancel":
if not (match.creator == user or user.telegram_id == 25167391): if not (match.creator == user or user.telegram_id == 25167391):
bot.answer_callback_query(update.callback_query.id, bot.answer_callback_query(update.callback_query.id,
@ -431,7 +439,7 @@ def on_callback_query(bot: Bot, update: Update):
player.status = status.value player.status = status.value
session.commit() session.commit()
bot.answer_callback_query(update.callback_query.id, 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) cache_time=1)
if not match.closed: if not match.closed:
inline_keyboard = InlineKeyboardMarkup([([InlineKeyboardButton(strings.MATCHMAKING.BUTTONS[key], inline_keyboard = InlineKeyboardMarkup([([InlineKeyboardButton(strings.MATCHMAKING.BUTTONS[key],