feat(napcat): 支持直接和反向 WebSocket 模式
Napcat 适配器现在支持“直接”(客户端)和“反向”(服务器)两种 WebSocket 连接模式。可以通过插件配置中的 `napcat_server.mode` 设置进行配置。 此外,此次提交修复了群组和私信消息过滤中的一个错误,即配置中的数字 ID 未能正确与消息中的字符串 ID 进行比较。现在所有列表 ID 都会被转换为字符串,以确保过滤可靠。
This commit is contained in:
@@ -50,6 +50,8 @@ class NapcatAdapter(BaseAdapter):
|
|||||||
host = config_api.get_plugin_config(plugin.config, "napcat_server.host", "localhost")
|
host = config_api.get_plugin_config(plugin.config, "napcat_server.host", "localhost")
|
||||||
port = config_api.get_plugin_config(plugin.config, "napcat_server.port", 8095)
|
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", "")
|
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}"
|
ws_url = f"ws://{host}:{port}"
|
||||||
headers = {}
|
headers = {}
|
||||||
@@ -58,10 +60,11 @@ class NapcatAdapter(BaseAdapter):
|
|||||||
else:
|
else:
|
||||||
ws_url = "ws://127.0.0.1:8095"
|
ws_url = "ws://127.0.0.1:8095"
|
||||||
headers = {}
|
headers = {}
|
||||||
|
ws_mode = "server"
|
||||||
|
|
||||||
# 配置 WebSocket 传输
|
# 配置 WebSocket 传输
|
||||||
transport = WebSocketAdapterOptions(
|
transport = WebSocketAdapterOptions(
|
||||||
mode="server",
|
mode=ws_mode,
|
||||||
url=ws_url,
|
url=ws_url,
|
||||||
headers=headers if headers else None,
|
headers=headers if headers else None,
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ class MessageHandler:
|
|||||||
|
|
||||||
# 获取群聊配置
|
# 获取群聊配置
|
||||||
group_list_type = features_config.get("group_list_type", "blacklist")
|
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":
|
if group_list_type == "blacklist":
|
||||||
# 黑名单模式:如果在黑名单中就过滤
|
# 黑名单模式:如果在黑名单中就过滤
|
||||||
@@ -96,7 +96,7 @@ class MessageHandler:
|
|||||||
elif message_type == "private":
|
elif message_type == "private":
|
||||||
# 获取私聊配置
|
# 获取私聊配置
|
||||||
private_list_type = features_config.get("private_list_type", "blacklist")
|
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":
|
if private_list_type == "blacklist":
|
||||||
# 黑名单模式:如果在黑名单中就过滤
|
# 黑名单模式:如果在黑名单中就过滤
|
||||||
|
|||||||
Reference in New Issue
Block a user