From dff07c09d8693fbfa3486f3a5fa84f0f6886f825 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Wed, 2 Sep 2026 22:39:44 -0700 Subject: [PATCH] =?UTF-8?q?refactor(hermes=5Fcli):=20gateway.py=20setup=20?= =?UTF-8?q?wizard=20=E2=80=94=20drop=20redundant=20local=20import,=20join?= =?UTF-8?q?=20choice=20lists?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hermes_cli/gateway.py | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) diff --git a/hermes_cli/gateway.py b/hermes_cli/gateway.py index 5fb6490f0b..dd8fdc5c78 100644 --- a/hermes_cli/gateway.py +++ b/hermes_cli/gateway.py @@ -4963,7 +4963,6 @@ def _systemd_unit_installed() -> bool: def _is_service_installed() -> bool: - """Check if the gateway is installed as a system service.""" return _installed_service_kind() is not None @@ -5027,7 +5026,6 @@ def _setup_weixin(): print_info(" Cancelled.") return - import asyncio try: credentials = asyncio.run(qr_login(str(get_hermes_home()))) except KeyboardInterrupt: @@ -5044,20 +5042,18 @@ def _setup_weixin(): account_id = credentials.get("account_id", "") user_id = credentials.get("user_id", "") - base_url = credentials.get("base_url", "") - save_env_value("WEIXIN_ACCOUNT_ID", account_id) save_env_value("WEIXIN_TOKEN", credentials.get("token", "")) - if base_url: - save_env_value("WEIXIN_BASE_URL", base_url) + if credentials.get("base_url", ""): + save_env_value("WEIXIN_BASE_URL", credentials.get("base_url", "")) save_env_value( "WEIXIN_CDN_BASE_URL", get_env_value("WEIXIN_CDN_BASE_URL") or "https://novac2c.cdn.weixin.qq.com/c2c" ) print() access_choices = [ - "Use DM pairing approval (recommended)", "Allow all direct messages", - "Only allow listed user IDs", "Disable direct messages", + "Use DM pairing approval (recommended)", "Allow all direct messages", "Only allow listed user IDs", + "Disable direct messages", ] access_idx = prompt_choice(" How should direct messages be authorized?", access_choices, 0) if access_idx == 2: @@ -5111,10 +5107,7 @@ def _setup_qqbot(): return print() - method_choices = [ - "Scan QR code to add bot automatically (recommended)", - "Enter existing App ID and App Secret manually", - ] + method_choices = ["Scan QR code to add bot automatically (recommended)", "Enter existing App ID and App Secret manually"] credentials = None if prompt_choice(" How would you like to set up QQ Bot?", method_choices, 0) == 0: try: @@ -5150,10 +5143,7 @@ def _setup_qqbot(): user_openid = credentials.get("user_openid", "") print() - access_choices = [ - "Use DM pairing approval (recommended)", "Allow all direct messages", - "Only allow listed user OpenIDs", - ] + access_choices = ["Use DM pairing approval (recommended)", "Allow all direct messages", "Only allow listed user OpenIDs"] access_idx = prompt_choice(" How should direct messages be authorized?", access_choices, 0) if access_idx == 0: save_env_value("QQ_ALLOW_ALL_USERS", "false") @@ -5682,11 +5672,10 @@ def _stop_installed_service(system: bool) -> bool: if kind is None: return False # SystemScopeRequiresRootError is a RuntimeError and must propagate from systemd_stop. - swallow = (subprocess.CalledProcessError, RuntimeError) if kind == "windows" else subprocess.CalledProcessError try: _service_call(kind, "stop", system) return True - except swallow: + except (subprocess.CalledProcessError, *((RuntimeError,) if kind == "windows" else ())): return False