diff options
Diffstat (limited to 'config.py')
-rw-r--r-- | config.py | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -25,6 +25,7 @@ LOG.setLevel(log_level) LOG.addHandler(stream) TOKEN = None +NAMING_SCHEME = None BOT_COLOR = None SQLITE_NAME = "disarchive" @@ -38,11 +39,14 @@ DB_PASSWORD = None schema = { "type": "object", "properties": { - "bot_info": { + "general": { "type": "object", "properties": { "token": {"type": "string"}, "bot_color": {"type": "string", "default": "#fc5f4e"}, + "naming_scheme": { + "enum": ["random", "timestamp", "id", "original"] + }, }, "required": ["token"], }, @@ -88,12 +92,16 @@ schema = { ], }, }, - "required": ["bot_info"], + "required": ["general"], } # Load config file or alert user if not found def load_config(): + # create images directory if it doesn't exist + if not os.path.exists("images"): + os.makedirs("images") + if os.path.exists("/.dockerenv"): file_path = "/config/config.yaml" else: @@ -115,7 +123,7 @@ def load_config(): # Validate the config file against the schema def validate_config(file_contents): - global TOKEN, BOT_COLOR, SQLITE_NAME, DB_NAME, DB_ENGINE, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD + global TOKEN, NAMING_SCHEME, BOT_COLOR, SQLITE_NAME, DB_NAME, DB_ENGINE, DB_HOST, DB_PORT, DB_USER, DB_PASSWORD config = yaml.safe_load(file_contents) try: @@ -128,20 +136,27 @@ def validate_config(file_contents): hex_pattern_two = "^([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$" # Check if the bot_color is a valid hex color - if "bot_color" in config["bot_info"]: + if "bot_color" in config["general"]: if not bool( - re.match(hex_pattern_one, config["bot_info"]["bot_color"]) + re.match(hex_pattern_one, config["general"]["bot_color"]) ) and not bool( - re.match(hex_pattern_two, config["bot_info"]["bot_color"]) + re.match(hex_pattern_two, config["general"]["bot_color"]) ): LOG.warn( "bot_color is not a valid hex color... defaulting to #26dfc9" ) else: BOT_COLOR = discord.Color( - int((config["bot_info"]["bot_color"]).replace("#", ""), 16) + int((config["general"]["bot_color"]).replace("#", ""), 16) ) + # Naming scheme + if "naming_scheme" in config["general"]: + NAMING_SCHEME = config["general"]["naming_scheme"] + else: + LOG.info("No naming scheme specified... defaulting to random") + NAMING_SCHEME = "random" + # Assign database variables if "sqlite" in config: DB_ENGINE = "sqlite" @@ -168,4 +183,4 @@ def validate_config(file_contents): LOG.warn("No database engine specified. Defaulting to SQLite.") DB_ENGINE = "sqlite" - TOKEN = config["bot_info"]["token"] + TOKEN = config["general"]["token"] |