From 0ecf3370e3ed5bb687266c7b460f3dce48a05cdb Mon Sep 17 00:00:00 2001 From: imlonghao Date: Wed, 27 Apr 2016 21:47:11 +0800 Subject: [PATCH] Fix issue when joining a closed game, send message via send_async, send message to the sender in same case. --- bot.py | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/bot.py b/bot.py index 8469b16..d43f6f5 100644 --- a/bot.py +++ b/bot.py @@ -115,9 +115,9 @@ def new_game(bot, update): help(bot, update) else: gm.new_game(update.message.chat) - bot.sendMessage(chat_id, - text="Created a new game! Join the game with /join " - "and start the game with /start") + send_async(bot, chat_id, + text="Created a new game! Join the game with /join " + "and start the game with /start") if botan: botan.track(update.message, 'New games') @@ -132,6 +132,7 @@ def join_game(bot, update): game = gm.chatid_games[chat_id][-1] if not game.open: send_async(bot, chat_id, text="The lobby is closed") + return except (KeyError, IndexError): pass @@ -163,7 +164,8 @@ def leave_game(bot, update): break else: send_async(bot, chat_id, text="You are not playing in a game in " - "this group.") + "this group.", + reply_to_message_id=update.message.message_id) return user = update.message.from_user @@ -173,10 +175,12 @@ def leave_game(bot, update): send_async(bot, chat_id, text="Game ended!") else: if gm.leave_game(user, chat_id): - send_async(bot, chat_id, text="Okay") + send_async(bot, chat_id, text="Okay", + reply_to_message_id=update.message.message_id) else: send_async(bot, chat_id, text="You are not playing in a game in " - "this group.") + "this group.", + reply_to_message_id=update.message.message_id) def select_game(bot, update): @@ -281,7 +285,8 @@ def close_game(bot, update): send_async(bot, chat_id, text="Closed the lobby") else: send_async(bot, chat_id, - text="Only the game creator can do that") + text="Only the game creator can do that", + reply_to_message_id=update.message.message_id) def open_game(bot, update): @@ -299,7 +304,8 @@ def open_game(bot, update): send_async(bot, chat_id, text="Opened the lobby") else: send_async(bot, chat_id, - text="Only the game creator can do that") + text="Only the game creator can do that", + reply_to_message_id=update.message.message_id) def skip_player(bot, update): @@ -320,7 +326,8 @@ def skip_player(bot, update): % display_name(game.current_player.user)) else: send_async(bot, chat_id, - text="Only the game creator can do that") + text="Only the game creator can do that", + reply_to_message_id=update.message.message_id) def help(bot, update):