✨ Four in a row is almost done
This commit is contained in:
72
Gwendolyn.py
72
Gwendolyn.py
@ -592,29 +592,8 @@ async def parseCommands(message,content):
|
||||
|
||||
# Runs a game of four in a row
|
||||
elif content.startswith("fourinarow"):
|
||||
response, showImage, deleteImage, gameDone = parseFourInARow(content.replace("fourinarow",""),str(message.channel),message.author.display_name)
|
||||
await message.channel.send(response)
|
||||
logThis(response,str(message.channel))
|
||||
if showImage:
|
||||
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))
|
||||
|
||||
if gameDone:
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
del data["4 in a row games"][str(message.channel)]
|
||||
|
||||
with open("resources/games/games.json","w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
command = content.replace("fourinarow","")
|
||||
await fiar(message.channel,command,message.author.display_name)
|
||||
|
||||
|
||||
|
||||
@ -623,6 +602,42 @@ async def parseCommands(message,content):
|
||||
logThis("That's not a command (error code 001)",str(message.channel))
|
||||
await message.channel.send("That's not a command (error code 001)")
|
||||
|
||||
async def fiar(channel,command,user):
|
||||
response, showImage, deleteImage, gameDone = parseFourInARow(command,str(channel),user)
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
try:
|
||||
logThis("Finding old image")
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
logThis("Deleting old image")
|
||||
await oldImage.delete()
|
||||
except:
|
||||
oldImage = ""
|
||||
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png"))
|
||||
if gameDone == False:
|
||||
await oldImage.add_reaction("1️⃣")
|
||||
await oldImage.add_reaction("2️⃣")
|
||||
await oldImage.add_reaction("3️⃣")
|
||||
await oldImage.add_reaction("4️⃣")
|
||||
await oldImage.add_reaction("5️⃣")
|
||||
await oldImage.add_reaction("6️⃣")
|
||||
await oldImage.add_reaction("7️⃣")
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
|
||||
if gameDone:
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
del data["4 in a row games"][str(channel)]
|
||||
|
||||
with open("resources/games/games.json","w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
|
||||
|
||||
# Makes files if they don't exist yet
|
||||
makeFiles()
|
||||
|
||||
@ -657,5 +672,16 @@ async def on_message(message):
|
||||
emoji = random.choice(["😠", "🖕", "👎"])
|
||||
await message.add_reaction(emoji)
|
||||
|
||||
@client.event
|
||||
async def on_reaction_add(reaction,user):
|
||||
message = reaction.message
|
||||
channel = message.channel
|
||||
logThis(user.display_name+" reacted to a message",str(channel))
|
||||
fourInARowTheirTurn, piece = fiarReactionTest(channel,message,user.display_name)
|
||||
|
||||
if fourInARowTheirTurn:
|
||||
place = emojiToNumber(reaction.emoji)
|
||||
await fiar(channel," place "+str(piece)+" "+str(place),user.display_name)
|
||||
|
||||
# Runs the whole shabang
|
||||
client.run(token)
|
||||
|
Reference in New Issue
Block a user