Skip to content

Commit a21f294

Browse files
committed
Embed only when !content.isEmpty()
Conditionally add the embed only if the original message content is NOT empty
1 parent 2742573 commit a21f294

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/features/mediaonly/MediaOnlyChannelListener.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,21 @@ private boolean messageHasNoMediaAttached(Message message) {
102102

103103
private MessageCreateData createNotificationMessage(Message message) {
104104
String originalMessageContent = message.getContentRaw();
105-
if (originalMessageContent.trim().isEmpty()) {
106-
originalMessageContent = "Original message had no visible text content";
107-
}
108105

109-
MessageEmbed originalMessageEmbed =
110-
new EmbedBuilder().setDescription(originalMessageContent)
111-
.setColor(Color.ORANGE)
112-
.build();
106+
MessageCreateBuilder messageBuilder = new MessageCreateBuilder();
107+
messageBuilder.setContent(message.getAuthor().getAsMention()
108+
+ " Hey there, you posted a message without media (image, video, link) in a media-only channel. Please see the description of the channel for details and then repost with media attached, thanks 😀");
109+
110+
// Conditionally add the embed only if the original message content is NOT empty
111+
if (!originalMessageContent.trim().isEmpty()) {
112+
MessageEmbed originalMessageEmbed =
113+
new EmbedBuilder().setDescription(originalMessageContent)
114+
.setColor(Color.ORANGE)
115+
.build();
116+
messageBuilder.setEmbeds(originalMessageEmbed);
117+
}
113118

114-
return new MessageCreateBuilder().setContent(message.getAuthor().getAsMention()
115-
+ " Hey there, you posted a message without media (image, video, link) in a media-only channel. Please see the description of the channel for details and then repost with media attached, thanks 😀")
116-
.setEmbeds(originalMessageEmbed)
117-
.build();
119+
return messageBuilder.build();
118120
}
119121

120122
private RestAction<Message> dmUser(Message message) {

0 commit comments

Comments
 (0)