feat: Reminders #44

Merged
Anri merged 54 commits from feat/reminders into main 2023-01-17 12:15:15 +01:00
4 changed files with 75 additions and 2 deletions
Showing only changes of commit 0299770ec1 - Show all commits

36
src/buttons/loader.ts Normal file
View file

@ -0,0 +1,36 @@
import { readdir } from 'fs/promises';
import { removeExtension } from '../utils/misc';
import { Client } from 'discord.js';
export default async (client: Client) => {
// Dossier des buttons
const buttons_categories = (await readdir(__dirname))
.filter(element => !element.endsWith('.js') && !element.endsWith('.ts'));
await Promise.all(
// For each categorie
buttons_categories.map(async buttons_category => {
// Retrieve all the commands
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),
);
// Add the button
return Promise.all(
button_files.map(async button_file => {
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);
return button.data;
}),
);
}),
);
};

View file

@ -1,6 +1,7 @@
import loadClient, { quit } from './utils/client';
import loadEvents from './events/loader';
import loadModals from './modals/loader';
import loadButtons from './buttons/loader';
import loadCommands from './commands/loader';
import { logStart } from './utils/misc';
@ -41,6 +42,15 @@ const run = async () => {
throw logStart(modals_name, false);
});
// Buttons Discord.JS
const buttons_name = 'Buttons';
await loadButtons(client)
.then(() => console.log(logStart(buttons_name, true)))
.catch((err) => {
console.error(err);
throw logStart(buttons_name, false);
});
// Commands Slash Discord.JS
const commands_name = 'Commands';
await loadCommands(client)

View file

@ -2,7 +2,7 @@ import { Collection } from 'discord.js';
import { SlashCommandBuilder } from '@discordjs/builders';
import { Database } from 'sqlite3';
export {};
export { };
declare module 'discord.js' {
// eslint-disable-next-line no-shadow
@ -37,7 +37,29 @@ declare module 'discord.js' {
interaction: (interaction: ModalSubmitInteraction, client: Client) => unknown
}
>,
},
/** Store all the buttons */
buttons: {
categories: Collection<
/** Category name */
string,
/** Name of the buttons in the category */
string[]
>,
list: Collection<
/** Button name */
string,
/** Button itself */
{
/** Data about the button */
data: {
name: string
},
/** How the button interact */
interaction: (interaction: ButtonInteraction, client: Client) => unknown
}
>,
},
/** Store all the slash commands */
commands: {
categories: Collection<

View file

@ -24,6 +24,11 @@ export default async () => {
list: new Collection(),
};
client.buttons = {
categories: new Collection(),
list: new Collection(),
};
client.commands = {
categories: new Collection(),
list: new Collection(),