diff options
author | 2021-07-08 16:03:20 -0400 | |
---|---|---|
committer | 2021-07-09 14:01:21 -0400 | |
commit | c87cf2c2189609a314bd38de9c9a153c880fa99f (patch) | |
tree | 9a093979129c61e1512c1470ce2a741ba75869d0 /bot/exts/evergreen/duck_game.py | |
parent | Fix card labels not appearing (diff) |
Add function to end the game
Diffstat (limited to 'bot/exts/evergreen/duck_game.py')
-rw-r--r-- | bot/exts/evergreen/duck_game.py | 28 |
1 files changed, 27 insertions, 1 deletions
diff --git a/bot/exts/evergreen/duck_game.py b/bot/exts/evergreen/duck_game.py index 1f41e500..55a57bb6 100644 --- a/bot/exts/evergreen/duck_game.py +++ b/bot/exts/evergreen/duck_game.py @@ -244,7 +244,33 @@ class DuckGamesDirector(commands.Cog): async def end_game(self, game: DuckGame, end_message: str) -> None: """Edit the game embed to reflect the end of the game and mark the game as not running.""" - pass + game.running = False + + scores = sorted( + game.scores.items(), + key=lambda item: item[1] + ) + scoreboard = "\n".join(f"{member.display_name}: {score}" for member, score in scores) + + missed = [ans for ans in game.solutions if ans not in game.claimed_answers] + if missed: + missed_text = "Flights everyone missed:\n" + "\n".join(f"{ans}" for ans in missed) + else: + missed_text = "All the flights were found!" + + game_embed, = game.embed_msg.embeds + old_footer = game_embed.footer.text + if old_footer == discord.Embed.Empty: + old_footer = "" + + embed_as_dict = game_embed.to_dict() # Cannot set embed color after initialization + embed_as_dict["color"] = Colours.soft_red + game_embed = discord.Embed.from_dict(embed_as_dict) + + game_embed.set_footer( + text=f"{old_footer.rstrip()}\n\n{end_message} Here are the scores:\n{scoreboard}\n\n{missed_text}" + ) + await edit_embed_with_image(game.embed_msg, game_embed) def setup(bot: Bot) -> None: |