Skip to content

Commit 07356b6

Browse files
committed
feat: add commands barrel export
1 parent 29ad085 commit 07356b6

1 file changed

Lines changed: 9 additions & 63 deletions

File tree

src/commands/index.ts

Lines changed: 9 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,9 @@
1-
import type { CommandInteraction, RESTPostAPIApplicationCommandsJSONBody } from 'discord.js';
2-
import { z } from 'zod';
3-
import type { StructurePredicate } from '../util/loaders.js';
4-
5-
export type Command = {
6-
/**
7-
* The data for the command
8-
*/
9-
data: RESTPostAPIApplicationCommandsJSONBody;
10-
/**
11-
* The function execute when the command is called
12-
*
13-
* @param interaction - The interaction that triggered the command
14-
*/
15-
execute: (interaction: CommandInteraction) => Promise<void> | void;
16-
17-
__isCommand__: true;
18-
};
19-
20-
/**
21-
* Defines a schema for a command
22-
*/
23-
export const schema = z.object({
24-
data: z.custom<RESTPostAPIApplicationCommandsJSONBody>(),
25-
execute: z.function(),
26-
__isCommand__: z.literal(true),
27-
});
28-
29-
/**
30-
* Defines the predicate to check if an object is a Command
31-
*/
32-
export const predicate: StructurePredicate<Command> = (obj: unknown): obj is Command =>
33-
schema.safeParse(obj).success;
34-
35-
/**
36-
*
37-
* Creates a command object
38-
*
39-
* @param data - The command data
40-
* @param execute - The function to execute when the command is called
41-
* @returns
42-
*/
43-
export const createCommand = (
44-
data: RESTPostAPIApplicationCommandsJSONBody,
45-
execute: (interaction: CommandInteraction) => Promise<void> | void
46-
): Command => {
47-
return { data, execute, __isCommand__: true } satisfies Command;
48-
};
49-
50-
/**
51-
* Creates multiple commands
52-
*
53-
* @param commands - An array of command data and execute functions
54-
* @returns
55-
*/
56-
export const createCommands = (
57-
commands: Array<{
58-
data: RESTPostAPIApplicationCommandsJSONBody;
59-
execute: (interaction: CommandInteraction) => Promise<void> | void;
60-
}>
61-
): Command[] => {
62-
return commands.map(({ data, execute }) => createCommand(data, execute));
63-
};
1+
import { docsCommands } from './docs/index.js';
2+
import { guidesCommand } from './guides/index.js';
3+
import { pingCommand } from './ping.js';
4+
import { tipsCommands } from './tips/index.js';
5+
import type { Command } from './types.js';
6+
7+
export const commands = new Map<string, Command>(
8+
[pingCommand, guidesCommand, docsCommands, tipsCommands].flat().map((cmd) => [cmd.data.name, cmd])
9+
);

0 commit comments

Comments
 (0)