From 31188d41ff25699ab595a0ef7565c93ff3797695 Mon Sep 17 00:00:00 2001 From: shtlrs Date: Sun, 30 Apr 2023 13:06:18 +0100 Subject: add base EnvConfig --- bot/constants.py | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'bot/constants.py') diff --git a/bot/constants.py b/bot/constants.py index 7e5fa1d9..827c5356 100644 --- a/bot/constants.py +++ b/bot/constants.py @@ -1,7 +1,9 @@ import enum import logging from os import environ -from typing import NamedTuple + +from pydantic import BaseSettings + __all__ = ( "Branding", @@ -36,8 +38,23 @@ log = logging.getLogger(__name__) PYTHON_PREFIX = "!" -class Branding: - cycle_frequency = int(environ.get("CYCLE_FREQUENCY", 3)) # 0: never, 1: every day, 2: every other day, ... +class EnvConfig(BaseSettings): + """Our default configuration for models that should load from .env files.""" + + class Config: + """Specify what .env files to load, and how to load them.""" + + env_file = ".env.server", ".env", + env_file_encoding = "utf-8" + + +class _Branding(EnvConfig): + EnvConfig.Config.env_prefix = "branding_" + + cycle_frequency = 3 # 0: never, 1: every day, 2: every other day, ... + + +Branding = _Branding() class Cats: -- cgit v1.2.3