From 1febca2243a0c0288270374962383297455e8ffa Mon Sep 17 00:00:00 2001 From: Franz Rolfsvaag Date: Sun, 10 Aug 2025 21:22:41 +0200 Subject: [PATCH] 0.3.9.2.a9 config bugfix --- bot.py | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/bot.py b/bot.py index db5e13d..3a38db3 100644 --- a/bot.py +++ b/bot.py @@ -9,7 +9,7 @@ from modules.common.boot_notice import post_boot_notice # Version consists of: # Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesn’t trigger auto update) -VERSION = "0.3.9.2.a8" +VERSION = "0.3.9.2.a9" # ---------- Env loading ---------- @@ -50,21 +50,41 @@ if not os.path.exists(DATA_FILE): bot.data_manager = DataManager(DATA_FILE) -# ---------- Self-check (env-aware via cfg_helper) ---------- +# ---------- Self-check: resolve from ENV first, then cfg_helper ---------- +def _resolve_channel_id(c, key: str) -> int: + # 1) ENV always wins + env_key = f"SHAI_{key.upper()}" + raw = os.getenv(env_key, "").strip().strip('"').strip("'") + if raw.isdigit(): + return int(raw) + + # 2) Try cfg_helper (if it happens to know) + try: + v = int(c.int(key, 0)) + if v: + return v + except Exception: + pass + + # 3) Last resort: legacy bot.config shapes + try: + # bot.config like dict + v = int(getattr(c, "get", lambda *_: 0)(key, 0)) + if v: + return v + except Exception: + pass + + return 0 + async def _guild_selfcheck(g: discord.Guild, c): problems = [] def _need_channel(id_key, *perms): - # Use typed accessor; falls back to default=0 if unset/invalid - cid = 0 - try: - cid = int(c.int(id_key, 0)) - except Exception: - cid = 0 - + cid = _resolve_channel_id(c, id_key) if not cid: - problems.append(f"Missing config key: {id_key}\n") + problems.append(f"Missing config key: {id_key}") return ch = g.get_channel(cid)