def main(): """The bot's main entry point. | Initialize the bot and start processing messages. """ config_file = path.join(path.dirname(__file__), 'config.cfg') if not path.exists(config_file): logging.info("Setting up config file") config.do_setup(config_file) return botconfig = configparser.ConfigParser(interpolation=configparser.ExtendedInterpolation()) with open(config_file) as f: botconfig.read_file(f) bot = IrcBot(botconfig) try: bot.start() except KeyboardInterrupt: # KeyboardInterrupt means someone tried to ^C, so shut down the bot bot.disconnect('Bot received a Ctrl-C') bot.shutdown_mp() sys.exit(0) except Exception as ex: bot.shutdown_mp(False) logging.error("The bot died! %s" % ex) output = "".join(traceback.format_exc()) for line in output.split('\n'): logging.error(line) sys.exit(1)
def init(confdir="/etc/cslbot"): """The bot's main entry point. | Initialize the bot and start processing messages. """ multiprocessing.set_start_method('spawn') parser = argparse.ArgumentParser() parser.add_argument('-d', '--debug', help='Enable debug logging.', action='store_true') args = parser.parse_args() loglevel = logging.DEBUG if args.debug else logging.INFO logging.basicConfig(level=loglevel) bot = IrcBot(confdir) try: bot.start() except KeyboardInterrupt: # KeyboardInterrupt means someone tried to ^C, so shut down the bot bot.disconnect('Bot received a Ctrl-C') bot.shutdown_mp() sys.exit(0) except Exception as ex: bot.shutdown_mp(False) logging.error("The bot died! %s" % ex) output = "".join(traceback.format_exc()).strip() for line in output.split('\n'): logging.error(line) sys.exit(1)