|
2 | 2 |
|
3 | 3 | import net.dv8tion.jda.api.events.interaction.command.CommandAutoCompleteInteractionEvent; |
4 | 4 | import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent; |
| 5 | +import net.dv8tion.jda.api.interactions.InteractionHook; |
5 | 6 | import net.dv8tion.jda.api.interactions.commands.OptionType; |
6 | 7 | import org.kohsuke.github.GHIssue; |
7 | 8 | import org.slf4j.Logger; |
@@ -44,6 +45,7 @@ public final class GitHubCommand extends SlashCommandAdapter { |
44 | 45 |
|
45 | 46 | private static final String TITLE_OPTION = "title"; |
46 | 47 | private static final Logger logger = LoggerFactory.getLogger(GitHubCommand.class); |
| 48 | + private static final int MAX_SUGGESTED_CHOICES = 25; |
47 | 49 |
|
48 | 50 | private final GitHubReference reference; |
49 | 51 |
|
@@ -98,28 +100,35 @@ public void onSlashCommand(SlashCommandInteractionEvent event) { |
98 | 100 | String[] issueData = titleOption.split(" ", 2); |
99 | 101 | String targetIssueTitle = issueData[1]; |
100 | 102 |
|
| 103 | + event.deferReply().queue(); |
| 104 | + InteractionHook hook = event.getHook(); |
| 105 | + |
101 | 106 | reference.findIssue(issueId, targetIssueTitle) |
102 | | - .ifPresentOrElse(issue -> event.replyEmbeds(reference.generateReply(issue)).queue(), |
103 | | - () -> event.reply("Could not find the issue you are looking for.") |
104 | | - .setEphemeral(true) |
| 107 | + .ifPresentOrElse( |
| 108 | + issue -> hook.editOriginalEmbeds(reference.generateReply(issue)).queue(), |
| 109 | + () -> hook.editOriginal("Could not find the issue you are looking for.") |
105 | 110 | .queue()); |
106 | 111 | } |
107 | 112 |
|
108 | 113 | @Override |
109 | 114 | public void onAutoComplete(CommandAutoCompleteInteractionEvent event) { |
110 | 115 | String title = event.getOption(TITLE_OPTION).getAsString(); |
111 | 116 |
|
| 117 | + List<String> choices; |
112 | 118 | if (title.isEmpty()) { |
113 | | - event.replyChoiceStrings(autocompleteGHIssueCache.stream().limit(25).toList()).queue(); |
| 119 | + choices = autocompleteGHIssueCache.stream().limit(MAX_SUGGESTED_CHOICES).toList(); |
114 | 120 | } else { |
115 | 121 | Queue<String> closestSuggestions = |
116 | 122 | new PriorityQueue<>(Comparator.comparingInt(suggestionScorer(title))); |
117 | | - |
118 | 123 | closestSuggestions.addAll(autocompleteGHIssueCache); |
| 124 | + choices = |
| 125 | + Stream.generate(closestSuggestions::poll).limit(MAX_SUGGESTED_CHOICES).toList(); |
| 126 | + } |
119 | 127 |
|
120 | | - List<String> choices = Stream.generate(closestSuggestions::poll).limit(25).toList(); |
121 | | - event.replyChoiceStrings(choices).queue(); |
| 128 | + if (choices.isEmpty()) { |
| 129 | + choices = List.of("No issues found"); |
122 | 130 | } |
| 131 | + event.replyChoiceStrings(choices).queue(); |
123 | 132 |
|
124 | 133 | if (isCacheExpired()) { |
125 | 134 | updateCache(); |
|
0 commit comments