Fully converted to slash commands

This commit is contained in:
NikolajDanger
2021-03-31 00:38:51 +02:00
parent a8a7e5eabd
commit b345720468
50 changed files with 1102 additions and 1111 deletions

View File

@ -0,0 +1,5 @@
"""Functions related to the Star Wars TTRPG."""
__all__ = ["StarWars"]
from .starWars import StarWars

View File

@ -0,0 +1,10 @@
from .starWarsChar import StarWarsChar
from .starWarsRoll import StarWarsRoll
from .starWarsDestiny import StarWarsDestiny
class StarWars():
def __init__(self, bot):
self.bot = bot
self.character = StarWarsChar(self.bot)
self.roll = StarWarsRoll(self.bot)
self.destiny = StarWarsDestiny(self.bot)

View File

@ -0,0 +1,518 @@
import json
import string
class StarWarsChar():
def __init__(self, bot):
self.bot = bot
def getCharName(self, user : str):
self.bot.log("Getting name for "+self.bot.databaseFuncs.getName(user)+"'s character")
userCharacter = self.bot.database["starwars characters"].find_one({"_id":user})
if userCharacter != None:
self.bot.log("Name is "+userCharacter["Name"])
return userCharacter["Name"]
else:
self.bot.log("Just using "+self.bot.databaseFuncs.getName(user))
return self.bot.databaseFuncs.getName(user)
def setUpDict(self, cmd : dict):
self.bot.log("Setting up a dictionary in a nice way")
if bool(cmd):
keys = list(cmd)
values = list(cmd.values())
result = ""
if isinstance(values[0],dict):
return ", ".join(values)
else:
for x, key in enumerate(keys):
if type(key) is list:
if x%3 != 2:
result += "**" + key + "**" + ": " + ", ".join(values[x]) + " "
else:
result += "**" + key + "**" + ": " + ", ".join(values[x]) + "\n"
else:
if x%3 != 2:
result += "**" + key + "**" + ": " + str(values[x]) + " "
else:
result += "**" + key + "**" + ": " + str(values[x]) + "\n"
self.bot.log("Returning a dictionary, but well formatted")
return result
else:
self.bot.log("Couldn't find anything")
return "There doesn't seem to be anything here..."
def lookUp(self, data : dict, key : str, cmd : str = ""):
if cmd == " ":
cmd = ""
elif cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
self.bot.log("Looking up "+key)
if key in data:
self.bot.log(key+" exists")
if cmd == "":
if type(data[key]) is dict and key != "Weapons":
return self.setUpDict(data[key])
elif key == "Weapons":
self.bot.log("Does this even get used? I'm too scared to delete it")
if bool(data[key]):
self.bot.log("Found "+(", ".join(list(data[key]))))
return ", ".join(list(data[key]))
else:
self.bot.log("There is nothing here")
return "There doesn't seem to be anything here..."
else:
if str(data[key]) != "":
self.bot.log("Returning "+str(data[key]))
return data[key]
else:
self.bot.log("There was nothing there")
return "There doesn't seem to be anything here"
elif cmd[0] == '+':
self.bot.log("Trying to add to "+key)
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Yeah, that fucked up")
return "Can't do that"
if type(data[key]) is int:
try:
newValue = data[key] + int(cmd)
data[key] = newValue
self.bot.log("Added "+cmd+" to "+key)
return data
except:
self.bot.log("Couldn't add "+cmd+" to "+key)
return "Can't add that"
elif type(data[key]) is list:
try:
data[key].append(cmd)
self.bot.log("Added "+cmd+" to "+key)
return data
except:
self.bot.log("Couldn't add "+cmd+" to "+key)
return "Can't add that"
else:
self.bot.log("Yeah, I can't add that to "+key)
return "Can't add that"
elif cmd[0] == '-':
self.bot.log("Trying to remove/subtract from "+key)
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Yeah, that fucked up")
return "Can't do that"
if type(data[key]) is int:
try:
newValue = data[key] - int(cmd)
data[key] = newValue
self.bot.log("Subtracted "+cmd+" from "+key)
return data
except:
self.bot.log("Couldn't subtract "+cmd+" from "+key)
return "Can't remove that"
elif type(data[key]) is list:
try:
data[key].remove(cmd)
self.bot.log("Removed "+cmd+" from "+key)
return data
except:
self.bot.log("Couldn't remove "+cmd+" from "+key)
return "Can't remove that"
else:
self.bot.log("Yeah, I can't remove/subtract that from "+key)
return "Can't remove that"
else:
while cmd[0] == ' ':
cmd = cmd[1:]
if type(data[key]) is dict:
newKey = cmd.split(" ")[0]
cmd = cmd[len(newKey):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
self.bot.log("Looking up "+newKey+" in "+key)
lookUpResult = self.lookUp(data[key],newKey,cmd)
if type(lookUpResult) is dict:
data[key] = lookUpResult
return data
else:
return lookUpResult
elif type(data[key]) != list:
self.bot.log("Trying to change "+key+" to "+cmd)
try:
cmd = type(data[key])(cmd)
data[key] = cmd
self.bot.log("Did that")
return data
except:
self.bot.log("No. That did not work")
return "Wrong data type"
else:
self.bot.log("Yeah, that didn't work")
return "Wrong data type"
else:
self.bot.log("Couldn't find "+key)
self.bot.log("Testing to see if it's a multi-word key")
cmd = key + " " + cmd
words = cmd.split(" ")
search = ""
i = 0
while search not in data:
try:
search += " " + words[i]
i += 1
except:
self.bot.log("It wasn't. "+search+" doesn't exist")
return search + " doesn't exist"
if search[0] == " ":
search = search[1:]
self.bot.log("Yeah! Did that! The key was "+search)
cmd = cmd[len(search):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
self.bot.log("Returning "+search)
return self.setUpDict(data[search])
else:
newKey = cmd.split(" ")[0]
cmd = cmd[len(newKey):]
if cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
lookUpResult = self.lookUp(data[search],newKey,cmd)
if type(lookUpResult) is dict:
data[search] = lookUpResult
return data
else:
return lookUpResult
def characterSheet(self,character : dict):
self.bot.log("Setting up a character sheet for "+character["Name"])
divider = "--------------------\n"
name = character["Name"]
textf = ""
if character["Force-rating"] != 0:
textf = "\n**Force Rating**: "+str(character["Force-rating"])
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 = self.setUpDict(character["Characteristics"])
text4 = self.setUpDict(character["Skills"])
text5 = ""
text6 = ""
text7 = ""
text8 = ""
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"
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"]))
return name, text1+text2+"\n\n"+text3+divider+text4+"\n"+divider+text5+text6+text7+text8
def charData(self,user : str,cmd : str):
userCharacter = self.bot.database["starwars characters"].find_one({"_id":user})
key = string.capwords(cmd.split(" ")[0])
cmd = cmd[len(key):]
if cmd == " ":
cmd = ""
elif cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
self.bot.log("Looking for "+self.bot.databaseFuncs.getName(user)+"'s character")
if userCharacter != None:
self.bot.log("Found it! Looking for "+key+" in the data")
if key in userCharacter:
self.bot.log("Found it!")
if type(userCharacter[key]) is dict:
self.bot.log("It's a dictionary!")
if cmd == "":
self.bot.log("Retrieving data")
if key == "Weapons":
if bool(userCharacter[key]):
self.bot.log("Returning a list of weapons")
return ", ".join(list(userCharacter[key]))
else:
self.bot.log("The character doesn't have any weapons. Which is probably for the best. Like, who just walks around with weapons? (error code 941)")
return "There doesn't seem to be anything there... (error code 941)"
else:
return self.setUpDict(userCharacter[key])
elif cmd[0] == "+":
self.bot.log("Gonna add something!!!")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Nope. That didn't happen (error code 942)")
return "Can't do that (error code 942)"
if (key == "Talents" or key == "Force-powers") and "," in cmd:
cmd = cmd.split(",")
while cmd[1][0] == " ":
cmd[1] = cmd[1][1:]
self.bot.log("Adding "+cmd[0]+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key+"."+cmd[0] : cmd[1]}})
return cmd[0]+" added to "+key+" for " + userCharacter["Name"]
elif key == "Obligations" and "," in cmd:
cmd = cmd.split(",")
while cmd[1][0] == " ":
cmd[1] = cmd[1][1:]
self.bot.log("Adding "+cmd[0]+" to "+key)
try:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key+"."+cmd[0] : int(cmd[1])}})
except:
self.bot.log("Fucked that up (error code 949)")
return "Wrong data type (error code 949)"
return cmd[0]+" added to "+key+" for " + userCharacter["Name"]
elif key == "Weapons":
with open("resources/starWars/starwarstemplates.json", "r") as f:
templates = json.load(f)
newWeapon = templates["Weapon"]
self.bot.log("Adding "+cmd+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key+"."+cmd : newWeapon}})
return cmd+" added to weapons for " + userCharacter["Name"]
else:
self.bot.log("That's not happening (error code 947d)")
return "Can't add that (error code 947d)"
elif cmd[0] == "-":
self.bot.log("Gonna subtract/remove something")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("AAAAAAAAAAAA (error code 948)")
return "Can't do that (error code 948)"
if key == "Talents" or key == "Force-powers" or key == "Weapons" or key == "Obligations":
self.bot.log("Trying to remove "+cmd+" from "+key)
if cmd in userCharacter[key]:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$unset": {cmd}})
self.bot.log("I did that")
return cmd+" removed from "+key+" from "+userCharacter["Name"]
else:
self.bot.log("Welp. I fucked that up (error code 946e)")
return "Can't remove that (error code 946e)"
else:
self.bot.log("Urgh! (error code 946d)")
return "Can't remove that (error code 946d)"
else:
self.bot.log("Looking up "+cmd+" in "+key)
if key == "Talents" or key == "Force-powers":
newKey = cmd
newcmd = ""
else:
newKey = string.capwords(cmd.split(" ")[0])
newcmd = cmd[len(newKey):]
lookUpResult = self.lookUp(userCharacter[key],newKey,newcmd)
if type(lookUpResult) is dict:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key : lookUpResult}})
return "Changed " + userCharacter["Name"] + "'s " + key
else:
return lookUpResult
else:
if cmd == "":
self.bot.log("Retrieving data")
if type(userCharacter[key]) is list:
return key+":\n"+", ".join(userCharacter[key])
else:
return userCharacter[key]
elif cmd[0] == '+':
self.bot.log("Adding")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("Error message (error code 948)")
return "Can't do that (error code 948)"
if type(userCharacter[key]) is int:
try:
self.bot.log("Adding "+cmd+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$inc": {key : int(cmd)}})
return "Added " + cmd + " to " + userCharacter["Name"] + "'s " + key
except:
self.bot.log("BITCH SANDWICH (error code 947c)")
return "Can't add that (error code 947c)"
elif type(userCharacter[key]) is list:
try:
self.bot.log("Adding "+cmd+" to "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$push": {key : cmd}})
return "Added " + cmd + " to " + userCharacter["Name"] + "'s " + key
except:
self.bot.log("tstststststs (error code 947b)")
return "Can't add that (error code 947b)"
else:
self.bot.log("Help (error code 947a)")
return "Can't add that (error code 947a)"
elif cmd[0] == '-':
self.bot.log("Removing/subtracting")
try:
cmd = cmd[1:]
while cmd[0] == ' ':
cmd = cmd[1:]
except:
self.bot.log("lalalala (error code 948)")
return "Can't do that (error code 948)"
if type(userCharacter[key]) is int:
try:
self.bot.log("Subtracting "+cmd+" from "+key)
self.bot.database["starwars characters"].update_one({"_id":user},
{"$inc": {key : -int(cmd)}})
return "Subtracted " + cmd + " from " + userCharacter["Name"] + "'s " + key
except:
self.bot.log("Tried it. Didn't want to (error code 946c)")
return "Can't remove that (error code 946c)"
elif type(userCharacter[key]) is list:
try:
self.bot.log("removing "+cmd+" from "+key)
try:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$pull": {key : cmd}})
except:
self.bot.log("They can only remove stuff that's actually in the list")
return "Not in list (error code 944b)"
return "Removed " + cmd + " from " + userCharacter["Name"] + "'s " + key
except:
self.bot.log("nah (error code 946b)")
return "Can't remove that (error code 946b)"
else:
self.bot.log("nyope (error code 946a)")
return "Can't remove that (error code 946a)"
else:
self.bot.log("Changing "+key+" to "+cmd)
if type(userCharacter[key]) is int:
try:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key : int(cmd)}})
except:
self.bot.log("I don't wanna tho (error code 945b)")
return "Can't do that (error code 945b)"
elif type(userCharacter[key]) is str:
self.bot.database["starwars characters"].update_one({"_id":user},
{"$set": {key : cmd}})
else:
self.bot.log("I don't wanna tho (error code 945a)")
return "Can't do that (error code 945a)"
return "Changed " + userCharacter["Name"] + "'s " + key +" to " + cmd
else:
self.bot.log(key+" isn't in there (error code 944)")
return "Couldn't find that data. Are you sure you spelled it correctly? (error code 944)"
else:
self.bot.log(user+" doesn't have a character (error code 943)")
return "You don't have a character. You can make one with !starwarscharacter (error code 943)"
def replaceSpaces(self,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, value in enumerate(withoutSpaces):
cmd = cmd.replace(withSpaces[x],value)
return cmd
def replaceWithSpaces(self,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, value in enumerate(withoutSpaces):
cmd = cmd.replace(value,withSpaces[x])
return cmd
def parseChar(self,user : str, cmd : str):
cmd = self.replaceSpaces(cmd)
userCharacter = self.bot.database["starwars characters"].find_one({"_id":user})
if cmd == " ":
cmd = ""
elif cmd != "":
while cmd[0] == " ":
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
if userCharacter != None:
text1, text2 = self.characterSheet(userCharacter)
return text1, self.replaceWithSpaces(text2)
else:
self.bot.log("Makin' a character for "+self.bot.databaseFuncs.getName(user))
with open("resources/starWars/starwarstemplates.json", "r") as f:
templates = json.load(f)
newChar = templates["Character"]
newChar["_id"] = user
self.bot.database["starwars characters"].insert_one(newChar)
return "", "Character for " + self.bot.databaseFuncs.getName(user) + " created"
else:
if cmd == "Purge":
self.bot.log("Deleting "+self.bot.databaseFuncs.getName(user)+"'s character")
self.bot.database["starwars characters"].delete_one({"_id":user})
return "", "Character for " + self.bot.databaseFuncs.getName(user) + " deleted"
else:
return "", self.replaceWithSpaces(str(self.charData(user,cmd)))
def lightsaberChar(self,user : str):
userCharacter = self.bot.database["starwars characters"].find_one({"_id":user})
if userCharacter != None:
return userCharacter["Lightsaber-characteristic"]
def userHasChar(self,user : str):
userCharacter = self.bot.database["starwars characters"].find_one({"_id":user})
return userCharacter != None

View File

@ -0,0 +1,66 @@
class StarWarsDestiny():
def __init__(self, bot):
self.bot = bot
def destinyNew(self, num : int):
self.bot.log("Creating a new destiny pool with "+str(num)+" players")
roll, diceResults = self.bot.starwarsroll.roll(0,0,0,0,0,0,num)
roll = "".join(sorted(roll))
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(roll)
return "Rolled for Destiny Points and got:\n"+self.bot.starwarsroll.diceResultToEmoji(diceResults)+"\n"+self.bot.starwarsroll.resultToEmoji(roll)
def destinyUse(self, user : str):
with open("resources/starWars/destinyPoints.txt","rt") as f:
points = f.read()
if user == "Nikolaj":
self.bot.log("Trying to use a dark side destiny point")
if 'B' in points:
points = points.replace("B","L",1)
points = "".join(sorted(points))
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
self.bot.log("Did it")
return "Used a dark side destiny point. Destiny pool is now:\n"+self.bot.starwarsroll.resultToEmoji(points)
else:
self.bot.log("There were no dark side destiny points")
return "No dark side destiny points"
else:
self.bot.log("Trying to use a light side destiny point")
if 'L' in points:
points = points.replace("L","B",1)
points = "".join(sorted(points))
with open("resources/starWars/destinyPoints.txt","wt") as f:
f.write(points)
self.bot.log("Did it")
return "Used a light side destiny point. Destiny pool is now:\n"+self.bot.starwarsroll.resultToEmoji(points)
else:
self.bot.log("There were no dark side destiny points")
return "No light side destiny points"
def parseDestiny(self, user : str, cmd : str):
if cmd != "":
while cmd[0] == ' ':
cmd = cmd[1:]
if cmd == "":
break
if cmd == "":
self.bot.log("Retrieving destiny pool info")
with open("resources/starWars/destinyPoints.txt","rt") as f:
return self.bot.starwarsroll.resultToEmoji(f.read())
else:
commands = cmd.upper().split(" ")
if commands[0] == "N":
if len(commands) > 1:
return self.destinyNew(int(commands[1]))
else:
return "You need to give an amount of players (error code 921)"
elif commands[0] == "U":
return self.destinyUse(user)
else:
return "I didn't quite understand that (error code 922)"

View File

@ -0,0 +1,378 @@
import random
import re
import string
import json
with open("resources/starWars/starwarsskills.json", "r") as f:
skillData = json.load(f)
class StarWarsRoll():
def __init__(self, bot):
self.bot = bot
# Rolls the specified dice
def roll(self, abi : int = 1, prof : int = 0, dif : int = 3, cha : int = 0, boo : int = 0, setb : int = 0, force : int = 0):
result = ""
diceResult = []
for _ in range(abi):
choice = random.choice(["","S","S","SS","A","A","SA","AA"])
result += choice
diceResult.append("abi"+choice)
for _ in range(prof):
choice = random.choice(["","S","S","SS","SS","A","SA","SA","SA","AA","AA","R"])
result += choice
diceResult.append("prof"+choice)
for _ in range(dif):
choice = random.choice(["","F","FF","H","H","H","HH","FH"])
result += choice
diceResult.append("dif"+choice)
for _ in range(cha):
choice = random.choice(["","F","F","FF","FF","H","H","FH","FH","HH","HH","D"])
result += choice
diceResult.append("cha"+choice)
for _ in range(boo):
choice = random.choice(["","","S","SA","AA","A"])
result += choice
diceResult.append("boo"+choice)
for _ in range(setb):
choice = random.choice(["","","F","F","H","H"])
result += choice
diceResult.append("setb"+choice)
for _ in range (force):
choice = random.choice(["B","B","B","B","B","B","BB","L","L","LL","LL","LL"])
result += choice
diceResult.append("force"+choice)
return result, diceResult
# Lets dice cancel each other out
def simplify(self, result : str):
self.bot.log("Simplifying "+result)
simp = ""
success = (result.count('S') + result.count('R')) - (result.count('F') + result.count('D'))
advantage = result.count('A') - result.count('H')
result = re.sub("S|A|F|H","",result)
if success > 0:
for _ in range(success):
simp += "S"
elif success < 0:
for _ in range(abs(success)):
simp += "F"
if advantage > 0:
for _ in range(advantage):
simp += "A"
elif advantage < 0:
for _ in range(abs(advantage)):
simp += "H"
simp += result
return simp
# Returns emoji that symbolize the dice results
def diceResultToEmoji(self, diceResults : list):
emoji = ""
for result in diceResults:
if result == "abiA":
emoji += "<:abil1a:695267684476125264> "
elif result == "abiSA":
emoji += "<:abil1a1s:695267684484513842> "
elif result == "abiS":
emoji += "<:abil1s:695267684514005013> "
elif result == "abiAA":
emoji += "<:abil2a:695267684547428352> "
elif result == "abiSS":
emoji += "<:abil2s:695267684761206914> "
elif result == "abi":
emoji += "<:abilbla:695267684660674602> "
elif result == "profA":
emoji += "<:prof1a:695267685361123338> "
elif result == "profSA":
emoji += "<:prof1a1s:695267685067653140> "
elif result == "profR":
emoji += "<:prof1r:695267685067522088> "
elif result == "profS":
emoji += "<:prof1s:695267684899881012> "
elif result == "profAA":
emoji += "<:prof2a:695267684996218982> "
elif result == "profSS":
emoji += "<:prof2s:695267684878647327> "
elif result == "prof":
emoji += "<:profbla:695267684698292235> "
elif result == "difF":
emoji += "<:dif1f:695267684924915804> "
elif result == "difH":
emoji += "<:dif1h:695267684908138506> "
elif result == "difFH":
emoji += "<:dif1h1f:695267684908269678> "
elif result == "difFF":
emoji += "<:dif2f:695267684924784680> "
elif result == "difHH":
emoji += "<:dif2h:695267685071585340> "
elif result == "dif":
emoji += "<:difbla:695267685000544276> "
elif result == "chaD":
emoji += "<:cha1d:695267684962533447> "
elif result == "chaF":
emoji += "<:cha1f:695267684601954346> "
elif result == "chaH":
emoji += "<:cha1h:695267685046681620> "
elif result == "chaFH":
emoji += "<:cha1h1f:695267685063327784> "
elif result == "chaFF":
emoji += "<:cha2f:695267684832641097> "
elif result == "chaHH":
emoji += "<:cha2h:695267684631183381> "
elif result == "cha":
emoji += "<:chabla:695267684895686787> "
elif result == "booA":
emoji += "<:boo1a:695267684975116329> "
elif result == "booSA":
emoji += "<:boo1a1s:695267684970922024> "
elif result == "booS":
emoji += "<:boo1s:695267684979441714> "
elif result == "booAA":
emoji += "<:boo2a:695267685100945488> "
elif result == "boo":
emoji += "<:boobla:695267684757012550> "
elif result == "setbF":
emoji += "<:set1f:695267685054939197> "
elif result == "setbH":
emoji += "<:set1h:695267685147082802> "
elif result == "setb":
emoji += "<:setbla:695267685151408169> "
elif result == "forceB":
emoji += "<:for1b:695267684593434677> "
elif result == "forceL":
emoji += "<:for1l:695267684606148640> "
elif result == "forceBB":
emoji += "<:for2b:695267684903944303> "
elif result == "forceLL":
emoji += "<:for2l:695267684992024626> "
return emoji
# Returns emoji that symbolize the results of the dice rolls
def resultToEmoji(self, result : str):
emoji = ""
for char in result:
if char == 'S':
emoji += "<:success:826026925280854026> "
elif char == 'A':
emoji += "<:advantage:826026925515604009> "
elif char == 'R':
emoji += "<:triumph:826026925319127070> "
elif char == 'F':
emoji += "<:failure:826026925288980511> "
elif char == 'H':
emoji += "<:threat:826026925280985108> "
elif char == 'D':
emoji += "<:despair:826026925272203294> "
elif char == 'L':
emoji += "<:light:826026925059211295>"
elif char == 'B':
emoji += "<:dark:826026925289373717>"
return emoji
# Converts emoji into letters
def emojiToResult(self, emoji : str):
result = ""
for char in emoji:
if char == "<:light:691010089905029171>":
emoji += 'L'
if char == "<:dark:691010101901000852>":
emoji += 'B'
return result
# Returns emoji that symbolize the dice
def diceToEmoji(self, dice : list):
emoji = ""
for _ in range(dice[0]):
emoji += "<:ability:690974213397282826> "
for _ in range(dice[1]):
emoji += "<:proficiency:690973435354153071> "
for _ in range(dice[2]):
emoji += "<:difficulty:690973992470708296> "
for _ in range(dice[3]):
emoji += "<:challenge:690973419906400306> "
for _ in range(dice[4]):
emoji += "<:boost:690972178216386561> "
for _ in range(dice[5]):
emoji += "<:setback:690972157890658415> "
for _ in range(dice[6]):
emoji += "<:force:690973451883774013> "
return emoji
# Rolls for obligation
def obligationRoll(self):
self.bot.log("Rolling for obligation")
data = self.bot.database["starwarscharacters"]
table = []
for character in data:
for obligation in data[character]["Obligations"]:
for _ in range(data[character]["Obligations"][obligation]):
table.append(data[character]["Name"]+", "+obligation)
while len(table) < 100:
table.append("Nothing")
return random.choice(table)
# Rolls for critical injury
def critRoll(self, addington : int):
dd = "<:difficulty:690973992470708296>"
sd = "<:setback:690972157890658415>"
bd = "<:boost:690972178216386561>"
roll = random.randint(1,100) + addington
injuries = [
"**Minor nick**: The target suffers 1 strain, "+dd] * 5 + [
"**Slowed down**: The target can only act during the last allied initiative slot this turn, "+dd] * 5 + [
"**Sudden Jolt**: The target drops whatever is in hand, "+dd] * 5 + [
"**Distracted**: The target cannot perform a Free maneuver during his next turn, "+dd] * 5 + [
"**Off-Balance**: The target adds "+sd+" to his next skill check, "+dd] * 5 + [
"**Discouraging Wound**: Flip one light side Destiny point to a dark side Destiny point (reverse if NPC), "+dd] * 5 + [
"**Stunned**: The target is staggered until the end of his next turn, "+dd] * 5 + [
"**Stinger**: Increase the difficulty of next check by one, "+dd] * 5 + [
"**Bowled Over**: The target is knocked prone and suffers 1 sttrain, "+dd+dd] * 5 + [
"**Head Ringer**: The target increases the difficulty of all Intellect and Cunning checks by one until the end of the encounter, "+dd+dd] * 5 + [
"**Fearsome Wound**: The target increases the difficulty of all Presence and Willpower checks by one until the end of the encounter, "+dd+dd] * 5 + [
"**Agonizing Wound**: The target increases the difficulty of all Brawn and Agility checks by one until the end of the encounter, "+dd+dd] * 5 + [
"**Slightly Dazed**: The target is disoriented until the end of the encounter, "+dd+dd] * 5 + [
"**Scattered Senses**: The target removes all "+bd+" from skill checks until the end of the encounter, "+dd+dd] * 5 + [
"**Hamstrung**: The target loses his free maneuver until the end of the encounter, "+dd+dd] * 5 + [
"**Overpowered**: The target leaves himselp open, and the attacker may immediately attempt another free attack agains him, using the exact same pool as the original, "+dd+dd] * 5 + [
"**Winded**: Until the end of the encounter, the target cannot voluntarily suffer strain to activate any abilities or gain additional maneuvers, "+dd+dd] * 5 + [
"**Compromised**: Incerase difficulty of all skill checks by one until the end of the encounter, "+dd+dd] * 5 + [
"**At the brink**: The target suffers 1 strain each time he performs an action, "+dd+dd+dd] * 5 + [
"**Crippled**: One of the target's limbs (selected by the GM) is crippled until healed or replaced. Increase difficulty of all checks that require use of that limb by one, "+dd+dd+dd] * 5 + [
"**Maimed**: One of the target's limbs (selected by the GM) is permanently lost. Unless the target has a cybernetic replacement, the target cannot perform actions that would require the use of that limb. All other actions gain "+sd+", "+dd+dd+dd] * 5 + [
"HI"] * 5 + [
"**Temporarily Lame**: Until this critical injury is healed, the target cannot perform more than one maneuver during his turn, "+dd+dd+dd] * 5 + [
"**Blinded**: The target can no longer see. Upgrade the difficulty of all checks twice. Upgrade the difficulty of perception checks three times, "+dd+dd+dd] * 5 + [
"**Knocked Senseless**: The target is staggered for the remainder of the encounter, "+dd+dd+dd] * 5 + [
"GI"] * 5 + [
"**Bleeding Out**: Every round, the target suffers 1 wound and 1 strain at the beginning of his turn. For every five wounds he suffers beyond his wound threshold, he suffers one additional critical injury. (If he suffers this one again, roll again), "+dd+dd+dd+dd] * 10 + [
"**The End is Nigh**: The target will die after the last initiative slot during the next round, "+dd+dd+dd+dd] * 10 + [
"**Dead**: U B Dead :("]
if roll >= len(injuries):
results = injuries[-1]
else:
results = injuries[roll]
if results == "HI":
characteristic = random.choice(["brawn"] * 3 + ["agility"] * 3 + ["intellect", "cunning", "presence"])
results = "**Horrific Injury**: Until this criticil injury is healed, treat the target's "+characteristic+" as if it's one lower, "+dd+dd+dd
if results == "GI":
characteristic = random.choice(["brawn"] * 3 + ["agility"] * 3 + ["intellect", "cunning", "presence"])
results = "**Gruesome Injury**: The target's "+characteristic+" is permanently one lower, "+dd+dd+dd+dd
return "Roll: "+str(roll)+"\nInjury:\n"+results
# Parses the command into something the other functions understand
def parseRoll(self, user : str,cmd : str = ""):
cmd = re.sub(' +',' ',cmd.upper()) + " "
if cmd[0] == " ":
cmd = cmd[1:]
cmd = self.bot.starwarschar.replaceSpaces(string.capwords(cmd))
commands = cmd.split(" ")
if commands[0] == "":
rollParameters = [1,0,3,0,0,0,0]
else:
rollParameters = [0,0,0,0,0,0,0]
if string.capwords(commands[0]) == "Obligations":
try:
return self.obligationRoll()
except:
self.bot.log("Obligation fucked up (error code 911)")
return "An error ocurred (error code 911)"
elif string.capwords(commands[0]) in skillData:
self.bot.log("Oh look! This guy has skills!")
if self.bot.starwarschar.userHasChar:
self.bot.log("They have a character. That much we know")
skillLevel = self.bot.starwarschar.charData(user,"Skills " + string.capwords(commands[0]))
if string.capwords(commands[0]) == "Lightsaber":
self.bot.log("The skill is lightsaber")
charLevel = self.bot.starwarschar.charData(user,"Characteristics " + self.bot.starwarschar.lightsaberChar(user))
else:
charLevel = self.bot.starwarschar.charData(user,"Characteristics " + skillData[string.capwords(commands[0])])
abilityDice = abs(charLevel-skillLevel)
proficiencyDice = min(skillLevel,charLevel)
commands = [str(abilityDice)] + [str(proficiencyDice)] + commands[1:]
self.bot.log("Converted skill to dice")
else:
self.bot.log("Okay, no they don't i guess (error code 912)")
return "You don't have a user. You can make one with !starwarscharacter (error code 912)"
elif string.capwords(commands[0]) in ["Ranged","Piloting"]:
self.bot.log("They fucked up writing the name of a ranged or piloting skill")
if string.capwords(commands[0]) == "Ranged":
return "Did you mean \"Ranged - Heavy\" or \"Ranged - Light\" (error code 913)"
else:
return "Did you mean \"Piloting - Planetary\" or \"Piloting - Space\" (error code 913)"
try:
self.bot.log("Converting commands to dice")
for x, command in enumerate(commands):
if command != "":
command = command.upper()
if command[0] == "A":
rollParameters[0] = int(command.replace("A",""))
elif command[0] == "P":
rollParameters[1] = int(command.replace("P",""))
elif command[0] == "D":
rollParameters[2] = int(command.replace("D",""))
elif command[0] == "C":
rollParameters[3] = int(command.replace("C",""))
elif command[0] == "B":
rollParameters[4] = int(command.replace("B",""))
elif command[0] == "S":
rollParameters[5] = int(command.replace("S",""))
elif command[0] == "F":
rollParameters[6] = int(command.replace("F",""))
else:
rollParameters[x] = int(command)
except:
self.bot.log("Someone fucked u-up! (it was them) (error code 914)")
return "Invalid input! (error code 914)"
self.bot.log("Rolling "+str(rollParameters))
rollResults, diceResults = self.roll(rollParameters[0],rollParameters[1],rollParameters[2],rollParameters[3],rollParameters[4],rollParameters[5],rollParameters[6])
simplified = self.simplify(rollResults)
name = self.bot.starwarschar.getCharName(user)
self.bot.log("Returns results and simplified results")
if simplified == "":
return name + " rolls: " + "\n" + self.diceResultToEmoji(diceResults) + "\nEverything cancels out!"
else:
return name + " rolls: " + "\n" + self.diceResultToEmoji(diceResults) + "\n" + self.resultToEmoji(simplified)