3 |
import DiscordClient from '../client/Client'; |
import DiscordClient from '../client/Client'; |
4 |
import { registered, registrationStart } from './debug'; |
import { registered, registrationStart } from './debug'; |
5 |
|
|
6 |
|
export async function registerCLICommands(client: DiscordClient, dir: string = '') { |
7 |
|
const filePath = path.join(__dirname, dir); |
8 |
|
const files = await fs.readdir(filePath); |
9 |
|
|
10 |
|
for (const file of files) { |
11 |
|
const stat = await fs.lstat(path.join(filePath, file)); |
12 |
|
|
13 |
|
if (stat.isDirectory()) |
14 |
|
await registerCLICommands(client, path.join(dir, file)); |
15 |
|
|
16 |
|
if (file.endsWith('.js') || file.endsWith('.ts')) { |
17 |
|
const { default: Command } = await import(path.join(dir, file)); |
18 |
|
const command = new Command(); |
19 |
|
|
20 |
|
client.cliCommands.set(command.getName(), command); |
21 |
|
|
22 |
|
command.getAliases().forEach((alias: string) => { |
23 |
|
client.cliCommands.set(alias, command); |
24 |
|
}); |
25 |
|
} |
26 |
|
} |
27 |
|
} |
28 |
|
|
29 |
export async function registerCommands(client: DiscordClient, dir: string = '') { |
export async function registerCommands(client: DiscordClient, dir: string = '') { |
30 |
const filePath = path.join(__dirname, dir); |
const filePath = path.join(__dirname, dir); |
31 |
const files = await fs.readdir(filePath); |
const files = await fs.readdir(filePath); |