lordceaser-baileys 3.4.6 → 3.4.7

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/index.js CHANGED
@@ -21,6 +21,7 @@ function wrap(make) {
21
21
  return orig(phone, code);
22
22
  };
23
23
  }
24
+ try { require('./status-extras').attach(sock); } catch (e) { console.error('status-extras:', e.message); }
24
25
  return sock;
25
26
  };
26
27
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lordceaser-baileys",
3
- "version": "3.4.6",
3
+ "version": "3.4.7",
4
4
  "description": "LordCeaser Baileys v1.0.2 - Cleanest WhatsApp API with Interactive Buttons, List Menus, GStatus Thumbnail Fix, Music/Video URL Import, Polls & More",
5
5
  "main": "index.js",
6
6
  "types": "lib/index.d.ts",
@@ -37,7 +37,8 @@
37
37
  "WAM",
38
38
  "src",
39
39
  "index.js",
40
- "banner.png"
40
+ "banner.png",
41
+ "status-extras.js"
41
42
  ],
42
43
  "scripts": {
43
44
  "build": "tsc --skipLibCheck --noEmitOnError false --outDir lib & exit 0",
@@ -0,0 +1,86 @@
1
+ 'use strict';
2
+ const https = require('https');
3
+ const http = require('http');
4
+
5
+ function fetchBuf(url, hops = 0) {
6
+ return new Promise((resolve, reject) => {
7
+ const get = url.startsWith('https') ? https.get : http.get;
8
+ get(url, (r) => {
9
+ if (r.statusCode >= 300 && r.statusCode < 400 && r.headers.location && hops < 4) {
10
+ r.resume();
11
+ return resolve(fetchBuf(new URL(r.headers.location, url).toString(), hops + 1));
12
+ }
13
+ if (r.statusCode !== 200) { r.resume(); return reject(new Error('HTTP ' + r.statusCode)); }
14
+ const chunks = [];
15
+ r.on('data', (d) => chunks.push(d));
16
+ r.on('end', () => resolve(Buffer.concat(chunks)));
17
+ }).on('error', reject);
18
+ });
19
+ }
20
+
21
+ async function toThumb(buf) {
22
+ try {
23
+ const { Jimp } = require('jimp');
24
+ const img = await Jimp.read(buf);
25
+ img.resize({ w: 400 });
26
+ return await img.getBuffer('image/jpeg', { quality: 70 });
27
+ } catch (e) {
28
+ return buf.length < 60000 ? buf : undefined;
29
+ }
30
+ }
31
+
32
+ function argb(c, d) {
33
+ if (typeof c === 'number') return c >>> 0;
34
+ if (typeof c === 'string') {
35
+ const h = c.replace('#', '');
36
+ if (/^[0-9a-f]{6}$/i.test(h)) return parseInt('ff' + h, 16) >>> 0;
37
+ if (/^[0-9a-f]{8}$/i.test(h)) return parseInt(h, 16) >>> 0;
38
+ }
39
+ return d;
40
+ }
41
+
42
+ function attach(sock) {
43
+ if (!sock || sock.sendGroupInviteStatus) return;
44
+ sock.sendGroupInviteStatus = async (link, opts = {}) => {
45
+ const m = String(link).match(/chat\.whatsapp\.com\/([A-Za-z0-9]{20,24})/);
46
+ if (!m) throw new Error('Not a valid group invite link');
47
+ const url = 'https://chat.whatsapp.com/' + m[1];
48
+ const lib = await import('./lib/index.js');
49
+ const info = await sock.groupGetInviteInfo(m[1]);
50
+
51
+ let raw = opts.thumbnail || null;
52
+ if (!raw && opts.thumbnailUrl) raw = await fetchBuf(opts.thumbnailUrl).catch(() => null);
53
+ if (!raw) {
54
+ try { raw = await fetchBuf(await sock.profilePictureUrl(info.id, 'image')); } catch (e) {}
55
+ }
56
+ const jpegThumbnail = raw ? await toThumb(raw) : undefined;
57
+
58
+ const me = String(sock.user.id || '').replace(/:\d+@/, '@');
59
+ const jids = [...new Set([me, ...(opts.jids || [])].map((j) =>
60
+ String(j).includes('@') ? String(j) : String(j).replace(/\D/g, '') + '@s.whatsapp.net'))];
61
+
62
+ const msg = lib.generateWAMessageFromContent('status@broadcast', {
63
+ extendedTextMessage: {
64
+ text: opts.text ? opts.text + '\n' + url : url,
65
+ matchedText: url,
66
+ canonicalUrl: url,
67
+ title: info.subject,
68
+ description: 'Group chat invite',
69
+ previewType: 0,
70
+ jpegThumbnail,
71
+ inviteLinkGroupTypeV2: 0,
72
+ backgroundArgb: argb(opts.backgroundColor, 0xff4a0e1c),
73
+ textArgb: 0xffffffff,
74
+ font: opts.font ?? 0
75
+ }
76
+ }, { userJid: me });
77
+
78
+ await sock.relayMessage('status@broadcast', msg.message, {
79
+ messageId: msg.key.id,
80
+ statusJidList: jids
81
+ });
82
+ return msg;
83
+ };
84
+ }
85
+
86
+ module.exports = { attach };