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 ++++++----- cogs/utils/temp.py | 4 ++-- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'cogs/utils') 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 diff --git a/cogs/utils/temp.py b/cogs/utils/temp.py index 528d6a3..0b2c8d7 100644 --- a/cogs/utils/temp.py +++ b/cogs/utils/temp.py @@ -8,11 +8,11 @@ import tempfile def get_temp_dir(subdir: str = "senator_sperma") -> str: """Get or create a temp subdirectory. - + Uses system temp directory (/tmp on Linux, %TEMP% on Windows). OS handles cleanup automatically. """ base_temp = tempfile.gettempdir() temp_path = os.path.join(base_temp, subdir) os.makedirs(temp_path, exist_ok=True) - return temp_path \ No newline at end of file + return temp_path -- cgit v1.2.3