Adding frontend-exception handler utility

This commit is contained in:
Salmonllama 2020-09-12 12:27:24 -04:00
parent 8661475472
commit e44687377b

View File

@ -0,0 +1,33 @@
/*
* Copyright (c) 2020. Aleksei Gryczewski
* All rights reserved.
*/
package dev.salmonllama.fsbot.utilities;
import dev.salmonllama.fsbot.config.BotConfig;
import dev.salmonllama.fsbot.guthix.CommandContext;
import org.javacord.api.entity.message.embed.EmbedBuilder;
import java.awt.*;
public class DiscordUtilities {
public static void handleException(Exception e, CommandContext ctx) {
EmbedBuilder embed = new EmbedBuilder()
.setTitle("Exception caught in command thread:")
.addField("message:", e.getMessage())
.setColor(Color.RED);
logException(e, ctx);
ctx.reply(embed);
}
private static void logException(Exception e, CommandContext ctx) {
EmbedBuilder embed = new EmbedBuilder()
.setTitle("Runtime error:")
.addField("Message:", e.getMessage())
.setColor(Color.RED);
ctx.getApi().getTextChannelById(BotConfig.ACTIVITY_LOG).ifPresent(channel -> channel.sendMessage(embed));
}
}