blob: c7ac55fd4e2ebb8cdd1391476c3d9163d98f2841 [file] [log] [blame]
PineaFan64486c42022-12-28 09:21:04 +00001import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders";
2import type { SlashCommandBuilder } from "discord.js";
3import config from "../../config/main.json" assert { type: "json" };
4import getSubcommandsInFolder from "./getFilesInFolder.js";
5
6
PineaFan752af462022-12-31 21:59:38 +00007const colours = {
8 red: "\x1b[31m",
9 green: "\x1b[32m",
10 none: "\x1b[0m"
11}
12
13
PineaFan64486c42022-12-28 09:21:04 +000014export async function group(name: string, description: string, path: string) {
PineaFan752af462022-12-31 21:59:38 +000015 console.log(`│ ├─ Loading group ${name}`)
16 const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path, "│ ")
17 console.log(`│ │ └─ ${fetched.errors ? colours.red : colours.green}Loaded ${fetched.subcommands.length} subcommands for ${name} (${fetched.errors} failed)${colours.none}`)
PineaFan64486c42022-12-28 09:21:04 +000018 return (subcommandGroup: SlashCommandSubcommandGroupBuilder) => {
19 subcommandGroup
20 .setName(name)
21 .setDescription(description)
22
23 for (const subcommand of fetched.subcommands) {
24 subcommandGroup.addSubcommand(subcommand);
25 };
26
27 return subcommandGroup;
28 };
29}
30
31export async function command(name: string, description: string, path: string) {
32 const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path);
PineaFan752af462022-12-31 21:59:38 +000033 console.log(`│ ├─ ${fetched.errors ? colours.red : colours.green}Loaded ${fetched.subcommands.length} subcommands and ${fetched.subcommandGroups.length} subcommand groups for ${name} (${fetched.errors} failed)${colours.none}`)
PineaFan64486c42022-12-28 09:21:04 +000034 return (command: SlashCommandBuilder) => {
35 command.setName(name)
36 command.setDescription(description)
37
38 for (const subcommand of fetched.subcommands) {
39 command.addSubcommand(subcommand);
40 }
41 for (const group of fetched.subcommandGroups) {
42 command.addSubcommandGroup(group);
43 };
44 return command;
45 };
46}