fix(ia): prevent private notes leak in places tool, guard recordTurn against disk failure, and add tests

This commit is contained in:
Marcos Paulo
2026-08-18 19:15:02 -03:00
parent ea55813019
commit 2220f11e64
3 changed files with 54 additions and 4 deletions
@@ -437,6 +437,7 @@ final class Ai {
return;
}
String clean = String.join(" ", segments);
lastAnswer = new Answered(askerId, question, clean);
// Only remember if the asker is still online: a PlayerQuitEvent forgets
// the player's history (carry-forward #6), and re-adding here after the
// quit would resurrect it. lastAnswer stays regardless, so /ia corrigir
@@ -444,10 +445,13 @@ final class Ai {
if (asker != null) {
conversations.remember(askerId, question, clean);
if (plugin.playerMemory() != null) {
plugin.playerMemory().recordTurn(askerId, asker.getName(), question, clean);
try {
plugin.playerMemory().recordTurn(askerId, asker.getName(), question, clean);
} catch (RuntimeException e) {
plugin.getLogger().warning("Falha ao gravar memória da IA para " + asker.getName() + ": " + e);
}
}
}
lastAnswer = new Answered(askerId, question, clean);
if (isPrivate || !settings.aiPublic()) {
if (asker != null) {
@@ -146,7 +146,20 @@ final class Tools {
}
String uuidStr = who.uuid();
List<DeathLog.Entry> deaths = plugin.deathLog().forPlayer(uuidStr);
List<Note> notes = plugin.notes().visibleTo(uuidStr, null, "");
List<Note> notes = plugin.notes().visibleTo(uuidStr, Note.Scope.PUBLICA, "");
return formatPlayerPlaces(who, deaths, notes);
}
String formatPlayerPlaces(OfflineStats.Known who, List<DeathLog.Entry> deaths, List<Note> visibleNotes) {
String uuidStr = who.uuid();
List<Note> notes = new java.util.ArrayList<>();
if (visibleNotes != null) {
for (Note n : visibleNotes) {
if (n.scope() == Note.Scope.PUBLICA && n.authorId() != null && n.authorId().equals(uuidStr)) {
notes.add(n);
}
}
}
StringBuilder sb = new StringBuilder();
sb.append("Lugares conhecidos de ").append(who.name()).append(":\n");
@@ -164,7 +177,7 @@ final class Tools {
sb.append("\n");
}
if (deaths.isEmpty()) {
if (deaths == null || deaths.isEmpty()) {
sb.append("- Mortes recentes: nenhum registro de morte recente.");
} else {
sb.append("- Mortes recentes: ");