mirror of
https://github.com/DiscordSRV/Ascension.git
synced 2024-12-28 17:37:52 +01:00
Chop embed parts to fit
This commit is contained in:
parent
a84eef853c
commit
fd249b4e03
@ -32,6 +32,7 @@ import com.discordsrv.api.placeholder.FormattedText;
|
|||||||
import com.discordsrv.api.placeholder.PlaceholderService;
|
import com.discordsrv.api.placeholder.PlaceholderService;
|
||||||
import com.discordsrv.api.placeholder.mapper.ResultMappers;
|
import com.discordsrv.api.placeholder.mapper.ResultMappers;
|
||||||
import com.discordsrv.api.placeholder.util.Placeholders;
|
import com.discordsrv.api.placeholder.util.Placeholders;
|
||||||
|
import net.dv8tion.jda.api.entities.MessageEmbed;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -278,47 +279,57 @@ public class SendableDiscordMessageImpl implements SendableDiscordMessage {
|
|||||||
// TODO: check which parts allow formatting more thoroughly
|
// TODO: check which parts allow formatting more thoroughly
|
||||||
ResultMappers.runInPlainContext(() -> {
|
ResultMappers.runInPlainContext(() -> {
|
||||||
embedBuilder.setAuthor(
|
embedBuilder.setAuthor(
|
||||||
placeholders.apply(
|
cutToLength(
|
||||||
embedBuilder.getAuthorName()),
|
placeholders.apply(embedBuilder.getAuthorName()),
|
||||||
placeholders.apply(
|
MessageEmbed.AUTHOR_MAX_LENGTH
|
||||||
embedBuilder.getAuthorUrl()),
|
),
|
||||||
placeholders.apply(
|
placeholders.apply(embedBuilder.getAuthorUrl()),
|
||||||
embedBuilder.getAuthorImageUrl()));
|
placeholders.apply(embedBuilder.getAuthorImageUrl()));
|
||||||
|
|
||||||
embedBuilder.setTitle(
|
embedBuilder.setTitle(
|
||||||
placeholders.apply(
|
cutToLength(
|
||||||
embedBuilder.getTitle()),
|
placeholders.apply(embedBuilder.getTitle()),
|
||||||
placeholders.apply(
|
MessageEmbed.TITLE_MAX_LENGTH
|
||||||
embedBuilder.getTitleUrl()));
|
),
|
||||||
|
placeholders.apply(embedBuilder.getTitleUrl())
|
||||||
|
);
|
||||||
|
|
||||||
embedBuilder.setThumbnailUrl(
|
embedBuilder.setThumbnailUrl(
|
||||||
placeholders.apply(
|
placeholders.apply(embedBuilder.getThumbnailUrl())
|
||||||
embedBuilder.getThumbnailUrl()));
|
);
|
||||||
|
|
||||||
embedBuilder.setImageUrl(
|
embedBuilder.setImageUrl(
|
||||||
placeholders.apply(
|
placeholders.apply(embedBuilder.getImageUrl())
|
||||||
embedBuilder.getImageUrl()));
|
);
|
||||||
|
|
||||||
embedBuilder.setFooter(
|
embedBuilder.setFooter(
|
||||||
placeholders.apply(
|
cutToLength(
|
||||||
embedBuilder.getFooter()),
|
placeholders.apply(embedBuilder.getFooter()),
|
||||||
placeholders.apply(
|
MessageEmbed.TEXT_MAX_LENGTH
|
||||||
embedBuilder.getFooterImageUrl()));
|
),
|
||||||
|
placeholders.apply(embedBuilder.getFooterImageUrl())
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
embedBuilder.setDescription(
|
embedBuilder.setDescription(
|
||||||
placeholders.apply(
|
cutToLength(
|
||||||
embedBuilder.getDescription())
|
placeholders.apply(embedBuilder.getDescription()),
|
||||||
|
MessageEmbed.DESCRIPTION_MAX_LENGTH
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
List<DiscordMessageEmbed.Field> fields = new ArrayList<>(embedBuilder.getFields());
|
List<DiscordMessageEmbed.Field> fields = new ArrayList<>(embedBuilder.getFields());
|
||||||
embedBuilder.getFields().clear();
|
embedBuilder.getFields().clear();
|
||||||
|
|
||||||
fields.forEach(field -> embedBuilder.addField(
|
fields.forEach(field -> embedBuilder.addField(
|
||||||
placeholders.apply(
|
cutToLength(
|
||||||
field.getTitle()),
|
placeholders.apply(field.getTitle()),
|
||||||
placeholders.apply(
|
MessageEmbed.TITLE_MAX_LENGTH
|
||||||
field.getValue()),
|
),
|
||||||
|
cutToLength(
|
||||||
|
placeholders.apply(field.getValue()),
|
||||||
|
MessageEmbed.VALUE_MAX_LENGTH
|
||||||
|
),
|
||||||
field.isInline()
|
field.isInline()
|
||||||
));
|
));
|
||||||
|
|
||||||
@ -332,5 +343,15 @@ public class SendableDiscordMessageImpl implements SendableDiscordMessage {
|
|||||||
|
|
||||||
return builder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String cutToLength(String input, int maxLength) {
|
||||||
|
if (input == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (input.length() > maxLength) {
|
||||||
|
return input.substring(0, maxLength);
|
||||||
|
}
|
||||||
|
return input;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user