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,251 @@
1
+ const { downloadContentFromMessage } = require('@whiskeysockets/baileys');
2
+ const fs = require('fs');
3
+ const path = require('path');
4
+ const axios = require('axios');
5
+ const { UploadFileUgu } = require('../../davelib/uploader');
6
+ const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
7
+
8
+ const DEBUG = true;
9
+ function debugLog(message, data = null) {
10
+ if (DEBUG) {
11
+ console.log(`[SHAZAM] ${message}`, data ? JSON.stringify(data, null, 2) : '');
12
+ }
13
+ }
14
+
15
+ async function getMediaBuffer(message, type) {
16
+ try {
17
+ debugLog(`Checking for ${type} media...`);
18
+ const m = message.message || {};
19
+ let messageType, fileExt, downloadType;
20
+
21
+ switch (type) {
22
+ case 'audio':
23
+ if (m.audioMessage) {
24
+ messageType = m.audioMessage;
25
+ fileExt = '.mp3';
26
+ downloadType = 'audio';
27
+ debugLog('Found audio message');
28
+ }
29
+ break;
30
+ case 'video':
31
+ if (m.videoMessage) {
32
+ messageType = m.videoMessage;
33
+ fileExt = '.mp4';
34
+ downloadType = 'video';
35
+ debugLog('Found video message');
36
+ }
37
+ break;
38
+ case 'image':
39
+ if (m.imageMessage) {
40
+ messageType = m.imageMessage;
41
+ fileExt = '.jpg';
42
+ downloadType = 'image';
43
+ debugLog('Found image message');
44
+ }
45
+ break;
46
+ }
47
+
48
+ if (messageType) {
49
+ debugLog(`Downloading ${type} content...`);
50
+ const stream = await downloadContentFromMessage(messageType, downloadType);
51
+ const chunks = [];
52
+ for await (const chunk of stream) {
53
+ chunks.push(chunk);
54
+ }
55
+ const buffer = Buffer.concat(chunks);
56
+ debugLog(`Downloaded ${type} buffer size:`, { size: buffer.length, type });
57
+ return { buffer, ext: fileExt, type };
58
+ }
59
+
60
+ debugLog(`No ${type} message found`);
61
+ return null;
62
+ } catch (error) {
63
+ console.error(`[SHAZAM] Error getting ${type} buffer:`, error.message);
64
+ return null;
65
+ }
66
+ }
67
+
68
+ async function getQuotedMediaBuffer(message, type) {
69
+ try {
70
+ debugLog(`Checking quoted message for ${type}...`);
71
+ const quoted = message.message?.extendedTextMessage?.contextInfo?.quotedMessage || null;
72
+ if (!quoted) {
73
+ debugLog('No quoted message found');
74
+ return null;
75
+ }
76
+ debugLog('Found quoted message, checking for media...');
77
+ return await getMediaBuffer({ message: quoted }, type);
78
+ } catch (error) {
79
+ console.error(`[SHAZAM] Error getting quoted ${type} buffer:`, error.message);
80
+ return null;
81
+ }
82
+ }
83
+
84
+ async function getAllMediaBuffers(message) {
85
+ debugLog('Scanning for all media types...');
86
+ const mediaTypes = ['audio', 'video', 'image'];
87
+
88
+ // Check current message
89
+ for (const type of mediaTypes) {
90
+ const media = await getMediaBuffer(message, type);
91
+ if (media) {
92
+ debugLog(`Found media in current message:`, { type: media.type, size: media.buffer.length });
93
+ return media;
94
+ }
95
+ }
96
+
97
+ debugLog('No media found in current message, checking quoted...');
98
+
99
+ // Check quoted message
100
+ for (const type of mediaTypes) {
101
+ const media = await getQuotedMediaBuffer(message, type);
102
+ if (media) {
103
+ debugLog(`Found media in quoted message:`, { type: media.type, size: media.buffer.length });
104
+ return media;
105
+ }
106
+ }
107
+
108
+ debugLog('No media found in current or quoted message');
109
+ return null;
110
+ }
111
+
112
+ async function shazamCommand(sock, chatId, message) {
113
+ let tempPath = null;
114
+
115
+ try {
116
+ debugLog('Shazam command started', { chatId, messageId: message.key.id });
117
+
118
+ const fakeContact = createFakeContact(message);
119
+ const botName = getBotName();
120
+
121
+ const media = await getAllMediaBuffers(message);
122
+
123
+ if (!media) {
124
+ debugLog('No media found - sending instructions');
125
+ await sock.sendMessage(chatId, {
126
+ text: `✦ *SHAZAM*
127
+
128
+ Send or reply to:
129
+ • Audio / Voice note
130
+ • Video with audio
131
+ • Image
132
+
133
+ To identify the song`
134
+ }, { quoted: fakeContact });
135
+ return;
136
+ }
137
+
138
+ debugLog('Media found, creating temp file...', { type: media.type, size: media.buffer.length });
139
+
140
+ const tempDir = path.join(__dirname, '../temp');
141
+ if (!fs.existsSync(tempDir)) {
142
+ debugLog('Creating temp directory...');
143
+ fs.mkdirSync(tempDir, { recursive: true });
144
+ }
145
+
146
+ tempPath = path.join(tempDir, `${Date.now()}_${media.type}${media.ext}`);
147
+ fs.writeFileSync(tempPath, media.buffer);
148
+ debugLog('Temp file created:', { path: tempPath, size: media.buffer.length });
149
+
150
+ let mediaUrl = '';
151
+ try {
152
+ debugLog('Uploading to Uguu...');
153
+ const res = await UploadFileUgu(tempPath);
154
+ debugLog('Uguu upload response:', res);
155
+
156
+ // Robust parsing of Uguu response
157
+ if (typeof res === 'string') {
158
+ mediaUrl = res;
159
+ } else if (res.url) {
160
+ mediaUrl = res.url;
161
+ } else if (res.url_full) {
162
+ mediaUrl = res.url_full;
163
+ } else if (res.data?.url) {
164
+ mediaUrl = res.data.url;
165
+ } else if (res.data?.url_full) {
166
+ mediaUrl = res.data.url_full;
167
+ }
168
+
169
+ if (!mediaUrl) {
170
+ debugLog('Uguu response structure unexpected:', res);
171
+ }
172
+ } catch (uploadError) {
173
+ console.error('[SHAZAM] Upload error:', uploadError);
174
+ throw new Error(`Upload failed: ${uploadError.message}`);
175
+ }
176
+
177
+ if (!mediaUrl) {
178
+ debugLog('No media URL obtained from upload');
179
+ await sock.sendMessage(chatId, { text: `✦ Failed to upload media` }, { quoted: fakeContact });
180
+ return;
181
+ }
182
+
183
+ debugLog('Media uploaded successfully, URL:', mediaUrl);
184
+
185
+ let resultText = '';
186
+ try {
187
+ debugLog('Calling Shazam API...', { url: mediaUrl });
188
+ const response = await axios.get(`https://apiskeith.vercel.app/ai/shazam`, {
189
+ params: { url: mediaUrl },
190
+ timeout: 30000
191
+ });
192
+
193
+ debugLog('Shazam API response:', { status: response.status, data: response.data });
194
+
195
+ const song = response.data?.result || response.data;
196
+
197
+ if (song && (song.title || song.artists)) {
198
+ resultText = `✦ *SONG IDENTIFIED*
199
+
200
+ Title: ${song.title || 'Unknown'}
201
+ Artist: ${song.artists || 'Unknown'}
202
+ Album: ${song.album || 'N/A'}
203
+ Release: ${song.release_date || 'N/A'}
204
+
205
+ Source: ${media.type}`;
206
+ debugLog('Song identified successfully');
207
+ } else {
208
+ resultText = `✦ Could not identify song from this ${media.type}`;
209
+ debugLog('No song identified from Shazam API');
210
+ }
211
+ } catch (apiError) {
212
+ console.error('[SHAZAM] API error:', apiError.message);
213
+ debugLog('Shazam API error details:', {
214
+ code: apiError.code,
215
+ response: apiError.response?.data,
216
+ status: apiError.response?.status
217
+ });
218
+
219
+ if (apiError.code === 'ECONNREFUSED') {
220
+ resultText = `✦ Service unavailable, try again later`;
221
+ } else if (apiError.response?.status === 404) {
222
+ resultText = `✦ Song not found, try clearer audio`;
223
+ } else {
224
+ resultText = `✦ Recognition failed for this ${media.type}`;
225
+ }
226
+ }
227
+
228
+ debugLog('Sending result to user...');
229
+ await sock.sendMessage(chatId, { text: resultText }, { quoted: fakeContact });
230
+
231
+ } catch (error) {
232
+ console.error('[SHAZAM] General error:', error.message);
233
+ debugLog('General error details:', { stack: error.stack });
234
+
235
+ const fakeContact = createFakeContact(message);
236
+ await sock.sendMessage(chatId, {
237
+ text: `✦ Failed: ${error.message}`
238
+ }, { quoted: fakeContact });
239
+ } finally {
240
+ if (tempPath && fs.existsSync(tempPath)) {
241
+ try {
242
+ fs.unlinkSync(tempPath);
243
+ debugLog('Temp file cleaned up');
244
+ } catch (cleanupError) {
245
+ console.error('[SHAZAM] Cleanup error:', cleanupError.message);
246
+ }
247
+ }
248
+ }
249
+ }
250
+
251
+ module.exports = shazamCommand;
@@ -0,0 +1,74 @@
1
+ const fs = require('fs');
2
+ const fsPromises = require('fs/promises');
3
+ const fse = require('fs-extra');
4
+ const path = require('path');
5
+ const webp = require('webp-converter');
6
+ const { downloadContentFromMessage } = require('@whiskeysockets/baileys');
7
+ const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
8
+
9
+ const tempDir = './temp';
10
+ if (!fs.existsSync(tempDir)) fs.mkdirSync(tempDir);
11
+
12
+ /**
13
+ * Schedule deletion of a file after a delay
14
+ * @param {string} filePath - Path of the file to delete
15
+ * @param {number} delay - Delay in ms before deletion
16
+ */
17
+ const scheduleFileDeletion = (filePath, delay = 10000) => {
18
+ setTimeout(async () => {
19
+ try {
20
+ await fse.remove(filePath);
21
+ console.log(`✅ Deleted: ${filePath}`);
22
+ } catch (error) {
23
+ console.error(`❌ Failed to delete ${filePath}:`, error);
24
+ }
25
+ }, delay);
26
+ };
27
+
28
+ /**
29
+ * Convert a WhatsApp sticker (WEBP) to PNG and send it back
30
+ * @param {object} sock - Baileys socket instance
31
+ * @param {object} quotedMessage - Quoted message containing sticker
32
+ * @param {string} chatId - Chat ID to send the converted image
33
+ */
34
+ const convertStickerToImage = async (sock, quotedMessage, chatId) => {
35
+ try {
36
+ const stickerMessage = quotedMessage?.stickerMessage;
37
+ if (!stickerMessage) {
38
+ await sock.sendMessage(chatId, { text: '⚠️ Reply to a sticker with .simage to convert it.' });
39
+ return;
40
+ }
41
+
42
+ const timestamp = Date.now();
43
+ const stickerFilePath = path.join(tempDir, `sticker_${timestamp}.webp`);
44
+ const outputImagePath = path.join(tempDir, `converted_${timestamp}.png`);
45
+
46
+ // Download sticker
47
+ const stream = await downloadContentFromMessage(stickerMessage, 'sticker');
48
+ let buffer = Buffer.alloc(0);
49
+ for await (const chunk of stream) buffer = Buffer.concat([buffer, chunk]);
50
+
51
+ await fsPromises.writeFile(stickerFilePath, buffer);
52
+
53
+ // Convert WEBP → PNG
54
+ const result = await webp.dwebp(stickerFilePath, outputImagePath, "-o");
55
+ console.log("WEBP → PNG conversion result:", result);
56
+
57
+ // Read and send converted image
58
+ const imageBuffer = await fsPromises.readFile(outputImagePath);
59
+ await sock.sendMessage(chatId, {
60
+ image: imageBuffer,
61
+ caption: '✅ Sticker converted to image!'
62
+ });
63
+
64
+ // Cleanup
65
+ scheduleFileDeletion(stickerFilePath);
66
+ scheduleFileDeletion(outputImagePath);
67
+
68
+ } catch (error) {
69
+ console.error('❌ Error converting sticker:', error);
70
+ await sock.sendMessage(chatId, { text: 'An error occurred while converting the sticker.' });
71
+ }
72
+ };
73
+
74
+ module.exports = convertStickerToImage;
@@ -0,0 +1,134 @@
1
+ const { downloadMediaMessage } = require('@whiskeysockets/baileys');
2
+ const { exec } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const settings = require('../../daveset');
6
+ const webp = require('node-webpmux');
7
+ const crypto = require('crypto');
8
+ const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
9
+
10
+ async function stickerCommand(sock, chatId, message) {
11
+ const fakeContact = createFakeContact(message);
12
+ const pushname= message.pushName || "Unknown User"
13
+ // The message that will be quoted in the reply.
14
+ const messageToQuote = message;
15
+
16
+ // The message object that contains the media to be downloaded.
17
+ let targetMessage = message;
18
+
19
+ // If the message is a reply, the target media is in the quoted message.
20
+ if (message.message?.extendedTextMessage?.contextInfo?.quotedMessage) {
21
+ // We need to build a new message object for downloadMediaMessage to work correctly.
22
+ const quotedInfo = message.message.extendedTextMessage.contextInfo;
23
+ targetMessage = {
24
+ key: {
25
+ remoteJid: chatId,
26
+ id: quotedInfo.stanzaId,
27
+ participant: quotedInfo.participant
28
+ },
29
+ message: quotedInfo.quotedMessage
30
+ };
31
+ }
32
+
33
+ const mediaMessage = targetMessage.message?.imageMessage || targetMessage.message?.videoMessage || targetMessage.message?.documentMessage;
34
+
35
+ if (!mediaMessage) {
36
+ await sock.sendMessage(chatId, {
37
+ text: 'Please reply to an image/video with .sticker, or send an image/video with .sticker as the caption.'
38
+ },{ quoted: fakeContact });
39
+ return;
40
+ }
41
+
42
+ try {
43
+ const mediaBuffer = await downloadMediaMessage(targetMessage, 'buffer', {}, {
44
+ logger: undefined,
45
+ reuploadRequest: sock.updateMediaMessage
46
+ });
47
+
48
+ if (!mediaBuffer) {
49
+ await sock.sendMessage(chatId, {
50
+ text: 'Failed to download media. Please try again.'
51
+ }, { quoted: fakeContact });
52
+ return;
53
+ }
54
+
55
+ // Create temp directory if it doesn't exist
56
+ const tmpDir = path.join(process.cwd(), 'tmp');
57
+ if (!fs.existsSync(tmpDir)) {
58
+ fs.mkdirSync(tmpDir, { recursive: true });
59
+ }
60
+
61
+ // Generate temp file paths
62
+ const tempInput = path.join(tmpDir, `temp_${Date.now()}`);
63
+ const tempOutput = path.join(tmpDir, `sticker_${Date.now()}.webp`);
64
+
65
+ // Write media to temp file
66
+ fs.writeFileSync(tempInput, mediaBuffer);
67
+
68
+ // Check if media is animated (GIF or video)
69
+ const isAnimated = mediaMessage.mimetype?.includes('gif') ||
70
+ mediaMessage.mimetype?.includes('video') ||
71
+ mediaMessage.seconds > 0;
72
+
73
+ // Convert to WebP using ffmpeg with optimized settings for animated/non-animated
74
+ const ffmpegCommand = isAnimated
75
+ ? `ffmpeg -i "${tempInput}" -vf "scale=512:512:force_original_aspect_ratio=decrease,fps=15,pad=512:512:(ow-iw)/2:(oh-ih)/2:color=#00000000" -c:v libwebp -preset default -loop 0 -vsync 0 -pix_fmt yuva420p -quality 75 -compression_level 6 "${tempOutput}"`
76
+ : `ffmpeg -i "${tempInput}" -vf "scale=512:512:force_original_aspect_ratio=decrease,format=rgba,pad=512:512:(ow-iw)/2:(oh-ih)/2:color=#00000000" -c:v libwebp -preset default -loop 0 -vsync 0 -pix_fmt yuva420p -quality 75 -compression_level 6 "${tempOutput}"`;
77
+
78
+ await new Promise((resolve, reject) => {
79
+ exec(ffmpegCommand, (error) => {
80
+ if (error) {
81
+ console.error('FFmpeg error:', error);
82
+ reject(error);
83
+ } else resolve();
84
+ });
85
+ });
86
+
87
+ // Read the WebP file
88
+ const webpBuffer = fs.readFileSync(tempOutput);
89
+
90
+ // Add metadata using webpmux
91
+ const img = new webp.Image();
92
+ await img.load(webpBuffer);
93
+
94
+ // Create metadata
95
+ const json = {
96
+ 'sticker-pack-id': crypto.randomBytes(32).toString('hex'),
97
+ 'sticker-pack-name': settings.packname || `${pushname}`,
98
+ 'emojis': ['🫩']
99
+ };
100
+
101
+ // Create exif buffer
102
+ const exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]);
103
+ const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8');
104
+ const exif = Buffer.concat([exifAttr, jsonBuffer]);
105
+ exif.writeUIntLE(jsonBuffer.length, 14, 4);
106
+
107
+ // Set the exif data
108
+ img.exif = exif;
109
+
110
+ // Get the final buffer with metadata
111
+ const finalBuffer = await img.save(null);
112
+
113
+ // Send the sticker
114
+ await sock.sendMessage(chatId, {
115
+ sticker: finalBuffer
116
+ },{ quoted: fakeContact });
117
+
118
+ // Cleanup temp files
119
+ try {
120
+ fs.unlinkSync(tempInput);
121
+ fs.unlinkSync(tempOutput);
122
+ } catch (err) {
123
+ console.error('Error cleaning up temp files:', err);
124
+ }
125
+
126
+ } catch (error) {
127
+ //console.error('Error in sticker command:', error);
128
+ await sock.sendMessage(chatId, {
129
+ text: 'Failed to create sticker! Try again later.'
130
+ }, { quoted: fakeContact });
131
+ }
132
+ }
133
+
134
+ module.exports = stickerCommand;
@@ -0,0 +1,133 @@
1
+ const { downloadMediaMessage } = require('@whiskeysockets/baileys');
2
+ const { exec } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const settings = require('../../daveset');
6
+ const webp = require('node-webpmux');
7
+ const crypto = require('crypto');
8
+ const { createFakeContact, getBotName } = require('../../davelib/fakeContact');
9
+
10
+ async function stickercropCommand(sock, chatId, message) {
11
+ // The message that will be quoted in the reply.
12
+ const messageToQuote = message;
13
+
14
+ // The message object that contains the media to be downloaded.
15
+ let targetMessage = message;
16
+
17
+ // If the message is a reply, the target media is in the quoted message.
18
+ if (message.message?.extendedTextMessage?.contextInfo?.quotedMessage) {
19
+ // We need to build a new message object for downloadMediaMessage to work correctly.
20
+ const quotedInfo = message.message.extendedTextMessage.contextInfo;
21
+ targetMessage = {
22
+ key: {
23
+ remoteJid: chatId,
24
+ id: quotedInfo.stanzaId,
25
+ participant: quotedInfo.participant
26
+ },
27
+ message: quotedInfo.quotedMessage
28
+ };
29
+ }
30
+
31
+ const mediaMessage = targetMessage.message?.imageMessage || targetMessage.message?.videoMessage || targetMessage.message?.documentMessage || targetMessage.message?.stickerMessage;
32
+
33
+ if (!mediaMessage) {
34
+ await sock.sendMessage(chatId, {
35
+ text: 'Please reply to an image/video/sticker with .crop, or send an image/video/sticker with .crop as the caption.'
36
+ },{ quoted: messageToQuote });
37
+ return;
38
+ }
39
+
40
+ try {
41
+ const mediaBuffer = await downloadMediaMessage(targetMessage, 'buffer', {}, {
42
+ logger: undefined,
43
+ reuploadRequest: sock.updateMediaMessage
44
+ });
45
+
46
+ if (!mediaBuffer) {
47
+ await sock.sendMessage(chatId, {
48
+ text: 'Failed to download media. Please try again.'
49
+ });
50
+ return;
51
+ }
52
+
53
+ // Create temp directory if it doesn't exist
54
+ const tmpDir = path.join(process.cwd(), 'tmp');
55
+ if (!fs.existsSync(tmpDir)) {
56
+ fs.mkdirSync(tmpDir, { recursive: true });
57
+ }
58
+
59
+ // Generate temp file paths
60
+ const tempInput = path.join(tmpDir, `temp_${Date.now()}`);
61
+ const tempOutput = path.join(tmpDir, `crop_${Date.now()}.webp`);
62
+
63
+ // Write media to temp file
64
+ fs.writeFileSync(tempInput, mediaBuffer);
65
+
66
+ // Check if media is animated (GIF or video)
67
+ const isAnimated = mediaMessage.mimetype?.includes('gif') ||
68
+ mediaMessage.mimetype?.includes('video') ||
69
+ mediaMessage.seconds > 0;
70
+
71
+ // Convert to WebP using ffmpeg with crop to square
72
+ // The crop filter will center-crop the image to a square
73
+ const ffmpegCommand = isAnimated
74
+ ? `ffmpeg -i "${tempInput}" -vf "crop=min(iw\\,ih):min(iw\\,ih),scale=512:512,fps=15" -c:v libwebp -preset default -loop 0 -vsync 0 -pix_fmt yuva420p -quality 75 -compression_level 6 "${tempOutput}"`
75
+ : `ffmpeg -i "${tempInput}" -vf "crop=min(iw\\,ih):min(iw\\,ih),scale=512:512,format=rgba" -c:v libwebp -preset default -loop 0 -vsync 0 -pix_fmt yuva420p -quality 75 -compression_level 6 "${tempOutput}"`;
76
+
77
+ await new Promise((resolve, reject) => {
78
+ exec(ffmpegCommand, (error) => {
79
+ if (error) {
80
+ console.error('FFmpeg error:', error);
81
+ reject(error);
82
+ } else resolve();
83
+ });
84
+ });
85
+
86
+ // Read the WebP file
87
+ const webpBuffer = fs.readFileSync(tempOutput);
88
+
89
+ // Add metadata using webpmux
90
+ const img = new webp.Image();
91
+ await img.load(webpBuffer);
92
+
93
+ // Create metadata
94
+ const json = {
95
+ 'sticker-pack-id': crypto.randomBytes(32).toString('hex'),
96
+ 'sticker-pack-name': settings.packname || 'Issah-X',
97
+ 'emojis': ['✂️']
98
+ };
99
+
100
+ // Create exif buffer
101
+ const exifAttr = Buffer.from([0x49, 0x49, 0x2A, 0x00, 0x08, 0x00, 0x00, 0x00, 0x01, 0x00, 0x41, 0x57, 0x07, 0x00, 0x00, 0x00, 0x00, 0x00, 0x16, 0x00, 0x00, 0x00]);
102
+ const jsonBuffer = Buffer.from(JSON.stringify(json), 'utf8');
103
+ const exif = Buffer.concat([exifAttr, jsonBuffer]);
104
+ exif.writeUIntLE(jsonBuffer.length, 14, 4);
105
+
106
+ // Set the exif data
107
+ img.exif = exif;
108
+
109
+ // Get the final buffer with metadata
110
+ const finalBuffer = await img.save(null);
111
+
112
+ // Send the sticker
113
+ await sock.sendMessage(chatId, {
114
+ sticker: finalBuffer
115
+ },{ quoted: messageToQuote });
116
+
117
+ // Cleanup temp files
118
+ try {
119
+ fs.unlinkSync(tempInput);
120
+ fs.unlinkSync(tempOutput);
121
+ } catch (err) {
122
+ console.error('Error cleaning up temp files:', err);
123
+ }
124
+
125
+ } catch (error) {
126
+ console.error('Error in stickercrop command:', error);
127
+ await sock.sendMessage(chatId, {
128
+ text: 'Failed to crop sticker! Try with an image.'
129
+ });
130
+ }
131
+ }
132
+
133
+ module.exports = stickercropCommand;