PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 1 | import type { SlashCommandSubcommandGroupBuilder } from "@discordjs/builders"; |
| 2 | import type { SlashCommandBuilder } from "discord.js"; |
| 3 | import config from "../../config/main.json" assert { type: "json" }; |
| 4 | import getSubcommandsInFolder from "./getFilesInFolder.js"; |
| 5 | |
| 6 | |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame^] | 7 | const colours = { |
| 8 | red: "\x1b[31m", |
| 9 | green: "\x1b[32m", |
| 10 | none: "\x1b[0m" |
| 11 | } |
| 12 | |
| 13 | |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 14 | export async function group(name: string, description: string, path: string) { |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame^] | 15 | 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}`) |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 18 | 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 | |
| 31 | export async function command(name: string, description: string, path: string) { |
| 32 | const fetched = await getSubcommandsInFolder(config.commandsFolder + "/" + path); |
PineaFan | 752af46 | 2022-12-31 21:59:38 +0000 | [diff] [blame^] | 33 | 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}`) |
PineaFan | 64486c4 | 2022-12-28 09:21:04 +0000 | [diff] [blame] | 34 | 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 | } |