diff --git a/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py b/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py index b8eca1c..e837e9d 100644 --- a/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py +++ b/zulip_bots/zulip_bots/bots/connect_four/test_connect_four.py @@ -53,6 +53,8 @@ class TestConnectFourBot(BotTestCase): `start game` * To start a game against another player, type `start game with @` +* To play game with the current number of players, type +`play game` * To quit a game at any time, type `quit` * To end a game with a draw, type diff --git a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py index 35c3565..d1c0876 100644 --- a/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py +++ b/zulip_bots/zulip_bots/bots/game_handler_bot/test_game_handler_bot.py @@ -111,6 +111,8 @@ class TestGameHandlerBot(BotTestCase): `start game with @` * To start a game with the computer, type `start game with` @**test-bot** +* To play game with the current number of players, type +`play game` * To quit a game at any time, type `quit` * To end a game with a draw, type diff --git a/zulip_bots/zulip_bots/game_handler.py b/zulip_bots/zulip_bots/game_handler.py index 44b43b0..e78c22f 100644 --- a/zulip_bots/zulip_bots/game_handler.py +++ b/zulip_bots/zulip_bots/game_handler.py @@ -72,6 +72,8 @@ class GameAdapter(object): `start game` * To start a game against another player, type `start game with @`{} +* To play game with the current number of players, type +`play game` * To quit a game at any time, type `quit` * To end a game with a draw, type @@ -167,6 +169,9 @@ class GameAdapter(object): elif content.lower().startswith('start game'): self.command_start_game(message, sender, content) + elif content.lower().startswith('play game'): + self.command_play(message, sender, content) + elif content.lower() == 'accept': self.command_accept(message, sender, content) @@ -323,6 +328,21 @@ class GameAdapter(object): return self.join_game(game_id, sender, message) + def command_play(self, message: Dict[str, Any], sender: str, content: str) -> None: + game_id = self.get_invite_in_subject( + message['subject'], message['display_recipient']) + if game_id is '': + self.send_reply( + message, 'There is not a game in this subject. Type `help` for all commands.') + return + num_players = len(self.get_players(game_id)) + if num_players >= self.min_players and num_players <= self.max_players: + self.start_game(game_id) + else: + self.send_reply( + message, 'Join {} more players to start the game'.format(self.max_players-num_players) + ) + def command_leaderboard(self, message: Dict[str, Any], sender: str, content: str) -> None: stats = self.get_sorted_player_statistics() num = 5 if len(stats) > 5 else len(stats)