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

Function handler

plugins/quran.js:34–119  ·  view source on GitHub ↗
(sock, message, args, context)

Source from the content-addressed store, hash-verified

32 description: 'Search Quran verses by surah:ayah or keyword',
33 usage: '.quran 1:1\n.quran 2:255\n.quran mercy',
34 async handler(sock, message, args, context) {
35 const { chatId, channelInfo } = context;
36 const input = args.join(' ').trim();
37 if (!input) {
38 return await sock.sendMessage(chatId, {
39 text: `📖 *Quran*\n\n` +
40 `*By Surah:Ayah:*\n` +
41 `\`.quran 1:1\` — Al-Fatihah, verse 1\n` +
42 `\`.quran 2:255\` — Ayat Al-Kursi\n` +
43 `\`.quran 36:1\` — Ya-Sin, verse 1\n\n` +
44 `*By keyword:*\n` +
45 `\`.quran mercy\`\n` +
46 `\`.quran patience\`\n` +
47 `\`.quran paradise\`\n\n` +
48 `*Full Surah:*\n` +
49 `\`.surah 1\` — Al-Fatihah\n` +
50 `\`.surah 112\` — Al-Ikhlas`,
51 ...channelInfo
52 }, { quoted: message });
53 }
54 try {
55 // Check if surah:ayah format
56 if (/^\d+:\d+$/.test(input)) {
57 const [surah, ayah] = input.split(':');
58 const [arRes, enRes] = await Promise.all([
59 axios.get(`${BASE}/ayah/${input}/quran-uthmani`),
60 axios.get(`${BASE}/ayah/${input}/en.asad`)
61 ]);
62 const ar = arRes.data.data;
63 const en = enRes.data.data;
64 const surahName = SURAH_NAMES[parseInt(surah, 10)] || ar.surah?.englishName;
65 await sock.sendMessage(chatId, {
66 text: `📖 *Surah ${surahName} — Ayah ${ayah}*\n\n` +
67 `*Arabic:*\n${ar.text}\n\n` +
68 `*Translation (Asad):*\n_${en.text}_\n\n` +
69 `📍 Surah: ${surah} | Ayah: ${ayah} | Juz: ${ar.juz} | Page: ${ar.page}`,
70 ...channelInfo
71 }, { quoted: message });
72 }
73 else if (/^\d+$/.test(input) || input.toLowerCase().startsWith('surah')) {
74 // Full surah
75 const num = input.replace(/[^0-9]/g, '') || '1';
76 const res = await axios.get(`${BASE}/surah/${num}/en.asad`);
77 const data = res.data.data;
78 const arRes = await axios.get(`${BASE}/surah/${num}/quran-uthmani`);
79 const arData = arRes.data.data;
80 const verses = data.ayahs.slice(0, 7).map((a, i) => `*${i + 1}.* ${arData.ayahs[i]?.text || ''}\n_${a.text}_`).join('\n\n');
81 await sock.sendMessage(chatId, {
82 text: `📖 *Surah ${data.englishName} (${data.name})*\n` +
83 `_${data.englishNameTranslation}_ — ${data.numberOfAyahs} verses — ${data.revelationType}\n\n` +
84 `${verses}\n\n` +
85 `_Showing first 7 of ${data.numberOfAyahs} verses_\n` +
86 `Use \`.quran ${num}:8\` for more`,
87 ...channelInfo
88 }, { quoted: message });
89 }
90 else {
91 // Keyword search

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected