diff --git a/bitbotd b/bitbotd index 8d5c5422..50661cad 100755 --- a/bitbotd +++ b/bitbotd @@ -1,10 +1,11 @@ #!/usr/bin/env python3 import sys +import src.utils.consts if sys.version_info < (3, 6): sys.stderr.write("BitBot requires python 3.6.0 or later\n") - sys.exit(1) + sys.exit(src.utils.consts.Exit.WRONGVERSION) import atexit, argparse, faulthandler, os, platform, time, typing from src import Cache, Config, Control, Database, EventManager, Exports, IRCBot @@ -87,7 +88,7 @@ log.info("Starting BitBot %s (Python v%s, db %s)", lock_file = LockFile.LockFile(lock_location) if not lock_file.available(): log.critical("Database is locked. Is BitBot already running?") - sys.exit(2) + sys.exit(utils.consts.Exit.LOCKED) atexit.register(lock_file.unlock) lock_file.lock() @@ -161,13 +162,13 @@ if len(server_configs): if not bot.connect(server): log.error("Failed to connect to '%s'", [str(server)], exc_info=True) if not args.startup_disconnects: - sys.exit(3) + sys.exit(utils.consts.Exit.DISCONNECT) try: bot.run() except Exception as e: log.critical("Unhandled exception: %s", [str(e)], exc_info=True) - sys.exit(4) + sys.exit(utils.consts.Exit.FATAL) else: try: if utils.cli.bool_input("no servers found, add one?"): diff --git a/src/IRCBot.py b/src/IRCBot.py index 40728096..89779f98 100644 --- a/src/IRCBot.py +++ b/src/IRCBot.py @@ -144,7 +144,7 @@ class Bot(object): exc_info = True self.log.critical("panic() called: %s", [reason], exc_info=exc_info) - sys.exit(20) + sys.exit(utils.consts.Exit.PANIC) def _module_lists(self): whitelist = self.config.get_list("module-whitelist") diff --git a/src/utils/consts.py b/src/utils/consts.py index d53a4660..423c7eac 100644 --- a/src/utils/consts.py +++ b/src/utils/consts.py @@ -1,4 +1,4 @@ -import typing +import enum, typing from . import _consts_256_color class IRCColor(object): @@ -68,3 +68,11 @@ ANSI_UNDERLINE_RESET = "\033[24m" PERMISSION_HARD_FAIL = 0 PERMISSION_FORCE_SUCCESS = 1 PERMISSION_ERROR = 2 + +class Exit(enum.Enum): + WRONGVERSION = 1 + LOCKED = 2 + DISCONNECT = 3 + FATAL = 4 + + PANIC = 20