MCPcopy Create free account
hub / github.com/GlobalTechInfo/MEGA-MD / handler

Function handler

plugins/searchcmd.js:22–60  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

20 description: 'Find a command by keyword or description',
21 usage: '.find [keyword]',
22 async handler(sock, message, args, context) {
23 const chatId = context.chatId || message.key.remoteJid;
24 const query = args.join(' ').toLowerCase();
25 if (!query) {
26 return await sock.sendMessage(chatId, { text: 'What are you looking for? Example: *.find status*' }, { quoted: message });
27 }
28 try {
29 const allCommands = Array.from(CommandHandler.commands.values());
30 const results = allCommands.filter(commandObject => {
31 const nameMatch = commandObject.command?.toLowerCase().includes(query);
32 const descMatch = commandObject.description?.toLowerCase().includes(query);
33 const aliasMatch = commandObject.aliases?.some((a) => a.toLowerCase().includes(query));
34 return nameMatch || descMatch || aliasMatch;
35 });
36 if (results.length === 0) {
37 const suggestion = CommandHandler.findSuggestion(query);
38 let failText = `❌ No commands found matching *"${query}"*`;
39 if (suggestion)
40 failText += `\n\nDid you mean: *.${suggestion}*?`;
41 return await sock.sendMessage(chatId, { text: failText }, { quoted: message });
42 }
43 let resultText = `🔍 *SEARCH RESULTS FOR:* "${query.toUpperCase()}"\n\n`;
44 results.forEach((res, index) => {
45 const status = CommandHandler.disabledCommands.has(res.command.toLowerCase()) ? '🔸' : '🔹';
46 resultText += `${index + 1}. ${status} *.${res.command}*\n`;
47 resultText += `📝 _${res.description || 'No description available.'}_\n`;
48 if (res.aliases && res.aliases.length > 0) {
49 resultText += `🔗 Aliases: ${res.aliases.join(', ')}\n`;
50 }
51 resultText += `\n`;
52 });
53 resultText += `💡 _Tip: Use the prefix before the command name to run it._`;
54 await sock.sendMessage(chatId, { text: resultText }, { quoted: message });
55 }
56 catch (error) {
57 console.error('Search Error:', error);
58 await sock.sendMessage(chatId, { text: '❌ An error occurred during the search.' });
59 }
60 }
61};
62/*****************************************************************************
63 * *

Callers

nothing calls this directly

Calls 1

findSuggestionMethod · 0.80

Tested by

no test coverage detected