handle attachements
This commit is contained in:
parent
a5b6924ddc
commit
a0fc0103f3
1 changed files with 21 additions and 4 deletions
|
@ -1,5 +1,6 @@
|
|||
import { Client, Message, MessageEmbed, TextBasedChannel } from 'discord.js';
|
||||
import { getLocale } from '../../utils/locales';
|
||||
import { isImage } from '../../utils/misc';
|
||||
import { showDate } from '../../utils/time';
|
||||
|
||||
/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */
|
||||
|
@ -75,21 +76,37 @@ export default async (message: Message, client: Client) => {
|
|||
// Remove undefined elements
|
||||
).filter(Boolean);
|
||||
|
||||
messages.map(valid_message => {
|
||||
messages.map(quoted_msg => {
|
||||
const embed = new MessageEmbed()
|
||||
.setColor('#2f3136')
|
||||
.setAuthor({
|
||||
name: 'Citation',
|
||||
iconURL: valid_message?.author.displayAvatarURL(),
|
||||
iconURL: quoted_msg?.author.displayAvatarURL(),
|
||||
})
|
||||
.setFooter({
|
||||
text: `Message posté le ${showDate(
|
||||
text: `Posté le ${showDate(
|
||||
client.config.default_lang,
|
||||
getLocale(client, client.config.default_lang),
|
||||
valid_message?.createdAt as Date)
|
||||
quoted_msg?.createdAt as Date)
|
||||
}`,
|
||||
});
|
||||
|
||||
// Handle attachments
|
||||
if (quoted_msg?.attachments.size === 1 && isImage(quoted_msg.attachments.first()?.name as string)) {
|
||||
// Only contains one image
|
||||
embed.setImage(quoted_msg.attachments.first()?.url as string);
|
||||
} else {
|
||||
// Contains more than one image or other files
|
||||
let files = '';
|
||||
quoted_msg?.attachments.forEach(attachment => {
|
||||
files += `[${attachment.name}](${attachment.url}), `;
|
||||
});
|
||||
embed.addFields({
|
||||
name: 'Fichiers joints',
|
||||
value: `${files.slice(0, -2)}.`,
|
||||
});
|
||||
}
|
||||
|
||||
return message.channel.send({ embeds: [embed] });
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue