Search in sources :

Example 31 with SlashCommandEvent

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

the class TagManageCommandTest method editWithMessageUnknownMessageFails.

@Test
@DisplayName("'/tag-manage edit-with-message' fails if the linked message is unknown")
void editWithMessageUnknownMessageFails() {
    // GIVEN a tag system with the "foo" tag and an unknown message id
    system.putTag("foo", "old");
    failOnRetrieveMessage("1", jdaTester.createErrorResponseException(ErrorResponse.UNKNOWN_MESSAGE));
    // WHEN using '/tag-manage edit-with-message id:foo message-id:1'
    SlashCommandEvent event = triggerEditWithMessageCommand("foo", "1");
    // THEN the command fails and responds accordingly, the tag has not changed
    verify(event).reply("The message with id '1' does not exist.");
    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 32 with SlashCommandEvent

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

the class TagManageCommandTest method editWithMessageGenericErrorFails.

@Test
@DisplayName("'/tag-manage edit-with-message' fails if there is a generic error (such as a network failure)")
void editWithMessageGenericErrorFails() {
    // GIVEN a tag system with the "foo" tag and a generic network failure
    system.putTag("foo", "old");
    failOnRetrieveMessage("1", new IOException("Generic network failure"));
    // WHEN using '/tag-manage edit-with-message id:foo message-id:1'
    SlashCommandEvent event = triggerEditWithMessageCommand("foo", "1");
    // THEN the command fails and responds accordingly, the tag has not changed
    verify(event).reply(startsWith("Something unexpected went wrong"));
    assertTrue(system.hasTag("foo"));
    assertEquals("old", system.getTag("foo").orElseThrow());
}
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)

Example 33 with SlashCommandEvent

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

the class PingCommandTest method pingRespondsWithPong.

@Test
@DisplayName("'/ping' responds with pong")
void pingRespondsWithPong() {
    // GIVEN
    // WHEN using '/ping'
    SlashCommandEvent event = triggerSlashCommand();
    // THEN the bot replies with pong
    verify(event).reply("Pong!");
}
Also used : SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 34 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project clancy by brendonmiranda.

the class PlayCmd method command.

@Override
public void command(SlashCommandEvent event) {
    OptionMapping option = event.getOption(MUSIC_ARG);
    String args = option.getAsString();
    logger.debug("PlayCmd loading track: {}", args);
    AudioPlayer audioPlayer = audioPlayerManager.createPlayer();
    audioPlayer.addListener(audioEventListener);
    Consumer<Message> success = (message) -> {
        Guild guild = event.getGuild();
        AudioManager audioManager = guild.getAudioManager();
        PlayResultHandler playResultHandler = new PlayResultHandler(audioPlayer, guild, audioManager, event, audioPlayerManager, eventWaiter, message, false, audioQueueService);
        audioPlayerManager.loadItemOrdered(event.getGuild(), args, playResultHandler);
    };
    event.replyEmbeds(MessageUtil.buildMessage("Searching...")).queue(interactionHook -> {
        interactionHook.retrieveOriginal().queue(success);
    });
}
Also used : OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Message(net.dv8tion.jda.api.entities.Message) OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) MessageUtil(io.github.brendonmiranda.bot.clancy.util.MessageUtil) Logger(org.slf4j.Logger) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) AudioManager(net.dv8tion.jda.api.managers.AudioManager) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) EventWaiter(com.jagrosh.jdautilities.commons.waiter.EventWaiter) AudioPlayerManager(com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) Consumer(java.util.function.Consumer) AudioQueueService(io.github.brendonmiranda.bot.clancy.service.AudioQueueService) Component(org.springframework.stereotype.Component) PlayResultHandler(io.github.brendonmiranda.bot.clancy.listener.PlayResultHandler) Guild(net.dv8tion.jda.api.entities.Guild) OptionMapping(net.dv8tion.jda.api.interactions.commands.OptionMapping) AudioEventListener(io.github.brendonmiranda.bot.clancy.listener.AudioEventListener) Collections(java.util.Collections) AudioManager(net.dv8tion.jda.api.managers.AudioManager) Message(net.dv8tion.jda.api.entities.Message) PlayResultHandler(io.github.brendonmiranda.bot.clancy.listener.PlayResultHandler) AudioPlayer(com.sedmelluq.discord.lavaplayer.player.AudioPlayer) Guild(net.dv8tion.jda.api.entities.Guild)

Example 35 with SlashCommandEvent

use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TechDiscordBot by TechsCode-Team.

the class GetReleaseCommand method onCommand.

@Override
public void onCommand(TextChannel channel, Member m, SlashCommandEvent e) {
    String plugin = e.getOption("plugin").getAsString();
    if (plugin.equals("error"))
        return;
    if (SUPPORT_CATEGORIES.query().stream().anyMatch(c -> c.getId().equals(channel.getParent().getId()))) {
        e.reply("Getting release... please wait.").queue(q -> {
            GithubRelease release = GitHubUtil.getLatestRelease(plugin);
            if (release == null) {
                q.editOriginal("**Failed!** Could not get the release!\n\n**Possible reasons:**\n- The repo isn't valid.\n- There is no release in the repo.\n- Github is down.").queue();
            } else if (release.getFile() != null) {
                q.editOriginal(release.getFile(), plugin + ".jar").queue(msg2 -> release.getFile().delete());
                q.editOriginalEmbeds(new TechEmbedBuilder(release.getRelease().getName()).text("```" + (release.getRelease().getBody().isEmpty() ? "No changes specified." : release.getRelease().getBody().replaceAll(" \\|\\| ", "\n")) + "```").build()).queue();
            } else {
                q.editOriginal("**Failed!** Could not get the file!\n\n**Possible reasons:**\n- The developer messed up.\n- The release has no files for some reason.\n- GitHub is down.").queue();
            }
        });
    } else {
        StringBuilder channels = new StringBuilder();
        SUPPORT_CATEGORIES.query().forEach(c -> channels.append("\n - ").append(c.getAsMention()));
        e.replyEmbeds(new TechEmbedBuilder("Get Release - Error").text("You can not use this command in this channel's category.\n\n**Available Categories:**" + channels).error().build()).setEphemeral(true).queue();
    }
}
Also used : OptionType(net.dv8tion.jda.api.interactions.commands.OptionType) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) TechDiscordBot(me.TechsCode.TechDiscordBot.TechDiscordBot) Category(net.dv8tion.jda.api.entities.Category) OptionData(net.dv8tion.jda.api.interactions.commands.build.OptionData) Member(net.dv8tion.jda.api.entities.Member) TextChannel(net.dv8tion.jda.api.entities.TextChannel) Command(net.dv8tion.jda.api.interactions.commands.Command) Collectors(java.util.stream.Collectors) SlashCommandEvent(net.dv8tion.jda.api.events.interaction.SlashCommandEvent) CommandModule(me.TechsCode.TechDiscordBot.module.CommandModule) GitHubUtil(me.TechsCode.TechDiscordBot.github.GitHubUtil) Role(net.dv8tion.jda.api.entities.Role) GithubRelease(me.TechsCode.TechDiscordBot.github.GithubRelease) CommandPrivilege(net.dv8tion.jda.api.interactions.commands.privileges.CommandPrivilege) DefinedQuery(me.TechsCode.TechDiscordBot.objects.DefinedQuery) Query(me.TechsCode.TechDiscordBot.objects.Query) TechEmbedBuilder(me.TechsCode.TechDiscordBot.util.TechEmbedBuilder) GithubRelease(me.TechsCode.TechDiscordBot.github.GithubRelease)

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