Updated error handling to better suited for when an error dosen't have an origina attr

doc_update
Joey Hines 2018-08-29 13:37:06 -05:00
parent 72bd148531
commit 6083e9d1c7
2 changed files with 23 additions and 21 deletions

View File

@ -66,7 +66,6 @@ class Config:
self.south_tunnel = self.config['Minecraft']['South_Tunnel']
self.west_tunnel = self.config['Minecraft']['West_Tunnel']
self.count = int(self.config['Logging']['Count'])
self.rotation_duration = int(self.config['Logging']['Rotation_Duration'])
self.special_name_list = dict(self.config.items('Special Names'))
@ -86,4 +85,5 @@ class Config:
return engine_args.format(driver, username, password, host, port, database_name)
bot_config = Config()

View File

@ -67,22 +67,12 @@ async def on_command(command, ctx):
@bot.event
async def on_command_error(error, ctx):
error_str = ''
if hasattr(ctx, 'cog'):
if "Admin_Commands" in ctx.cog.__str__():
return
if isinstance(error, commands.CommandNotFound):
return
elif isinstance(error, commands.CommandOnCooldown):
return
elif isinstance(error, commands.UserInputError):
error_str = 'Invalid syntax for **{}** you ding dong:' \
.format(ctx.invoked_with, ctx.invoked_with)
pages = bot.formatter.format_help_for(ctx, ctx.command)
for page in pages:
error_str = error_str + '\n' + page
elif isinstance(error.original, NoPermissionError):
if hasattr(error, 'original'):
if isinstance(error.original, NoPermissionError):
error_str = 'You don\'t have permission for that cool command.'
elif isinstance(error.original, UsernameLookupFailed):
error_str = 'Your user name was not found, either Mojang is having a fucky wucky ' \
@ -98,7 +88,19 @@ async def on_command_error(error, ctx):
elif isinstance(error.original, OperationalError):
await send_error_message('Error connecting to the MySQL server, is it offline?')
error_str = 'Database connection issue, looks like some admin has to fix something.'.format()
else:
elif isinstance(error, commands.CommandOnCooldown):
return
elif isinstance(error, commands.UserInputError):
error_str = 'Invalid syntax for **{}** you ding dong:' \
.format(ctx.invoked_with, ctx.invoked_with)
pages = bot.formatter.format_help_for(ctx, ctx.command)
for page in pages:
error_str = error_str + '\n' + page
elif isinstance(error, commands.CommandNotFound):
return
if error_str is None:
await send_error_message('Geoffrey encountered unhandled exception: {}. Context:'.format(error, ctx.args))
logger.error("Geoffrey encountered unhandled exception: %s", error)
@ -162,9 +164,9 @@ def setup_logging():
bot_info_logger.addHandler(handler)
bot_info_logger.addHandler(console)
def start_bot():
try:
setup_logging()
Commands()
for extension in extensions: