diff --git a/Gwendolyn.py b/Gwendolyn.py index 4a1779e..7e469c1 100644 --- a/Gwendolyn.py +++ b/Gwendolyn.py @@ -47,9 +47,15 @@ async def on_message(message): # Stops the bot 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() + if message.author.name == "Nikolaj": + print("\n"+localtime+"\n"+message.author.name+" ran !stop") + logging.info("\n"+localtime+"\n"+message.author.name+" ran !stop") + await message.channel.send("Logging out...") + await client.logout() + else: + print("\n"+localtime+"\n"+message.author.name+" tried to run !stop") + logging.info("\n"+localtime+"\n"+message.author.name+" tried to run !stop") + await message.channel.send("I don't think I will, "+message.author.name) # Does a hello with the helloFunc function from funcs/gwendolynFuncs.py elif message.content.lower().startswith("!hello"): @@ -184,14 +190,22 @@ async def on_message(message): logging.info("\n"+localtime+"\n"+message.author.name+" ran !swroll") command = funcs.cap(message.content.lower().replace("!swroll","")) await message.channel.send(funcs.parseRoll(message.author.name,command)) + + # Deals with Destiny Points and stuff + elif message.content.lower().startswith("!swd"): + localtime = time.asctime(time.localtime(time.time())) + print("\n"+localtime+"\n"+message.author.name+" ran !swd") + logging.info("\n"+localtime+"\n"+message.author.name+" ran !swd") + command = message.content.lower().replace("!swd","") + await message.channel.send(funcs.parseDestiny(message.author.name,command)) # Accesses and changes character sheet data with the parseChar function # from funcs/swfuncs/swchar.py - elif message.content.lower().startswith("!swchar"): + elif message.content.lower().startswith("!swchar") or message.content.lower().startswith("!sw"): localtime = time.asctime(time.localtime(time.time())) print("\n"+localtime+"\n"+message.author.name+" ran !swchar") logging.info("\n"+localtime+"\n"+message.author.name+" ran !swchar") - command = funcs.cap(message.content.lower().replace("!swchar","")) + command = funcs.cap(message.content.lower().replace("!swchar","").replace("!sw","").replace("+","+ ")) title, desc = funcs.parseChar(message.author.name,command) if title != "": em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF) @@ -200,5 +214,6 @@ async def on_message(message): await message.channel.send(desc) + # Runs the whole shabang client.run(token) diff --git a/funcs/__init__.py b/funcs/__init__.py index aadbe21..9d55bf9 100644 --- a/funcs/__init__.py +++ b/funcs/__init__.py @@ -1,6 +1,6 @@ from .gwendolynFuncs import helloFunc, roll_dice, cap, imageFunc -from .swfuncs import parseChar, parseRoll +from .swfuncs import parseChar, parseRoll, parseDestiny from .lookup import spellFunc, monsterFunc diff --git a/funcs/gwendolynFuncs.py b/funcs/gwendolynFuncs.py index 88fdb98..b243662 100644 --- a/funcs/gwendolynFuncs.py +++ b/funcs/gwendolynFuncs.py @@ -106,3 +106,5 @@ def imageFunc(): # Returns the image print("Successfully returned an image\n") return(image) + + diff --git a/funcs/swfuncs/__init__.py b/funcs/swfuncs/__init__.py index e4a73de..b5d9864 100644 --- a/funcs/swfuncs/__init__.py +++ b/funcs/swfuncs/__init__.py @@ -1,2 +1,3 @@ from .swchar import parseChar -from .swroll import parseRoll \ No newline at end of file +from .swroll import parseRoll +from .swdestiny import parseDestiny \ No newline at end of file diff --git a/funcs/swfuncs/swchar.py b/funcs/swfuncs/swchar.py index 61c4d7a..aa11cf5 100644 --- a/funcs/swfuncs/swchar.py +++ b/funcs/swfuncs/swchar.py @@ -99,7 +99,17 @@ def lookUp(data : dict, key : str, cmd : str = ""): else: while cmd[0] == ' ': cmd = cmd[1:] - if type(data[key]) != list: + + if type(data[key]) is dict: + newKey = cmd.split(" ")[0] + cmd = cmd[len(newKey):] + while cmd[0] == " ": + cmd = cmd[1:] + if cmd == "": + break + data[key] = lookUp(data[key],newKey,cmd) + return data + elif type(data[key]) != list: try: cmd = type(data[key])(cmd) data[key] = cmd @@ -162,13 +172,12 @@ def characterSheet(character : dict): text8 = "" if bool(character["Talents"]): - text5 = "**Talents**: "+",".join(list(character["Talents"]))+"\n\n" + text5 = "**Talents**: "+", ".join(list(character["Talents"]))+"\n\n" if bool(character["Force-powers"]): - text6 = "**Force Powers**: "+",".join(list(character["Force-powers"]))+"\n\n" + text6 = "**Force Powers**: "+", ".join(list(character["Force-powers"]))+"\n\n" - if bool(character["Weapons"]): - text7 = "**Weapons**: "+",".join(list(character["Weapons"]))+"\n"+divider + text7 = "**Equipment**: "+", ".join(character["Equipment"])+"\n**Credits**: "+str(character["Credits"])+"\n**Weapons**: "+", ".join(list(character["Weapons"]))+"\n"+divider if bool(character["Obligations"]): text8 = "**Obligations**: "+",".join(list(character["Obligations"])) @@ -250,7 +259,7 @@ def charData(user : str,cmd : str): except: return "Can't do that" - if key == "Talents" or key == "Force-powers" or key == "Weapons": + if key == "Talents" or key == "Force-powers" or key == "Weapons" or key == "Obligations": if cmd in data[user][key]: del data[user][key][cmd] with open("resources/swcharacters.json", "w") as f: @@ -298,7 +307,7 @@ def charData(user : str,cmd : str): 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 + return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key except: return "Can't add that" elif type(data[user][key]) is list: @@ -306,7 +315,7 @@ def charData(user : str,cmd : str): 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 " + data[user]["Name"] + "'s " + key except: return "Can't add that" else: @@ -325,7 +334,7 @@ def charData(user : str,cmd : str): 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 + return "Subtracted " + cmd + " from " + data[user]["Name"] + "'s " + key except: return "Can't remove that" elif type(data[user][key]) is list: @@ -337,7 +346,7 @@ def charData(user : str,cmd : str): 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 + return "Removed " + cmd + " from " + data[user]["Name"] + "'s " + key except: return "Can't remove that" else: @@ -412,7 +421,7 @@ def parseChar(user : str, cmd : str): with open("resources/swcharacters.json", "w") as f: json.dump(data,f,indent = 4) return "", "Character for " + user + " deleted" - return "", replaceWithSpaces(charData(user,cmd)) + return "", replaceWithSpaces(str(charData(user,cmd))) def lightsaberChar(user : str): with open("resources/swcharacters.json", "r") as f: diff --git a/funcs/swfuncs/swdestiny.py b/funcs/swfuncs/swdestiny.py new file mode 100644 index 0000000..ac4eeec --- /dev/null +++ b/funcs/swfuncs/swdestiny.py @@ -0,0 +1,53 @@ +from . import swroll + +def destinyNew(num : int): + roll = swroll.roll(0,0,0,0,0,0,num) + + with open("resources/destinyPoints.txt","wt") as f: + f.write(roll) + + return "Rolled for Destiny Points and got:\n"+swroll.resultToEmoji(roll) + +def destinyUse(user : str): + with open("resources/destinyPoints.txt","rt") as f: + points = f.read() + + if user == "Nikolaj": + if 'B' in points: + points = points.replace("B","L",1) + with open("resources/destinyPoints.txt","wt") as f: + f.write(points) + return "Used a dark side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points) + else: + return "No dark side destiny points" + else: + if 'L' in points: + points = points.replace("L","B",1) + with open("resources/destinyPoints.txt","wt") as f: + f.write(points) + return "Used a light side destiny point. Destiny pool is now:\n"+swroll.resultToEmoji(points) + else: + return "No light side destiny points" + +def parseDestiny(user : str, cmd : str): + if cmd != "": + while cmd[0] == ' ': + cmd = cmd[1:] + if cmd == "": + break + + + if cmd == "": + with open("resources/destinyPoints.txt","rt") as f: + return swroll.resultToEmoji(f.read()) + else: + commands = cmd.upper().split(" ") + if commands[0] == "N": + if len(commands) > 1: + return destinyNew(int(commands[1])) + else: + return "You need to give an amount of players" + elif commands[0] == "U": + return destinyUse(user) + else: + return "I didn't quite understand that" diff --git a/funcs/swfuncs/swroll.py b/funcs/swfuncs/swroll.py index 6089132..280a916 100644 --- a/funcs/swfuncs/swroll.py +++ b/funcs/swfuncs/swroll.py @@ -80,6 +80,16 @@ def resultToEmoji(result : str): return emoji +def emojiToResult(emoji : str): + result = "" + for char in emoji: + if char == "<:light:691010089905029171>": + emoji += 'L' + if char == "<:dark:691010101901000852>": + emoji += 'B' + + return result + def diceToEmoji(dice : list): emoji = "" @@ -112,7 +122,7 @@ def obligationRoll(): for character in data: for obligation in data[character]["Obligations"]: for x in range(data[character]["Obligations"][obligation]): - table.append(obligation) + table.append(data[character]["Name"]+", "+obligation) while len(table) < 100: table.append("Nothing") @@ -124,7 +134,6 @@ def parseRoll(user : str,cmd : str = ""): if cmd[0] == " ": cmd = cmd[1:] cmd = swchar.replaceSpaces(cmd.capitalize()) - print(cmd) commands = cmd.split(" ") if commands[0] == "": rollParameters = [1,0,3,0,0,0,0] diff --git a/resources/destinyPoints.txt b/resources/destinyPoints.txt new file mode 100644 index 0000000..fb92b78 --- /dev/null +++ b/resources/destinyPoints.txt @@ -0,0 +1 @@ +LLLLl \ No newline at end of file diff --git a/resources/swcharacters.json b/resources/swcharacters.json index 2155150..1eeba18 100644 --- a/resources/swcharacters.json +++ b/resources/swcharacters.json @@ -291,7 +291,6 @@ }, "Lightsaber-characteristic": "Brawn", "Obligations": { - "Bounty": 10, "Betrayal": 10 }, "Morality": { @@ -480,7 +479,7 @@ "Weapons": { "Lightsaber": { "Skill": "", - "Damage": 0, + "Damage": 2, "Range": "", "Crit": 0, "Special": []