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,169 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
const STORE_FILE = './baileys_store.json'
|
|
3
|
+
|
|
4
|
+
// Hard limits for low-memory panels
|
|
5
|
+
let MAX_MESSAGES = 5 // messages kept per chat
|
|
6
|
+
const MAX_CONTACTS = 250 // max contacts in memory
|
|
7
|
+
const MAX_CHATS = 60 // max chats in memory
|
|
8
|
+
|
|
9
|
+
try {
|
|
10
|
+
const settings = require('../daveset.js')
|
|
11
|
+
if (settings.maxStoreMessages && typeof settings.maxStoreMessages === 'number') {
|
|
12
|
+
MAX_MESSAGES = Math.min(settings.maxStoreMessages, 8)
|
|
13
|
+
}
|
|
14
|
+
} catch (e) {}
|
|
15
|
+
|
|
16
|
+
let _isDirty = false // only flush to disk when data actually changed
|
|
17
|
+
|
|
18
|
+
const store = {
|
|
19
|
+
messages: {},
|
|
20
|
+
contacts: {},
|
|
21
|
+
chats: {},
|
|
22
|
+
|
|
23
|
+
readFromFile(filePath = STORE_FILE) {
|
|
24
|
+
try {
|
|
25
|
+
if (fs.existsSync(filePath)) {
|
|
26
|
+
const raw = fs.readFileSync(filePath, 'utf-8')
|
|
27
|
+
if (!raw || raw.length < 2) return
|
|
28
|
+
const data = JSON.parse(raw)
|
|
29
|
+
this.contacts = data.contacts || {}
|
|
30
|
+
this.chats = data.chats || {}
|
|
31
|
+
this.messages = data.messages || {}
|
|
32
|
+
this._enforceAllLimits()
|
|
33
|
+
}
|
|
34
|
+
} catch (e) {
|
|
35
|
+
console.warn('[STORE] Failed to read:', e.message)
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
|
|
39
|
+
writeToFile(filePath = STORE_FILE) {
|
|
40
|
+
if (!_isDirty) return
|
|
41
|
+
try {
|
|
42
|
+
fs.writeFileSync(filePath, JSON.stringify({
|
|
43
|
+
contacts: this.contacts,
|
|
44
|
+
chats: this.chats,
|
|
45
|
+
messages: this.messages
|
|
46
|
+
}))
|
|
47
|
+
_isDirty = false
|
|
48
|
+
} catch (e) {
|
|
49
|
+
console.warn('[STORE] Failed to write:', e.message)
|
|
50
|
+
}
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
_enforceAllLimits() {
|
|
54
|
+
// Contacts
|
|
55
|
+
const cKeys = Object.keys(this.contacts)
|
|
56
|
+
if (cKeys.length > MAX_CONTACTS) {
|
|
57
|
+
for (const k of cKeys.slice(0, cKeys.length - MAX_CONTACTS)) {
|
|
58
|
+
delete this.contacts[k]
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Chats
|
|
62
|
+
const chatKeys = Object.keys(this.chats)
|
|
63
|
+
if (chatKeys.length > MAX_CHATS) {
|
|
64
|
+
for (const k of chatKeys.slice(0, chatKeys.length - MAX_CHATS)) {
|
|
65
|
+
delete this.chats[k]
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
// Messages — trim each chat and drop old-format objects
|
|
69
|
+
for (const jid of Object.keys(this.messages)) {
|
|
70
|
+
if (!Array.isArray(this.messages[jid])) {
|
|
71
|
+
const vals = Object.values(this.messages[jid])
|
|
72
|
+
this.messages[jid] = vals.slice(-MAX_MESSAGES)
|
|
73
|
+
} else if (this.messages[jid].length > MAX_MESSAGES) {
|
|
74
|
+
this.messages[jid] = this.messages[jid].slice(-MAX_MESSAGES)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
|
|
79
|
+
bind(ev) {
|
|
80
|
+
ev.on('messages.upsert', ({ messages }) => {
|
|
81
|
+
for (const msg of messages) {
|
|
82
|
+
if (!msg.key?.remoteJid) continue
|
|
83
|
+
const jid = msg.key.remoteJid
|
|
84
|
+
if (!this.messages[jid]) this.messages[jid] = []
|
|
85
|
+
this.messages[jid].push(msg)
|
|
86
|
+
if (this.messages[jid].length > MAX_MESSAGES) {
|
|
87
|
+
this.messages[jid] = this.messages[jid].slice(-MAX_MESSAGES)
|
|
88
|
+
}
|
|
89
|
+
_isDirty = true
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
ev.on('contacts.update', (contacts) => {
|
|
94
|
+
for (const contact of contacts) {
|
|
95
|
+
if (!contact.id) continue
|
|
96
|
+
this.contacts[contact.id] = {
|
|
97
|
+
id: contact.id,
|
|
98
|
+
name: contact.notify || contact.name || ''
|
|
99
|
+
}
|
|
100
|
+
_isDirty = true
|
|
101
|
+
}
|
|
102
|
+
const cKeys = Object.keys(this.contacts)
|
|
103
|
+
if (cKeys.length > MAX_CONTACTS) {
|
|
104
|
+
for (const k of cKeys.slice(0, cKeys.length - MAX_CONTACTS)) {
|
|
105
|
+
delete this.contacts[k]
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
ev.on('chats.set', (data) => {
|
|
111
|
+
const chatList = Array.isArray(data) ? data : (data?.chats || [])
|
|
112
|
+
if (!Array.isArray(chatList)) return
|
|
113
|
+
const recent = chatList.slice(-MAX_CHATS)
|
|
114
|
+
for (const chat of recent) {
|
|
115
|
+
if (chat?.id) {
|
|
116
|
+
this.chats[chat.id] = { id: chat.id, subject: chat.subject || '' }
|
|
117
|
+
_isDirty = true
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
const chatKeys = Object.keys(this.chats)
|
|
121
|
+
if (chatKeys.length > MAX_CHATS) {
|
|
122
|
+
for (const k of chatKeys.slice(0, chatKeys.length - MAX_CHATS)) {
|
|
123
|
+
delete this.chats[k]
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
},
|
|
128
|
+
|
|
129
|
+
async loadMessage(jid, id) {
|
|
130
|
+
return this.messages[jid]?.find(m => m.key.id === id) || null
|
|
131
|
+
},
|
|
132
|
+
|
|
133
|
+
// Called by index.js when RAM hits critical level — aggressive purge
|
|
134
|
+
purge() {
|
|
135
|
+
const msgJids = Object.keys(this.messages)
|
|
136
|
+
if (msgJids.length > 15) {
|
|
137
|
+
for (const k of msgJids.slice(0, msgJids.length - 15)) {
|
|
138
|
+
delete this.messages[k]
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
for (const jid of Object.keys(this.messages)) {
|
|
142
|
+
this.messages[jid] = this.messages[jid].slice(-2)
|
|
143
|
+
}
|
|
144
|
+
const cKeys = Object.keys(this.contacts)
|
|
145
|
+
for (const k of cKeys.slice(0, Math.floor(cKeys.length * 0.6))) {
|
|
146
|
+
delete this.contacts[k]
|
|
147
|
+
}
|
|
148
|
+
const chatKeys = Object.keys(this.chats)
|
|
149
|
+
for (const k of chatKeys.slice(0, Math.floor(chatKeys.length * 0.6))) {
|
|
150
|
+
delete this.chats[k]
|
|
151
|
+
}
|
|
152
|
+
_isDirty = false
|
|
153
|
+
},
|
|
154
|
+
|
|
155
|
+
getStats() {
|
|
156
|
+
let totalMessages = 0
|
|
157
|
+
for (const msgs of Object.values(this.messages)) {
|
|
158
|
+
if (Array.isArray(msgs)) totalMessages += msgs.length
|
|
159
|
+
}
|
|
160
|
+
return {
|
|
161
|
+
messages: totalMessages,
|
|
162
|
+
contacts: Object.keys(this.contacts).length,
|
|
163
|
+
chats: Object.keys(this.chats).length,
|
|
164
|
+
maxMessagesPerChat: MAX_MESSAGES
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
module.exports = store
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const channelInfo = {
|
|
2
|
+
contextInfo: {
|
|
3
|
+
forwardingScore: 999,
|
|
4
|
+
isForwarded: false,
|
|
5
|
+
forwardedNewsletterMessageInfo: {
|
|
6
|
+
newsletterJid: '@newsletter',
|
|
7
|
+
newsletterName: 'l',
|
|
8
|
+
serverMessageId: -1,
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
module.exports = {
|
|
14
|
+
channelInfo
|
|
15
|
+
};;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
function getMessageText(message) {
|
|
2
|
+
if (!message?.message) return '';
|
|
3
|
+
|
|
4
|
+
const msg = message.message;
|
|
5
|
+
|
|
6
|
+
return msg.conversation?.trim() ||
|
|
7
|
+
msg.extendedTextMessage?.text?.trim() ||
|
|
8
|
+
msg.imageMessage?.caption?.trim() ||
|
|
9
|
+
msg.videoMessage?.caption?.trim() ||
|
|
10
|
+
msg.documentMessage?.caption?.trim() ||
|
|
11
|
+
msg.buttonsResponseMessage?.selectedButtonId?.trim() ||
|
|
12
|
+
msg.listResponseMessage?.singleSelectReply?.selectedRowId?.trim() ||
|
|
13
|
+
msg.templateButtonReplyMessage?.selectedId?.trim() ||
|
|
14
|
+
'';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function isEditedMessage(message) {
|
|
18
|
+
if (!message?.message) return false;
|
|
19
|
+
|
|
20
|
+
const msg = message.message;
|
|
21
|
+
|
|
22
|
+
// Baileys protocol message for edits (type 14)
|
|
23
|
+
if (msg.protocolMessage?.type === 14) return true;
|
|
24
|
+
if (msg.protocolMessage?.type === 'MESSAGE_EDIT') return true;
|
|
25
|
+
if (msg.editedMessage) return true;
|
|
26
|
+
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getEditedMessageText(message) {
|
|
31
|
+
if (!message?.message) return '';
|
|
32
|
+
|
|
33
|
+
const msg = message.message;
|
|
34
|
+
|
|
35
|
+
if (msg.protocolMessage?.editedMessage?.message) {
|
|
36
|
+
const edited = msg.protocolMessage.editedMessage.message;
|
|
37
|
+
return edited.conversation?.trim() ||
|
|
38
|
+
edited.extendedTextMessage?.text?.trim() ||
|
|
39
|
+
'';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (msg.editedMessage?.message) {
|
|
43
|
+
const edited = msg.editedMessage.message;
|
|
44
|
+
return edited.conversation?.trim() ||
|
|
45
|
+
edited.extendedTextMessage?.text?.trim() ||
|
|
46
|
+
'';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return '';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function extractCommand(text, prefix) {
|
|
53
|
+
if (!text || typeof text !== 'string') return { command: '', args: [], fullArgs: '' };
|
|
54
|
+
|
|
55
|
+
const trimmed = text.trim();
|
|
56
|
+
|
|
57
|
+
if (prefix && !trimmed.startsWith(prefix)) {
|
|
58
|
+
return { command: '', args: [], fullArgs: '' };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const withoutPrefix = prefix ? trimmed.slice(prefix.length).trimStart() : trimmed;
|
|
62
|
+
const parts = withoutPrefix.split(/\s+/).filter(p => p.length > 0);
|
|
63
|
+
const command = parts[0]?.toLowerCase() || '';
|
|
64
|
+
const args = parts.slice(1);
|
|
65
|
+
const fullArgs = args.join(' ');
|
|
66
|
+
|
|
67
|
+
return { command, args, fullArgs };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
function shouldProcessEditedMessage(message, prefix) {
|
|
71
|
+
if (!isEditedMessage(message)) return false;
|
|
72
|
+
|
|
73
|
+
const editedText = getEditedMessageText(message);
|
|
74
|
+
if (!editedText) return false;
|
|
75
|
+
|
|
76
|
+
if (prefix && !editedText.startsWith(prefix)) return false;
|
|
77
|
+
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
module.exports = {
|
|
82
|
+
getMessageText,
|
|
83
|
+
isEditedMessage,
|
|
84
|
+
getEditedMessageText,
|
|
85
|
+
extractCommand,
|
|
86
|
+
shouldProcessEditedMessage
|
|
87
|
+
};
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const {
|
|
8
|
+
proto,
|
|
9
|
+
delay,
|
|
10
|
+
getContentType
|
|
11
|
+
} = require('@whiskeysockets/baileys')
|
|
12
|
+
const chalk = require('chalk').default || require('chalk')
|
|
13
|
+
const fs = require('fs')
|
|
14
|
+
const Crypto = require('crypto')
|
|
15
|
+
const axios = require('axios')
|
|
16
|
+
const moment = require('moment-timezone')
|
|
17
|
+
const {
|
|
18
|
+
sizeFormatter
|
|
19
|
+
} = require('human-readable')
|
|
20
|
+
const util = require('util')
|
|
21
|
+
const Jimp = require('jimp')
|
|
22
|
+
const {
|
|
23
|
+
defaultMaxListeners
|
|
24
|
+
} = require('stream')
|
|
25
|
+
const path = require('path')
|
|
26
|
+
const { tmpdir } = require('os')
|
|
27
|
+
|
|
28
|
+
const unixTimestampSeconds = (date = new Date()) => Math.floor(date.getTime() / 1000)
|
|
29
|
+
|
|
30
|
+
exports.unixTimestampSeconds = unixTimestampSeconds
|
|
31
|
+
|
|
32
|
+
exports.generateMessageTag = (epoch) => {
|
|
33
|
+
let tag = (0, exports.unixTimestampSeconds)().toString();
|
|
34
|
+
if (epoch)
|
|
35
|
+
tag += '.--' + epoch; // attach epoch if provided
|
|
36
|
+
return tag;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
exports.processTime = (timestamp, now) => {
|
|
40
|
+
return moment.duration(now - moment(timestamp * 1000)).asSeconds()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.getRandom = (ext) => {
|
|
44
|
+
return `${Math.floor(Math.random() * 10000)}${ext}`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exports.getBuffer = async (url, options) => {
|
|
48
|
+
try {
|
|
49
|
+
options ? options : {}
|
|
50
|
+
const res = await axios({
|
|
51
|
+
method: "get",
|
|
52
|
+
url,
|
|
53
|
+
headers: {
|
|
54
|
+
'DNT': 1,
|
|
55
|
+
'Upgrade-Insecure-Request': 1
|
|
56
|
+
},
|
|
57
|
+
...options,
|
|
58
|
+
responseType: 'arraybuffer'
|
|
59
|
+
})
|
|
60
|
+
return res.data
|
|
61
|
+
} catch (err) {
|
|
62
|
+
return err
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
exports.getImg = async (url, options) => {
|
|
67
|
+
try {
|
|
68
|
+
options ? options : {}
|
|
69
|
+
const res = await axios({
|
|
70
|
+
method: "get",
|
|
71
|
+
url,
|
|
72
|
+
headers: {
|
|
73
|
+
'DNT': 1,
|
|
74
|
+
'Upgrade-Insecure-Request': 1
|
|
75
|
+
},
|
|
76
|
+
...options,
|
|
77
|
+
responseType: 'arraybuffer'
|
|
78
|
+
})
|
|
79
|
+
return res.data
|
|
80
|
+
} catch (err) {
|
|
81
|
+
return err
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
exports.fetchJson = async (url, options) => {
|
|
86
|
+
try {
|
|
87
|
+
options ? options : {}
|
|
88
|
+
const res = await axios({
|
|
89
|
+
method: 'GET',
|
|
90
|
+
url: url,
|
|
91
|
+
headers: {
|
|
92
|
+
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36'
|
|
93
|
+
},
|
|
94
|
+
...options
|
|
95
|
+
})
|
|
96
|
+
return res.data
|
|
97
|
+
} catch (err) {
|
|
98
|
+
return err
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
exports.runtime = function(seconds) {
|
|
103
|
+
seconds = Number(seconds);
|
|
104
|
+
var d = Math.floor(seconds / (3600 * 24));
|
|
105
|
+
var h = Math.floor(seconds % (3600 * 24) / 3600);
|
|
106
|
+
var m = Math.floor(seconds % 3600 / 60);
|
|
107
|
+
var s = Math.floor(seconds % 60);
|
|
108
|
+
var dDisplay = d > 0 ? d + (d == 1 ? " day, " : " days, ") : "";
|
|
109
|
+
var hDisplay = h > 0 ? h + (h == 1 ? " hour, " : " hours, ") : "";
|
|
110
|
+
var mDisplay = m > 0 ? m + (m == 1 ? " minute, " : " minutes, ") : "";
|
|
111
|
+
var sDisplay = s > 0 ? s + (s == 1 ? " second" : " seconds") : "";
|
|
112
|
+
return dDisplay + hDisplay + mDisplay + sDisplay;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
exports.clockString = (ms) => {
|
|
116
|
+
let h = isNaN(ms) ? '--' : Math.floor(ms / 3600000)
|
|
117
|
+
let m = isNaN(ms) ? '--' : Math.floor(ms / 60000) % 60
|
|
118
|
+
let s = isNaN(ms) ? '--' : Math.floor(ms / 1000) % 60
|
|
119
|
+
return [h, m, s].map(v => v.toString().padStart(2, 0)).join(':')
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
exports.sleep = async (ms) => {
|
|
123
|
+
return new Promise(resolve => setTimeout(resolve, ms));
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
exports.isUrl = (url) => {
|
|
127
|
+
return url.match(new RegExp(/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_+.~#?&/=]*)/, 'gi'))
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
exports.getTime = (format, date) => {
|
|
131
|
+
if (date) {
|
|
132
|
+
return moment(date).locale('id').format(format)
|
|
133
|
+
} else {
|
|
134
|
+
return moment.tz('Asia/Jakarta').locale('id').format(format)
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.formatDate = (n, locale = 'id') => {
|
|
139
|
+
let d = new Date(n)
|
|
140
|
+
return d.toLocaleDateString(locale, {
|
|
141
|
+
weekday: 'long',
|
|
142
|
+
day: 'numeric',
|
|
143
|
+
month: 'long',
|
|
144
|
+
year: 'numeric',
|
|
145
|
+
hour: 'numeric',
|
|
146
|
+
minute: 'numeric',
|
|
147
|
+
second: 'numeric'
|
|
148
|
+
})
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
exports.tanggal = (numer) => {
|
|
152
|
+
const myMonths = ["Januari", "Februari", "Maret", "April", "Mei", "Juni", "Juli", "Agustus", "September", "Oktober", "November", "Desember"];
|
|
153
|
+
const myDays = ['Minggu', 'Senin', 'Selasa', 'Rabu', 'Kamis', "Jum'at", 'Sabtu'];
|
|
154
|
+
const tgl = new Date(numer);
|
|
155
|
+
const day = tgl.getDate();
|
|
156
|
+
const bulan = tgl.getMonth();
|
|
157
|
+
let thisDay = tgl.getDay();
|
|
158
|
+
thisDay = myDays[thisDay];
|
|
159
|
+
const yy = tgl.getYear();
|
|
160
|
+
const year = (yy < 1000) ? yy + 1900 : yy;
|
|
161
|
+
const time = moment.tz('Africa/Nsirobi').format('DD/MM HH:mm:ss');
|
|
162
|
+
const d = new Date();
|
|
163
|
+
const locale = 'id';
|
|
164
|
+
const gmt = new Date(0).getTime() - new Date('1 January 1970').getTime();
|
|
165
|
+
const weton = ['Pahing', 'Pon', 'Wage', 'Kliwon', 'Legi'][Math.floor(((d * 1) + gmt) / 84600000) % 5];
|
|
166
|
+
|
|
167
|
+
return `${thisDay}, ${day} - ${myMonths[bulan]} - ${year}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
exports.jam = (numer, options = {}) => {
|
|
171
|
+
let format = options.format ? options.format : "HH:mm"
|
|
172
|
+
let jam = options?.timeZone ? moment(numer).tz(timeZone).format(format) : moment(numer).format(format)
|
|
173
|
+
|
|
174
|
+
return `${jam}`
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
exports.formatp = sizeFormatter({
|
|
178
|
+
std: 'JEDEC', //'SI' = default | 'IEC' | 'JEDEC'
|
|
179
|
+
decimalPlaces: 2,
|
|
180
|
+
keepTrailingZeroes: false,
|
|
181
|
+
render: (literal, symbol) => `${literal} ${symbol}B`,
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
exports.json = (string) => {
|
|
185
|
+
return JSON.stringify(string, null, 2)
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
function format(...args) {
|
|
189
|
+
return util.format(...args)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
exports.logic = (check, inp, out) => {
|
|
193
|
+
if (inp.length !== out.length) throw new Error('Input and Output must have same length')
|
|
194
|
+
for (let i in inp)
|
|
195
|
+
if (util.isDeepStrictEqual(check, inp[i])) return out[i]
|
|
196
|
+
return null
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
exports.generateProfilePicture = async (buffer) => {
|
|
200
|
+
const jimp = await Jimp.read(buffer)
|
|
201
|
+
const min = jimp.getWidth()
|
|
202
|
+
const max = jimp.getHeight()
|
|
203
|
+
const cropped = jimp.crop(0, 0, min, max)
|
|
204
|
+
return {
|
|
205
|
+
img: await cropped.scaleToFit(720, 720).getBufferAsync(Jimp.MIME_JPEG),
|
|
206
|
+
preview: await cropped.scaleToFit(720, 720).getBufferAsync(Jimp.MIME_JPEG)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
exports.bytesToSize = (bytes, decimals = 2) => {
|
|
211
|
+
if (bytes === 0) return '0 Bytes';
|
|
212
|
+
|
|
213
|
+
const k = 1024;
|
|
214
|
+
const dm = decimals < 0 ? 0 : decimals;
|
|
215
|
+
const sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
|
|
216
|
+
|
|
217
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
218
|
+
|
|
219
|
+
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + ' ' + sizes[i];
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
exports.getSizeMedia = (path) => {
|
|
223
|
+
return new Promise((resolve, reject) => {
|
|
224
|
+
if (/http/.test(path)) {
|
|
225
|
+
axios.get(path)
|
|
226
|
+
.then((res) => {
|
|
227
|
+
let length = parseInt(res.headers['content-length'])
|
|
228
|
+
let size = exports.bytesToSize(length, 3)
|
|
229
|
+
if (!isNaN(length)) resolve(size)
|
|
230
|
+
})
|
|
231
|
+
} else if (Buffer.isBuffer(path)) {
|
|
232
|
+
let length = Buffer.byteLength(path)
|
|
233
|
+
let size = exports.bytesToSize(length, 3)
|
|
234
|
+
if (!isNaN(length)) resolve(size)
|
|
235
|
+
} else {
|
|
236
|
+
reject('error gatau apah')
|
|
237
|
+
}
|
|
238
|
+
})
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
exports.parseMention = (text = '') => {
|
|
242
|
+
return [...text.matchAll(/@([0-9]{5,16}|0)/g)].map(v => v[1] + '@s.whatsapp.net')
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
exports.getGroupAdmins = (participants) => {
|
|
246
|
+
let admins = []
|
|
247
|
+
for (let i of participants) {
|
|
248
|
+
i.admin === "superadmin" ? admins.push(i.id) : i.admin === "admin" ? admins.push(i.id) : ''
|
|
249
|
+
}
|
|
250
|
+
return admins || []
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
/**
|
|
254
|
+
* Serialize Message
|
|
255
|
+
* @param {WAConnection} conn
|
|
256
|
+
* @param {Object} m
|
|
257
|
+
* @param {store} store
|
|
258
|
+
*/
|
|
259
|
+
exports.smsg = (XeonBotInc, m, store) => {
|
|
260
|
+
if (!m) return m
|
|
261
|
+
let M = proto.WebMessageInfo
|
|
262
|
+
if (m.key) {
|
|
263
|
+
m.id = m.key.id
|
|
264
|
+
m.isBaileys = m.id.startsWith('BAE5') && m.id.length === 16
|
|
265
|
+
m.chat = m.key.remoteJid
|
|
266
|
+
m.fromMe = m.key.fromMe
|
|
267
|
+
m.isGroup = m.chat.endsWith('@g.us')
|
|
268
|
+
m.sender = XeonBotInc.decodeJid(m.fromMe && XeonBotInc.user.id || m.participant || m.key.participant || m.chat || '')
|
|
269
|
+
if (m.isGroup) m.participant = XeonBotInc.decodeJid(m.key.participant) || ''
|
|
270
|
+
}
|
|
271
|
+
if (m.message) {
|
|
272
|
+
m.mtype = getContentType(m.message)
|
|
273
|
+
m.msg = (m.mtype == 'viewOnceMessage' ? m.message[m.mtype].message[getContentType(m.message[m.mtype].message)] : m.message[m.mtype])
|
|
274
|
+
m.body = m.message.conversation || m.msg.caption || m.msg.text || (m.mtype == 'listResponseMessage') && m.msg.singleSelectReply.selectedRowId || (m.mtype == 'buttonsResponseMessage') && m.msg.selectedButtonId || (m.mtype == 'viewOnceMessage') && m.msg.caption || m.text
|
|
275
|
+
let quoted = m.quoted = m.msg.contextInfo ? m.msg.contextInfo.quotedMessage : null
|
|
276
|
+
m.mentionedJid = m.msg.contextInfo ? m.msg.contextInfo.mentionedJid : []
|
|
277
|
+
if (m.quoted) {
|
|
278
|
+
let type = getContentType(quoted)
|
|
279
|
+
m.quoted = m.quoted[type]
|
|
280
|
+
if (['productMessage'].includes(type)) {
|
|
281
|
+
type = getContentType(m.quoted)
|
|
282
|
+
m.quoted = m.quoted[type]
|
|
283
|
+
}
|
|
284
|
+
if (typeof m.quoted === 'string') m.quoted = {
|
|
285
|
+
text: m.quoted
|
|
286
|
+
}
|
|
287
|
+
m.quoted.mtype = type
|
|
288
|
+
m.quoted.id = m.msg.contextInfo.stanzaId
|
|
289
|
+
m.quoted.chat = m.msg.contextInfo.remoteJid || m.chat
|
|
290
|
+
m.quoted.isBaileys = m.quoted.id ? m.quoted.id.startsWith('BAE5') && m.quoted.id.length === 16 : false
|
|
291
|
+
m.quoted.sender = XeonBotInc.decodeJid(m.msg.contextInfo.participant)
|
|
292
|
+
m.quoted.fromMe = m.quoted.sender === (XeonBotInc.user && XeonBotInc.user.id)
|
|
293
|
+
m.quoted.text = m.quoted.text || m.quoted.caption || m.quoted.conversation || m.quoted.contentText || m.quoted.selectedDisplayText || m.quoted.title || ''
|
|
294
|
+
m.quoted.mentionedJid = m.msg.contextInfo ? m.msg.contextInfo.mentionedJid : []
|
|
295
|
+
m.getQuotedObj = m.getQuotedMessage = async () => {
|
|
296
|
+
if (!m.quoted.id) return false
|
|
297
|
+
let q = await store.loadMessage(m.chat, m.quoted.id, XeonBotInc)
|
|
298
|
+
return exports.smsg(XeonBotInc, q, store)
|
|
299
|
+
}
|
|
300
|
+
let vM = m.quoted.fakeObj = M.fromObject({
|
|
301
|
+
key: {
|
|
302
|
+
remoteJid: m.quoted.chat,
|
|
303
|
+
fromMe: m.quoted.fromMe,
|
|
304
|
+
id: m.quoted.id
|
|
305
|
+
},
|
|
306
|
+
message: quoted,
|
|
307
|
+
...(m.isGroup ? {
|
|
308
|
+
participant: m.quoted.sender
|
|
309
|
+
} : {})
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
*
|
|
314
|
+
* @returns
|
|
315
|
+
*/
|
|
316
|
+
m.quoted.delete = () => XeonBotInc.sendMessage(m.quoted.chat, {
|
|
317
|
+
delete: vM.key
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
*
|
|
322
|
+
* @param {*} jid
|
|
323
|
+
* @param {*} forceForward
|
|
324
|
+
* @param {*} options
|
|
325
|
+
* @returns
|
|
326
|
+
*/
|
|
327
|
+
m.quoted.copyNForward = (jid, forceForward = false, options = {}) => XeonBotInc.copyNForward(jid, vM, forceForward, options)
|
|
328
|
+
|
|
329
|
+
/**
|
|
330
|
+
*
|
|
331
|
+
* @returns
|
|
332
|
+
*/
|
|
333
|
+
m.quoted.download = () => XeonBotInc.downloadMediaMessage(m.quoted)
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (m.msg.url) m.download = () => XeonBotInc.downloadMediaMessage(m.msg)
|
|
337
|
+
m.text = m.msg.text || m.msg.caption || m.message.conversation || m.msg.contentText || m.msg.selectedDisplayText || m.msg.title || ''
|
|
338
|
+
/**
|
|
339
|
+
* Reply to this message
|
|
340
|
+
* @param {String|Object} text
|
|
341
|
+
* @param {String|false} chatId
|
|
342
|
+
* @param {Object} options
|
|
343
|
+
*/
|
|
344
|
+
m.reply = (text, chatId = m.chat, options = {}) => Buffer.isBuffer(text) ? XeonBotInc.sendMedia(chatId, text, 'file', '', m, {
|
|
345
|
+
...options
|
|
346
|
+
}) : XeonBotInc.sendText(chatId, text, m, {
|
|
347
|
+
...options
|
|
348
|
+
})
|
|
349
|
+
/**
|
|
350
|
+
* Copy this message
|
|
351
|
+
*/
|
|
352
|
+
m.copy = () => exports.smsg(XeonBotInc, M.fromObject(M.toObject(m)))
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
*
|
|
356
|
+
* @param {*} jid
|
|
357
|
+
* @param {*} forceForward
|
|
358
|
+
* @param {*} options
|
|
359
|
+
* @returns
|
|
360
|
+
*/
|
|
361
|
+
m.copyNForward = (jid = m.chat, forceForward = false, options = {}) => XeonBotInc.copyNForward(jid, m, forceForward, options)
|
|
362
|
+
|
|
363
|
+
return m
|
|
364
|
+
}
|
|
365
|
+
exports.reSize = (buffer, ukur1, ukur2) => {
|
|
366
|
+
return new Promise(async (resolve, reject) => {
|
|
367
|
+
var baper = await Jimp.read(buffer);
|
|
368
|
+
var ab = await baper.resize(ukur1, ukur2).getBufferAsync(Jimp.MIME_JPEG)
|
|
369
|
+
resolve(ab)
|
|
370
|
+
})
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
let file = require.resolve(__filename)
|
|
374
|
+
fs.watchFile(file, () => {
|
|
375
|
+
fs.unwatchFile(file)
|
|
376
|
+
console.log(chalk.redBright(`Update ${__filename}`))
|
|
377
|
+
delete require.cache[file]
|
|
378
|
+
require(file)
|
|
379
|
+
})
|