Skip to content

Commit

Permalink
Merge pull request #509 from danthe1st/message-links
Browse files Browse the repository at this point in the history
split message attachments in embed fields
  • Loading branch information
danthe1st authored Jan 14, 2025
2 parents e4869d1 + 1822ff3 commit 9f85534
Showing 1 changed file with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -206,15 +206,24 @@ private MessageEmbed buildMessageDeleteEmbed(Guild guild, User author, MessageCh
message.getMessageContent().length(),
MessageEmbed.VALUE_MAX_LENGTH)), false);
if (!message.getAttachments().isEmpty()) {
eb.addField("Attachments",
message
.getAttachments()
.stream()
.collect(Collectors.joining("\n")),
false);
addAttachmentsToMessageBuilder(message, eb);
}
return eb
.build();
return eb.build();
}

private void addAttachmentsToMessageBuilder(CachedMessage message, EmbedBuilder eb) {
StringBuilder attachmentBuilder = new StringBuilder();
for (String attachment : message.getAttachments()) {
if (attachmentBuilder.length() + attachment.length() >= MessageEmbed.VALUE_MAX_LENGTH - 1) {
eb.addField("Attachments", attachmentBuilder.toString(),false);
attachmentBuilder.setLength(0);

} else {
attachmentBuilder.append('\n');
}
attachmentBuilder.append(attachment);
}
eb.addField("Attachments", attachmentBuilder.toString(), false);
}

private InputStream buildDeletedMessageFile(User author, CachedMessage message) {
Expand Down

0 comments on commit 9f85534

Please sign in to comment.