第76批补:黑名单路径支持目录扫描(目录→遍历json文件)
Auto Release / build (push) Successful in 2m17s

This commit is contained in:
youpaishidifu
2026-11-04 09:20:08 +08:00
parent b454cfe5ba
commit 680b4f42ea
+27 -4
View File
@@ -1830,16 +1830,39 @@ public class AIChatManager {
return; return;
} }
try { try {
String content = Files.readString(resolved.toPath(), StandardCharsets.UTF_8); int totalCount = 0;
// ★ 第76批:支持目录扫描——路径是目录则遍历所有 .json,是文件则当单文件读
if (resolved.isDirectory()) {
File[] jsonFiles = resolved.listFiles((dir, name) -> name.endsWith(".json"));
if (jsonFiles != null) {
for (File jsonFile : jsonFiles) {
try {
String content = Files.readString(jsonFile.toPath(), StandardCharsets.UTF_8);
JsonArray arr = JsonParser.parseString(content).getAsJsonArray(); JsonArray arr = JsonParser.parseString(content).getAsJsonArray();
int count = 0;
for (JsonElement el : arr) { for (JsonElement el : arr) {
if (el.isJsonPrimitive()) { if (el.isJsonPrimitive()) {
blacklist.add(el.getAsString()); blacklist.add(el.getAsString());
count++; totalCount++;
} }
} }
plugin.getLogger().info("[AI聊天] 已从路径加载黑名单: " + rawPath + "(" + count + " 个关键词)"); plugin.getLogger().info("[AI聊天] 已加载黑名单文件: " + jsonFile.getName() + "(" + arr.size() + " 个关键词)");
} catch (Exception e) {
plugin.getLogger().warning("[AI聊天] 加载黑名单文件失败: " + jsonFile.getName() + " - " + e.getMessage());
}
}
}
} else {
// 单文件
String content = Files.readString(resolved.toPath(), StandardCharsets.UTF_8);
JsonArray arr = JsonParser.parseString(content).getAsJsonArray();
for (JsonElement el : arr) {
if (el.isJsonPrimitive()) {
blacklist.add(el.getAsString());
totalCount++;
}
}
}
plugin.getLogger().info("[AI聊天] 已从路径加载黑名单: " + rawPath + "(" + totalCount + " 个关键词)");
} catch (Exception e) { } catch (Exception e) {
plugin.getLogger().warning("[AI聊天] 加载黑名单路径失败: " + rawPath + " - " + e.getMessage()); plugin.getLogger().warning("[AI聊天] 加载黑名单路径失败: " + rawPath + " - " + e.getMessage());
} }