Browse Source

Change: Added logging to error handling.

Change: Added logging to error handling.
tags/v2.0.0
Roxie Gibson 5 years ago
parent
commit
b3ba318674
2 changed files with 16 additions and 8 deletions
  1. +0
    -1
      roxbot/base.py
  2. +16
    -7
      roxbot/err_handle.py

+ 0
- 1
roxbot/base.py View File

@@ -85,7 +85,6 @@ class Base:

for user in mentions:
if user.id == roxbot.owner:
print("[Commands:Blacklist] The owner cannot be blacklisted.")
await ctx.send("The owner cannot be blacklisted.")
mentions.remove(user)


+ 16
- 7
roxbot/err_handle.py View File

@@ -26,8 +26,8 @@ SOFTWARE.


import string
import logging
import datetime
import traceback
import youtube_dl

import discord
@@ -53,10 +53,6 @@ class ErrHandle:
self.bot = bot_client
self.dev = roxbot.dev_mode

async def on_error(self, event):
if self.dev:
traceback.print_exc()

async def on_command_error(self, ctx, error):
if self.dev:
raise error
@@ -77,10 +73,13 @@ class ErrHandle:
embed = discord.Embed()
if isinstance(error, commands.NoPrivateMessage):
embed.description = self.NODMS
logging.INFO(embed.description)
elif isinstance(error, commands.DisabledCommand):
embed.description = self.DISABLEDCOMMAND
logging.INFO(embed.description)
elif isinstance(error, roxbot.CogSettingDisabled):
embed.description = self.COGSETTINGDISABLED.format(error.args[0])
logging.INFO(embed.description)
elif isinstance(error, commands.CommandNotFound):
try:
# Sadly this is the only part that makes a cog not modular. I have tried my best though to make it usable without the cog.
@@ -92,28 +91,36 @@ class ErrHandle:
embed = None
else:
embed.description = self.COMMANDNOTFOUND
logging.INFO(embed.description)
except (KeyError, AttributeError):
# KeyError for cog missing, AttributeError if a command invoked via DM
embed.description = self.COMMANDNOTFOUND
logging.INFO(embed.description)
elif isinstance(error, commands.BotMissingPermissions):
embed.description = "{}".format(error.args[0].replace("Bot", "Roxbot"))
logging.INFO(embed.description)
elif isinstance(error, commands.MissingPermissions):
embed.description = "{}".format(error.args[0])
logging.INFO(embed.description)
elif isinstance(error, commands.CommandOnCooldown):
embed.description = self.COMMANDONCOOLDOWN.format(error.retry_after)
logging.INFO(embed.description)
elif isinstance(error, (commands.CheckFailure, commands.NotOwner)):
embed.description = self.CHECKFAILURE
logging.INFO(embed.description)

elif isinstance(error, commands.CommandInvokeError):
# YOUTUBE_DL ERROR HANDLING
if isinstance(error.original, youtube_dl.utils.GeoRestrictedError):
embed.description = self.YTDLDOWNLOADERROR.format("Video is GeoRestricted.")
logging.INFO(embed.description)
elif isinstance(error.original, youtube_dl.utils.DownloadError):
embed.description = self.YTDLDOWNLOADERROR.format(error.original.exc_info[1])
logging.INFO(embed.description)

# Final catches for errors undocumented.
else:
logging.ERROR(str(error))
embed = discord.Embed(title='Command Error', colour=roxbot.EmbedColours.dark_red)
embed.description = str(error)
embed.add_field(name='User', value=ctx.author)
@@ -121,8 +128,10 @@ class ErrHandle:
embed.timestamp = datetime.datetime.utcnow()
elif isinstance(error, commands.CommandError):
embed.description = "Error: {}".format(error.args[0])
logging.ERROR(embed.description)
else:
raise error
logging.ERROR(str(error))

if embed:
embed.colour = roxbot.EmbedColours.dark_red
await ctx.send(embed=embed)

Loading…
Cancel
Save