- Hybrid Python/Node.js architecture with WebSocket bridge - PySide6 desktop app with smoky blue futuristic theme - Dashboard, Create Doug, Settings screens - bedrock-protocol connection to BDS (offline + Xbox Live auth) - Realm support (auth flow with device code + browser auto-open) - Ollama integration with lean persona prompt (~95 tokens) - 40 personality traits (15 sliders + 23 quirks + 2 toggles) - SQLite + MariaDB database with 12 tables - Chat working in-game with proper Bedrock text packet format - RakNet protocol 11 patch for newer BDS versions - jsp-raknet backend (native crashes on ARM64 macOS) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
85 lines
2.4 KiB
Python
85 lines
2.4 KiB
Python
"""
|
|
Application configuration management.
|
|
Handles loading/saving settings from ~/.dougbot/settings.json
|
|
"""
|
|
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
from typing import Any, Optional
|
|
|
|
|
|
DEFAULT_CONFIG = {
|
|
"db_type": "sqlite",
|
|
"db_host": "127.0.0.1",
|
|
"db_port": 3306,
|
|
"db_user": "",
|
|
"db_pass": "",
|
|
"db_name": "dougbot",
|
|
"ollama_host": "http://127.0.0.1",
|
|
"ollama_port": 11434,
|
|
"ollama_model": "",
|
|
"bridge_base_port": 8765,
|
|
}
|
|
|
|
|
|
class AppConfig:
|
|
"""Manages application-wide configuration."""
|
|
|
|
def __init__(self):
|
|
self._config_dir = Path.home() / ".dougbot"
|
|
self._config_file = self._config_dir / "settings.json"
|
|
self._data: dict[str, Any] = {}
|
|
self.load()
|
|
|
|
def load(self) -> None:
|
|
"""Load configuration from disk, creating defaults if needed."""
|
|
self._config_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
if self._config_file.exists():
|
|
try:
|
|
with open(self._config_file, "r") as f:
|
|
self._data = json.load(f)
|
|
except (json.JSONDecodeError, IOError):
|
|
self._data = {}
|
|
|
|
# Merge defaults for any missing keys
|
|
for key, value in DEFAULT_CONFIG.items():
|
|
if key not in self._data:
|
|
self._data[key] = value
|
|
|
|
def save(self) -> None:
|
|
"""Save current configuration to disk."""
|
|
self._config_dir.mkdir(parents=True, exist_ok=True)
|
|
with open(self._config_file, "w") as f:
|
|
json.dump(self._data, f, indent=2)
|
|
|
|
def get(self, key: str, default: Any = None) -> Any:
|
|
"""Get a configuration value."""
|
|
return self._data.get(key, default)
|
|
|
|
def set(self, key: str, value: Any) -> None:
|
|
"""Set a configuration value."""
|
|
self._data[key] = value
|
|
|
|
def get_all(self) -> dict[str, Any]:
|
|
"""Get all configuration as a dict."""
|
|
return dict(self._data)
|
|
|
|
@property
|
|
def db_type(self) -> str:
|
|
return self._data.get("db_type", "sqlite")
|
|
|
|
@property
|
|
def ollama_url(self) -> str:
|
|
host = self._data.get("ollama_host", "http://127.0.0.1")
|
|
port = self._data.get("ollama_port", 11434)
|
|
return f"{host}:{port}"
|
|
|
|
@property
|
|
def sqlite_path(self) -> str:
|
|
return str(self._config_dir / "dougbot.db")
|
|
|
|
@property
|
|
def config_dir(self) -> Path:
|
|
return self._config_dir
|