Skip to content

Commit c9e5217

Browse files
committed
Apply fixes from @jh0ker
1 parent f11df72 commit c9e5217

File tree

3 files changed

+16
-22
lines changed

3 files changed

+16
-22
lines changed

actions.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
from telegram import Message, Chat
99
from telegram.ext import CallbackContext
10+
from apscheduler.jobstores.base import JobLookupError
1011

1112
from config import TIME_REMOVAL_AFTER_SKIP, MIN_FAST_TURN_TIME
1213
from errors import DeckEmptyError, NotEnoughPlayersError
@@ -192,7 +193,10 @@ def start_player_countdown(bot, game, job_queue):
192193

193194
if game.mode == 'fast':
194195
if game.job:
195-
game.job.schedule_removal()
196+
try:
197+
game.job.schedule_removal()
198+
except JobLookupError:
199+
pass
196200

197201
job = job_queue.run_once(
198202
#lambda x,y: do_skip(bot, player),

bot.py

+7-6
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
level=logging.INFO
5050
)
5151
logger = logging.getLogger(__name__)
52+
logging.getLogger('apscheduler').setLevel(logging.WARNING)
5253

5354
@user_locale
5455
def notify_me(update: Update, context: CallbackContext):
@@ -302,12 +303,12 @@ def select_game(update: Update, context: CallbackContext):
302303
def selected():
303304
back = [[InlineKeyboardButton(text=_("Back to last group"),
304305
switch_inline_query='')]]
305-
dispatcher.run_async(context.bot.answerCallbackQuery, update.callback_query.id,
306+
context.bot.answerCallbackQuery(update.callback_query.id,
306307
text=_("Please switch to the group you selected!"),
307308
show_alert=False,
308309
timeout=TIMEOUT)
309310

310-
dispatcher.run_async(context.bot.editMessageText, chat_id=update.callback_query.message.chat_id,
311+
context.bot.editMessageText(chat_id=update.callback_query.message.chat_id,
311312
message_id=update.callback_query.message.message_id,
312313
text=_("Selected group: {group}\n"
313314
"<b>Make sure that you switch to the correct "
@@ -317,7 +318,7 @@ def selected():
317318
parse_mode=ParseMode.HTML,
318319
timeout=TIMEOUT)
319320

320-
selected()
321+
dispatcher.run_async(selected)
321322

322323

323324
@game_locales
@@ -385,16 +386,16 @@ def start_game(update: Update, context: CallbackContext):
385386
def send_first():
386387
"""Send the first card and player"""
387388

388-
dispatcher.run_async(context.bot.sendSticker, chat.id,
389+
context.bot.sendSticker(chat.id,
389390
sticker=c.STICKERS[str(game.last_card)],
390391
timeout=TIMEOUT)
391392

392-
dispatcher.run_async(context.bot.sendMessage, chat.id,
393+
context.bot.sendMessage(chat.id,
393394
text=first_message,
394395
reply_markup=InlineKeyboardMarkup(choice),
395396
timeout=TIMEOUT)
396397

397-
send_first()
398+
dispatcher.run_async(send_first)
398399
start_player_countdown(context.bot, game, context.job_queue)
399400

400401
elif len(context.args) and context.args[0] == 'select':

internationalization.py

+4-15
Original file line numberDiff line numberDiff line change
@@ -151,21 +151,10 @@ def wrapped(update, context, *pargs, **kwargs):
151151

152152

153153
def _user_chat_from_update(update):
154+
user = update.effective_user
155+
chat = update.effective_chat
154156

155-
try:
156-
user = update.message.from_user
157-
chat = update.message.chat
158-
except (NameError, AttributeError):
159-
try:
160-
user = update.inline_query.from_user
161-
chat = gm.userid_current[user.id].game.chat
162-
except KeyError:
163-
chat = None
164-
except (NameError, AttributeError):
165-
try:
166-
user = update.chosen_inline_result.from_user
167-
chat = gm.userid_current[user.id].game.chat
168-
except (NameError, AttributeError, KeyError):
169-
chat = None
157+
if chat is None and user is not None and user.id in gm.userid_current:
158+
chat = gm.userid_current.get(user.id).game.chat
170159

171160
return user, chat

0 commit comments

Comments
 (0)