Search in sources :

Example 1 with ICommand

use of ml.duncte123.skybot.objects.command.ICommand in project SkyBot by DuncteBot.

the class CommandManager method runCustomCommand.

private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
    final CustomCommand cusomCommand = (CustomCommand) cmd;
    if (cusomCommand.getGuildId() != event.getGuild().getIdLong()) {
        return;
    }
    try {
        MDC.put("command.custom.message", cusomCommand.getMessage());
        final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables));
        final String message = parser.parse(cusomCommand.getMessage());
        final MessageConfig.Builder messageBuilder = MessageConfig.Builder.fromEvent(event);
        final DataObject object = parser.get("embed");
        boolean hasContent = false;
        if (!message.isEmpty()) {
            messageBuilder.setMessage("\u200B" + message);
            hasContent = true;
        }
        if (object != null) {
            final JDAImpl jda = (JDAImpl) event.getJDA();
            final EmbedBuilder embed = new EmbedBuilder(jda.getEntityBuilder().createMessageEmbed(object));
            messageBuilder.addEmbed(true, embed);
            hasContent = true;
        }
        if (hasContent) {
            sendMsg(messageBuilder.build());
        }
        parser.clear();
    } catch (Exception e) {
        sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Error with parsing custom command: " + e.getMessage()).build());
        Sentry.captureException(e);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) CustomCommand(ml.duncte123.skybot.objects.command.custom.CustomCommand) MessageConfig(me.duncte123.botcommons.messaging.MessageConfig) DataObject(net.dv8tion.jda.api.utils.data.DataObject) CommandContext(ml.duncte123.skybot.objects.command.CommandContext) JDAImpl(net.dv8tion.jda.internal.JDAImpl) Parser(com.jagrosh.jagtag.Parser)

Example 2 with ICommand

use of ml.duncte123.skybot.objects.command.ICommand in project SkyBot by DuncteBot.

the class CommandManager method dispatchCommand.

private void dispatchCommand(String invoke, String invokeLower, List<String> args, GuildMessageReceivedEvent event) {
    ICommand cmd = getCommand(invokeLower);
    if (cmd == null) {
        cmd = getCustomCommand(invokeLower, event.getGuild().getIdLong());
    }
    if (cmd == null) {
        return;
    }
    dispatchCommand(cmd, invoke, args, event);
}
Also used : ICommand(ml.duncte123.skybot.objects.command.ICommand)

Example 3 with ICommand

use of ml.duncte123.skybot.objects.command.ICommand in project SkyBot by DuncteBot.

the class CommandManager method runNormalCommand.

private void runNormalCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
    if (cmd.getCategory() == CommandCategory.NSFW && this.isSafeForWork(event)) {
        sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Woops, this channel is not marked as NSFW.\n" + "Please mark this channel as NSFW to use this command").build());
        return;
    }
    MDC.put("command.class", cmd.getClass().getName());
    LOGGER.info("Dispatching command \"{}\" in guild \"{}\" with {}", cmd.getClass().getSimpleName(), event.getGuild(), args);
    cmd.executeCommand(new CommandContext(invoke, args, event, variables));
}
Also used : CommandContext(ml.duncte123.skybot.objects.command.CommandContext)

Example 4 with ICommand

use of ml.duncte123.skybot.objects.command.ICommand in project SkyBot by duncte123.

the class CommandManager method dispatchCommand.

private void dispatchCommand(String invoke, String invokeLower, List<String> args, GuildMessageReceivedEvent event) {
    ICommand cmd = getCommand(invokeLower);
    if (cmd == null) {
        cmd = getCustomCommand(invokeLower, event.getGuild().getIdLong());
    }
    if (cmd == null) {
        return;
    }
    dispatchCommand(cmd, invoke, args, event);
}
Also used : ICommand(ml.duncte123.skybot.objects.command.ICommand)

Example 5 with ICommand

use of ml.duncte123.skybot.objects.command.ICommand in project SkyBot by duncte123.

the class CommandManager method runCustomCommand.

private void runCustomCommand(ICommand cmd, String invoke, List<String> args, GuildMessageReceivedEvent event) {
    final CustomCommand cusomCommand = (CustomCommand) cmd;
    if (cusomCommand.getGuildId() != event.getGuild().getIdLong()) {
        return;
    }
    try {
        MDC.put("command.custom.message", cusomCommand.getMessage());
        final Parser parser = CommandUtils.getParser(new CommandContext(invoke, args, event, variables));
        final String message = parser.parse(cusomCommand.getMessage());
        final MessageConfig.Builder messageBuilder = MessageConfig.Builder.fromEvent(event);
        final DataObject object = parser.get("embed");
        boolean hasContent = false;
        if (!message.isEmpty()) {
            messageBuilder.setMessage("\u200B" + message);
            hasContent = true;
        }
        if (object != null) {
            final JDAImpl jda = (JDAImpl) event.getJDA();
            final EmbedBuilder embed = new EmbedBuilder(jda.getEntityBuilder().createMessageEmbed(object));
            messageBuilder.addEmbed(true, embed);
            hasContent = true;
        }
        if (hasContent) {
            sendMsg(messageBuilder.build());
        }
        parser.clear();
    } catch (Exception e) {
        sendMsg(MessageConfig.Builder.fromEvent(event).setMessage("Error with parsing custom command: " + e.getMessage()).build());
        Sentry.captureException(e);
    }
}
Also used : EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) CustomCommand(ml.duncte123.skybot.objects.command.custom.CustomCommand) MessageConfig(me.duncte123.botcommons.messaging.MessageConfig) DataObject(net.dv8tion.jda.api.utils.data.DataObject) CommandContext(ml.duncte123.skybot.objects.command.CommandContext) JDAImpl(net.dv8tion.jda.internal.JDAImpl) Parser(com.jagrosh.jagtag.Parser)

Aggregations

CommandContext (ml.duncte123.skybot.objects.command.CommandContext)4 Parser (com.jagrosh.jagtag.Parser)2 MessageConfig (me.duncte123.botcommons.messaging.MessageConfig)2 ICommand (ml.duncte123.skybot.objects.command.ICommand)2 CustomCommand (ml.duncte123.skybot.objects.command.custom.CustomCommand)2 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)2 DataObject (net.dv8tion.jda.api.utils.data.DataObject)2 JDAImpl (net.dv8tion.jda.internal.JDAImpl)2