Add DiscordService#getMemberById

This commit is contained in:
Josh Roy 2022-12-25 16:13:56 -05:00 committed by MD
parent a7f4d6b16b
commit 376abc4aab
2 changed files with 24 additions and 0 deletions

View File

@ -4,6 +4,8 @@ import net.essentialsx.api.v2.events.discord.DiscordChatMessageEvent;
import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import java.util.concurrent.CompletableFuture;
/**
* A class which provides numerous methods to interact with EssentialsX Discord.
*/
@ -47,6 +49,13 @@ public interface DiscordService {
*/
InteractionController getInteractionController();
/**
* Gets an {@link InteractionMember} by their Discord ID.
* @param id The ID of the member to look up.
* @return A future which will complete with the member or null if none is reachable.
*/
CompletableFuture<InteractionMember> getMemberById(final String id);
/**
* Gets unstable API that is subject to change at any time.
* @return {@link Unsafe the unsafe} instance.

View File

@ -26,9 +26,11 @@ import net.essentialsx.api.v2.events.discord.DiscordMessageEvent;
import net.essentialsx.api.v2.services.discord.DiscordService;
import net.essentialsx.api.v2.services.discord.InteractionController;
import net.essentialsx.api.v2.services.discord.InteractionException;
import net.essentialsx.api.v2.services.discord.InteractionMember;
import net.essentialsx.api.v2.services.discord.MessageType;
import net.essentialsx.api.v2.services.discord.Unsafe;
import net.essentialsx.discord.interactions.InteractionControllerImpl;
import net.essentialsx.discord.interactions.InteractionMemberImpl;
import net.essentialsx.discord.interactions.commands.ExecuteCommand;
import net.essentialsx.discord.interactions.commands.ListCommand;
import net.essentialsx.discord.interactions.commands.MessageCommand;
@ -466,6 +468,19 @@ public class JDADiscordService implements DiscordService, IEssentialsModule {
}
}
@Override
public CompletableFuture<InteractionMember> getMemberById(final String id) {
final CompletableFuture<InteractionMember> future = new CompletableFuture<>();
getGuild().retrieveMemberById(id).queue(member -> {
if (member != null) {
future.complete(new InteractionMemberImpl(member));
return;
}
future.complete(null);
}, fail -> future.complete(null));
return future;
}
public JDA getJda() {
return jda;
}