From 393f76f0f47adb57c327b744acceb5565d4bfd0d Mon Sep 17 00:00:00 2001 From: jona605a Date: Tue, 4 Aug 2020 10:52:31 +0200 Subject: [PATCH] :pencil: Run hex --- Gwendolyn.py | 4 +-- gameLoops.py | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) diff --git a/Gwendolyn.py b/Gwendolyn.py index bec6f44..1771bcf 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -12,7 +12,7 @@ import os from funcs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, emojiToNumber, fiarReactionTest, deleteGame, stopServer, checkBalance, giveMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, spellFunc, monsterFunc, nameGen, tavernGen, movieFunc, roll_dice, parseChar, parseRoll, critRoll, parseDestiny -from gameLoops import fiar, blackjackLoop +from gameLoops import fiar, blackjackLoop, runhex commandPrefix = "!" @@ -566,7 +566,7 @@ async def parseCommands(message,content): elif content.startswith("hex"): try: command = content.replace("hex","") - await hex(message.channel,command,message.author.display_name) + await runhex(message.channel,command,message.author.display_name) except: logThis("Something went wrong (error code 1500)") diff --git a/gameLoops.py b/gameLoops.py index 932eb27..a0eb94b 100644 --- a/gameLoops.py +++ b/gameLoops.py @@ -17,6 +17,80 @@ async def deleteMessage(imageLocation,channel): return oldImage +# Runs Hex +async def runhex(channel,command,user): + try: + response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel),user) + except: + logThis("Error parsing command (error code 1510)") + + await channel.send(response) + logThis(response,str(channel)) + if showImage: + if deleteImage: + try: + oldImage = await deleteMessage("hex"+str(channel),channel) + except: + logThis("Error deleting old image (error code 1501)") + oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel)+".png")) + if gameDone == False: + if gwendoTurn: + try: + response, showImage, deleteImage, gameDone, gwendoTurn = hexAI(str(channel)) + except: + logThis("AI error (error code 1420)") + 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: + reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"] + for reaction in reactions: + await oldImage.add_reaction(reaction) + + 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: + reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"] + for reaction in reactions: + await oldImage.add_reaction(reaction) + 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)) + + if gameDone: + with open("resources/games/games.json", "r") as f: + data = json.load(f) + + try: + with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f: + oldImage = await channel.fetch_message(int(f.read())) + + await oldImage.delete() + except: + logThis("The old image was already deleted") + + winner = data["4 in a row games"][str(channel)]["winner"] + if winner != 0: + 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) + + deleteGame("4 in a row games",str(channel)) + + + # Runs Four in a Row async def fiar(channel,command,user): try: