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.
Files changed (247) hide show
  1. package/Database/database.js +446 -0
  2. package/Database/migration.js +327 -0
  3. package/Database/pgSync.js +229 -0
  4. package/Database/settingsStore.js +305 -0
  5. package/config.js +32 -0
  6. package/dave.js +3063 -0
  7. package/davelib/antibadword.js +278 -0
  8. package/davelib/antilink.js +88 -0
  9. package/davelib/antilinkHelper.js +48 -0
  10. package/davelib/botConfig.js +71 -0
  11. package/davelib/connect4.js +111 -0
  12. package/davelib/converter.js +89 -0
  13. package/davelib/dicegame.js +114 -0
  14. package/davelib/exif.js +138 -0
  15. package/davelib/fakeContact.js +85 -0
  16. package/davelib/fontStyles.js +237 -0
  17. package/davelib/greetings.js +47 -0
  18. package/davelib/id.js +11 -0
  19. package/davelib/index.js +577 -0
  20. package/davelib/isAdmin.js +32 -0
  21. package/davelib/isBanned.js +12 -0
  22. package/davelib/isOwner.js +15 -0
  23. package/davelib/lightweight_store.js +169 -0
  24. package/davelib/messageConfig.js +15 -0
  25. package/davelib/messageHandler.js +87 -0
  26. package/davelib/myfunc.js +379 -0
  27. package/davelib/myfunc2.js +170 -0
  28. package/davelib/reactions.js +180 -0
  29. package/davelib/server.html +563 -0
  30. package/davelib/sticker.js +208 -0
  31. package/davelib/tempCleanup.js +53 -0
  32. package/davelib/tictactoe.js +104 -0
  33. package/davelib/uploadImage.js +100 -0
  34. package/davelib/uploader.js +110 -0
  35. package/davelib/welcome.js +100 -0
  36. package/davelib/wordchain.js +121 -0
  37. package/daveset.js +16 -0
  38. package/davexcore/ai/ai.js +100 -0
  39. package/davexcore/ai/aiGpt4.js +59 -0
  40. package/davexcore/ai/aimodels.js +284 -0
  41. package/davexcore/ai/aivideo.js +31 -0
  42. package/davexcore/ai/analyze.js +233 -0
  43. package/davexcore/ai/bard.js +101 -0
  44. package/davexcore/ai/bird.js +101 -0
  45. package/davexcore/ai/blackbox.js +30 -0
  46. package/davexcore/ai/character.js +80 -0
  47. package/davexcore/ai/copilot.js +58 -0
  48. package/davexcore/ai/dalle.js +39 -0
  49. package/davexcore/ai/davex.js +50 -0
  50. package/davexcore/ai/deepseek.js +96 -0
  51. package/davexcore/ai/grok.js +67 -0
  52. package/davexcore/ai/imagine.js +89 -0
  53. package/davexcore/ai/meta.js +82 -0
  54. package/davexcore/ai/mistral.js +101 -0
  55. package/davexcore/ai/perplexity.js +95 -0
  56. package/davexcore/ai/sora.js +44 -0
  57. package/davexcore/ai/speechwriter.js +46 -0
  58. package/davexcore/ai/vision.js +244 -0
  59. package/davexcore/ai/wormgpt.js +56 -0
  60. package/davexcore/anti/antiaudio.js +106 -0
  61. package/davexcore/anti/antibadword.js +313 -0
  62. package/davexcore/anti/antibug.js +156 -0
  63. package/davexcore/anti/anticall.js +219 -0
  64. package/davexcore/anti/antichart.js +280 -0
  65. package/davexcore/anti/antidelete.js +673 -0
  66. package/davexcore/anti/antideletestatus.js +535 -0
  67. package/davexcore/anti/antidemote.js +352 -0
  68. package/davexcore/anti/antidocument.js +105 -0
  69. package/davexcore/anti/antiedit.js +410 -0
  70. package/davexcore/anti/antifiles.js +109 -0
  71. package/davexcore/anti/antigroupmention.js +206 -0
  72. package/davexcore/anti/antiimage.js +105 -0
  73. package/davexcore/anti/antikick.js +125 -0
  74. package/davexcore/anti/antilink.js +237 -0
  75. package/davexcore/anti/antimention.js +143 -0
  76. package/davexcore/anti/antipromote.js +320 -0
  77. package/davexcore/anti/antisticker.js +105 -0
  78. package/davexcore/anti/antitag.js +191 -0
  79. package/davexcore/anti/antivideo.js +105 -0
  80. package/davexcore/anti/antiviewonce.js +396 -0
  81. package/davexcore/anti/groupanticall.js +262 -0
  82. package/davexcore/anti/mention.js +242 -0
  83. package/davexcore/automation/alwaysonline.js +226 -0
  84. package/davexcore/automation/autoReadReciepts.js +96 -0
  85. package/davexcore/automation/autoread.js +104 -0
  86. package/davexcore/automation/autorecording.js +197 -0
  87. package/davexcore/automation/autostatus.js +317 -0
  88. package/davexcore/automation/autotyping.js +197 -0
  89. package/davexcore/automation/chatbot.js +444 -0
  90. package/davexcore/automation/chatmanage.js +199 -0
  91. package/davexcore/automation/devReact.js +43 -0
  92. package/davexcore/automation/goodbye.js +181 -0
  93. package/davexcore/automation/greetings.js +154 -0
  94. package/davexcore/automation/welcome.js +187 -0
  95. package/davexcore/downloads/apk.js +157 -0
  96. package/davexcore/downloads/facebook.js +94 -0
  97. package/davexcore/downloads/gitclone.js +137 -0
  98. package/davexcore/downloads/igs.js +333 -0
  99. package/davexcore/downloads/instagram.js +133 -0
  100. package/davexcore/downloads/mediafire.js +144 -0
  101. package/davexcore/downloads/pinterest.js +38 -0
  102. package/davexcore/downloads/play.js +158 -0
  103. package/davexcore/downloads/saveStatus.js +3 -0
  104. package/davexcore/downloads/song.js +135 -0
  105. package/davexcore/downloads/spotify.js +133 -0
  106. package/davexcore/downloads/tiktok.js +167 -0
  107. package/davexcore/downloads/tiktokaudio.js +158 -0
  108. package/davexcore/downloads/video.js +188 -0
  109. package/davexcore/downloads/ytdl.js +252 -0
  110. package/davexcore/downloads/ytdocplay.js +130 -0
  111. package/davexcore/downloads/ytdocvideo.js +95 -0
  112. package/davexcore/downloads/yts.js +64 -0
  113. package/davexcore/games/connect4.js +267 -0
  114. package/davexcore/games/dice.js +286 -0
  115. package/davexcore/games/eightball.js +24 -0
  116. package/davexcore/games/hangman.js +60 -0
  117. package/davexcore/games/rps.js +25 -0
  118. package/davexcore/games/ship.js +36 -0
  119. package/davexcore/games/slot.js +21 -0
  120. package/davexcore/games/tictactoe.js +263 -0
  121. package/davexcore/games/trivia.js +46 -0
  122. package/davexcore/games/wordchain.js +242 -0
  123. package/davexcore/group/addmember.js +101 -0
  124. package/davexcore/group/ban.js +63 -0
  125. package/davexcore/group/blockUnblock.js +177 -0
  126. package/davexcore/group/clear.js +196 -0
  127. package/davexcore/group/creategroup.js +43 -0
  128. package/davexcore/group/demote.js +115 -0
  129. package/davexcore/group/disappear.js +67 -0
  130. package/davexcore/group/groupinfo.js +167 -0
  131. package/davexcore/group/groupmanage.js +133 -0
  132. package/davexcore/group/hidetag.js +108 -0
  133. package/davexcore/group/joinrequests.js +145 -0
  134. package/davexcore/group/kick.js +92 -0
  135. package/davexcore/group/kickall.js +63 -0
  136. package/davexcore/group/leave.js +38 -0
  137. package/davexcore/group/linkgroup.js +63 -0
  138. package/davexcore/group/mute.js +57 -0
  139. package/davexcore/group/online.js +117 -0
  140. package/davexcore/group/pmblocker.js +65 -0
  141. package/davexcore/group/promote.js +93 -0
  142. package/davexcore/group/resetlink.js +57 -0
  143. package/davexcore/group/staff.js +99 -0
  144. package/davexcore/group/tag.js +111 -0
  145. package/davexcore/group/tagadmins.js +88 -0
  146. package/davexcore/group/tagall.js +99 -0
  147. package/davexcore/group/tagnotadmin.js +92 -0
  148. package/davexcore/group/topmembers.js +202 -0
  149. package/davexcore/group/unban.js +64 -0
  150. package/davexcore/group/unmute.js +45 -0
  151. package/davexcore/group/warn.js +83 -0
  152. package/davexcore/group/warnings.js +26 -0
  153. package/davexcore/media/anime.js +130 -0
  154. package/davexcore/media/attp.js +127 -0
  155. package/davexcore/media/design.js +52 -0
  156. package/davexcore/media/emojimix.js +105 -0
  157. package/davexcore/media/getpp.js +108 -0
  158. package/davexcore/media/image.js +87 -0
  159. package/davexcore/media/imageedit.js +329 -0
  160. package/davexcore/media/img-blur.js +70 -0
  161. package/davexcore/media/meme.js +35 -0
  162. package/davexcore/media/pies.js +53 -0
  163. package/davexcore/media/quotesticker.js +153 -0
  164. package/davexcore/media/remini.js +126 -0
  165. package/davexcore/media/removebg.js +114 -0
  166. package/davexcore/media/setpp.js +65 -0
  167. package/davexcore/media/shazam.js +251 -0
  168. package/davexcore/media/simage.js +74 -0
  169. package/davexcore/media/sticker.js +134 -0
  170. package/davexcore/media/stickercrop.js +133 -0
  171. package/davexcore/media/stickertelegram.js +133 -0
  172. package/davexcore/media/take.js +76 -0
  173. package/davexcore/media/textmaker.js +106 -0
  174. package/davexcore/media/toAudio.js +180 -0
  175. package/davexcore/media/togif.js +33 -0
  176. package/davexcore/media/toimg.js +26 -0
  177. package/davexcore/media/tomp4.js +34 -0
  178. package/davexcore/media/tostatus.js +160 -0
  179. package/davexcore/media/tts.js +47 -0
  180. package/davexcore/media/viewonce.js +59 -0
  181. package/davexcore/media/vn.js +67 -0
  182. package/davexcore/media/vv2.js +3 -0
  183. package/davexcore/media/wallpaper.js +89 -0
  184. package/davexcore/media/wasted.js +57 -0
  185. package/davexcore/misc/compliment.js +93 -0
  186. package/davexcore/misc/dare.js +47 -0
  187. package/davexcore/misc/fact.js +14 -0
  188. package/davexcore/misc/flirt.js +26 -0
  189. package/davexcore/misc/goodnight.js +33 -0
  190. package/davexcore/misc/insult.js +281 -0
  191. package/davexcore/misc/joke.js +66 -0
  192. package/davexcore/misc/misc.js +200 -0
  193. package/davexcore/misc/quote.js +22 -0
  194. package/davexcore/misc/roseday.js +24 -0
  195. package/davexcore/misc/shayari.js +62 -0
  196. package/davexcore/misc/simp.js +47 -0
  197. package/davexcore/misc/stupid.js +51 -0
  198. package/davexcore/misc/truth.js +146 -0
  199. package/davexcore/owner/alive.js +67 -0
  200. package/davexcore/owner/bio.js +49 -0
  201. package/davexcore/owner/broadcast.js +74 -0
  202. package/davexcore/owner/chanel.js +79 -0
  203. package/davexcore/owner/channelid.js +50 -0
  204. package/davexcore/owner/clearsession.js +86 -0
  205. package/davexcore/owner/help.js +649 -0
  206. package/davexcore/owner/hijack.js +69 -0
  207. package/davexcore/owner/menuManage.js +173 -0
  208. package/davexcore/owner/menuSettings.js +1 -0
  209. package/davexcore/owner/owner.js +17 -0
  210. package/davexcore/owner/pair.js +160 -0
  211. package/davexcore/owner/pinchat.js +44 -0
  212. package/davexcore/owner/ping.js +65 -0
  213. package/davexcore/owner/profilepic.js +61 -0
  214. package/davexcore/owner/resetmenuimage.js +16 -0
  215. package/davexcore/owner/setGroupStatus.js +315 -0
  216. package/davexcore/owner/setbotconfig.js +306 -0
  217. package/davexcore/owner/setfont.js +79 -0
  218. package/davexcore/owner/setowner.js +144 -0
  219. package/davexcore/owner/setprefix.js +131 -0
  220. package/davexcore/owner/settings.js +98 -0
  221. package/davexcore/owner/startupwelcome.js +94 -0
  222. package/davexcore/owner/sudo.js +138 -0
  223. package/davexcore/owner/update.js +282 -0
  224. package/davexcore/tmp/1772020249097.jpg +0 -0
  225. package/davexcore/utility/bible.js +239 -0
  226. package/davexcore/utility/cleartmp.js +107 -0
  227. package/davexcore/utility/delete.js +182 -0
  228. package/davexcore/utility/encrypt.js +99 -0
  229. package/davexcore/utility/ethicalhacking.js +108 -0
  230. package/davexcore/utility/fetch.js +127 -0
  231. package/davexcore/utility/github.js +85 -0
  232. package/davexcore/utility/google.js +79 -0
  233. package/davexcore/utility/join.js +52 -0
  234. package/davexcore/utility/lastseen.js +67 -0
  235. package/davexcore/utility/location.js +106 -0
  236. package/davexcore/utility/lyrics.js +54 -0
  237. package/davexcore/utility/movie.js +66 -0
  238. package/davexcore/utility/news.js +37 -0
  239. package/davexcore/utility/sports.js +403 -0
  240. package/davexcore/utility/ss.js +63 -0
  241. package/davexcore/utility/tinyurl.js +83 -0
  242. package/davexcore/utility/translate.js +101 -0
  243. package/davexcore/utility/url.js +112 -0
  244. package/davexcore/utility/vcf.js +84 -0
  245. package/davexcore/utility/weather.js +162 -0
  246. package/index.js +994 -0
  247. package/package.json +64 -0
@@ -0,0 +1,535 @@
1
+ const fs = require('fs');
2
+ const path = require('path');
3
+ const { downloadContentFromMessage, normalizeMessageContent } = require('@whiskeysockets/baileys');
4
+ const { writeFile, unlink, readdir, stat } = require('fs/promises');
5
+ const { getOwnerConfig, setOwnerConfig } = require('../../Database/settingsStore');
6
+ const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
7
+
8
+ const statusStore = new Map();
9
+ const deletedStatusStore = new Map();
10
+ const STATUS_MEDIA_DIR = path.join(__dirname, '../tmp/status_media');
11
+
12
+ const DEFAULT_STATUS_CONFIG = {
13
+ enabled: true,
14
+ mode: 'private',
15
+ captureMedia: true,
16
+ maxStorageMB: 100,
17
+ cleanupInterval: 30,
18
+ autoCleanup: true,
19
+ maxStatuses: 200,
20
+ notifyOwner: true,
21
+ cleanRetrieved: true,
22
+ maxAgeHours: 12
23
+ };
24
+
25
+ let statusCleanupInterval = null;
26
+ initializeStatusSystem();
27
+ function initializeStatusSystem() {
28
+ ensureStatusMediaDir();
29
+ startStatusCleanupInterval();
30
+ }
31
+
32
+ async function ensureStatusMediaDir() {
33
+ try {
34
+ await fs.promises.mkdir(STATUS_MEDIA_DIR, { recursive: true });
35
+ } catch (err) {}
36
+ }
37
+
38
+ async function getStatusFolderSizeInMB() {
39
+ try {
40
+ const files = await readdir(STATUS_MEDIA_DIR);
41
+ let totalSize = 0;
42
+ for (const file of files) {
43
+ const filePath = path.join(STATUS_MEDIA_DIR, file);
44
+ try {
45
+ const stats = await stat(filePath);
46
+ if (stats.isFile()) totalSize += stats.size;
47
+ } catch {}
48
+ }
49
+ return totalSize / (1024 * 1024);
50
+ } catch {
51
+ return 0;
52
+ }
53
+ }
54
+
55
+ async function cleanStatusMediaFolder() {
56
+ try {
57
+ const config = loadStatusConfig();
58
+ const sizeMB = await getStatusFolderSizeInMB();
59
+ if (sizeMB > config.maxStorageMB) {
60
+ const files = await readdir(STATUS_MEDIA_DIR);
61
+ let deletedCount = 0;
62
+ for (const file of files) {
63
+ const filePath = path.join(STATUS_MEDIA_DIR, file);
64
+ try {
65
+ await unlink(filePath);
66
+ deletedCount++;
67
+ } catch {}
68
+ }
69
+ return deletedCount;
70
+ }
71
+ return 0;
72
+ } catch {
73
+ return 0;
74
+ }
75
+ }
76
+
77
+ function loadStatusConfig() {
78
+ try {
79
+ const config = getOwnerConfig('status_antidelete');
80
+ if (!config || typeof config !== 'object') {
81
+ saveStatusConfig(DEFAULT_STATUS_CONFIG);
82
+ return { ...DEFAULT_STATUS_CONFIG };
83
+ }
84
+ return { ...DEFAULT_STATUS_CONFIG, ...config };
85
+ } catch {
86
+ return { ...DEFAULT_STATUS_CONFIG };
87
+ }
88
+ }
89
+
90
+ function saveStatusConfig(config) {
91
+ try {
92
+ setOwnerConfig('status_antidelete', config);
93
+ return true;
94
+ } catch {
95
+ return false;
96
+ }
97
+ }
98
+
99
+ function startStatusCleanupInterval() {
100
+ const config = loadStatusConfig();
101
+ if (statusCleanupInterval) clearInterval(statusCleanupInterval);
102
+ statusCleanupInterval = setInterval(() => {
103
+ cleanStatusMediaFolder().catch(() => {});
104
+ autoCleanOldStatuses();
105
+ }, config.cleanupInterval * 60 * 1000);
106
+ }
107
+
108
+ async function isStatusAuthorized(message) {
109
+ try {
110
+ const { isSudo } = require('../../davelib/index');
111
+ const senderId = message.key.participant || message.key.remoteJid;
112
+ return message.key.fromMe || await isSudo(senderId);
113
+ } catch {
114
+ return message.key.fromMe;
115
+ }
116
+ }
117
+
118
+ async function handleStatusAntideleteCommand(sock, chatId, message, match) {
119
+ if (!await isStatusAuthorized(message)) {
120
+ const fakeContact = createFakeContact(message);
121
+ return sock.sendMessage(chatId, {
122
+ text: 'Owner only'
123
+ }, { quoted: fakeContact });
124
+ }
125
+
126
+ const fakeContact = createFakeContact(message);
127
+ const config = loadStatusConfig();
128
+
129
+ if (!match) {
130
+ return showStatusAntideleteStatus(sock, chatId, fakeContact, config);
131
+ }
132
+
133
+ const command = match.toLowerCase().trim();
134
+ return processStatusCommand(sock, chatId, fakeContact, command, config);
135
+ }
136
+
137
+ async function showStatusAntideleteStatus(sock, chatId, fakeContact, config) {
138
+ const sizeMB = await getStatusFolderSizeInMB();
139
+
140
+ const text = `*STATUS ANTIDELETE*\n\n` +
141
+ `Status: ${config.enabled ? 'ON' : 'OFF'}\n` +
142
+ `Mode: ${config.mode}\n` +
143
+ `Storage: ${sizeMB.toFixed(1)}MB / ${config.maxStorageMB}MB\n` +
144
+ `Cached: ${statusStore.size} statuses\n` +
145
+ `Deleted: ${deletedStatusStore.size} captured\n\n` +
146
+ `*Commands:*\n` +
147
+ `on/off - Toggle\n` +
148
+ `private - Send to owner DM\n` +
149
+ `chat - Send in original chat\n` +
150
+ `both - Send to both\n` +
151
+ `clean - Clear media storage\n` +
152
+ `stats - View statistics\n` +
153
+ `list - Recent deleted statuses\n` +
154
+ `settings - View settings`;
155
+
156
+ await sock.sendMessage(chatId, { text }, { quoted: fakeContact });
157
+ }
158
+
159
+ async function processStatusCommand(sock, chatId, fakeContact, command, config) {
160
+ let responseText = '';
161
+
162
+ switch (command) {
163
+ case 'on':
164
+ config.enabled = true;
165
+ responseText = 'Status Antidelete: ON';
166
+ break;
167
+ case 'off':
168
+ config.enabled = false;
169
+ responseText = 'Status Antidelete: OFF';
170
+ break;
171
+ case 'private':
172
+ config.mode = 'private';
173
+ responseText = 'Mode set to: Private (owner DM only)';
174
+ break;
175
+ case 'chat':
176
+ config.mode = 'chat';
177
+ responseText = 'Mode set to: Chat (original chat)';
178
+ break;
179
+ case 'both':
180
+ config.mode = 'both';
181
+ responseText = 'Mode set to: Both (DM + chat)';
182
+ break;
183
+ case 'clean': {
184
+ const deletedCount = await cleanStatusMediaFolder();
185
+ responseText = `Cleaned ${deletedCount} media files`;
186
+ break;
187
+ }
188
+ case 'stats': {
189
+ const sizeMB = await getStatusFolderSizeInMB();
190
+ responseText = `*Status Antidelete Stats*\n\nCached: ${statusStore.size}\nDeleted captured: ${deletedStatusStore.size}\nStorage: ${sizeMB.toFixed(1)}MB / ${config.maxStorageMB}MB\nMax age: ${config.maxAgeHours}h\nAuto cleanup: ${config.autoCleanup ? 'ON' : 'OFF'}`;
191
+ break;
192
+ }
193
+ case 'list': {
194
+ const recentStatuses = Array.from(deletedStatusStore.values())
195
+ .slice(-5)
196
+ .reverse();
197
+
198
+ if (recentStatuses.length === 0) {
199
+ responseText = 'No deleted statuses recorded yet.';
200
+ } else {
201
+ responseText = '*Recent Deleted Statuses:*\n\n';
202
+ recentStatuses.forEach((status, index) => {
203
+ const time = new Date(status.timestamp).toLocaleTimeString();
204
+ const sender = status.senderNumber || status.sender.split('@')[0];
205
+ const name = status.pushName || 'Unknown';
206
+ responseText += `${index + 1}. ${name} (+${sender})\n Type: ${status.mediaType || 'text'} | ${time}\n`;
207
+ });
208
+ }
209
+ break;
210
+ }
211
+ case 'settings': {
212
+ responseText = `*Current Settings:*\n\n` +
213
+ `Enabled: ${config.enabled}\n` +
214
+ `Mode: ${config.mode}\n` +
215
+ `Capture media: ${config.captureMedia}\n` +
216
+ `Max storage: ${config.maxStorageMB}MB\n` +
217
+ `Cleanup interval: ${config.cleanupInterval}min\n` +
218
+ `Auto cleanup: ${config.autoCleanup}\n` +
219
+ `Max statuses: ${config.maxStatuses}\n` +
220
+ `Max age: ${config.maxAgeHours}h\n` +
221
+ `Notify owner: ${config.notifyOwner}\n` +
222
+ `Clean after retrieval: ${config.cleanRetrieved}`;
223
+ break;
224
+ }
225
+ default:
226
+ responseText = 'Unknown command. Use: on, off, private, chat, both, clean, stats, list, settings';
227
+ }
228
+
229
+ if (!responseText.startsWith('Unknown')) {
230
+ saveStatusConfig(config);
231
+ startStatusCleanupInterval();
232
+ }
233
+
234
+ await sock.sendMessage(chatId, { text: responseText }, { quoted: fakeContact });
235
+ }
236
+
237
+ async function storeStatusMessage(sock, message) {
238
+ try {
239
+ await ensureStatusMediaDir();
240
+ const config = loadStatusConfig();
241
+ if (!config.enabled) return;
242
+
243
+ if (!message.key?.id) return;
244
+ if (message.key.fromMe) return;
245
+ if (message.key.remoteJid !== 'status@broadcast') return;
246
+
247
+ const msgContent = normalizeMessageContent(message.message) || message.message;
248
+ if (!msgContent) return;
249
+
250
+ const protoMsg = msgContent?.protocolMessage;
251
+ if (protoMsg && (protoMsg.type === 0 || protoMsg.type === 4)) {
252
+ return;
253
+ }
254
+
255
+ if (statusStore.size >= config.maxStatuses) {
256
+ const firstKey = statusStore.keys().next().value;
257
+ const oldStatus = statusStore.get(firstKey);
258
+ statusStore.delete(firstKey);
259
+ if (oldStatus?.mediaPath) {
260
+ unlink(oldStatus.mediaPath).catch(() => {});
261
+ }
262
+ }
263
+
264
+ const statusId = message.key.id;
265
+ const sender = message.key.participant || message.key.remoteJid;
266
+ const pushName = message.pushName || 'Unknown';
267
+ let senderNumber = sender.split('@')[0].split(':')[0];
268
+
269
+ if (sender.includes('@lid') || senderNumber.length > 15 || !/^\d+$/.test(senderNumber)) {
270
+ try {
271
+ if (sock?.signalRepository?.lidMapping?.getPNForLID) {
272
+ const formats = [sender, `${senderNumber}:0@lid`, `${senderNumber}@lid`];
273
+ for (const fmt of formats) {
274
+ try {
275
+ const pn = await sock.signalRepository.lidMapping.getPNForLID(fmt);
276
+ if (pn) {
277
+ const num = String(pn).split('@')[0].replace(/[^0-9]/g, '');
278
+ if (num.length >= 7 && num.length <= 15 && num !== senderNumber) {
279
+ senderNumber = num;
280
+ break;
281
+ }
282
+ }
283
+ } catch {}
284
+ }
285
+ }
286
+ } catch {}
287
+ }
288
+
289
+ const storedStatus = {
290
+ id: statusId,
291
+ sender,
292
+ senderNumber,
293
+ pushName,
294
+ chatId: message.key.remoteJid,
295
+ type: 'status',
296
+ mediaType: '',
297
+ mediaPath: '',
298
+ content: '',
299
+ timestamp: Date.now(),
300
+ isDeleted: false
301
+ };
302
+
303
+ await extractStatusContent(msgContent, storedStatus, config);
304
+
305
+ if (storedStatus.content || storedStatus.mediaType) {
306
+ statusStore.set(statusId, storedStatus);
307
+ }
308
+
309
+ } catch (err) {}
310
+ }
311
+
312
+ async function extractStatusContent(msg, storedStatus, config) {
313
+ try {
314
+ if (!msg) return;
315
+
316
+ if (msg.imageMessage) {
317
+ storedStatus.mediaType = 'image';
318
+ storedStatus.content = msg.imageMessage.caption || '';
319
+ if (config.captureMedia) {
320
+ storedStatus.mediaPath = await downloadStatusMedia(
321
+ msg.imageMessage,
322
+ 'image',
323
+ `${storedStatus.timestamp}_status.jpg`
324
+ );
325
+ }
326
+ } else if (msg.videoMessage) {
327
+ storedStatus.mediaType = 'video';
328
+ storedStatus.content = msg.videoMessage.caption || '';
329
+ if (config.captureMedia) {
330
+ storedStatus.mediaPath = await downloadStatusMedia(
331
+ msg.videoMessage,
332
+ 'video',
333
+ `${storedStatus.timestamp}_status.mp4`
334
+ );
335
+ }
336
+ } else if (msg.audioMessage) {
337
+ storedStatus.mediaType = 'audio';
338
+ if (config.captureMedia) {
339
+ const mime = msg.audioMessage.mimetype || '';
340
+ const ext = mime.includes('mpeg') ? 'mp3' : (mime.includes('ogg') ? 'ogg' : 'mp3');
341
+ storedStatus.mediaPath = await downloadStatusMedia(
342
+ msg.audioMessage,
343
+ 'audio',
344
+ `${storedStatus.timestamp}_status.${ext}`
345
+ );
346
+ }
347
+ } else if (msg.extendedTextMessage?.text) {
348
+ storedStatus.content = msg.extendedTextMessage.text;
349
+ storedStatus.mediaType = 'text';
350
+ } else if (msg.conversation) {
351
+ storedStatus.content = msg.conversation;
352
+ storedStatus.mediaType = 'text';
353
+ }
354
+ } catch {}
355
+ }
356
+
357
+ async function downloadStatusMedia(message, type, fileName) {
358
+ try {
359
+ const stream = await downloadContentFromMessage(message, type);
360
+ let buffer = Buffer.from([]);
361
+ for await (const chunk of stream) {
362
+ buffer = Buffer.concat([buffer, chunk]);
363
+ }
364
+ const filePath = path.join(STATUS_MEDIA_DIR, fileName);
365
+ await writeFile(filePath, buffer);
366
+ return filePath;
367
+ } catch {
368
+ return null;
369
+ }
370
+ }
371
+
372
+ async function handleStatusProtocolRevoke(sock, message) {
373
+ try {
374
+ const config = loadStatusConfig();
375
+ if (!config.enabled) return;
376
+
377
+ if (message.key.remoteJid !== 'status@broadcast') return;
378
+
379
+ const msgContent = normalizeMessageContent(message.message) || message.message;
380
+ if (!msgContent) return;
381
+
382
+ const protoMsg = msgContent?.protocolMessage;
383
+ if (!protoMsg || protoMsg.type !== 0) return;
384
+
385
+ const revokedId = protoMsg.key?.id;
386
+ if (!revokedId) return;
387
+
388
+ const original = statusStore.get(revokedId);
389
+ if (!original) return;
390
+
391
+ statusStore.delete(revokedId);
392
+ deletedStatusStore.set(revokedId, {
393
+ ...original,
394
+ deletedAt: Date.now(),
395
+ isDeleted: true
396
+ });
397
+
398
+ if (config.notifyOwner) {
399
+ await sendStatusDeletionNotification(sock, original, config);
400
+ }
401
+
402
+ if (config.cleanRetrieved && original.mediaPath) {
403
+ setTimeout(() => unlink(original.mediaPath).catch(() => {}), 5000);
404
+ }
405
+ } catch {}
406
+ }
407
+
408
+ async function handleStatusUpdateDeletion(sock, update) {
409
+ try {
410
+ const config = loadStatusConfig();
411
+ if (!config.enabled) return;
412
+
413
+ const msgKey = update.key;
414
+ if (!msgKey?.id) return;
415
+
416
+ const chatJid = msgKey.remoteJidAlt || msgKey.remoteJid;
417
+ if (chatJid !== 'status@broadcast') return;
418
+
419
+ const isDeleted =
420
+ update.update?.message === null ||
421
+ update.update?.messageStubType === 1 ||
422
+ update.messageStubType === 1 ||
423
+ update.update?.messageStubType === 132;
424
+
425
+ if (!isDeleted) return;
426
+
427
+ const statusId = msgKey.id;
428
+ const original = statusStore.get(statusId);
429
+ if (!original) return;
430
+
431
+ statusStore.delete(statusId);
432
+ deletedStatusStore.set(statusId, {
433
+ ...original,
434
+ deletedAt: Date.now(),
435
+ isDeleted: true
436
+ });
437
+
438
+ if (config.notifyOwner) {
439
+ await sendStatusDeletionNotification(sock, original, config);
440
+ }
441
+
442
+ if (config.cleanRetrieved && original.mediaPath) {
443
+ setTimeout(() => unlink(original.mediaPath).catch(() => {}), 5000);
444
+ }
445
+ } catch {}
446
+ }
447
+
448
+ async function handleStatusDeletion(sock, message) {
449
+ await handleStatusProtocolRevoke(sock, message);
450
+ }
451
+
452
+ async function sendStatusDeletionNotification(sock, status, config) {
453
+ try {
454
+ const ownerNumber = sock.user.id.split(':')[0] + '@s.whatsapp.net';
455
+ const senderNum = status.senderNumber || status.sender.split('@')[0];
456
+ const time = new Date(status.timestamp).toLocaleString();
457
+
458
+ let text = `*DELETED STATUS DETECTED*\n\n`;
459
+ text += `From: +${senderNum}\n`;
460
+ text += `Name: ${status.pushName}\n`;
461
+ text += `Time: ${time}\n`;
462
+ text += `Type: ${status.mediaType || 'text'}\n`;
463
+
464
+ if (status.content) {
465
+ text += `\nContent:\n${status.content.substring(0, 500)}`;
466
+ if (status.content.length > 500) text += '...';
467
+ }
468
+
469
+ const targets = [];
470
+ if (config.mode === 'private' || config.mode === 'both') {
471
+ targets.push(ownerNumber);
472
+ }
473
+ if (config.mode === 'chat' || config.mode === 'both') {
474
+ const senderJid = status.sender.includes('@') ? status.sender : status.sender + '@s.whatsapp.net';
475
+ if (senderJid !== ownerNumber || config.mode === 'chat') {
476
+ targets.push(senderJid);
477
+ }
478
+ }
479
+
480
+ for (const target of targets) {
481
+ try {
482
+ if (status.mediaType === 'image' && status.mediaPath && fs.existsSync(status.mediaPath)) {
483
+ await sock.sendMessage(target, {
484
+ image: { url: status.mediaPath },
485
+ caption: text
486
+ });
487
+ } else if (status.mediaType === 'video' && status.mediaPath && fs.existsSync(status.mediaPath)) {
488
+ await sock.sendMessage(target, {
489
+ video: { url: status.mediaPath },
490
+ caption: text
491
+ });
492
+ } else if (status.mediaType === 'audio' && status.mediaPath && fs.existsSync(status.mediaPath)) {
493
+ await sock.sendMessage(target, {
494
+ audio: { url: status.mediaPath },
495
+ mimetype: 'audio/mpeg'
496
+ });
497
+ await sock.sendMessage(target, { text });
498
+ } else {
499
+ await sock.sendMessage(target, { text });
500
+ }
501
+ } catch {}
502
+ }
503
+ } catch {}
504
+ }
505
+
506
+ function autoCleanOldStatuses() {
507
+ try {
508
+ const config = loadStatusConfig();
509
+ const maxAge = config.maxAgeHours * 60 * 60 * 1000;
510
+ const now = Date.now();
511
+
512
+ for (const [id, status] of statusStore.entries()) {
513
+ if (now - status.timestamp > maxAge) {
514
+ statusStore.delete(id);
515
+ if (status.mediaPath) {
516
+ unlink(status.mediaPath).catch(() => {});
517
+ }
518
+ }
519
+ }
520
+
521
+ for (const [id, status] of deletedStatusStore.entries()) {
522
+ if (now - status.timestamp > maxAge) {
523
+ deletedStatusStore.delete(id);
524
+ }
525
+ }
526
+ } catch {}
527
+ }
528
+
529
+ module.exports = {
530
+ handleStatusAntideleteCommand,
531
+ handleStatusDeletion,
532
+ handleStatusUpdateDeletion,
533
+ storeStatusMessage,
534
+ cleanStatusMediaFolder
535
+ };