From 2a710145f6b6d7489f1107b83d43e5eae9bc8fd0 Mon Sep 17 00:00:00 2001 From: qubitnerd Date: Sat, 2 Jul 2016 21:23:34 +0530 Subject: [PATCH 1/3] added next_game , get a pm from when next game starts --- bot.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/bot.py b/bot.py index f9a14d2..4076247 100644 --- a/bot.py +++ b/bot.py @@ -51,6 +51,19 @@ logging.basicConfig( level=logging.INFO) logger = logging.getLogger(__name__) +remind_dict = {} +@user_locale +def next_game(bot, update): + """handler for /next_game command , pm people for next game""" + chat_id = update.message.chat_id + if update.message.chat.type == 'private': + send_async(bot, chat_id,text="call this in a group to be reminded ") + else: + try: + remind_dict[chat_id].append(update.message.from_user.id) + except KeyError: + remind_dict[chat_id] = [update.message.from_user.id] + @user_locale def new_game(bot, update): @@ -61,6 +74,9 @@ def new_game(bot, update): help(bot, update) else: + for user in remind_dict[update.message.chat_id]: + send_async(bot , user , text = "A new game has been started in " + update.message.chat.title) + del remind_dict[update.message.chat_id] game = gm.new_game(update.message.chat) game.owner = update.message.from_user send_async(bot, chat_id, @@ -711,6 +727,7 @@ dispatcher.add_handler(CommandHandler('enable_translations', dispatcher.add_handler(CommandHandler('disable_translations', disable_translations)) dispatcher.add_handler(CommandHandler('skip', skip_player)) +dispatcher.add_handler(CommandHandler('next_game',next_game)) simple_commands.register() settings.register() dispatcher.add_handler(MessageHandler([Filters.status_update], status_update)) From e28bcc58adee685f1caf13267a513951d5be42c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Sat, 2 Jul 2016 20:36:29 +0200 Subject: [PATCH 2/3] add qubitnerd to AUTHORS --- AUTHORS.md | 1 + 1 file changed, 1 insertion(+) diff --git a/AUTHORS.md b/AUTHORS.md index 04cffd8..419ee08 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -7,5 +7,6 @@ The following wonderful people contributed directly or indirectly to this project: - [imlonghao](https://github.com/imlonghao) +- [qubitnerd](https://github.com/qubitnerd) Please add yourself here alphabetically when you submit your first pull request. \ No newline at end of file From b136bdf99756a7555c2e4750fece507fc22b54a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jannes=20H=C3=B6ke?= Date: Sat, 2 Jul 2016 20:37:35 +0200 Subject: [PATCH 3/3] formatting, exception handling, documentation --- bot.py | 28 +++++++++++++++++++--------- game_manager.py | 2 ++ locales/unobot.pot | 4 ++++ simple_commands.py | 3 ++- 4 files changed, 27 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index 4076247..e27d733 100644 --- a/bot.py +++ b/bot.py @@ -51,18 +51,21 @@ logging.basicConfig( level=logging.INFO) logger = logging.getLogger(__name__) -remind_dict = {} + @user_locale -def next_game(bot, update): - """handler for /next_game command , pm people for next game""" +def notify_me(bot, update): + """Handler for /notify_me command, pm people for next game""" chat_id = update.message.chat_id if update.message.chat.type == 'private': - send_async(bot, chat_id,text="call this in a group to be reminded ") + send_async(bot, + chat_id, + text=_("Send this command in a group to be notified " + "when a new game is started there.")) else: try: - remind_dict[chat_id].append(update.message.from_user.id) + gm.remind_dict[chat_id].append(update.message.from_user.id) except KeyError: - remind_dict[chat_id] = [update.message.from_user.id] + gm.remind_dict[chat_id] = [update.message.from_user.id] @user_locale @@ -74,9 +77,16 @@ def new_game(bot, update): help(bot, update) else: - for user in remind_dict[update.message.chat_id]: - send_async(bot , user , text = "A new game has been started in " + update.message.chat.title) - del remind_dict[update.message.chat_id] + + if update.message.chat_id in gm.remind_dict: + for user in gm.remind_dict[update.message.chat_id]: + send_async(bot, + user, + text="A new game has been started in " + + update.message.chat.title) + + del gm.remind_dict[update.message.chat_id] + game = gm.new_game(update.message.chat) game.owner = update.message.from_user send_async(bot, chat_id, diff --git a/game_manager.py b/game_manager.py index c068fb1..5c94a22 100644 --- a/game_manager.py +++ b/game_manager.py @@ -33,6 +33,8 @@ class GameManager(object): self.chatid_games = dict() self.userid_players = dict() self.userid_current = dict() + self.remind_dict = dict() + self.logger = logging.getLogger(__name__) def new_game(self, chat): diff --git a/locales/unobot.pot b/locales/unobot.pot index a002baf..b65293e 100644 --- a/locales/unobot.pot +++ b/locales/unobot.pot @@ -75,6 +75,10 @@ msgstr "" msgid "Created a new game! Join the game with /join and start the game with /start" msgstr "" +#: bot.py +msgid "Send this command in a group to be notified when a new game is started there." +msgstr "" + #: bot.py:152 msgid "The lobby is closed" msgstr "" diff --git a/simple_commands.py b/simple_commands.py index 88920b2..05bece5 100644 --- a/simple_commands.py +++ b/simple_commands.py @@ -40,7 +40,8 @@ help_text = ("Follow these steps:\n\n" "the selected action.\n" "Players can join the game at any time. To leave a game, " "use /leave. If a player takes more than 90 seconds to play, " - "you can use /skip to skip that player.\n\n" + "you can use /skip to skip that player. Use /notify_me to " + "receive a private message when a new game is started.\n\n" "Language and other settings: /settings\n" "Other commands (only game creator):\n" "/close - Close lobby\n"