[AB-xxx] adding feature to split field value by configurable amount

using larger images for member avatar
This commit is contained in:
Sheldan
2023-03-05 13:49:32 +01:00
parent a984bdb84e
commit 735816f5dd
4 changed files with 8 additions and 5 deletions

View File

@@ -249,6 +249,7 @@ public class RemindServiceBeanTest {
when(guild.getIdLong()).thenReturn(8L);
when(remindedMember.getIdLong()).thenReturn(9L);
when(remindedMember.getUser()).thenReturn(jdaUser);
when(remindedMember.getEffectiveAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
when(jdaUser.getDefaultAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
Reminder remindedReminder = Mockito.mock(Reminder.class);
when(remindedReminder.getTargetDate()).thenReturn(Instant.now());

View File

@@ -25,6 +25,7 @@ public class EmbedField {
*/
private Boolean inline;
private Boolean forceNewEmbed;
private Integer valueSplitLength;
/**
* this will actively limit the length, not create another field
*/

View File

@@ -392,10 +392,11 @@ public class TemplateServiceBean implements TemplateService {
});
for (int i = 0; i < configuration.getFields().size(); i++) {
EmbedField field = configuration.getFields().get(i);
if (field != null && field.getValue() != null && field.getValue().length() > MessageEmbed.VALUE_MAX_LENGTH) {
int maxSplitLength = field != null && field.getValueSplitLength() != null ? Math.min(field.getValueSplitLength(), MessageEmbed.VALUE_MAX_LENGTH) : MessageEmbed.VALUE_MAX_LENGTH;
if (field != null && field.getValue() != null && field.getValue().length() > maxSplitLength) {
int segmentCounter = 0;
int segmentStart = 0;
int segmentEnd = MessageEmbed.VALUE_MAX_LENGTH;
int segmentEnd = maxSplitLength;
int handledIndex = 0;
String fullFieldValue = field.getValue();
while(handledIndex < fullFieldValue.length()) {
@@ -403,7 +404,7 @@ public class TemplateServiceBean implements TemplateService {
// start has a value, so some things are cut off
int segmentLength = fullFieldValue.length() - segmentStart;
// if its over the hard limit for a field
if(segmentLength > MessageEmbed.VALUE_MAX_LENGTH) {
if(segmentLength > maxSplitLength) {
// find the last space in the text, as a natural "splitting point"
int lastSpace = fullFieldValue.substring(segmentStart, segmentEnd).lastIndexOf(" ");
if(lastSpace != -1) {
@@ -431,7 +432,7 @@ public class TemplateServiceBean implements TemplateService {
segmentCounter++;
handledIndex = segmentEnd;
segmentStart = segmentEnd;
segmentEnd += MessageEmbed.VALUE_MAX_LENGTH;
segmentEnd += maxSplitLength;
}
}
}

View File

@@ -22,7 +22,7 @@ public class MemberNameDisplay {
String userAvatar = user.getAvatarUrl() != null ? user.getAvatarUrl() : user.getDefaultAvatar().getUrl(4096);
return MemberNameDisplay
.builder()
.memberAvatarUrl(member.getAvatarUrl())
.memberAvatarUrl(member.getEffectiveAvatar().getUrl(4096))
.nickname(member.getNickname())
.userName(user.getName())
.memberMention(member.getAsMention())