filter
This commit is contained in:
parent
facf0cd88e
commit
4667b668d5
1 changed files with 82 additions and 80 deletions
|
@ -98,89 +98,91 @@ export default async (message: Message, client: Client) => {
|
||||||
const loc = getLocale(client, client.config.default_lang);
|
const loc = getLocale(client, client.config.default_lang);
|
||||||
|
|
||||||
// Remove duplicates then map the quoted posts
|
// Remove duplicates then map the quoted posts
|
||||||
[...new Set(messages)].map((quoted_post) => {
|
[...new Set(messages)]
|
||||||
const embed = new EmbedBuilder().setColor("#2f3136").setAuthor({
|
.filter((p) => p !== undefined)
|
||||||
name: "Citation",
|
.map((quoted_post) => {
|
||||||
iconURL: quoted_post?.author.displayAvatarURL(),
|
const embed = new EmbedBuilder().setColor("#2f3136").setAuthor({
|
||||||
});
|
name: "Citation",
|
||||||
|
iconURL: quoted_post.author.displayAvatarURL(),
|
||||||
|
});
|
||||||
|
|
||||||
// Handle attachments
|
// Handle attachments
|
||||||
if (quoted_post?.attachments.size !== 0) {
|
if (quoted_post.attachments.size !== 0) {
|
||||||
if (quoted_post?.attachments.size === 1 && isImage(quoted_post.attachments.first()!.name)) {
|
if (quoted_post.attachments.size === 1 && isImage(quoted_post.attachments.first()!.name)) {
|
||||||
// Only contains one image
|
// Only contains one image
|
||||||
embed.setImage(quoted_post.attachments.first()!.url);
|
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({
|
||||||
|
// TODO: Don't pluralize when there is only one file.
|
||||||
|
// TODO: Locales
|
||||||
|
name: "Fichiers joints",
|
||||||
|
// TODO: Check if don't exceed char limit, if yes, split
|
||||||
|
// files into multiples field.
|
||||||
|
value: `${files.slice(0, -2)}.`,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Description as post content
|
||||||
|
if (quoted_post.content) {
|
||||||
|
// Only if content exists and length > 0
|
||||||
|
embed.setDescription(quoted_post.content);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Footer
|
||||||
|
let footer = `Posté le ${showDate(loc, quoted_post.createdAt)}`;
|
||||||
|
if (quoted_post.editedAt) {
|
||||||
|
footer += ` et modifié le ${showDate(loc, quoted_post.editedAt)}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
let author = "Auteur";
|
||||||
|
if (message.author === quoted_post.author) {
|
||||||
|
author += " & Citateur";
|
||||||
} else {
|
} else {
|
||||||
// Contains more than one image and/or other files
|
footer += `\nCité par ${userWithNickname(message.member!) ?? "?"} le ${showDate(
|
||||||
let files = "";
|
loc,
|
||||||
quoted_post?.attachments.forEach((file) => (files += `[${file.name}](${file.url}), `));
|
message.createdAt,
|
||||||
embed.addFields({
|
)}`;
|
||||||
// TODO: Don't pluralize when there is only one file.
|
}
|
||||||
// TODO: Locales
|
|
||||||
name: "Fichiers joints",
|
embed.setFooter({
|
||||||
// TODO: Check if don't exceed char limit, if yes, split
|
text: footer,
|
||||||
// files into multiples field.
|
iconURL: message.author.avatarURL() ?? undefined,
|
||||||
value: `${files.slice(0, -2)}.`,
|
});
|
||||||
|
|
||||||
|
// Location/author of the quoted post
|
||||||
|
embed.addFields(
|
||||||
|
{
|
||||||
|
name: author,
|
||||||
|
value: `${quoted_post.author}`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Message",
|
||||||
|
value: `${quoted_post.channel} - [Lien Message](${quoted_post.url})`,
|
||||||
|
inline: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
// Delete source message if no content when removing links
|
||||||
|
if (
|
||||||
|
!message.content.replace(new RegExp(regex, "g"), "").trim() &&
|
||||||
|
messages.length === urls.length &&
|
||||||
|
!message.mentions.repliedUser &&
|
||||||
|
message.channel.isSendable()
|
||||||
|
) {
|
||||||
|
message.delete();
|
||||||
|
return message.channel.send({ embeds: [embed] });
|
||||||
|
} else {
|
||||||
|
return message.reply({
|
||||||
|
embeds: [embed],
|
||||||
|
allowedMentions: {
|
||||||
|
repliedUser: false,
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Description as post content
|
|
||||||
if (quoted_post?.content) {
|
|
||||||
// Only if content exists and length > 0
|
|
||||||
embed.setDescription(quoted_post?.content);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Footer
|
|
||||||
let footer = `Posté le ${showDate(loc, quoted_post!.createdAt)}`;
|
|
||||||
if (quoted_post?.editedAt) {
|
|
||||||
footer += ` et modifié le ${showDate(loc, quoted_post.editedAt)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
let author = "Auteur";
|
|
||||||
if (message.author === quoted_post?.author) {
|
|
||||||
author += " & Citateur";
|
|
||||||
} else {
|
|
||||||
footer += `\nCité par ${userWithNickname(message.member!) ?? "?"} le ${showDate(
|
|
||||||
loc,
|
|
||||||
message.createdAt,
|
|
||||||
)}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
embed.setFooter({
|
|
||||||
text: footer,
|
|
||||||
iconURL: message.author.avatarURL() ?? undefined,
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Location/author of the quoted post
|
|
||||||
embed.addFields(
|
|
||||||
{
|
|
||||||
name: author,
|
|
||||||
value: `${quoted_post?.author}`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Message",
|
|
||||||
value: `${quoted_post?.channel} - [Lien Message](${quoted_post?.url})`,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
// Delete source message if no content when removing links
|
|
||||||
if (
|
|
||||||
!message.content.replace(new RegExp(regex, "g"), "").trim() &&
|
|
||||||
messages.length === urls.length &&
|
|
||||||
!message.mentions.repliedUser &&
|
|
||||||
message.channel.isSendable()
|
|
||||||
) {
|
|
||||||
message.delete();
|
|
||||||
return message.channel.send({ embeds: [embed] });
|
|
||||||
} else {
|
|
||||||
return message.reply({
|
|
||||||
embeds: [embed],
|
|
||||||
allowedMentions: {
|
|
||||||
repliedUser: false,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue