📄 Logging

This commit is contained in:
NikolajDanger
2020-07-30 11:02:36 +02:00
parent 8e6a6e0b55
commit c6a7f35602
2 changed files with 60 additions and 55 deletions

View File

@ -22,14 +22,14 @@ meanWords = ["stupid", "bitch", "fuck", "dumb", "idiot"]
# Loop of game rounds
async def blackjackLoop(channel,gameRound,gameID):
logThis("Loop "+str(gameRound))
logThis("Loop "+str(gameRound),str(channel))
with open("resources/games/oldImages/blackjack"+str(channel), "r") as f:
oldImage = await channel.fetch_message(int(f.read()))
new_message, allStanding, gamedone = blackjackContinue(str(channel))
if new_message != "":
logThis(new_message)
logThis(new_message,str(channel))
await channel.send(new_message)
if gamedone == False:
await oldImage.delete()
@ -50,15 +50,15 @@ async def blackjackLoop(channel,gameRound,gameID):
if gameRound == realRound and realGameID == gameID:
if gamedone == False:
logThis("Loop "+str(gameRound)+" calling blackjackLoop()")
logThis("Loop "+str(gameRound)+" calling blackjackLoop()",str(channel))
await blackjackLoop(channel,gameRound+1,gameID)
else:
new_message = blackjackFinish(str(channel))
await channel.send(new_message)
else:
logThis("Ending loop on round "+str(gameRound))
logThis("Ending loop on round "+str(gameRound),str(channel))
else:
logThis("Ending loop on round "+str(gameRound))
logThis("Ending loop on round "+str(gameRound),str(channel))
async def parseCommands(message,content):
# Sends the contents of a help file, as specified by the message.
@ -71,26 +71,26 @@ async def parseCommands(message,content):
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)")
logThis("Couldn't find help.txt (error code 101)",str(message.channel))
await message.channel.send("Couldn't find help.txt (error code 101)")
else:
command = content.replace(" ","-")
logThis("Looking for "+command+".txt")
logThis("Looking for "+command+".txt",str(message.channel))
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)")
logThis("Couldn't find help for that command (error code 102)",str(message.channel))
await message.channel.send("Couldn't find help for that command (error code 102)")
except:
logThis("Something fucked up (error code 100)")
logThis("Something fucked up (error code 100)",str(message.channel))
await message.channel.send("Something fucked up (error code 100)")
# Logs whatever you write in the message
if content.startswith("log "):
logThis(content.replace("log ",""))
logThis(content.replace("log ",""),str(message.channel))
# Stops the bot
elif content.startswith("stop"):
@ -110,10 +110,10 @@ async def parseCommands(message,content):
await client.logout()
else:
logThis(message.author.display_name+" tried to run stop me! (error code 201)")
logThis(message.author.display_name+" tried to run stop me! (error code 201)",str(message.channel))
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)")
logThis("Something fucked up (error code 200)",str(message.channel))
await message.channel.send("Something fucked up (error code 200)")
# Does a hello with the helloFunc function from funcs/gwendolynpy
@ -121,7 +121,7 @@ async def parseCommands(message,content):
try:
await message.channel.send(helloFunc(message.author.display_name))
except:
logThis("Something fucked up (error code 310)")
logThis("Something fucked up (error code 310)",str(message.channel))
await message.channel.send("Something fucked up (error code 310)")
# Rolls dice with the roll_dice function from funcs/roll/dice.py
@ -132,7 +132,7 @@ async def parseCommands(message,content):
else:
await message.channel.send(roll_dice(message.author.display_name, content.replace("roll","")))
except:
logThis("Something fucked up (error code 400)")
logThis("Something fucked up (error code 400)",str(message.channel))
await message.channel.send("Something fucked up (error code 400)")
# Looks up a spell with the spellFunc function from funcs/lookup/lookuppy
@ -140,7 +140,7 @@ async def parseCommands(message,content):
try:
await message.channel.send(spellFunc(cap(content.replace("spell",""))))
except:
logThis("Something fucked up (error code 500)")
logThis("Something fucked up (error code 500)",str(message.channel))
await message.channel.send("Something fucked up (error code 500)")
# Looks up a monster with the monsterFuncs() from funcs/lookup/lookuppy
@ -189,7 +189,7 @@ async def parseCommands(message,content):
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)")
logThis("Something fucked up (error code 600)",str(message.channel))
await message.channel.send("Something fucked up (error code 600)")
# Sends an image of the Senkulpa map
@ -197,7 +197,7 @@ async def parseCommands(message,content):
try:
await message.channel.send("https://i.imgur.com/diMXXJs.jpg")
except:
logThis("Something fucked up (error code 320)")
logThis("Something fucked up (error code 320)",str(message.channel))
await message.channel.send("Something fucked up (error code 320)")
# Finds a random image on the internet with the imageFuncs function from
@ -206,7 +206,7 @@ async def parseCommands(message,content):
try:
await message.channel.send(imageFunc())
except:
logThis("Something fucked up (error code 700)")
logThis("Something fucked up (error code 700)",str(message.channel))
await message.channel.send("Something fucked up (error code 700)")
# Sends information about a random movie with the movieFunc function from
@ -223,7 +223,7 @@ async def parseCommands(message,content):
embed.add_field(name="Cast", value=cast,inline = True)
await message.channel.send(embed = embed)
except:
logThis("Something fucked up (error code 800)")
logThis("Something fucked up (error code 800)",str(message.channel))
await message.channel.send("Something fucked up (error code 800)")
# Generates a random name with the nameGen function from funcs/other/generators.py
@ -231,7 +231,7 @@ async def parseCommands(message,content):
try:
await message.channel.send(nameGen())
except:
logThis("Something fucked up (error code 330)")
logThis("Something fucked up (error code 330)",str(message.channel))
await message.channel.send("Something fucked up (error code 330)")
# Generates a random tavern name with the tavernGen function from funcs/other/generators.py
@ -239,7 +239,7 @@ async def parseCommands(message,content):
try:
await message.channel.send(tavernGen())
except:
logThis("Something fucked up (error code 340)")
logThis("Something fucked up (error code 340)",str(message.channel))
await message.channel.send("Something fucked up (error code 340)")
# Changes the "Playing this game" thing in Discord
@ -249,7 +249,7 @@ async def parseCommands(message,content):
game = discord.Game(gamePlaying)
await client.change_presence(activity=game)
except:
logThis("Something fucked up (error code 350)")
logThis("Something fucked up (error code 350)",str(message.channel))
await message.channel.send("Something fucked up (error code 350)")
# Rolls star wars dice with the parseRoll function from funcs/swfuncs/swroll.py
@ -261,7 +261,7 @@ async def parseCommands(message,content):
for messageItem in messageList:
await message.channel.send(messageItem)
except:
logThis("Something fucked up (error code 910)")
logThis("Something fucked up (error code 910)",str(message.channel))
await message.channel.send("Something fucked up (error code 910)")
# Deals with Destiny Points and stuff
@ -273,7 +273,7 @@ async def parseCommands(message,content):
for messageItem in messageList:
await message.channel.send(messageItem)
except:
logThis("Something fucked up (error code 920)")
logThis("Something fucked up (error code 920)",str(message.channel))
await message.channel.send("Something fucked up (error code 920)")
# Rolls for critical injuries
@ -287,14 +287,14 @@ async def parseCommands(message,content):
try:
newMessage = critRoll(int(command))
except:
logThis("They didn't include a number (error code 931)")
logThis("They didn't include a number (error code 931)",str(message.channel))
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)")
logThis("Something fucked up (error code 930)",str(message.channel))
await message.channel.send("Something fucked up (error code 930)")
# Accesses and changes character sheet data with the parseChar function
@ -309,7 +309,7 @@ async def parseCommands(message,content):
else:
await message.channel.send(desc)
except:
logThis("Something fucked up (error code 940)")
logThis("Something fucked up (error code 940)",str(message.channel))
await message.channel.send("Something fucked up (error code 940)")
@ -320,7 +320,7 @@ async def parseCommands(message,content):
command = string.capwords(content.replace("wiki ",""))
title, content, thumbnail = findWikiPage(command)
if title != "":
logThis("Sending the embedded message")
logThis("Sending the embedded message",str(message.channel))
content += "\n[Læs mere](https://senkulpa.fandom.com/da/wiki/"+title.replace(" ","_")+")"
embed = discord.Embed(title = title, description = content, colour=0xDEADBF)
if thumbnail != "":
@ -330,7 +330,7 @@ async def parseCommands(message,content):
else:
await message.channel.send(content)
except:
logThis("Something fucked up (error code 1000)")
logThis("Something fucked up (error code 1000)",str(message.channel))
await message.channel.send("Something fucked up (error code 1000)")
@ -357,7 +357,7 @@ async def parseCommands(message,content):
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))
logThis("Time's up for the trivia question",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)
@ -370,10 +370,10 @@ async def parseCommands(message,content):
else:
await message.channel.send(response)
else:
logThis("I didn't understand that (error code 1101)")
logThis("I didn't understand that (error code 1101)",str(message.channel))
await message.channel.send("I didn't understand that (error code 1101)")
except:
logThis("Something fucked up (error code 1100)")
logThis("Something fucked up (error code 1100)",str(message.channel))
await message.channel.send("Something fucked up (error code 1100)")
@ -387,7 +387,7 @@ async def parseCommands(message,content):
new_message = message.author.display_name + " has " + str(response) + " GwendoBucks"
await message.channel.send(new_message)
except:
logThis("Something fucked up (error code 1210)")
logThis("Something fucked up (error code 1210)",str(message.channel))
await message.channel.send("Something fucked up (error code 1210)")
# Gives money to other player
@ -398,16 +398,16 @@ async def parseCommands(message,content):
try:
amount = int(commands[2])
except:
logThis("Conversion error (error code 1221)")
logThis("Conversion error (error code 1221)",str(message.channel))
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)")
logThis("I didn't understand that (error code 1222)",str(message.channel))
await message.channel.send("I didn't understand that (error code 1222)")
except:
logThis("Something fucked up (error code 1220)")
logThis("Something fucked up (error code 1220)",str(message.channel))
await message.channel.send("Something fucked up (error code 1220)")
# Runs a game of Blackjack
@ -424,7 +424,7 @@ async def parseCommands(message,content):
# Shuffles if not enough cards
if cardsLeft < blackjackMinCards:
blackjackShuffle(blackjackDecks)
logThis("Shuffling the blackjack deck...")
logThis("Shuffling the blackjack deck...",str(message.channel))
await message.channel.send("Shuffling the deck...")
new_message = "Blackjack game started. Use \""+commandPrefix+"blackjack bet [amount]\" to enter the game within the next 30 seconds."
@ -447,7 +447,7 @@ async def parseCommands(message,content):
# Loop of game rounds
if gamedone == False:
logThis("!blackjack calling blackjackLoop()")
logThis("!blackjack calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,1,gameID)
else:
new_message = blackjackFinish(str(message.channel))
@ -461,7 +461,7 @@ async def parseCommands(message,content):
try:
amount = int(commands[2])
except:
logThis("I didn't understand that")
logThis("I didn't understand that",str(message.channel))
response = "I didn't understand that"
else:
response = blackjackPlayerDrawHand(str(message.channel),message.author.display_name,amount)
@ -485,11 +485,11 @@ async def parseCommands(message,content):
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Hit calling blackjackLoop()")
logThis("Hit calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up")
await message.channel.send("something fucked up")
await message.channel.send("something fucked up",str(message.channel))
else:
await message.channel.send(response)
@ -504,10 +504,10 @@ async def parseCommands(message,content):
if response[6] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Stand calling blackjackLoop()")
logThis("Stand calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(response[7:])+1,gameID)
except:
logThis("Something fucked up")
logThis("Something fucked up",str(message.channel))
await message.channel.send("something fucked up")
else:
await message.channel.send(response)
@ -527,10 +527,10 @@ async def parseCommands(message,content):
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Double calling blackjackLoop()")
logThis("Double calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
except:
logThis("Something fucked up")
logThis("Something fucked up",str(message.channel))
await message.channel.send("something fucked up")
# Splitting hand
@ -543,7 +543,7 @@ async def parseCommands(message,content):
if roundDone[0] == "T":
with open("resources/games/games.json", "r") as f:
gameID = json.load(f)["blackjack games"][str(message.channel)]["id"]
logThis("Split calling blackjackLoop()")
logThis("Split calling blackjackLoop()",str(message.channel))
await blackjackLoop(message.channel,int(roundDone[1:])+1,gameID)
#except:
# logThis("Something fucked up")
@ -558,7 +558,7 @@ async def parseCommands(message,content):
# Shuffles the blackjack deck
elif content.startswith("blackjack shuffle"):
blackjackShuffle(blackjackDecks)
logThis("Shuffling the blackjack deck...")
logThis("Shuffling the blackjack deck...",str(message.channel))
await message.channel.send("Shuffling the deck...")
elif content.startswith("blackjack cards"):
@ -567,7 +567,7 @@ async def parseCommands(message,content):
for line in f:
cardsLeft += 1
decksLeft = math.round(cardsLeft/52)
decksLeft = round(cardsLeft/52,1)
await message.channel.send(str(cardsLeft)+" cards, "+str(decksLeft)+" decks")
else:
@ -577,13 +577,13 @@ async def parseCommands(message,content):
elif content.startswith("fourinarow"):
response, showImage = parseFourInARow(content.replace("fourinarow",""),str(message.channel),message.author.display_name)
await message.channel.send(response)
logThis(response)
logThis(response,str(message.channel))
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)")
logThis("That's not a command (error code 001)",str(message.channel))
await message.channel.send("That's not a command (error code 001)")
# Makes files if they don't exist yet
@ -611,7 +611,7 @@ async def on_message(message):
#try:
content = message.content
if content.startswith(commandPrefix):
logThis(message.author.display_name+" ran \""+content+"\"")
logThis(message.author.display_name+" ran \""+content+"\"",str(message.channel))
await parseCommands(message,content.lower()[1:])
#except:
# logThis("Something fucked up (error code 000)")
@ -619,7 +619,7 @@ async def on_message(message):
# 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():
logThis(message.author.display_name+" was a bit mean")
logThis(message.author.display_name+" was a bit mean",str(message.channel))
emoji = random.choice(["😠", "🖕", "👎"])
await message.add_reaction(emoji)