def start(name, debug=False): if sys.platform != 'linux' or debug: level = logging.DEBUG else: level = logging.INFO bot_logger = setup_logger(name) logger = module_logger(name, "launcher", level) module_logger(name, 'discord', logging.INFO) logger.info(f"Starting {name}.") if name in bots.keys(): classname = bots[name] else: classname = None bot = None if classname == 'revbot.RevBot': logger.debug("RevBot class selected. Initializing.") bot = revbot.RevBot(command_prefix='__', name=name, logger=bot_logger) elif classname == 'bulbe.Bulbe': logger.debug("Bulbe class selected. Initializing.") bot = bulbe.Bulbe(name=name, logger=bot_logger) elif classname == 'evalbot.EvalBot': logger.debug("EvalBot class selected. Initializing.") bot = evalbot.EvalBot() elif classname == 'juan.Juandissimo': logger.debug("Juandissimo class selected. Initializing.") bot = juan.Juandissimo(bot_logger) elif classname == 'clippy.Clippy': logger.debug("Clippy class selected. Initializing.") bot = clippy.Clippy(bot_logger) else: logger.error("No class found. Closing.") exit(1) if sys.platform != 'linux' or debug: try: logger.info("Adding debug cog.") bot.add_cog(Debug(bot)) except commands.ExtensionFailed: pass logger.info("Calling run method.") try: bot.run(authentication.tokens[name]) finally: try: exit_code = bot._exit_code except AttributeError: logger.info("Bot's exit code could not be retrieved.") exit_code = 0 logger.info(f"Bot closed with exit code {exit_code}.") exit(exit_code)
def __init__(self, bot): self.bot = bot self.logger = module_logger(self.bot._name, 'config') self.bot._config = {} c = self.read_config() if not c: raise Exception("Config could not be loaded from Sheets.")
def __init__(self, bot): self.bot = bot self.logger = module_logger(self.bot._name, 'config') if not self.bot.table: raise Exception("Connection to DynamoDB table not found.") self.bot.config = ConfigManager(bot, self) self.config = self.bot.config c = self.config.read() if not c: raise Exception("Config could not be loaded from DynamoDB.")
def __init__(self, table_name, bot=None): if bot: self.logger = module_logger(bot.name, 'dynamodb') else: self.logger = stream_logger('dynamodb') self.name = table_name self.resource = boto3.resource('dynamodb') self.table = self.resource.Table(table_name) self.primary_key = self.table.key_schema[0]['AttributeName'] self.sort_key = self.table.key_schema[1]['AttributeName'] self.logger.debug(f"Dynamodb table initialized. ({table_name})")
def __init__(self, bot_name=None): if bot_name: self.logger = module_logger(bot_name, 'sheets') else: self.logger = stream_logger('sheets') service = get_service() if service: self.snippets = SpreadsheetSnippets(service) else: self.logger.debug("Failed to initialize SheetsClient.") raise SheetsException("Failed to initialize SheetsClient.") self.logger.debug("SheetsClient initialized and connected.")
def start_bot(name, use_socket=True): logger = setup_logger(name) module_logger(name, 'discord', logging.INFO) logger.info(f"Starting {name}.") with open("configs/marvin.yaml") as f: _info = yaml.load(f, yaml.Loader) if name in _info['launcher'].keys(): classname = _info['launcher'][name] else: classname = _info['launcher']['default'] bot = None # if classname == 'discord.Client': # pass # elif classname == 'commands.Bot': # pass if classname == 'revbot.RevBot': bot = revbot.RevBot(command_prefix='__', name=name, logger=logger) elif classname == 'bulbe.Bulbe': bot = bulbe.Bulbe(name=name, logger=logger, use_socket=use_socket) elif classname == 'evalbot.EvalBot': bot = evalbot.EvalBot() elif classname == 'juan.Juandissimo': bot = juan.Juandissomo(logger) else: logger.error("No class found. Closing.") exit(0) try: bot.add_cog(Debug(bot)) bot.add_cog(evalbot.EvalCog(bot)) bot.run(authentication.tokens[name]) finally: logger.info("Bot closed.") exit(0)