Skip to content

Commit

Permalink
Validate Interaction and InteractionHook before deferReply
Browse files Browse the repository at this point in the history
  • Loading branch information
bivashy committed Mar 8, 2024
1 parent 17293bf commit 48a19d8
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import revxrsal.commands.jda.core.actor.BaseJDASlashCommandActor;

public class JDACommandListener implements EventListener {

private static final DiscordLinkType DISCORD_LINK_TYPE = DiscordLinkType.getInstance();
private final JDACommandHandler handler;
private final Function<JDAActor, LinkCommandActorWrapper> wrapper;
Expand All @@ -50,7 +51,7 @@ private void dispatch(JDAActor actor, ArgumentStack arguments) {
LinkCommandActorWrapper actorWrapper = wrapper.apply(actor);
try {
handler.dispatch(actorWrapper, arguments);
} catch(Throwable t) {
} catch (Throwable t) {
handler.getExceptionHandler().handleException(t, actorWrapper);
}
}
Expand Down Expand Up @@ -90,7 +91,7 @@ private void onAutocompleteEvent(CommandAutoCompleteInteractionEvent event) {
return new Choice(suggestion, Long.parseLong(suggestion));
return new Choice(suggestion, suggestion);
}).collect(Collectors.toList())).queue();
} catch(Throwable e) {
} catch (Throwable e) {
e.printStackTrace();
}
}
Expand All @@ -105,15 +106,16 @@ private void onButtonEvent(ButtonInteractionEvent event) {
try {
ArgumentStack arguments = ArgumentStack.parse(content);
dispatch(actor, arguments);
} catch(Throwable t) {
} catch (Throwable t) {
handler.getExceptionHandler().handleException(t, actor);
}
}

private void onSlashCommandEvent(SlashCommandInteractionEvent event) {
parseSlashCommandEvent(event).ifPresent(arguments -> {
JDAActor actor = new BaseJDASlashCommandActor(event, handler);
event.deferReply(true).queue();
if (!event.getInteraction().isAcknowledged() && !event.getHook().isExpired())
event.deferReply(true).queue();
dispatch(actor, arguments);
});
}
Expand Down Expand Up @@ -190,5 +192,6 @@ private void appendOptionMapping(Collection<String> arguments, OptionMapping opt
arguments.add(optionMapping.getAsString());
}
}

}

0 comments on commit 48a19d8

Please sign in to comment.