From bba614198a8d73dada280a29e801f7bdc2d20815 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Jul 2022 14:56:41 +0200 Subject: [PATCH 01/16] add message support --- src/utils/client.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/utils/client.ts b/src/utils/client.ts index 2176192..cb68532 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -45,6 +45,7 @@ export default async () => { const client: Client = new Client({ intents: [ Intents.FLAGS.GUILDS, + Intents.FLAGS.GUILD_MESSAGES, ], }); -- 2.45.2 From 403cefc7372ab67dfcc51b50150be985e89dd1d4 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Jul 2022 14:57:21 +0200 Subject: [PATCH 02/16] * support an event triggered when a message appear * WIP Quotes --- src/events/message/messageCreate.ts | 64 +++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 src/events/message/messageCreate.ts diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts new file mode 100644 index 0000000..b84ee0a --- /dev/null +++ b/src/events/message/messageCreate.ts @@ -0,0 +1,64 @@ +import { GuildBasedChannel, Message } from 'discord.js'; + +/** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */ +export default (message: Message) => { + // Ignore message if + if ( + // Author is a bot + message.author.bot || + // Author is Discord + message.author.system || + // Message isn't a message + message.system || + // Message is in PM (future-proof if we add Intents.FLAGS.DIRECT_MESSAGES) + !message.guild || + // Guild is offline + !message.guild.available + ) { + return; + } + + /* Citation */ + const regex = 'https://(?:canary\\.|ptb\\.)?discord(?:app)?\\.com/channels/(\\d{17,19})/(\\d{17,19})/(\\d{17,19})'; + const urls = message.content.match(new RegExp(regex, 'g')); + + // Ignore message if there is no URLs + if (!urls) { + return; + } + + const messages = ( + urls.reduce( + (data: { + message_id: string; + found_channel: GuildBasedChannel; + }[] = [], match) => { + const [, + guild_id, + channel_id, + message_id, + ] = new RegExp(regex).exec(match) as RegExpExecArray; + + // If message posted in another guild + if (guild_id !== message.guild?.id) { + return data; + } + + const found_channel = + message.guild.channels.cache.get(channel_id); + + // If channel doesn't exist in the guild + if (!found_channel) { + return data; + } + + data.push({ message_id, found_channel }); + + return data; + }, + [] + ) + ); + + console.log(messages); +}; -- 2.45.2 From fc427fd008df3ed4c85dca2aa0fbd3c4efc06f19 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Jul 2022 21:45:21 +0200 Subject: [PATCH 03/16] check if message exists --- src/events/message/messageCreate.ts | 70 +++++++++++++++++------------ 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index b84ee0a..46f73c8 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -1,7 +1,7 @@ -import { GuildBasedChannel, Message } from 'discord.js'; +import { Message, TextBasedChannel } from 'discord.js'; /** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */ -export default (message: Message) => { +export default async (message: Message) => { // Ignore message if if ( // Author is a bot @@ -28,37 +28,49 @@ export default (message: Message) => { } const messages = ( - urls.reduce( - (data: { - message_id: string; - found_channel: GuildBasedChannel; - }[] = [], match) => { - const [, - guild_id, - channel_id, - message_id, - ] = new RegExp(regex).exec(match) as RegExpExecArray; + await Promise.all( + urls.reduce( + (data: { + message_id: string; + channel: TextBasedChannel; + }[] = [], match) => { + const [, + guild_id, + channel_id, + message_id, + ] = new RegExp(regex).exec(match) as RegExpExecArray; + + // If message posted in another guild + if (guild_id !== message.guild?.id) { + return data; + } + + const channel = + message.guild.channels.cache.get(channel_id) as TextBasedChannel; + + // If channel doesn't exist in the guild and isn't text + if (!channel) { + return data; + } + + data.push({ message_id, channel }); - // If message posted in another guild - if (guild_id !== message.guild?.id) { return data; + }, [] + ).map(async ({ message_id, channel }) => { + const quoted_message = await channel.messages + .fetch(message_id) + .catch(() => undefined); + + // If message doesn't exist or empty + if (!quoted_message || (!quoted_message.content && quoted_message.attachments.size == 0)) { + return; } - const found_channel = - message.guild.channels.cache.get(channel_id); - - // If channel doesn't exist in the guild - if (!found_channel) { - return data; - } - - data.push({ message_id, found_channel }); - - return data; - }, - [] + return quoted_message; + }) ) - ); + // Remove undefined elements + ).filter(Boolean); - console.log(messages); }; -- 2.45.2 From b31aef9999cf9b9f5189490db6fb19f9f0ab1a49 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Jul 2022 23:41:29 +0200 Subject: [PATCH 04/16] move client to module folder --- src/modules/client.ts | 41 +++++++++++++++++++++++++++++++++++++++++ src/utils/client.ts | 39 +-------------------------------------- 2 files changed, 42 insertions(+), 38 deletions(-) create mode 100644 src/modules/client.ts diff --git a/src/modules/client.ts b/src/modules/client.ts new file mode 100644 index 0000000..8d0aa0e --- /dev/null +++ b/src/modules/client.ts @@ -0,0 +1,41 @@ +import { Collection } from 'discord.js'; +import { SlashCommandBuilder } from '@discordjs/builders'; + +export {}; + +declare module 'discord.js' { + // eslint-disable-next-line no-shadow + export interface Client { + /** Store the configuration */ + config: { + /** Bot version */ + version: string, + /** Bot token from env variable */ + token_discord: string | undefined, + /** Default lang used */ + default_lang: string + }, + /** Store all the slash commands */ + commands: { + categories: Collection< + /** Category name */ + string, + /** Name of the commands in the category */ + string[] + >, + list: Collection< + /** Command name */ + string, + /** Command itself */ + { + /** Data about the command */ + data: SlashCommandBuilder, + /** How the command interact */ + interaction: (interaction: CommandInteraction, client: Client) => unknown + } + >, + } + /** Store all the localizations */ + locales: Map> + } +} diff --git a/src/utils/client.ts b/src/utils/client.ts index cb68532..182ebf1 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -1,44 +1,7 @@ import { Client, Collection, Intents } from 'discord.js'; import { readFileSync } from 'fs'; -import { SlashCommandBuilder } from '@discordjs/builders'; import { loadLocales } from './locales'; - -declare module 'discord.js' { - // eslint-disable-next-line no-shadow - export interface Client { - /** Store the configuration */ - config: { - /** Bot version */ - version: string, - /** Bot token from env variable */ - token_discord: string | undefined, - /** Default lang used */ - default_lang: string - }, - /** Store all the slash commands */ - commands: { - categories: Collection< - /** Category name */ - string, - /** Name of the commands in the category */ - string[] - >, - list: Collection< - /** Command name */ - string, - /** Command itself */ - { - /** Data about the command */ - data: SlashCommandBuilder, - /** How the command interact */ - interaction: (interaction: CommandInteraction, client: Client) => unknown - } - >, - } - /** Store all the localizations */ - locales: Map> - } -} +import '../modules/client'; /** Creation of the client and definition of its properties. */ export default async () => { -- 2.45.2 From 5e17b7e351fa006f83c7fa86033238a865b5c09d Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Jul 2022 23:53:57 +0200 Subject: [PATCH 05/16] update translations --- src/locales/fr.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/locales/fr.json b/src/locales/fr.json index cad1fba..90fddc6 100644 --- a/src/locales/fr.json +++ b/src/locales/fr.json @@ -12,5 +12,7 @@ "c_help_opt1_desc": "Commande voulu en détail.", "c_help1": "Liste des catégories et des commandes associées", "c_help2": "`/help ` pour obtenir plus d'informations sur une commande.", - "c_help3": "Impossible de trouver :" + "c_help3": "Impossible de trouver :", + + "u_time_at": "à" } -- 2.45.2 From 1349ad52bb84cfdb598626fafe21a1c6e55972ee Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 26 Jul 2022 23:54:11 +0200 Subject: [PATCH 06/16] time utils --- src/utils/time.ts | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 src/utils/time.ts diff --git a/src/utils/time.ts b/src/utils/time.ts new file mode 100644 index 0000000..0243bbc --- /dev/null +++ b/src/utils/time.ts @@ -0,0 +1,16 @@ +/** + * Parsed string adapted with TZ (locales) and format for the specified lang. + * @param lang Lang + * @param locale Locales + * @param date Date + * @returns String + */ +export const showDate = ( + lang: string, + locale: Map, + date: Date +) => { + return date.toLocaleString(lang).replace(' ', ` ${ + locale.get('u_time_at') + } `); +}; -- 2.45.2 From a5b6924ddc3ba4d46b80d8a0f8288b7a71359f24 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 00:03:56 +0200 Subject: [PATCH 07/16] WIP embed --- src/events/message/messageCreate.ts | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index 46f73c8..812dbea 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -1,7 +1,9 @@ -import { Message, TextBasedChannel } from 'discord.js'; +import { Client, Message, MessageEmbed, TextBasedChannel } from 'discord.js'; +import { getLocale } from '../../utils/locales'; +import { showDate } from '../../utils/time'; /** https://discord.js.org/#/docs/discord.js/main/class/Client?scrollTo=e-messageCreate */ -export default async (message: Message) => { +export default async (message: Message, client: Client) => { // Ignore message if if ( // Author is a bot @@ -73,4 +75,21 @@ export default async (message: Message) => { // Remove undefined elements ).filter(Boolean); + messages.map(valid_message => { + const embed = new MessageEmbed() + .setColor('#2f3136') + .setAuthor({ + name: 'Citation', + iconURL: valid_message?.author.displayAvatarURL(), + }) + .setFooter({ + text: `Message posté le ${showDate( + client.config.default_lang, + getLocale(client, client.config.default_lang), + valid_message?.createdAt as Date) + }`, + }); + + return message.channel.send({ embeds: [embed] }); + }); }; -- 2.45.2 From a0fc0103f3030baed4348e1d055664d5c5895852 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 00:35:40 +0200 Subject: [PATCH 08/16] handle attachements --- src/events/message/messageCreate.ts | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index 812dbea..a15f934 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -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] }); }); }; -- 2.45.2 From b5016bb39b5aad08abab0bbe6abebdd3fe900836 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 00:35:47 +0200 Subject: [PATCH 09/16] file ext stuff --- src/utils/misc.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 0f76dd4..917fb74 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -36,3 +36,25 @@ export const removeExtension = (filename: string) => { return array.join('.'); }; + +/** + * Get extension from a filename. + * @param filename string of the filename + * @returns string of the extension if it exists + */ +export const getExtension = (filename: string) => { + const array = filename.split('.'); + + return array.pop(); +}; + +/** + * Define if a media is a media based on file extension. + * @param filename string of the filename + * @returns true is file is a media + */ +export const isImage = (filename: string) => { + return Boolean(getExtension(filename)?.match( + /jpg|jpeg|png|webp|gif/ + )); +}; -- 2.45.2 From a9c076247b4ab39ff8e0383150d449e20fa30268 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 01:22:13 +0200 Subject: [PATCH 10/16] famous userOrNick --- src/utils/misc.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 917fb74..0393cc0 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -1,3 +1,5 @@ +import { GuildMember } from 'discord.js'; + /** * Log module status. * @param {string} name Module name @@ -58,3 +60,19 @@ export const isImage = (filename: string) => { /jpg|jpeg|png|webp|gif/ )); }; + +/** + * String with pseudo and nickname if available. + * @param member Member + * @returns string + */ +export const userWithNickname = (member: GuildMember) => { + if (!member) { + return undefined; + } + if (member.nickname) { + return `${member.nickname} (${member.user.tag})`; + } else { + return member.user.tag; + } +}; -- 2.45.2 From 040ff1cc8cc81072140f4d0145e4147b8e8de32b Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 01:22:44 +0200 Subject: [PATCH 11/16] WIP Quote --- src/events/message/messageCreate.ts | 93 +++++++++++++++++++++-------- 1 file changed, 68 insertions(+), 25 deletions(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index a15f934..b7d4145 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -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,37 +79,77 @@ 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)) { - // 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)}.`, - }); + 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_post.attachments.first()?.url as string); + } else { + // Contains more than one image or other files + let files = ''; + quoted_post?.attachments.forEach(attachment => { + files += `[${attachment.name}](${attachment.url}), `; + }); + embed.addFields({ + name: 'Fichiers joints', + 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] }); }); }; -- 2.45.2 From 65559753b7c355758cef338c865dea56abbe7ed0 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 01:49:23 +0200 Subject: [PATCH 12/16] delete when only links in message and reply otherwise --- src/events/message/messageCreate.ts | 32 +++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 9 deletions(-) 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, + }, + }); + } }); }; -- 2.45.2 From af527042a643980a05b59a09cc9968294b6b9362 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 01:51:22 +0200 Subject: [PATCH 13/16] remove duplicates --- src/events/message/messageCreate.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index 78ffad9..4d82dbf 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -80,7 +80,9 @@ export default async (message: Message, client: Client) => { ).filter(Boolean); const loc = getLocale(client, client.config.default_lang); - messages.map(quoted_post => { + + // Remove duplicates + [...new Set(messages)].map(quoted_post => { const embed = new MessageEmbed() .setColor('#2f3136') .setAuthor({ -- 2.45.2 From d0db3de7cf30ad83900f10d1a0047586e2ab9929 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 02:08:49 +0200 Subject: [PATCH 14/16] fix comments and add todos --- src/events/message/messageCreate.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index 4d82dbf..23d9954 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -81,7 +81,7 @@ export default async (message: Message, client: Client) => { const loc = getLocale(client, client.config.default_lang); - // Remove duplicates + // Remove duplicates then map the quoted posts [...new Set(messages)].map(quoted_post => { const embed = new MessageEmbed() .setColor('#2f3136') @@ -104,7 +104,10 @@ export default async (message: Message, client: Client) => { `[${file.name}](${file.url}), ` ); embed.addFields({ + // TODO: Don't pluralize when there is only one file. name: 'Fichiers joints', + // TODO: Check if don't exceed char limit, if yes, split + // files into multiples field. value: `${files.slice(0, -2)}.`, }); } @@ -145,13 +148,14 @@ export default async (message: Message, client: Client) => { iconURL: message.author.avatarURL() ?? undefined, }); - // Location and author of the post + // Location/author of the quoted post embed.addField(author, `${quoted_post?.author}`, true); embed.addField( 'Message', `${quoted_post?.channel} - [Lien Message](${quoted_post?.url})`, true ); + // Delete source message if no content when removing links if ( !message.content.replace(new RegExp(regex, 'g'), '').trim() && messages.length === urls.length && -- 2.45.2 From ab9b1540eb5ebc23c9b63ff2d833b196849eda36 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 02:12:23 +0200 Subject: [PATCH 15/16] better arg name --- src/utils/time.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/time.ts b/src/utils/time.ts index 0243bbc..b44614e 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -1,16 +1,16 @@ /** * Parsed string adapted with TZ (locales) and format for the specified lang. - * @param lang Lang + * @param tz Lang * @param locale Locales * @param date Date * @returns String */ export const showDate = ( - lang: string, + tz: string, locale: Map, date: Date ) => { - return date.toLocaleString(lang).replace(' ', ` ${ + return date.toLocaleString(tz).replace(' ', ` ${ locale.get('u_time_at') } `); }; -- 2.45.2 From 3dc625d17667a010b0edfd18a918ac70bcdcd982 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 02:12:55 +0200 Subject: [PATCH 16/16] update translations --- src/locales/en-US.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/locales/en-US.json b/src/locales/en-US.json index 6f0439a..2ed735a 100644 --- a/src/locales/en-US.json +++ b/src/locales/en-US.json @@ -12,5 +12,7 @@ "c_help_opt1_desc": "Command wanted in depth.", "c_help1": "List of categories and associated commands", "c_help2": "`/help ` to get more information about a command.", - "c_help3": "Can't find :" + "c_help3": "Can't find :", + + "u_time_at": "at" } -- 2.45.2