Search in sources :

Example 86 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project Ninbot by Nincodedo.

the class PollCommandTest method parsePollMessage.

@Test
void parsePollMessage() {
    Member member = Mockito.mock(Member.class);
    TextChannel textChannel = Mockito.mock(TextChannel.class);
    Guild guild = Mockito.mock(Guild.class);
    OptionMapping choice1 = Mockito.mock(OptionMapping.class);
    OptionMapping choice2 = Mockito.mock(OptionMapping.class);
    OptionMapping choice3 = Mockito.mock(OptionMapping.class);
    OptionMapping questionOption = Mockito.mock(OptionMapping.class);
    when(slashCommandEvent.getChannel()).thenReturn(textChannel);
    when(slashCommandEvent.getGuild()).thenReturn(guild);
    when(slashCommandEvent.getOption("choice1")).thenReturn(choice1);
    when(slashCommandEvent.getOption("choice2")).thenReturn(choice2);
    when(slashCommandEvent.getOptions()).thenReturn(List.of(choice3));
    when(choice3.getName()).thenReturn("choice3");
    when(choice3.getAsString()).thenReturn("3rd");
    when(slashCommandEvent.getOption("question")).thenReturn(questionOption);
    when(questionOption.getAsString()).thenReturn("test");
    when(slashCommandEvent.getOption("userchoices")).thenReturn(null);
    when(slashCommandEvent.getOption("polllength")).thenReturn(null);
    when(guild.getId()).thenReturn("1");
    when(textChannel.getId()).thenReturn("1");
    when(member.getEffectiveAvatarUrl()).thenReturn("http://avatarturl.com/avatar.png");
    when(member.getEffectiveName()).thenReturn("Nincodedo");
    var poll = pollCommand.parsePollMessage(slashCommandEvent, member);
    assertThat(poll.getChoices()).isNotEmpty();
    assertThat(poll.getChoices()).hasSize(3);
    assertThat(poll.getTitle()).isEqualTo("test");
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) Test(org.junit.jupiter.api.Test)

Example 87 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project Ninbot by Nincodedo.

the class PollCommandTest method executePollCommand.

@Test
void executePollCommand() {
    Member member = Mockito.mock(Member.class);
    TextChannel textChannel = Mockito.mock(TextChannel.class);
    Guild guild = Mockito.mock(Guild.class);
    ReplyCallbackAction replyAction = Mockito.mock(ReplyCallbackAction.class);
    OptionMapping choice1 = Mockito.mock(OptionMapping.class);
    OptionMapping choice2 = Mockito.mock(OptionMapping.class);
    OptionMapping questionOption = Mockito.mock(OptionMapping.class);
    when(slashCommandEvent.getChannel()).thenReturn(textChannel);
    when(slashCommandEvent.getGuild()).thenReturn(guild);
    when(slashCommandEvent.getMember()).thenReturn(member);
    when(slashCommandEvent.getOption("choice1")).thenReturn(choice1);
    when(slashCommandEvent.getOption("choice2")).thenReturn(choice2);
    when(slashCommandEvent.getOption("question")).thenReturn(questionOption);
    when(slashCommandEvent.reply(any(Message.class))).thenReturn(replyAction);
    when(choice1.getAsString()).thenReturn("1st");
    when(choice2.getAsString()).thenReturn("2nd");
    when(questionOption.getAsString()).thenReturn("why?");
    when(guild.getId()).thenReturn("1");
    when(textChannel.getId()).thenReturn("1");
    when(member.getEffectiveAvatarUrl()).thenReturn("http://google.com/a-url");
    when(guild.getLocale()).thenReturn(Locale.ENGLISH);
    var actualMessageAction = pollCommand.execute(slashCommandEvent);
    assertThat(actualMessageAction).isNotNull();
    assertThat(actualMessageAction.getReactions()).isEmpty();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Message(net.dv8tion.jda.api.entities.Message) ReplyCallbackAction(net.dv8tion.jda.api.requests.restaction.interactions.ReplyCallbackAction) Guild(net.dv8tion.jda.api.entities.Guild) Member(net.dv8tion.jda.api.entities.Member) Test(org.junit.jupiter.api.Test)

Example 88 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project LightboltMeeting by LightboltMeeting.

the class StartMeetingSubcommand method handleMeetingCommand.

@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
    OptionMapping idOption = event.getOption("meeting-id");
    if (idOption == null) {
        return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
    }
    int id = (int) idOption.getAsLong();
    Optional<Meeting> meetingOptional = repo.getById(id);
    if (meetingOptional.isEmpty()) {
        return Responses.error(event, String.format(locale.getMeeting().getCommand().getMEETING_NOT_FOUND(), id));
    }
    Meeting meeting = meetingOptional.get();
    if (!MeetingManager.canEditMeeting(meeting, event.getUser().getIdLong())) {
        return Responses.error(event, locale.getMeeting().getMEETING_NO_PERMISSION());
    }
    Bot.meetingStateManager.cancelMeetingSchedule(meeting);
    new MeetingManager(event.getJDA(), meeting).startMeeting(event.getUser());
    var com = locale.getMeeting().getCommand();
    return Responses.success(event, com.getMEETING_START_SUCCESS_TITLE(), String.format(com.getMEETING_START_SUCCESS_DESCRIPTION(), meeting.getTitle()));
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) MeetingManager(de.lightbolt.meeting.systems.meeting.MeetingManager) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Example 89 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project LightboltMeeting by LightboltMeeting.

the class EditMeetingSubcommand method handleMeetingCommand.

@Override
protected ReplyCallbackAction handleMeetingCommand(SlashCommandInteractionEvent event, LocaleConfig locale, SystemsConfig.MeetingConfig config, MeetingRepository repo) throws SQLException {
    OptionMapping idOption = event.getOption("meeting-id");
    if (idOption == null) {
        return Responses.error(event, locale.getCommand().getMISSING_ARGUMENTS());
    }
    int id = (int) idOption.getAsLong();
    Optional<Meeting> meetingOptional = repo.getById(id);
    if (meetingOptional.isEmpty()) {
        return Responses.error(event, String.format(locale.getMeeting().getCommand().getMEETING_NOT_FOUND(), id));
    }
    Meeting meeting = meetingOptional.get();
    if (!MeetingManager.canEditMeeting(meeting, event.getUser().getIdLong())) {
        return Responses.error(event, locale.getMeeting().getMEETING_NO_PERMISSION());
    }
    this.buildEditModal(event, meeting, locale).queue();
    return null;
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) Meeting(de.lightbolt.meeting.systems.meeting.model.Meeting)

Example 90 with OptionMapping

use of net.dv8tion.jda.api.interactions.commands.OptionMapping in project TamaBot by Loli-Cafe.

the class LickPussyCommand method compose.

@Override
public void compose(SlashCommandInteractionEvent event) {
    checkContext(event.getMember(), event.getTextChannel());
    OptionMapping optionMapping = event.getOption("user");
    if (optionMapping == null)
        throw new CommandException(getUsage());
    event.replyEmbeds(execute(String.format("%s gaping %s pussy", event.getUser().getAsMention(), optionMapping.getAsUser().getAsMention()))).queue();
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) CommandException(uwu.narumi.tama.command.CommandException)

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