Search in sources :

Example 6 with CommandContext

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

the class TokenCommand method execute.

@Override
public void execute(@Nonnull CommandContext ctx) {
    final List<String> args = ctx.getArgs();
    final Matcher matcher = TOKEN_REGEX.matcher(args.get(0));
    if (!matcher.matches()) {
        sendMsg(ctx, "Your input `" + args.get(0) + "` has the wrong token format.");
        return;
    }
    final DuncteApis apis = ctx.getVariables().getApis();
    final JsonNode json = apis.decodeToken(args.get(0));
    if (json.get("success").asBoolean()) {
        handleSuccess(args.get(0), json.get("data"), ctx);
        return;
    }
    final JsonNode error = json.get("error");
    final String errorType = error.get("type").asText();
    final String errorMessage = error.get("message").asText();
    sendMsg(ctx, String.format("Invalid token: (%s) %s", errorType, errorMessage));
}
Also used : DuncteApis(ml.duncte123.skybot.objects.api.DuncteApis) Matcher(java.util.regex.Matcher) JsonNode(com.fasterxml.jackson.databind.JsonNode)

Example 7 with CommandContext

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

the class AudioUtils method loadAndPlay.

public Future<Void> loadAndPlay(final CommandContext ctx, final String trackUrlRaw, final boolean announce) {
    final boolean isPatron = CommandUtils.isUserTagPatron(ctx.getAuthor());
    // final boolean isPatron = false;
    final String trackUrl;
    // Strip <>'s that prevent discord from embedding link resources
    if (trackUrlRaw.charAt(0) == '<' && trackUrlRaw.endsWith(">")) {
        trackUrl = trackUrlRaw.substring(1, trackUrlRaw.length() - 1);
    } else {
        trackUrl = trackUrlRaw;
    }
    final GuildMusicManager mng = getMusicManager(ctx.getJDAGuild());
    final AudioLoader loader = new AudioLoader(ctx, mng, announce, trackUrl, isPatron);
    final DBAudioRef reference = new DBAudioRef(trackUrl, null, isPatron);
    return getPlayerManager().loadItemOrdered(mng, reference, loader);
}
Also used : GuildMusicManager(ml.duncte123.skybot.audio.GuildMusicManager) DBAudioRef(ml.duncte123.skybot.audio.sourcemanagers.DBAudioRef) AudioLoader(ml.duncte123.skybot.audio.AudioLoader)

Example 8 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext 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 9 with CommandContext

use of ml.duncte123.skybot.objects.command.CommandContext 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 10 with CommandContext

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

the class UnwarnCommand method execute.

@Override
public void execute(@Nonnull CommandContext ctx) {
    final List<Member> mentioned = ctx.getMentionedArg(0);
    if (mentioned.isEmpty()) {
        sendMsg(ctx, "No users found for query");
        return;
    }
    final DunctebotGuild guild = ctx.getGuild();
    final User target = mentioned.get(0).getUser();
    ctx.getDatabaseAdapter().deleteLatestWarningForUser(target.getIdLong(), guild.getIdLong(), (latestWarning) -> {
        if (latestWarning == null) {
            sendMsg(ctx, "This user has no active warnings");
            return null;
        }
        sendMsg(ctx, String.format("Latest warning for _%s_ removed\nReason was: %s", target.getAsTag(), latestWarning.getReason()));
        modLog(String.format("**%s** removed the latest warning for **%s**\nReason was: %s", ctx.getAuthor().getAsTag(), target.getAsTag(), latestWarning.getReason()), guild);
        return null;
    });
}
Also used : DunctebotGuild(ml.duncte123.skybot.entities.jda.DunctebotGuild) User(net.dv8tion.jda.api.entities.User) Member(net.dv8tion.jda.api.entities.Member)

Aggregations

CommandContext (ml.duncte123.skybot.objects.command.CommandContext)9 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)7 ArrayList (java.util.ArrayList)6 User (net.dv8tion.jda.api.entities.User)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 List (java.util.List)4 CustomCommand (ml.duncte123.skybot.objects.command.custom.CustomCommand)4 LongLongPair (ml.duncte123.skybot.objects.pairs.LongLongPair)4 JDA (net.dv8tion.jda.api.JDA)4 Member (net.dv8tion.jda.api.entities.Member)4 Message (net.dv8tion.jda.api.entities.Message)4 ShardManager (net.dv8tion.jda.api.sharding.ShardManager)4 Nonnull (javax.annotation.Nonnull)3 DataObject (net.dv8tion.jda.api.utils.data.DataObject)3 JDAImpl (net.dv8tion.jda.internal.JDAImpl)3 GuildSetting (com.dunctebot.models.settings.GuildSetting)2 Parser (com.jagrosh.jagtag.Parser)2 Sentry (io.sentry.Sentry)2 DecimalFormat (java.text.DecimalFormat)2 HashSet (java.util.HashSet)2