use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.
the class TagManageCommandTest method editWithMessageFailsForInvalidMessageId.
@Test
@DisplayName("'/tag-manage edit-with-message' fails if the given message id is in an invalid format")
void editWithMessageFailsForInvalidMessageId() {
// GIVEN a tag system with the "foo" tag
system.putTag("foo", "old");
// WHEN using '/tag-manage edit-with-message id:foo message-id:new'
SlashCommandEvent event = triggerEditWithMessageCommand("foo", "bar");
// THEN the command fails and responds accordingly, the tags content was not changed
verify(event).reply("The given message id 'bar' is invalid, expected a number.");
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 commandCanNotBeUsedWithoutRoles.
@Test
@DisplayName("Users without the required role can not use '/tag-manage'")
void commandCanNotBeUsedWithoutRoles() {
// GIVEN a regular user without roles
Member regularUser = jdaTester.createMemberSpy(1);
// WHEN the regular user triggers any '/tag-manage' command
SlashCommandEvent event = triggerRawCommandWithUser("foo", regularUser);
// THEN the command can not be used since the user lacks roles
verify(event).reply("Tags can only be managed by users with a corresponding role.");
}
use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.
the class TagManageCommandTest method editWithMessageUnknownTagFails.
@Test
@DisplayName("'/tag-manage edit-with-message' fails if the tag is unknown")
void editWithMessageUnknownTagFails() {
// GIVEN a tag system without any tags
postMessage("bar", "1");
// WHEN using '/tag-manage edit-with-message id:foo message-id:new'
SlashCommandEvent event = triggerEditWithMessageCommand("foo", "1");
// 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"));
}
use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.
the class TagManageCommandTest method editExistingTagWorks.
@Test
@DisplayName("'/tag-manage edit' works if the tag is known")
void editExistingTagWorks() {
// GIVEN a tag system with the "foo" tag
system.putTag("foo", "old");
// WHEN using '/tag-manage edit id:foo content:new'
SlashCommandEvent event = triggerEditCommand("foo", "new");
// THEN the command succeeds and the content of the tag was changed
assertEquals("Success", getResponse(event).getTitle());
assertEquals("new", system.getTag("foo").orElseThrow());
}
use of net.dv8tion.jda.api.events.interaction.SlashCommandEvent in project TJ-Bot by Together-Java.
the class TagsCommand method onSlashCommand.
@Override
public void onSlashCommand(@NotNull SlashCommandEvent event) {
Collection<String> tagIds = tagSystem.getAllIds();
if (tagIds.size() > MAX_TAGS_THRESHOLD_WARNING) {
// TODO Implement the edge case
logger.warn("The amount of tags is very high and it might soon exceed the maximum character limit. The code should be adjusted to support this edge case soon.");
}
String tagListText = tagIds.stream().sorted().map(tag -> "• " + tag).collect(Collectors.joining("\n"));
event.replyEmbeds(new EmbedBuilder().setTitle("All available tags").setDescription(tagListText).setFooter(event.getUser().getName() + " • used " + event.getCommandString()).setTimestamp(Instant.now()).setColor(TagSystem.AMBIENT_COLOR).build()).addActionRow(TagSystem.createDeleteButton(generateComponentId(event.getUser().getId()))).queue();
}
Aggregations