feat(napcat): 支持直接和反向 WebSocket 模式

Napcat 适配器现在支持“直接”(客户端)和“反向”(服务器)两种 WebSocket 连接模式。可以通过插件配置中的 `napcat_server.mode` 设置进行配置。

此外,此次提交修复了群组和私信消息过滤中的一个错误,即配置中的数字 ID 未能正确与消息中的字符串 ID 进行比较。现在所有列表 ID 都会被转换为字符串,以确保过滤可靠。
This commit is contained in:
tt-P607
2025-11-27 21:34:11 +08:00
parent bea0d033cf
commit a0d0a71b63
2 changed files with 6 additions and 3 deletions

View File

@@ -50,6 +50,8 @@ class NapcatAdapter(BaseAdapter):
host = config_api.get_plugin_config(plugin.config, "napcat_server.host", "localhost")
port = config_api.get_plugin_config(plugin.config, "napcat_server.port", 8095)
access_token = config_api.get_plugin_config(plugin.config, "napcat_server.access_token", "")
mode_str = config_api.get_plugin_config(plugin.config, "napcat_server.mode", "reverse")
ws_mode = "client" if mode_str == "direct" else "server"
ws_url = f"ws://{host}:{port}"
headers = {}
@@ -58,10 +60,11 @@ class NapcatAdapter(BaseAdapter):
else:
ws_url = "ws://127.0.0.1:8095"
headers = {}
ws_mode = "server"
# 配置 WebSocket 传输
transport = WebSocketAdapterOptions(
mode="server",
mode=ws_mode,
url=ws_url,
headers=headers if headers else None,
)

View File

@@ -79,7 +79,7 @@ class MessageHandler:
# 获取群聊配置
group_list_type = features_config.get("group_list_type", "blacklist")
group_list = features_config.get("group_list", [])
group_list = [str(item) for item in features_config.get("group_list", [])]
if group_list_type == "blacklist":
# 黑名单模式:如果在黑名单中就过滤
@@ -96,7 +96,7 @@ class MessageHandler:
elif message_type == "private":
# 获取私聊配置
private_list_type = features_config.get("private_list_type", "blacklist")
private_list = features_config.get("private_list", [])
private_list = [str(item) for item in features_config.get("private_list", [])]
if private_list_type == "blacklist":
# 黑名单模式:如果在黑名单中就过滤