🗃️ 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/
token.txt
resources/swcharacters.json
resources/starWars/swcharacters.json
resources/games/games.json
resources/games/blackjackCards/
resources/games/hilo/
resources/destinyPoints.txt
resources/starWars/destinyPoints.txt
resources/games/blackjackTables/
resources/games/oldImages/
resources/games/4InARowBoards/
resources/monsters.json
resources/spells.json
resources/lookup/monsters.json
resources/lookup/spells.json
gwendolynTest.py

View File

@ -24,7 +24,7 @@ def monsterFunc(command):
return("I don't know that monster... (error code 601)","","","","","")
else:
# 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:
if "name" in monster and str(command) == monster["name"]:
logThis("Found it!")
@ -125,7 +125,7 @@ def spellFunc(command):
logThis("Looking up "+command)
# 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:
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"]))

View File

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

View File

@ -5,7 +5,7 @@ from funcs import logThis
def getName(user : str):
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)
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
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)
key = string.capwords(cmd.split(" ")[0])
@ -285,7 +285,7 @@ def charData(user : str,cmd : str):
cmd[1] = cmd[1][1:]
logThis("Adding "+cmd[0]+" to "+key)
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)
return cmd[0]+" added to "+key+" for " + data[user]["Name"]
@ -299,18 +299,18 @@ def charData(user : str,cmd : str):
except:
logThis("Fucked that up (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)
return cmd[0]+" added to "+key+" for " + data[user]["Name"]
elif key == "Weapons":
with open("resources/swtemplates.json", "r") as f:
with open("resources/starWars/swtemplates.json", "r") as f:
templates = json.load(f)
newWeapon = templates["Weapon"]
logThis("Adding "+cmd+" to "+key)
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)
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)
if cmd in data[user][key]:
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)
logThis("I did that")
return cmd+" removed from "+key+" from "+data[user]["Name"]
@ -356,7 +356,7 @@ def charData(user : str,cmd : str):
if type(lookUpResult) is dict:
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)
return "Changed " + data[user]["Name"] + "'s " + key
else:
@ -383,7 +383,7 @@ def charData(user : str,cmd : str):
logThis("Adding "+cmd+" to "+key)
beforeData = data[user][key]
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)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except:
@ -393,7 +393,7 @@ def charData(user : str,cmd : str):
try:
logThis("Adding "+cmd+" to "+key)
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)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except:
@ -417,7 +417,7 @@ def charData(user : str,cmd : str):
logThis("Subtracting "+cmd+" from "+key)
beforeData = data[user][key]
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)
return "Subtracted " + cmd + " from " + data[user]["Name"] + "'s " + key
except:
@ -432,7 +432,7 @@ def charData(user : str,cmd : str):
except:
logThis("They can only remove stuff that's actually in the list")
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)
return "Removed " + cmd + " from " + data[user]["Name"] + "'s " + key
except:
@ -455,7 +455,7 @@ def charData(user : str,cmd : str):
logThis("I don't wanna tho (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)
return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd
else:
@ -487,7 +487,7 @@ def parseChar(user : str, cmd : str):
cmd = replaceSpaces(cmd)
with open("resources/swcharacters.json", "r") as f:
with open("resources/starWars/swcharacters.json", "r") as f:
data = json.load(f)
if cmd == " ":
@ -504,31 +504,31 @@ def parseChar(user : str, cmd : str):
return text1, replaceWithSpaces(text2)
else:
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)
newChar = templates["Character"]
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)
return "", "Character for " + user + " created"
else:
if cmd == "Purge":
logThis("Deleting "+user+"'s character")
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)
return "", "Character for " + user + " deleted"
return "", replaceWithSpaces(str(charData(user,cmd)))
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)
if user in data:
return data[user]["Lightsaber-characteristic"]
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)
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 = "".join(sorted(roll))
with open("resources/destinyPoints.txt","wt") as f:
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(roll)
return "Rolled for Destiny Points and got:\n"+swroll.diceResultToEmoji(diceResults)+"\n"+swroll.resultToEmoji(roll)
def destinyUse(user : str):
with open("resources/destinyPoints.txt","rt") as f:
with open("resources/starWars/destinyPoints.txt","rt") as f:
points = f.read()
if user == "Nikolaj":
@ -21,7 +21,7 @@ def destinyUse(user : str):
if 'B' in points:
points = points.replace("B","L",1)
points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f:
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
logThis("Did it")
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:
points = points.replace("L","B",1)
points = "".join(sorted(points))
with open("resources/destinyPoints.txt","wt") as f:
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
logThis("Did it")
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 == "":
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())
else:
commands = cmd.upper().split(" ")

View File

@ -7,7 +7,7 @@ import os
from . import swchar
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)
# Rolls the specified dice
@ -224,7 +224,7 @@ def diceToEmoji(dice : list):
# Rolls for obligation
def obligationRoll():
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)
table = []

View File

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