diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index b7d4145..78ffad9 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -89,18 +89,18 @@ export default async (message: Message, client: Client) => { }); // Handle attachments - if (quoted_post?.attachments.size) { + if (quoted_post?.attachments.size !== 0) { if (quoted_post?.attachments.size === 1 && isImage( quoted_post.attachments.first()?.name as string )) { // Only contains one image embed.setImage(quoted_post.attachments.first()?.url as string); } else { - // Contains more than one image or other files + // Contains more than one image and/or other files let files = ''; - quoted_post?.attachments.forEach(attachment => { - files += `[${attachment.name}](${attachment.url}), `; - }); + quoted_post?.attachments.forEach(file => files += + `[${file.name}](${file.url}), ` + ); embed.addFields({ name: 'Fichiers joints', value: `${files.slice(0, -2)}.`, @@ -108,7 +108,7 @@ export default async (message: Message, client: Client) => { } } - // Description + // Description as post content embed.setDescription(quoted_post?.content ?? ''); // Footer @@ -130,7 +130,7 @@ export default async (message: Message, client: Client) => { author += ' & Citateur'; } else { footer += `\nCité par ${userWithNickname( - message.guild?.members.cache.get(message.author.id) as GuildMember + message.member as GuildMember ) ?? '?'} le ${showDate( client.config.default_lang, loc, @@ -143,13 +143,27 @@ export default async (message: Message, client: Client) => { iconURL: message.author.avatarURL() ?? undefined, }); - // Info about the post + // Location and author of 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] }); + if ( + !message.content.replace(new RegExp(regex, 'g'), '').trim() && + messages.length === urls.length && + !message.mentions.repliedUser + ) { + message.delete(); + return message.channel.send({ embeds: [embed] }); + } else { + return message.reply({ + embeds: [embed], + allowedMentions: { + repliedUser: false, + }, + }); + } }); };