🥅 Error codes

This commit is contained in:
NikolajDanger
2020-07-29 12:14:30 +02:00
parent ef434ecee8
commit b991ac0385
10 changed files with 489 additions and 280 deletions

View File

@ -40,8 +40,8 @@ def giveMoney(user,targetUser,amount):
addMoney(targetUser,amount)
return "Transferred "+str(amount)+" GwendoBucks to "+user
else:
logThis("They didn't have enough GwendoBucks")
return "You don't have that many GwendoBucks"
logThis("They didn't have enough GwendoBucks (error code 1223b)")
return "You don't have that many GwendoBucks (error code 1223b)"
else:
logThis("They didn't have enough GwendoBucks")
return "You don't have that many GwendoBucks"
logThis("They didn't have enough GwendoBucks (error code 1223a)")
return "You don't have that many GwendoBucks (error code 1223a)"

View File

@ -43,8 +43,8 @@ def triviaStart(channel : str):
return question, answers, correctAnswer
else:
logThis("There was already a trivia question for that channel")
return "There's already a trivia question going on. Try again in like, a minute", "", ""
logThis("There was already a trivia question for that channel (error code 1106)")
return "There's already a trivia question going on. Try again in like, a minute (error code 1106)", "", ""
# Lets players answer a trivia question
def triviaAnswer(user : str, channel : str, command : str):
@ -63,11 +63,14 @@ def triviaAnswer(user : str, channel : str, command : str):
return "Locked in "+user+"'s answer"
else:
return user+" has already answered this question"
logThis(user+" has already answered this question (error code 1105)")
return user+" has already answered this question (error code 1105)"
else:
return "There's no question right now"
logThis("There's no question right now (error code 1104)")
return "There's no question right now (error code 1104)"
else:
return "I didn't quite understand that"
logThis("I didn't quite understand that (error code 1103)")
return "I didn't quite understand that (error code 1103)"
# Adds 1 GwendoBuck to each player that got the question right and deletes question from games.json.
@ -84,6 +87,6 @@ def triviaCountPoints(channel : str):
else:
logThis("Couldn't find the question")
logThis("Couldn't find the question (error code 1102)")
return None

View File

@ -20,8 +20,8 @@ def monsterFunc(command):
# 1-letter monsters don't exist
if len(command) < 2:
logThis("Monster doesn't exist in database")
return("I don't know that monster...","","","","","")
logThis("Monster name too short (error code 601)")
return("I don't know that monster... (error code 601)","","","","","")
else:
# Opens "mensters.json"
data = json.load(open('resources/monsters.json', encoding = "utf8"))
@ -117,8 +117,8 @@ def monsterFunc(command):
logThis("Returning monster information")
return(str(command),text1,text2,text3,text4,text5)
logThis("Couldn't find monster")
return("I don't know that monster...","","","","","")
logThis("Monster not in database (error code 602)")
return("I don't know that monster... (error code 602)","","","","","")
# Looks up a spell
def spellFunc(command):
@ -130,7 +130,7 @@ def spellFunc(command):
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"]))
else:
logThis("I don't know that spell")
spell_output = "I don't think that's a spell"
logThis("I don't know that spell (error code 501)")
spell_output = "I don't think that's a spell (error code 501)"
logThis("Successfully ran !spell")
return(spell_output)

View File

@ -81,19 +81,23 @@ def imageFunc():
logThis("Searching for "+search)
# Searches for the image and reads the resulting web page
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
read = page.read()
tree = lxml.etree.HTML(read)
images = tree.xpath('//a[@class = "thumb"]/@href')
try:
page = urllib.request.urlopen("https://www.bing.com/images/search?q="+search+"&safesearch=off")
read = page.read()
tree = lxml.etree.HTML(read)
images = tree.xpath('//a[@class = "thumb"]/@href')
# Picks an image
number = random.randint(1,len(images))-1
image = images[number]
# Picks an image
number = random.randint(1,len(images))-1
image = images[number]
logThis("Picked image number "+str(number))
logThis("Picked image number "+str(number))
# Returns the image
logThis("Successfully returned an image")
# Returns the image
logThis("Successfully returned an image")
except:
image = "Couldn't connect to bing (error code 701)"
logThis("Couldn't connect to bing (error code 701)")
return(image)
def logThis(message : str):
@ -120,11 +124,11 @@ def findWikiPage(search : str):
else:
return page.title, content, ""
except:
logThis("Fucked up")
return "", "Sorry. Fucked that one up", ""
logThis("Fucked up (error code 1001)")
return "", "Sorry. Fucked that one up (error code 1001)", ""
else:
logThis("Couldn't find the page")
return "", "Couldn't find page", ""
logThis("Couldn't find the page (error code 1002)")
return "", "Couldn't find page (error code 1002)", ""
def makeFiles():
# Creates swcharacters.json if it doesn't exist

View File

@ -9,26 +9,38 @@ def movieFunc():
logThis("Creating IMDb object")
ia = imdb.IMDb()
logThis("Picking a movie")
movs = open("resources/movies.txt", "r")
movlist = movs.read().split("\n")
mov = random.choice(movlist)
movs.close()
try:
logThis("Picking a movie")
movs = open("resources/movies.txt", "r")
movlist = movs.read().split("\n")
mov = random.choice(movlist)
movs.close()
except:
logThis("Problem picking the movie (error code 801)")
return("error","801","","")
logThis("Searching for "+mov)
s_result = ia.search_movie(mov)
try:
logThis("Searching for "+mov)
s_result = ia.search_movie(mov)
except:
logThis("Couldn't find on imdb (error code 802)")
return("error","802","","")
logThis("Getting the data")
movie = s_result[0]
ia.update(movie)
cast = movie['cast']
pcast = ""
for x in range(3):
if cast[x]:
pcast += cast[x]['name']+", "
try:
logThis("Getting the data")
movie = s_result[0]
ia.update(movie)
cast = movie['cast']
pcast = ""
for x in range(3):
if cast[x]:
pcast += cast[x]['name']+", "
except:
logThis("Couldn't extract data (error code 803)")
return("error","803","","")
logThis("Successfully ran !movie")
return(movie['title'], movie['plot'][0].split("::")[0], movie['cover url'].replace("150","600").replace("101","404"), pcast[:-2])
except:
logThis("Something bad happened...")
return("error","","","")
logThis("Something bad happened... (error code 800)")
return("error","800","","")

View File

@ -265,8 +265,8 @@ def charData(user : str,cmd : str):
logThis("Returning a list of weapons")
return ", ".join(list(data[user][key]))
else:
logThis("The character doesn't have any weapons. Which is probably for the best. Like, who just walks around with weapons?")
return "There doesn't seem to be anything there..."
logThis("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 setUpDict(data[user][key])
elif cmd[0] == "+":
@ -276,8 +276,8 @@ def charData(user : str,cmd : str):
while cmd[0] == ' ':
cmd = cmd[1:]
except:
logThis("Nope. That didn't happen")
return "Can't do that"
logThis("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(",")
@ -297,8 +297,8 @@ def charData(user : str,cmd : str):
try:
data[user][key][cmd[0]] = int(cmd[1])
except:
logThis("Fucked that up")
return "Wrong data type"
logThis("Fucked that up (error code 949)")
return "Wrong data type (error code 949)"
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return cmd[0]+" added to "+key+" for " + data[user]["Name"]
@ -315,8 +315,8 @@ def charData(user : str,cmd : str):
return cmd+" added to weapons for " + data[user]["Name"]
else:
logThis("That's not happening")
return "Can't add that"
logThis("That's not happening (error code 947d)")
return "Can't add that (error code 947d)"
elif cmd[0] == "-":
logThis("Gonna subtract/remove something")
@ -325,8 +325,8 @@ def charData(user : str,cmd : str):
while cmd[0] == ' ':
cmd = cmd[1:]
except:
logThis("AAAAAAAAAAAA")
return "Can't do that"
logThis("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":
logThis("Trying to remove "+cmd+" from "+key)
@ -337,11 +337,11 @@ def charData(user : str,cmd : str):
logThis("I did that")
return cmd+" removed from "+key+" from "+data[user]["Name"]
else:
logThis("Welp. I fucked that up")
return "Can't remove that"
logThis("Welp. I fucked that up (error code 946e)")
return "Can't remove that (error code 946e)"
else:
logThis("Urgh!")
return "Can't remove that"
logThis("Urgh! (error code 946d)")
return "Can't remove that (error code 946d)"
else:
logThis("Looking up "+cmd+" in "+key)
@ -375,8 +375,8 @@ def charData(user : str,cmd : str):
while cmd[0] == ' ':
cmd = cmd[1:]
except:
logThis("Error message")
return "Can't do that"
logThis("Error message (error code 948)")
return "Can't do that (error code 948)"
if type(data[user][key]) is int:
try:
@ -387,8 +387,8 @@ def charData(user : str,cmd : str):
json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except:
logThis("BITCH SANDWICH")
return "Can't add that"
logThis("BITCH SANDWICH (error code 947c)")
return "Can't add that (error code 947c)"
elif type(data[user][key]) is list:
try:
logThis("Adding "+cmd+" to "+key)
@ -397,11 +397,11 @@ def charData(user : str,cmd : str):
json.dump(data,f,indent = 4)
return "Added " + cmd + " to " + data[user]["Name"] + "'s " + key
except:
logThis("tstststststs")
return "Can't add that"
logThis("tstststststs (error code 947b)")
return "Can't add that (error code 947b)"
else:
logThis("Help")
return "Can't add that"
logThis("Help (error code 947a)")
return "Can't add that (error code 947a)"
elif cmd[0] == '-':
logThis("Removing/subtracting")
try:
@ -409,8 +409,8 @@ def charData(user : str,cmd : str):
while cmd[0] == ' ':
cmd = cmd[1:]
except:
logThis("lalalala")
return "Can't do that"
logThis("lalalala (error code 948)")
return "Can't do that (error code 948)"
if type(data[user][key]) is int:
try:
@ -421,8 +421,8 @@ def charData(user : str,cmd : str):
json.dump(data,f,indent = 4)
return "Subtracted " + cmd + " from " + data[user]["Name"] + "'s " + key
except:
logThis("Tried it. Didn't want to")
return "Can't remove that"
logThis("Tried it. Didn't want to (error code 946c)")
return "Can't remove that (error code 946c)"
elif type(data[user][key]) is list:
try:
logThis("removing "+cmd+" from "+key)
@ -431,38 +431,39 @@ def charData(user : str,cmd : str):
data[user][key].remove(cmd)
except:
logThis("They can only remove stuff that's actually in the list")
return "Not in list"
return "Not in list (error code 944b)"
with open("resources/swcharacters.json", "w") as f:
json.dump(data,f,indent = 4)
return "Removed " + cmd + " from " + data[user]["Name"] + "'s " + key
except:
logThis("nah")
return "Can't remove that"
logThis("nah (error code 946b)")
return "Can't remove that (error code 946b)"
else:
logThis("nyope")
return "Can't remove that"
logThis("nyope (error code 946a)")
return "Can't remove that (error code 946a)"
else:
logThis("Changing "+key+" to "+cmd)
if type(data[user][key]) is int:
try:
data[user][key] = int(cmd)
except:
return "Can't do that"
logThis("I don't wanna tho (error code 945b)")
return "Can't do that (error code 945b)"
elif type(data[user][key]) is str:
data[user][key] = cmd
else:
logThis("I don't wanna tho")
return "Can't do that"
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:
json.dump(data,f,indent = 4)
return "Changed " + data[user]["Name"] + "'s " + key +" to " + cmd
else:
logThis(key+" isn't in there")
return "Couldn't find that data. Are you sure you spelled it correctly?"
logThis(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:
logThis(user+" doesn't have a character")
return "You don't have a character. You can make one with !swchar"
logThis(user+" doesn't have a character (error code 943)")
return "You don't have a character. You can make one with !swchar (error code 943)"
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"]

View File

@ -59,8 +59,8 @@ def parseDestiny(user : str, cmd : str):
if len(commands) > 1:
return destinyNew(int(commands[1]))
else:
return "You need to give an amount of players"
return "You need to give an amount of players (error code 921)"
elif commands[0] == "U":
return destinyUse(user)
else:
return "I didn't quite understand that"
return "I didn't quite understand that (error code 922)"

View File

@ -304,7 +304,11 @@ def parseRoll(user : str,cmd : str = ""):
rollParameters = [0,0,0,0,0,0,0]
if string.capwords(commands[0]) == "Obligations":
return obligationRoll()
try:
return obligationRoll()
except:
logThis("Obligation fucked up (error code 911)")
return "An error occured (error code 911)"
elif string.capwords(commands[0]) in skillData:
logThis("Oh look! This guy has skills!")
@ -324,15 +328,15 @@ def parseRoll(user : str,cmd : str = ""):
commands = [str(abilityDice)] + [str(proficiencyDice)] + commands[1:]
logThis("Converted skill to dice")
else:
logThis("Okay, no they don't i guess")
return "You don't have a user. You can make one with !swchar"
logThis("Okay, no they don't i guess (error code 912)")
return "You don't have a user. You can make one with !swchar (error code 912)"
elif string.capwords(commands[0]) in ["Ranged","Piloting"]:
logThis("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\""
return "Did you mean \"Ranged - Heavy\" or \"Ranged - Light\" (error code 913)"
else:
return "Did you mean \"Piloting - Planetary\" or \"Piloting - Space\""
return "Did you mean \"Piloting - Planetary\" or \"Piloting - Space\" (error code 913)"
try:
logThis("Converting commands to dice")
@ -356,8 +360,8 @@ def parseRoll(user : str,cmd : str = ""):
else:
rollParameters[x] = int(commands[x])
except:
logThis("Someone fucked u-up! (it was them)")
return "Invalid input!"
logThis("Someone fucked u-up! (it was them) (error code 914)")
return "Invalid input! (error code 914)"
logThis("Rolling "+str(rollParameters))
rollResults, diceResults = roll(rollParameters[0],rollParameters[1],rollParameters[2],rollParameters[3],rollParameters[4],rollParameters[5],rollParameters[6])