✨ Four in a row "AI"
This commit is contained in:
139
Gwendolyn.py
139
Gwendolyn.py
@ -21,6 +21,83 @@ blackjackDecks = 4
|
||||
# Variable for reacting to messages
|
||||
meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
|
||||
|
||||
# Runs Four in a Row
|
||||
async def fiar(channel,command,user):
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel),user)
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
oldImage = await deleteMessage("fourInARow"+str(channel),channel)
|
||||
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png"))
|
||||
if gameDone == False:
|
||||
if gwendoTurn:
|
||||
await asyncio.sleep(2)
|
||||
response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel))
|
||||
await channel.send(response)
|
||||
logThis(response,str(channel))
|
||||
if showImage:
|
||||
if deleteImage:
|
||||
await oldImage.delete()
|
||||
oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png"))
|
||||
if gameDone == False:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
try:
|
||||
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️⃣")
|
||||
except:
|
||||
logThis("Image deleted before I could react to all of them")
|
||||
|
||||
else:
|
||||
with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f:
|
||||
f.write(str(oldImage.id))
|
||||
try:
|
||||
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️⃣")
|
||||
except:
|
||||
logThis("Image deleted before I could react to all of them")
|
||||
|
||||
if gameDone:
|
||||
with open("resources/games/games.json", "r") as f:
|
||||
data = json.load(f)
|
||||
|
||||
winner = data["4 in a row games"][str(channel)]["winner"]
|
||||
if winner != 0:
|
||||
with open("resources/games/games.json","w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),20)
|
||||
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)
|
||||
|
||||
# Deletes a message
|
||||
async def deleteMessage(imageLocation,channel):
|
||||
try:
|
||||
logThis("Finding old image")
|
||||
with open("resources/games/oldImages/"+imageLocation, "r") as f:
|
||||
oldImage = await channel.fetch_message(int(f.read()))
|
||||
logThis("Deleting old image")
|
||||
await oldImage.delete()
|
||||
except:
|
||||
oldImage = ""
|
||||
|
||||
return oldImage
|
||||
|
||||
# Loop of game rounds
|
||||
async def blackjackLoop(channel,gameRound,gameID):
|
||||
logThis("Loop "+str(gameRound),str(channel))
|
||||
@ -418,7 +495,7 @@ async def parseCommands(message,content):
|
||||
cardsLeft = 0
|
||||
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
||||
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
|
||||
for line in f:
|
||||
for _ in f:
|
||||
cardsLeft += 1
|
||||
|
||||
# Shuffles if not enough cards
|
||||
@ -581,7 +658,7 @@ async def parseCommands(message,content):
|
||||
cardsLeft = 0
|
||||
if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"):
|
||||
with open("resources/games/blackjackCards/"+str(message.channel)+".txt","r") as f:
|
||||
for line in f:
|
||||
for _ in f:
|
||||
cardsLeft += 1
|
||||
|
||||
decksLeft = round(cardsLeft/52,1)
|
||||
@ -602,49 +679,6 @@ 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)
|
||||
|
||||
winner = data["4 in a row games"][str(channel)]["winner"]
|
||||
if winner != 0:
|
||||
with open("resources/games/games.json","w") as f:
|
||||
json.dump(data,f,indent=4)
|
||||
addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),20)
|
||||
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()
|
||||
@ -682,14 +716,15 @@ async def on_message(message):
|
||||
|
||||
@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 user.bot == False:
|
||||
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)
|
||||
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