diff --git a/Gwendolyn.py b/Gwendolyn.py index 03e7b37..cd26e35 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -34,26 +34,26 @@ async def parseCommands(message,content): em = discord.Embed(title = "Help", description = text,colour = 0x59f442) await message.channel.send(embed = em) except: - logThis("Couldn't find help.txt (error code 101)",str(message.channel)) + logThis("Couldn't find help.txt (error code 101)",str(message.channel.id)) await message.channel.send("Couldn't find help.txt (error code 101)") else: command = content.replace(" ","-") - logThis("Looking for "+command+".txt",str(message.channel)) + logThis("Looking for "+command+".txt",str(message.channel.id)) try: with codecs.open("resources/help/"+command+".txt",encoding="utf-8") as f: text = f.read() em = discord.Embed(title = command.replace("help-","").capitalize(), description = text,colour = 0x59f442) await message.channel.send(embed = em) except: - logThis("Couldn't find help for that command (error code 102)",str(message.channel)) + logThis("Couldn't find help for that command (error code 102)",str(message.channel.id)) await message.channel.send("Couldn't find help for that command (error code 102)") except: - logThis("Something fucked up (error code 100)",str(message.channel)) + logThis("Something fucked up (error code 100)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 100)") # Logs whatever you write in the message elif content.startswith("log "): - logThis(content.replace("log ",""),str(message.channel)) + logThis(content.replace("log ",""),str(message.channel.id)) # Stops the bot elif content.startswith("stop"): @@ -65,10 +65,10 @@ async def parseCommands(message,content): await client.logout() else: - logThis(message.author.display_name+" tried to run stop me! (error code 201)",str(message.channel)) + logThis(message.author.display_name+" tried to run stop me! (error code 201)",str(message.channel.id)) await message.channel.send("I don't think I will, "+message.author.display_name+" (error code 201)") except: - logThis("Something fucked up (error code 200)",str(message.channel)) + logThis("Something fucked up (error code 200)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 200)") # Does a hello with the helloFunc function from funcs/gwendolynpy @@ -76,7 +76,7 @@ async def parseCommands(message,content): try: await message.channel.send(helloFunc(message.author.display_name)) except: - logThis("Something fucked up (error code 310)",str(message.channel)) + logThis("Something fucked up (error code 310)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 310)") # Rolls dice with the roll_dice function from funcs/roll/dice.py @@ -87,7 +87,7 @@ async def parseCommands(message,content): else: await message.channel.send(roll_dice(message.author.display_name, content.replace("roll",""))) except: - logThis("Something fucked up (error code 400)",str(message.channel)) + logThis("Something fucked up (error code 400)",str(message.channel.id)) await message.channel.send("Not a valid command (error code 400)") # Looks up a spell with the spellFunc function from funcs/lookup/lookuppy @@ -100,7 +100,7 @@ async def parseCommands(message,content): else: await message.channel.send(spell) except: - logThis("Something fucked up (error code 500)",str(message.channel)) + logThis("Something fucked up (error code 500)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 500)") # Looks up a monster with the monsterFuncs() from funcs/lookup/lookuppy @@ -149,7 +149,7 @@ async def parseCommands(message,content): em5_2 = discord.Embed(title = "", description = text5[2048:], colour=0xDEADBF) await message.channel.send(embed = em5_2) except: - logThis("Something fucked up (error code 600)",str(message.channel)) + logThis("Something fucked up (error code 600)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 600)") # Sends an image of the Senkulpa map @@ -157,7 +157,7 @@ async def parseCommands(message,content): try: await message.channel.send("https://i.imgur.com/diMXXJs.jpg") except: - logThis("Something fucked up (error code 320)",str(message.channel)) + logThis("Something fucked up (error code 320)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 320)") # Finds a random image on the internet with the imageFuncs function from @@ -167,7 +167,7 @@ async def parseCommands(message,content): randomImage = imageFunc() await message.channel.send(randomImage) except: - logThis("Something fucked up (error code 700)",str(message.channel)) + logThis("Something fucked up (error code 700)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 700)") # Sends information about a random movie with the movieFunc function from @@ -187,7 +187,7 @@ async def parseCommands(message,content): except: logThis("Error embedding (error code 805)") except: - logThis("Something fucked up (error code 800)",str(message.channel)) + logThis("Something fucked up (error code 800)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 800)") # Generates a random name with the nameGen function from funcs/other/generators.py @@ -195,7 +195,7 @@ async def parseCommands(message,content): try: await message.channel.send(nameGen()) except: - logThis("Something fucked up (error code 330)",str(message.channel)) + logThis("Something fucked up (error code 330)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 330)") # Generates a random tavern name with the tavernGen function from funcs/other/generators.py @@ -203,7 +203,7 @@ async def parseCommands(message,content): try: await message.channel.send(tavernGen()) except: - logThis("Something fucked up (error code 340)",str(message.channel)) + logThis("Something fucked up (error code 340)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 340)") # Changes the "Playing this game" thing in Discord @@ -213,7 +213,7 @@ async def parseCommands(message,content): game = discord.Game(gamePlaying) await client.change_presence(activity=game) except: - logThis("Something fucked up (error code 350)",str(message.channel)) + logThis("Something fucked up (error code 350)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 350)") # Rolls star wars dice with the parseRoll function from funcs/swfuncs/swroll.py @@ -225,7 +225,7 @@ async def parseCommands(message,content): for messageItem in messageList: await message.channel.send(messageItem) except: - logThis("Something fucked up (error code 910)",str(message.channel)) + logThis("Something fucked up (error code 910)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 910)") # Deals with Destiny Points and stuff @@ -237,7 +237,7 @@ async def parseCommands(message,content): for messageItem in messageList: await message.channel.send(messageItem) except: - logThis("Something fucked up (error code 920)",str(message.channel)) + logThis("Something fucked up (error code 920)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 920)") # Rolls for critical injuries @@ -251,14 +251,14 @@ async def parseCommands(message,content): try: newMessage = critRoll(int(command)) except: - logThis("They didn't include a number (error code 931)",str(message.channel)) + logThis("They didn't include a number (error code 931)",str(message.channel.id)) newMessage = "Try using a number, stupid (error code 931)" messageList = newMessage.split("\n") for messageItem in messageList: await message.channel.send(messageItem) except: - logThis("Something fucked up (error code 930)",str(message.channel)) + logThis("Something fucked up (error code 930)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 930)") # Accesses and changes character sheet data with the parseChar function @@ -273,7 +273,7 @@ async def parseCommands(message,content): else: await message.channel.send(desc) except: - logThis("Something fucked up (error code 940)",str(message.channel)) + logThis("Something fucked up (error code 940)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 940)") @@ -284,7 +284,7 @@ async def parseCommands(message,content): command = string.capwords(content.replace("wiki ","")) title, content, thumbnail = findWikiPage(command) if title != "": - logThis("Sending the embedded message",str(message.channel)) + logThis("Sending the embedded message",str(message.channel.id)) content += "\n[Læs mere](https://senkulpa.fandom.com/da/wiki/"+title.replace(" ","_")+")" embed = discord.Embed(title = title, description = content, colour=0xDEADBF) if thumbnail != "": @@ -294,7 +294,7 @@ async def parseCommands(message,content): else: await message.channel.send(content) except: - logThis("Something fucked up (error code 1000)",str(message.channel)) + logThis("Something fucked up (error code 1000)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 1000)") @@ -302,7 +302,7 @@ async def parseCommands(message,content): elif content.startswith("trivia"): try: if content == "trivia" or content == "trivia ": - question, answers, correctAnswer = triviaStart(str(message.channel)) + question, answers, correctAnswer = triviaStart(str(message.channel.id)) if answers != "": results = "**"+question+"**\n" for answer in range(len(answers)): @@ -312,27 +312,27 @@ async def parseCommands(message,content): await asyncio.sleep(60) - triviaCountPoints(str(message.channel)) + triviaCountPoints(str(message.channel.id)) - deleteGame("trivia questions",str(message.channel)) + deleteGame("trivia questions",str(message.channel.id)) - logThis("Time's up for the trivia question",str(message.channel)) + logThis("Time's up for the trivia question",str(message.channel.id)) await message.channel.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck") else: await message.channel.send(question) elif content.startswith("trivia "): command = content.replace("trivia ","") - response = triviaAnswer("#"+str(message.author.id),str(message.channel),command) + response = triviaAnswer("#"+str(message.author.id),str(message.channel.id),command) if response.startswith("Locked in "): await message.add_reaction("👍") else: await message.channel.send(response) else: - logThis("I didn't understand that (error code 1101)",str(message.channel)) + logThis("I didn't understand that (error code 1101)",str(message.channel.id)) await message.channel.send("I didn't understand that (error code 1101)") except: - logThis("Something fucked up (error code 1100)",str(message.channel)) + logThis("Something fucked up (error code 1100)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 1100)") @@ -346,7 +346,7 @@ async def parseCommands(message,content): new_message = message.author.display_name + " has " + str(response) + " GwendoBucks" await message.channel.send(new_message) except: - logThis("Something fucked up (error code 1210)",str(message.channel)) + logThis("Something fucked up (error code 1210)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 1210)") # Gives money to other player @@ -357,16 +357,16 @@ async def parseCommands(message,content): try: amount = int(commands[2]) except: - logThis("Conversion error (error code 1221)",str(message.channel)) + logThis("Conversion error (error code 1221)",str(message.channel.id)) await message.channel.send("I didn't quite understand that (error code 1221)") else: response = giveMoney("#"+str(message.author.id),commands[1],amount) await message.channel.send(response) else: - logThis("I didn't understand that (error code 1222)",str(message.channel)) + logThis("I didn't understand that (error code 1222)",str(message.channel.id)) await message.channel.send("I didn't understand that (error code 1222)") except: - logThis("Something fucked up (error code 1220)",str(message.channel)) + logThis("Something fucked up (error code 1220)",str(message.channel.id)) await message.channel.send("Something fucked up (error code 1220)") # Runs a game of Blackjack @@ -375,25 +375,25 @@ async def parseCommands(message,content): # Starts the game if content == "blackjack" or content == "blackjack ": 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: + if os.path.exists("resources/games/blackjackCards/"+str(message.channel.id)+".txt"): + with open("resources/games/blackjackCards/"+str(message.channel.id)+".txt","r") as f: for _ in f: cardsLeft += 1 # Shuffles if not enough cards if cardsLeft < blackjackMinCards: - blackjackShuffle(blackjackDecks,str(message.channel)) - logThis("Shuffling the blackjack deck...",str(message.channel)) + blackjackShuffle(blackjackDecks,str(message.channel.id)) + logThis("Shuffling the blackjack deck...",str(message.channel.id)) await message.channel.send("Shuffling the deck...") - new_message = blackjackStart(str(message.channel)) + new_message = blackjackStart(str(message.channel.id)) if new_message == "started": new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds." await message.channel.send(new_message) - oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel)+".png")) + oldImage = await message.channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(message.channel.id)+".png")) - with open("resources/games/oldImages/blackjack"+str(message.channel), "w") as f: + with open("resources/games/oldImages/blackjack"+str(message.channel.id), "w") as f: f.write(str(oldImage.id)) await asyncio.sleep(30) @@ -402,17 +402,17 @@ async def parseCommands(message,content): with open("resources/games/games.json", "r") as f: data = json.load(f) - if len(data["blackjack games"][str(message.channel)]["user hands"]) == 0: + if len(data["blackjack games"][str(message.channel.id)]["user hands"]) == 0: gamedone = True await message.channel.send("No one entered the game. Ending the game.") - gameID = data["blackjack games"][str(message.channel)]["id"] + gameID = data["blackjack games"][str(message.channel.id)]["id"] # Loop of game rounds if gamedone == False: - logThis("!blackjack calling blackjackLoop()",str(message.channel)) + logThis("!blackjack calling blackjackLoop()",str(message.channel.id)) await blackjackLoop(message.channel,1,gameID) else: - new_message = blackjackFinish(str(message.channel)) + new_message = blackjackFinish(str(message.channel.id)) await message.channel.send(new_message) else: await message.channel.send(new_message) @@ -423,34 +423,34 @@ async def parseCommands(message,content): try: amount = int(commands[2]) except: - logThis("I didn't understand that",str(message.channel)) + logThis("I didn't understand that",str(message.channel.id)) response = "I didn't understand that" else: - response = blackjackPlayerDrawHand(str(message.channel),"#"+str(message.author.id),amount) + response = blackjackPlayerDrawHand(str(message.channel.id),"#"+str(message.author.id),amount) await message.channel.send(response) # Hitting elif content.startswith("blackjack hit"): if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackHit(str(message.channel),"#"+str(message.author.id)) + response = blackjackHit(str(message.channel.id),"#"+str(message.author.id)) else: commands = content.split(" ") try: handNumber = int(commands[2]) except: handNumber = 0 - response = blackjackHit(str(message.channel),"#"+str(message.author.id),handNumber) + response = blackjackHit(str(message.channel.id),"#"+str(message.author.id),handNumber) if response.startswith("accept"): await message.add_reaction("👍") try: if response[6] == "T": with open("resources/games/games.json", "r") as f: - gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Hit calling blackjackLoop()",str(message.channel)) + gameID = json.load(f)["blackjack games"][str(message.channel.id)]["id"] + logThis("Hit calling blackjackLoop()",str(message.channel.id)) await blackjackLoop(message.channel,int(response[7:])+1,gameID) except: - logThis("Something fucked up (error code 1320)",str(message.channel)) + logThis("Something fucked up (error code 1320)",str(message.channel.id)) else: await message.channel.send(response) @@ -458,25 +458,25 @@ async def parseCommands(message,content): # Standing elif content.startswith("blackjack stand"): if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackStand(str(message.channel),"#"+str(message.author.id)) + response = blackjackStand(str(message.channel.id),"#"+str(message.author.id)) else: commands = content.split(" ") try: handNumber = int(commands[2]) except: handNumber = 0 - response = blackjackStand(str(message.channel),"#"+str(message.author.id),handNumber) + response = blackjackStand(str(message.channel.id),"#"+str(message.author.id),handNumber) if response.startswith("accept"): await message.add_reaction("👍") try: if response[6] == "T": with open("resources/games/games.json", "r") as f: - gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Stand calling blackjackLoop()",str(message.channel)) + gameID = json.load(f)["blackjack games"][str(message.channel.id)]["id"] + logThis("Stand calling blackjackLoop()",str(message.channel.id)) await blackjackLoop(message.channel,int(response[7:])+1,gameID) except: - logThis("Something fucked up (error code 1320)",str(message.channel)) + logThis("Something fucked up (error code 1320)",str(message.channel.id)) else: await message.channel.send(response) @@ -487,18 +487,18 @@ async def parseCommands(message,content): handNumber = int(commands[2]) except: handNumber = 0 - response, roundDone = blackjackDouble(str(message.channel),"#"+str(message.author.id),handNumber) + response, roundDone = blackjackDouble(str(message.channel.id),"#"+str(message.author.id),handNumber) await message.channel.send(response) try: if roundDone[0] == "T": with open("resources/games/games.json", "r") as f: - gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Double calling blackjackLoop()",str(message.channel)) + gameID = json.load(f)["blackjack games"][str(message.channel.id)]["id"] + logThis("Double calling blackjackLoop()",str(message.channel.id)) await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID) except: - logThis("Something fucked up (error code 1320)",str(message.channel)) + logThis("Something fucked up (error code 1320)",str(message.channel.id)) # Splitting hand elif content.startswith("blackjack split"): @@ -507,23 +507,23 @@ async def parseCommands(message,content): handNumber = int(commands[2]) except: handNumber = 0 - response, roundDone = blackjackSplit(str(message.channel),"#"+str(message.author.id),handNumber) + response, roundDone = blackjackSplit(str(message.channel.id),"#"+str(message.author.id),handNumber) await message.channel.send(response) try: if roundDone[0] == "T": with open("resources/games/games.json", "r") as f: - gameID = json.load(f)["blackjack games"][str(message.channel)]["id"] - logThis("Split calling blackjackLoop()",str(message.channel)) + gameID = json.load(f)["blackjack games"][str(message.channel.id)]["id"] + logThis("Split calling blackjackLoop()",str(message.channel.id)) await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID) except: logThis("Something fucked up (error code 1320)") # Returning current hi-lo value elif content.startswith("blackjack hilo") and "#"+str(message.author.id) == "#266269899859427329": - if os.path.exists("resources/games/blackjackCards/"+str(message.channel)+".txt"): - with open("resources/games/hilo/"+str(message.channel)+".txt", "r") as f: + if os.path.exists("resources/games/blackjackCards/"+str(message.channel.id)+".txt"): + with open("resources/games/hilo/"+str(message.channel.id)+".txt", "r") as f: data = f.read() else: data = "0" @@ -531,16 +531,16 @@ async def parseCommands(message,content): # Shuffles the blackjack deck elif content.startswith("blackjack shuffle"): - blackjackShuffle(blackjackDecks,str(message.channel)) - logThis("Shuffling the blackjack deck...",str(message.channel)) + blackjackShuffle(blackjackDecks,str(message.channel.id)) + logThis("Shuffling the blackjack deck...",str(message.channel.id)) await message.channel.send("Shuffling the deck...") # Tells you the amount of cards left elif content.startswith("blackjack cards"): 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: + if os.path.exists("resources/games/blackjackCards/"+str(message.channel.id)+".txt"): + with open("resources/games/blackjackCards/"+str(message.channel.id)+".txt","r") as f: for _ in f: cardsLeft += 1 @@ -579,7 +579,7 @@ async def parseCommands(message,content): # Not a command else: - logThis("That's not a command (error code 001)",str(message.channel)) + logThis("That's not a command (error code 001)",str(message.channel.id)) await message.channel.send("That's not a command (error code 001)") # Makes files if they don't exist yet @@ -604,7 +604,7 @@ async def on_message(message): try: content = message.content if content.startswith(commandPrefix): - logThis(message.author.display_name+" ("+"#"+str(message.author.id)+") ran \""+content+"\"",str(message.channel)) + logThis(message.author.display_name+" ("+"#"+str(message.author.id)+") ran \""+content+"\"",str(message.channel.id)) addToDict("#"+str(message.author.id),message.author.display_name) await parseCommands(message,content.lower()[1:]) except: @@ -613,7 +613,7 @@ async def on_message(message): # Is a bit sassy sometimes if ("gwendolyn" in message.content.lower() or message.content.startswith(commandPrefix)) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower(): - logThis(message.author.display_name+" was a bit mean",str(message.channel)) + logThis(message.author.display_name+" was a bit mean",str(message.channel.id)) emoji = random.choice(["😠", "🖕", "👎"]) await message.add_reaction(emoji) @@ -622,7 +622,7 @@ async def on_reaction_add(reaction,user): if user.bot == False: message = reaction.message channel = message.channel - logThis(user.display_name+" reacted to a message",str(channel)) + logThis(user.display_name+" reacted to a message",str(channel.id)) try: fourInARowTheirTurn, piece = fiarReactionTest(channel,message,"#"+str(user.id)) except: diff --git a/funcs/miscFuncs.py b/funcs/miscFuncs.py index 0546f0a..cf528c8 100644 --- a/funcs/miscFuncs.py +++ b/funcs/miscFuncs.py @@ -209,13 +209,13 @@ def fiarReactionTest(channel,message,user): with open("resources/games/games.json", "r") as f: data = json.load(f) - with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f: + with open("resources/games/oldImages/fourInARow"+str(channel.id), "r") as f: oldImage = int(f.read()) if message.id == oldImage: logThis("They reacted to the fourinarow game") - turn = data["4 in a row games"][str(channel)]["turn"] - if user == data["4 in a row games"][str(channel)]["players"][turn]: + turn = data["4 in a row games"][str(channel.id)]["turn"] + if user == data["4 in a row games"][str(channel.id)]["players"][turn]: return True, turn+1 else: logThis("It wasn't their turn") @@ -224,7 +224,7 @@ def fiarReactionTest(channel,message,user): return False, 0 def monopolyReactionTest(channel,message): - with open("resources/games/oldImages/monopoly"+str(channel), "r") as f: + with open("resources/games/oldImages/monopoly"+str(channel.id), "r") as f: oldImage = int(f.read()) if message.id == oldImage: diff --git a/gameLoops.py b/gameLoops.py index 058f033..893e737 100644 --- a/gameLoops.py +++ b/gameLoops.py @@ -20,34 +20,34 @@ async def deleteMessage(imageLocation,channel): # Runs Hex async def runHex(channel,command,user): try: - response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel),user) + response, showImage, deleteImage, gameDone, gwendoTurn = parseHex(command,str(channel.id),user) except: logThis("Error parsing command (error code 1510)") await channel.send(response) - logThis(response,str(channel)) + logThis(response,str(channel.id)) if showImage: if deleteImage: try: - oldImage = await deleteMessage("hex"+str(channel),channel) + oldImage = await deleteMessage("hex"+str(channel.id),channel) except: logThis("Error deleting old image (error code 1501)") - oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel)+".png")) + oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel.id)+".png")) if not gameDone: if gwendoTurn: try: - response, showImage, deleteImage, gameDone, gwendoTurn = hexAI(str(channel)) + response, showImage, deleteImage, gameDone, gwendoTurn = hexAI(str(channel.id)) except: logThis("AI error (error code 1520)") await channel.send(response) - logThis(response,str(channel)) + logThis(response,str(channel.id)) if showImage: if deleteImage: await oldImage.delete() - oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel)+".png")) + oldImage = await channel.send(file = discord.File("resources/games/hexBoards/board"+str(channel.id)+".png")) else: - with open("resources/games/oldImages/hex"+str(channel), "w") as f: + with open("resources/games/oldImages/hex"+str(channel.id), "w") as f: f.write(str(oldImage.id)) if gameDone: @@ -55,52 +55,52 @@ async def runHex(channel,command,user): data = json.load(f) try: - with open("resources/games/oldImages/hex"+str(channel), "r") as f: + with open("resources/games/oldImages/hex"+str(channel.id), "r") as f: oldImage = await channel.fetch_message(int(f.read())) await oldImage.delete() except: logThis("The old image was already deleted") - winner = data["hex games"][str(channel)]["winner"] + winner = data["hex games"][str(channel.id)]["winner"] if winner != 0: - addMoney(data["hex games"][str(channel)]["players"][winner-1].lower(),20) + addMoney(data["hex games"][str(channel.id)]["players"][winner-1].lower(),20) with open("resources/games/games.json", "r") as f: data = json.load(f) #why is this here? - deleteGame("hex games",str(channel)) + deleteGame("hex games",str(channel.id)) # Runs Four in a Row async def fiar(channel,command,user): try: - response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel),user) + response, showImage, deleteImage, gameDone, gwendoTurn = parseFourInARow(command,str(channel.id),user) except: logThis("Error parsing command (error code 1410)") await channel.send(response) - logThis(response,str(channel)) + logThis(response,str(channel.id)) if showImage: if deleteImage: try: - oldImage = await deleteMessage("fourInARow"+str(channel),channel) + oldImage = await deleteMessage("fourInARow"+str(channel.id),channel) except: logThis("Error deleting message (error code 1401)") - oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png")) + oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel.id)+".png")) if gameDone == False: if gwendoTurn: try: - response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel)) + response, showImage, deleteImage, gameDone, gwendoTurn = fourInARowAI(str(channel.id)) except: logThis("AI error (error code 1420)") await channel.send(response) - logThis(response,str(channel)) + logThis(response,str(channel.id)) if showImage: if deleteImage: await oldImage.delete() - oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel)+".png")) + oldImage = await channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(channel.id)+".png")) if gameDone == False: - with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f: + with open("resources/games/oldImages/fourInARow"+str(channel.id), "w") as f: f.write(str(oldImage.id)) try: reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"] @@ -111,7 +111,7 @@ async def fiar(channel,command,user): logThis("Image deleted before I could react to all of them") else: - with open("resources/games/oldImages/fourInARow"+str(channel), "w") as f: + with open("resources/games/oldImages/fourInARow"+str(channel.id), "w") as f: f.write(str(oldImage.id)) try: reactions = ["1️⃣","2️⃣","3️⃣","4️⃣","5️⃣","6️⃣","7️⃣"] @@ -125,39 +125,39 @@ async def fiar(channel,command,user): data = json.load(f) try: - with open("resources/games/oldImages/fourInARow"+str(channel), "r") as f: + with open("resources/games/oldImages/fourInARow"+str(channel.id), "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"] - difficulty = int(data["4 in a row games"][str(channel)]["difficulty"]) + winner = data["4 in a row games"][str(channel.id)]["winner"] + difficulty = int(data["4 in a row games"][str(channel.id)]["difficulty"]) reward = difficulty**2 + 5 if winner != 0: - if data["4 in a row games"][str(channel)]["players"][winner-1].lower() != "gwendolyn": - addMoney(data["4 in a row games"][str(channel)]["players"][winner-1].lower(),reward) + if data["4 in a row games"][str(channel.id)]["players"][winner-1].lower() != "gwendolyn": + addMoney(data["4 in a row games"][str(channel.id)]["players"][winner-1].lower(),reward) with open("resources/games/games.json", "r") as f: data = json.load(f) #why is this here? - deleteGame("4 in a row games",str(channel)) + deleteGame("4 in a row games",str(channel.id)) # Loop of blackjack game rounds async def blackjackLoop(channel,gameRound,gameID): - logThis("Loop "+str(gameRound),str(channel)) + logThis("Loop "+str(gameRound),str(channel.id)) - with open("resources/games/oldImages/blackjack"+str(channel), "r") as f: + with open("resources/games/oldImages/blackjack"+str(channel.id), "r") as f: oldImage = await channel.fetch_message(int(f.read())) - new_message, allStanding, gamedone = blackjackContinue(str(channel)) + new_message, allStanding, gamedone = blackjackContinue(str(channel.id)) if new_message != "": - logThis(new_message,str(channel)) + logThis(new_message,str(channel.id)) await channel.send(new_message) if gamedone == False: await oldImage.delete() - oldImage = await channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel)+".png")) - with open("resources/games/oldImages/blackjack"+str(channel), "w") as f: + oldImage = await channel.send(file = discord.File("resources/games/blackjackTables/blackjackTable"+str(channel.id)+".png")) + with open("resources/games/oldImages/blackjack"+str(channel.id), "w") as f: f.write(str(oldImage.id)) try: @@ -171,41 +171,41 @@ async def blackjackLoop(channel,gameRound,gameID): with open("resources/games/games.json", "r") as f: data = json.load(f) - if str(channel) in data["blackjack games"]: - realRound = data["blackjack games"][str(channel)]["round"] - realGameID = data["blackjack games"][str(channel)]["id"] + if str(channel.id) in data["blackjack games"]: + realRound = data["blackjack games"][str(channel.id)]["round"] + realGameID = data["blackjack games"][str(channel.id)]["id"] if gameRound == realRound and realGameID == gameID: if gamedone == False: - logThis("Loop "+str(gameRound)+" calling blackjackLoop()",str(channel)) + logThis("Loop "+str(gameRound)+" calling blackjackLoop()",str(channel.id)) await blackjackLoop(channel,gameRound+1,gameID) else: try: - new_message = blackjackFinish(str(channel)) + new_message = blackjackFinish(str(channel.id)) except: logThis("Something fucked up (error code 1310)") await channel.send(new_message) else: - logThis("Ending loop on round "+str(gameRound),str(channel)) + logThis("Ending loop on round "+str(gameRound),str(channel.id)) else: - logThis("Ending loop on round "+str(gameRound),str(channel)) + logThis("Ending loop on round "+str(gameRound),str(channel.id)) async def runMonopoly(channel, command, user): try: - response, showImage, deleteImage, gameStarted, gameContinue = parseMonopoly(command,str(channel),user) + response, showImage, deleteImage, gameStarted, gameContinue = parseMonopoly(command,str(channel.id),user) except: logThis("Error parsing command (error code 1610)") if response != "": await channel.send(response) - logThis(response,str(channel)) + logThis(response,str(channel.id)) if showImage: if deleteImage: try: - oldImage = await deleteMessage("monopoly"+str(channel),channel) + oldImage = await deleteMessage("monopoly"+str(channel.id),channel) except: logThis("Error deleting message (error code 1601)") - oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel)+".png")) - with open("resources/games/oldImages/monopoly"+str(channel), "w") as f: + oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel.id)+".png")) + with open("resources/games/oldImages/monopoly"+str(channel.id), "w") as f: f.write(str(oldImage.id)) if gameContinue: @@ -213,17 +213,17 @@ async def runMonopoly(channel, command, user): await asyncio.sleep(60) else: await asyncio.sleep(5) - response, showImage, deleteImage, gameDone = monopolyContinue(str(channel)) + response, showImage, deleteImage, gameDone = monopolyContinue(str(channel.id)) em = discord.Embed(description=response,colour = 0x59f442) await channel.send(embed=em) if showImage: if deleteImage: try: - oldImage = await deleteMessage("monopoly"+str(channel),channel) + oldImage = await deleteMessage("monopoly"+str(channel.id),channel) except: logThis("Error deleting message (error code 1601)") - oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel)+".png")) - with open("resources/games/oldImages/monopoly"+str(channel), "w") as f: + oldImage = await channel.send(file = discord.File("resources/games/monopolyBoards/monopolyBoard"+str(channel.id)+".png")) + with open("resources/games/oldImages/monopoly"+str(channel.id), "w") as f: f.write(str(oldImage.id)) if gameDone == False: try: