🗃️ Resource cleanup

This commit is contained in:
Nikolaj Danger
2020-08-03 15:11:24 +02:00
parent cd1eff01a0
commit 6ca2c80432
11 changed files with 42 additions and 49 deletions

8
.gitignore vendored
View File

@ -150,14 +150,14 @@ static
.vscode/ .vscode/
token.txt token.txt
resources/swcharacters.json resources/starWars/swcharacters.json
resources/games/games.json resources/games/games.json
resources/games/blackjackCards/ resources/games/blackjackCards/
resources/games/hilo/ resources/games/hilo/
resources/destinyPoints.txt resources/starWars/destinyPoints.txt
resources/games/blackjackTables/ resources/games/blackjackTables/
resources/games/oldImages/ resources/games/oldImages/
resources/games/4InARowBoards/ resources/games/4InARowBoards/
resources/monsters.json resources/lookup/monsters.json
resources/spells.json resources/lookup/spells.json
gwendolynTest.py gwendolynTest.py

View File

@ -24,7 +24,7 @@ def monsterFunc(command):
return("I don't know that monster... (error code 601)","","","","","") return("I don't know that monster... (error code 601)","","","","","")
else: else:
# Opens "mensters.json" # Opens "mensters.json"
data = json.load(open('resources/monsters.json', encoding = "utf8")) data = json.load(open('resources/lookup/monsters.json', encoding = "utf8"))
for monster in data: for monster in data:
if "name" in monster and str(command) == monster["name"]: if "name" in monster and str(command) == monster["name"]:
logThis("Found it!") logThis("Found it!")
@ -125,7 +125,7 @@ def spellFunc(command):
logThis("Looking up "+command) logThis("Looking up "+command)
# Opens "spells.json" # Opens "spells.json"
data = json.load(open('resources/spells.json', encoding = "utf8")) data = json.load(open('resources/lookup/spells.json', encoding = "utf8"))
if str(command) in data: if str(command) in data:
logThis("Returning spell information") logThis("Returning spell information")
spell_output = ("***"+str(command)+"***\n*"+str(data[str(command)]["level"])+" level "+str(data[str(command)]["school"])+"\nCasting Time: "+str(data[str(command)]["casting_time"])+"\nRange: "+str(data[str(command)]["range"])+"\nComponents: "+str(data[str(command)]["components"])+"\nDuration: "+str(data[str(command)]["duration"])+"*\n \n"+str(data[str(command)]["description"])) spell_output = ("***"+str(command)+"***\n*"+str(data[str(command)]["level"])+" level "+str(data[str(command)]["school"])+"\nCasting Time: "+str(data[str(command)]["casting_time"])+"\nRange: "+str(data[str(command)]["range"])+"\nComponents: "+str(data[str(command)]["components"])+"\nDuration: "+str(data[str(command)]["duration"])+"*\n \n"+str(data[str(command)]["description"]))

View File

@ -138,11 +138,11 @@ def findWikiPage(search : str):
def makeFiles(): def makeFiles():
# Creates swcharacters.json if it doesn't exist # Creates swcharacters.json if it doesn't exist
try: try:
f = open("resources/swcharacters.json","r") f = open("resources/starWars/swcharacters.json","r")
except: except:
logThis("swcharacters.json didn't exist. Making it now.") logThis("swcharacters.json didn't exist. Making it now.")
emptyDict = {} emptyDict = {}
with open("resources/swcharacters.json","w") as f: with open("resources/starWars/swcharacters.json","w") as f:
json.dump(emptyDict,f,indent = 4) json.dump(emptyDict,f,indent = 4)
finally: finally:
f.close() f.close()
@ -160,34 +160,34 @@ def makeFiles():
# Creates monsters.json if it doesn't exist # Creates monsters.json if it doesn't exist
try: try:
f = open("resources/monsters.json","r") f = open("resources/lookup/monsters.json","r")
except: except:
logThis("monsters.json didn't exist. Making it now.") logThis("monsters.json didn't exist. Making it now.")
with open("resources/lookupExamples.json") as f: with open("resources/lookup/lookupExamples.json") as f:
data = json.load(f)["monster"] data = json.load(f)["monster"]
with open("resources/monsters.json","w") as f: with open("resources/lookup/monsters.json","w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
finally: finally:
f.close() f.close()
# Creates spells.json if it doesn't exist # Creates spells.json if it doesn't exist
try: try:
f = open("resources/spells.json","r") f = open("resources/lookup/spells.json","r")
except: except:
logThis("spells.json didn't exist. Making it now.") logThis("spells.json didn't exist. Making it now.")
with open("resources/lookupExamples.json") as f: with open("resources/lookup/lookupExamples.json") as f:
data = json.load(f)["spell"] data = json.load(f)["spell"]
with open("resources/spells.json","w") as f: with open("resources/lookup/spells.json","w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
finally: finally:
f.close() f.close()
# Creates destinyPoints.txt if it doesn't exist # Creates destinyPoints.txt if it doesn't exist
try: try:
f = open("resources/destinyPoints.txt","r") f = open("resources/starWars/destinyPoints.txt","r")
except: except:
logThis("destinyPoints.txt didn't exist. Making it now.") logThis("destinyPoints.txt didn't exist. Making it now.")
with open("resources/destinyPoints.txt","w") as f: with open("resources/starWars/destinyPoints.txt","w") as f:
f.write("") f.write("")
finally: finally:
f.close() f.close()

View File

@ -5,7 +5,7 @@ from funcs import logThis
def getName(user : str): def getName(user : str):
logThis("Getting name for "+user+"'s character") logThis("Getting name for "+user+"'s character")
with open("resources/swcharacters.json", "r") as f: with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
if user in data: if user in data:
@ -238,7 +238,7 @@ def characterSheet(character : dict):
return name, text1+text2+"\n\n"+text3+divider+text4+"\n"+divider+text5+text6+text7+text8 return name, text1+text2+"\n\n"+text3+divider+text4+"\n"+divider+text5+text6+text7+text8
def charData(user : str,cmd : str): def charData(user : str,cmd : str):
with open("resources/swcharacters.json", "r") as f: with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
key = string.capwords(cmd.split(" ")[0]) key = string.capwords(cmd.split(" ")[0])
@ -285,7 +285,7 @@ def charData(user : str,cmd : str):
cmd[1] = cmd[1][1:] cmd[1] = cmd[1][1:]
logThis("Adding "+cmd[0]+" to "+key) logThis("Adding "+cmd[0]+" to "+key)
data[user][key][cmd[0]] = cmd[1] data[user][key][cmd[0]] = cmd[1]
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return cmd[0]+" added to "+key+" for " + data[user]["Name"] return cmd[0]+" added to "+key+" for " + data[user]["Name"]
@ -299,18 +299,18 @@ def charData(user : str,cmd : str):
except: except:
logThis("Fucked that up (error code 949)") logThis("Fucked that up (error code 949)")
return "Wrong data type (error code 949)" return "Wrong data type (error code 949)"
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return cmd[0]+" added to "+key+" for " + data[user]["Name"] return cmd[0]+" added to "+key+" for " + data[user]["Name"]
elif key == "Weapons": elif key == "Weapons":
with open("resources/swtemplates.json", "r") as f: with open("resources/starWars/swtemplates.json", "r") as f:
templates = json.load(f) templates = json.load(f)
newWeapon = templates["Weapon"] newWeapon = templates["Weapon"]
logThis("Adding "+cmd+" to "+key) logThis("Adding "+cmd+" to "+key)
data[user][key][cmd] = newWeapon data[user][key][cmd] = newWeapon
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return cmd+" added to weapons for " + data[user]["Name"] return cmd+" added to weapons for " + data[user]["Name"]
@ -332,7 +332,7 @@ def charData(user : str,cmd : str):
logThis("Trying to remove "+cmd+" from "+key) logThis("Trying to remove "+cmd+" from "+key)
if cmd in data[user][key]: if cmd in data[user][key]:
del data[user][key][cmd] del data[user][key][cmd]
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
logThis("I did that") logThis("I did that")
return cmd+" removed from "+key+" from "+data[user]["Name"] return cmd+" removed from "+key+" from "+data[user]["Name"]
@ -356,7 +356,7 @@ def charData(user : str,cmd : str):
if type(lookUpResult) is dict: if type(lookUpResult) is dict:
data[user][key] = lookUpResult data[user][key] = lookUpResult
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key return "Changed " + data[user]["Name"] + "'s " + key
else: else:
@ -383,7 +383,7 @@ def charData(user : str,cmd : str):
logThis("Adding "+cmd+" to "+key) logThis("Adding "+cmd+" to "+key)
beforeData = data[user][key] beforeData = data[user][key]
data[user][key] = beforeData+ int(cmd) data[user][key] = beforeData+ int(cmd)
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except: except:
@ -393,7 +393,7 @@ def charData(user : str,cmd : str):
try: try:
logThis("Adding "+cmd+" to "+key) logThis("Adding "+cmd+" to "+key)
data[user][key].append(cmd) data[user][key].append(cmd)
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except: except:
@ -417,7 +417,7 @@ def charData(user : str,cmd : str):
logThis("Subtracting "+cmd+" from "+key) logThis("Subtracting "+cmd+" from "+key)
beforeData = data[user][key] beforeData = data[user][key]
data[user][key] = beforeData - int(cmd) data[user][key] = beforeData - int(cmd)
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Subtracted " + cmd + " from " + data[user]["Name"] + "'s " + key return "Subtracted " + cmd + " from " + data[user]["Name"] + "'s " + key
except: except:
@ -432,7 +432,7 @@ def charData(user : str,cmd : str):
except: except:
logThis("They can only remove stuff that's actually in the list") logThis("They can only remove stuff that's actually in the list")
return "Not in list (error code 944b)" return "Not in list (error code 944b)"
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Removed " + cmd + " from " + data[user]["Name"] + "'s " + key return "Removed " + cmd + " from " + data[user]["Name"] + "'s " + key
except: except:
@ -455,7 +455,7 @@ def charData(user : str,cmd : str):
logThis("I don't wanna tho (error code 945a)") logThis("I don't wanna tho (error code 945a)")
return "Can't do that (error code 945a)" return "Can't do that (error code 945a)"
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd
else: else:
@ -487,7 +487,7 @@ def parseChar(user : str, cmd : str):
cmd = replaceSpaces(cmd) cmd = replaceSpaces(cmd)
with open("resources/swcharacters.json", "r") as f: with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
if cmd == " ": if cmd == " ":
@ -504,31 +504,31 @@ def parseChar(user : str, cmd : str):
return text1, replaceWithSpaces(text2) return text1, replaceWithSpaces(text2)
else: else:
logThis("Makin' a character for "+user) logThis("Makin' a character for "+user)
with open("resources/swtemplates.json", "r") as f: with open("resources/starWars/swtemplates.json", "r") as f:
templates = json.load(f) templates = json.load(f)
newChar = templates["Character"] newChar = templates["Character"]
data[user] = newChar data[user] = newChar
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "", "Character for " + user + " created" return "", "Character for " + user + " created"
else: else:
if cmd == "Purge": if cmd == "Purge":
logThis("Deleting "+user+"'s character") logThis("Deleting "+user+"'s character")
del data[user] del data[user]
with open("resources/swcharacters.json", "w") as f: with open("resources/starWars/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4) json.dump(data,f,indent = 4)
return "", "Character for " + user + " deleted" return "", "Character for " + user + " deleted"
return "", replaceWithSpaces(str(charData(user,cmd))) return "", replaceWithSpaces(str(charData(user,cmd)))
def lightsaberChar(user : str): def lightsaberChar(user : str):
with open("resources/swcharacters.json", "r") as f: with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
if user in data: if user in data:
return data[user]["Lightsaber-characteristic"] return data[user]["Lightsaber-characteristic"]
def userHasChar(user : str): def userHasChar(user : str):
with open("resources/swcharacters.json", "r") as f: with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
return user in data return user in data

View File

@ -7,13 +7,13 @@ def destinyNew(num : int):
roll, diceResults = swroll.roll(0,0,0,0,0,0,num) roll, diceResults = swroll.roll(0,0,0,0,0,0,num)
roll = "".join(sorted(roll)) roll = "".join(sorted(roll))
with open("resources/destinyPoints.txt","wt") as f: with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(roll) f.write(roll)
return "Rolled for Destiny Points and got:\n"+swroll.diceResultToEmoji(diceResults)+"\n"+swroll.resultToEmoji(roll) return "Rolled for Destiny Points and got:\n"+swroll.diceResultToEmoji(diceResults)+"\n"+swroll.resultToEmoji(roll)
def destinyUse(user : str): def destinyUse(user : str):
with open("resources/destinyPoints.txt","rt") as f: with open("resources/starWars/destinyPoints.txt","rt") as f:
points = f.read() points = f.read()
if user == "Nikolaj": if user == "Nikolaj":
@ -21,7 +21,7 @@ def destinyUse(user : str):
if 'B' in points: if 'B' in points:
points = points.replace("B","L",1) points = points.replace("B","L",1)
points = "".join(sorted(points)) points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f: with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points) f.write(points)
logThis("Did it") logThis("Did it")
return "Used a dark side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points) return "Used a dark side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points)
@ -33,7 +33,7 @@ def destinyUse(user : str):
if 'L' in points: if 'L' in points:
points = points.replace("L","B",1) points = points.replace("L","B",1)
points = "".join(sorted(points)) points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f: with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points) f.write(points)
logThis("Did it") logThis("Did it")
return "Used a light side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points) return "Used a light side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points)
@ -51,7 +51,7 @@ def parseDestiny(user : str, cmd : str):
if cmd == "": if cmd == "":
logThis("Retrieving destiny pool info") logThis("Retrieving destiny pool info")
with open("resources/destinyPoints.txt","rt") as f: with open("resources/starWars/destinyPoints.txt","rt") as f:
return swroll.resultToEmoji(f.read()) return swroll.resultToEmoji(f.read())
else: else:
commands = cmd.upper().split(" ") commands = cmd.upper().split(" ")

View File

@ -7,7 +7,7 @@ import os
from . import swchar from . import swchar
from funcs import logThis from funcs import logThis
with open("resources/swskills.json", "r") as f: with open("resources/starWars/swskills.json", "r") as f:
skillData = json.load(f) skillData = json.load(f)
# Rolls the specified dice # Rolls the specified dice
@ -224,7 +224,7 @@ def diceToEmoji(dice : list):
# Rolls for obligation # Rolls for obligation
def obligationRoll(): def obligationRoll():
logThis("Rolling for obligation") logThis("Rolling for obligation")
with open("resources/swcharacters.json", "r") as f: with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
table = [] table = []

View File

@ -1,7 +0,0 @@
{
"trivia questions": {},
"users": {
"nikolaj": 1,
"jonathanh\u00f8jlev": 6
}
}