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

Method getCommand

lib/commandHandler.ts:233–269  ·  view source on GitHub ↗
(text: string, prefixes: string[])

Source from the content-addressed store, hash-verified

231 }
232
233 getCommand(text: string, prefixes: string[]) {
234 const usedPrefix = prefixes.find(p => text.startsWith(p));
235 const firstWord = text.trim().split(' ')[0].toLowerCase();
236
237 if (!usedPrefix) {
238 if (this.prefixlessCommands.has(firstWord)) {
239 const targetCmd = this.prefixlessCommands.get(firstWord);
240 return this.commands.get(targetCmd);
241 }
242 return null;
243 }
244
245 const fullCommand = text.slice(usedPrefix.length).trim().split(' ')[0].toLowerCase();
246
247 if (this.commands.has(fullCommand)) {
248 return this.commands.get(fullCommand);
249 }
250 if (this.aliases.has(fullCommand)) {
251 const mainCommand = this.aliases.get(fullCommand);
252 return this.commands.get(mainCommand);
253 }
254
255 const suggestion = this.findSuggestion(fullCommand);
256 if (suggestion) {
257 return {
258 command: suggestion,
259 handler: async (sock: any, message: any) => {
260 const chatId = message.key.remoteJid;
261 await sock.sendMessage(chatId, {
262 text: `❓ Did you mean *${usedPrefix}${suggestion}*?`
263 }, { quoted: message });
264 }
265 };
266 }
267
268 return null;
269 }
270
271 getCommandsByCategory(category: string) {
272 return this.categories.get(category.toLowerCase()) || [];

Callers 2

handleMessagesFunction · 0.80

Calls 1

findSuggestionMethod · 0.95

Tested by

no test coverage detected