From e0eab627fe4c539c7a6e001e89ba497938549d6d Mon Sep 17 00:00:00 2001 From: NikolajDanger Date: Thu, 19 Aug 2021 19:59:46 +0200 Subject: [PATCH] :bug: small change in order of operations --- gwendolyn/funcs/games/connect_four.py | 17 ++++++----------- gwendolyn/funcs/games/hangman.py | 22 ++++++++++------------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/gwendolyn/funcs/games/connect_four.py b/gwendolyn/funcs/games/connect_four.py index 4e1938a..6dcb726 100644 --- a/gwendolyn/funcs/games/connect_four.py +++ b/gwendolyn/funcs/games/connect_four.py @@ -167,14 +167,13 @@ class ConnectFour(): log_message = "They started a game" self.bot.log(log_message) + await ctx.send(send_message) # Sets the whole game in motion if started_game: boards_path = "gwendolyn/resources/games/connect_four_boards/" file_path = f"{boards_path}board{ctx.channel_id}.png" - image_message = await ctx.send( - send_message, file=discord.File(file_path) - ) + image_message = await ctx.send(file=discord.File(file_path)) board_string = self._encode_board_string(board) if gwendolyn_turn: @@ -229,8 +228,6 @@ class ConnectFour(): await image_message.edit( components=action_rows ) - else: - await ctx.send(send_message) async def place_piece(self, ctx: ComponentContext, board_string: str, column: int, players: list[int], difficulty: int, @@ -242,6 +239,8 @@ class ConnectFour(): column: int The column the player is placing the piece in. """ + old_message = await ctx.channel.fetch_message(message_id) + await old_message.delete() player_number = players.index(placer)+1 user_name = self.get_name(f"#{placer}") @@ -286,6 +285,7 @@ class ConnectFour(): placed_piece = True self.bot.log(log_message) + await ctx.channel.send(send_message) if placed_piece: channel = str(ctx.channel) @@ -295,8 +295,7 @@ class ConnectFour(): boards_path = "gwendolyn/resources/games/connect_four_boards/" file_path = boards_path + f"board{channel}.png" - image_message = await ctx.channel.send( - send_message, file=discord.File(file_path)) + image_message = await ctx.channel.send(file=discord.File(file_path)) if game_won: self._end_game(winner, players, difficulty) @@ -355,11 +354,7 @@ class ConnectFour(): await image_message.edit( components=action_rows ) - else: - await ctx.channel.send(send_message) - old_message = await ctx.channel.fetch_message(message_id) - await old_message.delete() async def surrender(self, ctx: ComponentContext, players: list, difficulty: int, message_id: int): diff --git a/gwendolyn/funcs/games/hangman.py b/gwendolyn/funcs/games/hangman.py index 0b93d11..83c3dfe 100644 --- a/gwendolyn/funcs/games/hangman.py +++ b/gwendolyn/funcs/games/hangman.py @@ -92,11 +92,11 @@ class Hangman(): send_message = f"{ctx.author.display_name} started a game of hangman." self.bot.log("Game started") + await ctx.send(send_message) boards_path = "gwendolyn/resources/games/hangman_boards/" file_path = f"{boards_path}hangman_board{game_id}.png" - image_message = await ctx.send( - send_message, + image_message = await ctx.channel.send( file=discord.File(file_path) ) @@ -165,6 +165,10 @@ class Hangman(): The context of the command. """ + for msg_id in messages: + msg = await ctx.channel.fetch_message(msg_id) + await msg.delete() + self.bot.log("Deleting old messages") await ctx.channel.send("Hangman game stopped") @@ -172,10 +176,6 @@ class Hangman(): file_path = f"{boards_path}hangman_board{game_id}.png" os.remove(file_path) - for msg_id in messages: - msg = await ctx.channel.fetch_message(msg_id) - await msg.delete() - async def guess(self, ctx: ComponentContext, guess: str, word: str, guessed_letters: str, game_id: str, *messages: list[str]): """ @@ -190,6 +190,9 @@ class Hangman(): guess: str The guess. """ + for msg_id in messages: + msg = await ctx.channel.fetch_message(msg_id) + await msg.delete() misses = 0 guessed_letters += guess @@ -228,10 +231,10 @@ class Hangman(): if remaining_letters != []: + await ctx.channel.send(send_message) boards_path = "gwendolyn/resources/games/hangman_boards/" file_path = f"{boards_path}hangman_board{game_id}.png" image_message = await ctx.channel.send( - send_message, file=discord.File(file_path) ) blank_message_one = await ctx.channel.send("_ _") @@ -291,11 +294,6 @@ class Hangman(): os.remove(file_path) - for msg_id in messages: - msg = await ctx.channel.fetch_message(msg_id) - await msg.delete() - -