From 783049257ea63df91b1fc4b4c0cf9aa387c8e75a Mon Sep 17 00:00:00 2001 From: zhilv Date: Mon, 4 May 2026 00:05:18 +0800 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20refactor(command):=20?= =?UTF-8?q?=E9=BB=91=E7=99=BD=E5=90=8D=E5=8D=95=E8=BF=87=E6=BB=A4=E4=BB=8E?= =?UTF-8?q?=20AND=20=E6=94=B9=E4=B8=BA=20OR=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 白名单模式:用户在名单 OR 群在名单 → 放行 - 黑名单模式:用户在名单 OR 群在名单 → 拒绝 - 名单为空时表示不限制 - 更新前端提示说明 OR 逻辑的语义 --- handlers/admin.py | 12 ++++++++---- plugin.py | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/handlers/admin.py b/handlers/admin.py index de3396b..1782de5 100644 --- a/handlers/admin.py +++ b/handlers/admin.py @@ -606,7 +606,10 @@ body {

名单开关

- 开启后,仅名单内的群/用户可触发命令(白名单),或名单内的群/用户不可触发(黑名单)。 + 白名单模式:用户在名单 群在名单 → 可触发。
+ 例如:设置白名单群后,该群全员可用;设置白名单用户后,该用户全域可用。
+ 黑名单模式:用户在名单 群在名单 → 拒绝。
+ 名单为空时表示不限制。
@@ -835,20 +838,21 @@ function updateListModeUI() { const allowUserContainer = document.getElementById('allowedUsersContainer'); const denyUserContainer = document.getElementById('deniedUsersContainer'); - // Reset + // Reset - all enabled [allowGroups, denyGroups, allowUsers, denyUsers].forEach(el => el.style.opacity = '1'); [allowContainer, denyContainer, allowUserContainer, denyUserContainer].forEach(el => el.classList.remove('disabled')); if (!enabled) return; + // OR 逻辑下,两种名单可以同时配置,但只用当前模式的名单 if (mode === 'allow') { - // 白名单模式:灰掉黑名单 + // 白名单模式:灰掉黑名单(不生效) denyGroups.style.opacity = '0.4'; denyUsers.style.opacity = '0.4'; denyContainer.classList.add('disabled'); denyUserContainer.classList.add('disabled'); } else { - // 黑名单模式:灰掉白名单 + // 黑名单模式:灰掉白名单(不生效) allowGroups.style.opacity = '0.4'; allowUsers.style.opacity = '0.4'; allowContainer.classList.add('disabled'); diff --git a/plugin.py b/plugin.py index 27f76da..878b1a5 100644 --- a/plugin.py +++ b/plugin.py @@ -125,18 +125,18 @@ class WebHookPlugin(NcatBotPlugin): # 黑白名单过滤 if command.list_enabled: if command.list_mode == "allow": - # 白名单模式:在名单内才放行 - if command.allowed_groups and is_group: - if event.data.group_id not in command.allowed_groups: + # 白名单模式(OR 逻辑):用户在名单 OR 群在名单 → 放行 + # 名单为空时视为不限制 + if command.allowed_users or command.allowed_groups: + user_ok = event.data.user_id in command.allowed_users + group_ok = is_group and event.data.group_id in command.allowed_groups + if not (user_ok or group_ok): continue - if command.allowed_users and event.data.user_id not in command.allowed_users: - continue elif command.list_mode == "deny": - # 黑名单模式:在名单内则拒绝 - if command.denied_groups and is_group: - if event.data.group_id in command.denied_groups: - continue - if command.denied_users and event.data.user_id in command.denied_users: + # 黑名单模式:用户在名单 OR 群在名单 → 拒绝 + user_blocked = event.data.user_id in command.denied_users + group_blocked = is_group and event.data.group_id in command.denied_groups + if user_blocked or group_blocked: continue # 构建回调数据