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());
}
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());
}
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!");
}
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);
});
}
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();
}
}
Aggregations