Search in sources :

Example 6 with SlashCommandEvent

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

the class TagManageCommandTest method createWithMessageFailsForInvalidMessageId.

@Test
@DisplayName("'/tag-manage create-with-message' fails if the given message id is in an invalid format")
void createWithMessageFailsForInvalidMessageId() {
    // GIVEN a tag system without any tags
    // WHEN using '/tag-manage create-with-message id:foo message-id:bar'
    SlashCommandEvent event = triggerCreateWithMessageCommand("foo", "bar");
    // THEN the command fails and responds accordingly, the tag was not created
    verify(event).reply("The given message id 'bar' is invalid, expected a number.");
    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 7 with SlashCommandEvent

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

the class TagManageCommandTest method createWithMessageTagThatAlreadyExistsFails.

@Test
@DisplayName("'/tag-manage create-with-message' fails if the tag is known")
void createWithMessageTagThatAlreadyExistsFails() {
    // GIVEN a tag system with the "foo" tag and a message with id and content
    system.putTag("foo", "old");
    postMessage("new", "1");
    // 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 is still there and unchanged
    verify(event).reply("The tag with id 'foo' already exists.");
    assertTrue(system.hasTag("foo"));
    assertEquals("old", 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 8 with SlashCommandEvent

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

the class TagManageCommandTest method triggerDeleteCommand.

@NotNull
private SlashCommandEvent triggerDeleteCommand(@NotNull String tagId) {
    SlashCommandEvent event = jdaTester.createSlashCommandEvent(command).setSubcommand(TagManageCommand.Subcommand.DELETE.getName()).setOption(TagManageCommand.ID_OPTION, tagId).setUserWhoTriggered(moderator).build();
    command.onSlashCommand(event);
    return event;
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with SlashCommandEvent

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

the class TagManageCommandTest method editUnknownTagFails.

@Test
@DisplayName("'/tag-manage edit' fails if the tag is unknown")
void editUnknownTagFails() {
    // GIVEN a tag system without any tags
    // WHEN using '/tag-manage edit id:foo content:new'
    SlashCommandEvent event = triggerEditCommand("foo", "new");
    // THEN the command fails and responds accordingly, the tag was not created
    verify(event).reply(startsWith("Could not find any tag with id"));
    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 10 with SlashCommandEvent

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

the class TagManageCommandTest method createTagThatAlreadyExistsFails.

@Test
@DisplayName("'/tag-manage create' fails if the tag already exists")
void createTagThatAlreadyExistsFails() {
    // GIVEN a tag system with the "foo" tag
    system.putTag("foo", "old");
    // WHEN using '/tag-manage create id:foo content:new'
    SlashCommandEvent event = triggerCreateCommand("foo", "new");
    // THEN the command fails and responds accordingly, the tag is still there and unchanged
    verify(event).reply("The tag with id 'foo' already exists.");
    assertTrue(system.hasTag("foo"));
    assertEquals("old", 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