Skip to content

Commit

Permalink
Merge pull request #102 from Softawii/fix/exception-handler-fail
Browse files Browse the repository at this point in the history
feat: adding exception special cases
  • Loading branch information
yaansz authored Jul 21, 2024
2 parents 9c4bfe8 + 77db4fb commit eb6b0ea
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
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;
import net.dv8tion.jda.api.entities.channel.concrete.TextChannel;
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;
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit eb6b0ea

Please sign in to comment.