small fixes

This commit is contained in:
Jannes Höke 2016-06-02 15:03:33 +02:00
parent beaa46f8e4
commit 5c87e74ae2
3 changed files with 29 additions and 29 deletions

16
bot.py
View file

@ -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,14 +158,15 @@ 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
@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,
@ -182,6 +182,8 @@ def select_game(bot, update):
parse_mode=ParseMode.HTML,
timeout=TIMEOUT)
selected()
@game_locales
def status_update(bot, update):
@ -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)

View file

@ -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]

View file

@ -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:
@ -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