Apply fixes from @jh0ker

This commit is contained in:
NekoInverter 2022-03-03 16:18:53 +08:00
parent f11df72b0b
commit c9e52174e1
3 changed files with 16 additions and 22 deletions

View file

@ -7,6 +7,7 @@ from datetime import datetime
from telegram import Message, Chat
from telegram.ext import CallbackContext
from apscheduler.jobstores.base import JobLookupError
from config import TIME_REMOVAL_AFTER_SKIP, MIN_FAST_TURN_TIME
from errors import DeckEmptyError, NotEnoughPlayersError
@ -192,7 +193,10 @@ def start_player_countdown(bot, game, job_queue):
if game.mode == 'fast':
if game.job:
game.job.schedule_removal()
try:
game.job.schedule_removal()
except JobLookupError:
pass
job = job_queue.run_once(
#lambda x,y: do_skip(bot, player),

13
bot.py
View file

@ -49,6 +49,7 @@ logging.basicConfig(
level=logging.INFO
)
logger = logging.getLogger(__name__)
logging.getLogger('apscheduler').setLevel(logging.WARNING)
@user_locale
def notify_me(update: Update, context: CallbackContext):
@ -302,12 +303,12 @@ def select_game(update: Update, context: CallbackContext):
def selected():
back = [[InlineKeyboardButton(text=_("Back to last group"),
switch_inline_query='')]]
dispatcher.run_async(context.bot.answerCallbackQuery, update.callback_query.id,
context.bot.answerCallbackQuery(update.callback_query.id,
text=_("Please switch to the group you selected!"),
show_alert=False,
timeout=TIMEOUT)
dispatcher.run_async(context.bot.editMessageText, chat_id=update.callback_query.message.chat_id,
context.bot.editMessageText(chat_id=update.callback_query.message.chat_id,
message_id=update.callback_query.message.message_id,
text=_("Selected group: {group}\n"
"<b>Make sure that you switch to the correct "
@ -317,7 +318,7 @@ def select_game(update: Update, context: CallbackContext):
parse_mode=ParseMode.HTML,
timeout=TIMEOUT)
selected()
dispatcher.run_async(selected)
@game_locales
@ -385,16 +386,16 @@ def start_game(update: Update, context: CallbackContext):
def send_first():
"""Send the first card and player"""
dispatcher.run_async(context.bot.sendSticker, chat.id,
context.bot.sendSticker(chat.id,
sticker=c.STICKERS[str(game.last_card)],
timeout=TIMEOUT)
dispatcher.run_async(context.bot.sendMessage, chat.id,
context.bot.sendMessage(chat.id,
text=first_message,
reply_markup=InlineKeyboardMarkup(choice),
timeout=TIMEOUT)
send_first()
dispatcher.run_async(send_first)
start_player_countdown(context.bot, game, context.job_queue)
elif len(context.args) and context.args[0] == 'select':

View file

@ -151,21 +151,10 @@ def game_locales(func):
def _user_chat_from_update(update):
user = update.effective_user
chat = update.effective_chat
try:
user = update.message.from_user
chat = update.message.chat
except (NameError, AttributeError):
try:
user = update.inline_query.from_user
chat = gm.userid_current[user.id].game.chat
except KeyError:
chat = None
except (NameError, AttributeError):
try:
user = update.chosen_inline_result.from_user
chat = gm.userid_current[user.id].game.chat
except (NameError, AttributeError, KeyError):
chat = None
if chat is None and user is not None and user.id in gm.userid_current:
chat = gm.userid_current.get(user.id).game.chat
return user, chat