handle errors on interactions
All checks were successful
Deploy to Dokku / docker (ubuntu-latest) (push) Successful in 39s

This commit is contained in:
Lee 2024-07-04 03:07:08 +01:00
parent 2fcc1b66c1
commit 750b8cbfea
2 changed files with 25 additions and 5 deletions

@ -45,5 +45,4 @@ public class DragRequest {
* The request message sent in the voice channel
*/
private Message requestMessage;
}

@ -1,5 +1,6 @@
package cc.fascinated.bat.service;
import cc.fascinated.bat.common.EmbedUtils;
import cc.fascinated.bat.event.EventListener;
import cc.fascinated.bat.model.BatGuild;
import cc.fascinated.bat.model.BatUser;
@ -142,9 +143,19 @@ public class EventService extends ListenerAdapter {
BatGuild guild = event.getGuild() != null ? guildService.getGuild(event.getGuild().getId()) : null;
BatUser user = userService.getUser(event.getUser().getId());
try {
for (EventListener listener : LISTENERS) {
listener.onButtonInteraction(guild, user, event);
}
} catch (Exception e) {
log.error("An error occurred while handling a modal interaction.", e);
if (event.isAcknowledged()) {
return;
}
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("An error occurred while handling your interaction.\nError: ```java\n%s\n```".formatted(e.getMessage()))
.build()).queue();
}
}
@Override
@ -155,9 +166,19 @@ public class EventService extends ListenerAdapter {
BatGuild guild = event.getGuild() != null ? guildService.getGuild(event.getGuild().getId()) : null;
BatUser user = userService.getUser(event.getUser().getId());
try {
for (EventListener listener : LISTENERS) {
listener.onModalInteraction(guild, user, event);
}
} catch (Exception e) {
log.error("An error occurred while handling a modal interaction.", e);
if (event.isAcknowledged()) {
return;
}
event.replyEmbeds(EmbedUtils.errorEmbed()
.setDescription("An error occurred while handling your interaction.\nError: ```java\n%s\n```".formatted(e.getMessage()))
.build()).queue();
}
}
@Override