Skip to content

Commit e4a7c0b

Browse files
committed
Use filterChoices in forms commands where possible
1 parent 78624bb commit e4a7c0b

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/commands/AddFieldFormSubcommand.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.dv8tion.jda.api.interactions.commands.OptionType;
1717
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
1818
import xyz.dynxsty.dih4jda.interactions.AutoCompletable;
19+
import xyz.dynxsty.dih4jda.util.AutoCompleteUtils;
1920

2021
/**
2122
* The `/form add-field` command. This command allows for modification of
@@ -75,8 +76,10 @@ public void execute(SlashCommandInteractionEvent event) {
7576
@Override
7677
public void handleAutoComplete(CommandAutoCompleteInteractionEvent event, AutoCompleteQuery target) {
7778
if (!handleFormIDAutocomplete(event, target) && "style".equals(target.getName())) {
78-
event.replyChoices(Arrays.stream(TextInputStyle.values()).filter(t -> t != TextInputStyle.UNKNOWN)
79-
.map(style -> new Choice(style.name(), style.name())).toList()).queue();
79+
event.replyChoices(AutoCompleteUtils.filterChoices(event,
80+
Arrays.stream(TextInputStyle.values()).filter(t -> t != TextInputStyle.UNKNOWN)
81+
.map(style -> new Choice(style.name(), style.name())).toList()))
82+
.queue();
8083
}
8184
}
8285

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/commands/AttachFormSubcommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import net.dv8tion.jda.api.interactions.commands.build.OptionData;
2828
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
2929
import xyz.dynxsty.dih4jda.interactions.AutoCompletable;
30+
import xyz.dynxsty.dih4jda.util.AutoCompleteUtils;
3031
import xyz.dynxsty.dih4jda.util.ComponentIdBuilder;
3132

3233
/**
@@ -122,9 +123,9 @@ public void execute(SlashCommandInteractionEvent event) {
122123
@Override
123124
public void handleAutoComplete(CommandAutoCompleteInteractionEvent event, AutoCompleteQuery target) {
124125
if (!handleFormIDAutocomplete(event, target) && "button-style".equals(target.getName())) {
125-
event.replyChoices(
126+
event.replyChoices(AutoCompleteUtils.filterChoices(event,
126127
Set.of(ButtonStyle.DANGER, ButtonStyle.PRIMARY, ButtonStyle.SECONDARY, ButtonStyle.SUCCESS).stream()
127-
.map(style -> new Choice(style.name(), style.name())).toList())
128+
.map(style -> new Choice(style.name(), style.name())).toList()))
128129
.queue();
129130
}
130131
}

src/main/java/net/discordjug/javabot/systems/staff_commands/forms/commands/RemoveFieldFormSubcommand.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import net.dv8tion.jda.api.interactions.commands.OptionType;
1717
import net.dv8tion.jda.api.interactions.commands.build.SubcommandData;
1818
import xyz.dynxsty.dih4jda.interactions.AutoCompletable;
19+
import xyz.dynxsty.dih4jda.util.AutoCompleteUtils;
1920

2021
/**
2122
* The `/form remove-field` command. This command removes a field from the form.
@@ -80,7 +81,7 @@ public void handleAutoComplete(CommandAutoCompleteInteractionEvent event, AutoCo
8081
for (int i = 0; i < fields.size(); i++) {
8182
choices.add(new Choice(fields.get(i).label(), i));
8283
}
83-
event.replyChoices(choices).queue();
84+
event.replyChoices(AutoCompleteUtils.filterChoices(event, choices)).queue();
8485
return;
8586
}
8687
}

0 commit comments

Comments
 (0)