0.3.9.2.a3

Attempted fix at docker boot issue
This commit is contained in:
Franz Rolfsvaag 2025-08-10 18:49:24 +02:00
parent e6ccc86629
commit b152440241

22
bot.py
View File

@ -8,7 +8,7 @@ from modules.common.boot_notice import post_boot_notice
# Version consists of: # Version consists of:
# Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesnt trigger auto update) # Major.Enhancement.Minor.Patch.Test (Test is alphanumeric; doesnt trigger auto update)
VERSION = "0.3.9.2.a2" VERSION = "0.3.9.2.a3"
# ---------- Env & config loading ---------- # ---------- Env & config loading ----------
@ -25,21 +25,25 @@ if 'DEFAULT' not in config:
config['DEFAULT'] = {} config['DEFAULT'] = {}
def _overlay_env_into_config(cfg: ConfigParser): def _overlay_env_into_config(cfg: ConfigParser):
"""
Overlay all SHAI_* environment variables into cfg['DEFAULT'] so env wins.
Also accept SHAI_DATA_FILE or SHAI_DATA for data_file.
"""
d = cfg['DEFAULT'] d = cfg['DEFAULT']
for k, v in os.environ.items(): for k, v in os.environ.items():
if not k.startswith('SHAI_'): if not k.startswith('SHAI_'):
continue continue
key = k[5:].lower() # drop 'SHAI_' key = k[5:].lower()
if key == 'data': if key == 'data':
key = 'data_file' key = 'data_file'
d[key] = str(v) if v is None:
continue
vv = str(v).strip().strip('"').strip("'")
if key == 'data_file' and not vv:
continue
d[key] = vv
if not d.get('data_file', '').strip(): if not d.get('data_file', '').strip():
d['data_file'] = '/data/data.json' d['data_file'] = '/data/data.json'
print("[Config] SHAI_CONFIG:", os.getenv('SHAI_CONFIG', '(unset)'))
print("[Config] DEFAULT keys now:", list(config['DEFAULT'].keys()))
# IMPORTANT: apply env overlay BEFORE we read values from config # IMPORTANT: apply env overlay BEFORE we read values from config
_overlay_env_into_config(config) _overlay_env_into_config(config)
@ -55,9 +59,11 @@ intents.voice_states = True
# ---------- Bot + DataManager ---------- # ---------- Bot + DataManager ----------
data_file = config['DEFAULT']['data_file'] # guaranteed present by overlay ddefault = config['DEFAULT']
data_file = (ddefault.get('data_file', '') or '').strip() or '/data/data.json'
if not TOKEN: if not TOKEN:
print("[Config] WARNING: DISCORD_TOKEN not set (env). Bot will fail to log in.") print("[Config] WARNING: DISCORD_TOKEN not set (env). Bot will fail to log in.")
print(f"[Config] Using data_file: {data_file}")
bot = commands.Bot(command_prefix='!', intents=intents) bot = commands.Bot(command_prefix='!', intents=intents)
bot.config = config bot.config = config