async def cog_command_error(self, ctx: Context, error: CommandError): # TODO: More comprehensive list of errors and proper handlers if isinstance(error, MissingRequiredArgument): return await KaiserModule.send_error( ctx, f'Missing Argument', 'The command you tried to run ({ctx.message.content}), requires an argument you didn\'t provide: {error}' ) Logger.warning(f'Error in {self.name}: {error}')
async def on_command_error(self, ctx: Context, error: CommandError): if isinstance(error, CommandNotFound): return await KaiserModule.send_error( ctx, 'Command Not Found', f'The command you tried to run ({ctx.message.content}), does not exist' ) # TODO: More comprehensive list of errors and proper handlers Logger.warning(f'Unhandled error type {type(error)}') await KaiserModule.send_error(ctx)
def database_read(self, key: str, field: str = 'UserData', user_id: int = 0, subfield_override=False): if subfield_override: if not subfield_override == 'Common': Logger.warning("Cross-module database access is discouraged") else: subfield_override = self.name if field == 'UserData': return Database.database[field][user_id][subfield_override][key] else: return Database.database[field][subfield_override][key]
async def on_ready(self): Logger.info(f'Kasier loaded in {time() - Kaiser.started_at} seconds')
def load_module(self, module_init: Callable): module = module_init(self) Logger.info(f'Loading module {module.name}...') self.add_cog(module_init(self))
@classmethod async def on_command_error(self, ctx: Context, error: CommandError): if isinstance(error, CommandNotFound): return await KaiserModule.send_error( ctx, 'Command Not Found', f'The command you tried to run ({ctx.message.content}), does not exist' ) # TODO: More comprehensive list of errors and proper handlers Logger.warning(f'Unhandled error type {type(error)}') await KaiserModule.send_error(ctx) if __name__ == '__main__': Kaiser.started_at = time() Logger.info('Starting...') argparser = ArgumentParser(description=Kaiser.description) argparser.add_argument('-o', '--outfile', help='the log file to output to', dest='logfile', type=str, default=None) argparser.add_argument('-d', '--datafile', help='the database json file to use', dest='database', type=str, default=None) args = argparser.parse_args()
def cog_unload(self): Logger.info(f'Unloading module {self.name}')