Search in sources :

Example 21 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagCommandTest method triggerSlashCommand.

@NotNull
private SlashCommandEvent triggerSlashCommand(@NotNull String id, @Nullable Member userToReplyTo) {
    SlashCommandEventBuilder builder = jdaTester.createSlashCommandEvent(command).setOption(TagCommand.ID_OPTION, id);
    if (userToReplyTo != null) {
        builder.setOption(TagCommand.REPLY_TO_USER_OPTION, userToReplyTo);
    }
    SlashCommandEvent event = builder.build();
    command.onSlashCommand(event);
    return event;
}
Also used : SlashCommandEventBuilder(org.togetherjava.tjbot.jda.SlashCommandEventBuilder) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagManageCommandTest method createWithMessageUnknownMessageFails.

@Test
@DisplayName("'/tag-manage create-with-message' fails if the linked message is unknown")
void createWithMessageUnknownMessageFails() {
    // GIVEN a tag system without any tags and an unknown message id
    failOnRetrieveMessage("1", jdaTester.createErrorResponseException(ErrorResponse.UNKNOWN_MESSAGE));
    // WHEN using '/tag-manage create-with-message id:foo message-id:1'
    SlashCommandEvent event = triggerCreateWithMessageCommand("foo", "1");
    // THEN the command fails and responds accordingly, the tag was not created
    verify(event).reply("The message with id '1' does not exist.");
    assertFalse(system.hasTag("foo"));
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 23 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagManageCommandTest method createWithMessageNewTagWorks.

@Test
@DisplayName("'/tag-manage create-with-message' works if the tag is new")
void createWithMessageNewTagWorks() {
    // GIVEN a tag system without any tags and a message with id and content
    postMessage("bar", "1");
    // WHEN using '/tag-manage create-with-message id:foo message-id:1'
    SlashCommandEvent event = triggerCreateWithMessageCommand("foo", "1");
    // THEN the command succeeds and the system contains the tag
    assertEquals("Success", getResponse(event).getTitle());
    assertTrue(system.hasTag("foo"));
    assertEquals("bar", system.getTag("foo").orElseThrow());
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 24 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagManageCommandTest method createNewTagWorks.

@Test
@DisplayName("'/tag-manage create' works if the tag is new")
void createNewTagWorks() {
    // GIVEN a tag system without any tags
    // WHEN using '/tag-manage create id:foo content:bar'
    SlashCommandEvent event = triggerCreateCommand("foo", "bar");
    // THEN the command succeeds and the system contains the tag
    assertEquals("Success", getResponse(event).getTitle());
    assertTrue(system.hasTag("foo"));
    assertEquals("bar", system.getTag("foo").orElseThrow());
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 25 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.

the class TagManageCommandTest method editWithMessageExistingTagWorks.

@Test
@DisplayName("'/tag-manage edit-with-message' works if the tag is known")
void editWithMessageExistingTagWorks() {
    // GIVEN a tag system with the "foo" tag
    system.putTag("foo", "old");
    postMessage("new", "1");
    // WHEN using '/tag-manage edit-with-message id:foo message-id:1'
    SlashCommandEvent event = triggerEditWithMessageCommand("foo", "1");
    // THEN the command succeeds and the content of the tag was changed
    assertEquals("Success", getResponse(event).getTitle());
    assertEquals("new", system.getTag("foo").orElseThrow());
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

SlashCommandEvent (net.dv8tion.jda.api.events.interaction.SlashCommandEvent)35 Test (org.junit.jupiter.api.Test)24 DisplayName (org.junit.jupiter.api.DisplayName)23 NotNull (org.jetbrains.annotations.NotNull)8 Collectors (java.util.stream.Collectors)3 Member (net.dv8tion.jda.api.entities.Member)3 IOException (java.io.IOException)2 List (java.util.List)2 Consumer (java.util.function.Consumer)2 TechDiscordBot (me.TechsCode.TechDiscordBot.TechDiscordBot)2 DefinedQuery (me.TechsCode.TechDiscordBot.objects.DefinedQuery)2 Query (me.TechsCode.TechDiscordBot.objects.Query)2 TechEmbedBuilder (me.TechsCode.TechDiscordBot.util.TechEmbedBuilder)2 Permission (net.dv8tion.jda.api.Permission)2 Guild (net.dv8tion.jda.api.entities.Guild)2 MessageEmbed (net.dv8tion.jda.api.entities.MessageEmbed)2 OptionType (net.dv8tion.jda.api.interactions.commands.OptionType)2 OptionData (net.dv8tion.jda.api.interactions.commands.build.OptionData)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2