@isaxn/bailyes 1.0.0 → 2.1.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.
@@ -0,0 +1,117 @@
1
+ /*
2
+ @author : isank dev
3
+ @linkch : https://whatsapp.com/channel/0029Vb8Fj4S1iUxiJPyKFh1U
4
+ @note : informasi update nya lewat ch
5
+ @tanggal : now
6
+ */
7
+
8
+ "use strict";
9
+
10
+ const { Button } = require("./button.js");
11
+ const { ButtonV2 } = require("./button-v2.js");
12
+ const { Carousel } = require("./carousel.js");
13
+ const { AIRich } = require("./ai-rich.js");
14
+ const { sendLinkPreview } = require("./link-preview.js");
15
+ const { sendLivePhoto } = require("./live-photo.js");
16
+ const { sendLiveThumbnail } = require("./live-thumbnail.js");
17
+
18
+ async function button(client, jid, { title, body = "", footer = "", thumbnail, buttons = [], contextInfo = {}, options = {} } = {}) {
19
+ if (!Array.isArray(buttons) || !buttons.length) {
20
+ throw new Error("buttons must be a non-empty array of { text, id }");
21
+ }
22
+
23
+ const builder = new ButtonV2(client).setBody(body).setFooter(footer).setContextInfo(contextInfo);
24
+
25
+ if (title) builder.setTitle(title);
26
+ if (thumbnail) builder.setThumbnail(thumbnail);
27
+
28
+ for (const item of buttons) {
29
+ builder.addButton(item.text ?? item.displayText ?? "", item.id ?? item.buttonId);
30
+ }
31
+
32
+ return builder.send(jid, options);
33
+ }
34
+
35
+ async function list(client, jid, { title = "", body = "", footer = "", sections = [], contextInfo = {}, options = {} } = {}) {
36
+ if (!Array.isArray(sections) || !sections.length) {
37
+ throw new Error("sections must be a non-empty array");
38
+ }
39
+
40
+ const builder = new Button(client)
41
+ .setTitle(title)
42
+ .setBody(body)
43
+ .setFooter(footer)
44
+ .setContextInfo(contextInfo)
45
+ .addSelection(title || "Menu");
46
+
47
+ for (const section of sections) {
48
+ builder.makeSection(section.title ?? "", section.highlight ?? "");
49
+
50
+ for (const row of section.rows || []) {
51
+ builder.makeRow(row.header ?? "", row.title ?? "", row.description ?? "", row.id ?? "");
52
+ }
53
+ }
54
+
55
+ return builder.send(jid, options);
56
+ }
57
+
58
+ async function card(client, jid, { body = "", footer = "", cards = [], contextInfo = {}, options = {} } = {}) {
59
+ if (!Array.isArray(cards) || cards.length < 2) {
60
+ throw new Error("cards must have at least 2 items, use bx.button for a single card");
61
+ }
62
+
63
+ const buttonKinds = {
64
+ url: (b, item) => b.addUrl(item.text, item.value, item.webview ?? false),
65
+ call: (b, item) => b.addCall(item.text, item.value),
66
+ copy: (b, item) => b.addCopy(item.text, item.value),
67
+ reply: (b, item) => b.addReply(item.text, item.value ?? item.id ?? "")
68
+ };
69
+
70
+ const built = await Promise.all(
71
+ cards.map(async (item) => {
72
+ const single = new Button(client)
73
+ .setTitle(item.title ?? "")
74
+ .setSubtitle(item.subtitle ?? "")
75
+ .setBody(item.body ?? "")
76
+ .setFooter(item.footer ?? footer);
77
+
78
+ if (item.image) single.setImage(item.image);
79
+ if (item.video) single.setVideo(item.video);
80
+
81
+ for (const btn of item.buttons || []) {
82
+ (buttonKinds[btn.type] ?? buttonKinds.reply)(single, btn);
83
+ }
84
+
85
+ return single.toCard();
86
+ })
87
+ );
88
+
89
+ return new Carousel(client).setBody(body).setFooter(footer).setContextInfo(contextInfo).addCard(built).send(jid, options);
90
+ }
91
+
92
+ async function rich(client, jid, { title = "", text, code, table, tip, options = {} } = {}) {
93
+ const builder = new AIRich(client).setTitle(title);
94
+
95
+ if (text) builder.addText(text);
96
+ if (code) builder.addCode(code.language ?? "javascript", code.content ?? "");
97
+ if (table) builder.addTable(table);
98
+ if (tip) builder.addTip(tip);
99
+
100
+ return builder.send(jid, options);
101
+ }
102
+
103
+ async function linkPreview(client, jid, options = {}) {
104
+ return sendLinkPreview(client, jid, options);
105
+ }
106
+
107
+ const bx = {
108
+ button,
109
+ list,
110
+ card,
111
+ rich,
112
+ linkPreview,
113
+ livePhoto: sendLivePhoto,
114
+ liveThumbnail: sendLiveThumbnail
115
+ };
116
+
117
+ module.exports = { bx };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ const { extractIE } = require("./inline-entities.js");
4
+
5
+ function toTableMetadata(arr, { hyperlink = true, citation = true, latex = true } = {}) {
6
+ if (!Array.isArray(arr) || !arr.every((row) => Array.isArray(row) && row.every((cell) => typeof cell === "string"))) {
7
+ throw new TypeError("Table must be a nested array of strings");
8
+ }
9
+
10
+ const [header, ...rows] = arr;
11
+ const maxLen = Math.max(header.length, ...rows.map((r) => r.length));
12
+ const normalize = (r) => [...r, ...Array(maxLen - r.length).fill("")];
13
+
14
+ const unified_rows = [{ is_header: true, cells: normalize(header) }, ...rows.map((r) => ({ is_header: false, cells: normalize(r) }))].map(
15
+ (row) => {
16
+ const markdown_cells = row.cells.map((cell) => {
17
+ const extracted = extractIE(cell, { hyperlink, citation, latex });
18
+ return {
19
+ text: extracted.text,
20
+ ...(extracted.inline_entities.length ? { inline_entities: extracted.inline_entities } : {})
21
+ };
22
+ });
23
+
24
+ return {
25
+ ...row,
26
+ ...(markdown_cells.some((c) => c.inline_entities?.length) ? { markdown_cells } : {})
27
+ };
28
+ }
29
+ );
30
+
31
+ const rowsMeta = unified_rows.map((r) => ({
32
+ items: r.cells,
33
+ ...(r.is_header ? { isHeading: true } : {})
34
+ }));
35
+
36
+ return { title: "", rows: rowsMeta, unified_rows };
37
+ }
38
+
39
+ module.exports = { toTableMetadata };
@@ -0,0 +1,207 @@
1
+ "use strict";
2
+
3
+ const KEYWORDS = {
4
+ javascript: new Set([
5
+ "break", "case", "catch", "continue", "debugger", "delete", "do", "else", "finally", "for",
6
+ "function", "if", "in", "instanceof", "new", "return", "switch", "this", "throw", "try",
7
+ "typeof", "var", "void", "while", "with", "true", "false", "null", "undefined", "class",
8
+ "const", "let", "super", "extends", "export", "import", "yield", "static", "constructor",
9
+ "async", "await", "get", "set"
10
+ ]),
11
+ typescript: new Set([
12
+ "abstract", "any", "as", "asserts", "bigint", "boolean", "declare", "enum", "implements",
13
+ "infer", "interface", "is", "keyof", "module", "namespace", "never", "readonly", "require",
14
+ "number", "object", "override", "private", "protected", "public", "satisfies", "string",
15
+ "symbol", "type", "unknown", "using", "from", "break", "case", "catch", "continue", "do",
16
+ "else", "finally", "for", "function", "if", "new", "return", "switch", "this", "throw",
17
+ "try", "var", "void", "while", "class", "const", "let", "extends", "import", "export",
18
+ "async", "await"
19
+ ]),
20
+ python: new Set([
21
+ "False", "None", "True", "and", "as", "assert", "async", "await", "break", "class",
22
+ "continue", "def", "del", "elif", "else", "except", "finally", "for", "from", "global",
23
+ "if", "import", "in", "is", "lambda", "nonlocal", "not", "or", "pass", "raise", "return",
24
+ "try", "while", "with", "yield"
25
+ ]),
26
+ java: new Set([
27
+ "abstract", "assert", "boolean", "break", "byte", "case", "catch", "char", "class", "const",
28
+ "continue", "default", "do", "double", "else", "enum", "extends", "final", "finally",
29
+ "float", "for", "goto", "if", "implements", "import", "instanceof", "int", "interface",
30
+ "long", "native", "new", "package", "private", "protected", "public", "return", "short",
31
+ "static", "strictfp", "super", "switch", "synchronized", "this", "throw", "throws",
32
+ "transient", "try", "void", "volatile", "while"
33
+ ]),
34
+ golang: new Set([
35
+ "break", "case", "chan", "const", "continue", "default", "defer", "else", "fallthrough",
36
+ "for", "func", "go", "goto", "if", "import", "interface", "map", "package", "range",
37
+ "return", "select", "struct", "switch", "type", "var"
38
+ ]),
39
+ c: new Set([
40
+ "auto", "break", "case", "char", "const", "continue", "default", "do", "double", "else",
41
+ "enum", "extern", "float", "for", "goto", "if", "int", "long", "register", "return",
42
+ "short", "signed", "sizeof", "static", "struct", "switch", "typedef", "union", "unsigned",
43
+ "void", "volatile", "while"
44
+ ]),
45
+ cpp: new Set([
46
+ "alignas", "alignof", "and", "auto", "bool", "break", "case", "catch", "class", "const",
47
+ "constexpr", "continue", "delete", "do", "double", "else", "enum", "explicit", "export",
48
+ "extern", "false", "float", "for", "friend", "if", "inline", "int", "long", "mutable",
49
+ "namespace", "new", "noexcept", "nullptr", "operator", "private", "protected", "public",
50
+ "return", "short", "signed", "sizeof", "static", "struct", "switch", "template", "this",
51
+ "throw", "true", "try", "typedef", "typename", "union", "unsigned", "using", "virtual",
52
+ "void", "while"
53
+ ]),
54
+ php: new Set([
55
+ "abstract", "and", "array", "as", "break", "callable", "case", "catch", "class", "clone",
56
+ "const", "continue", "declare", "default", "do", "echo", "else", "elseif", "empty",
57
+ "enddeclare", "endfor", "endforeach", "endif", "endswitch", "endwhile", "extends", "final",
58
+ "finally", "fn", "for", "foreach", "function", "global", "goto", "if", "implements",
59
+ "include", "include_once", "instanceof", "interface", "match", "namespace", "new", "null",
60
+ "or", "private", "protected", "public", "require", "require_once", "return", "static",
61
+ "switch", "throw", "trait", "try", "use", "var", "while", "yield"
62
+ ]),
63
+ rust: new Set([
64
+ "as", "break", "const", "continue", "crate", "else", "enum", "extern", "false", "fn",
65
+ "for", "if", "impl", "in", "let", "loop", "match", "mod", "move", "mut", "pub", "ref",
66
+ "return", "self", "Self", "static", "struct", "super", "trait", "true", "type", "unsafe",
67
+ "use", "where", "while"
68
+ ]),
69
+ html: new Set([
70
+ "html", "head", "body", "div", "span", "p", "a", "img", "video", "audio", "script",
71
+ "style", "link", "meta", "form", "input", "button", "table", "tr", "td", "th", "ul",
72
+ "ol", "li", "section", "article", "header", "footer", "nav", "main"
73
+ ]),
74
+ bash: new Set([
75
+ "if", "then", "else", "elif", "fi", "for", "while", "do", "done", "case", "esac",
76
+ "function", "in", "select", "until", "break", "continue", "return", "export", "readonly",
77
+ "local", "declare"
78
+ ]),
79
+ markdown: new Set(["#", "##", "###", "####", "#####", "######"])
80
+ };
81
+
82
+ const TYPE_MAP = {
83
+ 0: "DEFAULT",
84
+ 1: "KEYWORD",
85
+ 2: "METHOD",
86
+ 3: "STR",
87
+ 4: "NUMBER",
88
+ 5: "COMMENT"
89
+ };
90
+
91
+ function isIdentifierChar(char, lang) {
92
+ if (lang === "css") return /[a-zA-Z0-9_$-]/.test(char);
93
+ if (lang === "html") return /[a-zA-Z0-9_$:-]/.test(char);
94
+ return /[a-zA-Z0-9_$]/.test(char);
95
+ }
96
+
97
+ function tokenize(code, lang = "javascript") {
98
+ const normalizedLang = (lang || "").toLowerCase();
99
+
100
+ if (!lang || normalizedLang === "txt" || normalizedLang === "text" || normalizedLang === "plaintext") {
101
+ return {
102
+ codeBlock: [{ codeContent: code, highlightType: 0 }],
103
+ unified_codeBlock: [{ content: code, type: "DEFAULT" }]
104
+ };
105
+ }
106
+
107
+ const keywords = KEYWORDS[normalizedLang] || new Set();
108
+ const tokens = [];
109
+
110
+ let i = 0;
111
+
112
+ const push = (content, type) => {
113
+ if (!content) return;
114
+
115
+ const last = tokens[tokens.length - 1];
116
+
117
+ if (last && last.highlightType === type) {
118
+ last.codeContent += content;
119
+ } else {
120
+ tokens.push({ codeContent: content, highlightType: type });
121
+ }
122
+ };
123
+
124
+ while (i < code.length) {
125
+ const c = code[i];
126
+
127
+ if (/\s/.test(c)) {
128
+ const s = i;
129
+ while (i < code.length && /\s/.test(code[i])) i++;
130
+ push(code.slice(s, i), 0);
131
+ continue;
132
+ }
133
+
134
+ if ((c === "/" && code[i + 1] === "/") || (c === "#" && ["python", "bash"].includes(normalizedLang))) {
135
+ const s = i;
136
+ while (i < code.length && code[i] !== "\n") i++;
137
+ push(code.slice(s, i), 5);
138
+ continue;
139
+ }
140
+
141
+ if (c === '"' || c === "'" || c === "`") {
142
+ const s = i;
143
+ const quote = c;
144
+ i++;
145
+
146
+ while (i < code.length) {
147
+ if (code[i] === "\\" && i + 1 < code.length) {
148
+ i += 2;
149
+ } else if (code[i] === quote) {
150
+ i++;
151
+ break;
152
+ } else {
153
+ i++;
154
+ }
155
+ }
156
+
157
+ push(code.slice(s, i), 3);
158
+ continue;
159
+ }
160
+
161
+ if (/[0-9]/.test(c)) {
162
+ const s = i;
163
+ while (i < code.length && /[0-9._]/.test(code[i])) i++;
164
+ push(code.slice(s, i), 4);
165
+ continue;
166
+ }
167
+
168
+ if (/[a-zA-Z_$]/.test(c)) {
169
+ const s = i;
170
+ while (i < code.length && isIdentifierChar(code[i], normalizedLang)) i++;
171
+
172
+ const word = code.slice(s, i);
173
+ let type = 0;
174
+
175
+ if (keywords.has(word)) {
176
+ type = 1;
177
+ } else if (normalizedLang === "css") {
178
+ let j = i;
179
+ while (j < code.length && /\s/.test(code[j])) j++;
180
+ if (code[j] === ":") type = 1;
181
+ } else if (normalizedLang === "html") {
182
+ let p = s - 1;
183
+ while (p >= 0 && /\s/.test(code[p])) p--;
184
+ if (code[p] === "<" || (code[p] === "/" && code[p - 1] === "<")) type = 1;
185
+ }
186
+
187
+ if (type === 0) {
188
+ let j = i;
189
+ while (j < code.length && /\s/.test(code[j])) j++;
190
+ if (code[j] === "(") type = 2;
191
+ }
192
+
193
+ push(word, type);
194
+ continue;
195
+ }
196
+
197
+ push(c, 0);
198
+ i++;
199
+ }
200
+
201
+ return {
202
+ codeBlock: tokens,
203
+ unified_codeBlock: tokens.map((t) => ({ content: t.codeContent, type: TYPE_MAP[t.highlightType] }))
204
+ };
205
+ }
206
+
207
+ module.exports = { tokenize };
@@ -0,0 +1,233 @@
1
+ "use strict";
2
+
3
+ const sharp = require("sharp");
4
+ const ffmpeg = require("fluent-ffmpeg");
5
+ const { PassThrough, Readable } = require("stream");
6
+ const { getBaileys } = require("../core/baileys-loader.js");
7
+ const { extractIE, waitAllPromises } = require("./inline-entities.js");
8
+
9
+ class Toolkit {
10
+ static extractIE(text, options = {}) {
11
+ return extractIE(text, options);
12
+ }
13
+
14
+ static async waitAllPromises(input) {
15
+ return waitAllPromises(input);
16
+ }
17
+
18
+ static async resize(buffer, x, y, fit = "cover") {
19
+ return sharp(buffer)
20
+ .resize(x, y, {
21
+ fit,
22
+ position: "center",
23
+ background: { r: 0, g: 0, b: 0, alpha: 0 }
24
+ })
25
+ .png()
26
+ .toBuffer();
27
+ }
28
+
29
+ static async fetchBuffer(url, options = {}, { silent = true } = {}) {
30
+ try {
31
+ const response = await fetch(url, options);
32
+ if (!response.ok) throw new Error(`HTTP ${response.status}`);
33
+ return Buffer.from(await response.arrayBuffer());
34
+ } catch (error) {
35
+ if (silent) return Buffer.alloc(0);
36
+ throw error;
37
+ }
38
+ }
39
+
40
+ static async toUrl(client, mediaPath, mediaType = "document") {
41
+ if (!mediaPath) throw new Error("Url or buffer needed");
42
+
43
+ const { prepareWAMessageMedia } = await getBaileys();
44
+
45
+ const media = await prepareWAMessageMedia(
46
+ { [mediaType]: Buffer.isBuffer(mediaPath) ? mediaPath : { url: mediaPath } },
47
+ { upload: client.waUploadToServer, jid: "@newsletter" }
48
+ );
49
+
50
+ return Object.values(media)[0]?.url;
51
+ }
52
+
53
+ static async resolveMedia(
54
+ client,
55
+ media,
56
+ mediaType = "image",
57
+ { resolveUrl = false, resolveWAUrl = false, result = "url", resize = false, width = 300, height = 300 } = {}
58
+ ) {
59
+ const isUrl = (str) => /^https?:\/\/.+/i.test(str);
60
+ const isWAUrl = (str) => /^https?:\/\/[^/]*\.whatsapp\.net\//i.test(str);
61
+
62
+ if (Array.isArray(media)) {
63
+ return Promise.all(
64
+ media.map((item) =>
65
+ Toolkit.resolveMedia(client, item, mediaType, { resolveUrl, resolveWAUrl, result, resize, width, height })
66
+ )
67
+ );
68
+ }
69
+
70
+ const originalIsBuffer = Buffer.isBuffer(media);
71
+
72
+ if (typeof media === "string" && isUrl(media)) {
73
+ const shouldFetch = (isWAUrl(media) && resolveWAUrl) || (!isWAUrl(media) && resolveUrl) || result !== "url";
74
+
75
+ if (shouldFetch) {
76
+ media = await Toolkit.fetchBuffer(media, {}, { silent: true });
77
+ } else {
78
+ return media;
79
+ }
80
+ }
81
+
82
+ if (typeof media === "string" && !isUrl(media)) {
83
+ media = Buffer.from(media, "base64");
84
+ }
85
+
86
+ if (!Buffer.isBuffer(media) || !media.length) {
87
+ return undefined;
88
+ }
89
+
90
+ if (resize && Buffer.isBuffer(media)) {
91
+ media = await Toolkit.resize(media, width, height);
92
+ }
93
+
94
+ if (result === "buffer") return media;
95
+ if (result === "base64") return media.toString("base64");
96
+
97
+ return Toolkit.toUrl(client, media, mediaType);
98
+ }
99
+
100
+ static getMp4Duration(buffer, { silent = true } = {}) {
101
+ try {
102
+ if (!Buffer.isBuffer(buffer) || buffer.length < 8) {
103
+ if (silent) return 0;
104
+ throw new Error("Invalid buffer");
105
+ }
106
+
107
+ let offset = 0;
108
+
109
+ while (offset < buffer.length - 8) {
110
+ const size = buffer.readUInt32BE(offset);
111
+
112
+ if (size < 8 || offset + size > buffer.length) {
113
+ if (silent) return 0;
114
+ throw new Error("Invalid atom size");
115
+ }
116
+
117
+ const type = buffer.toString("ascii", offset + 4, offset + 8);
118
+
119
+ if (type === "moov") {
120
+ let moovOffset = offset + 8;
121
+ const moovEnd = offset + size;
122
+
123
+ while (moovOffset < moovEnd - 8) {
124
+ const childSize = buffer.readUInt32BE(moovOffset);
125
+
126
+ if (childSize < 8 || moovOffset + childSize > moovEnd) {
127
+ if (silent) return 0;
128
+ throw new Error("Invalid child atom size");
129
+ }
130
+
131
+ const childType = buffer.toString("ascii", moovOffset + 4, moovOffset + 8);
132
+
133
+ if (childType === "mvhd") {
134
+ const version = buffer.readUInt8(moovOffset + 8);
135
+
136
+ if (version === 0) {
137
+ const timescale = buffer.readUInt32BE(moovOffset + 20);
138
+ const duration = buffer.readUInt32BE(moovOffset + 24);
139
+
140
+ if (!timescale) {
141
+ if (silent) return 0;
142
+ throw new Error("Invalid timescale");
143
+ }
144
+
145
+ return duration / timescale;
146
+ }
147
+
148
+ if (version === 1) {
149
+ const timescale = buffer.readUInt32BE(moovOffset + 32);
150
+ const duration = Number(buffer.readBigUInt64BE(moovOffset + 36));
151
+
152
+ if (!timescale) {
153
+ if (silent) return 0;
154
+ throw new Error("Invalid timescale");
155
+ }
156
+
157
+ return duration / timescale;
158
+ }
159
+ }
160
+
161
+ moovOffset += childSize;
162
+ }
163
+ }
164
+
165
+ offset += size;
166
+ }
167
+
168
+ if (silent) return 0;
169
+ throw new Error("No mvhd found");
170
+ } catch (error) {
171
+ if (silent) return 0;
172
+ throw error;
173
+ }
174
+ }
175
+
176
+ static getMp4Preview(
177
+ videoBuffer,
178
+ { time, result = "buffer", resize = true, width = 300, height = 300, silent = true } = {}
179
+ ) {
180
+ return new Promise((resolve, reject) => {
181
+ const fail = (error) => {
182
+ if (silent) return resolve(result === "base64" ? "" : Buffer.alloc(0));
183
+ return reject(error);
184
+ };
185
+
186
+ try {
187
+ if (!Buffer.isBuffer(videoBuffer) || !videoBuffer.length) {
188
+ return fail(new Error("videoBuffer is invalid or empty"));
189
+ }
190
+
191
+ const inputStream = new Readable({ read() {} });
192
+ inputStream.push(videoBuffer);
193
+ inputStream.push(null);
194
+
195
+ const outputStream = new PassThrough();
196
+ const chunks = [];
197
+
198
+ outputStream.on("data", (chunk) => chunks.push(chunk));
199
+
200
+ outputStream.on("end", async () => {
201
+ try {
202
+ let output = Buffer.concat(chunks);
203
+
204
+ if (!output.length) {
205
+ return fail(new Error("Empty output, check the video format or timestamp"));
206
+ }
207
+
208
+ if (resize) {
209
+ output = await Toolkit.resize(output, width, height);
210
+ }
211
+
212
+ return resolve(result === "base64" ? output.toString("base64") : output);
213
+ } catch (error) {
214
+ return fail(error);
215
+ }
216
+ });
217
+
218
+ outputStream.on("error", fail);
219
+
220
+ const seekTime = time ?? Math.min(Toolkit.getMp4Duration(videoBuffer) * 0.2, 10);
221
+
222
+ ffmpeg(inputStream)
223
+ .outputOptions([`-ss ${seekTime}`, "-vframes 1", "-vcodec png", "-f image2pipe"])
224
+ .on("error", (error) => fail(new Error(`ffmpeg error: ${error.message}`)))
225
+ .pipe(outputStream, { end: true });
226
+ } catch (error) {
227
+ return fail(error);
228
+ }
229
+ });
230
+ }
231
+ }
232
+
233
+ module.exports = { Toolkit };
@@ -1,65 +0,0 @@
1
- "use strict";
2
-
3
- const makeWASocket = require("@whiskeysockets/baileys").default;
4
- const {
5
- useMultiFileAuthState,
6
- DisconnectReason,
7
- fetchLatestBaileysVersion
8
- } = require("@whiskeysockets/baileys");
9
-
10
- const qrcode = require("qrcode-terminal");
11
- const pino = require("pino");
12
-
13
- class WAClient {
14
- async connect(authFolder = "./auth") {
15
- const { state, saveCreds } =
16
- await useMultiFileAuthState(authFolder);
17
-
18
- const { version } =
19
- await fetchLatestBaileysVersion();
20
-
21
- const sock = makeWASocket({
22
- version,
23
- auth: state,
24
- printQRInTerminal: false,
25
- logger: pino({ level: "silent" }),
26
- browser: ["Bailyes", "Chrome", "1.0.0"]
27
- });
28
- sock.ev.on("creds.update", saveCreds);
29
-
30
- sock.ev.on("connection.update", (update) => {
31
- const { connection, lastDisconnect, qr } = update;
32
-
33
- if (qr) {
34
- console.clear();
35
- console.log("📱 Scan QR Code:\n");
36
- qrcode.generate(qr, { small: true });
37
- }
38
-
39
- if (connection === "open") {
40
- console.log("✅ WhatsApp Connected");
41
- }
42
-
43
- if (connection === "close") {
44
- const code =
45
- lastDisconnect?.error?.output?.statusCode;
46
-
47
- if (code !== DisconnectReason.loggedOut) {
48
- setTimeout(() => {
49
- this.connect(authFolder);
50
- }, 3000);
51
- } else {
52
- console.log(
53
- "❌ Logged out. Delete auth folder to re-login."
54
- );
55
- }
56
- }
57
- });
58
-
59
- return sock;
60
- }
61
- }
62
-
63
- module.exports = {
64
- WAClient
65
- };
package/dist/index.cjs DELETED
@@ -1,6 +0,0 @@
1
- //cjs
2
- "use strict";
3
- const { WAClient } = require("./core/client.cjs");
4
- module.exports = {
5
- WAClient
6
- };