"""Small shared configuration helpers; importing this module has no side effects.""" import os _TRUE = frozenset({"1", "true", "yes", "on"}) def env_enabled(name, default=False): value = os.environ.get(name) return default if value is None else value.strip().lower() in _TRUE def notifications_enabled(channel=None): if not env_enabled("IISHKO_NOTIFICATIONS_ENABLED"): return False if channel in ("support", "entry") and not env_enabled("IISHKO_SUPPORT_DELIVERY_ENABLED", True): return False return channel != "entry" or env_enabled("IISHKO_ENTRY_DELIVERY_ENABLED", True) def skin_db_path(): """Canonical name wins; keep the old gateway-only name for existing units.""" return (os.environ.get("IISHKO_SKIN_DB") or os.environ.get("GATE_TG_DB") or "/opt/grok-web-skin-tg.db") def bot_config_path(): return (os.environ.get("GROK_BOT_CFG") or os.environ.get("GROK_BOT_CONFIG") or os.environ.get("GATE_BOT_CONFIG") or "/opt/grok-bot/config.json") def gateway_db_path(fallback="/opt/grok-gateway/new-api/one-api.db"): return os.environ.get("IISHKO_GW_DB") or os.environ.get("GATE_NEWAPI_DB") or fallback def bot_db_path(fallback="/opt/grok-bot/bot.db"): return (os.environ.get("IISHKO_BOT_DB") or os.environ.get("GROK_BOT_DB") or os.environ.get("GATE_BOT_DB") or fallback) def econ_state_path(fallback="/opt/grok-bot/econ_cap_state.json"): return os.environ.get("IISHKO_ECON_STATE") or fallback def upstream_url(fallback="http://127.0.0.1:48000"): return (os.environ.get("IISHKO_UPSTREAM") or os.environ.get("NEWAPI_URL") or fallback) def effective_bot_config(config): """Apply one environment contract to bot, Mini App and Telegram login.""" config = dict(config) for key, name in (("bot_token", "GROK_BOT_TOKEN"), ("newapi_pass", "NEWAPI_PASS")): if os.environ.get(name): config[key] = os.environ[name] config["bot_db"] = bot_db_path(config.get("bot_db") or "/opt/grok-bot/bot.db") config["newapi_db"] = gateway_db_path( config.get("newapi_db") or "/opt/grok-gateway/new-api/one-api.db") config["newapi_url"] = upstream_url( config.get("newapi_url") or "http://127.0.0.1:48000") return config