This commit is contained in:
@@ -1830,16 +1830,39 @@ public class AIChatManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
String content = Files.readString(resolved.toPath(), StandardCharsets.UTF_8);
|
int totalCount = 0;
|
||||||
JsonArray arr = JsonParser.parseString(content).getAsJsonArray();
|
// ★ 第76批:支持目录扫描——路径是目录则遍历所有 .json,是文件则当单文件读
|
||||||
int count = 0;
|
if (resolved.isDirectory()) {
|
||||||
for (JsonElement el : arr) {
|
File[] jsonFiles = resolved.listFiles((dir, name) -> name.endsWith(".json"));
|
||||||
if (el.isJsonPrimitive()) {
|
if (jsonFiles != null) {
|
||||||
blacklist.add(el.getAsString());
|
for (File jsonFile : jsonFiles) {
|
||||||
count++;
|
try {
|
||||||
|
String content = Files.readString(jsonFile.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聊天] 已加载黑名单文件: " + 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 + "(" + count + " 个关键词)");
|
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());
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user