def run_bot(): from gevent import monkey monkey.patch_all() #patch_MessageTable() parser = argparse.ArgumentParser() parser.add_argument('--token', help="discord api auth token", default=None) parser.add_argument('--log-level', help='log level', default="INFO") if not os.path.exists(CONFIG_FILE): print("%s missing, pls fix" % CONFIG_FILE) exit() config = ClientConfig.from_file(CONFIG_FILE) args = parser.parse_args() if args.log_level: setup_logging(level=getattr(logging, args.log_level.upper())) if args.token is not None: config.token = args.token if not is_valid_token(config.token): print("the token '%s' isn't valid" % config.token) exit() client = Client(config) bot_config = BotConfig(config.bot) # get plugin files # todo: support multilevel nested plugins _, _, filenames = next(os.walk("plugins"), (None, None, [])) filenames.remove("__init__.py") # convert plugins from ayylmao.py to plugins.ayylmao filenames = ["plugins.%s" % os.path.splitext(p)[0] for p in filenames] # remove disabled plugins from plugin array filenames = [p for p in filenames if p not in config.disabled_plugins] bot_config.plugins = filenames if len(bot_config.plugins) > 0: print("discovered plugins:") for p in bot_config.plugins: print(" - %s" % p) else: print("no plugins found") bot = Bot(client, bot_config) bot.run_forever()
def disco_main(run=False): """ Creates an argument parser and parses a standard set of command line arguments, creating a new :class:`Client`. Returns ------- :class:`Client` A new Client from the provided command line arguments """ args = parser.parse_args() from disco.client import Client, ClientConfig from disco.bot import Bot, BotConfig from disco.util.token import is_valid_token from disco.util.logging import setup_logging if os.path.exists(args.config): config = ClientConfig.from_file(args.config) else: config = ClientConfig() for k, v in six.iteritems(vars(args)): if hasattr(config, k) and v is not None: setattr(config, k, v) if not is_valid_token(config.token): print('Invalid token passed') return if args.shard_auto: from disco.gateway.sharder import AutoSharder AutoSharder(config).run() return if hasattr(config, 'logging_format'): setup_logging(level=logging.INFO, format=config.logging_format) else: setup_logging(level=logging.INFO) client = Client(config) bot = None if args.run_bot or hasattr(config, 'bot'): bot_config = BotConfig(config.bot) if hasattr(config, 'bot') else BotConfig() if not hasattr(bot_config, 'plugins'): bot_config.plugins = args.plugin else: bot_config.plugins += args.plugin bot = Bot(client, bot_config) if run: (bot or client).run_forever() return (bot or client)
def disco_main(run=False): """ Creates an argument parser and parses a standard set of command line arguments, creating a new :class:`Client`. Returns ------- :class:`Client` A new Client from the provided command line arguments """ from gevent import monkey monkey.patch_all() from disco.client import Client, ClientConfig from disco.bot import Bot, BotConfig from disco.util.token import is_valid_token from disco.util.logging import setup_logging config = ClientConfig.from_file('config.yaml') if not is_valid_token(config.token): print('Invalid token passed') return setup_logging(level='WARN') client = Client(config) bot_config = BotConfig(config.bot) bot = Bot(client, bot_config) from db import ChartingDao bot.db = ChartingDao() bot.run_forever() return bot
def disco_main(run=False): """ Creates an argument parser and parses a standard set of command line arguments, creating a new :class:`Client`. Returns ------- :class:`Client` A new Client from the provided command line arguments """ args = parser.parse_args() from disco.client import Client, ClientConfig from disco.bot import Bot, BotConfig from disco.util.token import is_valid_token from disco.util.logging import setup_logging if os.path.exists(args.config): config = ClientConfig.from_file(args.config) else: config = ClientConfig() config.manhole_enable = args.manhole if args.manhole_bind: config.manhole_bind = args.manhole_bind for k, v in six.iteritems(vars(args)): if hasattr(config, k) and v is not None: setattr(config, k, v) if not is_valid_token(config.token): print('Invalid token passed') return if args.shard_auto: from disco.gateway.sharder import AutoSharder AutoSharder(config).run() return # TODO: make configurable setup_logging(level=getattr(logging, args.log_level.upper())) client = Client(config) bot = None if args.run_bot or hasattr(config, 'bot'): bot_config = BotConfig(config.bot) if hasattr(config, 'bot') else BotConfig() if not hasattr(bot_config, 'plugins'): bot_config.plugins = args.plugin else: bot_config.plugins += args.plugin if args.http_bind: bot_config.http_enabled = True host, port = args.http_bind.split(':', 1) bot_config.http_host = host bot_config.http_port = int(port) bot = Bot(client, bot_config) if run: (bot or client).run_forever() return (bot or client)