Search in sources :

Example 21 with CommandContext

use of net.robinfriedli.aiode.command.CommandContext in project aiode by robinfriedli.

the class ExceptionUtils method handleCommandException.

public static void handleCommandException(Throwable e, Command command, Logger logger) {
    if (e instanceof CommandFailure) {
        return;
    }
    CommandContext commandContext = command.getContext();
    if (Aiode.isShuttingDown()) {
        logger.warn(String.format("Suppressed error from command %s because it happened during shutdown: %s", commandContext.getId(), e));
        return;
    }
    MessageChannel channel = commandContext.getChannel();
    String commandDisplay = command.display();
    MessageService messageService = Aiode.get().getMessageService();
    if (e instanceof UserException) {
        EmbedBuilder embedBuilder = ((UserException) e).buildEmbed();
        messageService.sendTemporary(embedBuilder.build(), channel);
    } else {
        EmbedBuilder embedBuilder = ExceptionUtils.buildErrorEmbed(e);
        embedBuilder.addField("CommandContext ID", commandContext.getId(), false);
        messageService.send(embedBuilder.build(), channel);
        logger.error(String.format("Exception while handling command %s on guild %s", commandDisplay, commandContext.getGuild().getName()), e);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) CommandContext(net.robinfriedli.aiode.command.CommandContext) MessageChannel(net.dv8tion.jda.api.entities.MessageChannel) MessageService(net.robinfriedli.aiode.discord.MessageService)

Aggregations

CommandContext (net.robinfriedli.aiode.command.CommandContext)21 Session (org.hibernate.Session)9 InvalidCommandException (net.robinfriedli.aiode.exceptions.InvalidCommandException)8 Guild (net.dv8tion.jda.api.entities.Guild)7 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)6 Aiode (net.robinfriedli.aiode.Aiode)6 SecurityManager (net.robinfriedli.aiode.command.SecurityManager)6 AbstractCommand (net.robinfriedli.aiode.command.AbstractCommand)5 PermissionTarget (net.robinfriedli.aiode.command.PermissionTarget)5 CustomPermissionTarget (net.robinfriedli.aiode.entities.CustomPermissionTarget)5 StoredScript (net.robinfriedli.aiode.entities.StoredScript)3 List (java.util.List)2 MessageChannel (net.dv8tion.jda.api.entities.MessageChannel)2 Role (net.dv8tion.jda.api.entities.Role)2 User (net.dv8tion.jda.api.entities.User)2 InsufficientPermissionException (net.dv8tion.jda.api.exceptions.InsufficientPermissionException)2 AudioManager (net.robinfriedli.aiode.audio.AudioManager)2 ThreadExecutionQueue (net.robinfriedli.aiode.concurrent.ThreadExecutionQueue)2 AccessConfiguration (net.robinfriedli.aiode.entities.AccessConfiguration)2 GrantedRole (net.robinfriedli.aiode.entities.GrantedRole)2