diff --git a/src/main/java/net/hypr/doki/commands/levelling/Leaderboard.java b/src/main/java/net/hypr/doki/commands/levelling/Leaderboard.java index 3f8d523..36f17ed 100644 --- a/src/main/java/net/hypr/doki/commands/levelling/Leaderboard.java +++ b/src/main/java/net/hypr/doki/commands/levelling/Leaderboard.java @@ -7,6 +7,8 @@ import com.freya02.botcommands.api.prefixed.annotations.Category; import com.freya02.botcommands.api.prefixed.annotations.Description; import com.freya02.botcommands.api.prefixed.annotations.JDATextCommand; import net.dv8tion.jda.api.EmbedBuilder; +import net.dv8tion.jda.api.JDA; +import net.dv8tion.jda.api.entities.User; import net.hypr.doki.utils.DBUtils; import net.hypr.doki.utils.UserRecord; @@ -29,13 +31,15 @@ public class Leaderboard extends TextCommand { private EmbedBuilder buildLeaderboardEmbed(List userRecords , CommandEvent event) { StringBuilder leaderboard = new StringBuilder(); + JDA jda = event.getJDA(); int idx = 1; for (UserRecord record : userRecords) { + User user = jda.retrieveUserById(record.user_id).complete(); leaderboard .append("**") .append(idx) .append(".** ") - .append(record.username) + .append(user.getName()) .append(" - ") .append(record.level) .append(" (") diff --git a/src/main/java/net/hypr/doki/utils/DBUtils.java b/src/main/java/net/hypr/doki/utils/DBUtils.java index 48f04fc..352ee52 100644 --- a/src/main/java/net/hypr/doki/utils/DBUtils.java +++ b/src/main/java/net/hypr/doki/utils/DBUtils.java @@ -50,24 +50,22 @@ public class DBUtils { * Creates a new user record * @param user_id The users ID * @param server_id The server ID - * @param username The users username * @throws SQLException A SQL exception */ - public static UserRecord createUserRecord(long user_id, long server_id, String username) throws SQLException { + public static UserRecord createUserRecord(long user_id, long server_id) throws SQLException { Logger log = Logging.getLogger(); - log.info("Creating record (usr:{},srv:{},unm:{})", user_id, server_id, username); + log.info("Creating record (usr:{},srv:{})", user_id, server_id); BasicDataSource dataSource = Doki.getDataSource(); Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement( - "INSERT INTO users (user_id, server_id, username, last_message) VALUES (?, ?, ?, ?)" + "INSERT INTO users (user_id, server_id, last_message) VALUES (?, ?, ?)" ); stmt.setLong(1, user_id); stmt.setLong(2, server_id); - stmt.setString(3, username); - stmt.setTimestamp(4, Timestamp.valueOf(LocalDateTime.now())); + stmt.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now())); stmt.execute(); - log.info("Record (usr:{},srv:{},unm:{}) created!", user_id, server_id, username); - return new UserRecord(user_id, server_id, username); + log.info("Record (usr:{},srv:{}) created!", user_id, server_id); + return new UserRecord(user_id, server_id); } /** @@ -109,7 +107,7 @@ public class DBUtils { BasicDataSource dataSource = Doki.getDataSource(); Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement( - "SELECT user_id, server_id, username, last_message, xp, total_xp, level FROM users WHERE user_id = ? AND server_id = ?" + "SELECT user_id, server_id, last_message, xp, total_xp, level FROM users WHERE user_id = ? AND server_id = ?" ); stmt.setLong(1, user_id); stmt.setLong(2, server_id); @@ -118,7 +116,6 @@ public class DBUtils { return new UserRecord( rs.getLong("user_id"), rs.getLong("server_id"), - rs.getString("username"), rs.getTimestamp("last_message"), rs.getInt("xp"), rs.getInt("total_xp"), @@ -136,7 +133,7 @@ public class DBUtils { BasicDataSource dataSource = Doki.getDataSource(); Connection conn = dataSource.getConnection(); PreparedStatement stmt = conn.prepareStatement( - "SELECT user_id, username, last_message, xp, total_xp, level FROM users WHERE server_id = ?" + "SELECT user_id, last_message, xp, total_xp, level FROM users WHERE server_id = ?" ); stmt.setLong(1, server_id); ResultSet rs = stmt.executeQuery(); @@ -145,7 +142,6 @@ public class DBUtils { userRecordList.add(new UserRecord( rs.getLong("user_id"), server_id, - rs.getString("username"), rs.getTimestamp("last_message"), rs.getInt("xp"), rs.getInt("total_xp"), diff --git a/src/main/java/net/hypr/doki/utils/LevellingUtils.java b/src/main/java/net/hypr/doki/utils/LevellingUtils.java index 03ca881..0173367 100644 --- a/src/main/java/net/hypr/doki/utils/LevellingUtils.java +++ b/src/main/java/net/hypr/doki/utils/LevellingUtils.java @@ -27,9 +27,9 @@ public class LevellingUtils { totalXp, levelNew ); - logger.info("Incremented {}'s XP in {} ({} -> {})", userRecord.username, userRecord.server_id, userRecord.xp, xpNew); + logger.info("Incremented {}'s XP in {} ({} -> {})", userRecord.user_id, userRecord.server_id, userRecord.xp, xpNew); if (levelNew > userRecord.level) { - logger.info("Incremented {}'s level in {} ({} -> {})", userRecord.username, userRecord.server_id, userRecord.level, levelNew); + logger.info("Incremented {}'s level in {} ({} -> {})", userRecord.user_id, userRecord.server_id, userRecord.level, levelNew); } } } diff --git a/src/main/java/net/hypr/doki/utils/UserRecord.java b/src/main/java/net/hypr/doki/utils/UserRecord.java index f4dd704..281c5a0 100644 --- a/src/main/java/net/hypr/doki/utils/UserRecord.java +++ b/src/main/java/net/hypr/doki/utils/UserRecord.java @@ -6,7 +6,6 @@ import java.sql.Timestamp; public class UserRecord { public final long user_id; public final long server_id; - public final String username; public final Timestamp lastMessage; public final int xp; public int totalXp; @@ -16,12 +15,10 @@ public class UserRecord { * Instantiates a new UserRecord * @param user_id The User ID * @param server_id The Server/Guild ID - * @param username The Username */ - public UserRecord (long user_id, long server_id, String username) { + public UserRecord (long user_id, long server_id) { this.user_id = user_id; this.server_id = server_id; - this.username = username; this.lastMessage = new Timestamp(0); this.xp = 0; this.level = 1; @@ -31,16 +28,14 @@ public class UserRecord { * Instantiates a new UserRecord * @param user_id The User ID * @param server_id The Server/Guild ID - * @param username The Username * @param lastMessage The timestamp of the user's last message * @param xp The user's XP * @param totalXp The user's total XP * @param level The user's level */ - public UserRecord (long user_id, long server_id, String username, Timestamp lastMessage, int xp, int totalXp, int level) { + public UserRecord (long user_id, long server_id, Timestamp lastMessage, int xp, int totalXp, int level) { this.user_id = user_id; this.server_id = server_id; - this.username = username; this.lastMessage = lastMessage; this.xp = xp; this.totalXp = totalXp;