WIP Quote
This commit is contained in:
parent
a9c076247b
commit
040ff1cc8c
1 changed files with 68 additions and 25 deletions
|
@ -1,6 +1,6 @@
|
|||
import { Client, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
||||
import { Client, GuildMember, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
||||
import { getLocale } from '../../utils/locales';
|
||||
import { isImage } from '../../utils/misc';
|
||||
import { isImage, userWithNickname } from '../../utils/misc';
|
||||
import { showDate } from '../../utils/time';
|
||||
|
||||
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
||||
|
@ -66,7 +66,10 @@ export default async (message: Message, client: Client) => {
|
|||
.catch(() => undefined);
|
||||
|
||||
// If message doesn't exist or empty
|
||||
if (!quoted_message || (!quoted_message.content && quoted_message.attachments.size == 0)) {
|
||||
if (!quoted_message || (
|
||||
!quoted_message.content &&
|
||||
quoted_message.attachments.size == 0)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -76,29 +79,26 @@ export default async (message: Message, client: Client) => {
|
|||
// Remove undefined elements
|
||||
).filter(Boolean);
|
||||
|
||||
messages.map(quoted_msg => {
|
||||
const loc = getLocale(client, client.config.default_lang);
|
||||
messages.map(quoted_post => {
|
||||
const embed = new MessageEmbed()
|
||||
.setColor('#2f3136')
|
||||
.setAuthor({
|
||||
name: 'Citation',
|
||||
iconURL: quoted_msg?.author.displayAvatarURL(),
|
||||
})
|
||||
.setFooter({
|
||||
text: `Posté le ${showDate(
|
||||
client.config.default_lang,
|
||||
getLocale(client, client.config.default_lang),
|
||||
quoted_msg?.createdAt as Date)
|
||||
}`,
|
||||
iconURL: quoted_post?.author.displayAvatarURL(),
|
||||
});
|
||||
|
||||
// Handle attachments
|
||||
if (quoted_msg?.attachments.size === 1 && isImage(quoted_msg.attachments.first()?.name as string)) {
|
||||
if (quoted_post?.attachments.size) {
|
||||
if (quoted_post?.attachments.size === 1 && isImage(
|
||||
quoted_post.attachments.first()?.name as string
|
||||
)) {
|
||||
// Only contains one image
|
||||
embed.setImage(quoted_msg.attachments.first()?.url as string);
|
||||
embed.setImage(quoted_post.attachments.first()?.url as string);
|
||||
} else {
|
||||
// Contains more than one image or other files
|
||||
let files = '';
|
||||
quoted_msg?.attachments.forEach(attachment => {
|
||||
quoted_post?.attachments.forEach(attachment => {
|
||||
files += `[${attachment.name}](${attachment.url}), `;
|
||||
});
|
||||
embed.addFields({
|
||||
|
@ -106,6 +106,49 @@ export default async (message: Message, client: Client) => {
|
|||
value: `${files.slice(0, -2)}.`,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Description
|
||||
embed.setDescription(quoted_post?.content ?? '');
|
||||
|
||||
// Footer
|
||||
let footer = `Posté le ${showDate(
|
||||
client.config.default_lang,
|
||||
loc,
|
||||
quoted_post?.createdAt as Date
|
||||
)}`;
|
||||
if (quoted_post?.editedAt) {
|
||||
footer += ` et modifié le ${showDate(
|
||||
client.config.default_lang,
|
||||
loc,
|
||||
quoted_post.editedAt
|
||||
)}`;
|
||||
}
|
||||
|
||||
let author = 'Auteur';
|
||||
if (message.author == quoted_post?.author) {
|
||||
author += ' & Citateur';
|
||||
} else {
|
||||
footer += `\nCité par ${userWithNickname(
|
||||
message.guild?.members.cache.get(message.author.id) as GuildMember
|
||||
) ?? '?'} le ${showDate(
|
||||
client.config.default_lang,
|
||||
loc,
|
||||
message.createdAt
|
||||
)}`;
|
||||
}
|
||||
|
||||
embed.setFooter({
|
||||
text: footer,
|
||||
iconURL: message.author.avatarURL() ?? undefined,
|
||||
});
|
||||
|
||||
// Info about the post
|
||||
embed.addField(author, `${quoted_post?.author}`, true);
|
||||
embed.addField(
|
||||
'Message', `${quoted_post?.channel} - [Lien Message](${quoted_post?.url})`,
|
||||
true
|
||||
);
|
||||
|
||||
return message.channel.send({ embeds: [embed] });
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue