Search in sources :

Example 81 with OptionMapping

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

the class ListQuestionsSubcommand method handleCommand.

@Override
protected ReplyCallbackAction handleCommand(SlashCommandInteractionEvent event, Connection con, long guildId) throws SQLException {
    var repository = new QuestionQueueRepository(con);
    OptionMapping pageOption = event.getOption("page");
    int page = 0;
    if (pageOption != null) {
        int userPage = (int) pageOption.getAsLong();
        if (userPage < 0) {
            return Responses.warning(event, "Invalid page.");
        }
        page = userPage;
    }
    var questions = repository.getQuestions(guildId, page, 10);
    EmbedBuilder embedBuilder = new EmbedBuilder().setTitle("QOTW Questions Queue");
    if (questions.isEmpty()) {
        embedBuilder.setDescription("There are no questions in the queue.");
        return event.replyEmbeds(embedBuilder.build());
    }
    Bot.asyncPool.submit(() -> {
        for (var question : questions) {
            embedBuilder.addField(String.valueOf(question.getId()), String.format("> %s\nPriority: **%d**\nCreated by: %s\nCreated at: %s", question.getText(), question.getPriority(), event.getJDA().retrieveUserById(question.getCreatedBy()).complete().getAsTag(), question.getCreatedAt().format(DateTimeFormatter.ofPattern("d MMMM yyyy"))), false);
        }
        event.getHook().sendMessageEmbeds(embedBuilder.build()).queue();
    });
    return event.deferReply();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder) QuestionQueueRepository(net.javadiscord.javabot.systems.qotw.dao.QuestionQueueRepository)

Example 82 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.

the class AuditCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    OptionMapping targetOption = Objects.requireNonNull(event.getOption(TARGET_OPTION), "The target is null");
    User target = targetOption.getAsUser();
    Member author = Objects.requireNonNull(event.getMember(), "The author is null");
    Guild guild = Objects.requireNonNull(event.getGuild());
    Member bot = guild.getSelfMember();
    if (!handleChecks(bot, author, targetOption.getAsMember(), guild, event)) {
        return;
    }
    auditUser(target, guild, event);
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Example 83 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.

the class RoleSelectCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull final SlashCommandEvent event) {
    Member member = Objects.requireNonNull(event.getMember(), "Member is null");
    if (!member.hasPermission(Permission.MANAGE_ROLES)) {
        event.reply("You dont have the right permissions to use this command").setEphemeral(true).queue();
        return;
    }
    Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember();
    if (!selfMember.hasPermission(Permission.MANAGE_ROLES)) {
        event.reply("The bot needs the manage role permissions").setEphemeral(true).queue();
        logger.error("The bot needs the manage role permissions");
        return;
    }
    SelectionMenu.Builder menu = SelectionMenu.create(generateComponentId(Lifespan.PERMANENT, member.getId()));
    addMenuOptions(event, menu, "Select the roles to display", 1);
    // Handle Optional arguments
    OptionMapping titleOption = event.getOption(TITLE_OPTION);
    OptionMapping descriptionOption = event.getOption(DESCRIPTION_OPTION);
    String title = handleOption(titleOption);
    String description = handleOption(descriptionOption);
    MessageBuilder messageBuilder = new MessageBuilder(makeEmbed(title, description)).setActionRows(ActionRow.of(menu.build()));
    event.reply(messageBuilder.build()).setEphemeral(true).queue();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) MessageBuilder(net.dv8tion.jda.api.MessageBuilder) SelectionMenu(net.dv8tion.jda.api.interactions.components.selections.SelectionMenu)

Example 84 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.

the class NoteCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    OptionMapping targetOption = event.getOption(USER_OPTION);
    Member author = event.getMember();
    Guild guild = event.getGuild();
    String content = event.getOption(CONTENT_OPTION).getAsString();
    if (!handleChecks(guild.getSelfMember(), author, targetOption.getAsMember(), content, event)) {
        return;
    }
    sendNote(targetOption.getAsUser(), author, content, guild, event);
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping)

Example 85 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TJ-Bot by Together-Java.

the class TagCommand method onSlashCommand.

@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
    String id = Objects.requireNonNull(event.getOption(ID_OPTION)).getAsString();
    OptionMapping replyToUserOption = event.getOption(REPLY_TO_USER_OPTION);
    if (tagSystem.handleIsUnknownTag(id, event)) {
        return;
    }
    ReplyAction message = event.replyEmbeds(new EmbedBuilder().setDescription(tagSystem.getTag(id).orElseThrow()).setFooter(event.getUser().getName() + " • used " + event.getCommandString()).setTimestamp(Instant.now()).setColor(TagSystem.AMBIENT_COLOR).build());
    if (replyToUserOption != null) {
        message = message.setContent(replyToUserOption.getAsUser().getAsMention());
    }
    message.queue();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) ReplyAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyAction) EmbedBuilder(net.dv8tion.jda.api.EmbedBuilder)

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