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

Function handler

plugins/android1.ts:13–105  ·  view source on GitHub ↗
(sock: any, message: any, args: any, context: BotContext)

Source from the content-addressed store, hash-verified

11 usage: '.apkdl <apk_name>',
12
13 async handler(sock: any, message: any, args: any, context: BotContext) {
14 const chatId = context.chatId || message.key.remoteJid;
15 const query = args.join(' ').trim();
16
17 try {
18 if (!query) {
19 return await sock.sendMessage(chatId, { text: '*Please provide an APK name.*\nExample: .apkdl Telegram' }, { quoted: message });
20 }
21
22 await sock.sendMessage(chatId, { text: '🔎 Searching for APKs...' }, { quoted: message });
23
24 const res = await QasimAny.apksearch(query);
25
26 if (!res?.data || !Array.isArray(res.data) || res.data.length === 0) {
27 return await sock.sendMessage(chatId, { text: '❌ No APKs found.' }, { quoted: message });
28 }
29
30 const results = res.data;
31 const first = results[0];
32
33 let caption = `📱 *APK Search Results for:* *${query}*\n\n`;
34 caption += `↩️ *Reply with a number to download*\n\n`;
35
36 results.forEach((item: any, i: number) => {
37 caption +=
38 `*${i + 1}.* ${item.judul}\n` +
39 `👨‍💻 Developer: ${item.dev}\n` +
40 `⭐ Rating: ${item.rating}\n` +
41 `🔗 ${item.link}\n\n`;
42 });
43
44 const sentMsg = await sock.sendMessage(chatId, { image: { url: first.thumb }, caption }, { quoted: message });
45
46 const timeout = setTimeout(async () => {
47 sock.ev.off('messages.upsert', listener);
48 await sock.sendMessage(chatId, { text: '⏱ APK selection expired. Please search again.' }, { quoted: sentMsg });
49 }, 5 * 60 * 1000);
50
51 const listener = async ({ messages }: { messages: any[] }) => {
52 const m = messages[0];
53 if (!m?.message || m.key.remoteJid !== chatId) return;
54
55 const ctx = m.message?.extendedTextMessage?.contextInfo;
56 if (!ctx?.stanzaId || ctx.stanzaId !== sentMsg.key.id) return;
57
58 const replyText =
59 m.message.conversation ||
60 m.message.extendedTextMessage?.text ||
61 '';
62
63 const choice = parseInt(replyText.trim(), 10);
64 if (isNaN(choice) || choice < 1 || choice > results.length) {
65 return await sock.sendMessage(chatId, { text: `❌ Invalid choice. Pick 1-${results.length}.` }, { quoted: m });
66 }
67
68 clearTimeout(timeout);
69 sock.ev.off('messages.upsert', listener);
70

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected