Skip to content

Commit

Permalink
feat: adding exception special cases
Browse files Browse the repository at this point in the history
  • Loading branch information
yaansz committed Jul 21, 2024
1 parent dc43b96 commit 77db4fb
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 77db4fb

Please sign in to comment.