forked from test/mau_mau_bot
small fixes
This commit is contained in:
parent
beaa46f8e4
commit
5c87e74ae2
3 changed files with 29 additions and 29 deletions
42
bot.py
42
bot.py
|
@ -147,7 +147,6 @@ def leave_game(bot, update):
|
|||
reply_to_message_id=update.message.message_id)
|
||||
|
||||
|
||||
@run_async
|
||||
def select_game(bot, update):
|
||||
"""Handler for callback queries to select the current game"""
|
||||
|
||||
|
@ -159,28 +158,31 @@ def select_game(bot, update):
|
|||
gm.userid_current[user_id] = player
|
||||
break
|
||||
else:
|
||||
bot.sendMessage(update.callback_query.message.chat_id,
|
||||
text=_("Game not found."),
|
||||
timeout=TIMEOUT)
|
||||
send_async(bot,
|
||||
update.callback_query.message.chat_id,
|
||||
text=_("Game not found."))
|
||||
return
|
||||
|
||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
||||
switch_inline_query='')]]
|
||||
@run_async
|
||||
def selected(bot):
|
||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
||||
switch_inline_query='')]]
|
||||
bot.answerCallbackQuery(update.callback_query.id,
|
||||
text=_("Please switch to the group you selected!"),
|
||||
show_alert=False,
|
||||
timeout=TIMEOUT)
|
||||
|
||||
bot.answerCallbackQuery(update.callback_query.id,
|
||||
text=_("Please switch to the group you selected!"),
|
||||
show_alert=False,
|
||||
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 "
|
||||
"group!</b>").format(
|
||||
group=gm.userid_current[user_id].game.chat.title),
|
||||
reply_markup=InlineKeyboardMarkup(back),
|
||||
parse_mode=ParseMode.HTML,
|
||||
timeout=TIMEOUT)
|
||||
|
||||
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 "
|
||||
"group!</b>").format(
|
||||
group=gm.userid_current[user_id].game.chat.title),
|
||||
reply_markup=InlineKeyboardMarkup(back),
|
||||
parse_mode=ParseMode.HTML,
|
||||
timeout=TIMEOUT)
|
||||
selected()
|
||||
|
||||
|
||||
@game_locales
|
||||
|
@ -192,8 +194,8 @@ def status_update(bot, update):
|
|||
user = update.message.left_chat_member
|
||||
|
||||
try:
|
||||
game = gm.player_for_user_in_chat(user, chat).game
|
||||
gm.leave_game(user, chat)
|
||||
game = gm.player_for_user_in_chat(user, chat).game
|
||||
|
||||
except NoGameInChatError:
|
||||
pass
|
||||
|
@ -539,7 +541,7 @@ def process_result(bot, update):
|
|||
game = player.game
|
||||
result_id = update.chosen_inline_result.result_id
|
||||
chat = game.chat
|
||||
except KeyError:
|
||||
except (KeyError, AttributeError):
|
||||
return
|
||||
|
||||
logger.debug("Selected result: " + result_id)
|
||||
|
|
|
@ -144,7 +144,7 @@ class GameManager(object):
|
|||
pass
|
||||
|
||||
if this_users_players:
|
||||
self.userid_current[player.user.id] = this_users_players[0]
|
||||
self.userid_current[player_in_game.user.id] = this_users_players[0]
|
||||
else:
|
||||
del self.userid_players[player_in_game.user.id]
|
||||
del self.userid_current[player_in_game.user.id]
|
||||
|
|
|
@ -86,9 +86,7 @@ def __(singular, plural=None, n=1, multi=False):
|
|||
translations = list()
|
||||
|
||||
if not multi and len(set(_.locale_stack)) >= 1:
|
||||
_.push('en_US')
|
||||
translations.append(_(singular, plural, n))
|
||||
_.pop()
|
||||
translations.append(_(singular, plural, n, 'en_US'))
|
||||
|
||||
else:
|
||||
for locale in _.locale_stack:
|
||||
|
@ -109,10 +107,10 @@ def user_locale(func):
|
|||
with db_session:
|
||||
us = UserSetting.get(id=user.id)
|
||||
|
||||
if us and us.lang != 'en':
|
||||
_.push(us.lang)
|
||||
else:
|
||||
_.push('en_US')
|
||||
if us and us.lang != 'en':
|
||||
_.push(us.lang)
|
||||
else:
|
||||
_.push('en_US')
|
||||
|
||||
result = func(bot, update, *pargs, **kwargs)
|
||||
_.pop()
|
||||
|
@ -167,7 +165,7 @@ def _user_chat_from_update(update):
|
|||
try:
|
||||
user = update.chosen_inline_result.from_user
|
||||
chat = gm.userid_current[user.id].game.chat
|
||||
except (NameError, AttributeError):
|
||||
except (NameError, AttributeError, KeyError):
|
||||
chat = None
|
||||
|
||||
return user, chat
|
||||
|
|
Loading…
Reference in a new issue