Swchar and character sheet

This commit is contained in:
NikolajDanger
2020-03-30 22:28:00 +02:00
parent 892529cc4d
commit db0124c82b
7 changed files with 321 additions and 76 deletions

View File

@ -41,6 +41,9 @@ async def on_message(message):
await message.channel.send(embed = em) await message.channel.send(embed = em)
elif message.content.lower().startswith("!stop"): elif message.content.lower().startswith("!stop"):
localtime = time.asctime( time.localtime(time.time()) )
print("\n"+localtime+"\n"+message.author.name+" ran !stop")
logging.info("\n"+localtime+"\n"+message.author.name+" ran !stop")
await client.logout() await client.logout()
elif message.content.lower().startswith("!hello"): elif message.content.lower().startswith("!hello"):

View File

@ -14,7 +14,7 @@ def getName(user : str):
return user return user
def setUpDict(cmd : dict): def setUpDict(cmd : dict):
if bool(dict): if bool(cmd):
keys = list(cmd) keys = list(cmd)
values = list(cmd.values()) values = list(cmd.values())
result = "" result = ""
@ -41,8 +41,13 @@ def lookUp(data : dict, key : str, cmd : str = ""):
if key in data: if key in data:
if cmd == "": if cmd == "":
if type(data[key]) is dict: if type(data[key]) is dict and key != "Weapons":
return setUpDict(data[key]) return setUpDict(data[key])
elif key == "Weapons":
if bool(data[key]):
return ", ".join(list(data[key]))
else:
return "There doesn't seem to be anything here..."
else: else:
return data[key] return data[key]
elif cmd[0] == '+': elif cmd[0] == '+':
@ -60,28 +65,111 @@ def lookUp(data : dict, key : str, cmd : str = ""):
return data return data
except: except:
return "Can't add that" return "Can't add that"
elif type(data[key]) is list:
try:
data[key].append(cmd)
return data
except:
return "Can't add that"
else: else:
return "Can't add that" return "Can't add that"
elif cmd[0] == '-':
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
return "Can't do that"
if type(data[key]) is int:
try:
newValue = data[key] - int(cmd)
data[key] = newValue
return data
except:
return "Can't remove that"
elif type(data[key]) is list:
try:
data[key].remove(cmd)
return data
except:
return "Can't remove that"
else:
return "Can't remove that"
else: else:
while cmd[0] == ' ': while cmd[0] == ' ':
cmd = cmd[1:] cmd = cmd[1:]
try: if type(data[key]) != list:
cmd = type(data[key])(cmd) try:
data[key] = cmd cmd = type(data[key])(cmd)
return data data[key] = cmd
except: return data
except:
return "Wrong data type"
else:
return "Wrong data type" return "Wrong data type"
else: else:
return key + " doesn't exist" cmd = key + " " + cmd
words = cmd.split(" ")
search = ""
i = 0
while search not in data:
try:
search += " " + words[i]
i += 1
except:
return search + " doesn't exist"
if search[0] == " ":
search = search[1:]
cmd = cmd[len(search):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
return setUpDict(data[search])
else:
newKey = cmd.split(" ")[0]
cmd = cmd[len(newKey):]
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
lookUpResult = lookUp(data[search],newKey,cmd)
if type(lookUpResult) is dict:
data[search] = lookUpResult
return data
else:
return lookUpResult
def characterSheet(character : dict): def characterSheet(character : dict):
divider = "\n----------\n" divider = "--------------------\n"
name = character["Name"] name = character["Name"]
text1 = "**Species**: "+character["Species"]+"\n**Career**: "+character["Career"] textf = ""
text2 = setUpDict(character["Characteristics"]) if character["Force-rating"] != 0:
text3 = setUpDict(character["Skills"]) textf = "\n**Force Rating**: "+str(character["Force-rating"])
return name, text1+"\n\n"+text2+divider+text3 text1 = "**Species**: "+character["Species"]+"\n**Career**: "+character["Career"]+"\n**Specialization Trees**: "+", ".join(character["Specialization-trees"])+textf+"\n**Soak**: "+str(character["Soak"])
text2 = "\n\n**Wounds**: "+str(character["Wounds"])+"/"+str(character["Wound-threshold"])+"\n**Strain**: "+str(character["Strain"])+"/"+str(character["Strain-threshold"])
text3 = setUpDict(character["Characteristics"])
text4 = setUpDict(character["Skills"])
text5 = ""
text6 = ""
text7 = ""
if bool(character["Talents"]):
text5 = "**Talents**: "+",".join(list(character["Talents"]))+"\n\n"
if bool(character["Force-powers"]):
text6 = "**Force Powers**: "+",".join(list(character["Force-powers"]))+"\n\n"
if bool(character["Weapons"]):
text7 = "**Weapons**: "+",".join(list(character["Weapons"]))+"\n\n"
return name, text1+text2+"\n\n"+text3+divider+text4+"\n"+divider+text5+text6+text7
def charData(user : str,cmd : str): def charData(user : str,cmd : str):
with open("resources/swcharacters.json", "r") as f: with open("resources/swcharacters.json", "r") as f:
@ -101,10 +189,69 @@ def charData(user : str,cmd : str):
if key in data[user]: if key in data[user]:
if type(data[user][key]) is dict: if type(data[user][key]) is dict:
if cmd == "": if cmd == "":
return setUpDict(data[user][key]) if key == "Weapons":
if bool(data[user][key]):
return ", ".join(list(data[user][key]))
else:
return "There doesn't seem to be anything there..."
else:
return setUpDict(data[user][key])
elif cmd[0] == "+":
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
return "Can't do that"
if (key == "Talents" or key == "Force-powers") and "," in cmd:
cmd = cmd.split(",")
while cmd[1][0] == " ":
cmd[1] = cmd[1][1:]
data[user][key][cmd[0]] = cmd[1]
with open("resources/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:
templates = json.load(f)
newWeapon = templates["Weapon"]
data[user][key][cmd] = newWeapon
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return cmd+" added to weapons for " + data[user]["Name"]
else:
return "Can't add that"
elif cmd[0] == "-":
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
return "Can't do that"
if key == "Talents" or key == "Force-powers" or key == "Weapons":
if cmd in data[user][key]:
del data[user][key][cmd]
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return cmd+" removed from "+key+" for "+data[user]["Name"]
else:
return "Can't remove that"
else:
return "Can't remove that"
else: else:
newKey = string.capwords(cmd.split(" ")[0]) if key != "Talents" and key != "Force-powers":
newcmd = cmd[len(newKey):] newKey = string.capwords(cmd.split(" ")[0])
newcmd = cmd[len(newKey):]
else:
newKey = cmd
newcmd = ""
lookUpResult = lookUp(data[user][key],newKey,newcmd) lookUpResult = lookUp(data[user][key],newKey,newcmd)
@ -117,7 +264,10 @@ def charData(user : str,cmd : str):
return lookUpResult return lookUpResult
else: else:
if cmd == "": if cmd == "":
return data[user][key] if type(data[user][key]) is list:
return key+":\n"+", ".join(data[user][key])
else:
return data[user][key]
elif cmd[0] == '+': elif cmd[0] == '+':
try: try:
cmd = cmd[1:] cmd = cmd[1:]
@ -128,14 +278,65 @@ def charData(user : str,cmd : str):
if type(data[user][key]) is int: if type(data[user][key]) is int:
try: try:
data[user][key] += int(cmd) beforeData = data[user][key]
data[user][key] = beforeData+ int(cmd)
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + user + "'s " + key
except:
return "Can't add that"
elif type(data[user][key]) is list:
try:
data[user][key].append(cmd)
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + user + "'s " + key return "Added " + cmd + " to " + user + "'s " + key
except: except:
return "Can't add that" return "Can't add that"
else: else:
return "Can't add that" return "Can't add that"
elif cmd[0] == '-':
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
return "Can't do that"
if type(data[user][key]) is int:
try:
beforeData = data[user][key]
data[user][key] = beforeData - int(cmd)
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Subtracted " + cmd + " from " + user + "'s " + key
except:
return "Can't remove that"
elif type(data[user][key]) is list:
try:
beforeData = data[user][key]
try:
data[user][key].remove(cmd)
except:
return "Not in list"
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Removed " + cmd + " from " + user + "'s " + key
except:
return "Can't remove that"
else:
return "Can't remove that"
else: else:
data[user][key] = cmd if type(data[user][key]) is int:
try:
data[user][key] = int(cmd)
except:
return "Can't do that"
elif type(data[user][key]) is str:
data[user][key] = cmd
else:
return "Can't do that"
with open("resources/swcharacters.json", "w") as f: with open("resources/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
@ -144,7 +345,28 @@ def charData(user : str,cmd : str):
else: else:
return "You don't have a character. You can make one with !swchar" return "You don't have a character. You can make one with !swchar"
def replaceSpaces(cmd : str):
withSpaces = ["Specialization Trees","Wound Threshold","Strain Threshold","Defense - Ranged","Defense - Melee","Force Rating","Core Worlds","Outer Rim","Piloting - Planetary","Piloting - Space","Ranged - Heavy","Ranged - light","Lightsaber Characteristic","Critical Injuries","Force Powers"]
withoutSpaces = ["Specialization-trees","Wound-threshold","Strain-threshold","Defense-ranged","Defense-melee","Force-rating","Core-worlds","Outer-rim","Piloting-planetary","Piloting-space","Ranged-heavy","Ranged-light","Lightsaber-characteristic","Critical-injuries","Force-powers"]
for x in range(len(withoutSpaces)):
cmd = cmd.replace(withSpaces[x],withoutSpaces[x])
return cmd
def replaceWithSpaces(cmd : str):
withSpaces = ["Specialization Trees","Wound Threshold","Strain Threshold","Defense - Ranged","Defense - Melee","Force Rating","Core Worlds","Outer Rim","Piloting - Planetary","Piloting - Space","Ranged - Heavy","Ranged - light","Lightsaber Characteristic","Critical Injuries","Force Powers"]
withoutSpaces = ["Specialization-trees","Wound-threshold","Strain-threshold","Defense-ranged","Defense-melee","Force-rating","Core-worlds","Outer-rim","Piloting-planetary","Piloting-space","Ranged-heavy","Ranged-light","Lightsaber-characteristic","Critical-injuries","Force-powers"]
for x in range(len(withoutSpaces)):
cmd = cmd.replace(withoutSpaces[x],withSpaces[x])
return cmd
def parseChar(user : str, cmd : str): def parseChar(user : str, cmd : str):
cmd = replaceSpaces(cmd)
with open("resources/swcharacters.json", "r") as f: with open("resources/swcharacters.json", "r") as f:
data = json.load(f) data = json.load(f)
@ -158,7 +380,8 @@ def parseChar(user : str, cmd : str):
if cmd == "": if cmd == "":
if user in data: if user in data:
return characterSheet(data[user]) text1, text2 = characterSheet(data[user])
return text1, replaceWithSpaces(text2)
else: else:
with open("resources/swtemplates.json", "r") as f: with open("resources/swtemplates.json", "r") as f:
templates = json.load(f) templates = json.load(f)
@ -166,14 +389,14 @@ def parseChar(user : str, cmd : str):
data[user] = newChar data[user] = newChar
with open("resources/swcharacters.json", "w") as f: with open("resources/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":
del data[user] del data[user]
with open("resources/swcharacters.json", "w") as f: with open("resources/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 "", charData(user,cmd) return "", replaceWithSpaces(charData(user,cmd))
def lightsaberChar(user : str): def lightsaberChar(user : str):
with open("resources/swcharacters.json", "r") as f: with open("resources/swcharacters.json", "r") as f:

View File

@ -107,6 +107,8 @@ def parseRoll(user : str,cmd : str = ""):
cmd = re.sub(' +',' ',cmd.upper()) + " " cmd = re.sub(' +',' ',cmd.upper()) + " "
if cmd[0] == " ": if cmd[0] == " ":
cmd = cmd[1:] cmd = cmd[1:]
cmd = swchar.replaceSpaces(cmd.capitalize())
print(cmd)
commands = cmd.split(" ") commands = cmd.split(" ")
if commands[0] == "": if commands[0] == "":
rollParameters = [1,0,3,0,0,0,0] rollParameters = [1,0,3,0,0,0,0]

View File

@ -1,24 +1,24 @@
{ {
"TestUser": { "Nikolaj": {
"Name": "New Character", "Name": "New Character",
"Species": "", "Species": "",
"Career": "", "Career": "",
"Specialization Trees": [], "Specialization-trees": [],
"Soak": 0, "Soak": 0,
"Wound Threshold": 0, "Wound-threshold": 12,
"Wounds": 0, "Wounds": 0,
"Strain Threshold": 0, "Strain-threshold": 0,
"Strain": 0, "Strain": 0,
"Defense, Ranged": 0, "Defense-ranged": 0,
"Defense, Melee": 0, "Defense-melee": 0,
"Force Rating": 0, "Force-rating": 1,
"Characteristics": { "Characteristics": {
"Brawn": 0, "Brawn": 2,
"Agility": 0, "Agility": 2,
"Intellect": 0, "Intellect": 2,
"Cunning": 0, "Cunning": 2,
"Willpower": 0, "Willpower": 2,
"Presence": 0 "Presence": 2
}, },
"Skills": { "Skills": {
"Astrogation": 0, "Astrogation": 0,
@ -29,7 +29,7 @@
"Computers": 0, "Computers": 0,
"Cool": 0, "Cool": 0,
"Coordination": 0, "Coordination": 0,
"Core Worlds": 0, "Core-worlds": 0,
"Discipline": 0, "Discipline": 0,
"Gunnery": 0, "Gunnery": 0,
"Leadership": 0, "Leadership": 0,
@ -39,12 +39,12 @@
"Medicine": 0, "Medicine": 0,
"Melee": 0, "Melee": 0,
"Negotiation": 0, "Negotiation": 0,
"Outer Rim": 0, "Outer-rim": 0,
"Perception": 0, "Perception": 0,
"Piloting - Planetary": 0, "Piloting-planetary": 0,
"Piloting - Space": 0, "Piloting-space": 0,
"Ranged - Heavy": 0, "Ranged-heavy": 0,
"Ranged - Light": 0, "Ranged-light": 0,
"Resilience": 0, "Resilience": 0,
"Skullduggery": 0, "Skullduggery": 0,
"Stealth": 0, "Stealth": 0,
@ -54,20 +54,30 @@
"Vigilance": 0, "Vigilance": 0,
"Xenology": 0 "Xenology": 0
}, },
"Lightsaber Characteristic": "Brawn", "Lightsaber-characteristic": "Brawn",
"Obligations": {}, "Obligations": {},
"Morality": { "Morality": {
"Emotional Weakness": "", "Weakness": "Dicks",
"Emotional Strength": "", "Strength": "",
"Conflict": "", "Conflict": "",
"Morality": "" "Morality": ""
}, },
"Credits": 0, "Credits": 0,
"Equipment": [], "Equipment": [],
"Armor": "", "Armor": "",
"Critical Injuries": {}, "Critical-injuries": {},
"Weapons": {}, "Weapons": {
"Light Blaster Rifle": {
"Skill": "",
"Damage": 0,
"Range": "",
"Crit": 0,
"Special": []
}
},
"Talents": {}, "Talents": {},
"Force Powers": {} "Force-powers": {
"Dick 4 Dayz": "You Got Hella Dick"
}
} }
} }

View File

@ -6,23 +6,23 @@
"Mechanics" : "Intellect", "Mechanics" : "Intellect",
"Melee" : "Brawn", "Melee" : "Brawn",
"Perception" : "Cunning", "Perception" : "Cunning",
"Piloting - Space" : "Agility", "Piloting-space" : "Agility",
"Ranged - Heavy" : "Agility", "Ranged-heavy" : "Agility",
"Ranged - Light" : "Agility", "Ranged-light" : "Agility",
"Athletics" : "Brawn", "Athletics" : "Brawn",
"Coercion" : "Willpower", "Coercion" : "Willpower",
"Coordination" : "Agility", "Coordination" : "Agility",
"Charm" : "Presence", "Charm" : "Presence",
"Medicine" : "Intellect", "Medicine" : "Intellect",
"Negotiation" : "Presence", "Negotiation" : "Presence",
"Piloting - Planetary" : "Agility", "Piloting-planetary" : "Agility",
"Stealth" : "Agility", "Stealth" : "Agility",
"Skullduggery" : "Cunning", "Skullduggery" : "Cunning",
"Brawl" : "Brawn", "Brawl" : "Brawn",
"Discipline" : "Willpower", "Discipline" : "Willpower",
"Gunnery" : "Agility", "Gunnery" : "Agility",
"Core Worlds" : "Intellect", "Core-worlds" : "Intellect",
"Outer Rim" : "Intellect", "Outer-rim" : "Intellect",
"Underworld" : "Intellect", "Underworld" : "Intellect",
"Leadership" : "Presence", "Leadership" : "Presence",
"Lore" : "Intellect", "Lore" : "Intellect",

View File

@ -5,23 +5,23 @@ Vigilance
Mechanics Mechanics
Melee Melee
Perception Perception
Piloting - Space Piloting-space
Ranged - Heavy Ranged-heavy
Ranged - Light Ranged-light
Athletics Athletics
Coercion Coercion
Coordination Coordination
Charm Charm
Medicine Medicine
Negotiation Negotiation
Piloting - Planetary Piloting-planetary
Stealth Stealth
Skullduggery Skullduggery
Brawl Brawl
Discipline Discipline
Gunnery Gunnery
Core Worlds Core-worlds
Outer Rim Outer-rim
Underworld Underworld
Leadership Leadership
Lore Lore

View File

@ -3,15 +3,15 @@
"Name": "New Character", "Name": "New Character",
"Species": "", "Species": "",
"Career": "", "Career": "",
"Specialization Trees": [], "Specialization-trees": [],
"Soak": 0, "Soak": 0,
"Wound Threshold": 0, "Wound-threshold": 0,
"Wounds": 0, "Wounds": 0,
"Strain Threshold": 0, "Strain-threshold": 0,
"Strain": 0, "Strain": 0,
"Defense, Ranged": 0, "Defense-ranged": 0,
"Defense, Melee": 0, "Defense-melee": 0,
"Force Rating": 0, "Force-rating": 0,
"Characteristics": { "Characteristics": {
"Brawn": 2, "Brawn": 2,
"Agility": 2, "Agility": 2,
@ -29,7 +29,7 @@
"Computers": 0, "Computers": 0,
"Cool": 0, "Cool": 0,
"Coordination": 0, "Coordination": 0,
"Core Worlds": 0, "Core-worlds": 0,
"Discipline": 0, "Discipline": 0,
"Gunnery": 0, "Gunnery": 0,
"Leadership": 0, "Leadership": 0,
@ -39,12 +39,12 @@
"Medicine": 0, "Medicine": 0,
"Melee": 0, "Melee": 0,
"Negotiation": 0, "Negotiation": 0,
"Outer Rim": 0, "Outer-rim": 0,
"Perception": 0, "Perception": 0,
"Piloting - Planetary": 0, "Piloting-planetary": 0,
"Piloting - Space": 0, "Piloting-space": 0,
"Ranged - Heavy": 0, "Ranged-heavy": 0,
"Ranged - Light": 0, "Ranged-light": 0,
"Resilience": 0, "Resilience": 0,
"Skullduggery": 0, "Skullduggery": 0,
"Stealth": 0, "Stealth": 0,
@ -54,20 +54,27 @@
"Vigilance": 0, "Vigilance": 0,
"Xenology": 0 "Xenology": 0
}, },
"Lightsaber Characteristic": "Brawn", "Lightsaber-characteristic": "Brawn",
"Obligations": {}, "Obligations": {},
"Morality": { "Morality": {
"Emotional Weakness": "", "Weakness": "",
"Emotional Strength": "", "Strength": "",
"Conflict": "", "Conflict": "",
"Morality": "" "Morality": ""
}, },
"Credits": 0, "Credits": 0,
"Equipment": [], "Equipment": [],
"Armor": "", "Armor": "",
"Critical Injuries": {}, "Critical-injuries": {},
"Weapons": {}, "Weapons": {},
"Talents": {}, "Talents": {},
"Force Powers": {} "Force-powers": {}
},
"Weapon": {
"Skill" : "",
"Damage" : 0,
"Range" : "",
"Crit" : 0,
"Special" : []
} }
} }