From 77db4fbb6863eba888a3569dd7bf569210a82004 Mon Sep 17 00:00:00 2001 From: yaansz Date: Sun, 21 Jul 2024 13:48:26 -0300 Subject: [PATCH] feat: adding exception special cases --- .../capivara/utils/CapivaraExceptionHandler.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/main/java/com/softawii/capivara/utils/CapivaraExceptionHandler.java b/src/main/java/com/softawii/capivara/utils/CapivaraExceptionHandler.java index b842995..422c592 100644 --- a/src/main/java/com/softawii/capivara/utils/CapivaraExceptionHandler.java +++ b/src/main/java/com/softawii/capivara/utils/CapivaraExceptionHandler.java @@ -1,6 +1,8 @@ package com.softawii.capivara.utils; import com.softawii.curupira.core.ExceptionHandler; +import com.softawii.curupira.exceptions.InvalidChannelTypeException; +import com.softawii.curupira.exceptions.MissingPermissionsException; import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.MessageEmbed; @@ -8,6 +10,7 @@ import net.dv8tion.jda.api.events.Event; import net.dv8tion.jda.api.events.channel.GenericChannelEvent; import net.dv8tion.jda.api.events.guild.GenericGuildEvent; +import net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent; import net.dv8tion.jda.api.interactions.Interaction; import net.dv8tion.jda.api.requests.restaction.MessageCreateAction; import net.dv8tion.jda.api.utils.FileUpload; @@ -39,6 +42,17 @@ public CapivaraExceptionHandler(String channelId, Path logDirectory) { @Override public void handle(Throwable throwable, Interaction interaction) { + if (interaction instanceof GenericCommandInteractionEvent event) { + if (throwable instanceof MissingPermissionsException) { + event.reply("You don't have permission to execute this command!").setEphemeral(true).queue(); + return; + } + else if(throwable instanceof InvalidChannelTypeException) { + event.reply("You can't execute this command in this channel!").setEphemeral(true).queue(); + return; + } + } + InputStream logFileBytes = null; if (logDirectory != null) { Path logFile = logDirectory.resolve("capivara.log");