fix fields
All checks were successful
PR Check / lint-and-format (pull_request) Successful in 21s

This commit is contained in:
Mylloon 2024-10-14 22:10:26 +02:00
parent 93548c0069
commit ddcf488be5
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -119,24 +119,29 @@ export default async (message: Message, client: Client) => {
// but we can't do much about it // but we can't do much about it
const maxFieldValueLength = 1024; const maxFieldValueLength = 1024;
const files = quoted_post.attachments const files = quoted_post.attachments
.map((file) => `[${file.name}](${file.url}`) .map((file) => `[${file.name}](${file.url})`)
.filter((link) => link.length <= maxFieldValueLength); .filter((link) => link.length <= maxFieldValueLength);
let currentField = ""; let currentField = "";
const fields: APIEmbedField[] = []; const fields: APIEmbedField[] = [];
let multiple = 0;
files.forEach((file, idx) => { files.forEach((file, idx) => {
const potentialField = `${currentField}, ${file}`; const fieldValue = currentField.length > 0 ? `${currentField}, ${file}` : file;
if (potentialField.length > maxFieldValueLength || idx === files.length - 1) { if (fieldValue.length > maxFieldValueLength || idx === files.length - 1) {
multiple = multiple === 0 && idx !== files.length - 1 ? 1 : multiple + 1;
fields.push({ fields.push({
name: loc.get( name:
quoted_post.attachments.size > 1 ? "e_attachements" : "e_attachement", loc.get(
), quoted_post.attachments.size > 1 && idx !== files.length - 1
? "e_attachements"
: "e_attachement",
) + (multiple ? ` (${multiple})` : ""),
value: currentField, value: currentField,
}); });
currentField = file; currentField = file;
} else { } else {
currentField = potentialField; currentField = fieldValue;
} }
}); });