🐛 small change in order of operations

This commit is contained in:
NikolajDanger
2021-08-19 19:59:46 +02:00
parent b8a2f6022e
commit e0eab627fe
2 changed files with 16 additions and 23 deletions

View File

@ -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):

View File

@ -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()