Search in sources :

Example 76 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class CancelSubcommand method handleJamCommand.

@Override
protected ReplyCallbackAction handleJamCommand(SlashCommandInteractionEvent event, Jam activeJam, Connection con, JamConfig config) throws SQLException {
    OptionMapping confirmOption = event.getOption("confirm");
    if (confirmOption == null || !confirmOption.getAsString().equals("yes")) {
        return Responses.warning(event, "Invalid confirmation. Type `yes` to confirm cancellation.");
    }
    NewsChannel announcementChannel = config.getAnnouncementChannel();
    if (announcementChannel == null)
        throw new IllegalArgumentException("Invalid jam announcement channel id.");
    new JamRepository(con).cancelJam(activeJam);
    announcementChannel.sendMessage("The current Java Jam has been cancelled.").queue();
    return Responses.success(event, "Jam Cancelled", "The " + activeJam.getFullName() + " has been cancelled.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) NewsChannel(net.dv8tion.jda.api.entities.NewsChannel) JamRepository(net.javadiscord.javabot.systems.jam.dao.JamRepository)

Example 77 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class ModerateUserCommand method handleModerationCommand.

@Override
protected final ReplyCallbackAction handleModerationCommand(SlashCommandInteractionEvent event, Member commandUser) throws ResponseException {
    OptionMapping targetOption = event.getOption("user");
    if (targetOption == null) {
        return Responses.error(event, "Missing required arguments.");
    }
    Member target = targetOption.getAsMember();
    if (target == null) {
        return Responses.error(event, "Cannot report a user who is not a member of this server");
    }
    if (!actOnSelf || !commandUser.isOwner()) {
        if (commandUser.getId().equals(target.getId())) {
            return Responses.error(event, "You cannot perform this action on yourself.");
        }
    }
    if (target.isOwner()) {
        return Responses.error(event, "You cannot preform actions on a higher member staff member.");
    } else {
        // If both users have at least one role.
        if (target.getRoles().size() > 0 && commandUser.getRoles().size() > 0) {
            if (commandUser.getRoles().get(0).getPosition() <= target.getRoles().get(0).getPosition()) {
                return Responses.error(event, "You cannot preform actions on a higher/equal member staff member.");
            }
        }
    }
    return handleModerationActionCommand(event, commandUser, target);
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) Member(net.dv8tion.jda.api.entities.Member)

Example 78 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class PruneCommand method handleModerationCommand.

@Override
protected ReplyCallbackAction handleModerationCommand(SlashCommandInteractionEvent event, Member commandUser) throws ResponseException {
    var config = Bot.config.get(event.getGuild()).getModeration();
    OptionMapping patternOption = event.getOption("pattern");
    OptionMapping beforeOption = event.getOption("before");
    OptionMapping afterOption = event.getOption("after");
    OptionMapping reasonOption = event.getOption("reason");
    OptionMapping delDaysOption = event.getOption("delete-days-of-history");
    final var pattern = patternOption == null ? null : Pattern.compile(patternOption.getAsString());
    final var before = beforeOption == null ? null : LocalDateTime.parse(beforeOption.getAsString(), TIMESTAMP_FORMATTER).atOffset(ZoneOffset.UTC);
    final var after = afterOption == null ? null : LocalDateTime.parse(afterOption.getAsString(), TIMESTAMP_FORMATTER).atOffset(ZoneOffset.UTC);
    final var delDays = delDaysOption == null ? 0 : (int) delDaysOption.getAsLong();
    final var reason = reasonOption == null ? null : reasonOption.getAsString();
    if (pattern == null && before == null && after == null) {
        return Responses.warning(event, "At least one filter parameter must be given; cannot remove every user from the server.");
    }
    if (delDays < 0 || delDays > 7) {
        return Responses.warning(event, "The number of days of history to delete must not be less than 0, or greater than 7.");
    }
    if (reason != null && reason.length() > 512) {
        return Responses.warning(event, "The reason for the prune cannot be more than 512 characters.");
    }
    event.getGuild().loadMembers().onSuccess(members -> {
        members.forEach(member -> {
            boolean shouldRemove = (pattern == null || pattern.matcher(member.getUser().getName()).find()) && (before == null || member.getTimeJoined().isBefore(before)) && (after == null || member.getTimeJoined().isAfter(after));
            if (shouldRemove) {
                config.getLogChannel().sendMessage("Removing " + member.getUser().getAsTag() + " as part of prune.").queue();
                member.ban(delDays, reason).queue();
            }
        });
    });
    return Responses.success(event, "Prune Started", "The prune action has started. Please check the log channel for information on the status of the prune.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Example 79 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class AddQuestionSubcommand method handleCommand.

@Override
protected ReplyCallbackAction handleCommand(SlashCommandInteractionEvent event, Connection con, long guildId) throws SQLException {
    QOTWQuestion question = new QOTWQuestion();
    question.setGuildId(guildId);
    question.setCreatedBy(event.getUser().getIdLong());
    question.setPriority(0);
    OptionMapping textOption = event.getOption("question");
    if (textOption == null) {
        return Responses.warning(event, "Missing required arguments.");
    }
    String text = textOption.getAsString();
    if (text.isBlank() || text.length() > 1024) {
        return Responses.warning(event, "Invalid question text. Must not be blank, and must be less than 1024 characters.");
    }
    question.setText(text);
    OptionMapping priorityOption = event.getOption("priority");
    if (priorityOption != null) {
        question.setPriority((int) priorityOption.getAsLong());
    }
    new QuestionQueueRepository(con).save(question);
    return Responses.success(event, "Question Added", "Your question has been added to the queue. Its id is `" + question.getId() + "`.");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) QOTWQuestion(net.javadiscord.javabot.systems.qotw.model.QOTWQuestion) QuestionQueueRepository(net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository)

Example 80 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project JavaBot by Java-Discord.

the class PurgeCommand method handleModerationActionCommand.

@Override
protected ReplyCallbackAction handleModerationActionCommand(SlashCommandInteractionEvent event, Member commandUser, Member target) throws ResponseException {
    Member member = event.getMember();
    if (member == null) {
        return Responses.warning(event, "This command can only be used in a guild.");
    }
    var config = Bot.config.get(event.getGuild()).getModeration();
    OptionMapping amountOption = event.getOption("amount");
    OptionMapping userOption = event.getOption("user");
    OptionMapping archiveOption = event.getOption("archive");
    Long amount = (amountOption == null) ? null : amountOption.getAsLong();
    User user = (userOption == null) ? null : userOption.getAsUser();
    boolean archive = archiveOption != null && archiveOption.getAsBoolean();
    int maxAmount = config.getPurgeMaxMessageCount();
    if (amount != null && (amount < 1 || amount > maxAmount)) {
        return Responses.warning(event, "Invalid amount. If specified, should be between 1 and " + maxAmount + ", inclusive.");
    }
    Bot.asyncPool.submit(() -> this.purge(amount, user, archive, event.getTextChannel(), config.getLogChannel()));
    StringBuilder sb = new StringBuilder();
    sb.append(amount != null ? (amount > 1 ? "Up to " + amount + " messages " : "1 message ") : "All messages ");
    if (user != null) {
        sb.append("by the user ").append(user.getAsTag()).append(' ');
    }
    sb.append("will be removed").append(archive ? " and placed in an archive." : '.');
    return Responses.info(event, "Purge Started", sb.toString());
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Aggregations

OptionMapping (net.dv8tion.jda.api.interactions.commands.OptionMapping)133 CommandException (uwu.narumi.tama.command.CommandException)44 EmbedBuilder (net.dv8tion.jda.api.EmbedBuilder)12 Member (net.dv8tion.jda.api.entities.Member)8 TextChannel (net.dv8tion.jda.api.entities.TextChannel)8 Guild (net.dv8tion.jda.api.entities.Guild)5 Meeting (de.lightbolt.meeting.systems.meeting.model.Meeting)4 User (net.dv8tion.jda.api.entities.User)4 SlashCommandInteractionEvent (net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent)4 Message (net.dv8tion.jda.api.entities.Message)3 JamSubmissionRepository (net.javadiscord.javabot.systems.jam.dao.JamSubmissionRepository)3 Logger (org.slf4j.Logger)3 LoggerFactory (org.slf4j.LoggerFactory)3 Bean (at.xirado.bean.Bean)2 SlashCommand (at.xirado.bean.command.SlashCommand)2 SlashCommandContext (at.xirado.bean.command.SlashCommandContext)2 EmbedUtil (at.xirado.bean.misc.EmbedUtil)2 ApplicationOptionData (com.freya02.botcommands.internal.ApplicationOptionData)2 EventWaiter (com.jagrosh.jdautilities.commons.waiter.EventWaiter)2 AudioPlayer (com.sedmelluq.discord.lavaplayer.player.AudioPlayer)2