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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 51 by rakin, Mon Jul 29 17:28:23 2024 UTC revision 58 by rakin, Mon Jul 29 17:28:25 2024 UTC
# Line 1  Line 1 
1  import path from 'path';  import path from 'path';
2  import { promises as fs } from 'fs';  import { promises as fs } from 'fs';
3  import DiscordClient from '../client/Client';  import DiscordClient from '../client/Client';
4    import { registered, registrationStart } from './debug';
5    
6  export async function registerCommands(client: DiscordClient, dir: string = '') {  export async function registerCommands(client: DiscordClient, dir: string = '') {
7      const filePath = path.join(__dirname, dir);      const filePath = path.join(__dirname, dir);
# Line 10  export async function registerCommands(c Line 11  export async function registerCommands(c
11          const stat = await fs.lstat(path.join(filePath, file));          const stat = await fs.lstat(path.join(filePath, file));
12    
13          if (stat.isDirectory())          if (stat.isDirectory())
14              registerCommands(client, path.join(dir, file));              await registerCommands(client, path.join(dir, file));
15                    
16          if (file.endsWith('.js') || file.endsWith('.ts')) {          if (file.endsWith('.js') || file.endsWith('.ts')) {
17                const startTime = Date.now();
18              const { default: Command } = await import(path.join(dir, file));              const { default: Command } = await import(path.join(dir, file));
19              const command = new Command();              const command = new Command();
20    
21              client.commands.set(command.getName(), command);              client.commands.set(command.getName(), command);
22                
23              command.getAliases().forEach((alias: string) => {              command.getAliases().forEach((alias: string) => {
24                  client.commands.set(alias, command);                  client.commands.set(alias, command);
25              });              });
26    
27                const endTime = Date.now();
28    
29                registered(command, startTime, endTime);
30          }          }
31      }      }
32  }  }
# Line 33  export async function registerEvents(cli Line 39  export async function registerEvents(cli
39          const stat = await fs.lstat(path.join(filePath, file));          const stat = await fs.lstat(path.join(filePath, file));
40    
41          if (stat.isDirectory())          if (stat.isDirectory())
42              registerEvents(client, path.join(dir, file));              await registerEvents(client, path.join(dir, file));
43    
44          if (file.endsWith('.js') || file.endsWith('.ts')) {          if (file.endsWith('.js') || file.endsWith('.ts')) {
45                const startTime = Date.now();
46              const { default: Event } = await import(path.join(dir, file));              const { default: Event } = await import(path.join(dir, file));
47              const event = new Event();              const event = new Event();
48              client.events.set(event.getName(), event);              client.events.set(event.getName(), event);
49              client.on(event.getName(), event.run.bind(event, client));              client.on(event.getName(), event.run.bind(event, client));
50                const endTime = Date.now();
51                registered(event, startTime, endTime);
52          }          }
53      }      }
54  }  }

Legend:
Removed from v.51  
changed lines
  Added in v.58

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26