第58批:修复自动互动配置重读刷屏
Check Source / check (push) Successful in 3s
Auto Release / build (push) Successful in 2m39s
Simple Test / test (push) Successful in 2s
Test Env / test (push) Successful in 2s

- loadConfig() 加 quiet 参数,重读时不打印配置加载日志
- checkAutoChat 中 loadConfig 移到时间检查之后,只有真正发请求时才重读
- 避免每秒刷屏
This commit is contained in:
youpaishidifu
2026-10-28 17:37:22 +08:00
parent d2835dd272
commit 13ee2eb515
+13 -3
View File
@@ -103,6 +103,14 @@ public class AIChatManager {
// ==================== 配置加载 ==================== // ==================== 配置加载 ====================
private void loadConfig() { private void loadConfig() {
loadConfig(false);
}
/**
* 加载配置
* @param quiet true=静默模式(重读时不打印"配置加载完成"),false=初始加载(打印)
*/
private void loadConfig(boolean quiet) {
try { try {
// 确保 openai 目录存在 // 确保 openai 目录存在
File openaiDir = new File(plugin.getDataFolder(), "openai"); File openaiDir = new File(plugin.getDataFolder(), "openai");
@@ -229,8 +237,10 @@ public class AIChatManager {
issueRecord = JsonParser.parseString(Files.readString(issueFile.toPath(), StandardCharsets.UTF_8)).getAsJsonObject(); issueRecord = JsonParser.parseString(Files.readString(issueFile.toPath(), StandardCharsets.UTF_8)).getAsJsonObject();
} }
if (!quiet) {
plugin.getLogger().info("[AI聊天] 配置加载完成: " + modelEndpoints.size() + "个模型, " plugin.getLogger().info("[AI聊天] 配置加载完成: " + modelEndpoints.size() + "个模型, "
+ aliasToFullModel.size() + "个别名, 黑名单" + blacklist.size() + "条"); + aliasToFullModel.size() + "个别名, 黑名单" + blacklist.size() + "条");
}
} catch (Exception e) { } catch (Exception e) {
plugin.getLogger().warning("[AI聊天] 配置加载失败: " + e.getMessage()); plugin.getLogger().warning("[AI聊天] 配置加载失败: " + e.getMessage());
@@ -770,9 +780,6 @@ public class AIChatManager {
if (!autoChatRunning.compareAndSet(false, true)) return; if (!autoChatRunning.compareAndSet(false, true)) return;
try { try {
// ★ 每次发请求前重读配置,获取最新的模型、人设、黑名单等信息
loadConfig();
// 检查是否到了自动互动时间 // 检查是否到了自动互动时间
long intervalMs = (minIntervalMin + (int)(Math.random() * (maxIntervalMin - minIntervalMin + 1))) * 60000L; long intervalMs = (minIntervalMin + (int)(Math.random() * (maxIntervalMin - minIntervalMin + 1))) * 60000L;
@@ -780,6 +787,9 @@ public class AIChatManager {
if (recentChatBuffer.isEmpty()) return; if (recentChatBuffer.isEmpty()) return;
if (defaultModelFull.isEmpty()) return; if (defaultModelFull.isEmpty()) return;
// ★ 每次发请求前重读配置(静默模式,不打印日志避免刷屏)
loadConfig(true);
// ★ 互动指标:在线玩家数量达标才触发自动互动 // ★ 互动指标:在线玩家数量达标才触发自动互动
// ★ 日志静默:调度器每1秒跑一次,跳过时不再每秒刷屏。 // ★ 日志静默:调度器每1秒跑一次,跳过时不再每秒刷屏。
// 仅在状态变化(在线玩家从达标→不达标)时记一条,避免日志被刷屏。 // 仅在状态变化(在线玩家从达标→不达标)时记一条,避免日志被刷屏。