diff --git a/.eslintrc.json b/.eslintrc.json index 5d752e9..5beaf40 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,9 +1,5 @@ { - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "prettier" - ], + "extends": ["eslint:recommended", "plugin:@typescript-eslint/recommended", "prettier"], "parser": "@typescript-eslint/parser", "parserOptions": { "project": ["./tsconfig.json"] @@ -23,15 +19,9 @@ "no-inline-comments": "error", "no-lonely-if": "error", "no-multi-spaces": "error", - "no-multiple-empty-lines": [ - "error", - { "max": 2, "maxEOF": 1, "maxBOF": 0 } - ], + "no-multiple-empty-lines": ["error", { "max": 2, "maxEOF": 1, "maxBOF": 0 }], "no-shadow": "off", - "@typescript-eslint/no-shadow": [ - "error", - { "allow": ["err", "resolve", "reject"] } - ], + "@typescript-eslint/no-shadow": ["error", { "allow": ["err", "resolve", "reject"] }], "no-trailing-spaces": ["error"], "no-var": "error", "prefer-const": "error", diff --git a/.prettierrc.json b/.prettierrc.json index 0967ef4..c843044 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1 +1 @@ -{} +{ "printWidth": 100 } diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d40e86b..1730f67 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -123,22 +123,13 @@ export default { return new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_desc`) ?? "" + client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? "" ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_desc`) - ); + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); }, - interaction: async ( - interaction: ChatInputCommandInteraction, - client: Client - ) => { + interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); /* Votre code ici */ diff --git a/src/buttons/loader.ts b/src/buttons/loader.ts index 83f79b5..bec5d3d 100644 --- a/src/buttons/loader.ts +++ b/src/buttons/loader.ts @@ -1,10 +1,6 @@ import { readdir } from "fs/promises"; import { removeExtension } from "../utils/misc"; -import { - ChatInputCommandInteraction, - Client, - MessageComponentInteraction, -} from "discord.js"; +import { ChatInputCommandInteraction, Client, MessageComponentInteraction } from "discord.js"; import { getLocale } from "../utils/locales"; export default async (client: Client) => { @@ -20,17 +16,12 @@ export default async (client: Client) => { const button_files = await readdir(`${__dirname}/${buttons_category}`); // Add the category to the collection for the help command - client.buttons.categories.set( - buttons_category, - button_files.map(removeExtension) - ); + client.buttons.categories.set(buttons_category, button_files.map(removeExtension)); // Add the button return Promise.all( button_files.map(async (button_file) => { - const button = ( - await import(`../buttons/${buttons_category}/${button_file}`) - ).default; + const button = (await import(`../buttons/${buttons_category}/${button_file}`)).default; // Add it to the collection so the interaction will work client.buttons.list.set(button.data.name, button); diff --git a/src/buttons/misc/reminderList-next.ts b/src/buttons/misc/reminderList-next.ts index 0b1a64f..a652710 100644 --- a/src/buttons/misc/reminderList-next.ts +++ b/src/buttons/misc/reminderList-next.ts @@ -16,10 +16,7 @@ export default { data: { name: getFilename(__filename), }, - interaction: async ( - interaction: MessageComponentInteraction, - client: Client - ) => { + interaction: async (interaction: MessageComponentInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); const embed_desc = interaction.message.embeds.at(0)?.description as string; diff --git a/src/buttons/misc/reminderList-prec.ts b/src/buttons/misc/reminderList-prec.ts index 33c91fd..058fc3e 100644 --- a/src/buttons/misc/reminderList-prec.ts +++ b/src/buttons/misc/reminderList-prec.ts @@ -16,10 +16,7 @@ export default { data: { name: getFilename(__filename), }, - interaction: async ( - interaction: MessageComponentInteraction, - client: Client - ) => { + interaction: async (interaction: MessageComponentInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); const embed_desc = interaction.message.embeds.at(0)?.description as string; diff --git a/src/commands/loader.ts b/src/commands/loader.ts index 8f02d48..ba5785b 100644 --- a/src/commands/loader.ts +++ b/src/commands/loader.ts @@ -20,17 +20,13 @@ export default async (client: Client) => { const command_files = await readdir(`${__dirname}/${command_category}`); // Add the category to the collection for the help command - client.commands.categories.set( - command_category, - command_files.map(removeExtension) - ); + client.commands.categories.set(command_category, command_files.map(removeExtension)); // Add the command return Promise.all( command_files.map(async (command_file) => { - const command = ( - await import(`../commands/${command_category}/${command_file}`) - ).default; + const command = (await import(`../commands/${command_category}/${command_file}`)) + .default; // Add it to the collection so the interaction will work command.data = command.data(client); @@ -68,12 +64,9 @@ export default async (client: Client) => { scopedCommands.forEach( async (command, guild) => - await rest.put( - Routes.applicationGuildCommands(client.user?.id as string, guild), - { - body: command, - } - ) + await rest.put(Routes.applicationGuildCommands(client.user?.id as string, guild), { + body: command, + }) ); // Send global commands to Discord diff --git a/src/commands/misc/archive.ts b/src/commands/misc/archive.ts index 8d1ecbb..935d93b 100644 --- a/src/commands/misc/archive.ts +++ b/src/commands/misc/archive.ts @@ -20,36 +20,22 @@ export default { new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_desc`) ?? "" - ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_desc`) + client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? "" ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)) // Command option .addStringOption((option) => option .setName( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_opt1_name`) ?? "" + client.locales.get(client.config.default_lang)?.get(`c_${filename}_opt1_name`) ?? "" ) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_opt1_desc`) ?? "" - ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_opt1_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_opt1_desc`) + client.locales.get(client.config.default_lang)?.get(`c_${filename}_opt1_desc`) ?? "" ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)) ) ); }, @@ -111,9 +97,7 @@ export default { const allChannelDesired = channelGuild .filter((chan) => chan?.type == 0) - .filter( - (chan) => chan?.parentId == catToArchive.map((cat) => cat?.id)[0] - ); + .filter((chan) => chan?.parentId == catToArchive.map((cat) => cat?.id)[0]); // If no channels in the source category if (allChannelDesired.size == 0) { @@ -128,9 +112,7 @@ export default { } // Move channels to the archived categoryx - allChannelDesired.forEach((elem) => - elem?.setParent(catArchived?.id as string) - ); + allChannelDesired.forEach((elem) => elem?.setParent(catArchived?.id as string)); return interaction.reply({ embeds: [ diff --git a/src/commands/misc/help.ts b/src/commands/misc/help.ts index 83f940e..2c5f7a0 100644 --- a/src/commands/misc/help.ts +++ b/src/commands/misc/help.ts @@ -1,11 +1,6 @@ import { SlashCommandBuilder } from "@discordjs/builders"; import { Locale } from "discord-api-types/v9"; -import { - Client, - ChatInputCommandInteraction, - EmbedBuilder, - Colors, -} from "discord.js"; +import { Client, ChatInputCommandInteraction, EmbedBuilder, Colors } from "discord.js"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; import "../../modules/string"; @@ -19,44 +14,27 @@ export default { new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_desc`) ?? "" - ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_desc`) + client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? "" ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)) // Command option .addStringOption((option) => option .setName( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_opt1_name`) ?? "" + client.locales.get(client.config.default_lang)?.get(`c_${filename}_opt1_name`) ?? "" ) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_opt1_desc`) ?? "" - ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_opt1_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_opt1_desc`) + client.locales.get(client.config.default_lang)?.get(`c_${filename}_opt1_desc`) ?? "" ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)) ) ); }, - interaction: async ( - interaction: ChatInputCommandInteraction, - client: Client - ) => { + interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); const desired_command = interaction.options.getString( client.locales @@ -116,9 +94,8 @@ export default { .setDescription( // Loads the description // according to the user's locals - command.data.description_localizations?.[ - interaction.locale as Locale - ] ?? command.data.description + command.data.description_localizations?.[interaction.locale as Locale] ?? + command.data.description ), ], }); diff --git a/src/commands/misc/ping.ts b/src/commands/misc/ping.ts index b46f9b1..7d62d24 100644 --- a/src/commands/misc/ping.ts +++ b/src/commands/misc/ping.ts @@ -11,22 +11,13 @@ export default { return new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_desc`) ?? "" + client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? "" ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_desc`) - ); + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)); }, - interaction: async ( - interaction: ChatInputCommandInteraction, - client: Client - ) => { + interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { const loc = getLocale(client, interaction.locale); const sent = (await interaction.reply({ diff --git a/src/commands/misc/prep.ts b/src/commands/misc/prep.ts index 9f34fb0..36676d6 100644 --- a/src/commands/misc/prep.ts +++ b/src/commands/misc/prep.ts @@ -1,11 +1,5 @@ import { SlashCommandBuilder } from "@discordjs/builders"; -import { - ChannelType, - Client, - Colors, - CommandInteraction, - EmbedBuilder, -} from "discord.js"; +import { ChannelType, Client, Colors, CommandInteraction, EmbedBuilder } from "discord.js"; import "../../modules/string"; import { getLocale, getLocalizations } from "../../utils/locales"; import { getFilename } from "../../utils/misc"; @@ -19,36 +13,22 @@ export default { new SlashCommandBuilder() .setName(filename.toLowerCase()) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_desc`) ?? "" - ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_desc`) + client.locales.get(client.config.default_lang)?.get(`c_${filename}_desc`) ?? "" ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)) // Command option .addStringOption((option) => option .setName( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_opt1_name`) ?? "" + client.locales.get(client.config.default_lang)?.get(`c_${filename}_opt1_name`) ?? "" ) .setDescription( - client.locales - .get(client.config.default_lang) - ?.get(`c_${filename}_opt1_desc`) ?? "" - ) - .setNameLocalizations( - getLocalizations(client, `c_${filename}_opt1_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_opt1_desc`) + client.locales.get(client.config.default_lang)?.get(`c_${filename}_opt1_desc`) ?? "" ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_opt1_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_opt1_desc`)) ) ); }, @@ -98,16 +78,12 @@ export default { const all_channel_desired = channel_guild .filter((chan) => chan?.type == 0) .filter((chan) => chan?.parentId == cat_to_prep_id[0]); - const all_channel_desired_name = all_channel_desired.map( - (c_d) => c_d?.name - ); + const all_channel_desired_name = all_channel_desired.map((c_d) => c_d?.name); let desc = ""; const general = "général"; - if ( - all_channel_desired_name.filter((cdn) => cdn == general).length == 0 - ) { + if (all_channel_desired_name.filter((cdn) => cdn == general).length == 0) { interaction.guild?.channels.create({ name: general, type: 0, diff --git a/src/commands/misc/reminder.ts b/src/commands/misc/reminder.ts index 4d61cb5..4f2d4e4 100644 --- a/src/commands/misc/reminder.ts +++ b/src/commands/misc/reminder.ts @@ -1,7 +1,4 @@ -import { - ModalActionRowComponentBuilder, - SlashCommandBuilder, -} from "@discordjs/builders"; +import { ModalActionRowComponentBuilder, SlashCommandBuilder } from "@discordjs/builders"; import { ActionRowBuilder, ButtonBuilder, @@ -39,38 +36,22 @@ export default { // Command .setName(filename.toLowerCase()) .setDescription(loc_default.get(`c_${filename}_desc`) ?? "") - .setNameLocalizations( - getLocalizations(client, `c_${filename}_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_desc`) - ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_desc`)) // New reminder .addSubcommand((subcommand) => subcommand - .setName( - loc_default.get(`c_${filename}_sub1_name`)?.toLowerCase() ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub1_name`)?.toLowerCase() ?? "") .setDescription(loc_default.get(`c_${filename}_sub1_desc`) ?? "") - .setNameLocalizations( - getLocalizations(client, `c_${filename}_sub1_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_sub1_desc`) - ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub1_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub1_desc`)) // Specified Time .addStringOption((option) => option - .setName( - loc_default - .get(`c_${filename}_sub1_opt1_name`) - ?.toLowerCase() ?? "" - ) - .setDescription( - loc_default.get(`c_${filename}_sub1_opt1_desc`) ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub1_opt1_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub1_opt1_desc`) ?? "") .setNameLocalizations( getLocalizations(client, `c_${filename}_sub1_opt1_name`, true) ) @@ -82,14 +63,8 @@ export default { // Specified message (not required) .addStringOption((option) => option - .setName( - loc_default - .get(`c_${filename}_sub1_opt2_name`) - ?.toLowerCase() ?? "" - ) - .setDescription( - loc_default.get(`c_${filename}_sub1_opt2_desc`) ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub1_opt2_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub1_opt2_desc`) ?? "") .setNameLocalizations( getLocalizations(client, `c_${filename}_sub1_opt2_name`, true) ) @@ -102,28 +77,16 @@ export default { // List reminders .addSubcommand((subcommand) => subcommand - .setName( - loc_default.get(`c_${filename}_sub2_name`)?.toLowerCase() ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub2_name`)?.toLowerCase() ?? "") .setDescription(loc_default.get(`c_${filename}_sub2_desc`) ?? "") - .setNameLocalizations( - getLocalizations(client, `c_${filename}_sub2_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_sub2_desc`) - ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub2_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub2_desc`)) // User .addUserOption((option) => option - .setName( - loc_default - .get(`c_${filename}_sub2_opt1_name`) - ?.toLowerCase() ?? "" - ) - .setDescription( - loc_default.get(`c_${filename}_sub2_opt1_desc`) ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub2_opt1_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub2_opt1_desc`) ?? "") .setNameLocalizations( getLocalizations(client, `c_${filename}_sub2_opt1_name`, true) ) @@ -135,14 +98,8 @@ export default { // Page .addIntegerOption((option) => option - .setName( - loc_default - .get(`c_${filename}_sub2_opt2_name`) - ?.toLowerCase() ?? "" - ) - .setDescription( - loc_default.get(`c_${filename}_sub2_opt2_desc`) ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub2_opt2_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub2_opt2_desc`) ?? "") .setNameLocalizations( getLocalizations(client, `c_${filename}_sub2_opt2_name`, true) ) @@ -155,28 +112,16 @@ export default { // Delete a reminder .addSubcommand((subcommand) => subcommand - .setName( - loc_default.get(`c_${filename}_sub3_name`)?.toLowerCase() ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub3_name`)?.toLowerCase() ?? "") .setDescription(loc_default.get(`c_${filename}_sub3_desc`) ?? "") - .setNameLocalizations( - getLocalizations(client, `c_${filename}_sub3_name`, true) - ) - .setDescriptionLocalizations( - getLocalizations(client, `c_${filename}_sub3_desc`) - ) + .setNameLocalizations(getLocalizations(client, `c_${filename}_sub3_name`, true)) + .setDescriptionLocalizations(getLocalizations(client, `c_${filename}_sub3_desc`)) // ID .addIntegerOption((option) => option - .setName( - loc_default - .get(`c_${filename}_sub3_opt1_name`) - ?.toLowerCase() ?? "" - ) - .setDescription( - loc_default.get(`c_${filename}_sub3_opt1_desc`) ?? "" - ) + .setName(loc_default.get(`c_${filename}_sub3_opt1_name`)?.toLowerCase() ?? "") + .setDescription(loc_default.get(`c_${filename}_sub3_opt1_desc`) ?? "") .setNameLocalizations( getLocalizations(client, `c_${filename}_sub3_opt1_name`, true) ) @@ -189,10 +134,7 @@ export default { ); }, - interaction: async ( - interaction: ChatInputCommandInteraction, - client: Client - ) => { + interaction: async (interaction: ChatInputCommandInteraction, client: Client) => { const loc_default = client.locales.get(client.config.default_lang); const filename = getFilename(__filename); const loc = getLocale(client, interaction.locale); @@ -243,12 +185,8 @@ export default { .setRequired(false); modal.addComponents( - new ActionRowBuilder().addComponents( - timeGUI - ), - new ActionRowBuilder().addComponents( - messageGUI - ) + new ActionRowBuilder().addComponents(timeGUI), + new ActionRowBuilder().addComponents(messageGUI) ); return interaction.showModal(modal); @@ -316,12 +254,7 @@ export default { // Check if the ID exists and belongs to the user if ( - await checkOwnershipReminder( - client, - id, - interaction.user.id, - interaction.guildId ?? "0" - ) + await checkOwnershipReminder(client, id, interaction.user.id, interaction.guildId ?? "0") ) { return interaction.reply({ content: loc.get(`c_${filename}3`), @@ -334,11 +267,7 @@ export default { clearTimeout(reminderInfo.timeout_id); // Delete from database - return deleteReminder( - client, - reminderInfo.creation_date, - reminderInfo.user_id - ).then(() => + return deleteReminder(client, reminderInfo.creation_date, reminderInfo.user_id).then(() => interaction.reply({ content: `Reminder **#${id}** supprimé !`, ephemeral: true, diff --git a/src/events/client/ready.ts b/src/events/client/ready.ts index f645667..ab55980 100644 --- a/src/events/client/ready.ts +++ b/src/events/client/ready.ts @@ -42,11 +42,7 @@ export default async (client: Client) => { if (element.expiration_date <= now) { // Reminder expired - deleteReminder( - client, - element.creation_date, - `${element.user_id}` - ).then((res) => { + deleteReminder(client, element.creation_date, `${element.user_id}`).then((res) => { if (res != true) { throw res; } diff --git a/src/events/message/messageCreate.ts b/src/events/message/messageCreate.ts index 5d1527f..4e0b97a 100644 --- a/src/events/message/messageCreate.ts +++ b/src/events/message/messageCreate.ts @@ -1,10 +1,4 @@ -import { - Client, - GuildMember, - Message, - TextBasedChannel, - EmbedBuilder, -} from "discord.js"; +import { Client, GuildMember, Message, TextBasedChannel, EmbedBuilder } from "discord.js"; import { getLocale } from "../../utils/locales"; import { isImage, userWithNickname } from "../../utils/misc"; import { showDate } from "../../utils/time"; @@ -57,9 +51,7 @@ export default async (message: Message, client: Client) => { return data; } - const channel = message.guild.channels.cache.get( - channel_id - ) as TextBasedChannel; + 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) { @@ -73,9 +65,7 @@ export default async (message: Message, client: Client) => { [] ) .map(async ({ message_id, channel }) => { - const quoted_message = await channel.messages - .fetch(message_id) - .catch(() => undefined); + const quoted_message = await channel.messages.fetch(message_id).catch(() => undefined); // If message doesn't exist or empty if ( @@ -112,9 +102,7 @@ export default async (message: Message, client: Client) => { } else { // Contains more than one image and/or other files let files = ""; - quoted_post?.attachments.forEach( - (file) => (files += `[${file.name}](${file.url}), `) - ); + quoted_post?.attachments.forEach((file) => (files += `[${file.name}](${file.url}), `)); embed.addFields({ // TODO: Don't pluralize when there is only one file. // TODO: Locales @@ -136,20 +124,18 @@ export default async (message: Message, client: Client) => { quoted_post?.createdAt as Date )}`; if (quoted_post?.editedAt) { - footer += ` et modifié le ${showDate( - client.config.default_lang, - loc, - 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.member as GuildMember) ?? "?" - } le ${showDate(client.config.default_lang, loc, message.createdAt)}`; + footer += `\nCité par ${userWithNickname(message.member as GuildMember) ?? "?"} le ${showDate( + client.config.default_lang, + loc, + message.createdAt + )}`; } embed.setFooter({ diff --git a/src/index.ts b/src/index.ts index 0fa3d81..ee6917b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -61,9 +61,7 @@ const run = async () => { }); console.log(logStart(client_name, true)); - console.log( - `Botanique "${client.user?.username}" v${client.config.version} started!` - ); + console.log(`Botanique "${client.user?.username}" v${client.config.version} started!`); // ^C process.on("SIGINT", () => quit(client)); diff --git a/src/modals/loader.ts b/src/modals/loader.ts index 268a1f0..bd5d958 100644 --- a/src/modals/loader.ts +++ b/src/modals/loader.ts @@ -15,17 +15,12 @@ export default async (client: Client) => { const modal_files = await readdir(`${__dirname}/${modals_category}`); // Add the category to the collection for the help command - client.modals.categories.set( - modals_category, - modal_files.map(removeExtension) - ); + client.modals.categories.set(modals_category, modal_files.map(removeExtension)); // Add the modal return Promise.all( modal_files.map(async (modal_file) => { - const modal = ( - await import(`../modals/${modals_category}/${modal_file}`) - ).default; + const modal = (await import(`../modals/${modals_category}/${modal_file}`)).default; // Add it to the collection so the interaction will work client.modals.list.set(modal.data.name, modal); diff --git a/src/modals/misc/reminderGUI.ts b/src/modals/misc/reminderGUI.ts index b74a496..a0e2ac7 100644 --- a/src/modals/misc/reminderGUI.ts +++ b/src/modals/misc/reminderGUI.ts @@ -7,19 +7,14 @@ export default { name: getFilename(__filename), }, interaction: async (interaction: ModalSubmitInteraction, client: Client) => - newReminder( - client, - interaction.fields.fields.get("reminderGUI-time")?.value as string, - { - locale: interaction.locale, - message: - interaction.fields.fields.get("reminderGUI-message")?.value ?? null, - createdAt: interaction.createdAt.getTime(), - channelId: interaction.channelId, - userId: interaction.user.id, - guildId: interaction.guildId, - } - ).then((msg) => + newReminder(client, interaction.fields.fields.get("reminderGUI-time")?.value as string, { + locale: interaction.locale, + message: interaction.fields.fields.get("reminderGUI-message")?.value ?? null, + createdAt: interaction.createdAt.getTime(), + channelId: interaction.channelId, + userId: interaction.user.id, + guildId: interaction.guildId, + }).then((msg) => interaction.reply({ content: msg as string, ephemeral: true, diff --git a/src/modules/client.ts b/src/modules/client.ts index 559604a..5169a8d 100644 --- a/src/modules/client.ts +++ b/src/modules/client.ts @@ -34,10 +34,7 @@ declare module "discord.js" { name: string; }; /** How the modal interact */ - interaction: ( - interaction: ModalSubmitInteraction, - client: Client - ) => unknown; + interaction: (interaction: ModalSubmitInteraction, client: Client) => unknown; } >; }; @@ -82,10 +79,7 @@ declare module "discord.js" { /** Data about the command */ data: SlashCommandBuilder; /** How the command interact */ - interaction: ( - interaction: CommandInteraction, - client: Client - ) => unknown; + interaction: (interaction: CommandInteraction, client: Client) => unknown; } >; }; diff --git a/src/utils/client.ts b/src/utils/client.ts index 7a2a407..448b882 100644 --- a/src/utils/client.ts +++ b/src/utils/client.ts @@ -34,9 +34,7 @@ export default async () => { console.log("Translations progression :"); client.locales = await loadLocales(client.config.default_lang); - client.db = new Database( - `${process.env.DOCKERIZED === "1" ? "/config" : "./config"}/db.sqlite3` - ); + client.db = new Database(`${process.env.DOCKERIZED === "1" ? "/config" : "./config"}/db.sqlite3`); initDatabase(client.db); diff --git a/src/utils/locales.ts b/src/utils/locales.ts index 074b0cb..c98d6b4 100644 --- a/src/utils/locales.ts +++ b/src/utils/locales.ts @@ -52,20 +52,14 @@ export const loadLocales = async (default_lang: string) => { * @param text Name of string to fetch * @returns the dictionary */ -export const getLocalizations = ( - client: Client, - text: string, - lowercase = false -) => { +export const getLocalizations = (client: Client, text: string, lowercase = false) => { const data: Record = {}; // Load all the localizations client.locales.forEach((locale, lang) => { // Fetch the text and fallback to default lang if needed // See getLocale for more info on why we *can* fallback - let str = - locale.get(text) ?? - client.locales.get(client.config.default_lang)?.get(text); + let str = locale.get(text) ?? client.locales.get(client.config.default_lang)?.get(text); // Store it if defined if (str !== undefined) { @@ -114,10 +108,7 @@ export const getLocale = (client: Client, lang: string) => { * @param default_lang default lang * @returns void */ -const checkLocales = async ( - locales: Map>, - default_lang: string -) => { +const checkLocales = async (locales: Map>, default_lang: string) => { // Associate each lang with the number of locale it has let locales_size = new Map(); locales.forEach((locales_data, lang) => { @@ -125,9 +116,7 @@ const checkLocales = async ( }); // Sort the map - locales_size = new Map( - [...locales_size.entries()].sort((a, b) => b[1] - a[1]) - ); + locales_size = new Map([...locales_size.entries()].sort((a, b) => b[1] - a[1])); // Check if default lang is 100% const [max_size_name] = locales_size.keys(); @@ -177,9 +166,7 @@ const checkLocales = async ( const padding = " ".repeat(lang.length === 5 ? 1 : 4); console.log( - `${padding}${lang} | ${color()}${blocks}\x1b[0m${blank} | ${percentage.toPrecision( - 3 - )}%` + `${padding}${lang} | ${color()}${blocks}\x1b[0m${blank} | ${percentage.toPrecision(3)}%` ); }); }; diff --git a/src/utils/reminder.ts b/src/utils/reminder.ts index 1412cb5..9a24680 100644 --- a/src/utils/reminder.ts +++ b/src/utils/reminder.ts @@ -62,11 +62,7 @@ const splitTime = (time: string) => { * @param info data about the context of the reminder * @returns Promise resolution of the sql request */ -export const newReminder = async ( - client: Client, - time: string, - info: infoReminder -) => +export const newReminder = async (client: Client, time: string, info: infoReminder) => new Promise((ok, ko) => { const data = splitTime(time); const timeout = strToSeconds(data.time); @@ -107,11 +103,7 @@ export const newReminder = async ( * @param userId User ID who created the reminder * @returns what the SQlite request sended */ -export const deleteReminder = ( - client: Client, - createdAt: string, - userId: string -) => { +export const deleteReminder = (client: Client, createdAt: string, userId: string) => { // Delete the reminder for the database return new Promise((ok, ko) => { // Add the remind to the db @@ -130,11 +122,7 @@ export const deleteReminder = ( }); }; -export const sendReminder = ( - client: Client, - info: infoReminder, - option: OptionReminder -) => { +export const sendReminder = (client: Client, info: infoReminder, option: OptionReminder) => { const loc = getLocale(client, info.locale); // Send the message in the appropriate channel // TODO: Embed @@ -184,9 +172,7 @@ export const sendReminder = ( if (channel?.isTextBased()) { let content = `<@${info.userId}>`; embed.setFooter({ - text: `${loc.get("c_reminder17")} ${timeDeltaToString( - info.createdAt - )}`, + text: `${loc.get("c_reminder17")} ${timeDeltaToString(info.createdAt)}`, }); // Mention everybody if needed @@ -218,15 +204,13 @@ export const setTimeoutReminder = ( ) => { return Number( setTimeout(() => { - deleteReminder(client, String(info.createdAt), info.userId).then( - (val) => { - if (val != true) { - throw val; - } - - sendReminder(client, info, option); + deleteReminder(client, String(info.createdAt), info.userId).then((val) => { + if (val != true) { + throw val; } - ); + + sendReminder(client, info, option); + }); }, timeout * 1000) ); }; @@ -342,11 +326,7 @@ export const updateReminder = (client: Client, data: dbReminder) => { * @param guildId guild ID * @returns List of reminders of a user in a guild */ -const listReminders = async ( - client: Client, - userId: string, - guildId: string | null -) => { +const listReminders = async (client: Client, userId: string, guildId: string | null) => { return (await new Promise((ok, ko) => { // Check the ownership client.db.all( @@ -394,9 +374,7 @@ export const embedListReminders = async ( const embed = new EmbedBuilder() .setColor(Colors.DarkGrey) .setDescription( - `${loc.get("c_reminder5")} ${user} • ${loc.get( - "c_reminder6" - )} ${page}/${pageMax}` + `${loc.get("c_reminder5")} ${user} • ${loc.get("c_reminder6")} ${page}/${pageMax}` ) .setThumbnail(user.displayAvatarURL()); @@ -411,9 +389,7 @@ export const embedListReminders = async ( if (text.length > 1024) { text = `${text.substring(0, 1021)}...`; } - const expiration = `${loc.get("c_reminder8")} ${timeDeltaToString( - remind.expiration_date - )}`; + const expiration = `${loc.get("c_reminder8")} ${timeDeltaToString(remind.expiration_date)}`; embed.addFields({ name: `#${remind.id} • ${loc.get("c_reminder9")} ${showDate( local, diff --git a/src/utils/time.ts b/src/utils/time.ts index eb713f6..6c00351 100644 --- a/src/utils/time.ts +++ b/src/utils/time.ts @@ -5,11 +5,7 @@ * @param date Date * @returns String */ -export const showDate = ( - tz: string, - locale: Map, - date: Date -) => { +export const showDate = (tz: string, locale: Map, date: Date) => { return date.toLocaleString(tz).replace(" ", ` ${locale.get("u_time_at")} `); };