integrations: Remove !avatar from game handler.
The issue linked to this commit suggest suggests to replace the avatar with the username only, I just needed to remove !avatar as the code already shows the username. Fixes part of #632.
This commit is contained in:
parent
e995e52896
commit
9ce2ea53a5
|
@ -229,7 +229,7 @@ class TestGameHandlerBot(BotTestCase, DefaultTests):
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.verify_response(
|
self.verify_response(
|
||||||
'quit', 'Game cancelled.\n!avatar(foo@example.com) **foo** quit.', 0, bot, 'foo')
|
'quit', 'Game cancelled.\n**foo** quit.', 0, bot, 'foo')
|
||||||
|
|
||||||
def test_user_already_in_game_errors(self) -> None:
|
def test_user_already_in_game_errors(self) -> None:
|
||||||
bot = self.setup_game()
|
bot = self.setup_game()
|
||||||
|
@ -313,14 +313,14 @@ class TestGameHandlerBot(BotTestCase, DefaultTests):
|
||||||
|
|
||||||
def test_normal_turns(self) -> None:
|
def test_normal_turns(self) -> None:
|
||||||
bot = self.setup_game()
|
bot = self.setup_game()
|
||||||
self.verify_response('move 3', '**foo** moved in column 3\n\nfoo\n\n!avatar(baz@example.com) It\'s **baz**\'s (:red_circle:) turn.',
|
self.verify_response('move 3', '**foo** moved in column 3\n\nfoo\n\nIt\'s **baz**\'s (:red_circle:) turn.',
|
||||||
0, bot=bot, stream='test', subject='test game')
|
0, bot=bot, stream='test', subject='test game')
|
||||||
self.verify_response('move 3', '**baz** moved in column 3\n\nfoo\n\n!avatar(foo@example.com) It\'s **foo**\'s (:blue_circle:) turn.',
|
self.verify_response('move 3', '**baz** moved in column 3\n\nfoo\n\nIt\'s **foo**\'s (:blue_circle:) turn.',
|
||||||
0, bot=bot, stream='test', subject='test game', user_name='baz')
|
0, bot=bot, stream='test', subject='test game', user_name='baz')
|
||||||
|
|
||||||
def test_wrong_turn(self) -> None:
|
def test_wrong_turn(self) -> None:
|
||||||
bot = self.setup_game()
|
bot = self.setup_game()
|
||||||
self.verify_response('move 5', '!avatar(foo@example.com) It\'s **foo**\'s (:blue_circle:) turn.', 0,
|
self.verify_response('move 5', 'It\'s **foo**\'s (:blue_circle:) turn.', 0,
|
||||||
bot=bot, stream='test', subject='test game', user_name='baz')
|
bot=bot, stream='test', subject='test game', user_name='baz')
|
||||||
|
|
||||||
def test_private_message_error(self) -> None:
|
def test_private_message_error(self) -> None:
|
||||||
|
@ -390,7 +390,7 @@ class TestGameHandlerBot(BotTestCase, DefaultTests):
|
||||||
bot = self.setup_game()
|
bot = self.setup_game()
|
||||||
bot.put_user_cache()
|
bot.put_user_cache()
|
||||||
with patch('zulip_bots.bots.game_handler_bot.game_handler_bot.MockModel.determine_game_over', return_value='foo@example.com'):
|
with patch('zulip_bots.bots.game_handler_bot.game_handler_bot.MockModel.determine_game_over', return_value='foo@example.com'):
|
||||||
self.verify_response('move 3', '!avatar(foo@example.com) **foo** won! :tada:',
|
self.verify_response('move 3', '**foo** won! :tada:',
|
||||||
1, bot=bot, stream='test', subject='test game')
|
1, bot=bot, stream='test', subject='test game')
|
||||||
leaderboard = '**Most wins**\n\n\
|
leaderboard = '**Most wins**\n\n\
|
||||||
Player | Games Won | Games Drawn | Games Lost | Total Games\n\
|
Player | Games Won | Games Drawn | Games Lost | Total Games\n\
|
||||||
|
@ -403,12 +403,12 @@ Player | Games Won | Games Drawn | Games Lost | Total Games\n\
|
||||||
def test_current_turn_winner(self) -> None:
|
def test_current_turn_winner(self) -> None:
|
||||||
bot = self.setup_game()
|
bot = self.setup_game()
|
||||||
with patch('zulip_bots.bots.game_handler_bot.game_handler_bot.MockModel.determine_game_over', return_value='current turn'):
|
with patch('zulip_bots.bots.game_handler_bot.game_handler_bot.MockModel.determine_game_over', return_value='current turn'):
|
||||||
self.verify_response('move 3', '!avatar(foo@example.com) **foo** won! :tada:',
|
self.verify_response('move 3', '**foo** won! :tada:',
|
||||||
1, bot=bot, stream='test', subject='test game')
|
1, bot=bot, stream='test', subject='test game')
|
||||||
|
|
||||||
def test_computer_turn(self) -> None:
|
def test_computer_turn(self) -> None:
|
||||||
bot = self.setup_computer_game()
|
bot = self.setup_computer_game()
|
||||||
self.verify_response('move 3', '**foo** moved in column 3\n\nfoo\n\n!avatar(test-bot@example.com) It\'s **test-bot**\'s (:red_circle:) turn.',
|
self.verify_response('move 3', '**foo** moved in column 3\n\nfoo\n\nIt\'s **test-bot**\'s (:red_circle:) turn.',
|
||||||
0, bot=bot, stream='test', subject='test game')
|
0, bot=bot, stream='test', subject='test game')
|
||||||
with patch('zulip_bots.bots.game_handler_bot.game_handler_bot.MockModel.determine_game_over', return_value='test-bot@example.com'):
|
with patch('zulip_bots.bots.game_handler_bot.game_handler_bot.MockModel.determine_game_over', return_value='test-bot@example.com'):
|
||||||
self.verify_response('move 5', 'I won! Well Played!',
|
self.verify_response('move 5', 'I won! Well Played!',
|
||||||
|
@ -462,7 +462,6 @@ Player | Games Won | Games Drawn | Games Lost | Total Games\n\
|
||||||
def test_parse_message(self) -> None:
|
def test_parse_message(self) -> None:
|
||||||
bot = self.setup_game()
|
bot = self.setup_game()
|
||||||
self.verify_response('move 3', 'Join your game using the link below!\n\n> **Game `abc123`**\n\
|
self.verify_response('move 3', 'Join your game using the link below!\n\n> **Game `abc123`**\n\
|
||||||
> !avatar(foo@example.com)\n\
|
|
||||||
> foo test game\n\
|
> foo test game\n\
|
||||||
> 2/2 players\n\
|
> 2/2 players\n\
|
||||||
> **[Join Game](/#narrow/stream/test/topic/test game)**', 0, bot=bot)
|
> **[Join Game](/#narrow/stream/test/topic/test game)**', 0, bot=bot)
|
||||||
|
@ -471,7 +470,6 @@ Player | Games Won | Games Drawn | Games Lost | Total Games\n\
|
||||||
To move subjects, send your message again, otherwise join the game using the link below.
|
To move subjects, send your message again, otherwise join the game using the link below.
|
||||||
|
|
||||||
> **Game `abc123`**
|
> **Game `abc123`**
|
||||||
> !avatar(foo@example.com)
|
|
||||||
> foo test game
|
> foo test game
|
||||||
> 2/2 players
|
> 2/2 players
|
||||||
> **[Join Game](/#narrow/stream/test/topic/test game)**''', 0, bot=bot, stream='test 2', subject='game 2')
|
> **[Join Game](/#narrow/stream/test/topic/test game)**''', 0, bot=bot, stream='test 2', subject='game 2')
|
||||||
|
@ -485,7 +483,6 @@ To move subjects, send your message again, otherwise join the game using the lin
|
||||||
To move subjects, send your message again, otherwise join the game using the link below.
|
To move subjects, send your message again, otherwise join the game using the link below.
|
||||||
|
|
||||||
> **Game `abcdefg`**
|
> **Game `abcdefg`**
|
||||||
> !avatar(bar@example.com)
|
|
||||||
> foo test game
|
> foo test game
|
||||||
> 2/2 players
|
> 2/2 players
|
||||||
> **[Join Game](/#narrow/stream/test2/topic/test game 2)**''', 0, bot=bot, user_name='bar', stream='test game', subject='test2')
|
> **[Join Game](/#narrow/stream/test2/topic/test game 2)**''', 0, bot=bot, user_name='bar', stream='test game', subject='test2')
|
||||||
|
|
|
@ -139,7 +139,9 @@ class GameAdapter:
|
||||||
|
|
||||||
def alert_new_invitation(self, game_id: str) -> str:
|
def alert_new_invitation(self, game_id: str) -> str:
|
||||||
# Since the first player invites, the challenger is always the first player
|
# Since the first player invites, the challenger is always the first player
|
||||||
return '**' + self.get_host(game_id) + ' has invited you to play a game of ' + self.game_name + '.**\n' +\
|
player_email = self.get_players(game_id)[0]
|
||||||
|
sender_name = self.get_username_by_email(player_email)
|
||||||
|
return '**' + sender_name + ' has invited you to play a game of ' + self.game_name + '.**\n' +\
|
||||||
self.get_formatted_game_object(game_id) + '\n\n' +\
|
self.get_formatted_game_object(game_id) + '\n\n' +\
|
||||||
'Type ```accept``` to accept the game invitation\n' +\
|
'Type ```accept``` to accept the game invitation\n' +\
|
||||||
'Type ```decline``` to decline the game invitation.'
|
'Type ```decline``` to decline the game invitation.'
|
||||||
|
@ -381,9 +383,8 @@ class GameAdapter:
|
||||||
if game_id == '':
|
if game_id == '':
|
||||||
self.send_reply(
|
self.send_reply(
|
||||||
message, 'You are not in a game. Type `help` for all commands.')
|
message, 'You are not in a game. Type `help` for all commands.')
|
||||||
sender_avatar = "!avatar({})".format(sender)
|
|
||||||
sender_name = self.get_username_by_email(sender)
|
sender_name = self.get_username_by_email(sender)
|
||||||
self.cancel_game(game_id, reason='{} **{}** quit.'.format(sender_avatar, sender_name))
|
self.cancel_game(game_id, reason='**{}** quit.'.format(sender_name))
|
||||||
|
|
||||||
def command_join(self, message: Dict[str, Any], sender: str, content: str) -> None:
|
def command_join(self, message: Dict[str, Any], sender: str, content: str) -> None:
|
||||||
if not self.is_user_not_player(sender, message):
|
if not self.is_user_not_player(sender, message):
|
||||||
|
@ -485,8 +486,7 @@ class GameAdapter:
|
||||||
def get_formatted_game_object(self, game_id: str) -> str:
|
def get_formatted_game_object(self, game_id: str) -> str:
|
||||||
object = '''> **Game `{}`**
|
object = '''> **Game `{}`**
|
||||||
> {}
|
> {}
|
||||||
> {}
|
> {}/{} players'''.format(game_id, self.game_name, self.get_number_of_players(game_id), self.max_players)
|
||||||
> {}/{} players'''.format(game_id, self.get_host(game_id), self.game_name, self.get_number_of_players(game_id), self.max_players)
|
|
||||||
if game_id in self.instances.keys():
|
if game_id in self.instances.keys():
|
||||||
instance = self.instances[game_id]
|
instance = self.instances[game_id]
|
||||||
if not self.is_single_player:
|
if not self.is_single_player:
|
||||||
|
@ -554,11 +554,6 @@ class GameAdapter:
|
||||||
num = len(self.get_players(game_id))
|
num = len(self.get_players(game_id))
|
||||||
return num
|
return num
|
||||||
|
|
||||||
def get_host(self, game_id: str) -> str:
|
|
||||||
player_email = self.get_players(game_id)[0]
|
|
||||||
player_avatar = "!avatar({})".format(player_email)
|
|
||||||
return player_avatar
|
|
||||||
|
|
||||||
def parse_message(self, message: Dict[str, Any]) -> None:
|
def parse_message(self, message: Dict[str, Any]) -> None:
|
||||||
game_id = self.is_user_in_game(message['sender_email'])
|
game_id = self.is_user_in_game(message['sender_email'])
|
||||||
game = self.get_game_info(game_id)
|
game = self.get_game_info(game_id)
|
||||||
|
@ -825,9 +820,7 @@ class GameInstance:
|
||||||
if self.gameAdapter.is_single_player:
|
if self.gameAdapter.is_single_player:
|
||||||
self.broadcast('It\'s your turn')
|
self.broadcast('It\'s your turn')
|
||||||
else:
|
else:
|
||||||
user_turn_avatar = "!avatar({})".format(self.players[self.turn])
|
self.broadcast('It\'s **{}**\'s ({}) turn.'.format(
|
||||||
self.broadcast('{} It\'s **{}**\'s ({}) turn.'.format(
|
|
||||||
user_turn_avatar,
|
|
||||||
self.gameAdapter.get_username_by_email(
|
self.gameAdapter.get_username_by_email(
|
||||||
self.players[self.turn]),
|
self.players[self.turn]),
|
||||||
self.gameAdapter.gameMessageHandler.get_player_color(self.turn)))
|
self.gameAdapter.gameMessageHandler.get_player_color(self.turn)))
|
||||||
|
@ -889,9 +882,7 @@ class GameInstance:
|
||||||
game_over = self.players[self.turn]
|
game_over = self.players[self.turn]
|
||||||
self.end_game(game_over)
|
self.end_game(game_over)
|
||||||
return
|
return
|
||||||
user_turn_avatar = "!avatar({})".format(self.players[self.turn])
|
self.current_messages.append('It\'s **{}**\'s ({}) turn.'.format(
|
||||||
self.current_messages.append('{} It\'s **{}**\'s ({}) turn.'.format(
|
|
||||||
user_turn_avatar,
|
|
||||||
self.gameAdapter.get_username_by_email(self.players[self.turn]),
|
self.gameAdapter.get_username_by_email(self.players[self.turn]),
|
||||||
self.gameAdapter.gameMessageHandler.get_player_color(self.turn)
|
self.gameAdapter.gameMessageHandler.get_player_color(self.turn)
|
||||||
))
|
))
|
||||||
|
@ -906,9 +897,7 @@ class GameInstance:
|
||||||
if self.gameAdapter.is_single_player:
|
if self.gameAdapter.is_single_player:
|
||||||
self.current_messages.append('It\'s your turn.')
|
self.current_messages.append('It\'s your turn.')
|
||||||
else:
|
else:
|
||||||
user_turn_avatar = "!avatar({})".format(self.players[self.turn])
|
self.current_messages.append('It\'s **{}**\'s ({}) turn.'.format(
|
||||||
self.current_messages.append('{} It\'s **{}**\'s ({}) turn.'.format(
|
|
||||||
user_turn_avatar,
|
|
||||||
self.gameAdapter.get_username_by_email(self.players[self.turn]),
|
self.gameAdapter.get_username_by_email(self.players[self.turn]),
|
||||||
self.gameAdapter.gameMessageHandler.get_player_color(self.turn)
|
self.gameAdapter.gameMessageHandler.get_player_color(self.turn)
|
||||||
))
|
))
|
||||||
|
@ -931,9 +920,8 @@ class GameInstance:
|
||||||
elif winner.startswith('except:'):
|
elif winner.startswith('except:'):
|
||||||
loser = winner.lstrip('except:')
|
loser = winner.lstrip('except:')
|
||||||
else:
|
else:
|
||||||
winner_avatar = "!avatar({})".format(winner)
|
|
||||||
winner_name = self.gameAdapter.get_username_by_email(winner)
|
winner_name = self.gameAdapter.get_username_by_email(winner)
|
||||||
self.broadcast('{} **{}** won! :tada:'.format(winner_avatar, winner_name))
|
self.broadcast('**{}** won! :tada:'.format(winner_name))
|
||||||
for u in self.players:
|
for u in self.players:
|
||||||
values = {'total_games': 1, 'games_won': 0,
|
values = {'total_games': 1, 'games_won': 0,
|
||||||
'games_lost': 0, 'games_drawn': 0}
|
'games_lost': 0, 'games_drawn': 0}
|
||||||
|
|
Loading…
Reference in a new issue