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)
|
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,28 +158,31 @@ 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
|
||||||
|
|
||||||
back = [[InlineKeyboardButton(text=_("Back to last group"),
|
@run_async
|
||||||
switch_inline_query='')]]
|
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,
|
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
||||||
text=_("Please switch to the group you selected!"),
|
message_id=update.callback_query.message.message_id,
|
||||||
show_alert=False,
|
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)
|
timeout=TIMEOUT)
|
||||||
|
|
||||||
bot.editMessageText(chat_id=update.callback_query.message.chat_id,
|
selected()
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
@game_locales
|
@game_locales
|
||||||
|
@ -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:
|
||||||
|
@ -109,10 +107,10 @@ def user_locale(func):
|
||||||
with db_session:
|
with db_session:
|
||||||
us = UserSetting.get(id=user.id)
|
us = UserSetting.get(id=user.id)
|
||||||
|
|
||||||
if us and us.lang != 'en':
|
if us and us.lang != 'en':
|
||||||
_.push(us.lang)
|
_.push(us.lang)
|
||||||
else:
|
else:
|
||||||
_.push('en_US')
|
_.push('en_US')
|
||||||
|
|
||||||
result = func(bot, update, *pargs, **kwargs)
|
result = func(bot, update, *pargs, **kwargs)
|
||||||
_.pop()
|
_.pop()
|
||||||
|
@ -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