Compare commits
No commits in common. "93548c00690fee1bf0e5d516da7e0b52bca896a7" and "937627b8796c6621067156f678d30f13384ac3de" have entirely different histories.
93548c0069
...
937627b879
2 changed files with 13 additions and 32 deletions
|
@ -1,4 +1,4 @@
|
|||
import { APIEmbedField, Client, EmbedBuilder, Message, TextBasedChannel } from "discord.js";
|
||||
import { Client, EmbedBuilder, Message, TextBasedChannel } from "discord.js";
|
||||
import { getLocale } from "../../utils/locales";
|
||||
import { isImage, userWithNickname } from "../../utils/misc";
|
||||
import { showDate } from "../../utils/time";
|
||||
|
@ -96,7 +96,7 @@ export default async (message: Message, client: Client) => {
|
|||
// Remove undefined elements
|
||||
.filter(Boolean);
|
||||
|
||||
const loc = getLocale(client);
|
||||
const loc = getLocale(client, client.config.default_lang);
|
||||
|
||||
// Remove duplicates then map the quoted posts
|
||||
[...new Set(messages)]
|
||||
|
@ -114,33 +114,18 @@ export default async (message: Message, client: Client) => {
|
|||
embed.setImage(quoted_post.attachments.first()!.url);
|
||||
} else {
|
||||
// Contains more than one image and/or other files
|
||||
let files = "";
|
||||
quoted_post.attachments.forEach((file) => (files += `[${file.name}](${file.url}), `));
|
||||
embed.addFields({
|
||||
name:
|
||||
quoted_post.attachments.size > 1
|
||||
? loc.get("e_attachements")
|
||||
: loc.get("e_attachement"),
|
||||
|
||||
// We are currently losing a link to a file if the link is too long,
|
||||
// but we can't do much about it
|
||||
const maxFieldValueLength = 1024;
|
||||
const files = quoted_post.attachments
|
||||
.map((file) => `[${file.name}](${file.url}`)
|
||||
.filter((link) => link.length <= maxFieldValueLength);
|
||||
|
||||
let currentField = "";
|
||||
const fields: APIEmbedField[] = [];
|
||||
files.forEach((file, idx) => {
|
||||
const potentialField = `${currentField}, ${file}`;
|
||||
|
||||
if (potentialField.length > maxFieldValueLength || idx === files.length - 1) {
|
||||
fields.push({
|
||||
name: loc.get(
|
||||
quoted_post.attachments.size > 1 ? "e_attachements" : "e_attachement",
|
||||
),
|
||||
value: currentField,
|
||||
// TODO: Check if don't exceed char limit, if yes, split
|
||||
// files into multiples field.
|
||||
value: `${files.slice(0, -2)}.`,
|
||||
});
|
||||
currentField = file;
|
||||
} else {
|
||||
currentField = potentialField;
|
||||
}
|
||||
});
|
||||
|
||||
embed.addFields(fields);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -81,13 +81,9 @@ export const getLocalizations = (client: Client, text: string, lowercase = false
|
|||
* @param lang Lang to fetch
|
||||
* @returns the map with the desired languaged clogged with the default one
|
||||
*/
|
||||
export const getLocale = (client: Client, lang: string | undefined = undefined) => {
|
||||
export const getLocale = (client: Client, lang: string) => {
|
||||
// Load default lang
|
||||
const default_locales = client.locales.get(client.config.default_lang);
|
||||
if (!lang) {
|
||||
return default_locales!;
|
||||
}
|
||||
|
||||
// Load desired lang
|
||||
const desired_locales = client.locales.get(lang);
|
||||
|
||||
|
|
Loading…
Reference in a new issue