Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat: adding exception special cases #102

Merged
merged 1 commit into from
Jul 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading