Commit 635e9dec by Jonathan Thomas

Display actual error message on screen, instead of making players check the log.…

Display actual error message on screen, instead of making players check the log. Message only goes to the player who initiated the error.
parent 3ffd39d8
Pipeline #12109 passed with stage
in 22 seconds
......@@ -320,10 +320,15 @@ public class ChatDataManager {
String randomErrorMessage = Randomizer.getRandomMessage(Randomizer.RandomType.ERROR);
this.addMessage(randomErrorMessage, ChatSender.ASSISTANT, player.getUuidAsString());
// Determine error message to display
String errorMessage = "Help is available at discord.creaturechat.com";
if (!ChatGPTRequest.lastErrorMessage.isEmpty()) {
errorMessage = "Error: " + truncateString(ChatGPTRequest.lastErrorMessage, 55) + "\n" + errorMessage;
}
// Send clickable error message
ServerPackets.SendClickableError(player,
"Help is available at discord.creaturechat.com",
"http://discord.creaturechat.com");
errorMessage, "http://discord.creaturechat.com");
// Clear history (if no character sheet was generated)
if (characterSheet.isEmpty()) {
......@@ -336,6 +341,10 @@ public class ChatDataManager {
});
}
public static String truncateString(String input, int maxLength) {
return input.length() > maxLength ? input.substring(0, maxLength - 3) + "..." : input;
}
// Add a message to the history and update the current message
public void addMessage(String message, ChatSender messageSender, String playerId) {
// Truncate message (prevent crazy long messages... just in case)
......
......@@ -26,6 +26,7 @@ import java.util.regex.Pattern;
*/
public class ChatGPTRequest {
public static final Logger LOGGER = LoggerFactory.getLogger("creaturechat");
public static String lastErrorMessage;
static class ChatGPTRequestMessage {
String role;
......@@ -175,8 +176,11 @@ public class ChatGPTRequest {
errorResponse.append(errorLine.trim());
}
LOGGER.error("Error response from API: " + errorResponse);
lastErrorMessage = errorResponse.toString();
}
return null;
} else {
lastErrorMessage = null;
}
try (BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8))) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment