Use @Slf4j in QueriesUserByRole, improve query filtering by active accounts, and refine error handling in CommandSyncNitro.

This commit is contained in:
akastijn 2025-11-08 21:18:08 +01:00
parent b0d3498d1c
commit a396b13261
2 changed files with 14 additions and 5 deletions

View File

@ -56,16 +56,21 @@ public class CommandSyncNitro extends DiscordCommand {
ReplyCallbackAction replyCallbackAction = event.deferReply(true);
QueriesUserByRole.getUserIdsByRole("nitro").thenAcceptAsync(optionalUserIdList -> {
QueriesUserByRole.getUserIdsByRole("nitro").whenCompleteAsync((optionalUserIdList, error) -> {
if (error != null) {
log.error("Unable to retrieve user list.", error);
replyCallbackAction
.setEmbeds(Util.genericErrorEmbed("Error", "Unable to retrieve user list."))
.queue(RestAction.getDefaultSuccess(), Util::handleFailure);
return;
}
if (optionalUserIdList.isEmpty()) {
replyCallbackAction.setEmbeds(Util.genericErrorEmbed("Error", "No users found."))
.setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
return;
}
checkAllMembers(optionalUserIdList.get(), guildById, replyCallbackAction);
}, error -> replyCallbackAction
.setEmbeds(Util.genericErrorEmbed("Error", "Unable to retrieve user list."))
.queue(RestAction.getDefaultSuccess(), Util::handleFailure));
});
Role roleById = guildById.getRoleById(585557866275012633L);
guildById.getMembersWithRoles(roleById).forEach(member -> {

View File

@ -2,6 +2,7 @@ package com.alttd.database.queries;
import com.alttd.database.Database;
import com.alttd.util.Logger;
import lombok.extern.slf4j.Slf4j;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -11,6 +12,7 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
@Slf4j
public class QueriesUserByRole {
public static CompletableFuture<Optional<List<Long>>> getUserIdsByRole(String role) {
@ -18,7 +20,8 @@ public class QueriesUserByRole {
SELECT discord_id
FROM linked_accounts
JOIN account_roles ON linked_accounts.player_uuid = account_roles.uuid
WHERE account_roles.role_name = ?;
WHERE account_roles.role_name = ?
AND linked_accounts.active = true;
""";
return CompletableFuture.supplyAsync(() -> {
try {
@ -33,6 +36,7 @@ public class QueriesUserByRole {
}
return Optional.of(discordIds);
} catch (SQLException exception) {
log.error("Failed to get user ids by role", exception);
Logger.altitudeLogs.error(exception);
}
return Optional.empty();