forked from Guru322/GURU-Ai
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGita-verse.js
50 lines (37 loc) · 1.31 KB
/
Gita-verse.js
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
import fetch from 'node-fetch';
let gitaVerseHandler = async (m, { conn }) => {
try {
// Extract the verse number from the command text.
let verseNumber = m.text.split(' ')[1];
if (!verseNumber || isNaN(verseNumber)) {
verseNumber = Math.floor(Math.random() * 700) + 1;
}
let res = await fetch(`https://gita-api.vercel.app/odi/verse/${verseNumber}`);
if (!res.ok) {
let error = await res.json();
throw new Error(`API request failed with status ${res.status} and message ${error.detail[0].msg}`);
}
let json = await res.json();
console.log('JSON response:', json);
let gitaVerse = `
🕉 *Bhagavad Gita: Sacred Teachings*\n
📜 *Chapter ${json.chapter_no}: ${json.chapter_name}*\n
Verse ${json.verse_no}:\n
" ${json.verse} "\n
*🔮 Translation:*\n
${json.translation}\n
*🧘♂️ Spiritual Insight (Purport):*\n
${json.purport}`;
m.reply(gitaVerse);
if (json.audio_link) {
conn.sendFile(m.chat, json.audio_link, 'audio.mp3', null, m, true, { type: 'audioMessage', ptt: true });
}
} catch (error) {
console.error(error);
// Handle the error appropriately
}
};
gitaVerseHandler.help = ['gita [verse_number]'];
gitaVerseHandler.tags = ['religion'];
gitaVerseHandler.command = ['gita', 'verse']
export default gitaVerseHandler;