The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
refactor(discord): move config.yaml readers to adapter_config_readers
Tekniume8d3dc9eef94
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.pyindex 68e802a127c..b10478bfa24 100644--- a/plugins/platforms/discord/adapter.py+++ b/plugins/platforms/discord/adapter.py@@ -1200,30 +1200,8 @@ class VoiceReceiver:)-def _read_dm_role_auth_guild() -> Optional[int]:- """Return the guild ID opted-in for DM role-based auth, or None (secure default). Read from- config.yaml ``discord.dm_role_auth_guild`` only (behavioral, not a secret); int or numeric string."""- try:- from hermes_cli.config import read_raw_config- cfg = read_raw_config() or {}- discord_cfg = cfg.get("discord", {}) or {}- raw = discord_cfg.get("dm_role_auth_guild")- except Exception:- return None- if raw is None or raw == "":- return None- try:- guild_id = int(raw)- except (TypeError, ValueError):- return None- return guild_id if guild_id > 0 else None---# Default timeout for Discord button views when ``approvals.discord_prompt_timeout`` is unset;-# Discord interaction tokens expire at ~15 minutes, so 900s is the practical ceiling.-_DISCORD_PROMPT_TIMEOUT_DEFAULT = 300-_DISCORD_PROMPT_TIMEOUT_MIN = 30-_DISCORD_PROMPT_TIMEOUT_MAX = 900+from plugins.platforms.discord.adapter_config_readers import ( # noqa: F401 - re-exported for callers/tests+ _DISCORD_PROMPT_TIMEOUT_DEFAULT, _DISCORD_PROMPT_TIMEOUT_MIN, _read_discord_prompt_timeout, _read_dm_role_auth_guild)def _env_bool(name: str, default: bool = False) -> bool:@@ -1233,30 +1211,6 @@ def _env_bool(name: str, default: bool = False) -> bool:return raw in {"true", "1", "yes", "on"}-def _read_discord_prompt_timeout() -> int:- """Timeout (seconds) for Discord button views from ``approvals.discord_prompt_timeout``- (default 300), clamped to [MIN, MAX] so a typo can't make prompts vanish or outlive tokens."""- raw: Any = None- try:- from hermes_cli.config import read_raw_config- cfg = read_raw_config() or {}- approvals_cfg = cfg.get("approvals", {}) or {}- raw = approvals_cfg.get("discord_prompt_timeout")- except Exception:- return _DISCORD_PROMPT_TIMEOUT_DEFAULT- if raw is None or raw == "":- return _DISCORD_PROMPT_TIMEOUT_DEFAULT- try:- seconds = int(raw)- except (TypeError, ValueError):- return _DISCORD_PROMPT_TIMEOUT_DEFAULT- if seconds < _DISCORD_PROMPT_TIMEOUT_MIN:- return _DISCORD_PROMPT_TIMEOUT_MIN- if seconds > _DISCORD_PROMPT_TIMEOUT_MAX:- return _DISCORD_PROMPT_TIMEOUT_MAX- return seconds--from plugins.platforms.discord.adapter_media import DiscordMediaMixinfrom plugins.platforms.discord.adapter_authorization import DiscordAuthorizationMixinfrom plugins.platforms.discord.adapter_slash_auth import DiscordSlashAuthMixindiff --git a/plugins/platforms/discord/adapter_config_readers.py b/plugins/platforms/discord/adapter_config_readers.pynew file mode 100644index 00000000000..200cb210cd6--- /dev/null+++ b/plugins/platforms/discord/adapter_config_readers.py@@ -0,0 +1,55 @@+"""config.yaml readers for the Discord adapter: DM role-auth guild opt-in and button-view timeout.++Re-exported from ``plugins.platforms.discord.adapter`` (callers and tests import them there).+"""+from typing import Any, Optional+++def _read_dm_role_auth_guild() -> Optional[int]:+ """Return the guild ID opted-in for DM role-based auth, or None (secure default). Read from+ config.yaml ``discord.dm_role_auth_guild`` only (behavioral, not a secret); int or numeric string."""+ try:+ from hermes_cli.config import read_raw_config+ cfg = read_raw_config() or {}+ discord_cfg = cfg.get("discord", {}) or {}+ raw = discord_cfg.get("dm_role_auth_guild")+ except Exception:+ return None+ if raw is None or raw == "":+ return None+ try:+ guild_id = int(raw)+ except (TypeError, ValueError):+ return None+ return guild_id if guild_id > 0 else None+++# Default timeout for Discord button views when ``approvals.discord_prompt_timeout`` is unset;+# Discord interaction tokens expire at ~15 minutes, so 900s is the practical ceiling.+_DISCORD_PROMPT_TIMEOUT_DEFAULT = 300+_DISCORD_PROMPT_TIMEOUT_MIN = 30+_DISCORD_PROMPT_TIMEOUT_MAX = 900+++def _read_discord_prompt_timeout() -> int:+ """Timeout (seconds) for Discord button views from ``approvals.discord_prompt_timeout``+ (default 300), clamped to [MIN, MAX] so a typo can't make prompts vanish or outlive tokens."""+ raw: Any = None+ try:+ from hermes_cli.config import read_raw_config+ cfg = read_raw_config() or {}+ approvals_cfg = cfg.get("approvals", {}) or {}+ raw = approvals_cfg.get("discord_prompt_timeout")+ except Exception:+ return _DISCORD_PROMPT_TIMEOUT_DEFAULT+ if raw is None or raw == "":+ return _DISCORD_PROMPT_TIMEOUT_DEFAULT+ try:+ seconds = int(raw)+ except (TypeError, ValueError):+ return _DISCORD_PROMPT_TIMEOUT_DEFAULT+ if seconds < _DISCORD_PROMPT_TIMEOUT_MIN:+ return _DISCORD_PROMPT_TIMEOUT_MIN+ if seconds > _DISCORD_PROMPT_TIMEOUT_MAX:+ return _DISCORD_PROMPT_TIMEOUT_MAX+ return seconds