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
package/index.js
ADDED
|
@@ -0,0 +1,994 @@
|
|
|
1
|
+
const config = require('./config');
|
|
2
|
+
require('dotenv').config();
|
|
3
|
+
|
|
4
|
+
const fs = require('fs')
|
|
5
|
+
const chalk = require('chalk').default || require('chalk')
|
|
6
|
+
const path = require('path')
|
|
7
|
+
const axios = require('axios')
|
|
8
|
+
const os = require('os')
|
|
9
|
+
const PhoneNumber = require('awesome-phonenumber')
|
|
10
|
+
const express = require('express')
|
|
11
|
+
|
|
12
|
+
const app = express()
|
|
13
|
+
const PORT = process.env.PORT || 3000
|
|
14
|
+
app.get('/', (req, res) => {
|
|
15
|
+
res.sendFile(path.join(__dirname, 'davelib', 'server.html'))
|
|
16
|
+
})
|
|
17
|
+
app.listen(PORT, '0.0.0.0', () => {
|
|
18
|
+
console.log(`[ DAVE-X ] Web server running on port ${PORT}`)
|
|
19
|
+
})
|
|
20
|
+
const {
|
|
21
|
+
default: makeWASocket,
|
|
22
|
+
useMultiFileAuthState,
|
|
23
|
+
DisconnectReason,
|
|
24
|
+
fetchLatestBaileysVersion,
|
|
25
|
+
jidNormalizedUser,
|
|
26
|
+
makeCacheableSignalKeyStore,
|
|
27
|
+
delay
|
|
28
|
+
} = require("@whiskeysockets/baileys")
|
|
29
|
+
|
|
30
|
+
const NodeCache = require("node-cache")
|
|
31
|
+
const pino = require("pino")
|
|
32
|
+
const readline = require("readline")
|
|
33
|
+
const { rmSync } = require('fs')
|
|
34
|
+
|
|
35
|
+
// --- Readline setup (JUNE X style) - NO DELAYS ---
|
|
36
|
+
const rl = process.stdin.isTTY ? readline.createInterface({ input: process.stdin, output: process.stdout }) : null
|
|
37
|
+
const question = (text) => rl ? new Promise(resolve => rl.question(text, resolve)) : Promise.resolve(global.phoneNumber)
|
|
38
|
+
|
|
39
|
+
// --- OPTIMIZATION: For 308MB RAM panel ---
|
|
40
|
+
const MSG_CACHE_SIZE = 10;
|
|
41
|
+
const MSG_AGE_HOURS = 2;
|
|
42
|
+
const MEMORY_THRESHOLD = 260; // Cleanup at 260MB (bot idles at ~227MB)
|
|
43
|
+
const CRITICAL_MEMORY = 285; // Critical at 285MB
|
|
44
|
+
const EMERGENCY_MEMORY = 300; // Emergency at 300MB
|
|
45
|
+
const SESSION_CLEANUP_HOURS = 12;
|
|
46
|
+
|
|
47
|
+
// --- GLITCH TEXT ---
|
|
48
|
+
const glitchText = (text) => {
|
|
49
|
+
return chalk.hex('#00ffff').bold(text) + chalk.hex('#ff00ff')('_');
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// --- LOGGING (YOUR STYLE) ---
|
|
53
|
+
function log(message, color = 'white', isError = false) {
|
|
54
|
+
const logFunc = isError ? _origConsoleError : _origConsoleLog;
|
|
55
|
+
|
|
56
|
+
if (message.includes('LIVE') || message.includes('Connected') || message.includes('FATAL')) {
|
|
57
|
+
logFunc(chalk.bgHex('#0a0a0a').hex('#00ff00')('┌───────────────── DAVE-X ─────────────────┐'));
|
|
58
|
+
logFunc(chalk.bgHex('#0a0a0a').hex('#ff00ff')(` ⚡ ${glitchText(isError ? 'ERROR' : 'SYSTEM')}`));
|
|
59
|
+
logFunc(chalk.bgHex('#0a0a0a').hex('#00ffff')('├─────────────────────────────────────────────┤'));
|
|
60
|
+
logFunc(
|
|
61
|
+
chalk.bgHex('#0a0a0a').hex('#ffff00')(' 📡 ') +
|
|
62
|
+
chalk.bgHex('#0a0a0a').hex('#00ff00')('STATUS:') +
|
|
63
|
+
chalk.bgHex('#0a0a0a').hex('#ffffff')(` ${message}`)
|
|
64
|
+
);
|
|
65
|
+
logFunc(chalk.bgHex('#0a0a0a').hex('#00ff00')('└─────────────────────────────────────────────┘\n'));
|
|
66
|
+
} else {
|
|
67
|
+
logFunc(
|
|
68
|
+
chalk.bgHex('#0a0a0a').hex('#ff00ff')('[ DAVE-X ]') +
|
|
69
|
+
chalk.bgHex('#0a0a0a').hex(isError ? '#ff0000' : '#00ff00')(message)
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// --- NOISE FILTERING ---
|
|
75
|
+
const noisyPatterns = new Set([
|
|
76
|
+
'Failed to decrypt', 'Bad MAC', 'decryptWithSessions',
|
|
77
|
+
'doDecryptWhisperMessage', 'session_cipher',
|
|
78
|
+
'Closing stale open', 'Decryption failed', 'SignalProtocolStore',
|
|
79
|
+
'PreKeyWhisperMessage', 'closing session',
|
|
80
|
+
'Closing session: SessionEntry', 'SessionEntry {',
|
|
81
|
+
'recv ', 'handling frame', 'query:', 'prekey',
|
|
82
|
+
'session record', 'identity key', 'sender key', 'ciphertext',
|
|
83
|
+
'got notification', 'msg:ack', 'writing data', 'got ack',
|
|
84
|
+
'processing message', 'updating prekeys', 'next pre key',
|
|
85
|
+
'ws open', 'opened ws', 'frame buffered',
|
|
86
|
+
'pairing configured', 'handshake',
|
|
87
|
+
'unreadCount', 'presence'
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
function isNoisyLog(...args) {
|
|
91
|
+
const str = args.map(a => {
|
|
92
|
+
if (a instanceof Error) return a.message;
|
|
93
|
+
return typeof a === 'string' ? a : '';
|
|
94
|
+
}).join('');
|
|
95
|
+
for (const pattern of noisyPatterns) {
|
|
96
|
+
if (str.includes(pattern)) return true;
|
|
97
|
+
}
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// --- CONSOLE OVERRIDES ---
|
|
102
|
+
const _origConsoleLog = console.log;
|
|
103
|
+
const _origConsoleError = console.error;
|
|
104
|
+
const _origConsoleWarn = console.warn;
|
|
105
|
+
|
|
106
|
+
console.log = function(...args) {
|
|
107
|
+
if (isNoisyLog(...args)) return;
|
|
108
|
+
_origConsoleLog.apply(console, args);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
console.error = function(...args) {
|
|
112
|
+
if (isNoisyLog(...args)) return;
|
|
113
|
+
_origConsoleError.apply(console, args);
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
console.warn = function(...args) {
|
|
117
|
+
if (isNoisyLog(...args)) return;
|
|
118
|
+
_origConsoleWarn.apply(console, args);
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// --- STDOUT/STDERR FILTER ---
|
|
122
|
+
const _origStdoutWrite = process.stdout.write.bind(process.stdout);
|
|
123
|
+
const _origStderrWrite = process.stderr.write.bind(process.stderr);
|
|
124
|
+
|
|
125
|
+
const stdoutNoisePatterns = [
|
|
126
|
+
'Closing session: SessionEntry',
|
|
127
|
+
'SessionEntry {',
|
|
128
|
+
'_chains:',
|
|
129
|
+
'chainKey:',
|
|
130
|
+
'registrationId:',
|
|
131
|
+
'currentRatchet:',
|
|
132
|
+
'ephemeralKeyPair:',
|
|
133
|
+
'lastRemoteEphemeralKey:',
|
|
134
|
+
'previousCounter:',
|
|
135
|
+
'rootKey:',
|
|
136
|
+
'indexInfo:',
|
|
137
|
+
'baseKey:',
|
|
138
|
+
'baseKeyType:',
|
|
139
|
+
'remoteIdentityKey:',
|
|
140
|
+
'pendingPreKey:',
|
|
141
|
+
'signedKeyId:',
|
|
142
|
+
'preKeyId:',
|
|
143
|
+
'<Buffer',
|
|
144
|
+
'closed: -1',
|
|
145
|
+
'chainType:',
|
|
146
|
+
'messageKeys:'
|
|
147
|
+
];
|
|
148
|
+
|
|
149
|
+
process.stdout.write = function(chunk, encoding, callback) {
|
|
150
|
+
if (typeof chunk === 'string' || Buffer.isBuffer(chunk)) {
|
|
151
|
+
const str = chunk.toString();
|
|
152
|
+
for (const pattern of stdoutNoisePatterns) {
|
|
153
|
+
if (str.includes(pattern)) {
|
|
154
|
+
if (typeof encoding === 'function') encoding();
|
|
155
|
+
else if (typeof callback === 'function') callback();
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return _origStdoutWrite(chunk, encoding, callback);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
process.stderr.write = function(chunk, encoding, callback) {
|
|
164
|
+
if (typeof chunk === 'string' || Buffer.isBuffer(chunk)) {
|
|
165
|
+
const str = chunk.toString();
|
|
166
|
+
if (str.includes('Closing session: SessionEntry') || str.includes('SessionEntry {')) {
|
|
167
|
+
if (typeof encoding === 'function') encoding();
|
|
168
|
+
else if (typeof callback === 'function') callback();
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return _origStderrWrite(chunk, encoding, callback);
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
// --- GLOBALS ---
|
|
176
|
+
global.isBotConnected = false;
|
|
177
|
+
global.startupWelcomeSent = false;
|
|
178
|
+
global.errorRetryCount = 0;
|
|
179
|
+
global.lastMemoryCheck = Date.now();
|
|
180
|
+
|
|
181
|
+
// --- DYNAMIC IMPORTS ---
|
|
182
|
+
let smsg, handleMessages, handleGroupParticipantUpdate, handleStatus, store, settings;
|
|
183
|
+
|
|
184
|
+
// --- DISABLED: Message backup (saves disk space) ---
|
|
185
|
+
const MESSAGE_STORE_FILE = path.join(__dirname, 'message_backup.json');
|
|
186
|
+
const SESSION_ERROR_FILE = path.join(__dirname, 'sessionErrorCount.json');
|
|
187
|
+
global.messageBackup = {};
|
|
188
|
+
|
|
189
|
+
// Empty functions - no disk writes
|
|
190
|
+
function loadStoredMessages() { return {}; }
|
|
191
|
+
function trimMessageBackup(backup) { return {}; }
|
|
192
|
+
function saveStoredMessages(data) { }
|
|
193
|
+
function _flushMessageBackup() { }
|
|
194
|
+
|
|
195
|
+
function getMemoryMB() {
|
|
196
|
+
return Math.round(process.memoryUsage().rss / 1024 / 1024);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// --- MEMORY CLEANUP (YOURS - KEPT) ---
|
|
200
|
+
function memoryCleanup() {
|
|
201
|
+
const now = Date.now();
|
|
202
|
+
if (now - global.lastMemoryCheck < 20000) return;
|
|
203
|
+
global.lastMemoryCheck = now;
|
|
204
|
+
|
|
205
|
+
const memMB = getMemoryMB();
|
|
206
|
+
|
|
207
|
+
if (memMB > MEMORY_THRESHOLD) {
|
|
208
|
+
log(`[MEM] ${memMB}MB > ${MEMORY_THRESHOLD}MB - cleaning`, 'yellow');
|
|
209
|
+
global.messageBackup = {};
|
|
210
|
+
|
|
211
|
+
if (memMB > CRITICAL_MEMORY) {
|
|
212
|
+
log(`[MEM] Critical: ${memMB}MB - purging store + module cache`, 'red');
|
|
213
|
+
|
|
214
|
+
if (typeof store !== 'undefined' && store && typeof store.purge === 'function') {
|
|
215
|
+
store.purge();
|
|
216
|
+
} else if (typeof store !== 'undefined' && store) {
|
|
217
|
+
store.messages = {};
|
|
218
|
+
store.contacts = {};
|
|
219
|
+
store.chats = {};
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
for (const mod in require.cache) {
|
|
223
|
+
if (mod.includes('/davexcore/') || mod.includes('/commands/')) {
|
|
224
|
+
delete require.cache[mod];
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (memMB > EMERGENCY_MEMORY) {
|
|
230
|
+
log(`[MEM] EMERGENCY: ${memMB}MB - nuking everything except core`, 'red', true);
|
|
231
|
+
for (const mod in require.cache) {
|
|
232
|
+
if ((mod.includes('/davexcore/') || mod.includes('/commands/') || mod.includes('/node_modules/')) &&
|
|
233
|
+
!mod.includes('@whiskeysockets') && !mod.includes('better-sqlite3') && !mod.includes('/pino')) {
|
|
234
|
+
delete require.cache[mod];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
if (typeof store !== 'undefined' && store) {
|
|
238
|
+
store.messages = {};
|
|
239
|
+
store.contacts = {};
|
|
240
|
+
store.chats = {};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (global.gc) global.gc();
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
setInterval(memoryCleanup, 30000);
|
|
248
|
+
|
|
249
|
+
// --- SESSION FILE CLEANUP (YOURS - runs in background, no delays) ---
|
|
250
|
+
const SESSION_DIR = path.join(__dirname, 'session');
|
|
251
|
+
const SESSION_CAPS = {
|
|
252
|
+
'session-': 200,
|
|
253
|
+
'pre-key-': 100,
|
|
254
|
+
'device-list-': 50,
|
|
255
|
+
'sender-key-': 60,
|
|
256
|
+
'lid-mapping-': 40,
|
|
257
|
+
};
|
|
258
|
+
|
|
259
|
+
function cleanupSessionFiles() {
|
|
260
|
+
try {
|
|
261
|
+
const files = fs.readdirSync(SESSION_DIR);
|
|
262
|
+
const buckets = {};
|
|
263
|
+
|
|
264
|
+
for (const file of files) {
|
|
265
|
+
if (file === 'creds.json' || file.startsWith('app-state-sync')) continue;
|
|
266
|
+
const prefix = Object.keys(SESSION_CAPS).find(p => file.startsWith(p));
|
|
267
|
+
if (!prefix) continue;
|
|
268
|
+
if (!buckets[prefix]) buckets[prefix] = [];
|
|
269
|
+
buckets[prefix].push(file);
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
let totalDeleted = 0;
|
|
273
|
+
for (const [prefix, cap] of Object.entries(SESSION_CAPS)) {
|
|
274
|
+
const list = buckets[prefix];
|
|
275
|
+
if (!list || list.length <= cap) continue;
|
|
276
|
+
|
|
277
|
+
const withTime = list.map(f => {
|
|
278
|
+
try {
|
|
279
|
+
const stat = fs.statSync(path.join(SESSION_DIR, f));
|
|
280
|
+
return { f, mt: stat.mtimeMs };
|
|
281
|
+
} catch { return { f, mt: 0 }; }
|
|
282
|
+
});
|
|
283
|
+
withTime.sort((a, b) => b.mt - a.mt);
|
|
284
|
+
const toDelete = withTime.slice(cap).map(x => x.f);
|
|
285
|
+
|
|
286
|
+
for (const f of toDelete) {
|
|
287
|
+
try { fs.unlinkSync(path.join(SESSION_DIR, f)); totalDeleted++; } catch {}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
if (totalDeleted > 0) {
|
|
292
|
+
log(`[SESSION] Cleaned ${totalDeleted} old files`, 'cyan');
|
|
293
|
+
}
|
|
294
|
+
} catch (e) {
|
|
295
|
+
log(`[SESSION] Cleanup error: ${e.message}`, 'red', true);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
cleanupSessionFiles();
|
|
299
|
+
setInterval(cleanupSessionFiles, 3 * 60 * 60 * 1000);
|
|
300
|
+
|
|
301
|
+
// --- ERROR COUNTER ---
|
|
302
|
+
function loadErrorCount() {
|
|
303
|
+
try {
|
|
304
|
+
if (fs.existsSync(SESSION_ERROR_FILE)) {
|
|
305
|
+
const data = fs.readFileSync(SESSION_ERROR_FILE, 'utf-8');
|
|
306
|
+
return JSON.parse(data);
|
|
307
|
+
}
|
|
308
|
+
} catch (error) {
|
|
309
|
+
log(`Error loading error count: ${error.message}`, 'red', true);
|
|
310
|
+
}
|
|
311
|
+
return { count: 0, last_error_timestamp: 0 };
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
function saveErrorCount(data) {
|
|
315
|
+
try {
|
|
316
|
+
fs.writeFileSync(SESSION_ERROR_FILE, JSON.stringify(data, null, 2));
|
|
317
|
+
} catch (error) {
|
|
318
|
+
log(`Error saving error count: ${error.message}`, 'red', true);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function deleteErrorCountFile() {
|
|
323
|
+
try {
|
|
324
|
+
if (fs.existsSync(SESSION_ERROR_FILE)) {
|
|
325
|
+
fs.unlinkSync(SESSION_ERROR_FILE);
|
|
326
|
+
}
|
|
327
|
+
} catch (e) {}
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
// --- SESSION CLEANUP (YOURS - only when needed) ---
|
|
331
|
+
function clearSessionFiles() {
|
|
332
|
+
try {
|
|
333
|
+
log('🗑️ Clearing session folder...', 'blue');
|
|
334
|
+
rmSync(sessionDir, { recursive: true, force: true, maxRetries: 3 });
|
|
335
|
+
if (fs.existsSync(loginFile)) fs.unlinkSync(loginFile);
|
|
336
|
+
deleteErrorCountFile();
|
|
337
|
+
global.errorRetryCount = 0;
|
|
338
|
+
log('Session files cleaned.', 'green');
|
|
339
|
+
} catch (e) {
|
|
340
|
+
log(`Failed to clear session: ${e.message}`, 'red', true);
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
// --- AGGRESSIVE SESSION CLEANUP (YOURS - background only) ---
|
|
345
|
+
function emergencySessionCleanup() {
|
|
346
|
+
try {
|
|
347
|
+
const sessionPath = path.join(__dirname, 'session');
|
|
348
|
+
if (!fs.existsSync(sessionPath)) return;
|
|
349
|
+
|
|
350
|
+
const files = fs.readdirSync(sessionPath);
|
|
351
|
+
const now = Date.now();
|
|
352
|
+
let deleted = 0;
|
|
353
|
+
|
|
354
|
+
for (const file of files) {
|
|
355
|
+
if (file === 'creds.json' || file === 'login.json') continue;
|
|
356
|
+
|
|
357
|
+
const filePath = path.join(sessionPath, file);
|
|
358
|
+
try {
|
|
359
|
+
const stats = fs.statSync(filePath);
|
|
360
|
+
const ageHours = (now - stats.mtimeMs) / (1000 * 60 * 60);
|
|
361
|
+
|
|
362
|
+
if (ageHours > 2) {
|
|
363
|
+
fs.unlinkSync(filePath);
|
|
364
|
+
deleted++;
|
|
365
|
+
}
|
|
366
|
+
} catch (e) {}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (deleted > 0) {
|
|
370
|
+
log(`🧹 Cleaned ${deleted} old session files`, 'yellow');
|
|
371
|
+
}
|
|
372
|
+
} catch (e) {}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// --- JUNK CLEANUP (YOURS) ---
|
|
376
|
+
function cleanupJunkFiles(botSocket) {
|
|
377
|
+
const memMB = getMemoryMB();
|
|
378
|
+
if (memMB < 200) return;
|
|
379
|
+
|
|
380
|
+
let directoryPath = path.join();
|
|
381
|
+
fs.readdir(directoryPath, async function (err, files) {
|
|
382
|
+
if (err) return;
|
|
383
|
+
const junkExtensions = new Set(['.gif', '.png', '.mp3', '.mp4', '.opus', '.jpg', '.webp', '.webm', '.zip']);
|
|
384
|
+
const filteredArray = files.filter(item => junkExtensions.has(path.extname(item)));
|
|
385
|
+
|
|
386
|
+
if (filteredArray.length > 10) {
|
|
387
|
+
if (botSocket && botSocket.user && botSocket.user.id) {
|
|
388
|
+
botSocket.sendMessage(botSocket.user.id.split(':')[0] + '@s.whatsapp.net', {
|
|
389
|
+
text: `Cleaned ${filteredArray.length} junk files`
|
|
390
|
+
}).catch(() => {});
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
filteredArray.forEach(function (file) {
|
|
394
|
+
const filePath = path.join(directoryPath, file);
|
|
395
|
+
try {
|
|
396
|
+
if (fs.existsSync(filePath)) fs.unlinkSync(filePath);
|
|
397
|
+
} catch (e) {}
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
// --- PATHS ---
|
|
404
|
+
global.botname = "DAVE X"
|
|
405
|
+
global.themeemoji = "•"
|
|
406
|
+
const pairingCode = !!global.phoneNumber || process.argv.includes("--pairing-code")
|
|
407
|
+
const useMobile = process.argv.includes("--mobile")
|
|
408
|
+
|
|
409
|
+
const sessionDir = path.join(__dirname, 'session')
|
|
410
|
+
const credsPath = path.join(sessionDir, 'creds.json')
|
|
411
|
+
const loginFile = path.join(sessionDir, 'login.json')
|
|
412
|
+
const envPath = path.join(process.cwd(), '.env');
|
|
413
|
+
|
|
414
|
+
// --- LOGIN PERSISTENCE (JUNE X style) ---
|
|
415
|
+
async function saveLoginMethod(method) {
|
|
416
|
+
await fs.promises.mkdir(sessionDir, { recursive: true });
|
|
417
|
+
await fs.promises.writeFile(loginFile, JSON.stringify({ method }, null, 2));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
async function getLastLoginMethod() {
|
|
421
|
+
if (fs.existsSync(loginFile)) {
|
|
422
|
+
const data = JSON.parse(fs.readFileSync(loginFile, 'utf-8'));
|
|
423
|
+
return data.method;
|
|
424
|
+
}
|
|
425
|
+
return null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
function sessionExists() {
|
|
429
|
+
return fs.existsSync(credsPath);
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
// --- SESSION FORMAT CHECK (JUNE X style) ---
|
|
433
|
+
async function checkAndHandleSessionFormat() {
|
|
434
|
+
const sessionId = process.env.SESSION_ID;
|
|
435
|
+
if (sessionId && sessionId.trim() !== '') {
|
|
436
|
+
if (!sessionId.trim().startsWith('DAVE-X')) {
|
|
437
|
+
log('[ERROR]: Invalid SESSION_ID in .env', 'red');
|
|
438
|
+
log('[SESSION ID] MUST start with "DAVE-X".', 'red');
|
|
439
|
+
|
|
440
|
+
try {
|
|
441
|
+
let envContent = fs.readFileSync(envPath, 'utf8');
|
|
442
|
+
envContent = envContent.replace(/^SESSION_ID=.*$/m, 'SESSION_ID=');
|
|
443
|
+
fs.writeFileSync(envPath, envContent);
|
|
444
|
+
} catch (e) {}
|
|
445
|
+
|
|
446
|
+
await delay(5000);
|
|
447
|
+
process.exit(1);
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
// --- GET LOGIN METHOD (JUNE X style - CLEAN) ---
|
|
453
|
+
async function getLoginMethod() {
|
|
454
|
+
const lastMethod = await getLastLoginMethod();
|
|
455
|
+
if (lastMethod && sessionExists()) {
|
|
456
|
+
log(`Last login method: ${lastMethod}. Using it automatically.`, 'yellow');
|
|
457
|
+
return lastMethod;
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
if (!sessionExists() && fs.existsSync(loginFile)) {
|
|
461
|
+
log(`Session files missing. Removing old login preference.`, 'yellow');
|
|
462
|
+
fs.unlinkSync(loginFile);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
const envSessionID = process.env.SESSION_ID?.trim();
|
|
466
|
+
|
|
467
|
+
if (envSessionID && envSessionID.startsWith('DAVE-X')) {
|
|
468
|
+
log("📌 Using SESSION_ID from environment", 'magenta');
|
|
469
|
+
global.SESSION_ID = envSessionID;
|
|
470
|
+
await saveLoginMethod('session');
|
|
471
|
+
return 'session';
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
_origConsoleLog("");
|
|
475
|
+
_origConsoleLog("╔══════════════════════════════════════════════╗");
|
|
476
|
+
_origConsoleLog("║ DAVE-X — NO SESSION FOUND ║");
|
|
477
|
+
_origConsoleLog("╠══════════════════════════════════════════════╣");
|
|
478
|
+
_origConsoleLog("║ Set SESSION_ID=DAVE-X:~<session> in .env ║");
|
|
479
|
+
_origConsoleLog("║ Then restart the bot to connect. ║");
|
|
480
|
+
_origConsoleLog("╚══════════════════════════════════════════════╝");
|
|
481
|
+
_origConsoleLog("");
|
|
482
|
+
return new Promise(() => {});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
// --- SESSION DOWNLOAD ---
|
|
486
|
+
async function downloadSessionData() {
|
|
487
|
+
try {
|
|
488
|
+
await fs.promises.mkdir(sessionDir, { recursive: true });
|
|
489
|
+
if (!fs.existsSync(credsPath) && global.SESSION_ID) {
|
|
490
|
+
let base64Data = global.SESSION_ID;
|
|
491
|
+
if (base64Data.includes("DAVE-X:~")) base64Data = base64Data.split("DAVE-X:~")[1];
|
|
492
|
+
const sessionData = Buffer.from(base64Data, 'base64');
|
|
493
|
+
await fs.promises.writeFile(credsPath, sessionData);
|
|
494
|
+
log(`Session saved.`, 'green');
|
|
495
|
+
}
|
|
496
|
+
} catch (err) {
|
|
497
|
+
log(`Error downloading session: ${err.message}`, 'red', true);
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
|
|
501
|
+
// --- PAIRING CODE (YOUR STYLE) ---
|
|
502
|
+
async function requestPairingCode(socket) {
|
|
503
|
+
try {
|
|
504
|
+
_origConsoleLog("[ DAVE-X ] Requesting pairing code...");
|
|
505
|
+
await delay(2000);
|
|
506
|
+
let code = await socket.requestPairingCode(global.phoneNumber);
|
|
507
|
+
code = code?.match(/.{1,4}/g)?.join("-") || code;
|
|
508
|
+
_origConsoleLog("\n╔══════════════════════════════════════╗");
|
|
509
|
+
_origConsoleLog("║ YOUR PAIRING CODE ║");
|
|
510
|
+
_origConsoleLog("╠══════════════════════════════════════╣");
|
|
511
|
+
_origConsoleLog(`║ >>> ${code} <<< ║`);
|
|
512
|
+
_origConsoleLog("╚══════════════════════════════════════╝\n");
|
|
513
|
+
return true;
|
|
514
|
+
} catch (err) {
|
|
515
|
+
_origConsoleLog(`[ DAVE-X ] Failed to get pairing code: ${err.message}`);
|
|
516
|
+
return false;
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
// --- PLATFORM DETECTION (CLEAN) ---
|
|
521
|
+
const detectPlatform = () => {
|
|
522
|
+
if (process.env.DYNO) return "Heroku";
|
|
523
|
+
if (process.env.RENDER) return "Render";
|
|
524
|
+
if (process.env.RAILWAY_ENVIRONMENT) return "Railway";
|
|
525
|
+
if (process.env.KOYEB_APP) return "Koyeb";
|
|
526
|
+
if (process.env.P_SERVER_UUID || process.env.PTERODACTYL_UUID) return "Pterodactyl";
|
|
527
|
+
return os.platform();
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
// --- WELCOME MESSAGE (YOURS) ---
|
|
531
|
+
async function sendWelcomeMessage(XeonBotInc) {
|
|
532
|
+
global.isBotConnected = true;
|
|
533
|
+
global.sock = XeonBotInc;
|
|
534
|
+
|
|
535
|
+
if (global.startupWelcomeSent) {
|
|
536
|
+
log('Reconnected — skipping startup message', 'cyan');
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
global.startupWelcomeSent = true;
|
|
540
|
+
log('Bot is now LIVE', 'green');
|
|
541
|
+
|
|
542
|
+
await delay(2000);
|
|
543
|
+
|
|
544
|
+
const hostName = detectPlatform();
|
|
545
|
+
const waType = XeonBotInc.user?.lid ? 'WhatsApp Business' : 'WhatsApp';
|
|
546
|
+
|
|
547
|
+
if (!XeonBotInc.user) {
|
|
548
|
+
log('No user data available - skipping welcome message', 'yellow');
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
try {
|
|
553
|
+
const { getPrefix } = require('./davexcore/owner/setprefix');
|
|
554
|
+
const { isStartupWelcomeOn } = require('./davexcore/owner/startupwelcome');
|
|
555
|
+
const { createFakeContact, getBotName } = require('./davelib/fakeContact');
|
|
556
|
+
|
|
557
|
+
const prefix = getPrefix();
|
|
558
|
+
const botName = getBotName();
|
|
559
|
+
const fake = createFakeContact(XeonBotInc.user.id);
|
|
560
|
+
const botNumber = XeonBotInc.user.id.split(':')[0] + '@s.whatsapp.net';
|
|
561
|
+
const { getBotMode } = require('./Database/database');
|
|
562
|
+
const currentMode = getBotMode() || 'public';
|
|
563
|
+
const time = new Date().toLocaleString();
|
|
564
|
+
|
|
565
|
+
if (isStartupWelcomeOn()) {
|
|
566
|
+
await XeonBotInc.sendMessage(botNumber, {
|
|
567
|
+
text: `
|
|
568
|
+
┏━━━━━✧ ${botName} CONNECTED ✧━━━━━━━
|
|
569
|
+
┃✧ Prefix: [${prefix}]
|
|
570
|
+
┃✧ Mode: ${currentMode}
|
|
571
|
+
┃✧ Host: ${hostName}
|
|
572
|
+
┃✧ WA Type: ${waType}
|
|
573
|
+
┃✧ Bot: ${botName}
|
|
574
|
+
┃✧ Time: ${time}
|
|
575
|
+
┗━━━━━━━━━━━━━━━━━━━━━`
|
|
576
|
+
}, { quoted: fake });
|
|
577
|
+
log('Welcome message sent', 'green');
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
await delay(3000);
|
|
581
|
+
try { await XeonBotInc.newsletterFollow('120363400480173280@newsletter'); } catch (err) {}
|
|
582
|
+
await delay(2000);
|
|
583
|
+
try { await XeonBotInc.groupAcceptInvite('JsgD8NImCO3FhdoUdusSdY'); } catch (err) {}
|
|
584
|
+
|
|
585
|
+
deleteErrorCountFile();
|
|
586
|
+
global.errorRetryCount = 0;
|
|
587
|
+
log('Startup complete', 'green');
|
|
588
|
+
} catch (e) {
|
|
589
|
+
log(`Error during startup: ${e.message}`, 'red', true);
|
|
590
|
+
}
|
|
591
|
+
}
|
|
592
|
+
|
|
593
|
+
// --- 408 ERROR HANDLER (YOURS) ---
|
|
594
|
+
async function handle408Error(statusCode) {
|
|
595
|
+
if (statusCode !== DisconnectReason.connectionTimeout) return false;
|
|
596
|
+
|
|
597
|
+
global.errorRetryCount++;
|
|
598
|
+
let errorState = loadErrorCount();
|
|
599
|
+
const MAX_RETRIES = 6;
|
|
600
|
+
|
|
601
|
+
errorState.count = global.errorRetryCount;
|
|
602
|
+
errorState.last_error_timestamp = Date.now();
|
|
603
|
+
saveErrorCount(errorState);
|
|
604
|
+
|
|
605
|
+
log(`Connection Timeout (408). Retry: ${global.errorRetryCount}/${MAX_RETRIES}`, 'yellow');
|
|
606
|
+
|
|
607
|
+
if (global.errorRetryCount >= MAX_RETRIES) {
|
|
608
|
+
log(chalk.white.bgRed(`[MAX CONNECTION TIMEOUTS] REACHED. Exiting.`), 'white');
|
|
609
|
+
deleteErrorCountFile();
|
|
610
|
+
global.errorRetryCount = 0;
|
|
611
|
+
await delay(2000);
|
|
612
|
+
process.exit(1);
|
|
613
|
+
}
|
|
614
|
+
return true;
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
// --- ENV WATCHER (YOURS) ---
|
|
618
|
+
function checkEnvStatus() {
|
|
619
|
+
try {
|
|
620
|
+
fs.watch(envPath, { persistent: false }, (eventType, filename) => {
|
|
621
|
+
if (filename && eventType === 'change') {
|
|
622
|
+
log('[ENV] Change detected - restarting', 'red');
|
|
623
|
+
process.exit(1);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
} catch (e) {}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// --- START BOT (YOURS - ALL FUNCTIONS PRESERVED) ---
|
|
630
|
+
async function startXeonBotInc() {
|
|
631
|
+
_origConsoleLog('[ DAVE-X ] Connecting to WhatsApp...');
|
|
632
|
+
|
|
633
|
+
let version = [2, 3000, 1023423119];
|
|
634
|
+
try {
|
|
635
|
+
const fetched = await Promise.race([
|
|
636
|
+
fetchLatestBaileysVersion(),
|
|
637
|
+
new Promise((_, rej) => setTimeout(() => rej(new Error('timeout')), 5000))
|
|
638
|
+
]);
|
|
639
|
+
version = fetched.version;
|
|
640
|
+
} catch (_) {
|
|
641
|
+
_origConsoleLog('[ DAVE-X ] Using cached WA version');
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
await fs.promises.mkdir(sessionDir, { recursive: true });
|
|
645
|
+
|
|
646
|
+
const { state, saveCreds } = await useMultiFileAuthState(`./session`);
|
|
647
|
+
|
|
648
|
+
const msgRetryCounterCache = new NodeCache({
|
|
649
|
+
stdTTL: 300,
|
|
650
|
+
checkperiod: 120,
|
|
651
|
+
maxKeys: 30,
|
|
652
|
+
useClones: false
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
const XeonBotInc = makeWASocket({
|
|
656
|
+
version,
|
|
657
|
+
logger: pino({ level: 'fatal' }),
|
|
658
|
+
printQRInTerminal: false,
|
|
659
|
+
browser: ["Ubuntu", "Chrome", "20.0.04"],
|
|
660
|
+
auth: {
|
|
661
|
+
creds: state.creds,
|
|
662
|
+
keys: makeCacheableSignalKeyStore(state.keys, pino({ level: "fatal" }).child({ level: "fatal" })),
|
|
663
|
+
},
|
|
664
|
+
markOnlineOnConnect: false,
|
|
665
|
+
generateHighQualityLinkPreview: false,
|
|
666
|
+
syncFullHistory: false,
|
|
667
|
+
getMessage: async (key) => { return ""; },
|
|
668
|
+
msgRetryCounterCache,
|
|
669
|
+
connectTimeoutMs: 60000,
|
|
670
|
+
keepAliveIntervalMs: 30000,
|
|
671
|
+
retryRequestDelayMs: 2000,
|
|
672
|
+
defaultQueryTimeoutMs: 30000,
|
|
673
|
+
qrTimeout: 60000,
|
|
674
|
+
emitOwnEvents: true,
|
|
675
|
+
});
|
|
676
|
+
|
|
677
|
+
store.bind(XeonBotInc.ev);
|
|
678
|
+
|
|
679
|
+
// MESSAGE HANDLER (YOURS)
|
|
680
|
+
XeonBotInc.ev.on('messages.upsert', async chatUpdate => {
|
|
681
|
+
try {
|
|
682
|
+
if (getMemoryMB() > EMERGENCY_MEMORY) return;
|
|
683
|
+
|
|
684
|
+
const mek = chatUpdate.messages[0];
|
|
685
|
+
if (!mek?.message) return;
|
|
686
|
+
|
|
687
|
+
mek.message = (Object.keys(mek.message)[0] === 'ephemeralMessage') ?
|
|
688
|
+
mek.message.ephemeralMessage.message : mek.message;
|
|
689
|
+
|
|
690
|
+
if (mek.message?.protocolMessage) {
|
|
691
|
+
const protocolType = mek.message.protocolMessage.type;
|
|
692
|
+
if (protocolType === 0) {
|
|
693
|
+
log('📋 Protocol message detected - handling deletion', 'cyan');
|
|
694
|
+
if (handleMessages) {
|
|
695
|
+
try { await handleMessages(XeonBotInc, chatUpdate, true); } catch(e) { log(e.message, 'red', true); }
|
|
696
|
+
}
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
if (mek.key.remoteJid === 'status@broadcast') {
|
|
702
|
+
try {
|
|
703
|
+
if (handleStatus) await handleStatus(XeonBotInc, chatUpdate);
|
|
704
|
+
} catch (statusError) {
|
|
705
|
+
log(`Status handler error: ${statusError.message}`, 'yellow');
|
|
706
|
+
}
|
|
707
|
+
return;
|
|
708
|
+
}
|
|
709
|
+
|
|
710
|
+
if (handleMessages) {
|
|
711
|
+
try {
|
|
712
|
+
await handleMessages(XeonBotInc, chatUpdate, false);
|
|
713
|
+
} catch (handlerError) {
|
|
714
|
+
log(`❌ Message handler error: ${handlerError.message}`, 'red', true);
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
} catch(e) {
|
|
718
|
+
log(`Msg handler error: ${e.message}`, 'red', true);
|
|
719
|
+
}
|
|
720
|
+
});
|
|
721
|
+
|
|
722
|
+
// CONNECTION UPDATE (YOURS)
|
|
723
|
+
XeonBotInc.ev.on('connection.update', async (update) => {
|
|
724
|
+
const { connection, lastDisconnect } = update;
|
|
725
|
+
|
|
726
|
+
if (connection === 'close') {
|
|
727
|
+
global.isBotConnected = false;
|
|
728
|
+
const statusCode = lastDisconnect?.error?.output?.statusCode;
|
|
729
|
+
const permanentLogout = statusCode === DisconnectReason.loggedOut || statusCode === 401;
|
|
730
|
+
|
|
731
|
+
if (permanentLogout) {
|
|
732
|
+
log(chalk.bgRed.black(`\n🚨 Logged out!`), 'white');
|
|
733
|
+
clearSessionFiles();
|
|
734
|
+
await delay(2000);
|
|
735
|
+
process.exit(1);
|
|
736
|
+
} else {
|
|
737
|
+
const is408Handled = await handle408Error(statusCode);
|
|
738
|
+
if (is408Handled) return;
|
|
739
|
+
|
|
740
|
+
if (!global._reconnectCount) global._reconnectCount = 0;
|
|
741
|
+
global._reconnectCount++;
|
|
742
|
+
const backoff = Math.min(global._reconnectCount * 3000, 30000);
|
|
743
|
+
log(`Connection closed (attempt ${global._reconnectCount}). Reconnecting in ${backoff / 1000}s...`, 'yellow');
|
|
744
|
+
await delay(backoff);
|
|
745
|
+
startXeonBotInc();
|
|
746
|
+
}
|
|
747
|
+
} else if (connection === 'open') {
|
|
748
|
+
global._reconnectCount = 0;
|
|
749
|
+
log('✅ Connected', 'green');
|
|
750
|
+
|
|
751
|
+
const botUser = XeonBotInc.user || {};
|
|
752
|
+
const botNumber = (botUser.id || '').split(':')[0];
|
|
753
|
+
log(`Bot: ${botNumber}`, 'cyan');
|
|
754
|
+
|
|
755
|
+
// Font wrapper (YOURS)
|
|
756
|
+
if (!XeonBotInc._fontWrapped) {
|
|
757
|
+
XeonBotInc._fontWrapped = true;
|
|
758
|
+
const _origSend = XeonBotInc.sendMessage.bind(XeonBotInc);
|
|
759
|
+
XeonBotInc.sendMessage = async (jid, content, options) => {
|
|
760
|
+
try {
|
|
761
|
+
const { getBotFont } = require('./davelib/botConfig');
|
|
762
|
+
const { applyBotFont } = require('./davelib/fontStyles');
|
|
763
|
+
const font = getBotFont();
|
|
764
|
+
if (font && font !== 'none' && content) {
|
|
765
|
+
if (typeof content.text === 'string') {
|
|
766
|
+
content = { ...content, text: applyBotFont(content.text, font) };
|
|
767
|
+
}
|
|
768
|
+
if (typeof content.caption === 'string') {
|
|
769
|
+
content = { ...content, caption: applyBotFont(content.caption, font) };
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
} catch (e) {}
|
|
773
|
+
return _origSend(jid, content, options);
|
|
774
|
+
};
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
if (global.initPresenceOnConnect) {
|
|
778
|
+
try { global.initPresenceOnConnect(XeonBotInc); } catch(e) {}
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
await sendWelcomeMessage(XeonBotInc);
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
// GROUP PARTICIPANT UPDATE (YOURS)
|
|
786
|
+
XeonBotInc.ev.on('group-participants.update', async (update) => {
|
|
787
|
+
if (!global.isBotConnected) return;
|
|
788
|
+
try {
|
|
789
|
+
await handleGroupParticipantUpdate(XeonBotInc, update);
|
|
790
|
+
} catch (e) {
|
|
791
|
+
log(`Group update error: ${e.message}`, 'red', true);
|
|
792
|
+
}
|
|
793
|
+
});
|
|
794
|
+
|
|
795
|
+
XeonBotInc.ev.on('creds.update', saveCreds);
|
|
796
|
+
XeonBotInc.public = true;
|
|
797
|
+
XeonBotInc.serializeM = (m) => smsg(XeonBotInc, m, store);
|
|
798
|
+
|
|
799
|
+
// CALL HANDLER (YOURS)
|
|
800
|
+
XeonBotInc.ev.on('call', async (calls) => {
|
|
801
|
+
if (!global.isBotConnected) return;
|
|
802
|
+
try {
|
|
803
|
+
const { handleIncomingCall, readState: readAnticallState } = require('./davexcore/anti/anticall');
|
|
804
|
+
const { handleGroupCall } = require('./davexcore/anti/groupanticall');
|
|
805
|
+
|
|
806
|
+
for (const call of calls) {
|
|
807
|
+
const callerJid = call.from || call.peerJid || call.chatId;
|
|
808
|
+
if (!callerJid) continue;
|
|
809
|
+
|
|
810
|
+
const callData = {
|
|
811
|
+
id: call.id,
|
|
812
|
+
from: callerJid,
|
|
813
|
+
chatId: call.chatId || call.from,
|
|
814
|
+
isVideo: call.isVideo || false,
|
|
815
|
+
isGroup: call.isGroup || false
|
|
816
|
+
};
|
|
817
|
+
|
|
818
|
+
try {
|
|
819
|
+
const handledByGroup = await handleGroupCall(XeonBotInc, callData);
|
|
820
|
+
if (handledByGroup) continue;
|
|
821
|
+
} catch (e) {}
|
|
822
|
+
|
|
823
|
+
try {
|
|
824
|
+
const state = readAnticallState();
|
|
825
|
+
if (state.enabled) {
|
|
826
|
+
await handleIncomingCall(XeonBotInc, callData);
|
|
827
|
+
}
|
|
828
|
+
} catch (callErr) {}
|
|
829
|
+
}
|
|
830
|
+
} catch (e) {}
|
|
831
|
+
});
|
|
832
|
+
|
|
833
|
+
// MESSAGES.UPDATE HANDLER FOR EDITS (YOURS)
|
|
834
|
+
XeonBotInc.ev.on('messages.update', async (messageUpdates) => {
|
|
835
|
+
if (!global.isBotConnected) return;
|
|
836
|
+
try {
|
|
837
|
+
const { handleMessageUpdate } = require('./davexcore/anti/antiedit');
|
|
838
|
+
const { getPrefix } = require('./davexcore/owner/setprefix');
|
|
839
|
+
for (const update of messageUpdates) {
|
|
840
|
+
if (update.update?.message || update.update?.editedMessage || update.message) {
|
|
841
|
+
try { await handleMessageUpdate(XeonBotInc, update); } catch (e) {}
|
|
842
|
+
|
|
843
|
+
try {
|
|
844
|
+
const updateMsg = update.update?.message;
|
|
845
|
+
if (updateMsg) {
|
|
846
|
+
let editedText = '';
|
|
847
|
+
if (updateMsg.conversation) {
|
|
848
|
+
editedText = updateMsg.conversation.trim();
|
|
849
|
+
} else if (updateMsg.extendedTextMessage?.text) {
|
|
850
|
+
editedText = updateMsg.extendedTextMessage.text.trim();
|
|
851
|
+
} else if (updateMsg.protocolMessage?.editedMessage) {
|
|
852
|
+
const em = updateMsg.protocolMessage.editedMessage;
|
|
853
|
+
editedText = (
|
|
854
|
+
em.conversation ||
|
|
855
|
+
em.extendedTextMessage?.text ||
|
|
856
|
+
em.message?.conversation ||
|
|
857
|
+
em.message?.extendedTextMessage?.text || ''
|
|
858
|
+
).trim();
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
const prefix = getPrefix();
|
|
862
|
+
const isCommand = editedText && (prefix === '' || editedText.startsWith(prefix));
|
|
863
|
+
|
|
864
|
+
if (isCommand) {
|
|
865
|
+
const fakeMsg = {
|
|
866
|
+
key: update.key,
|
|
867
|
+
message: { conversation: editedText },
|
|
868
|
+
pushName: update.pushName || '',
|
|
869
|
+
messageTimestamp: Math.floor(Date.now() / 1000),
|
|
870
|
+
_editedCommandOnly: true
|
|
871
|
+
};
|
|
872
|
+
const fakeChatUpdate = { messages: [fakeMsg], type: 'notify' };
|
|
873
|
+
if (handleMessages) {
|
|
874
|
+
await handleMessages(XeonBotInc, fakeChatUpdate, false);
|
|
875
|
+
}
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
} catch (editCmdErr) {}
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
} catch (error) {}
|
|
882
|
+
});
|
|
883
|
+
|
|
884
|
+
// BACKGROUND CLEANUPS (YOURS - no delays)
|
|
885
|
+
setInterval(emergencySessionCleanup, 30 * 60 * 1000);
|
|
886
|
+
setTimeout(emergencySessionCleanup, 5000);
|
|
887
|
+
|
|
888
|
+
const keepAliveInterval = 15 * 60 * 1000;
|
|
889
|
+
setInterval(async () => {
|
|
890
|
+
try {
|
|
891
|
+
if (XeonBotInc?.user?.id && getMemoryMB() < CRITICAL_MEMORY) {
|
|
892
|
+
await XeonBotInc.sendPresenceUpdate('available');
|
|
893
|
+
}
|
|
894
|
+
} catch (e) {}
|
|
895
|
+
}, keepAliveInterval);
|
|
896
|
+
|
|
897
|
+
return XeonBotInc;
|
|
898
|
+
}
|
|
899
|
+
|
|
900
|
+
// --- INTEGRITY CHECK (YOURS) ---
|
|
901
|
+
async function checkSessionIntegrityAndClean() {
|
|
902
|
+
const isSessionFolderPresent = fs.existsSync(sessionDir);
|
|
903
|
+
const isValidSession = sessionExists();
|
|
904
|
+
|
|
905
|
+
if (isSessionFolderPresent && !isValidSession) {
|
|
906
|
+
log('⚠️ Detected incomplete session files. Cleaning up...', 'red');
|
|
907
|
+
clearSessionFiles();
|
|
908
|
+
await delay(2000);
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
// --- MAIN LOGIN FLOW (JUNE X priority) ---
|
|
913
|
+
async function tylor() {
|
|
914
|
+
try {
|
|
915
|
+
require('./daveset');
|
|
916
|
+
const mainModules = require('./dave');
|
|
917
|
+
handleMessages = mainModules.handleMessages;
|
|
918
|
+
handleGroupParticipantUpdate = mainModules.handleGroupParticipantUpdate;
|
|
919
|
+
handleStatus = mainModules.handleStatus;
|
|
920
|
+
global.initPresenceOnConnect = mainModules.initPresenceOnConnect;
|
|
921
|
+
|
|
922
|
+
const myfuncModule = require('./davelib/myfunc');
|
|
923
|
+
smsg = myfuncModule.smsg;
|
|
924
|
+
|
|
925
|
+
store = require('./davelib/lightweight_store');
|
|
926
|
+
store.readFromFile();
|
|
927
|
+
settings = require('./daveset');
|
|
928
|
+
setInterval(() => store.writeToFile(), settings.storeWriteInterval || 30000);
|
|
929
|
+
|
|
930
|
+
log("Core files loaded.", 'green');
|
|
931
|
+
} catch (e) {
|
|
932
|
+
log(`FATAL: Failed to load core files: ${e.message}`, 'red', true);
|
|
933
|
+
process.exit(1);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
await checkAndHandleSessionFormat();
|
|
937
|
+
global.errorRetryCount = loadErrorCount().count;
|
|
938
|
+
|
|
939
|
+
const envSessionID = process.env.SESSION_ID?.trim();
|
|
940
|
+
|
|
941
|
+
// Priority 1: .env SESSION_ID
|
|
942
|
+
if (envSessionID && envSessionID.startsWith('DAVE-X')) {
|
|
943
|
+
log("📌 Using SESSION_ID from .env", 'magenta');
|
|
944
|
+
global.SESSION_ID = envSessionID;
|
|
945
|
+
|
|
946
|
+
if (!sessionExists()) {
|
|
947
|
+
await downloadSessionData();
|
|
948
|
+
await saveLoginMethod('session');
|
|
949
|
+
}
|
|
950
|
+
|
|
951
|
+
log("🚀 Starting bot...", 'green');
|
|
952
|
+
await delay(2000);
|
|
953
|
+
await startXeonBotInc();
|
|
954
|
+
checkEnvStatus();
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
|
|
958
|
+
log("📌 No SESSION_ID in .env. Checking stored session...", 'yellow');
|
|
959
|
+
|
|
960
|
+
// Priority 2: Stored session
|
|
961
|
+
await checkSessionIntegrityAndClean();
|
|
962
|
+
|
|
963
|
+
if (sessionExists()) {
|
|
964
|
+
log("✅ Valid stored session found, starting bot...", 'green');
|
|
965
|
+
await delay(2000);
|
|
966
|
+
await startXeonBotInc();
|
|
967
|
+
checkEnvStatus();
|
|
968
|
+
return;
|
|
969
|
+
}
|
|
970
|
+
|
|
971
|
+
// Priority 3: Interactive login
|
|
972
|
+
await getLoginMethod();
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
// --- START ---
|
|
976
|
+
tylor().catch(err => {
|
|
977
|
+
log(`Fatal error: ${err.message}`, 'red', true);
|
|
978
|
+
if (err.stack) _origConsoleError(err.stack);
|
|
979
|
+
});
|
|
980
|
+
|
|
981
|
+
process.on('uncaughtException', (err) => {
|
|
982
|
+
if (!err.message?.includes('ECONNRESET') && !err.message?.includes('socket hang up')) {
|
|
983
|
+
log(`Uncaught Exception: ${err.message}`, 'red', true);
|
|
984
|
+
if (err.stack) _origConsoleError(err.stack);
|
|
985
|
+
}
|
|
986
|
+
});
|
|
987
|
+
|
|
988
|
+
process.on('unhandledRejection', (err) => {
|
|
989
|
+
const msg = err?.message || String(err);
|
|
990
|
+
if (!msg.includes('ECONNRESET') && !msg.includes('socket hang up')) {
|
|
991
|
+
log(`Unhandled Rejection: ${msg}`, 'red', true);
|
|
992
|
+
if (err?.stack) _origConsoleError(err.stack);
|
|
993
|
+
}
|
|
994
|
+
});
|