jsdecryptor 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Database/database.js +446 -0
- package/Database/migration.js +327 -0
- package/Database/pgSync.js +229 -0
- package/Database/settingsStore.js +305 -0
- package/config.js +32 -0
- package/dave.js +3063 -0
- package/davelib/antibadword.js +278 -0
- package/davelib/antilink.js +88 -0
- package/davelib/antilinkHelper.js +48 -0
- package/davelib/botConfig.js +71 -0
- package/davelib/connect4.js +111 -0
- package/davelib/converter.js +89 -0
- package/davelib/dicegame.js +114 -0
- package/davelib/exif.js +138 -0
- package/davelib/fakeContact.js +85 -0
- package/davelib/fontStyles.js +237 -0
- package/davelib/greetings.js +47 -0
- package/davelib/id.js +11 -0
- package/davelib/index.js +577 -0
- package/davelib/isAdmin.js +32 -0
- package/davelib/isBanned.js +12 -0
- package/davelib/isOwner.js +15 -0
- package/davelib/lightweight_store.js +169 -0
- package/davelib/messageConfig.js +15 -0
- package/davelib/messageHandler.js +87 -0
- package/davelib/myfunc.js +379 -0
- package/davelib/myfunc2.js +170 -0
- package/davelib/reactions.js +180 -0
- package/davelib/server.html +563 -0
- package/davelib/sticker.js +208 -0
- package/davelib/tempCleanup.js +53 -0
- package/davelib/tictactoe.js +104 -0
- package/davelib/uploadImage.js +100 -0
- package/davelib/uploader.js +110 -0
- package/davelib/welcome.js +100 -0
- package/davelib/wordchain.js +121 -0
- package/daveset.js +16 -0
- package/davexcore/ai/ai.js +100 -0
- package/davexcore/ai/aiGpt4.js +59 -0
- package/davexcore/ai/aimodels.js +284 -0
- package/davexcore/ai/aivideo.js +31 -0
- package/davexcore/ai/analyze.js +233 -0
- package/davexcore/ai/bard.js +101 -0
- package/davexcore/ai/bird.js +101 -0
- package/davexcore/ai/blackbox.js +30 -0
- package/davexcore/ai/character.js +80 -0
- package/davexcore/ai/copilot.js +58 -0
- package/davexcore/ai/dalle.js +39 -0
- package/davexcore/ai/davex.js +50 -0
- package/davexcore/ai/deepseek.js +96 -0
- package/davexcore/ai/grok.js +67 -0
- package/davexcore/ai/imagine.js +89 -0
- package/davexcore/ai/meta.js +82 -0
- package/davexcore/ai/mistral.js +101 -0
- package/davexcore/ai/perplexity.js +95 -0
- package/davexcore/ai/sora.js +44 -0
- package/davexcore/ai/speechwriter.js +46 -0
- package/davexcore/ai/vision.js +244 -0
- package/davexcore/ai/wormgpt.js +56 -0
- package/davexcore/anti/antiaudio.js +106 -0
- package/davexcore/anti/antibadword.js +313 -0
- package/davexcore/anti/antibug.js +156 -0
- package/davexcore/anti/anticall.js +219 -0
- package/davexcore/anti/antichart.js +280 -0
- package/davexcore/anti/antidelete.js +673 -0
- package/davexcore/anti/antideletestatus.js +535 -0
- package/davexcore/anti/antidemote.js +352 -0
- package/davexcore/anti/antidocument.js +105 -0
- package/davexcore/anti/antiedit.js +410 -0
- package/davexcore/anti/antifiles.js +109 -0
- package/davexcore/anti/antigroupmention.js +206 -0
- package/davexcore/anti/antiimage.js +105 -0
- package/davexcore/anti/antikick.js +125 -0
- package/davexcore/anti/antilink.js +237 -0
- package/davexcore/anti/antimention.js +143 -0
- package/davexcore/anti/antipromote.js +320 -0
- package/davexcore/anti/antisticker.js +105 -0
- package/davexcore/anti/antitag.js +191 -0
- package/davexcore/anti/antivideo.js +105 -0
- package/davexcore/anti/antiviewonce.js +396 -0
- package/davexcore/anti/groupanticall.js +262 -0
- package/davexcore/anti/mention.js +242 -0
- package/davexcore/automation/alwaysonline.js +226 -0
- package/davexcore/automation/autoReadReciepts.js +96 -0
- package/davexcore/automation/autoread.js +104 -0
- package/davexcore/automation/autorecording.js +197 -0
- package/davexcore/automation/autostatus.js +317 -0
- package/davexcore/automation/autotyping.js +197 -0
- package/davexcore/automation/chatbot.js +444 -0
- package/davexcore/automation/chatmanage.js +199 -0
- package/davexcore/automation/devReact.js +43 -0
- package/davexcore/automation/goodbye.js +181 -0
- package/davexcore/automation/greetings.js +154 -0
- package/davexcore/automation/welcome.js +187 -0
- package/davexcore/downloads/apk.js +157 -0
- package/davexcore/downloads/facebook.js +94 -0
- package/davexcore/downloads/gitclone.js +137 -0
- package/davexcore/downloads/igs.js +333 -0
- package/davexcore/downloads/instagram.js +133 -0
- package/davexcore/downloads/mediafire.js +144 -0
- package/davexcore/downloads/pinterest.js +38 -0
- package/davexcore/downloads/play.js +158 -0
- package/davexcore/downloads/saveStatus.js +3 -0
- package/davexcore/downloads/song.js +135 -0
- package/davexcore/downloads/spotify.js +133 -0
- package/davexcore/downloads/tiktok.js +167 -0
- package/davexcore/downloads/tiktokaudio.js +158 -0
- package/davexcore/downloads/video.js +188 -0
- package/davexcore/downloads/ytdl.js +252 -0
- package/davexcore/downloads/ytdocplay.js +130 -0
- package/davexcore/downloads/ytdocvideo.js +95 -0
- package/davexcore/downloads/yts.js +64 -0
- package/davexcore/games/connect4.js +267 -0
- package/davexcore/games/dice.js +286 -0
- package/davexcore/games/eightball.js +24 -0
- package/davexcore/games/hangman.js +60 -0
- package/davexcore/games/rps.js +25 -0
- package/davexcore/games/ship.js +36 -0
- package/davexcore/games/slot.js +21 -0
- package/davexcore/games/tictactoe.js +263 -0
- package/davexcore/games/trivia.js +46 -0
- package/davexcore/games/wordchain.js +242 -0
- package/davexcore/group/addmember.js +101 -0
- package/davexcore/group/ban.js +63 -0
- package/davexcore/group/blockUnblock.js +177 -0
- package/davexcore/group/clear.js +196 -0
- package/davexcore/group/creategroup.js +43 -0
- package/davexcore/group/demote.js +115 -0
- package/davexcore/group/disappear.js +67 -0
- package/davexcore/group/groupinfo.js +167 -0
- package/davexcore/group/groupmanage.js +133 -0
- package/davexcore/group/hidetag.js +108 -0
- package/davexcore/group/joinrequests.js +145 -0
- package/davexcore/group/kick.js +92 -0
- package/davexcore/group/kickall.js +63 -0
- package/davexcore/group/leave.js +38 -0
- package/davexcore/group/linkgroup.js +63 -0
- package/davexcore/group/mute.js +57 -0
- package/davexcore/group/online.js +117 -0
- package/davexcore/group/pmblocker.js +65 -0
- package/davexcore/group/promote.js +93 -0
- package/davexcore/group/resetlink.js +57 -0
- package/davexcore/group/staff.js +99 -0
- package/davexcore/group/tag.js +111 -0
- package/davexcore/group/tagadmins.js +88 -0
- package/davexcore/group/tagall.js +99 -0
- package/davexcore/group/tagnotadmin.js +92 -0
- package/davexcore/group/topmembers.js +202 -0
- package/davexcore/group/unban.js +64 -0
- package/davexcore/group/unmute.js +45 -0
- package/davexcore/group/warn.js +83 -0
- package/davexcore/group/warnings.js +26 -0
- package/davexcore/media/anime.js +130 -0
- package/davexcore/media/attp.js +127 -0
- package/davexcore/media/design.js +52 -0
- package/davexcore/media/emojimix.js +105 -0
- package/davexcore/media/getpp.js +108 -0
- package/davexcore/media/image.js +87 -0
- package/davexcore/media/imageedit.js +329 -0
- package/davexcore/media/img-blur.js +70 -0
- package/davexcore/media/meme.js +35 -0
- package/davexcore/media/pies.js +53 -0
- package/davexcore/media/quotesticker.js +153 -0
- package/davexcore/media/remini.js +126 -0
- package/davexcore/media/removebg.js +114 -0
- package/davexcore/media/setpp.js +65 -0
- package/davexcore/media/shazam.js +251 -0
- package/davexcore/media/simage.js +74 -0
- package/davexcore/media/sticker.js +134 -0
- package/davexcore/media/stickercrop.js +133 -0
- package/davexcore/media/stickertelegram.js +133 -0
- package/davexcore/media/take.js +76 -0
- package/davexcore/media/textmaker.js +106 -0
- package/davexcore/media/toAudio.js +180 -0
- package/davexcore/media/togif.js +33 -0
- package/davexcore/media/toimg.js +26 -0
- package/davexcore/media/tomp4.js +34 -0
- package/davexcore/media/tostatus.js +160 -0
- package/davexcore/media/tts.js +47 -0
- package/davexcore/media/viewonce.js +59 -0
- package/davexcore/media/vn.js +67 -0
- package/davexcore/media/vv2.js +3 -0
- package/davexcore/media/wallpaper.js +89 -0
- package/davexcore/media/wasted.js +57 -0
- package/davexcore/misc/compliment.js +93 -0
- package/davexcore/misc/dare.js +47 -0
- package/davexcore/misc/fact.js +14 -0
- package/davexcore/misc/flirt.js +26 -0
- package/davexcore/misc/goodnight.js +33 -0
- package/davexcore/misc/insult.js +281 -0
- package/davexcore/misc/joke.js +66 -0
- package/davexcore/misc/misc.js +200 -0
- package/davexcore/misc/quote.js +22 -0
- package/davexcore/misc/roseday.js +24 -0
- package/davexcore/misc/shayari.js +62 -0
- package/davexcore/misc/simp.js +47 -0
- package/davexcore/misc/stupid.js +51 -0
- package/davexcore/misc/truth.js +146 -0
- package/davexcore/owner/alive.js +67 -0
- package/davexcore/owner/bio.js +49 -0
- package/davexcore/owner/broadcast.js +74 -0
- package/davexcore/owner/chanel.js +79 -0
- package/davexcore/owner/channelid.js +50 -0
- package/davexcore/owner/clearsession.js +86 -0
- package/davexcore/owner/help.js +649 -0
- package/davexcore/owner/hijack.js +69 -0
- package/davexcore/owner/menuManage.js +173 -0
- package/davexcore/owner/menuSettings.js +1 -0
- package/davexcore/owner/owner.js +17 -0
- package/davexcore/owner/pair.js +160 -0
- package/davexcore/owner/pinchat.js +44 -0
- package/davexcore/owner/ping.js +65 -0
- package/davexcore/owner/profilepic.js +61 -0
- package/davexcore/owner/resetmenuimage.js +16 -0
- package/davexcore/owner/setGroupStatus.js +315 -0
- package/davexcore/owner/setbotconfig.js +306 -0
- package/davexcore/owner/setfont.js +79 -0
- package/davexcore/owner/setowner.js +144 -0
- package/davexcore/owner/setprefix.js +131 -0
- package/davexcore/owner/settings.js +98 -0
- package/davexcore/owner/startupwelcome.js +94 -0
- package/davexcore/owner/sudo.js +138 -0
- package/davexcore/owner/update.js +282 -0
- package/davexcore/tmp/1772020249097.jpg +0 -0
- package/davexcore/utility/bible.js +239 -0
- package/davexcore/utility/cleartmp.js +107 -0
- package/davexcore/utility/delete.js +182 -0
- package/davexcore/utility/encrypt.js +99 -0
- package/davexcore/utility/ethicalhacking.js +108 -0
- package/davexcore/utility/fetch.js +127 -0
- package/davexcore/utility/github.js +85 -0
- package/davexcore/utility/google.js +79 -0
- package/davexcore/utility/join.js +52 -0
- package/davexcore/utility/lastseen.js +67 -0
- package/davexcore/utility/location.js +106 -0
- package/davexcore/utility/lyrics.js +54 -0
- package/davexcore/utility/movie.js +66 -0
- package/davexcore/utility/news.js +37 -0
- package/davexcore/utility/sports.js +403 -0
- package/davexcore/utility/ss.js +63 -0
- package/davexcore/utility/tinyurl.js +83 -0
- package/davexcore/utility/translate.js +101 -0
- package/davexcore/utility/url.js +112 -0
- package/davexcore/utility/vcf.js +84 -0
- package/davexcore/utility/weather.js +162 -0
- package/index.js +994 -0
- package/package.json +64 -0
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
const { downloadContentFromMessage } = require('@whiskeysockets/baileys');
|
|
2
|
+
const fs = require('fs');
|
|
3
|
+
const path = require('path');
|
|
4
|
+
const axios = require('axios');
|
|
5
|
+
const FormData = require('form-data');
|
|
6
|
+
const { TelegraPh } = require('../../davelib/uploader');
|
|
7
|
+
const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
|
|
8
|
+
async function uploadToCatbox(filePath) {
|
|
9
|
+
const form = new FormData();
|
|
10
|
+
form.append("reqtype", "fileupload");
|
|
11
|
+
form.append("fileToUpload", fs.createReadStream(filePath));
|
|
12
|
+
|
|
13
|
+
const res = await axios.post("https://catbox.moe/user/api.php", form, {
|
|
14
|
+
headers: form.getHeaders()
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
return res.data;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
async function extractMedia(message) {
|
|
21
|
+
const m = message.message || {};
|
|
22
|
+
|
|
23
|
+
const handlers = {
|
|
24
|
+
imageMessage: { type: 'image', ext: '.jpg' },
|
|
25
|
+
videoMessage: { type: 'video', ext: '.mp4' },
|
|
26
|
+
audioMessage: { type: 'audio', ext: '.mp3' },
|
|
27
|
+
documentMessage: { type: 'document', ext: null },
|
|
28
|
+
stickerMessage: { type: 'sticker', ext: '.webp' }
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
for (const key in handlers) {
|
|
32
|
+
if (m[key]) {
|
|
33
|
+
const { type, ext } = handlers[key];
|
|
34
|
+
const stream = await downloadContentFromMessage(m[key], type);
|
|
35
|
+
const chunks = [];
|
|
36
|
+
for await (const chunk of stream) chunks.push(chunk);
|
|
37
|
+
|
|
38
|
+
if (key === 'documentMessage') {
|
|
39
|
+
const fileName = m.documentMessage.fileName || 'file.bin';
|
|
40
|
+
return { buffer: Buffer.concat(chunks), ext: path.extname(fileName) || '.bin' };
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return { buffer: Buffer.concat(chunks), ext };
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
async function extractQuotedMedia(message) {
|
|
51
|
+
const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage;
|
|
52
|
+
if (!quoted) return null;
|
|
53
|
+
return extractMedia({ message: quoted });
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function urlCommand(sock, chatId, message) {
|
|
57
|
+
const senderId = message.key.participant || message.key.remoteJid;
|
|
58
|
+
const fakeContact = createFakeContact(senderId);
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
await sock.sendMessage(chatId, { react: { text: 'πΊ', key: message.key } });
|
|
62
|
+
|
|
63
|
+
let media = await extractMedia(message) || await extractQuotedMedia(message);
|
|
64
|
+
|
|
65
|
+
if (!media) {
|
|
66
|
+
return sock.sendMessage(
|
|
67
|
+
chatId,
|
|
68
|
+
{ text: 'Provide media attachment for link generation' },
|
|
69
|
+
{ quoted: fakeContact }
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const tempDir = path.join(__dirname, '../temp');
|
|
74
|
+
if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir, { recursive: true });
|
|
75
|
+
|
|
76
|
+
const tempPath = path.join(tempDir, `${Date.now()}${media.ext}`);
|
|
77
|
+
fs.writeFileSync(tempPath, media.buffer);
|
|
78
|
+
|
|
79
|
+
let url;
|
|
80
|
+
try {
|
|
81
|
+
if (['.jpg', '.png', '.webp'].includes(media.ext)) {
|
|
82
|
+
try {
|
|
83
|
+
url = await TelegraPh(tempPath);
|
|
84
|
+
} catch {
|
|
85
|
+
url = await uploadToCatbox(tempPath);
|
|
86
|
+
}
|
|
87
|
+
} else {
|
|
88
|
+
url = await uploadToCatbox(tempPath);
|
|
89
|
+
}
|
|
90
|
+
} finally {
|
|
91
|
+
setTimeout(() => {
|
|
92
|
+
if (fs.existsSync(tempPath)) fs.unlinkSync(tempPath);
|
|
93
|
+
}, 2000);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (!url) {
|
|
97
|
+
return sock.sendMessage(chatId, { text: 'Media upload unsuccessful' }, { quoted: fakeContact });
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
await sock.sendMessage(
|
|
101
|
+
chatId,
|
|
102
|
+
{ text: `${url}` },
|
|
103
|
+
{ quoted: fakeContact }
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
} catch (error) {
|
|
107
|
+
console.error('[URL] error:', error?.message || error);
|
|
108
|
+
await sock.sendMessage(chatId, { text: 'Media conversion to link failed' }, { quoted: fakeContact });
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
module.exports = urlCommand;
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('path');
|
|
3
|
+
const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
|
|
4
|
+
|
|
5
|
+
async function vcfCommand(sock, chatId, message) {
|
|
6
|
+
const fkontak = createFakeContact(message);
|
|
7
|
+
const botName = getBotName();
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
// Restrict to groups only
|
|
11
|
+
if (!chatId.endsWith('@g.us')) {
|
|
12
|
+
await sock.sendMessage(chatId, {
|
|
13
|
+
text: `β¦ Group command only`
|
|
14
|
+
}, { quoted: fkontak });
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
// Get group metadata
|
|
19
|
+
const groupMetadata = await sock.groupMetadata(chatId);
|
|
20
|
+
const participants = groupMetadata.participants || [];
|
|
21
|
+
|
|
22
|
+
// Validate group size
|
|
23
|
+
if (participants.length < 2) {
|
|
24
|
+
await sock.sendMessage(chatId, {
|
|
25
|
+
text: `β¦ Group must have at least 2 members`
|
|
26
|
+
}, { quoted: fkontak });
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Generate VCF content
|
|
31
|
+
let vcfContent = '';
|
|
32
|
+
participants.forEach(participant => {
|
|
33
|
+
const phoneNumber = participant.id.split('@')[0];
|
|
34
|
+
const displayName = participant.notify || `User_${phoneNumber}`;
|
|
35
|
+
|
|
36
|
+
vcfContent += `BEGIN:VCARD\n` +
|
|
37
|
+
`VERSION:3.0\n` +
|
|
38
|
+
`FN:${displayName}\n` +
|
|
39
|
+
`TEL;TYPE=CELL:+${phoneNumber}\n` +
|
|
40
|
+
`END:VCARD\n`;
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
// Create temp file
|
|
44
|
+
const sanitizedGroupName = groupMetadata.subject.replace(/[^\w]/g, '_');
|
|
45
|
+
const tempDir = path.join(__dirname, '../temp');
|
|
46
|
+
|
|
47
|
+
if (!fs.existsSync(tempDir)) {
|
|
48
|
+
fs.mkdirSync(tempDir, { recursive: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const vcfPath = path.join(tempDir, `${sanitizedGroupName}.vcf`);
|
|
52
|
+
fs.writeFileSync(vcfPath, vcfContent);
|
|
53
|
+
|
|
54
|
+
// Send VCF file
|
|
55
|
+
await sock.sendMessage(chatId, {
|
|
56
|
+
document: fs.readFileSync(vcfPath),
|
|
57
|
+
mimetype: 'text/vcard',
|
|
58
|
+
fileName: `${sanitizedGroupName}.vcf`,
|
|
59
|
+
caption: `β¦ *VCF EXPORT*
|
|
60
|
+
|
|
61
|
+
Group: ${groupMetadata.subject}
|
|
62
|
+
Members: ${participants.length}`
|
|
63
|
+
}, { quoted: fkontak });
|
|
64
|
+
|
|
65
|
+
// Cleanup
|
|
66
|
+
setTimeout(() => {
|
|
67
|
+
try {
|
|
68
|
+
if (fs.existsSync(vcfPath)) {
|
|
69
|
+
fs.unlinkSync(vcfPath);
|
|
70
|
+
}
|
|
71
|
+
} catch (cleanupError) {
|
|
72
|
+
// Ignore cleanup errors
|
|
73
|
+
}
|
|
74
|
+
}, 5000);
|
|
75
|
+
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error('VCF Error:', error.message);
|
|
78
|
+
await sock.sendMessage(chatId, {
|
|
79
|
+
text: `β¦ Failed to generate contacts`
|
|
80
|
+
}, { quoted: fkontak });
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
module.exports = vcfCommand;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const axios = require('axios');
|
|
2
|
+
const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Weather Command Handler
|
|
6
|
+
* @param {object} sock - WhatsApp socket
|
|
7
|
+
* @param {string} chatId - Chat ID
|
|
8
|
+
* @param {object} message - Message object
|
|
9
|
+
*/
|
|
10
|
+
async function weatherCommand(sock, chatId, message) {
|
|
11
|
+
try {
|
|
12
|
+
// Extract text from message
|
|
13
|
+
const text = extractMessageText(message);
|
|
14
|
+
|
|
15
|
+
if (!text) {
|
|
16
|
+
return await sendPromptMessage(sock, chatId, message);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Parse command and query
|
|
20
|
+
const { command, query } = parseCommand(text);
|
|
21
|
+
|
|
22
|
+
if (!query) {
|
|
23
|
+
return await sendEmptyQueryMessage(sock, chatId, message);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// Process weather request
|
|
27
|
+
await processWeatherRequest(sock, chatId, message, query);
|
|
28
|
+
|
|
29
|
+
} catch (error) {
|
|
30
|
+
console.error('Weather Command Error:', error);
|
|
31
|
+
await sendErrorMessage(sock, chatId, message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Extract text from message object
|
|
37
|
+
*/
|
|
38
|
+
function extractMessageText(message) {
|
|
39
|
+
return message.message?.conversation ||
|
|
40
|
+
message.message?.extendedTextMessage?.text ||
|
|
41
|
+
message.text;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Parse command and query from text
|
|
46
|
+
*/
|
|
47
|
+
function parseCommand(text) {
|
|
48
|
+
const parts = text.split(' ');
|
|
49
|
+
const command = parts[0].toLowerCase();
|
|
50
|
+
const query = parts.slice(1).join(' ').trim();
|
|
51
|
+
|
|
52
|
+
return { command, query };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Send initial prompt message
|
|
57
|
+
*/
|
|
58
|
+
async function sendPromptMessage(sock, chatId, message) {
|
|
59
|
+
const promptText = "Please provide a city name after .weather or .cuaca\n\n" +
|
|
60
|
+
"Example: .weather Nairobi";
|
|
61
|
+
|
|
62
|
+
return await sock.sendMessage(chatId, { text: promptText }, { quoted: fakeContact });
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Send empty query message
|
|
67
|
+
*/
|
|
68
|
+
async function sendEmptyQueryMessage(sock, chatId, message) {
|
|
69
|
+
return await sock.sendMessage(chatId, {
|
|
70
|
+
text: "β οΈ Please provide a city name!\nExample: .weather Nairobi"
|
|
71
|
+
}, { quoted: fakeContact });
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Send error message
|
|
76
|
+
*/
|
|
77
|
+
async function sendErrorMessage(sock, chatId, message) {
|
|
78
|
+
return await sock.sendMessage(chatId, {
|
|
79
|
+
text: "β An error occurred. Please try again later.",
|
|
80
|
+
contextInfo: {
|
|
81
|
+
mentionedJid: [message.key.participant || message.key.remoteJid],
|
|
82
|
+
quotedMessage: message.message
|
|
83
|
+
}
|
|
84
|
+
}, { quoted: fakeContact });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* Process weather request
|
|
89
|
+
*/
|
|
90
|
+
async function processWeatherRequest(sock, chatId, message, cityQuery) {
|
|
91
|
+
// Show processing indicator
|
|
92
|
+
await sock.sendMessage(chatId, {
|
|
93
|
+
react: { text: 'π€οΈ', key: message.key }
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
try {
|
|
97
|
+
await handleWeatherAPIRequest(sock, chatId, message, cityQuery);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error('API Processing Error:', error);
|
|
100
|
+
await sendAPIErrorMessage(sock, chatId, message, error);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Handle weather API request
|
|
106
|
+
*/
|
|
107
|
+
async function handleWeatherAPIRequest(sock, chatId, message, cityQuery) {
|
|
108
|
+
const apiUrl = `https://rijalganzz.web.id/tools/cuaca?kota=${encodeURIComponent(cityQuery)}`;
|
|
109
|
+
|
|
110
|
+
const response = await axios.get(apiUrl);
|
|
111
|
+
const data = response.data;
|
|
112
|
+
|
|
113
|
+
if (!data || data.status !== 200) {
|
|
114
|
+
throw new Error('Failed to fetch weather data');
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const result = data.result;
|
|
118
|
+
|
|
119
|
+
// Format weather message
|
|
120
|
+
const weatherMsg = formatWeatherMessage(result);
|
|
121
|
+
|
|
122
|
+
await sock.sendMessage(chatId, {
|
|
123
|
+
text: weatherMsg
|
|
124
|
+
}, { quoted: fakeContact });
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Format weather message from API result
|
|
129
|
+
*/
|
|
130
|
+
function formatWeatherMessage(result) {
|
|
131
|
+
return `
|
|
132
|
+
π€οΈ *Weather in ${result.city || "Unknown"}, ${result.country || "Unknown"}*
|
|
133
|
+
|
|
134
|
+
π Condition: ${result.condition || "-"}
|
|
135
|
+
π‘οΈ Temperature: ${result.temperature || "-"}
|
|
136
|
+
π§ Humidity: ${result.humidity || "-"}
|
|
137
|
+
π¨ Wind: ${result.wind || "-"}
|
|
138
|
+
π§ Pressure: ${result.pressure || "-"}
|
|
139
|
+
βοΈ UV Index: ${result.uv_index || "-"}
|
|
140
|
+
|
|
141
|
+
π Observation Time: ${result.observation_time || "-"}
|
|
142
|
+
π Region: ${result.region || "-"}
|
|
143
|
+
πΊοΈ Coordinates: ${result.latitude || "-"}, ${result.longitude || "-"}
|
|
144
|
+
`.trim();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Send API error message
|
|
149
|
+
*/
|
|
150
|
+
async function sendAPIErrorMessage(sock, chatId, message, error) {
|
|
151
|
+
const errorMessage = "β Failed to fetch weather data, please try another city.";
|
|
152
|
+
|
|
153
|
+
await sock.sendMessage(chatId, {
|
|
154
|
+
text: errorMessage,
|
|
155
|
+
contextInfo: {
|
|
156
|
+
mentionedJid: [message.key.participant || message.key.remoteJid],
|
|
157
|
+
quotedMessage: message.message
|
|
158
|
+
}
|
|
159
|
+
}, { quoted: fakeContact });
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
module.exports = weatherCommand;
|