diff --git a/geoffrey/BotConfig.py b/geoffrey/BotConfig.py index b47d169..1f72e87 100644 --- a/geoffrey/BotConfig.py +++ b/geoffrey/BotConfig.py @@ -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() diff --git a/geoffrey/bot.py b/geoffrey/bot.py index f0de364..4d5ed4d 100644 --- a/geoffrey/bot.py +++ b/geoffrey/bot.py @@ -67,11 +67,27 @@ 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 + 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 ' \ + 'or your nickname is not set correctly. *stares at the Mods*' + elif isinstance(error.original, PlayerNotFound): + error_str = 'Make sure to use ?register first you ding dong.' + elif isinstance(error.original, EntryNameNotUniqueError): + error_str = 'An entry in the database already has that name you ding dong.' + elif isinstance(error.original, DatabaseValueError): + error_str = 'Use a shorter name or a smaller value, dong ding.' + elif isinstance(error.original, NotOnServerError): + error_str = 'Command needs to be run on 24CC. Run this command there whoever you are.'.format() + 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() elif isinstance(error, commands.CommandOnCooldown): return elif isinstance(error, commands.UserInputError): @@ -81,24 +97,10 @@ async def on_command_error(error, ctx): 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 - elif 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 ' \ - 'or your nickname is not set correctly. *stares at the Mods*' - elif isinstance(error.original, PlayerNotFound): - error_str = 'Make sure to use ?register first you ding dong.' - elif isinstance(error.original, EntryNameNotUniqueError): - error_str = 'An entry in the database already has that name you ding dong.' - elif isinstance(error.original, DatabaseValueError): - error_str = 'Use a shorter name or a smaller value, dong ding.' - elif isinstance(error.original, NotOnServerError): - error_str = 'Command needs to be run on 24CC. Run this command there whoever you are.'.format() - 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: + 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: