Add support for miniMessage serialization in chat logs
This commit is contained in:
@@ -15,15 +15,22 @@ import java.util.concurrent.CompletionException;
|
||||
public class ChatLogQueries {
|
||||
|
||||
protected static void createChatLogTable() {
|
||||
String nicknamesTableQuery = "CREATE TABLE IF NOT EXISTS chat_log("
|
||||
+ "uuid CHAR(48) NOT NULL,"
|
||||
+ "time_stamp TIMESTAMP(6) NOT NULL, "
|
||||
+ "server VARCHAR(50) NOT NULL, "
|
||||
+ "chat_message VARCHAR(300) NOT NULL, "
|
||||
+ "blocked BIT(1) NOT NULL DEFAULT 0"
|
||||
+ ")";
|
||||
String nicknamesTableQuery = """
|
||||
CREATE TABLE chat_log (
|
||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||
uuid CHAR(36) NOT NULL,
|
||||
time_stamp TIMESTAMP(6) NOT NULL,
|
||||
server VARCHAR(50) NOT NULL,
|
||||
chat_message VARCHAR(300) NOT NULL,
|
||||
mini_message JSON,
|
||||
blocked BOOLEAN NOT NULL DEFAULT FALSE,
|
||||
|
||||
INDEX idx_time_stamp (time_stamp)
|
||||
)
|
||||
""";
|
||||
|
||||
try (PreparedStatement preparedStatement = DatabaseConnection.getConnection().prepareStatement(nicknamesTableQuery)) {
|
||||
try (PreparedStatement preparedStatement = DatabaseConnection.getConnection().prepareStatement(
|
||||
nicknamesTableQuery)) {
|
||||
preparedStatement.executeUpdate();
|
||||
} catch (Throwable throwable) {
|
||||
ALogger.error("Failed to create chat log table", throwable);
|
||||
@@ -31,7 +38,7 @@ public class ChatLogQueries {
|
||||
}
|
||||
|
||||
public static @NotNull CompletableFuture<Boolean> storeMessages(HashMap<UUID, List<ChatLog>> chatMessages) {
|
||||
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, chat_message, blocked) VALUES (?, ?, ?, ?, ?)";
|
||||
String insertQuery = "INSERT INTO chat_log (uuid, time_stamp, server, chat_message, mini_message, blocked) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
return CompletableFuture.supplyAsync(() -> {
|
||||
try (Connection connection = DatabaseConnection.createTransactionConnection()) {
|
||||
PreparedStatement preparedStatement = connection.prepareStatement(insertQuery);
|
||||
@@ -76,7 +83,9 @@ public class ChatLogQueries {
|
||||
return chatLogs;
|
||||
} catch (SQLException sqlException) {
|
||||
ALogger.error(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
||||
throw new CompletionException(String.format("Failed to retrieve messages for user %s", uuid), sqlException);
|
||||
throw new CompletionException(String.format("Failed to retrieve messages for user %s", uuid),
|
||||
sqlException
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -90,8 +99,13 @@ public class ChatLogQueries {
|
||||
preparedStatement.setTimestamp(1, Timestamp.from(Instant.now().minus(duration)));
|
||||
return preparedStatement.execute();
|
||||
} catch (SQLException sqlException) {
|
||||
ALogger.error(String.format("Failed to delete messages older than %s days", duration.toDays()), sqlException);
|
||||
throw new CompletionException(String.format("Failed to delete messages older than %s days", duration.toDays()), sqlException);
|
||||
ALogger.error(String.format("Failed to delete messages older than %s days", duration.toDays()),
|
||||
sqlException
|
||||
);
|
||||
throw new CompletionException(String.format("Failed to delete messages older than %s days",
|
||||
duration.toDays()
|
||||
), sqlException
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user