This commit is contained in:
@@ -1830,16 +1830,39 @@ public class AIChatManager {
|
||||
return;
|
||||
}
|
||||
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();
|
||||
int count = 0;
|
||||
for (JsonElement el : arr) {
|
||||
if (el.isJsonPrimitive()) {
|
||||
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) {
|
||||
plugin.getLogger().warning("[AI聊天] 加载黑名单路径失败: " + rawPath + " - " + e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user