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



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



+ 16
- 7
roxbot/err_handle.py View File





import string import string
import logging
import datetime import datetime
import traceback
import youtube_dl import youtube_dl


import discord import discord
self.bot = bot_client self.bot = bot_client
self.dev = roxbot.dev_mode 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): async def on_command_error(self, ctx, error):
if self.dev: if self.dev:
raise error raise error
embed = discord.Embed() embed = discord.Embed()
if isinstance(error, commands.NoPrivateMessage): if isinstance(error, commands.NoPrivateMessage):
embed.description = self.NODMS embed.description = self.NODMS
logging.INFO(embed.description)
elif isinstance(error, commands.DisabledCommand): elif isinstance(error, commands.DisabledCommand):
embed.description = self.DISABLEDCOMMAND embed.description = self.DISABLEDCOMMAND
logging.INFO(embed.description)
elif isinstance(error, roxbot.CogSettingDisabled): elif isinstance(error, roxbot.CogSettingDisabled):
embed.description = self.COGSETTINGDISABLED.format(error.args[0]) embed.description = self.COGSETTINGDISABLED.format(error.args[0])
logging.INFO(embed.description)
elif isinstance(error, commands.CommandNotFound): elif isinstance(error, commands.CommandNotFound):
try: 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. # 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.
embed = None embed = None
else: else:
embed.description = self.COMMANDNOTFOUND embed.description = self.COMMANDNOTFOUND
logging.INFO(embed.description)
except (KeyError, AttributeError): except (KeyError, AttributeError):
# KeyError for cog missing, AttributeError if a command invoked via DM # KeyError for cog missing, AttributeError if a command invoked via DM
embed.description = self.COMMANDNOTFOUND embed.description = self.COMMANDNOTFOUND
logging.INFO(embed.description)
elif isinstance(error, commands.BotMissingPermissions): elif isinstance(error, commands.BotMissingPermissions):
embed.description = "{}".format(error.args[0].replace("Bot", "Roxbot")) embed.description = "{}".format(error.args[0].replace("Bot", "Roxbot"))
logging.INFO(embed.description)
elif isinstance(error, commands.MissingPermissions): elif isinstance(error, commands.MissingPermissions):
embed.description = "{}".format(error.args[0]) embed.description = "{}".format(error.args[0])
logging.INFO(embed.description)
elif isinstance(error, commands.CommandOnCooldown): elif isinstance(error, commands.CommandOnCooldown):
embed.description = self.COMMANDONCOOLDOWN.format(error.retry_after) embed.description = self.COMMANDONCOOLDOWN.format(error.retry_after)
logging.INFO(embed.description)
elif isinstance(error, (commands.CheckFailure, commands.NotOwner)): elif isinstance(error, (commands.CheckFailure, commands.NotOwner)):
embed.description = self.CHECKFAILURE embed.description = self.CHECKFAILURE
logging.INFO(embed.description)


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


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

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

Loading…
Cancel
Save