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

Function handler

plugins/list.ts:183–252  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

181 usage: '.menu [command]',
182
183 async handler(sock: any, message: any, args: any, context: BotContext) {
184 const { chatId, channelInfo } = context;
185 const prefix = config.prefixes[0];
186 const imagePath = path.join(process.cwd(), 'assets/thumb.png');
187
188 if (args.length) {
189 const searchTerm = args[0].toLowerCase();
190
191 let cmd = commandHandler.commands.get(searchTerm);
192
193 if (!cmd && commandHandler.aliases.has(searchTerm)) {
194 const mainCommand = commandHandler.aliases.get(searchTerm);
195 cmd = commandHandler.commands.get(mainCommand);
196 }
197
198 if (!cmd) {
199 return (sock as any).sendMessage(chatId, {
200 text: `❌ Command "${args[0]}" not found.\n\nUse ${prefix}menu to see all commands.`,
201 ...channelInfo
202 }, { quoted: message });
203 }
204
205 const text =
206`╭━━━━━━━━━━━━━━⬣
207┃ 📌 *COMMAND INFO*
208┃
209┃ ⚡ *Command:* ${prefix}${cmd.command}
210┃ 📝 *Desc:* ${cmd.description || 'No description'}
211┃ 📖 *Usage:* ${cmd.usage || `${prefix}${cmd.command}`}
212┃ 🏷️ *Category:* ${cmd.category || 'misc'}
213┃ 🔖 *Aliases:* ${cmd.aliases?.length ? cmd.aliases.map((a: string) => prefix + a).join(', ') : 'None'}
214┃
215╰━━━━━━━━━━━━━━⬣`;
216
217 if (fs.existsSync(imagePath)) {
218 return (sock as any).sendMessage(chatId, {
219 image: { url: imagePath },
220 caption: text,
221 ...channelInfo
222 }, { quoted: message });
223 }
224
225 return (sock as any).sendMessage(chatId, { text, ...channelInfo } as any, { quoted: message });
226 }
227
228 const style = pick(menuStyles);
229
230 const text = style.render({
231 title: config.botName,
232 prefix,
233 info: {
234 bot: config.botName,
235 prefix: config.prefixes.join(', '),
236 total: commandHandler.commands.size,
237 version: config.version || "6.0.0",
238 time: formatTime()
239 },
240 categories: commandHandler.categories

Callers

nothing calls this directly

Calls 3

renderMethod · 0.80
pickFunction · 0.70
formatTimeFunction · 0.70

Tested by

no test coverage detected