Search in sources :

Example 26 with SlashCommandEvent

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

the class TagManageCommandTest method triggerTagMessageCommand.

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

Example 27 with SlashCommandEvent

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

the class TagManageCommandTest method deleteUnknownTagFails.

@Test
@DisplayName("'/tag-manage delete' fails if the tag is unknown")
void deleteUnknownTagFails() {
    // GIVEN a tag system without any tags
    // WHEN using '/tag-manage delete id:foo'
    SlashCommandEvent event = triggerDeleteCommand("foo");
    // THEN the command fails and responds accordingly
    verify(event).reply(startsWith("Could not find any tag with id"));
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 28 with SlashCommandEvent

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

the class TagManageCommandTest method triggerRawCommandWithUser.

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

Example 29 with SlashCommandEvent

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

the class TagManageCommandTest method deleteExistingTagWorks.

@Test
@DisplayName("'/tag-manage delete' works if the tag is known")
void deleteExistingTagWorks() {
    // GIVEN a tag system with the "foo" tag
    system.putTag("foo", "bar");
    // WHEN using '/tag-manage delete id:foo'
    SlashCommandEvent event = triggerDeleteCommand("foo");
    // THEN the command succeeds and the tag was deleted
    assertEquals("Success", getResponse(event).getTitle());
    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 30 with SlashCommandEvent

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

the class TagManageCommandTest method createWithMessageGenericErrorFails.

@Test
@DisplayName("'/tag-manage create-with-message' fails if there is a generic error (such as a network failure)")
void createWithMessageGenericErrorFails() {
    // GIVEN a tag system without any tags and a generic network failure
    failOnRetrieveMessage("1", new IOException("Generic network failure"));
    // 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(startsWith("Something unexpected went wrong"));
    assertFalse(system.hasTag("foo"));
}
Also used : IOException(java.io.IOException) 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