This commit is contained in:
@@ -1831,38 +1831,47 @@ public class AIChatManager {
|
||||
}
|
||||
try {
|
||||
int totalCount = 0;
|
||||
// ★ 第76批:支持目录扫描——路径是目录则遍历所有 .json,是文件则当单文件读
|
||||
// ★ 第76批补:增量重载——用指纹对比文件内容,无变化闭嘴、有变化才打印
|
||||
// 复用 blacklistFileKeywords/blacklistFileHashes 映射
|
||||
java.util.List<File> targetFiles = new java.util.ArrayList<>();
|
||||
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();
|
||||
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());
|
||||
}
|
||||
}
|
||||
targetFiles.addAll(java.util.Arrays.asList(jsonFiles));
|
||||
}
|
||||
} else {
|
||||
// 单文件
|
||||
String content = Files.readString(resolved.toPath(), StandardCharsets.UTF_8);
|
||||
targetFiles.add(resolved);
|
||||
}
|
||||
for (File jsonFile : targetFiles) {
|
||||
String fileName = jsonFile.getName();
|
||||
String content = Files.readString(jsonFile.toPath(), StandardCharsets.UTF_8);
|
||||
String newHash = crc32(content);
|
||||
String oldHash = blacklistFileHashes.get(fileName);
|
||||
if (newHash.equals(oldHash)) {
|
||||
continue; // 文件没变 → 内存不动,闭嘴
|
||||
}
|
||||
// 有变化或新文件:加载关键词
|
||||
java.util.List<String> newKeywords = new java.util.ArrayList<>();
|
||||
JsonArray arr = JsonParser.parseString(content).getAsJsonArray();
|
||||
for (JsonElement el : arr) {
|
||||
if (el.isJsonPrimitive()) {
|
||||
blacklist.add(el.getAsString());
|
||||
totalCount++;
|
||||
newKeywords.add(el.getAsString());
|
||||
}
|
||||
}
|
||||
if (blacklistFileKeywords.containsKey(fileName)) {
|
||||
blacklist.removeAll(blacklistFileKeywords.get(fileName));
|
||||
plugin.getLogger().info("[AI聊天] 黑名单文件已更新: " + fileName + "(" + newKeywords.size() + " 个关键词)");
|
||||
} else {
|
||||
plugin.getLogger().info("[AI聊天] 已加载黑名单文件: " + fileName + "(" + newKeywords.size() + " 个关键词)");
|
||||
}
|
||||
blacklist.addAll(newKeywords);
|
||||
blacklistFileKeywords.put(fileName, newKeywords);
|
||||
blacklistFileHashes.put(fileName, newHash);
|
||||
totalCount += newKeywords.size();
|
||||
}
|
||||
if (totalCount > 0) {
|
||||
plugin.getLogger().info("[AI聊天] 已从路径加载黑名单: " + rawPath + "(" + totalCount + " 个关键词)");
|
||||
}
|
||||
plugin.getLogger().info("[AI聊天] 已从路径加载黑名单: " + rawPath + "(" + totalCount + " 个关键词)");
|
||||
} catch (Exception e) {
|
||||
plugin.getLogger().warning("[AI聊天] 加载黑名单路径失败: " + rawPath + " - " + e.getMessage());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user