Compare commits
3 Commits
9be7c0b1d2
...
5c5c9e2723
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c5c9e2723 | |||
| b4e48ce375 | |||
| 7c9cf0d8b4 |
30
bot/api.py
30
bot/api.py
@@ -2978,15 +2978,27 @@ async def set_config_value(request: Request):
|
|||||||
from config_manager import config_manager
|
from config_manager import config_manager
|
||||||
config_manager.set(key_path, value, persist=persist)
|
config_manager.set(key_path, value, persist=persist)
|
||||||
|
|
||||||
# Update globals if needed
|
# ── Sync globals for every runtime-relevant key path ──
|
||||||
if key_path == "discord.language_mode":
|
_GLOBALS_SYNC = {
|
||||||
globals.LANGUAGE_MODE = value
|
"discord.language_mode": ("LANGUAGE_MODE", str),
|
||||||
elif key_path == "autonomous.debug_mode":
|
"autonomous.debug_mode": ("AUTONOMOUS_DEBUG", bool),
|
||||||
globals.AUTONOMOUS_DEBUG = value
|
"voice.debug_mode": ("VOICE_DEBUG_MODE", bool),
|
||||||
elif key_path == "voice.debug_mode":
|
"memory.use_cheshire_cat": ("USE_CHESHIRE_CAT", bool),
|
||||||
globals.VOICE_DEBUG_MODE = value
|
"gpu.prefer_amd": ("PREFER_AMD_GPU", bool),
|
||||||
elif key_path == "gpu.prefer_amd":
|
}
|
||||||
globals.PREFER_AMD_GPU = value
|
|
||||||
|
if key_path in _GLOBALS_SYNC:
|
||||||
|
attr, converter = _GLOBALS_SYNC[key_path]
|
||||||
|
setattr(globals, attr, converter(value))
|
||||||
|
elif key_path == "runtime.mood.dm_mood":
|
||||||
|
# DM mood needs description loaded alongside
|
||||||
|
if isinstance(value, str) and value in getattr(globals, "AVAILABLE_MOODS", []):
|
||||||
|
globals.DM_MOOD = value
|
||||||
|
try:
|
||||||
|
from utils.moods import load_mood_description
|
||||||
|
globals.DM_MOOD_DESCRIPTION = load_mood_description(value)
|
||||||
|
except Exception:
|
||||||
|
globals.DM_MOOD_DESCRIPTION = f"I'm feeling {value} today."
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"success": True,
|
"success": True,
|
||||||
|
|||||||
@@ -225,9 +225,16 @@ class ConfigManager:
|
|||||||
"""
|
"""
|
||||||
Reset configuration to defaults.
|
Reset configuration to defaults.
|
||||||
|
|
||||||
|
Clears runtime overrides from config_runtime.yaml AND resets the
|
||||||
|
corresponding globals to their default values so the change takes
|
||||||
|
effect immediately without a restart.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
key_path: Specific key to reset, or None to reset all runtime config
|
key_path: Specific key to reset, or None to reset all runtime config
|
||||||
"""
|
"""
|
||||||
|
import globals as g
|
||||||
|
from config import CONFIG
|
||||||
|
|
||||||
if key_path:
|
if key_path:
|
||||||
# Remove specific key from runtime config
|
# Remove specific key from runtime config
|
||||||
self._remove_nested_key(self.runtime_config, key_path)
|
self._remove_nested_key(self.runtime_config, key_path)
|
||||||
@@ -239,6 +246,38 @@ class ConfigManager:
|
|||||||
|
|
||||||
self.save_runtime_config()
|
self.save_runtime_config()
|
||||||
|
|
||||||
|
# ---- Reset live globals to match defaults ----
|
||||||
|
# Map: config_runtime key path -> (globals attr, default from CONFIG)
|
||||||
|
_DEFAULTS_MAP = {
|
||||||
|
"discord.language_mode": ("LANGUAGE_MODE", CONFIG.discord.language_mode),
|
||||||
|
"autonomous.debug_mode": ("AUTONOMOUS_DEBUG", CONFIG.autonomous.debug_mode),
|
||||||
|
"voice.debug_mode": ("VOICE_DEBUG_MODE", CONFIG.voice.debug_mode),
|
||||||
|
"memory.use_cheshire_cat": ("USE_CHESHIRE_CAT", CONFIG.cheshire_cat.enabled),
|
||||||
|
"gpu.prefer_amd": ("PREFER_AMD_GPU", CONFIG.gpu.prefer_amd),
|
||||||
|
}
|
||||||
|
|
||||||
|
reset_items = []
|
||||||
|
|
||||||
|
if key_path:
|
||||||
|
# Reset only the specific global
|
||||||
|
if key_path in _DEFAULTS_MAP:
|
||||||
|
attr, default = _DEFAULTS_MAP[key_path]
|
||||||
|
setattr(g, attr, default)
|
||||||
|
reset_items.append(f"{attr}={default}")
|
||||||
|
else:
|
||||||
|
# Reset all globals to defaults
|
||||||
|
for kp, (attr, default) in _DEFAULTS_MAP.items():
|
||||||
|
setattr(g, attr, default)
|
||||||
|
reset_items.append(f"{attr}={default}")
|
||||||
|
|
||||||
|
# Also reset DM mood to neutral
|
||||||
|
g.DM_MOOD = "neutral"
|
||||||
|
g.DM_MOOD_DESCRIPTION = "I'm feeling neutral and balanced today."
|
||||||
|
reset_items.append("DM_MOOD=neutral")
|
||||||
|
|
||||||
|
if reset_items:
|
||||||
|
logger.info(f"🔄 Reset {len(reset_items)} globals: {', '.join(reset_items)}")
|
||||||
|
|
||||||
def _remove_nested_key(self, config: Dict, key_path: str):
|
def _remove_nested_key(self, config: Dict, key_path: str):
|
||||||
"""Remove nested key from config."""
|
"""Remove nested key from config."""
|
||||||
keys = key_path.split(".")
|
keys = key_path.split(".")
|
||||||
@@ -282,48 +321,6 @@ class ConfigManager:
|
|||||||
self._current_gpu = value
|
self._current_gpu = value
|
||||||
logger.debug(f"📊 State: {key} = {value}")
|
logger.debug(f"📊 State: {key} = {value}")
|
||||||
|
|
||||||
# ========== Server Configuration ==========
|
|
||||||
|
|
||||||
def get_server_config(self, guild_id: int) -> Dict:
|
|
||||||
"""Get configuration for a specific server."""
|
|
||||||
server_config_file = self.memory_dir / "servers_config.json"
|
|
||||||
|
|
||||||
try:
|
|
||||||
if server_config_file.exists():
|
|
||||||
with open(server_config_file, "r") as f:
|
|
||||||
all_servers = json.load(f)
|
|
||||||
return all_servers.get(str(guild_id), {})
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"❌ Failed to load server config: {e}")
|
|
||||||
|
|
||||||
return {}
|
|
||||||
|
|
||||||
def set_server_config(self, guild_id: int, config: Dict):
|
|
||||||
"""Set configuration for a specific server."""
|
|
||||||
server_config_file = self.memory_dir / "servers_config.json"
|
|
||||||
|
|
||||||
try:
|
|
||||||
# Load existing config
|
|
||||||
all_servers = {}
|
|
||||||
if server_config_file.exists():
|
|
||||||
with open(server_config_file, "r") as f:
|
|
||||||
all_servers = json.load(f)
|
|
||||||
|
|
||||||
# Update server config
|
|
||||||
all_servers[str(guild_id)] = {
|
|
||||||
**all_servers.get(str(guild_id), {}),
|
|
||||||
**config,
|
|
||||||
"last_updated": datetime.now().isoformat()
|
|
||||||
}
|
|
||||||
|
|
||||||
# Save
|
|
||||||
with open(server_config_file, "w") as f:
|
|
||||||
json.dump(all_servers, f, indent=2)
|
|
||||||
|
|
||||||
logger.info(f"💾 Saved server config for {guild_id}")
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"❌ Failed to save server config: {e}")
|
|
||||||
|
|
||||||
# ========== GPU State ==========
|
# ========== GPU State ==========
|
||||||
|
|
||||||
def get_gpu(self) -> str:
|
def get_gpu(self) -> str:
|
||||||
|
|||||||
Reference in New Issue
Block a user