From 1dcdbe3cf03ff16b3ff2e2e6d572e0b3c72c18c0 Mon Sep 17 00:00:00 2001 From: salmonik Date: Sun, 19 Apr 2026 15:43:32 +0200 Subject: refactor: simplify cogs, reduce complexity - Remove unused imports and dead code - Cleaner error handling - Reduce cognitive complexity --- cogs/utils/settings.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'cogs/utils/settings.py') diff --git a/cogs/utils/settings.py b/cogs/utils/settings.py index 984ec16..d66ce7f 100644 --- a/cogs/utils/settings.py +++ b/cogs/utils/settings.py @@ -12,18 +12,19 @@ from dataclasses import dataclass, field logger = logging.getLogger(__name__) settings_file = "data/settings.json" +DEFAULT_BASEURL = "http://localhost:8080" @dataclass class Settings: volume: float = 1.0 - baseurl: str = "http://localhost:8080" + baseurl: str = DEFAULT_BASEURL _data: dict = field(default_factory=dict, init=False) async def load(self) -> "Settings": default_settings = { "volume": 1.0, - "baseurl": "http://localhost:8080", + "baseurl": DEFAULT_BASEURL, } try: @@ -44,7 +45,7 @@ class Settings: self._sync_from_data() await self.save() logger.info("Created default settings.json") - except (json.JSONDecodeError, Exception) as e: + except json.JSONDecodeError as e: logger.error(f"Error loading settings: {e}") self._data = default_settings.copy() self._sync_from_data() @@ -53,7 +54,7 @@ class Settings: def _sync_from_data(self): self.volume = self._data.get("volume", 1.0) - self.baseurl = self._data.get("baseurl", "http://localhost:8080") + self.baseurl = self._data.get("baseurl", DEFAULT_BASEURL) def _sync_to_data(self): self._data["volume"] = self.volume @@ -89,4 +90,4 @@ def get_volume() -> float: def get_baseurl() -> str: - return _settings_instance.baseurl.rstrip("/") if _settings_instance else "http://localhost:8080" + return _settings_instance.baseurl.rstrip("/") if _settings_instance else DEFAULT_BASEURL -- cgit v1.2.3