🗃️ Resource cleanup
This commit is contained in:
@ -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
|
||||
|
Reference in New Issue
Block a user