config.py 766 B

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. import os.path
  3. import toml
  4. _dir = os.environ.get("ROLLBOT_CFG_DIR", ".")
  5. with open(os.path.join(_dir, "config.toml")) as cfile:
  6. _cfg = toml.load(cfile)
  7. with open(os.path.join(_dir, "secrets.toml")) as sfile:
  8. _secrets = toml.load(sfile)
  9. def get_config(key):
  10. c = _cfg
  11. for k in key.split("."):
  12. c = c[k]
  13. return c
  14. def get_secret(key):
  15. c = _secrets
  16. for k in key.split("."):
  17. c = c[k]
  18. return c
  19. BOTS_LOOKUP = get_config("bots")
  20. GLOBAL_ADMINS = get_config("auths.global")
  21. GROUP_ADMINS = get_config("auths.group")
  22. PLUGINS = get_config("plugins")
  23. API_KEY = get_secret("api_key")
  24. POSTGRES = f'{get_config("postgres.user")}:{get_secret("postgres.pass")}@{get_config("postgres.host")}/{get_config("postgres.db")}'