Four in a row deletes old images

This commit is contained in:
NikolajDanger
2020-07-30 12:10:10 +02:00
parent c6a7f35602
commit 2c01464157
2 changed files with 14 additions and 5 deletions

View File

@ -575,11 +575,20 @@ async def parseCommands(message,content):
# Runs a game of four in a row
elif content.startswith("fourinarow"):
response, showImage = parseFourInARow(content.replace("fourinarow",""),str(message.channel),message.author.display_name)
response, showImage, deleteImage = parseFourInARow(content.replace("fourinarow",""),str(message.channel),message.author.display_name)
await message.channel.send(response)
logThis(response,str(message.channel))
if showImage:
await message.channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(message.channel)+".png"))
if deleteImage:
try:
with open("resources/games/oldImages/fourInARow"+str(message.channel), "r") as f:
oldImage = await message.channel.fetch_message(int(f.read()))
await oldImage.delete()
except:
oldImage = ""
oldImage = await message.channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(message.channel)+".png"))
with open("resources/games/oldImages/fourInARow"+str(message.channel), "w") as f:
f.write(str(oldImage.id))
# Not a command
else:

View File

@ -59,8 +59,8 @@ def parseFourInARow(command, channel, user):
elif command.startswith(" place"):
commands = command.split(" ")
try:
return placePiece(channel,int(commands[2]),int(commands[3])-1)
return placePiece(channel,int(commands[2]),int(commands[3])-1), True
except:
return "I didn't quite get that", False
return "I didn't quite get that", False, True
else:
return "I didn't get that", False
return "I didn't get that", False, True