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
16
bot.py
16
bot.py
|
@ -147,7 +147,6 @@ def leave_game(bot, update):
|
||||||
reply_to_message_id=update.message.message_id)
|
reply_to_message_id=update.message.message_id)
|
||||||
|
|
||||||
|
|
||||||
@run_async
|
|
||||||
def select_game(bot, update):
|
def select_game(bot, update):
|
||||||
"""Handler for callback queries to select the current game"""
|
"""Handler for callback queries to select the current game"""
|
||||||
|
|
||||||
|
@ -159,14 +158,15 @@ def select_game(bot, update):
|
||||||
gm.userid_current[user_id] = player
|
gm.userid_current[user_id] = player
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
bot.sendMessage(update.callback_query.message.chat_id,
|
send_async(bot,
|
||||||
text=_("Game not found."),
|
update.callback_query.message.chat_id,
|
||||||
timeout=TIMEOUT)
|
text=_("Game not found."))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@run_async
|
||||||
|
def selected(bot):
|
||||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
||||||
switch_inline_query='')]]
|
switch_inline_query='')]]
|
||||||
|
|
||||||
bot.answerCallbackQuery(update.callback_query.id,
|
bot.answerCallbackQuery(update.callback_query.id,
|
||||||
text=_("Please switch to the group you selected!"),
|
text=_("Please switch to the group you selected!"),
|
||||||
show_alert=False,
|
show_alert=False,
|
||||||
|
@ -182,6 +182,8 @@ def select_game(bot, update):
|
||||||
parse_mode=ParseMode.HTML,
|
parse_mode=ParseMode.HTML,
|
||||||
timeout=TIMEOUT)
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
|
selected()
|
||||||
|
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
def status_update(bot, update):
|
def status_update(bot, update):
|
||||||
|
@ -192,8 +194,8 @@ def status_update(bot, update):
|
||||||
user = update.message.left_chat_member
|
user = update.message.left_chat_member
|
||||||
|
|
||||||
try:
|
try:
|
||||||
game = gm.player_for_user_in_chat(user, chat).game
|
|
||||||
gm.leave_game(user, chat)
|
gm.leave_game(user, chat)
|
||||||
|
game = gm.player_for_user_in_chat(user, chat).game
|
||||||
|
|
||||||
except NoGameInChatError:
|
except NoGameInChatError:
|
||||||
pass
|
pass
|
||||||
|
@ -539,7 +541,7 @@ def process_result(bot, update):
|
||||||
game = player.game
|
game = player.game
|
||||||
result_id = update.chosen_inline_result.result_id
|
result_id = update.chosen_inline_result.result_id
|
||||||
chat = game.chat
|
chat = game.chat
|
||||||
except KeyError:
|
except (KeyError, AttributeError):
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.debug("Selected result: " + result_id)
|
logger.debug("Selected result: " + result_id)
|
||||||
|
|
|
@ -144,7 +144,7 @@ class GameManager(object):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if this_users_players:
|
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:
|
else:
|
||||||
del self.userid_players[player_in_game.user.id]
|
del self.userid_players[player_in_game.user.id]
|
||||||
del self.userid_current[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()
|
translations = list()
|
||||||
|
|
||||||
if not multi and len(set(_.locale_stack)) >= 1:
|
if not multi and len(set(_.locale_stack)) >= 1:
|
||||||
_.push('en_US')
|
translations.append(_(singular, plural, n, 'en_US'))
|
||||||
translations.append(_(singular, plural, n))
|
|
||||||
_.pop()
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
for locale in _.locale_stack:
|
for locale in _.locale_stack:
|
||||||
|
@ -167,7 +165,7 @@ def _user_chat_from_update(update):
|
||||||
try:
|
try:
|
||||||
user = update.chosen_inline_result.from_user
|
user = update.chosen_inline_result.from_user
|
||||||
chat = gm.userid_current[user.id].game.chat
|
chat = gm.userid_current[user.id].game.chat
|
||||||
except (NameError, AttributeError):
|
except (NameError, AttributeError, KeyError):
|
||||||
chat = None
|
chat = None
|
||||||
|
|
||||||
return user, chat
|
return user, chat
|
||||||
|
|
Loading…
Reference in a new issue