0.3.9.2.a9
config bugfix
This commit is contained in:
		
							parent
							
								
									e2b6dd667b
								
							
						
					
					
						commit
						1febca2243
					
				
							
								
								
									
										40
									
								
								bot.py
									
									
									
									
									
								
							
							
						
						
									
										40
									
								
								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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user