Search in sources :

Example 16 with CommandContext

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

the class AutoBanBypassCommand method execute.

@Override
public void execute(@NotNull CommandContext ctx) {
    final long checkId;
    try {
        checkId = MiscUtil.parseSnowflake(ctx.getArgs().get(0));
    } catch (NumberFormatException ignored) {
        sendMsg(ctx, "Your input (`" + ctx.getArgs().get(0) + "`) is not a valid user id.");
        return;
    }
    final DatabaseAdapter database = ctx.getDatabaseAdapter();
    final long guildId = ctx.getGuild().getIdLong();
    database.getBanBypass(guildId, checkId, (byPass) -> {
        if (byPass == null) {
            database.createBanBypass(guildId, checkId);
            sendMsg(ctx, "Single use bypass created, please note that this bypass will expire after a week if unused." + "\nPlease keep in mind that this has not unbanned any user, meaning that you will have to unban the user yourself if they are banned");
            return null;
        }
        sendMsg(ctx, "A bypass already exists for this user");
        return null;
    });
}
Also used : DatabaseAdapter(ml.duncte123.skybot.adapters.DatabaseAdapter)

Example 17 with CommandContext

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

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)

Example 18 with CommandContext

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

Example 19 with CommandContext

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

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 20 with CommandContext

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

the class PronounsCheckCommand method execute.

@Override
public void execute(@Nonnull CommandContext ctx) {
    final User target = getMentionedUser(ctx);
    final long userId = target.getIdLong();
    final JsonNode json = ctx.getApis().getPronouns(userId);
    final boolean isSelf = userId == ctx.getAuthor().getIdLong();
    if (json == null) {
        sendMsg(ctx, (isSelf ? "You do" : target.getName() + " does") + " not have any pronouns set");
        return;
    }
    final String pronouns = json.get("pronouns").asText();
    final String singular = json.get("singular").asBoolean() ? "Singular" : "Plural";
    final String userName = isSelf ? "Your" : target.getName() + "'s";
    final String format = "%s current pronouns are:%n**%s** (%s)";
    sendMsg(ctx, String.format(format, userName, pronouns, singular));
}
Also used : AirUtils.getMentionedUser(ml.duncte123.skybot.utils.AirUtils.getMentionedUser) User(net.dv8tion.jda.api.entities.User) JsonNode(com.fasterxml.jackson.databind.JsonNode)

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