MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MDX / loadCommands

Method loadCommands

lib/commandHandler.ts:59–84  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

57 }
58
59 async loadCommands() {
60 const pluginsPath = path.join(process.cwd(), 'dist/plugins');
61 const files = fs.readdirSync(pluginsPath).filter(f => f.endsWith('.js'));
62
63 for (const file of files) {
64 try {
65 const filePath = path.join(pluginsPath, file);
66 const plugin = (await import(pathToFileURL(filePath).href)).default || (await import(pathToFileURL(filePath).href));
67
68 if (plugin.command) {
69 this.registerCommand(plugin);
70 if (plugin.isPrefixless === true) {
71 const cmdKey = plugin.command.toLowerCase();
72 this.prefixlessCommands.set(cmdKey, cmdKey);
73 if (plugin.aliases && Array.isArray(plugin.aliases)) {
74 plugin.aliases.forEach((alias: string) => {
75 this.prefixlessCommands.set(alias.toLowerCase(), cmdKey);
76 });
77 }
78 }
79 }
80 } catch(error: any) {
81 console.error(`Error loading ${file}:`, error.message);
82 }
83 }
84 }
85
86 registerCommand(plugin: any) {
87 const { command, aliases = [], category = 'misc', handler } = plugin;

Callers 2

reloadCommandsMethod · 0.95
mainFunction · 0.80

Calls 1

registerCommandMethod · 0.95

Tested by

no test coverage detected