From ef404c8bc81a5786577093ae17af7000432d7b49 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Wed, 8 Dec 2021 18:22:17 +0100 Subject: [PATCH 01/10] This is a pull request on resolving the issue#275, The issue was resolved with adding a parameters to MethodUtils which would provide the tags into the footer for the embeds, also edited the values of 5 classes so they match the parameters for MethodUtils --- .../togetherjava/tjbot/commands/free/FreeCommand.java | 2 +- .../org/togetherjava/tjbot/commands/tags/TagCommand.java | 2 +- .../tjbot/commands/tags/TagManageCommand.java | 9 +++++---- .../togetherjava/tjbot/commands/tags/TagsCommand.java | 6 ++++-- .../togetherjava/tjbot/commands/utils/MessageUtils.java | 5 +++-- 5 files changed, 14 insertions(+), 10 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index 006f789b99..88a1c40611 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -202,7 +202,7 @@ public void displayStatus(@NotNull TextChannel channel) { String messageTxt = buildStatusMessage(guild); MessageEmbed embed = MessageUtils.generateEmbed(STATUS_TITLE, messageTxt, - channel.getJDA().getSelfUser(), MESSAGE_HIGHLIGHT_COLOR); + channel.getJDA().getSelfUser(), MESSAGE_HIGHLIGHT_COLOR, null); getStatusMessageIn(channel).flatMap(this::deleteIfNotLatest) .ifPresentOrElse(message -> message.editMessageEmbeds(embed).queue(), diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index 9d48fba27a..f897adfe85 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -45,7 +45,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event .replyEmbeds(MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), - event.getUser(), TagSystem.AMBIENT_COLOR)) + event.getUser(), TagSystem.AMBIENT_COLOR, event.getCommandString())) .queue(); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index 0e34190be5..6c7829aa0e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -90,9 +90,10 @@ public TagManageCommand(TagSystem tagSystem) { private static void sendSuccessMessage(@NotNull Interaction event, @NotNull String id, @NotNull String actionVerb) { logger.info("User '{}' {} the tag with id '{}'.", event.getUser().getId(), actionVerb, id); - event.replyEmbeds(MessageUtils.generateEmbed("Success", - "Successfully %s tag '%s'.".formatted(actionVerb, id), event.getUser(), - TagSystem.AMBIENT_COLOR)) + event + .replyEmbeds(MessageUtils.generateEmbed("Success", + "Successfully %s tag '%s'.".formatted(actionVerb, id), event.getUser(), + TagSystem.AMBIENT_COLOR, null)) .queue(); } @@ -149,7 +150,7 @@ private void rawTag(@NotNull SlashCommandEvent event) { event.replyEmbeds(MessageUtils.generateEmbed(null, MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow()), event.getUser(), - TagSystem.AMBIENT_COLOR)) + TagSystem.AMBIENT_COLOR, null)) .queue(); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java index 82baa36a94..43db3fa086 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java @@ -42,8 +42,10 @@ public TagsCommand(TagSystem tagSystem) { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // TODO A list might be better than comma separated, which is hard to read - event.replyEmbeds(MessageUtils.generateEmbed("All available tags", - String.join(", ", tagSystem.getAllIds()), event.getUser(), TagSystem.AMBIENT_COLOR)) + event + .replyEmbeds(MessageUtils.generateEmbed("All available tags", + String.join(", ", tagSystem.getAllIds()), event.getUser(), + TagSystem.AMBIENT_COLOR, null)) .addActionRow( TagSystem.createDeleteButton(generateComponentId(event.getUser().getId()))) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index 6828b594c2..8056be993a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -54,11 +54,12 @@ public static void disableButtons(@NotNull Message message) { * @return the generated embed */ public static @NotNull MessageEmbed generateEmbed(@Nullable String title, - @NotNull CharSequence content, @Nullable User user, @Nullable Color ambientColor) { + @NotNull CharSequence content, @Nullable User user, @Nullable Color ambientColor, + @Nullable String footer) { return new EmbedBuilder().setTitle(title) .setDescription(content) .setTimestamp(Instant.now()) - .setFooter(user == null ? null : user.getName()) + .setFooter(user == null ? null : user.getName() + " " + footer) .setColor(ambientColor) .build(); } From 8e15c4d8799403ca7e708e03da353481a2feabfa Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Wed, 8 Dec 2021 19:41:35 +0100 Subject: [PATCH 02/10] Sollution to improving the footer reply --- .../togetherjava/tjbot/commands/tags/TagCommand.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index f897adfe85..17194013af 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -1,5 +1,7 @@ package org.togetherjava.tjbot.commands.tags; +import net.dv8tion.jda.api.entities.MessageEmbed; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; @@ -43,9 +45,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - event - .replyEmbeds(MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), - event.getUser(), TagSystem.AMBIENT_COLOR, event.getCommandString())) - .queue(); + event.replyEmbeds(tagEmbed(id, event.getUser(), event.getCommandString())).queue(); + } + + private MessageEmbed tagEmbed(String id, User user, String commandString) { + return MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), user, + TagSystem.AMBIENT_COLOR, user.getName() + " " + commandString); } } From 4baa29fe98c8f9fa0ddbc8c50719f4c6333fabdb Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 09:34:51 +0100 Subject: [PATCH 03/10] Removed the generate embed method from MessageUtils.java and added the EmbedBuilder instead to the classes as a replacement --- .../tjbot/commands/free/FreeCommand.java | 22 +++++++++++-- .../tjbot/commands/tags/TagCommand.java | 19 +++++++++--- .../tjbot/commands/tags/TagManageCommand.java | 31 ++++++++++++++----- .../tjbot/commands/tags/TagsCommand.java | 17 +++++++--- .../tjbot/commands/utils/MessageUtils.java | 26 ---------------- 5 files changed, 70 insertions(+), 45 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index 88a1c40611..fb32c9d699 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -1,5 +1,6 @@ package org.togetherjava.tjbot.commands.free; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Message; @@ -16,11 +17,11 @@ import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -import org.togetherjava.tjbot.commands.utils.MessageUtils; import org.togetherjava.tjbot.config.Config; import org.togetherjava.tjbot.config.FreeCommandConfig; import java.awt.*; +import java.time.Instant; import java.util.*; // TODO (can SlashCommandVisibility be narrower than GUILD?) @@ -197,12 +198,27 @@ private boolean handleShouldBeProcessed(@NotNull final SlashCommandEvent event) * * @param channel the text channel the status message will be posted in. */ + + /* + * event.replyEmbeds(new EmbedBuilder() .setDescription(tagSystem.getTag(id).orElseThrow() + * .setFooter(event.getUser() + " - used /tag foo") .setColor(TagSystem.AMBIENT_COLOR) + * ).queue(); + */ public void displayStatus(@NotNull TextChannel channel) { final Guild guild = channel.getGuild(); + /* + * MessageUtils.generateEmbed(STATUS_TITLE, messageTxt, channel.getJDA().getSelfUser(), + * MESSAGE_HIGHLIGHT_COLOR, null) + */ + String messageTxt = buildStatusMessage(guild); - MessageEmbed embed = MessageUtils.generateEmbed(STATUS_TITLE, messageTxt, - channel.getJDA().getSelfUser(), MESSAGE_HIGHLIGHT_COLOR, null); + MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE) + .setDescription(messageTxt) + .setAuthor(String.valueOf(channel.getJDA().getSelfUser())) + .setTimestamp(Instant.now()) + .setColor(MESSAGE_HIGHLIGHT_COLOR) + .build(); getStatusMessageIn(channel).flatMap(this::deleteIfNotLatest) .ifPresentOrElse(message -> message.editMessageEmbeds(embed).queue(), diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index 17194013af..aa1cce6d6b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -1,14 +1,13 @@ package org.togetherjava.tjbot.commands.tags; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -import org.togetherjava.tjbot.commands.utils.MessageUtils; +import java.time.Instant; import java.util.Objects; /** @@ -44,12 +43,22 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (tagSystem.handleIsUnknownTag(id, event)) { return; } - - event.replyEmbeds(tagEmbed(id, event.getUser(), event.getCommandString())).queue(); +/* +event.replyEmbeds(tagEmbed(id, event.getUser(), event.getCommandString())).queue(); } private MessageEmbed tagEmbed(String id, User user, String commandString) { return MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), user, TagSystem.AMBIENT_COLOR, user.getName() + " " + commandString); } + */ + + event + .replyEmbeds(new EmbedBuilder().setDescription(tagSystem.getTag(id).orElseThrow()) + .setFooter(event.getUser().getName() + " - used /tag foo") + .setTimestamp(Instant.now()) + .setColor(TagSystem.AMBIENT_COLOR) + .build()) + .queue(); + } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index 6c7829aa0e..13ee1cc15c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -1,5 +1,6 @@ package org.togetherjava.tjbot.commands.tags; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.Role; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -17,6 +18,7 @@ import org.togetherjava.tjbot.commands.utils.MessageUtils; import org.togetherjava.tjbot.config.Config; +import java.time.Instant; import java.util.Objects; import java.util.OptionalLong; import java.util.function.BiConsumer; @@ -90,10 +92,18 @@ public TagManageCommand(TagSystem tagSystem) { private static void sendSuccessMessage(@NotNull Interaction event, @NotNull String id, @NotNull String actionVerb) { logger.info("User '{}' {} the tag with id '{}'.", event.getUser().getId(), actionVerb, id); + /* + * MessageUtils.generateEmbed("Success", "Successfully %s tag '%s'.".formatted(actionVerb, + * id), event.getUser(), TagSystem.AMBIENT_COLOR, null) + */ + event - .replyEmbeds(MessageUtils.generateEmbed("Success", - "Successfully %s tag '%s'.".formatted(actionVerb, id), event.getUser(), - TagSystem.AMBIENT_COLOR, null)) + .replyEmbeds(new EmbedBuilder().setTitle("Success") + .setDescription("Successfully %s tag '%s'.".formatted(actionVerb, id)) + .setAuthor(String.valueOf(event.getUser())) + .setTimestamp(Instant.now()) + .setColor(TagSystem.AMBIENT_COLOR) + .build()) .queue(); } @@ -147,10 +157,17 @@ private void rawTag(@NotNull SlashCommandEvent event) { if (tagSystem.handleIsUnknownTag(id, event)) { return; } - - event.replyEmbeds(MessageUtils.generateEmbed(null, - MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow()), event.getUser(), - TagSystem.AMBIENT_COLOR, null)) + /* + * MessageUtils.generateEmbed(null, + * MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow()), event.getUser(), + * TagSystem.AMBIENT_COLOR, null) + */ + event + .replyEmbeds(new EmbedBuilder() + .setDescription(MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow())) + .setAuthor(String.valueOf(event.getUser())) + .setColor(TagSystem.AMBIENT_COLOR) + .build()) .queue(); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java index 43db3fa086..c50b9a1011 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java @@ -1,13 +1,14 @@ package org.togetherjava.tjbot.commands.tags; +import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.events.interaction.ButtonClickEvent; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -import org.togetherjava.tjbot.commands.utils.MessageUtils; +import java.time.Instant; import java.util.List; import java.util.Objects; @@ -42,10 +43,18 @@ public TagsCommand(TagSystem tagSystem) { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // TODO A list might be better than comma separated, which is hard to read + /* + * MessageUtils.generateEmbed("All available tags", String.join(", ", + * tagSystem.getAllIds()), event.getUser(), TagSystem.AMBIENT_COLOR, null) + */ + event - .replyEmbeds(MessageUtils.generateEmbed("All available tags", - String.join(", ", tagSystem.getAllIds()), event.getUser(), - TagSystem.AMBIENT_COLOR, null)) + .replyEmbeds(new EmbedBuilder().setTitle("All available tags") + .setDescription(String.join(", ", tagSystem.getAllIds())) + .setFooter(event.getUser().getName() + " - used /tag foo") + .setTimestamp(Instant.now()) + .setColor(TagSystem.AMBIENT_COLOR) + .build()) .addActionRow( TagSystem.createDeleteButton(generateComponentId(event.getUser().getId()))) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java index 8056be993a..70895df89a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/utils/MessageUtils.java @@ -1,17 +1,11 @@ package org.togetherjava.tjbot.commands.utils; -import net.dv8tion.jda.api.EmbedBuilder; import net.dv8tion.jda.api.entities.Message; -import net.dv8tion.jda.api.entities.MessageEmbed; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.interactions.components.ActionRow; import net.dv8tion.jda.api.interactions.components.Button; import net.dv8tion.jda.api.utils.MarkdownSanitizer; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import java.awt.*; -import java.time.Instant; import java.util.List; /** @@ -43,26 +37,6 @@ public static void disableButtons(@NotNull Message message) { .queue(); } - /** - * Generates an embed with the given content. - * - * @param title title of the embed or {@code null} if not desired - * @param content content to display in the embed - * @param user name of the user who requested the embed or {@code null} if no user requested - * this - * @param ambientColor the ambient color of the embed or {@code null} for a default color - * @return the generated embed - */ - public static @NotNull MessageEmbed generateEmbed(@Nullable String title, - @NotNull CharSequence content, @Nullable User user, @Nullable Color ambientColor, - @Nullable String footer) { - return new EmbedBuilder().setTitle(title) - .setDescription(content) - .setTimestamp(Instant.now()) - .setFooter(user == null ? null : user.getName() + " " + footer) - .setColor(ambientColor) - .build(); - } /** * Escapes every markdown content in the given string. From 3ee5423dae9c26d46864603cf92c2e742a36f7b1 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 10:00:28 +0100 Subject: [PATCH 04/10] Another comment of previous generate embed class --- .../tjbot/commands/tags/TagCommand.java | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index aa1cce6d6b..22b9151b7d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -43,15 +43,13 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (tagSystem.handleIsUnknownTag(id, event)) { return; } -/* -event.replyEmbeds(tagEmbed(id, event.getUser(), event.getCommandString())).queue(); - } - - private MessageEmbed tagEmbed(String id, User user, String commandString) { - return MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), user, - TagSystem.AMBIENT_COLOR, user.getName() + " " + commandString); - } - */ + /* + * event.replyEmbeds(tagEmbed(id, event.getUser(), event.getCommandString())).queue(); } + * + * private MessageEmbed tagEmbed(String id, User user, String commandString) { return + * MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), user, + * TagSystem.AMBIENT_COLOR, user.getName() + " " + commandString); } + */ event .replyEmbeds(new EmbedBuilder().setDescription(tagSystem.getTag(id).orElseThrow()) From 463d53d41437c806787073101d78c4c5baa06fc4 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 17:13:30 +0100 Subject: [PATCH 05/10] Removed the redundant comments, the setAuthor method and added the timestamp --- .../tjbot/commands/free/FreeCommand.java | 6 ------ .../tjbot/commands/tags/TagCommand.java | 9 +-------- .../tjbot/commands/tags/TagManageCommand.java | 13 ++----------- .../tjbot/commands/tags/TagsCommand.java | 6 +----- 4 files changed, 4 insertions(+), 30 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index fb32c9d699..0f685396c9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -207,15 +207,9 @@ private boolean handleShouldBeProcessed(@NotNull final SlashCommandEvent event) public void displayStatus(@NotNull TextChannel channel) { final Guild guild = channel.getGuild(); - /* - * MessageUtils.generateEmbed(STATUS_TITLE, messageTxt, channel.getJDA().getSelfUser(), - * MESSAGE_HIGHLIGHT_COLOR, null) - */ - String messageTxt = buildStatusMessage(guild); MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE) .setDescription(messageTxt) - .setAuthor(String.valueOf(channel.getJDA().getSelfUser())) .setTimestamp(Instant.now()) .setColor(MESSAGE_HIGHLIGHT_COLOR) .build(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index 22b9151b7d..16993ac70c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -43,17 +43,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (tagSystem.handleIsUnknownTag(id, event)) { return; } - /* - * event.replyEmbeds(tagEmbed(id, event.getUser(), event.getCommandString())).queue(); } - * - * private MessageEmbed tagEmbed(String id, User user, String commandString) { return - * MessageUtils.generateEmbed(null, tagSystem.getTag(id).orElseThrow(), user, - * TagSystem.AMBIENT_COLOR, user.getName() + " " + commandString); } - */ event .replyEmbeds(new EmbedBuilder().setDescription(tagSystem.getTag(id).orElseThrow()) - .setFooter(event.getUser().getName() + " - used /tag foo") + .setFooter(event.getUser().getName() + " • used " + event.getCommandString()) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index 13ee1cc15c..9b24db59d0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -92,15 +92,10 @@ public TagManageCommand(TagSystem tagSystem) { private static void sendSuccessMessage(@NotNull Interaction event, @NotNull String id, @NotNull String actionVerb) { logger.info("User '{}' {} the tag with id '{}'.", event.getUser().getId(), actionVerb, id); - /* - * MessageUtils.generateEmbed("Success", "Successfully %s tag '%s'.".formatted(actionVerb, - * id), event.getUser(), TagSystem.AMBIENT_COLOR, null) - */ event .replyEmbeds(new EmbedBuilder().setTitle("Success") .setDescription("Successfully %s tag '%s'.".formatted(actionVerb, id)) - .setAuthor(String.valueOf(event.getUser())) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) @@ -157,15 +152,11 @@ private void rawTag(@NotNull SlashCommandEvent event) { if (tagSystem.handleIsUnknownTag(id, event)) { return; } - /* - * MessageUtils.generateEmbed(null, - * MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow()), event.getUser(), - * TagSystem.AMBIENT_COLOR, null) - */ + event .replyEmbeds(new EmbedBuilder() .setDescription(MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow())) - .setAuthor(String.valueOf(event.getUser())) + .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java index c50b9a1011..8cb0825f88 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java @@ -43,15 +43,11 @@ public TagsCommand(TagSystem tagSystem) { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // TODO A list might be better than comma separated, which is hard to read - /* - * MessageUtils.generateEmbed("All available tags", String.join(", ", - * tagSystem.getAllIds()), event.getUser(), TagSystem.AMBIENT_COLOR, null) - */ event .replyEmbeds(new EmbedBuilder().setTitle("All available tags") .setDescription(String.join(", ", tagSystem.getAllIds())) - .setFooter(event.getUser().getName() + " - used /tag foo") + .setFooter(event.getUser().getName() + " • used " + event.getCommandString()) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) From c09b4ca4ced8c73f22e88e06de02a40925194e18 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 18:34:10 +0100 Subject: [PATCH 06/10] Removed the additional comment, reverted back to an old call and changed its implementation --- .../org/togetherjava/tjbot/commands/free/FreeCommand.java | 6 +----- .../togetherjava/tjbot/commands/tags/TagManageCommand.java | 1 + 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index 0f685396c9..6775ac692a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -199,17 +199,13 @@ private boolean handleShouldBeProcessed(@NotNull final SlashCommandEvent event) * @param channel the text channel the status message will be posted in. */ - /* - * event.replyEmbeds(new EmbedBuilder() .setDescription(tagSystem.getTag(id).orElseThrow() - * .setFooter(event.getUser() + " - used /tag foo") .setColor(TagSystem.AMBIENT_COLOR) - * ).queue(); - */ public void displayStatus(@NotNull TextChannel channel) { final Guild guild = channel.getGuild(); String messageTxt = buildStatusMessage(guild); MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE) .setDescription(messageTxt) + .setFooter(channel.getJDA().getSelfUser().toString()) .setTimestamp(Instant.now()) .setColor(MESSAGE_HIGHLIGHT_COLOR) .build(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index 9b24db59d0..db7b80dddf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -156,6 +156,7 @@ private void rawTag(@NotNull SlashCommandEvent event) { event .replyEmbeds(new EmbedBuilder() .setDescription(MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow())) + .setFooter(event.getUser().toString()) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) From e512ffa53ee7f0f105988982fe3d76daea171790 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 20:14:10 +0100 Subject: [PATCH 07/10] Removing, the usertoString and replacing it with user.getName --- .../java/org/togetherjava/tjbot/commands/free/FreeCommand.java | 2 +- .../org/togetherjava/tjbot/commands/tags/TagManageCommand.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index 6775ac692a..fd1b54caab 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -205,7 +205,7 @@ public void displayStatus(@NotNull TextChannel channel) { String messageTxt = buildStatusMessage(guild); MessageEmbed embed = new EmbedBuilder().setTitle(STATUS_TITLE) .setDescription(messageTxt) - .setFooter(channel.getJDA().getSelfUser().toString()) + .setFooter(channel.getJDA().getSelfUser().getName()) .setTimestamp(Instant.now()) .setColor(MESSAGE_HIGHLIGHT_COLOR) .build(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index db7b80dddf..52268df69c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -96,6 +96,7 @@ private static void sendSuccessMessage(@NotNull Interaction event, @NotNull Stri event .replyEmbeds(new EmbedBuilder().setTitle("Success") .setDescription("Successfully %s tag '%s'.".formatted(actionVerb, id)) + .setFooter(event.getUser().getName()) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) @@ -156,7 +157,7 @@ private void rawTag(@NotNull SlashCommandEvent event) { event .replyEmbeds(new EmbedBuilder() .setDescription(MessageUtils.escapeMarkdown(tagSystem.getTag(id).orElseThrow())) - .setFooter(event.getUser().toString()) + .setFooter(event.getUser().getName()) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) From 2d2c980f2c5b01a71863a9896e81369f80634812 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 20:15:15 +0100 Subject: [PATCH 08/10] Removing the empty line --- .../java/org/togetherjava/tjbot/commands/free/FreeCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java index fd1b54caab..aa1a353a95 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/free/FreeCommand.java @@ -198,7 +198,6 @@ private boolean handleShouldBeProcessed(@NotNull final SlashCommandEvent event) * * @param channel the text channel the status message will be posted in. */ - public void displayStatus(@NotNull TextChannel channel) { final Guild guild = channel.getGuild(); From 63815945bdd11508877152bbe007511422d30900 Mon Sep 17 00:00:00 2001 From: IslamSakrak Date: Fri, 10 Dec 2021 20:20:33 +0100 Subject: [PATCH 09/10] Applied spotless --- .../org/togetherjava/tjbot/commands/tags/TagManageCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index 52268df69c..0114c4d44f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -96,7 +96,7 @@ private static void sendSuccessMessage(@NotNull Interaction event, @NotNull Stri event .replyEmbeds(new EmbedBuilder().setTitle("Success") .setDescription("Successfully %s tag '%s'.".formatted(actionVerb, id)) - .setFooter(event.getUser().getName()) + .setFooter(event.getUser().getName()) .setTimestamp(Instant.now()) .setColor(TagSystem.AMBIENT_COLOR) .build()) From abde994dfdfec21b8191d700a33a4c1b125255b2 Mon Sep 17 00:00:00 2001 From: Islam Date: Mon, 20 Dec 2021 09:52:18 +0100 Subject: [PATCH 10/10] Removed the Todo comment --- .../java/org/togetherjava/tjbot/commands/tags/TagsCommand.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java index 8cb0825f88..18b769c8c0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java @@ -42,8 +42,6 @@ public TagsCommand(TagSystem tagSystem) { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - // TODO A list might be better than comma separated, which is hard to read - event .replyEmbeds(new EmbedBuilder().setTitle("All available tags") .setDescription(String.join(", ", tagSystem.getAllIds())) @@ -68,7 +66,6 @@ public void onButtonClick(@NotNull ButtonClickEvent event, @NotNull List .queue(); return; } - event.getMessage().delete().queue(); } }