1 | static int discordEmbed_addField_maxLength = 800; |
2 | |
3 | svoid discordEmbed_addField(EmbedBuilder eb, S field, S text) { |
4 | int n = 1; |
5 | while ping (l(text) > discordEmbed_addField_maxLength) { |
6 | LS lines = lines(text); |
7 | new StringBuilder buf; |
8 | int i = 0; |
9 | while (i < l(lines) && l(buf)+l(lines.get(i))+1 <= discordEmbed_addField_maxLength) |
10 | buf.append(lines.get(i++)).append("\n"); |
11 | S part = str(buf); |
12 | if (i == 0) { |
13 | // first line too long for max length, cut off |
14 | part = takeFirst(text, discordEmbed_addField_maxLength); |
15 | text = substring(text, discordEmbed_addField_maxLength); |
16 | } else |
17 | text = lines(subList(lines, i)); |
18 | eb.addField(appendNumberUnless1(field, n++), part, false); |
19 | } |
20 | if (!emptyAfterTrim(text)) |
21 | eb.addField(appendNumberUnless1(field, n), text, false); |
22 | } |
download show line numbers debug dex old transpilations
Travelled to 6 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt
No comments. add comment
Snippet ID: | #1026251 |
Snippet name: | discordEmbed_addField - with splitting if >1k |
Eternal ID of this version: | #1026251/3 |
Text MD5: | 291968e978433c75050b12c31e8ae32d |
Author: | stefan |
Category: | javax / discord |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-12-08 23:34:45 |
Source code size: | 843 bytes / 22 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 262 / 282 |
Version history: | 2 change(s) |
Referenced in: | [show references] |