Logging
This commit is contained in:
76
Gwendolyn.py
76
Gwendolyn.py
@ -3,14 +3,10 @@
|
||||
import discord
|
||||
import asyncio
|
||||
import pickle
|
||||
import time
|
||||
import logging
|
||||
import codecs
|
||||
|
||||
import funcs
|
||||
|
||||
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
|
||||
|
||||
# Gets secret bot token
|
||||
with open("token.txt","r") as f:
|
||||
token = f.read().replace("\n","")
|
||||
@ -20,13 +16,7 @@ client = discord.Client()
|
||||
# Logs in
|
||||
@client.event
|
||||
async def on_ready():
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print(localtime)
|
||||
print("Logged in as")
|
||||
print(client.user.name)
|
||||
print(client.user.id)
|
||||
print("-----------")
|
||||
logging.info("\n-----------\n"+localtime+"\nLogged in")
|
||||
funcs.logThis("Logged in as "+client.user.name+", "+str(client.user.id))
|
||||
game = discord.Game("Some weeb shit")
|
||||
await client.change_presence(activity=game)
|
||||
|
||||
@ -35,40 +25,30 @@ async def on_ready():
|
||||
async def on_message(message):
|
||||
# Sends the contents of "help.txt"
|
||||
if message.content.lower().startswith("!help"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !help")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !help")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
with codecs.open("resources/help.txt",encoding="utf-8") as f:
|
||||
text = f.read()
|
||||
print(text)
|
||||
em = discord.Embed(title = "Help", description = text,colour = 0x59f442)
|
||||
await message.channel.send(embed = em)
|
||||
|
||||
# Stops the bot
|
||||
elif message.content.lower().startswith("!stop"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
if message.author.name == "Nikolaj":
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !stop")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !stop")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send("Logging out...")
|
||||
await client.logout()
|
||||
else:
|
||||
print("\n"+localtime+"\n"+message.author.name+" tried to run !stop")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" tried to run !stop")
|
||||
funcs.logThis(message.author.name+" tried to run "+message.content)
|
||||
await message.channel.send("I don't think I will, "+message.author.name)
|
||||
|
||||
# Does a hello with the helloFunc function from funcs/gwendolynFuncs.py
|
||||
elif message.content.lower().startswith("!hello"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !hello")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !hello")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send(funcs.helloFunc(message.author.name))
|
||||
|
||||
# Rolls dice with the roll_dice function from funcs/roll/dice.py
|
||||
elif message.content.lower().startswith("!roll"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !roll")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !roll")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
if message.content.lower() == "!roll" or message.content.lower() == "!roll ":
|
||||
await message.channel.send(funcs.roll_dice(message.author.name))
|
||||
else:
|
||||
@ -76,16 +56,12 @@ async def on_message(message):
|
||||
|
||||
# Looks up a spell with the spellFunc function from funcs/lookup/lookupFuncs.py
|
||||
elif message.content.lower().startswith("!spell "):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !spell")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !spell")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send(funcs.spellFunc(message.content))
|
||||
|
||||
# Looks up a monster with the monsterFuncs() from funcs/lookup/lookupFuncs.py
|
||||
elif message.content.lower().startswith("!monster "):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !monster")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !monster")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
title, text1, text2, text3, text4, text5 = funcs.monsterFunc(message.content)
|
||||
em1 = discord.Embed(title = title, description = text1, colour=0xDEADBF)
|
||||
|
||||
@ -131,25 +107,19 @@ async def on_message(message):
|
||||
|
||||
# Sends an image of the Senkulpa map
|
||||
elif message.content.lower().startswith("!map"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !map")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !map")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send("https://i.imgur.com/diMXXJs.jpg")
|
||||
|
||||
# Finds a random image on the internet with the imageFuncs function from
|
||||
# funcs/gwendolynFuncs.py
|
||||
elif message.content.lower().startswith("!image"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !image")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !image")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send(funcs.imageFunc())
|
||||
|
||||
# Sends information about a random movie with the movieFunc function from
|
||||
# funcs/other/movie.py
|
||||
elif message.content.lower().startswith("!movie"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !movie")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !movie")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
async with message.channel.typing():
|
||||
title, plot, cover, cast = funcs.movieFunc()
|
||||
if title == "error":
|
||||
@ -162,49 +132,37 @@ async def on_message(message):
|
||||
|
||||
# Generates a random name with the nameGen function from funcs/other/generators.py
|
||||
elif message.content.lower().startswith("!name"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !name")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !name")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send(funcs.nameGen())
|
||||
|
||||
# Generates a random tavern name with the tavernGen function from funcs/other/generators.py
|
||||
elif message.content.lower().startswith("!tavern"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !tavern")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !tavern")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
await message.channel.send(funcs.tavernGen())
|
||||
|
||||
# Changes the "Playing this game" thing in Discord
|
||||
elif message.content.lower().startswith("!game "):
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
gamePlaying = funcs.cap(message.content.lower().replace("!game ",""))
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !game, changing the game to '"+gamePlaying+"'")
|
||||
game = discord.Game(gamePlaying)
|
||||
await client.change_presence(activity=game)
|
||||
|
||||
# Rolls star wars dice with the parseRoll function from funcs/swfuncs/swroll.py
|
||||
elif message.content.lower().startswith("!swroll"):
|
||||
localtime = time.asctime( time.localtime(time.time()) )
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !swroll")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swroll")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
command = funcs.cap(message.content.lower().replace("!swroll",""))
|
||||
await message.channel.send(funcs.parseRoll(message.author.name,command))
|
||||
|
||||
# Deals with Destiny Points and stuff
|
||||
elif message.content.lower().startswith("!swd"):
|
||||
localtime = time.asctime(time.localtime(time.time()))
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !swd")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swd")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
command = message.content.lower().replace("!swd","")
|
||||
await message.channel.send(funcs.parseDestiny(message.author.name,command))
|
||||
|
||||
# Accesses and changes character sheet data with the parseChar function
|
||||
# from funcs/swfuncs/swchar.py
|
||||
elif message.content.lower().startswith("!swchar") or message.content.lower().startswith("!sw"):
|
||||
localtime = time.asctime(time.localtime(time.time()))
|
||||
print("\n"+localtime+"\n"+message.author.name+" ran !swchar")
|
||||
logging.info("\n"+localtime+"\n"+message.author.name+" ran !swchar")
|
||||
funcs.logThis(message.author.name+" ran \""+message.content+"\"")
|
||||
command = funcs.cap(message.content.lower().replace("!swchar","").replace("!sw","").replace("+","+ "))
|
||||
title, desc = funcs.parseChar(message.author.name,command)
|
||||
if title != "":
|
||||
|
Reference in New Issue
Block a user