🥅 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

@ -22,21 +22,30 @@ meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
async def parseCommands(message,content):
# Sends the contents of a help file, as specified by the message.
if content.startswith("help"):
if content == "help" or content == "help ":
with codecs.open("resources/help/help.txt",encoding="utf-8") as f:
text = f.read()
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
await message.channel.send(embed = em)
else:
command = content.replace(" ","-")
logThis("Looking for "+command+".txt")
try:
with codecs.open("resources/help/"+command+".txt",encoding="utf-8") as f:
text = f.read()
em = discord.Embed(title = command.replace("help-","").capitalize(), description = text,colour = 0x59f442)
await message.channel.send(embed = em)
except:
await message.channel.send("Couldn't find help for that command")
try:
if content == "help" or content == "help ":
try:
with codecs.open("resources/help/help.txt",encoding="utf-8") as f:
text = f.read()
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
await message.channel.send(embed = em)
except:
logThis("Couldn't find help.txt (error code 101)")
await message.channel.send("Couldn't find help.txt (error code 101)")
else:
command = content.replace(" ","-")
logThis("Looking for "+command+".txt")
try:
with codecs.open("resources/help/"+command+".txt",encoding="utf-8") as f:
text = f.read()
em = discord.Embed(title = command.replace("help-","").capitalize(), description = text,colour = 0x59f442)
await message.channel.send(embed = em)
except:
logThis("Couldn't find help for that command (error code 102)")
await message.channel.send("Couldn't find help for that command (error code 102)")
except:
logThis("Something fucked up (error code 100)")
await message.channel.send("Something fucked up (error code 100)")
# Logs whatever you write in the message
if content.startswith("log "):
@ -44,244 +53,321 @@ async def parseCommands(message,content):
# Stops the bot
elif content.startswith("stop"):
if message.author.display_name == "Nikolaj":
await message.channel.send("Logging out...")
try:
if message.author.display_name == "Nikolaj":
await message.channel.send("Logging out...")
with open("resources/games/games.json","r") as f:
data = json.load(f)
data["trivia questions"] = {}
data["blackjack games"] = {}
data["4 in a row games"] = {}
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
with open("resources/games/games.json","r") as f:
data = json.load(f)
data["trivia questions"] = {}
data["blackjack games"] = {}
data["4 in a row games"] = {}
with open("resources/games/games.json","w") as f:
json.dump(data,f,indent=4)
await client.logout()
else:
logThis(message.author.display_name+" tried to run stop me!")
await message.channel.send("I don't think I will, "+message.author.display_name)
await client.logout()
else:
logThis(message.author.display_name+" tried to run stop me! (error code 201)")
await message.channel.send("I don't think I will, "+message.author.display_name+" (error code 201)")
except:
logThis("Something fucked up (error code 200)")
await message.channel.send("Something fucked up (error code 200)")
# Does a hello with the helloFunc function from funcs/gwendolynpy
elif content.startswith("hello"):
await message.channel.send(helloFunc(message.author.display_name))
try:
await message.channel.send(helloFunc(message.author.display_name))
except:
logThis("Something fucked up (error code 310)")
await message.channel.send("Something fucked up (error code 310)")
# Rolls dice with the roll_dice function from funcs/roll/dice.py
elif content.startswith("roll"):
if content == "roll" or content == "roll ":
await message.channel.send(roll_dice(message.author.display_name))
else:
await message.channel.send(roll_dice(message.author.display_name, content.replace("roll","")))
try:
if content == "roll" or content == "roll ":
await message.channel.send(roll_dice(message.author.display_name))
else:
await message.channel.send(roll_dice(message.author.display_name, content.replace("roll","")))
except:
logThis("Something fucked up (error code 400)")
await message.channel.send("Something fucked up (error code 400)")
# Looks up a spell with the spellFunc function from funcs/lookup/lookuppy
elif content.startswith("spell "):
await message.channel.send(spellFunc(cap(content.replace("spell",""))))
try:
await message.channel.send(spellFunc(cap(content.replace("spell",""))))
except:
logThis("Something fucked up (error code 500)")
await message.channel.send("Something fucked up (error code 500)")
# Looks up a monster with the monsterFuncs() from funcs/lookup/lookuppy
elif content.startswith("monster "):
title, text1, text2, text3, text4, text5 = monsterFunc(cap(content.replace("monster","")))
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
try:
title, text1, text2, text3, text4, text5 = monsterFunc(cap(content.replace("monster","")))
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
# Sends the received information. Seperates into seperate messages if
# there is too much text
await message.channel.send(embed = em1)
if text2 != "":
if len(text2) < 2048:
em2 = discord.Embed(title = "Special Abilities", description = text2, colour=0xDEADBF)
await message.channel.send(embed = em2)
else:
em2 = discord.Embed(title = "Special Abilities", description = text2[:2048], colour=0xDEADBF)
await message.channel.send(embed = em2)
em2_2 = discord.Embed(title = "", description = text2[2048:], colour=0xDEADBF)
await message.channel.send(embed = em2_2)
if text3 != "":
if len(text3) < 2048:
em3 = discord.Embed(title = "Actions", description = text3, colour=0xDEADBF)
await message.channel.send(embed = em3)
else:
em3 = discord.Embed(title = "Actions", description = text3[:2048], colour=0xDEADBF)
await message.channel.send(embed = em3)
em3_2 = discord.Embed(title = "", description = text3[2048:], colour=0xDEADBF)
await message.channel.send(embed = em3_2)
if text4 != "":
if len(text4) < 2048:
em4 = discord.Embed(title = "Reactions", description = text4, colour=0xDEADBF)
await message.channel.send(embed = em4)
else:
em4 = discord.Embed(title = "Reactions", description = text4[:2048], colour=0xDEADBF)
await message.channel.send(embed = em4)
em4_2 = discord.Embed(title = "", description = text4[2048:], colour=0xDEADBF)
await message.channel.send(embed = em4_2)
if text5 != "":
if len(text5) < 2048:
em5 = discord.Embed(title = "Legendary Actions", description = text5, colour=0xDEADBF)
await message.channel.send(embed = em5)
else:
em5 = discord.Embed(title = "Legendary Actions", description = text5[:2048], colour=0xDEADBF)
await message.channel.send(embed = em5)
em5_2 = discord.Embed(title = "", description = text5[2048:], colour=0xDEADBF)
await message.channel.send(embed = em5_2)
# Sends the received information. Seperates into seperate messages if
# there is too much text
await message.channel.send(embed = em1)
if text2 != "":
if len(text2) < 2048:
em2 = discord.Embed(title = "Special Abilities", description = text2, colour=0xDEADBF)
await message.channel.send(embed = em2)
else:
em2 = discord.Embed(title = "Special Abilities", description = text2[:2048], colour=0xDEADBF)
await message.channel.send(embed = em2)
em2_2 = discord.Embed(title = "", description = text2[2048:], colour=0xDEADBF)
await message.channel.send(embed = em2_2)
if text3 != "":
if len(text3) < 2048:
em3 = discord.Embed(title = "Actions", description = text3, colour=0xDEADBF)
await message.channel.send(embed = em3)
else:
em3 = discord.Embed(title = "Actions", description = text3[:2048], colour=0xDEADBF)
await message.channel.send(embed = em3)
em3_2 = discord.Embed(title = "", description = text3[2048:], colour=0xDEADBF)
await message.channel.send(embed = em3_2)
if text4 != "":
if len(text4) < 2048:
em4 = discord.Embed(title = "Reactions", description = text4, colour=0xDEADBF)
await message.channel.send(embed = em4)
else:
em4 = discord.Embed(title = "Reactions", description = text4[:2048], colour=0xDEADBF)
await message.channel.send(embed = em4)
em4_2 = discord.Embed(title = "", description = text4[2048:], colour=0xDEADBF)
await message.channel.send(embed = em4_2)
if text5 != "":
if len(text5) < 2048:
em5 = discord.Embed(title = "Legendary Actions", description = text5, colour=0xDEADBF)
await message.channel.send(embed = em5)
else:
em5 = discord.Embed(title = "Legendary Actions", description = text5[:2048], colour=0xDEADBF)
await message.channel.send(embed = em5)
em5_2 = discord.Embed(title = "", description = text5[2048:], colour=0xDEADBF)
await message.channel.send(embed = em5_2)
except:
logThis("Something fucked up (error code 600)")
await message.channel.send("Something fucked up (error code 600)")
# Sends an image of the Senkulpa map
elif content.startswith("map"):
await message.channel.send("https://i.imgur.com/diMXXJs.jpg")
try:
await message.channel.send("https://i.imgur.com/diMXXJs.jpg")
except:
logThis("Something fucked up (error code 320)")
await message.channel.send("Something fucked up (error code 320)")
# Finds a random image on the internet with the imageFuncs function from
# funcs/gwendolynpy
elif content.startswith("image"):
await message.channel.send(imageFunc())
try:
await message.channel.send(imageFunc())
except:
logThis("Something fucked up (error code 700)")
await message.channel.send("Something fucked up (error code 700)")
# Sends information about a random movie with the movieFunc function from
# funcs/other/movie.py
elif content.startswith("movie"):
async with message.channel.typing():
title, plot, cover, cast = movieFunc()
if title == "error":
await message.channel.send("An error occurred. Try again")
else:
embed = discord.Embed(title=title, description=plot, color=0x24ec19)
embed.set_thumbnail(url=cover)
embed.add_field(name="Cast", value=cast,inline = True)
await message.channel.send(embed = embed)
try:
async with message.channel.typing():
title, plot, cover, cast = movieFunc()
if title == "error":
await message.channel.send("An error occurred. Try again (error code "+plot+")")
else:
embed = discord.Embed(title=title, description=plot, color=0x24ec19)
embed.set_thumbnail(url=cover)
embed.add_field(name="Cast", value=cast,inline = True)
await message.channel.send(embed = embed)
except:
logThis("Something fucked up (error code 800)")
await message.channel.send("Something fucked up (error code 800)")
# Generates a random name with the nameGen function from funcs/other/generators.py
elif content.startswith("name"):
await message.channel.send(nameGen())
try:
await message.channel.send(nameGen())
except:
logThis("Something fucked up (error code 330)")
await message.channel.send("Something fucked up (error code 330)")
# Generates a random tavern name with the tavernGen function from funcs/other/generators.py
elif content.startswith("tavern"):
await message.channel.send(tavernGen())
try:
await message.channel.send(tavernGen())
except:
logThis("Something fucked up (error code 340)")
await message.channel.send("Something fucked up (error code 340)")
# Changes the "Playing this game" thing in Discord
elif content.startswith("game "):
gamePlaying = cap(content.replace("game ",""))
game = discord.Game(gamePlaying)
await client.change_presence(activity=game)
try:
gamePlaying = cap(content.replace("game ",""))
game = discord.Game(gamePlaying)
await client.change_presence(activity=game)
except:
logThis("Something fucked up (error code 350)")
await message.channel.send("Something fucked up (error code 350)")
# Rolls star wars dice with the parseRoll function from funcs/swfuncs/swroll.py
elif content.startswith("swroll"):
command = cap(content.replace("swroll",""))
newMessage = parseRoll(message.author.display_name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
try:
command = cap(content.replace("swroll",""))
newMessage = parseRoll(message.author.display_name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
except:
logThis("Something fucked up (error code 910)")
await message.channel.send("Something fucked up (error code 910)")
# Deals with Destiny Points and stuff
elif content.startswith("swd"):
command = content.replace("swd","")
newMessage = parseDestiny(message.author.display_name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
try:
command = content.replace("swd","")
newMessage = parseDestiny(message.author.display_name,command)
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
except:
logThis("Something fucked up (error code 920)")
await message.channel.send("Something fucked up (error code 920)")
# Rolls for critical injuries
elif content.startswith("swcrit"):
command = content.replace("swcrit","").replace(" ","").replace("+","")
if command == "":
command = 0
try:
newMessage = critRoll(int(command))
except:
newMessage = "Try using a number, stupid"
command = content.replace("swcrit","").replace(" ","").replace("+","")
if command == "":
command = 0
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
try:
newMessage = critRoll(int(command))
except:
logThis("They didn't include a number (error code 931)")
newMessage = "Try using a number, stupid (error code 931)"
messageList = newMessage.split("\n")
for messageItem in messageList:
await message.channel.send(messageItem)
except:
logThis("Something fucked up (error code 930)")
await message.channel.send("Something fucked up (error code 930)")
# Accesses and changes character sheet data with the parseChar function
# from funcs/swfuncs/swchar.py
elif content.startswith("swchar") or content.startswith("sw"):
command = string.capwords(content.replace("swchar","").replace("sw","").replace("+","+ ").replace("-","- ").replace(",",", "))
title, desc = parseChar(message.author.display_name,command)
if title != "":
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
await message.channel.send(embed = em1)
else:
await message.channel.send(desc)
try:
command = string.capwords(content.replace("swchar","").replace("sw","").replace("+","+ ").replace("-","- ").replace(",",", "))
title, desc = parseChar(message.author.display_name,command)
if title != "":
em1 = discord.Embed(title = title, description = desc, colour=0xDEADBF)
await message.channel.send(embed = em1)
else:
await message.channel.send(desc)
except:
logThis("Something fucked up (error code 940)")
await message.channel.send("Something fucked up (error code 940)")
# Searches for a specific page on the Senkulpa Wiki
elif content.startswith("wiki "):
async with message.channel.typing():
command = string.capwords(content.replace("wiki ",""))
title, content, thumbnail = findWikiPage(command)
if title != "":
logThis("Sending the embedded message")
content += "\n[Læs mere](https://senkulpa.fandom.com/da/wiki/"+title.replace(" ","_")+")"
embed = discord.Embed(title = title, description = content, colour=0xDEADBF)
if thumbnail != "":
embed.set_thumbnail(url=thumbnail)
try:
async with message.channel.typing():
command = string.capwords(content.replace("wiki ",""))
title, content, thumbnail = findWikiPage(command)
if title != "":
logThis("Sending the embedded message")
content += "\n[Læs mere](https://senkulpa.fandom.com/da/wiki/"+title.replace(" ","_")+")"
embed = discord.Embed(title = title, description = content, colour=0xDEADBF)
if thumbnail != "":
embed.set_thumbnail(url=thumbnail)
await message.channel.send(embed = embed)
else:
await message.channel.send(content)
await message.channel.send(embed = embed)
else:
await message.channel.send(content)
except:
logThis("Something fucked up (error code 1000)")
await message.channel.send("Something fucked up (error code 1000)")
# Runs a trivia game
elif content.startswith("trivia"):
if content == "trivia" or content == "trivia ":
question, answers, correctAnswer = triviaStart(str(message.channel))
if answers != "":
results = "**"+question+"**\n"
for answer in range(len(answers)):
results += chr(answer+97) + ") "+answers[answer]+"\n"
await message.channel.send(results)
try:
if content == "trivia" or content == "trivia ":
question, answers, correctAnswer = triviaStart(str(message.channel))
if answers != "":
results = "**"+question+"**\n"
for answer in range(len(answers)):
results += chr(answer+97) + ") "+answers[answer]+"\n"
await message.channel.send(results)
await asyncio.sleep(60)
await asyncio.sleep(60)
triviaCountPoints(str(message.channel))
triviaCountPoints(str(message.channel))
with open("resources/games/games.json", "r") as f:
data = json.load(f)
del data["trivia questions"][str(message.channel)]
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
with open("resources/games/games.json", "r") as f:
data = json.load(f)
del data["trivia questions"][str(message.channel)]
with open("resources/games/games.json", "w") as f:
json.dump(data,f,indent=4)
logThis("Time's up for the trivia question in "+str(message.channel))
await message.channel.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
logThis("Time's up for the trivia question in "+str(message.channel))
await message.channel.send("Time's up The answer was \""+chr(correctAnswer)+") "+answers[correctAnswer-97]+"\". Anyone who answered that has gotten 1 GwendoBuck")
else:
await message.channel.send(question)
elif content.startswith("trivia "):
command = content.replace("trivia ","")
response = triviaAnswer(message.author.display_name.lower(),str(message.channel),command)
if response.startswith("Locked in "):
await message.add_reaction("👍")
else:
await message.channel.send(response)
else:
await message.channel.send(question)
elif content.startswith("trivia "):
command = content.replace("trivia ","")
response = triviaAnswer(message.author.display_name.lower(),str(message.channel),command)
if response.startswith("Locked in "):
await message.add_reaction("👍")
else:
await message.channel.send(response)
else:
logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
logThis("I didn't understand that (error code 1101)")
await message.channel.send("I didn't understand that (error code 1101)")
except:
logThis("Something fucked up (error code 1100)")
await message.channel.send("Something fucked up (error code 1100)")
# Checks your GwendoBucks balance
elif content.startswith("balance"):
response = checkBalance(message.author.display_name.lower())
if response == 1:
new_message = message.author.display_name + " has " + str(response) + " GwendoBuck"
else:
new_message = message.author.display_name + " has " + str(response) + " GwendoBucks"
await message.channel.send(new_message)
try:
response = checkBalance(message.author.display_name.lower())
if response == 1:
new_message = message.author.display_name + " has " + str(response) + " GwendoBuck"
else:
new_message = message.author.display_name + " has " + str(response) + " GwendoBucks"
await message.channel.send(new_message)
except:
logThis("Something fucked up (error code 1210)")
await message.channel.send("Something fucked up (error code 1210)")
# Gives money to other player
elif content.startswith("give "):
commands = content.split(" ")
if len(commands) >= 3:
try:
amount = int(commands[2])
response = giveMoney(message.author.display_name.lower(),commands[1],amount)
await message.channel.send(response)
except:
logThis("I didn't quite understand that")
await message.channel.send("I didn't quite understand that")
else:
logThis("I didn't understand that")
await message.channel.send("I didn't understand that")
try:
commands = content.split(" ")
if len(commands) >= 3:
try:
amount = int(commands[2])
except:
logThis("Conversion error (error code 1221)")
await message.channel.send("I didn't quite understand that (error code 1221)")
else:
response = giveMoney(message.author.display_name.lower(),commands[1],amount)
await message.channel.send(response)
else:
logThis("I didn't understand that (error code 1222)")
await message.channel.send("I didn't understand that (error code 1222)")
except:
logThis("Something fucked up (error code 1220)")
await message.channel.send("Something fucked up (error code 1220)")
# Runs a game of Blackjack
elif content.startswith("blackjack"):
@ -399,6 +485,11 @@ async def parseCommands(message,content):
logThis(response)
if showImage:
await message.channel.send(file = discord.File("resources/games/4InARowBoards/board"+str(message.channel)+".png"))
# Not a command
else:
logThis("That's not a command (error code 001)")
await message.channel.send("That's not a command (error code 001)")
# Makes files if they don't exist yet
makeFiles()
@ -422,10 +513,14 @@ async def on_ready():
# Reads messages and tests if they are Gwendolyn commands
@client.event
async def on_message(message):
content = message.content
if content.startswith(commandPrefix):
logThis(message.author.display_name+" ran \""+content+"\"")
await parseCommands(message,content.lower()[1:])
try:
content = message.content
if content.startswith(commandPrefix):
logThis(message.author.display_name+" ran \""+content+"\"")
await parseCommands(message,content.lower()[1:])
except:
logThis("Something fucked up (error code 000)")
await message.channel.send("Something fucked up (error code 000)")
# Is a bit sassy sometimes
if ("gwendolyn" in message.content.lower() or message.content.startswith(commandPrefix)) and any(x in message.content.lower() for x in meanWords) and "ikke" not in message.content.lower() and "not" not in message.content.lower():

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])

90
resources/errorCodes.txt Normal file
View File

@ -0,0 +1,90 @@
000 - Unspecified error
001 - Not a command
1 - Help
100 - Unspecified error
101 - Couldn't find help.txt
102 - Couldn't find help file for specified command
2 - Stop
200 - Unspecified error
201 - Unauthorized user
3 - Simple Commands
310 - Hello error
320 - Map error
330 - Name error
340 - Tavern error
350 - Game error
4 - Roll
400 - Unspecified error
5 - Spell
500 - Unspecified error
501 - Spell not in database
6 - Monster
600 - Unspecified error
601 - Monster name too short
602 - Monster not in database
7 - Image
700 - Unspecified error
701 - Can't connect to Bing
8 - Movie
800 - Unspecified error
801 - Can't pick movie
802 - Can't find movie on imdb
803 - Can't extract data
9 - Star Wars
910 - Unspecified swroll error
911 - Obligation roll fucked up
912 - No character swroll
913 - Didn't include heavy/light in ranged or planetary/space in piloting
914 - Swroll invalid input
920 - Unspecified swd error
921 - Didn't specify amount of players
922 - Invalid input
930 - Unspecified swcrit
931 - Swcrit didn't include a number
940 - Unspecified swchar error
941 - No weapons
942 - Can't add to character sheet
943 - No character swchar
944 - Not on character sheet
945 - Problem overwriting data
946 - Problem removing data
947 - Problem adding data
948 - Problem removing spaces
949 - Wrong data type
10 - Wiki
1000 - Unspecified error
1001 - Something fucked up
1002 - Can't find page
11 - Trivia
1100 - Unspecified error
1101 - Incorrect input
1102 - Can't find question
1103 - Not an answer
1104 - No question going on
1105 - User has already answered
1106 - There's already a question goin on in the channel
12 - Money
1210 - Unspecified balance error
1220 - Unspecified give error
1221 - Conversion error
1222 - Incorrect input
1223a - User has no money
1223b - Not enough money
13 - Blackjack
1300 - Unspecified
14 - Four in a row
600 - Unspecified