♻️ refactor(command): 黑白名单过滤从 AND 改为 OR 逻辑
- 白名单模式:用户在名单 OR 群在名单 → 放行 - 黑名单模式:用户在名单 OR 群在名单 → 拒绝 - 名单为空时表示不限制 - 更新前端提示说明 OR 逻辑的语义
This commit is contained in:
@@ -606,7 +606,10 @@ body {
|
||||
<div class="card-header"><h3>名单开关</h3></div>
|
||||
<div class="card-body">
|
||||
<div class="info-block">
|
||||
开启后,仅名单内的群/用户可触发命令(白名单),或名单内的群/用户不可触发(黑名单)。
|
||||
<strong>白名单模式:</strong>用户在名单 <em>或</em> 群在名单 → 可触发。<br>
|
||||
例如:设置白名单群后,该群全员可用;设置白名单用户后,该用户全域可用。<br>
|
||||
<strong>黑名单模式:</strong>用户在名单 <em>或</em> 群在名单 → 拒绝。<br>
|
||||
名单为空时表示不限制。
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<div class="switch-wrapper">
|
||||
@@ -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');
|
||||
|
||||
20
plugin.py
20
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
|
||||
|
||||
# 构建回调数据
|
||||
|
||||
Reference in New Issue
Block a user