|
24 | 24 | import vc.util.PlayerLookup; |
25 | 25 |
|
26 | 26 | import java.time.LocalDate; |
27 | | -import java.util.List; |
| 27 | +import java.util.concurrent.atomic.AtomicBoolean; |
28 | 28 |
|
29 | 29 | import static discord4j.common.util.TimestampFormat.SHORT_DATE_TIME; |
30 | 30 | import static org.slf4j.LoggerFactory.getLogger; |
@@ -74,32 +74,28 @@ private Mono<Message> resolveConnections(final DeferrableInteractionEvent event, |
74 | 74 | } |
75 | 75 | } |
76 | 76 | if (connectionsResponse == null || connectionsResponse.getConnections() == null || connectionsResponse.getConnections().isEmpty()) |
77 | | - return error(event, "No connections found for player"); |
78 | | - List<String> connectionStrings = connectionsResponse.getConnections().stream() |
79 | | - .map(c -> c.getConnection().getValue() + " " + SHORT_DATE_TIME.format(c.getTime().toInstant())) |
80 | | - .toList(); |
81 | | - StringBuilder result = new StringBuilder(); |
82 | | - for (String s : connectionStrings) { |
83 | | - if (result.length() + s.length() > 4090) { |
84 | | - LOGGER.warn("Message too long, truncating: {}", s); |
85 | | - break; |
86 | | - } |
87 | | - result.append(s).append("\n"); |
88 | | - } |
89 | | - if (result.length() > 0) { |
90 | | - result = new StringBuilder(result.substring(0, result.length() - 1)); |
91 | | - } else { |
92 | 77 | return event.createFollowup() |
93 | 78 | .withEmbeds(populateIdentity(EmbedCreateSpec.builder(), identity) |
94 | | - .title("Connections") |
95 | | - .color(Color.CYAN) |
| 79 | + .color(Color.RUBY) |
96 | 80 | .description("No connections found") |
97 | 81 | .thumbnail(identity.getAvatarURL()) |
98 | 82 | .build()); |
99 | | - } |
| 83 | + |
| 84 | + final StringBuilder result = new StringBuilder(); |
| 85 | + final AtomicBoolean truncated = new AtomicBoolean(false); |
| 86 | + connectionsResponse.getConnections().stream() |
| 87 | + .map(c -> c.getConnection().getValue() + " " + SHORT_DATE_TIME.format(c.getTime().toInstant())) |
| 88 | + .forEachOrdered(s -> { |
| 89 | + if (result.length() + s.length() + 1 > 4090) { |
| 90 | + truncated.set(true); |
| 91 | + return; |
| 92 | + } |
| 93 | + result.append(s).append("\n"); |
| 94 | + }); |
| 95 | + if (!result.isEmpty()) result.deleteCharAt(result.length() - 1); // cut off the last newline |
| 96 | + if (truncated.get()) LOGGER.warn("Truncated connections response"); |
100 | 97 | return event.createFollowup() |
101 | 98 | .withEmbeds(populateIdentity(EmbedCreateSpec.builder(), identity) |
102 | | - .title("Connections") |
103 | 99 | .color(Color.CYAN) |
104 | 100 | .description(result.toString()) |
105 | 101 | .addField("Total", ""+connectionsResponse.getTotal(), true) |
|
0 commit comments