/[sudobot]/trunk/src/utils/registry.ts
ViewVC logotype

Annotation of /trunk/src/utils/registry.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 51 - (hide annotations)
Mon Jul 29 17:28:23 2024 UTC (8 months, 1 week ago) by rakin
File MIME type: application/typescript
File size: 1563 byte(s)
Release version 2.0
1 rakin 51 import path from 'path';
2     import { promises as fs } from 'fs';
3     import DiscordClient from '../client/Client';
4    
5     export async function registerCommands(client: DiscordClient, dir: string = '') {
6     const filePath = path.join(__dirname, dir);
7     const files = await fs.readdir(filePath);
8    
9     for (const file of files) {
10     const stat = await fs.lstat(path.join(filePath, file));
11    
12     if (stat.isDirectory())
13     registerCommands(client, path.join(dir, file));
14    
15     if (file.endsWith('.js') || file.endsWith('.ts')) {
16     const { default: Command } = await import(path.join(dir, file));
17     const command = new Command();
18    
19     client.commands.set(command.getName(), command);
20    
21     command.getAliases().forEach((alias: string) => {
22     client.commands.set(alias, command);
23     });
24     }
25     }
26     }
27    
28     export async function registerEvents(client: DiscordClient, dir: string = '') {
29     const filePath = path.join(__dirname, dir);
30     const files = await fs.readdir(filePath);
31    
32     for (const file of files) {
33     const stat = await fs.lstat(path.join(filePath, file));
34    
35     if (stat.isDirectory())
36     registerEvents(client, path.join(dir, file));
37    
38     if (file.endsWith('.js') || file.endsWith('.ts')) {
39     const { default: Event } = await import(path.join(dir, file));
40     const event = new Event();
41     client.events.set(event.getName(), event);
42     client.on(event.getName(), event.run.bind(event, client));
43     }
44     }
45     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26