increase lines char limit

This commit is contained in:
Mylloon 2023-01-17 22:35:21 +01:00
parent 983333238f
commit b2325410f4
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
22 changed files with 124 additions and 389 deletions

View file

@ -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",

View file

@ -1 +1 @@
{}
{ "printWidth": 100 }

View file

@ -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 */

View file

@ -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);

View file

@ -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;

View file

@ -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;

View file

@ -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),
{
await rest.put(Routes.applicationGuildCommands(client.user?.id as string, guild), {
body: command,
}
)
})
);
// Send global commands to Discord

View file

@ -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: [

View file

@ -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
),
],
});

View file

@ -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({

View file

@ -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,

View file

@ -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<ModalActionRowComponentBuilder>().addComponents(
timeGUI
),
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(
messageGUI
)
new ActionRowBuilder<ModalActionRowComponentBuilder>().addComponents(timeGUI),
new ActionRowBuilder<ModalActionRowComponentBuilder>().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,

View file

@ -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;
}

View file

@ -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({

View file

@ -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));

View file

@ -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);

View file

@ -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,
{
newReminder(client, interaction.fields.fields.get("reminderGUI-time")?.value as string, {
locale: interaction.locale,
message:
interaction.fields.fields.get("reminderGUI-message")?.value ?? null,
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) =>
}).then((msg) =>
interaction.reply({
content: msg as string,
ephemeral: true,

View file

@ -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;
}
>;
};

View file

@ -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);

View file

@ -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<string, string> = {};
// 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<string, Map<string, string>>,
default_lang: string
) => {
const checkLocales = async (locales: Map<string, Map<string, string>>, default_lang: string) => {
// Associate each lang with the number of locale it has
let locales_size = new Map<string, number>();
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)}%`
);
});
};

View file

@ -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) => {
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,

View file

@ -5,11 +5,7 @@
* @param date Date
* @returns String
*/
export const showDate = (
tz: string,
locale: Map<string, unknown>,
date: Date
) => {
export const showDate = (tz: string, locale: Map<string, unknown>, date: Date) => {
return date.toLocaleString(tz).replace(" ", ` ${locale.get("u_time_at")} `);
};