diff --git a/.gitignore b/.gitignore index 5effeab..d3e7cab 100644 --- a/.gitignore +++ b/.gitignore @@ -162,4 +162,5 @@ resources/lookup/monsters.json resources/lookup/spells.json resources/movies.txt resources/names.txt +resources/users.json gwendolynTest.py diff --git a/Gwendolyn.py b/Gwendolyn.py index 2174558..1a32918 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -10,7 +10,7 @@ import random #import math 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, parseHex +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, parseHex, addToDict from gameLoops import fiar, blackjackLoop, runhex @@ -58,7 +58,7 @@ async def parseCommands(message,content): # Stops the bot elif content.startswith("stop"): try: - if message.author.display_name == "Nikolaj": + if "#"+str(message.author.id) == "#266269899859427329": await message.channel.send("Logging out...") stopServer() @@ -220,7 +220,7 @@ async def parseCommands(message,content): elif content.startswith("swroll"): try: command = cap(content.replace("swroll","")) - newMessage = parseRoll(message.author.display_name,command) + newMessage = parseRoll("#"+str(message.author.id),command) messageList = newMessage.split("\n") for messageItem in messageList: await message.channel.send(messageItem) @@ -232,7 +232,7 @@ async def parseCommands(message,content): elif content.startswith("swd"): try: command = content.replace("swd","") - newMessage = parseDestiny(message.author.display_name,command) + newMessage = parseDestiny("#"+str(message.author.id),command) messageList = newMessage.split("\n") for messageItem in messageList: await message.channel.send(messageItem) @@ -266,7 +266,7 @@ async def parseCommands(message,content): elif content.startswith("swchar") or content.startswith("sw"): try: command = string.capwords(content.replace("swchar","").replace("sw","").replace("+","+ ").replace("-","- ").replace(",",", ")) - title, desc = parseChar(message.author.display_name,command) + title, desc = parseChar("#"+str(message.author.id),command) if title != "": em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF) await message.channel.send(embed = em1) @@ -323,7 +323,7 @@ async def parseCommands(message,content): elif content.startswith("trivia "): command = content.replace("trivia ","") - response = triviaAnswer(message.author.display_name.lower(),str(message.channel),command) + response = triviaAnswer("#"+str(message.author.id),str(message.channel),command) if response.startswith("Locked in "): await message.add_reaction("👍") else: @@ -339,7 +339,7 @@ async def parseCommands(message,content): # Checks your GwendoBucks balance elif content.startswith("balance"): try: - response = checkBalance(message.author.display_name.lower()) + response = checkBalance("#"+str(message.author.id)) if response == 1: new_message = message.author.display_name + " has " + str(response) + " GwendoBuck" else: @@ -360,7 +360,7 @@ async def parseCommands(message,content): logThis("Conversion error (error code 1221)",str(message.channel)) await message.channel.send("I didn't quite understand that (error code 1221)") else: - response = giveMoney(message.author.display_name.lower(),commands[1],amount) + 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)) @@ -426,20 +426,20 @@ async def parseCommands(message,content): logThis("I didn't understand that",str(message.channel)) response = "I didn't understand that" else: - response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount) + response = blackjackPlayerDrawHand(str(message.channel),"#"+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),message.author.display_name) + response = blackjackHit(str(message.channel),"#"+str(message.author.id)) else: commands = content.split(" ") try: handNumber = int(commands[2]) except: handNumber = 0 - response = blackjackHit(str(message.channel),message.author.display_name,handNumber) + response = blackjackHit(str(message.channel),"#"+str(message.author.id),handNumber) if response.startswith("accept"): await message.add_reaction("👍") @@ -458,14 +458,14 @@ async def parseCommands(message,content): # Standing elif content.startswith("blackjack stand"): if content == "blackjack hit" or content == "blackjack hit ": - response = blackjackStand(str(message.channel),message.author.display_name) + response = blackjackStand(str(message.channel),"#"+str(message.author.id)) else: commands = content.split(" ") try: handNumber = int(commands[2]) except: handNumber = 0 - response = blackjackStand(str(message.channel),message.author.display_name,handNumber) + response = blackjackStand(str(message.channel),"#"+str(message.author.id),handNumber) if response.startswith("accept"): await message.add_reaction("👍") @@ -487,7 +487,7 @@ async def parseCommands(message,content): handNumber = int(commands[2]) except: handNumber = 0 - response, roundDone = blackjackDouble(str(message.channel),message.author.display_name,handNumber) + response, roundDone = blackjackDouble(str(message.channel),"#"+str(message.author.id),handNumber) await message.channel.send(response) @@ -507,7 +507,7 @@ async def parseCommands(message,content): handNumber = int(commands[2]) except: handNumber = 0 - response, roundDone = blackjackSplit(str(message.channel),message.author.display_name,handNumber) + response, roundDone = blackjackSplit(str(message.channel),"#"+str(message.author.id),handNumber) await message.channel.send(response) @@ -521,7 +521,7 @@ async def parseCommands(message,content): logThis("Something fucked up (error code 1320)") # Returning current hi-lo value - elif content.startswith("blackjack hilo") and message.author.display_name == "Nikolaj": + 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: data = f.read() @@ -557,7 +557,7 @@ async def parseCommands(message,content): elif content.startswith("fourinarow"): try: command = content.replace("fourinarow","") - await fiar(message.channel,command,message.author.display_name) + await fiar(message.channel,command,"#"+str(message.author.id)) except: logThis("Something went wrong (error code 1400)") @@ -565,7 +565,7 @@ async def parseCommands(message,content): elif content.startswith("hex"): try: command = content.replace("hex","") - await runhex(message.channel,command,message.author.display_name) + await runhex(message.channel,command,"#"+str(message.author.id)) except: logThis("Something went wrong (error code 1500)") @@ -574,7 +574,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)") - # Makes files if they don't exist yet makeFiles() @@ -597,7 +596,8 @@ async def on_message(message): try: content = message.content if content.startswith(commandPrefix): - logThis(message.author.display_name+" ran \""+content+"\"",str(message.channel)) + logThis(message.author.display_name+" ("+"#"+str(message.author.id)+") ran \""+content+"\"",str(message.channel)) + addToDict("#"+str(message.author.id),message.author.display_name) await parseCommands(message,content.lower()[1:]) except: logThis("Something fucked up (error code 000)") @@ -615,11 +615,11 @@ 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) + fourInARowTheirTurn, piece = fiarReactionTest(channel,message,"#"+str(user.id)) if fourInARowTheirTurn: place = emojiToNumber(reaction.emoji) - await fiar(channel," place "+str(piece)+" "+str(place),user.display_name) + await fiar(channel," place "+str(piece)+" "+str(place),user.id) # Runs the whole shabang client.run(token) diff --git a/funcs/__init__.py b/funcs/__init__.py index 3954c0e..a7198c3 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -1,8 +1,8 @@ """A collection of all Gwendolyn functions.""" -__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "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","parseHex"] +__all__ = ["helloFunc", "cap", "imageFunc", "logThis", "findWikiPage", "makeFiles", "emojiToNumber", "fiarReactionTest", "deleteGame", "stopServer", "checkBalance", "giveMoney", "addMoney", "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", "parseHex", "addToDict", "getName", "getID"] -from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer +from .miscFuncs import helloFunc, cap, imageFunc, logThis, findWikiPage, makeFiles, replaceMultiple, emojiToNumber, fiarReactionTest, deleteGame, stopServer, addToDict, getName, getID from .games import checkBalance, giveMoney, addMoney, triviaCountPoints, triviaStart, triviaAnswer, blackjackShuffle, blackjackStart, blackjackPlayerDrawHand, blackjackContinue, blackjackFinish, blackjackHit, blackjackStand, blackjackDouble, blackjackSplit, parseFourInARow, fourInARowAI, parseHex diff --git a/funcs/games/blackjack.py b/funcs/games/blackjack.py index f0ad5b1..719bbd8 100644 --- a/funcs/games/blackjack.py +++ b/funcs/games/blackjack.py @@ -5,7 +5,7 @@ import datetime from shutil import copyfile -from funcs import logThis, replaceMultiple +from funcs import logThis, replaceMultiple, getName from . import money, blackjackDraw # Shuffles the blackjack cards @@ -352,7 +352,7 @@ def blackjackDouble(channel,user,handNumber = 0): roundDone = False - return "Adding another "+str(bet)+" GwendoBucks to "+user+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) + return "Adding another "+str(bet)+" GwendoBucks to "+getName(user)+"'s bet and drawing another card.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) else: logThis(user+" doesn't have enough GwendoBucks") return "You don't have enough GwendoBucks","" @@ -544,7 +544,7 @@ def blackjackSplit(channel,user,handNumber = 0): if person["fourth hand"]["hit"] == False and person["fourth hand"]["standing"] == False: roundDone = False - return "Splitting "+user+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) + return "Splitting "+getName(user)+"'s hand into 2. Adding their original bet to the second hand. You can use \"!Blackjack hit/stand/double 1\" and \"!Blackjack hit/stand/double 2\" to play the different hands.",str(roundDone)[0] + str(data["blackjack games"][channel]["round"]) else: logThis(user+" doesn't have enough GwendoBucks") return "You don't have enough GwendoBucks","" @@ -572,7 +572,7 @@ def blackjackPlayerDrawHand(channel,user,bet): with open("resources/games/games.json", "r") as f: data = json.load(f) - logThis(user+" is trying to join the game in "+channel) + logThis(getName(user)+" is trying to join the game in "+channel) if channel in data["blackjack games"]: if user not in data["blackjack games"][channel]["user hands"]: @@ -600,8 +600,8 @@ def blackjackPlayerDrawHand(channel,user,bet): with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) - logThis(user+" entered the game") - return user+" entered the game" + logThis(getName(user)+" entered the game") + return getName(user)+" entered the game" else: logThis(user+" doesn't have enough GwendoBucks") return "You don't have enough GwendoBucks to place that bet" @@ -669,14 +669,14 @@ def blackjackFinish(channel): if winnings < 0: if winnings == -1: - finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n" + finalWinnings += getName(user)+" lost "+str(-1 * winnings)+" GwendoBuck "+reason+"\n" else: - finalWinnings += user+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n" + finalWinnings += getName(user)+" lost "+str(-1 * winnings)+" GwendoBucks "+reason+"\n" else: if winnings == 1: - finalWinnings += user+" won "+str(winnings)+" GwendoBuck "+reason+"\n" + finalWinnings += getName(user)+" won "+str(winnings)+" GwendoBuck "+reason+"\n" else: - finalWinnings += user+" won "+str(winnings)+" GwendoBucks "+reason+"\n" + finalWinnings += getName(user)+" won "+str(winnings)+" GwendoBucks "+reason+"\n" money.addMoney(user,netWinnings) diff --git a/funcs/games/blackjackDraw.py b/funcs/games/blackjackDraw.py index 1d934ab..12e0a47 100644 --- a/funcs/games/blackjackDraw.py +++ b/funcs/games/blackjackDraw.py @@ -1,7 +1,7 @@ import json from PIL import Image, ImageDraw, ImageFont -from funcs import logThis +from funcs import logThis, getName border = 100 placement = [0,0] @@ -35,6 +35,7 @@ def drawImage(channel): for x in range(len(hands)): key, value = list(hands.items())[x] + key = getName(key) logThis("drawing "+key+"'s hand") userHand = drawHand(value["hand"],False,value["busted"],value["blackjack"]) try: diff --git a/funcs/games/fourInARow.py b/funcs/games/fourInARow.py index 3235fe3..7def0e1 100644 --- a/funcs/games/fourInARow.py +++ b/funcs/games/fourInARow.py @@ -4,7 +4,7 @@ import copy import math from . import fourInARowDraw -from funcs import logThis +from funcs import logThis, getName, getID AIScores = { "middle": 3, @@ -26,48 +26,52 @@ def fourInARowStart(channel, user, opponent): with open("resources/games/games.json", "r") as f: data = json.load(f) - if user.lower() != opponent.lower(): - if channel not in data["4 in a row games"]: + if channel not in data["4 in a row games"]: - if opponent in ["1","2","3","4","5"]: - difficulty = int(opponent) - diffText = " with difficulty "+opponent - opponent = "Gwendolyn" - elif opponent.lower() == "gwendolyn": - difficulty = 3 - diffText = " with difficulty 3" - opponent = "Gwendolyn" - else: - try: - int(opponent) - return "That difficulty doesn't exist", False, False, False, False - except: - # Opponent is another player + if opponent in ["1","2","3","4","5"]: + difficulty = int(opponent) + diffText = " with difficulty "+opponent + opponent = "Gwendolyn" + elif opponent.lower() == "gwendolyn": + difficulty = 3 + diffText = " with difficulty 3" + opponent = "Gwendolyn" + else: + try: + int(opponent) + return "That difficulty doesn't exist", False, False, False, False + except: + # Opponent is another player + opponent = getID(opponent) + if opponent != None: difficulty = 5 diffText = "" + else: + return "I can't find that user", False, False, False, False + + if user == opponent: + return "You can't play against yourself", False, False, False, False - board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ] - players = [user,opponent] - random.shuffle(players) + board = [ [ 0 for i in range(columnCount) ] for j in range(rowCount) ] + players = [user,opponent] + random.shuffle(players) - data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"", - "win coordinates":[0,0],"players":players,"turn":0,"difficulty":difficulty} + data["4 in a row games"][channel] = {"board": board,"winner":0,"win direction":"", + "win coordinates":[0,0],"players":players,"turn":0,"difficulty":difficulty} - with open("resources/games/games.json", "w") as f: - json.dump(data,f,indent=4) + with open("resources/games/games.json", "w") as f: + json.dump(data,f,indent=4) - fourInARowDraw.drawImage(channel) + fourInARowDraw.drawImage(channel) - gwendoTurn = False + gwendoTurn = False - if players[0] == "Gwendolyn": - gwendoTurn = True + if players[0] == "Gwendolyn": + gwendoTurn = True - return "Started game against "+opponent+diffText+". It's "+players[0]+"'s turn", True, False, False, gwendoTurn - else: - return "There's already a 4 in a row game going on in this channel", False, False, False, False + return "Started game against "+getName(opponent)+diffText+". It's "+getName(players[0])+"'s turn", True, False, False, gwendoTurn else: - return "You can't play against yourself", False, False, False, False + return "There's already a 4 in a row game going on in this channel", False, False, False, False # Places a piece at the lowest available point in a specific column def placePiece(channel : str,player : int,column : int): @@ -97,7 +101,7 @@ def placePiece(channel : str,player : int,column : int): data["4 in a row games"][channel]["win direction"] = winDirection data["4 in a row games"][channel]["win coordinates"] = winCoordinates - message = data["4 in a row games"][channel]["players"][won-1]+" won." + message = getName(data["4 in a row games"][channel]["players"][won-1])+" won." winAmount = int(data["4 in a row games"][channel]["difficulty"])^2+5 if data["4 in a row games"][channel]["players"][won-1] != "Gwendolyn": message += " Adding "+str(winAmount)+" GwendoBucks to their account." @@ -106,7 +110,7 @@ def placePiece(channel : str,player : int,column : int): message = "It's a draw!" else: gameWon = False - message = data["4 in a row games"][channel]["players"][player-1]+" placed a piece in column "+str(column+1)+". It's now "+data["4 in a row games"][channel]["players"][turn]+"'s turn." + message = getName(data["4 in a row games"][channel]["players"][player-1])+" placed a piece in column "+str(column+1)+". It's now "+getName(data["4 in a row games"][channel]["players"][turn])+"'s turn." with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) diff --git a/funcs/games/fourInARowDraw.py b/funcs/games/fourInARowDraw.py index c17850a..ddbbc9e 100644 --- a/funcs/games/fourInARowDraw.py +++ b/funcs/games/fourInARowDraw.py @@ -2,7 +2,7 @@ import json import math from PIL import Image, ImageDraw, ImageFont -from funcs import logThis +from funcs import logThis, getName # Draws the whole thing def drawImage(channel): @@ -32,6 +32,16 @@ def drawImage(channel): pieceStartx = (border+gridBorder)+math.floor(placeGridSize[0]/2)-math.floor(placeSize/2) pieceStarty = (border+gridBorder)+math.floor(placeGridSize[1]/2)-math.floor(placeSize/2) + if data["4 in a row games"][channel]["players"][0] == "Gwendolyn": + player1 = "Gwendolyn" + else: + player1 = getName(data["4 in a row games"][channel]["players"][0]) + + if data["4 in a row games"][channel]["players"][1] == "Gwendolyn": + player2 = "Gwendolyn" + else: + player2 = getName(data["4 in a row games"][channel]["players"][1]) + background = Image.new("RGB", (w,h+bottomBorder),backgroundColor) d = ImageDraw.Draw(background,"RGBA") @@ -124,11 +134,11 @@ def drawImage(channel): exampleHeight = h - border + int((bottomBorder+border)/2) - int(exampleCircles/2) d.ellipse([(border,exampleHeight),(border+exampleCircles),(exampleHeight+exampleCircles)],fill=(255,255,0),outline=(0,0,0),width=3) - d.text((border+exampleCircles+textPadding,exampleHeight),data["4 in a row games"][channel]["players"][0],font=fnt,fill=(0,0,0)) + d.text((border+exampleCircles+textPadding,exampleHeight),player1,font=fnt,fill=(0,0,0)) - textWidth = fnt.getsize(data["4 in a row games"][channel]["players"][1])[0] + textWidth = fnt.getsize(player2)[0] d.ellipse([(w-border-exampleCircles-textWidth-textPadding,exampleHeight),(w-border-textWidth-textPadding),(exampleHeight+exampleCircles)],fill=(255,0,0),outline=(0,0,0),width=3) - d.text((w-border-textWidth,exampleHeight),data["4 in a row games"][channel]["players"][1],font=fnt,fill=(0,0,0)) + d.text((w-border-textWidth,exampleHeight),player2,font=fnt,fill=(0,0,0)) background.save("resources/games/4InARowBoards/board"+channel+".png") diff --git a/funcs/games/money.py b/funcs/games/money.py index 5972630..7c76d65 100644 --- a/funcs/games/money.py +++ b/funcs/games/money.py @@ -1,47 +1,52 @@ import json -from funcs import logThis +from funcs import logThis, getID # Returns the account balance for a user def checkBalance(user): user = user.lower() logThis("checking "+user+"'s account balance") - with open("resources/games/games.json", "r") as f: + with open("resources/users.json", "r") as f: data = json.load(f) - if user in data["users"]: - return data["users"][user] + if user in data: + return data[user]["money"] else: return 0 # Adds money to the account of a user def addMoney(user,amount): - user = user.lower() logThis("adding "+str(amount)+" to "+user+"'s account") - with open("resources/games/games.json", "r") as f: + with open("resources/users.json", "r") as f: data = json.load(f) - if user in data["users"]: - points = data["users"][user] - data["users"][user] = points + amount + if user in data: + points = data[user]["money"] + data[user]["money"] = points + amount else: - data["users"][user] = amount + logThis("Error adding money") - with open("resources/games/games.json", "w") as f: + with open("resources/users.json", "w") as f: json.dump(data,f,indent=4) # Transfers money from one user to another def giveMoney(user,targetUser,amount): - with open("resources/games/games.json", "r") as f: + with open("resources/users.json", "r") as f: data = json.load(f) - if user in data["users"]: - if data["users"][user] >= amount: - addMoney(user,-1 * amount) - addMoney(targetUser,amount) - return "Transferred "+str(amount)+" GwendoBucks to "+targetUser + targetUser == getID(targetUser) + + if targetUser.startswith("#"): + if user in data: + if data[user]["money"] >= amount: + addMoney(user,-1 * amount) + addMoney(targetUser,amount) + return "Transferred "+str(amount)+" GwendoBucks to "+targetUser + else: + logThis("They didn't have enough GwendoBucks (error code 1223b)") + return "You don't have that many GwendoBucks (error code 1223b)" else: - logThis("They didn't have enough GwendoBucks (error code 1223b)") - return "You don't have that many GwendoBucks (error code 1223b)" + logThis("They didn't have enough GwendoBucks (error code 1223a)") + return "You don't have that many GwendoBucks (error code 1223a)" else: - logThis("They didn't have enough GwendoBucks (error code 1223a)") - return "You don't have that many GwendoBucks (error code 1223a)" + logThis("They weren't in the system") + return "The target doesn't exist" \ No newline at end of file diff --git a/funcs/miscFuncs.py b/funcs/miscFuncs.py index 9120785..ca699b4 100644 --- a/funcs/miscFuncs.py +++ b/funcs/miscFuncs.py @@ -180,6 +180,17 @@ def makeFiles(): json.dump(data,f,indent = 4) finally: f.close() + + # Creates users.json if it doesn't exist + try: + f = open("resources/users.json","r") + except: + logThis("users.json didn't exist. Making it now.") + data = {} + with open("resources/users.json","w") as f: + json.dump(data,f,indent = 4) + finally: + f.close() # Creates destinyPoints.txt if it doesn't exist try: @@ -291,11 +302,9 @@ def fiarReactionTest(channel,message,user): if message.id == oldImage: logThis("They reacted to the fourinarow game") turn = data["4 in a row games"][str(channel)]["turn"] - if user.lower() == data["4 in a row games"][str(channel)]["players"][turn].lower(): - if user != data["4 in a row games"][str(channel)]["players"][turn]: - data["4 in a row games"][str(channel)]["players"][turn] = user - with open("resources/games/games.json","w") as f: - json.dump(data,f,indent=4) + print(user) + print(data["4 in a row games"][str(channel)]["players"][turn]) + if user == data["4 in a row games"][str(channel)]["players"][turn]: return True, turn+1 else: logThis("It wasn't their turn") @@ -321,3 +330,61 @@ def deleteGame(gameType,channel): del data[gameType][channel] with open("resources/games/games.json", "w") as f: json.dump(data,f,indent=4) + +def addToDict(userID,userName): + with open("resources/users.json", "r") as f: + data = json.load(f) + + if userID in data: + if data[userID]["user name"] != userName: + logThis("changing name for "+userName) + data[userID]["user name"] = userName + with open("resources/users.json", "w") as f: + json.dump(data,f,indent=4) + else: + logThis("creating "+userName+" in the system") + + with open("resources/games/games.json","r") as f: + games = json.load(f) + + if userName.lower() in games["users"]: + money = games["users"][userName.lower()] + del games["users"][userName.lower()] + with open("resources/games/games.json", "w") as f: + json.dump(games,f,indent=4) + else: + money = 0 + + data[userID] = {"user name" : userName, "money" : money} + with open("resources/users.json", "w") as f: + json.dump(data,f,indent=4) + +def getName(userID): + try: + with open("resources/users.json", "r") as f: + data = json.load(f) + + if userID in data: + logThis("yeet") + return data[userID]["user name"] + else: + logThis("Couldn't find user") + return userID + except: + logThis("Error getting name") + +def getID(userName): + try: + with open("resources/users.json", "r") as f: + data = json.load(f) + + userID = None + + for key, value in data.items(): + if userName.lower() == value["user name"].lower(): + userID = key + break + + return userID + except: + logThis("Error getting ID") \ No newline at end of file diff --git a/funcs/swfuncs/swchar.py b/funcs/swfuncs/swchar.py index 1f09016..3bfab77 100644 --- a/funcs/swfuncs/swchar.py +++ b/funcs/swfuncs/swchar.py @@ -1,10 +1,10 @@ import json import string -from funcs import logThis +from funcs import logThis, getName -def getName(user : str): - logThis("Getting name for "+user+"'s character") +def getCharName(user : str): + logThis("Getting name for "+getName(user)+"'s character") with open("resources/starWars/swcharacters.json", "r") as f: data = json.load(f) @@ -12,8 +12,8 @@ def getName(user : str): logThis("Name is "+data[user]["Name"]) return data[user]["Name"] else: - logThis("Just using "+user) - return user + logThis("Just using "+getName(user)) + return getName(user) def setUpDict(cmd : dict): logThis("Setting up a dictionary in a nice way") @@ -251,7 +251,7 @@ def charData(user : str,cmd : str): if cmd == "": break - logThis("Looking for "+user+"'s character") + logThis("Looking for "+getName(user)+"'s character") if user in data: logThis("Foundt it! Looking for "+key+" in the data") if key in data[user]: @@ -498,27 +498,29 @@ def parseChar(user : str, cmd : str): if cmd == "": break + if cmd == "": if user in data: text1, text2 = characterSheet(data[user]) return text1, replaceWithSpaces(text2) else: - logThis("Makin' a character for "+user) + logThis("Makin' a character for "+getName(user)) with open("resources/starWars/swtemplates.json", "r") as f: templates = json.load(f) newChar = templates["Character"] data[user] = newChar with open("resources/starWars/swcharacters.json", "w") as f: json.dump(data,f,indent = 4) - return "", "Character for " + user + " created" + return "", "Character for " + getName(user) + " created" else: if cmd == "Purge": - logThis("Deleting "+user+"'s character") + logThis("Deleting "+getName(user)+"'s character") del data[user] with open("resources/starWars/swcharacters.json", "w") as f: json.dump(data,f,indent = 4) - return "", "Character for " + user + " deleted" - return "", replaceWithSpaces(str(charData(user,cmd))) + return "", "Character for " + getName(user) + " deleted" + else: + return "", replaceWithSpaces(str(charData(user,cmd))) def lightsaberChar(user : str): with open("resources/starWars/swcharacters.json", "r") as f: diff --git a/funcs/swfuncs/swroll.py b/funcs/swfuncs/swroll.py index 2f4a4d6..2b20bd7 100644 --- a/funcs/swfuncs/swroll.py +++ b/funcs/swfuncs/swroll.py @@ -367,7 +367,7 @@ def parseRoll(user : str,cmd : str = ""): simplified = simplify(rollResults) - name = swchar.getName(user) + name = swchar.getCharName(user) logThis("Returns results and simplified results")