Use @Slf4j in QueriesUserByRole, improve query filtering by active accounts, and refine error handling in CommandSyncNitro.
This commit is contained in:
parent
b0d3498d1c
commit
a396b13261
|
|
@ -56,16 +56,21 @@ public class CommandSyncNitro extends DiscordCommand {
|
||||||
|
|
||||||
ReplyCallbackAction replyCallbackAction = event.deferReply(true);
|
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()) {
|
if (optionalUserIdList.isEmpty()) {
|
||||||
replyCallbackAction.setEmbeds(Util.genericErrorEmbed("Error", "No users found."))
|
replyCallbackAction.setEmbeds(Util.genericErrorEmbed("Error", "No users found."))
|
||||||
.setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
.setEphemeral(true).queue(RestAction.getDefaultSuccess(), Util::handleFailure);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
checkAllMembers(optionalUserIdList.get(), guildById, replyCallbackAction);
|
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);
|
Role roleById = guildById.getRoleById(585557866275012633L);
|
||||||
guildById.getMembersWithRoles(roleById).forEach(member -> {
|
guildById.getMembersWithRoles(roleById).forEach(member -> {
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package com.alttd.database.queries;
|
||||||
|
|
||||||
import com.alttd.database.Database;
|
import com.alttd.database.Database;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
|
|
@ -11,6 +12,7 @@ import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.concurrent.CompletableFuture;
|
import java.util.concurrent.CompletableFuture;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class QueriesUserByRole {
|
public class QueriesUserByRole {
|
||||||
|
|
||||||
public static CompletableFuture<Optional<List<Long>>> getUserIdsByRole(String role) {
|
public static CompletableFuture<Optional<List<Long>>> getUserIdsByRole(String role) {
|
||||||
|
|
@ -18,7 +20,8 @@ public class QueriesUserByRole {
|
||||||
SELECT discord_id
|
SELECT discord_id
|
||||||
FROM linked_accounts
|
FROM linked_accounts
|
||||||
JOIN account_roles ON linked_accounts.player_uuid = account_roles.uuid
|
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(() -> {
|
return CompletableFuture.supplyAsync(() -> {
|
||||||
try {
|
try {
|
||||||
|
|
@ -33,6 +36,7 @@ public class QueriesUserByRole {
|
||||||
}
|
}
|
||||||
return Optional.of(discordIds);
|
return Optional.of(discordIds);
|
||||||
} catch (SQLException exception) {
|
} catch (SQLException exception) {
|
||||||
|
log.error("Failed to get user ids by role", exception);
|
||||||
Logger.altitudeLogs.error(exception);
|
Logger.altitudeLogs.error(exception);
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user