Explorar o código

Configuration reading logic

Kirk Trombley %!s(int64=6) %!d(string=hai) anos
pai
achega
2894737871
Modificáronse 1 ficheiros con 33 adicións e 0 borrados
  1. 33 0
      config.py

+ 33 - 0
config.py

@@ -0,0 +1,33 @@
+import os
+import os.path
+
+import toml
+
+_dir = os.environ.get("ROLLBOT_CFG_DIR", ".")
+
+with open(os.path.join(_dir, "config.toml")) as cfile:
+    _cfg = toml.load(cfile)
+
+with open(os.path.join(_dir, "secrets.toml")) as sfile:
+    _secrets = toml.load(sfile)
+
+
+def get_config(key):
+    c = _cfg
+    for k in key.split("."):
+        c = c[k]
+    return c
+
+
+def get_secret(key):
+    c = _secrets
+    for k in key.split("."):
+        c = c[k]
+    return c
+
+BOTS_LOOKUP = get_config("bots")
+GLOBAL_ADMINS = get_config("auths.global")
+GROUP_ADMINS = get_config("auths.group")
+PLUGINS = get_config("plugins")
+API_KEY = get_secret("api_key")
+POSTGRES = f'{get_config("postgres.user")}:{get_secret("postgres.pass")}@{get_config("postgres.host")}/{get_config("postgres.db")}'