mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-14 19:56:29 +00:00
[AB-xxx] adding feature to split field value by configurable amount
using larger images for member avatar
This commit is contained in:
@@ -249,6 +249,7 @@ public class RemindServiceBeanTest {
|
|||||||
when(guild.getIdLong()).thenReturn(8L);
|
when(guild.getIdLong()).thenReturn(8L);
|
||||||
when(remindedMember.getIdLong()).thenReturn(9L);
|
when(remindedMember.getIdLong()).thenReturn(9L);
|
||||||
when(remindedMember.getUser()).thenReturn(jdaUser);
|
when(remindedMember.getUser()).thenReturn(jdaUser);
|
||||||
|
when(remindedMember.getEffectiveAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
|
||||||
when(jdaUser.getDefaultAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
|
when(jdaUser.getDefaultAvatar()).thenReturn(Mockito.mock(ImageProxy.class));
|
||||||
Reminder remindedReminder = Mockito.mock(Reminder.class);
|
Reminder remindedReminder = Mockito.mock(Reminder.class);
|
||||||
when(remindedReminder.getTargetDate()).thenReturn(Instant.now());
|
when(remindedReminder.getTargetDate()).thenReturn(Instant.now());
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ public class EmbedField {
|
|||||||
*/
|
*/
|
||||||
private Boolean inline;
|
private Boolean inline;
|
||||||
private Boolean forceNewEmbed;
|
private Boolean forceNewEmbed;
|
||||||
|
private Integer valueSplitLength;
|
||||||
/**
|
/**
|
||||||
* this will actively limit the length, not create another field
|
* this will actively limit the length, not create another field
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -392,10 +392,11 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
});
|
});
|
||||||
for (int i = 0; i < configuration.getFields().size(); i++) {
|
for (int i = 0; i < configuration.getFields().size(); i++) {
|
||||||
EmbedField field = configuration.getFields().get(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 segmentCounter = 0;
|
||||||
int segmentStart = 0;
|
int segmentStart = 0;
|
||||||
int segmentEnd = MessageEmbed.VALUE_MAX_LENGTH;
|
int segmentEnd = maxSplitLength;
|
||||||
int handledIndex = 0;
|
int handledIndex = 0;
|
||||||
String fullFieldValue = field.getValue();
|
String fullFieldValue = field.getValue();
|
||||||
while(handledIndex < fullFieldValue.length()) {
|
while(handledIndex < fullFieldValue.length()) {
|
||||||
@@ -403,7 +404,7 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
// start has a value, so some things are cut off
|
// start has a value, so some things are cut off
|
||||||
int segmentLength = fullFieldValue.length() - segmentStart;
|
int segmentLength = fullFieldValue.length() - segmentStart;
|
||||||
// if its over the hard limit for a field
|
// 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"
|
// find the last space in the text, as a natural "splitting point"
|
||||||
int lastSpace = fullFieldValue.substring(segmentStart, segmentEnd).lastIndexOf(" ");
|
int lastSpace = fullFieldValue.substring(segmentStart, segmentEnd).lastIndexOf(" ");
|
||||||
if(lastSpace != -1) {
|
if(lastSpace != -1) {
|
||||||
@@ -431,7 +432,7 @@ public class TemplateServiceBean implements TemplateService {
|
|||||||
segmentCounter++;
|
segmentCounter++;
|
||||||
handledIndex = segmentEnd;
|
handledIndex = segmentEnd;
|
||||||
segmentStart = segmentEnd;
|
segmentStart = segmentEnd;
|
||||||
segmentEnd += MessageEmbed.VALUE_MAX_LENGTH;
|
segmentEnd += maxSplitLength;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ public class MemberNameDisplay {
|
|||||||
String userAvatar = user.getAvatarUrl() != null ? user.getAvatarUrl() : user.getDefaultAvatar().getUrl(4096);
|
String userAvatar = user.getAvatarUrl() != null ? user.getAvatarUrl() : user.getDefaultAvatar().getUrl(4096);
|
||||||
return MemberNameDisplay
|
return MemberNameDisplay
|
||||||
.builder()
|
.builder()
|
||||||
.memberAvatarUrl(member.getAvatarUrl())
|
.memberAvatarUrl(member.getEffectiveAvatar().getUrl(4096))
|
||||||
.nickname(member.getNickname())
|
.nickname(member.getNickname())
|
||||||
.userName(user.getName())
|
.userName(user.getName())
|
||||||
.memberMention(member.getAsMention())
|
.memberMention(member.getAsMention())
|
||||||
|
|||||||
Reference in New Issue
Block a user