diff --git a/__pycache__/config.cpython-311.pyc b/__pycache__/config.cpython-311.pyc index 6ecb7f4..100ae0d 100644 Binary files a/__pycache__/config.cpython-311.pyc and b/__pycache__/config.cpython-311.pyc differ diff --git a/config.py b/config.py index fd1cfae..d921284 100644 --- a/config.py +++ b/config.py @@ -30,7 +30,6 @@ DISCORD_TOKEN = _config.get("DISCORD_TOKEN", "YOUR_DISCORD_BOT_TOKEN_HERE") ALLOWED_CHANNEL_ID = _config.get("ALLOWED_CHANNEL_ID", 0) # Intervals -POLL_INTERVAL = _config.get("POLL_INTERVAL", 30) HIT_CHECK_INTERVAL = _config.get("HIT_CHECK_INTERVAL", 60) REASSIGN_DELAY = _config.get("REASSIGN_DELAY", 120) diff --git a/routers/__pycache__/config.cpython-311.pyc b/routers/__pycache__/config.cpython-311.pyc index 6045274..97308eb 100644 Binary files a/routers/__pycache__/config.cpython-311.pyc and b/routers/__pycache__/config.cpython-311.pyc differ diff --git a/routers/config.py b/routers/config.py index 4172076..579dc3a 100644 --- a/routers/config.py +++ b/routers/config.py @@ -31,24 +31,29 @@ def reload_config_from_file(): async def get_config(): """Get all config values (with sensitive values masked)""" path = Path("data/config.json") - if not path.exists(): - # Return defaults from config.py (masked) - config_values = { - "TORN_API_KEY": config_module.TORN_API_KEY, - "FFSCOUTER_KEY": config_module.FFSCOUTER_KEY, - "DISCORD_TOKEN": config_module.DISCORD_TOKEN, - "ALLOWED_CHANNEL_ID": config_module.ALLOWED_CHANNEL_ID, - "POLL_INTERVAL": config_module.POLL_INTERVAL, - "HIT_CHECK_INTERVAL": config_module.HIT_CHECK_INTERVAL, - "REASSIGN_DELAY": config_module.REASSIGN_DELAY, - "ASSIGNMENT_TIMEOUT": config_module.ASSIGNMENT_TIMEOUT, - "ASSIGNMENT_REMINDER": config_module.ASSIGNMENT_REMINDER, - "CHAIN_TIMER_THRESHOLD": config_module.CHAIN_TIMER_THRESHOLD - } - else: + + # Default config values from config.py + default_values = { + "TORN_API_KEY": config_module.TORN_API_KEY, + "FFSCOUTER_KEY": config_module.FFSCOUTER_KEY, + "DISCORD_TOKEN": config_module.DISCORD_TOKEN, + "ALLOWED_CHANNEL_ID": config_module.ALLOWED_CHANNEL_ID, + "HIT_CHECK_INTERVAL": config_module.HIT_CHECK_INTERVAL, + "REASSIGN_DELAY": config_module.REASSIGN_DELAY, + "ASSIGNMENT_TIMEOUT": config_module.ASSIGNMENT_TIMEOUT, + "ASSIGNMENT_REMINDER": config_module.ASSIGNMENT_REMINDER, + "CHAIN_TIMER_THRESHOLD": config_module.CHAIN_TIMER_THRESHOLD + } + + if path.exists(): with open(path, "r", encoding="utf-8") as f: data = json.load(f) - config_values = data.get("config", {}) + file_values = data.get("config", {}) + + # Merge defaults with file values (file values take precedence) + config_values = {**default_values, **file_values} + else: + config_values = default_values # Mask sensitive values masked_config = config_values.copy() @@ -66,6 +71,17 @@ async def update_config(req: ConfigUpdateRequest): """Update a single config value""" path = Path("data/config.json") + # Valid config keys (from config.py) + valid_keys = { + "TORN_API_KEY", "FFSCOUTER_KEY", "DISCORD_TOKEN", "ALLOWED_CHANNEL_ID", + "HIT_CHECK_INTERVAL", "REASSIGN_DELAY", + "ASSIGNMENT_TIMEOUT", "ASSIGNMENT_REMINDER", "CHAIN_TIMER_THRESHOLD" + } + + # Validate key is valid + if req.key not in valid_keys: + raise HTTPException(status_code=400, detail="Invalid config key") + # Load existing or create from current config if path.exists(): with open(path, "r", encoding="utf-8") as f: @@ -78,7 +94,6 @@ async def update_config(req: ConfigUpdateRequest): "FFSCOUTER_KEY": config_module.FFSCOUTER_KEY, "DISCORD_TOKEN": config_module.DISCORD_TOKEN, "ALLOWED_CHANNEL_ID": config_module.ALLOWED_CHANNEL_ID, - "POLL_INTERVAL": config_module.POLL_INTERVAL, "HIT_CHECK_INTERVAL": config_module.HIT_CHECK_INTERVAL, "REASSIGN_DELAY": config_module.REASSIGN_DELAY, "ASSIGNMENT_TIMEOUT": config_module.ASSIGNMENT_TIMEOUT, @@ -87,9 +102,10 @@ async def update_config(req: ConfigUpdateRequest): } } - # Validate key exists + # Add key if it doesn't exist in config (for backwards compatibility) if req.key not in data["config"]: - raise HTTPException(status_code=400, detail="Invalid config key") + print(f"Adding new config key: {req.key}") + data["config"][req.key] = getattr(config_module, req.key) # Update value data["config"][req.key] = req.value diff --git a/static/config.js b/static/config.js index d0301f9..2adf3ec 100644 --- a/static/config.js +++ b/static/config.js @@ -4,7 +4,6 @@ const CONFIG_FIELDS = { "FFSCOUTER_KEY": "ffscouter-key", "DISCORD_TOKEN": "discord-token", "ALLOWED_CHANNEL_ID": "allowed-channel-id", - "POLL_INTERVAL": "poll-interval", "HIT_CHECK_INTERVAL": "hit-check-interval", "REASSIGN_DELAY": "reassign-delay", "ASSIGNMENT_TIMEOUT": "assignment-timeout", diff --git a/templates/config.html b/templates/config.html index a98a30c..0066313 100644 --- a/templates/config.html +++ b/templates/config.html @@ -70,13 +70,6 @@ -
General polling interval for data refresh
- - -Interval for checking hit completion