mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-28 17:37:52 +01:00
Add responding with choices to DiscordCommandAutoCompleteInteractionEvent
This commit is contained in:
parent
1ce73a2842
commit
2f3c9946b5
@ -29,8 +29,13 @@ import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
|
|||||||
import com.discordsrv.api.discord.events.interaction.AbstractInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.AbstractInteractionEvent;
|
||||||
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent;
|
||||||
|
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class DiscordCommandAutoCompleteInteractionEvent extends AbstractInteractionEvent<CommandAutoCompleteInteractionEvent> {
|
public class DiscordCommandAutoCompleteInteractionEvent extends AbstractInteractionEvent<CommandAutoCompleteInteractionEvent> {
|
||||||
|
|
||||||
|
private final Map<String, Object> choices = new LinkedHashMap<>();
|
||||||
|
|
||||||
public DiscordCommandAutoCompleteInteractionEvent(
|
public DiscordCommandAutoCompleteInteractionEvent(
|
||||||
CommandAutoCompleteInteractionEvent jdaEvent,
|
CommandAutoCompleteInteractionEvent jdaEvent,
|
||||||
DiscordUser user,
|
DiscordUser user,
|
||||||
@ -39,4 +44,20 @@ public class DiscordCommandAutoCompleteInteractionEvent extends AbstractInteract
|
|||||||
) {
|
) {
|
||||||
super(jdaEvent, user, member, channel);
|
super(jdaEvent, user, member, channel);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addChoice(String key, String value) {
|
||||||
|
this.choices.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChoice(String key, double value) {
|
||||||
|
this.choices.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChoice(String key, long value) {
|
||||||
|
this.choices.put(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, Object> getChoices() {
|
||||||
|
return choices;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,10 @@ import com.discordsrv.api.discord.entity.channel.DiscordMessageChannel;
|
|||||||
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
|
import com.discordsrv.api.discord.entity.guild.DiscordGuildMember;
|
||||||
import com.discordsrv.api.discord.entity.interaction.DiscordInteractionHook;
|
import com.discordsrv.api.discord.entity.interaction.DiscordInteractionHook;
|
||||||
import com.discordsrv.api.discord.events.interaction.DiscordModalInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.DiscordModalInteractionEvent;
|
||||||
|
import com.discordsrv.api.discord.events.interaction.command.DiscordChatInputInteractionEvent;
|
||||||
import com.discordsrv.api.discord.events.interaction.command.DiscordCommandAutoCompleteInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.command.DiscordCommandAutoCompleteInteractionEvent;
|
||||||
import com.discordsrv.api.discord.events.interaction.command.DiscordMessageContextInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.command.DiscordMessageContextInteractionEvent;
|
||||||
import com.discordsrv.api.discord.events.interaction.command.DiscordUserContextInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.command.DiscordUserContextInteractionEvent;
|
||||||
import com.discordsrv.api.discord.events.interaction.command.DiscordChatInputInteractionEvent;
|
|
||||||
import com.discordsrv.api.discord.events.interaction.component.DiscordButtonInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.component.DiscordButtonInteractionEvent;
|
||||||
import com.discordsrv.api.discord.events.interaction.component.DiscordSelectMenuInteractionEvent;
|
import com.discordsrv.api.discord.events.interaction.component.DiscordSelectMenuInteractionEvent;
|
||||||
import com.discordsrv.api.discord.events.member.role.DiscordMemberRoleAddEvent;
|
import com.discordsrv.api.discord.events.member.role.DiscordMemberRoleAddEvent;
|
||||||
@ -55,7 +55,11 @@ import net.dv8tion.jda.api.events.message.MessageDeleteEvent;
|
|||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
|
import net.dv8tion.jda.api.events.message.MessageUpdateEvent;
|
||||||
import net.dv8tion.jda.api.interactions.callbacks.IDeferrableCallback;
|
import net.dv8tion.jda.api.interactions.callbacks.IDeferrableCallback;
|
||||||
|
import net.dv8tion.jda.api.interactions.commands.Command;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class DiscordAPIEventModule extends AbstractModule<DiscordSRV> {
|
public class DiscordAPIEventModule extends AbstractModule<DiscordSRV> {
|
||||||
@ -126,8 +130,22 @@ public class DiscordAPIEventModule extends AbstractModule<DiscordSRV> {
|
|||||||
DiscordGuildMember guildMember = member != null ? api().getGuildMember(member) : null;
|
DiscordGuildMember guildMember = member != null ? api().getGuildMember(member) : null;
|
||||||
DiscordMessageChannel channel = api().getMessageChannel(event.getMessageChannel());
|
DiscordMessageChannel channel = api().getMessageChannel(event.getMessageChannel());
|
||||||
if (event instanceof CommandAutoCompleteInteractionEvent) {
|
if (event instanceof CommandAutoCompleteInteractionEvent) {
|
||||||
discordSRV.eventBus().publish(new DiscordCommandAutoCompleteInteractionEvent(
|
DiscordCommandAutoCompleteInteractionEvent autoComplete = new DiscordCommandAutoCompleteInteractionEvent(
|
||||||
(CommandAutoCompleteInteractionEvent) event, user, guildMember, channel));
|
(CommandAutoCompleteInteractionEvent) event, user, guildMember, channel);
|
||||||
|
discordSRV.eventBus().publish(autoComplete);
|
||||||
|
List<Command.Choice> choices = new ArrayList<>();
|
||||||
|
for (Map.Entry<String, Object> entry : autoComplete.getChoices().entrySet()) {
|
||||||
|
String key = entry.getKey();
|
||||||
|
Object value = entry.getValue();
|
||||||
|
if (value instanceof String) {
|
||||||
|
choices.add(new Command.Choice(key, (String) value));
|
||||||
|
} else if (value instanceof Double || value instanceof Float) {
|
||||||
|
choices.add(new Command.Choice(key, ((Number) value).doubleValue()));
|
||||||
|
} else {
|
||||||
|
choices.add(new Command.Choice(key, ((Number) value).longValue()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
((CommandAutoCompleteInteractionEvent) event).replyChoices(choices).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user