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

Function handler

plugins/list.js:157–216  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

155 description: 'Show all commands',
156 usage: '.menu [command]',
157 async handler(sock, message, args, context) {
158 const { chatId, channelInfo } = context;
159 const prefix = config.prefixes[0];
160 const imagePath = path.join(process.cwd(), 'assets/thumb.png');
161 if (args.length) {
162 const searchTerm = args[0].toLowerCase();
163 let cmd = commandHandler.commands.get(searchTerm);
164 if (!cmd && commandHandler.aliases.has(searchTerm)) {
165 const mainCommand = commandHandler.aliases.get(searchTerm);
166 cmd = commandHandler.commands.get(mainCommand);
167 }
168 if (!cmd) {
169 return sock.sendMessage(chatId, {
170 text: `❌ Command "${args[0]}" not found.\n\nUse ${prefix}menu to see all commands.`,
171 ...channelInfo
172 }, { quoted: message });
173 }
174 const text = `╭━━━━━━━━━━━━━━⬣
175┃ 📌 *COMMAND INFO*
176
177┃ ⚡ *Command:* ${prefix}${cmd.command}
178┃ 📝 *Desc:* ${cmd.description || 'No description'}
179┃ 📖 *Usage:* ${cmd.usage || `${prefix}${cmd.command}`}
180┃ 🏷️ *Category:* ${cmd.category || 'misc'}
181┃ 🔖 *Aliases:* ${cmd.aliases?.length ? cmd.aliases.map((a) => prefix + a).join(', ') : 'None'}
182
183╰━━━━━━━━━━━━━━⬣`;
184 if (fs.existsSync(imagePath)) {
185 return sock.sendMessage(chatId, {
186 image: { url: imagePath },
187 caption: text,
188 ...channelInfo
189 }, { quoted: message });
190 }
191 return sock.sendMessage(chatId, { text, ...channelInfo }, { quoted: message });
192 }
193 const style = pick(menuStyles);
194 const text = style.render({
195 title: config.botName,
196 prefix,
197 info: {
198 bot: config.botName,
199 prefix: config.prefixes.join(', '),
200 total: commandHandler.commands.size,
201 version: config.version || "6.0.0",
202 time: formatTime()
203 },
204 categories: commandHandler.categories
205 });
206 if (fs.existsSync(imagePath)) {
207 await sock.sendMessage(chatId, {
208 image: { url: imagePath },
209 caption: text,
210 ...channelInfo
211 }, { quoted: message });
212 }
213 else {
214 await sock.sendMessage(chatId, { text, ...channelInfo }, { quoted: message });

Callers

nothing calls this directly

Calls 3

pickFunction · 0.85
renderMethod · 0.80
formatTimeFunction · 0.70

Tested by

no test coverage detected