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

Function handler

plugins/searchcmd.ts:26–73  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

findSuggestionMethod · 0.80

Tested by

no test coverage detected