🐛 Added some more logging for bug fixing
This commit is contained in:
@ -29,9 +29,9 @@ class Gwendolyn(commands.Bot):
|
|||||||
intents = discord.Intents.default()
|
intents = discord.Intents.default()
|
||||||
intents.members = True
|
intents.members = True
|
||||||
|
|
||||||
super().__init__(command_prefix=" ", case_insensitive=True, intents = intents)
|
super().__init__(command_prefix=" ", case_insensitive=True, intents = intents, status = discord.Status.dnd)
|
||||||
|
|
||||||
def log(self, messages, channel : str = "", level : int = 10):
|
def log(self, messages, channel : str = "", level : int = 20):
|
||||||
logThis(messages, channel, level)
|
logThis(messages, channel, level)
|
||||||
|
|
||||||
|
|
||||||
|
@ -5,17 +5,22 @@ class EventCog(commands.Cog):
|
|||||||
def __init__(self, bot):
|
def __init__(self, bot):
|
||||||
self.bot = bot
|
self.bot = bot
|
||||||
|
|
||||||
# Sets the game and logs when the bot logs in
|
# Syncs commands, sets the game, and logs when the bot logs in
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_ready(self):
|
async def on_ready(self):
|
||||||
self.bot.log("Logged in as "+self.bot.user.name+", "+str(self.bot.user.id), level = 20)
|
await self.bot.databaseFuncs.syncCommands()
|
||||||
|
self.bot.log("Logged in as "+self.bot.user.name+", "+str(self.bot.user.id), level = 25)
|
||||||
game = discord.Game("Use /help for commands")
|
game = discord.Game("Use /help for commands")
|
||||||
await self.bot.change_presence(activity=game)
|
await self.bot.change_presence(activity=game, status = discord.Status.online)
|
||||||
|
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_disconnect(self):
|
||||||
|
await self.bot.change_presence(status = discord.Status.offline)
|
||||||
|
|
||||||
# Logs when user sends a command
|
# Logs when user sends a command
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
async def on_slash_command(self, ctx):
|
async def on_slash_command(self, ctx):
|
||||||
self.bot.log(f"{ctx.author.display_name} ran /{ctx.name}", str(ctx.channel_id), level = 20)
|
self.bot.log(f"{ctx.author.display_name} ran /{ctx.name}", str(ctx.channel_id), level = 25)
|
||||||
|
|
||||||
# Logs if a command experiences an error
|
# Logs if a command experiences an error
|
||||||
@commands.Cog.listener()
|
@commands.Cog.listener()
|
||||||
@ -36,5 +41,17 @@ class EventCog(commands.Cog):
|
|||||||
self.bot.log([f"exception in /{ctx.name}", f"{exceptionString}"],str(ctx.channel_id), 40)
|
self.bot.log([f"exception in /{ctx.name}", f"{exceptionString}"],str(ctx.channel_id), 40)
|
||||||
await ctx.send("Something went wrong (error code 000)")
|
await ctx.send("Something went wrong (error code 000)")
|
||||||
|
|
||||||
|
# Logs if an error occurs
|
||||||
|
@commands.Cog.listener()
|
||||||
|
async def on_error(self, method):
|
||||||
|
exception = traceback.format_exc()
|
||||||
|
stopAt = "\nThe above exception was the direct cause of the following exception:\n\n"
|
||||||
|
if stopAt in exception:
|
||||||
|
index = exception.index(stopAt)
|
||||||
|
exception = exception[:index]
|
||||||
|
|
||||||
|
exceptionString = "".join(exception)
|
||||||
|
self.bot.log([f"exception in /{method}", f"{exceptionString}"], level = 40)
|
||||||
|
|
||||||
def setup(bot):
|
def setup(bot):
|
||||||
bot.add_cog(EventCog(bot))
|
bot.add_cog(EventCog(bot))
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import re, git, os, json
|
import re, git, os, json, time
|
||||||
|
|
||||||
def sanitize(data : str, options : bool = False):
|
def sanitize(data : str, options : bool = False):
|
||||||
data = data.splitlines()
|
data = data.splitlines()
|
||||||
@ -130,3 +130,16 @@ class databaseFuncs():
|
|||||||
return True, False, data["imdbNames"]
|
return True, False, data["imdbNames"]
|
||||||
else:
|
else:
|
||||||
return False, None, None
|
return False, None, None
|
||||||
|
|
||||||
|
async def syncCommands(self):
|
||||||
|
collection = self.bot.database["last synced"]
|
||||||
|
lastSynced = collection.find_one()
|
||||||
|
now = time.time()
|
||||||
|
if lastSynced["last synced"] < now - 86400:
|
||||||
|
slashCommandList = str(await self.bot.slash.to_dict())
|
||||||
|
self.bot.log(f"Updating commands: {slashCommandList}")
|
||||||
|
await self.bot.slash.sync_all_commands()
|
||||||
|
idNumber = lastSynced["_id"]
|
||||||
|
queryFilter = {"_id" : idNumber}
|
||||||
|
update = {"$set" : {"last synced" : now}}
|
||||||
|
collection.update_one(queryFilter, update)
|
||||||
|
@ -4,6 +4,7 @@ import logging
|
|||||||
import os
|
import os
|
||||||
from .helperClasses import Options
|
from .helperClasses import Options
|
||||||
|
|
||||||
|
logging.addLevelName(25, "PRINT")
|
||||||
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
|
logging.basicConfig(filename="gwendolyn.log", level=logging.INFO)
|
||||||
|
|
||||||
def getParams():
|
def getParams():
|
||||||
@ -33,7 +34,7 @@ def logThis(messages, channel : str = "", level : int = 20):
|
|||||||
if len(messages) > 1:
|
if len(messages) > 1:
|
||||||
messages[0] += " (details in log)"
|
messages[0] += " (details in log)"
|
||||||
|
|
||||||
if level != 10:
|
if level >= 25:
|
||||||
print(messages[0])
|
print(messages[0])
|
||||||
|
|
||||||
for logMessage in messages:
|
for logMessage in messages:
|
||||||
|
Reference in New Issue
Block a user