Skip to content

Commit

Permalink
🔀 Merge pull request #128 from divadsn/bugfix/env-config
Browse files Browse the repository at this point in the history
Improve admin list and bool parsing from envvars
  • Loading branch information
jh0ker authored Mar 12, 2024
2 parents 9bd86bd + 49ef6b7 commit f89559c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

The following wonderful people contributed directly or indirectly to this project:

- [divadsn](https://github.com/divadsn)
- [imlonghao](https://github.com/imlonghao)
- [Iuri Guilherme](https://github.com/iuriguilherme)
- [JuniorJPDJ](https://github.com/JuniorJPDJ)
Expand Down
17 changes: 14 additions & 3 deletions config.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,26 @@

try:
with open("config.json", "r") as f:
config = json.loads(f.read())
config = json.load(f)
except FileNotFoundError:
config = {}

TOKEN = os.getenv("TOKEN", config.get("token"))
WORKERS = int(os.getenv("WORKERS", config.get("workers", 32)))
ADMIN_LIST = os.getenv("ADMIN_LIST", config.get("admin_list", None))
OPEN_LOBBY = os.getenv("OPEN_LOBBY", config.get("open_lobby", True)) == "True"
ENABLE_TRANSLATIONS = os.getenv("ENABLE_TRANSLATIONS", config.get("enable_translations", False)) == "True"

if isinstance(ADMIN_LIST, str):
ADMIN_LIST = set(int(x) for x in ADMIN_LIST.split())

OPEN_LOBBY = os.getenv("OPEN_LOBBY", config.get("open_lobby", True))
ENABLE_TRANSLATIONS = os.getenv("ENABLE_TRANSLATIONS", config.get("enable_translations", False))

if isinstance(OPEN_LOBBY, str):
OPEN_LOBBY = OPEN_LOBBY.lower() in ("yes", "true", "t", "1")

if isinstance(ENABLE_TRANSLATIONS, str):
ENABLE_TRANSLATIONS = ENABLE_TRANSLATIONS.lower() in ("yes", "true", "t", "1")

DEFAULT_GAMEMODE = os.getenv("DEFAULT_GAMEMODE", config.get("default_gamemode", "fast"))
WAITING_TIME = int(os.getenv("WAITING_TIME", config.get("waiting_time", 120)))
TIME_REMOVAL_AFTER_SKIP = int(os.getenv("TIME_REMOVAL_AFTER_SKIP", config.get("time_removal_after_skip", 20)))
Expand Down

0 comments on commit f89559c

Please sign in to comment.