-
Notifications
You must be signed in to change notification settings - Fork 638
Expand file tree
/
Copy pathandroid1.js
More file actions
81 lines (81 loc) Β· 4.34 KB
/
Copy pathandroid1.js
File metadata and controls
81 lines (81 loc) Β· 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import pkg from 'api-qasim';
const QasimAny = pkg;
import axios from 'axios';
export default {
command: 'apkdl',
aliases: ['apk', 'an1apk', 'appdl', 'app'],
category: 'download',
description: 'Search APKs and download by reply',
usage: '.apkdl <apk_name>',
async handler(sock, message, args, context) {
const chatId = context.chatId || message.key.remoteJid;
const query = args.join(' ').trim();
try {
if (!query) {
return await sock.sendMessage(chatId, { text: '*Please provide an APK name.*\nExample: .apkdl Telegram' }, { quoted: message });
}
await sock.sendMessage(chatId, { text: 'π Searching for APKs...' }, { quoted: message });
const res = await QasimAny.apksearch(query);
if (!res?.data || !Array.isArray(res.data) || res.data.length === 0) {
return await sock.sendMessage(chatId, { text: 'β No APKs found.' }, { quoted: message });
}
const results = res.data;
const first = results[0];
let caption = `π± *APK Search Results for:* *${query}*\n\n`;
caption += `β©οΈ *Reply with a number to download*\n\n`;
results.forEach((item, i) => {
caption +=
`*${i + 1}.* ${item.judul}\n` +
`π¨βπ» Developer: ${item.dev}\n` +
`β Rating: ${item.rating}\n` +
`π ${item.link}\n\n`;
});
const sentMsg = await sock.sendMessage(chatId, { image: { url: first.thumb }, caption }, { quoted: message });
const timeout = setTimeout(async () => {
sock.ev.off('messages.upsert', listener);
await sock.sendMessage(chatId, { text: 'β± APK selection expired. Please search again.' }, { quoted: sentMsg });
}, 5 * 60 * 1000);
const listener = async ({ messages }) => {
const m = messages[0];
if (!m?.message || m.key.remoteJid !== chatId)
return;
const ctx = m.message?.extendedTextMessage?.contextInfo;
if (!ctx?.stanzaId || ctx.stanzaId !== sentMsg.key.id)
return;
const replyText = m.message.conversation ||
m.message.extendedTextMessage?.text ||
'';
const choice = parseInt(replyText.trim(), 10);
if (isNaN(choice) || choice < 1 || choice > results.length) {
return await sock.sendMessage(chatId, { text: `β Invalid choice. Pick 1-${results.length}.` }, { quoted: m });
}
clearTimeout(timeout);
sock.ev.off('messages.upsert', listener);
const selected = results[choice - 1];
await sock.sendMessage(chatId, { text: `β¬οΈ Downloading *${selected.judul}*...\nβ± Please wait...` }, { quoted: m });
const apiUrl = `https://discardapi.dpdns.org/api/apk/dl/android1?apikey=guru&url=${
encodeURIComponent(selected.link)}`;
const dlRes = await axios.get(apiUrl);
const apk = dlRes.data?.result;
if (!apk?.url) {
return await sock.sendMessage(chatId, { text: 'β Failed to get APK download link.' }, { quoted: m });
}
const safeName = apk.name.replace(/[^\w.-]/g, '_');
const apkCaption = `π¦ *APK Downloaded*\n\n` +
`π Name: ${apk.name}\n` +
`β Rating: ${apk.rating}\n` +
`π¦ Size: ${apk.size}\n` +
`π± Android: ${apk.requirement}\n` +
`π§ Age: ${apk.rated}\n` +
`π
Published: ${apk.published}\n\n` +
`π Description:\n${apk.description}`;
await sock.sendMessage(chatId, { document: { url: apk.url }, fileName: `${safeName}.apk`, mimetype: 'application/vnd.android.package-archive', caption: apkCaption }, { quoted: m });
};
sock.ev.on('messages.upsert', listener);
}
catch (err) {
console.error('β Android Plugin Error:', err);
await sock.sendMessage(chatId, { text: 'β Failed to process APK request.' }, { quoted: message });
}
}
};