@celestial-community/baileys 0.0.1-security → 1.0.0
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.
Potentially problematic release.
This version of @celestial-community/baileys might be problematic. Click here for more details.
- package/WAProto/index.js +138933 -0
- package/engine-requirements.js +10 -0
- package/lib/Defaults/baileys-version.json +7 -0
- package/lib/Defaults/index.js +157 -0
- package/lib/Defaults/phonenumber-mcc.json +223 -0
- package/lib/Signal/Group/ciphertext-message.js +15 -0
- package/lib/Signal/Group/group-session-builder.js +94 -0
- package/lib/Signal/Group/group_cipher.js +118 -0
- package/lib/Signal/Group/index.js +138 -0
- package/lib/Signal/Group/keyhelper.js +75 -0
- package/lib/Signal/Group/queue-job.js +54 -0
- package/lib/Signal/Group/sender-chain-key.js +39 -0
- package/lib/Signal/Group/sender-key-distribution-message.js +71 -0
- package/lib/Signal/Group/sender-key-message.js +76 -0
- package/lib/Signal/Group/sender-key-name.js +50 -0
- package/lib/Signal/Group/sender-key-record.js +65 -0
- package/lib/Signal/Group/sender-key-state.js +114 -0
- package/lib/Signal/Group/sender-message-key.js +33 -0
- package/lib/Signal/libsignal.js +204 -0
- package/lib/Signal/lid-mapping.js +267 -0
- package/lib/Socket/Client/abstract-socket-client.js +13 -0
- package/lib/Socket/Client/index.js +32 -0
- package/lib/Socket/Client/mobile-socket-client.js +82 -0
- package/lib/Socket/Client/web-socket-client.js +89 -0
- package/lib/Socket/Denzy-ZeroDay.js +805 -0
- package/lib/Socket/business.js +279 -0
- package/lib/Socket/chats.js +1169 -0
- package/lib/Socket/community.d.ts +120 -0
- package/lib/Socket/community.js +388 -0
- package/lib/Socket/graphql.js +1122 -0
- package/lib/Socket/groups.js +345 -0
- package/lib/Socket/index.js +22 -0
- package/lib/Socket/interop.js +265 -0
- package/lib/Socket/lid-mapping.js +111 -0
- package/lib/Socket/messages-recv.js +1385 -0
- package/lib/Socket/messages-send.js +956 -0
- package/lib/Socket/mex.js +69 -0
- package/lib/Socket/newsletter.js +424 -0
- package/lib/Socket/privacy.js +229 -0
- package/lib/Socket/registration.js +190 -0
- package/lib/Socket/socket.js +783 -0
- package/lib/Socket/username.d.ts +185 -0
- package/lib/Socket/username.js +168 -0
- package/lib/Socket/usync.js +80 -0
- package/lib/Store/index.js +14 -0
- package/lib/Store/keyed-db.js +158 -0
- package/lib/Store/make-cache-manager-store.js +88 -0
- package/lib/Store/make-in-memory-store.js +484 -0
- package/lib/Store/make-ordered-dictionary.js +78 -0
- package/lib/Store/object-repository.js +27 -0
- package/lib/Types/Auth.js +2 -0
- package/lib/Types/Call.js +2 -0
- package/lib/Types/Chat.js +10 -0
- package/lib/Types/Contact.js +2 -0
- package/lib/Types/Events.js +2 -0
- package/lib/Types/GroupMetadata.js +2 -0
- package/lib/Types/Label.js +27 -0
- package/lib/Types/LabelAssociation.js +9 -0
- package/lib/Types/Message.js +14 -0
- package/lib/Types/MexUpdates.js +19 -0
- package/lib/Types/Newsletter.js +38 -0
- package/lib/Types/Product.js +2 -0
- package/lib/Types/RichType.js +30 -0
- package/lib/Types/Signal.js +2 -0
- package/lib/Types/Socket.js +2 -0
- package/lib/Types/State.js +2 -0
- package/lib/Types/USync.js +2 -0
- package/lib/Types/index.js +58 -0
- package/lib/Utils/anti-ban.js +339 -0
- package/lib/Utils/anti-delete.d.ts +158 -0
- package/lib/Utils/anti-delete.js +293 -0
- package/lib/Utils/antiban-presets.js +91 -0
- package/lib/Utils/antiban-profiles.js +43 -0
- package/lib/Utils/auth-utils.js +210 -0
- package/lib/Utils/baileys-event-stream.js +66 -0
- package/lib/Utils/browser-utils.js +52 -0
- package/lib/Utils/business.js +261 -0
- package/lib/Utils/chat-control.d.ts +113 -0
- package/lib/Utils/chat-control.js +230 -0
- package/lib/Utils/chat-utils.js +922 -0
- package/lib/Utils/companion-reg-client-utils.js +37 -0
- package/lib/Utils/contact-graph-warmer.js +208 -0
- package/lib/Utils/crypto.js +196 -0
- package/lib/Utils/decode-wa-message.js +208 -0
- package/lib/Utils/delivery-tracker.js +110 -0
- package/lib/Utils/device-fingerprint.js +135 -0
- package/lib/Utils/event-buffer.js +531 -0
- package/lib/Utils/generics.js +571 -0
- package/lib/Utils/group-operation-guard.js +147 -0
- package/lib/Utils/health-monitor.js +207 -0
- package/lib/Utils/history.js +122 -0
- package/lib/Utils/human-entropy.js +226 -0
- package/lib/Utils/identity-change-handler.js +72 -0
- package/lib/Utils/index.js +83 -0
- package/lib/Utils/interactive-message.d.ts +139 -0
- package/lib/Utils/interactive-message.js +273 -0
- package/lib/Utils/legitimacy-signal-injector.js +180 -0
- package/lib/Utils/link-preview.js +106 -0
- package/lib/Utils/logger.d.ts +13 -0
- package/lib/Utils/logger.js +9 -0
- package/lib/Utils/lt-hash.js +54 -0
- package/lib/Utils/make-mutex.js +41 -0
- package/lib/Utils/message-composer.d.ts +106 -0
- package/lib/Utils/message-composer.js +721 -0
- package/lib/Utils/message-retry-manager.d.ts +88 -0
- package/lib/Utils/message-retry-manager.js +160 -0
- package/lib/Utils/message-search.d.ts +52 -0
- package/lib/Utils/message-search.js +226 -0
- package/lib/Utils/messages-media.js +899 -0
- package/lib/Utils/messages.js +2698 -0
- package/lib/Utils/noise-handler.js +175 -0
- package/lib/Utils/offline-node-processor.js +45 -0
- package/lib/Utils/pre-key-manager.js +131 -0
- package/lib/Utils/presence-choreographer.js +438 -0
- package/lib/Utils/process-message.js +423 -0
- package/lib/Utils/rate-limiter.js +232 -0
- package/lib/Utils/reconnect-throttle.js +157 -0
- package/lib/Utils/reply-ratio-guard.js +137 -0
- package/lib/Utils/reporting-utils.js +307 -0
- package/lib/Utils/retry-reason-tracker.js +140 -0
- package/lib/Utils/rich-message-utils.d.ts +48 -0
- package/lib/Utils/rich-message-utils.js +400 -0
- package/lib/Utils/rich-response-utils.js +461 -0
- package/lib/Utils/scheduling.d.ts +135 -0
- package/lib/Utils/scheduling.js +246 -0
- package/lib/Utils/session-fingerprint.js +226 -0
- package/lib/Utils/session-stability.js +224 -0
- package/lib/Utils/signal.js +188 -0
- package/lib/Utils/stanza-ack.js +38 -0
- package/lib/Utils/state-manager.js +91 -0
- package/lib/Utils/status-posting.d.ts +81 -0
- package/lib/Utils/status-posting.js +187 -0
- package/lib/Utils/stealth-connect.js +124 -0
- package/lib/Utils/sync-action-utils.js +55 -0
- package/lib/Utils/tc-token-utils.js +171 -0
- package/lib/Utils/templates.d.ts +54 -0
- package/lib/Utils/templates.js +244 -0
- package/lib/Utils/timelock-guard.js +162 -0
- package/lib/Utils/use-mongo-file-auth-state.d.ts +6 -0
- package/lib/Utils/use-mongo-file-auth-state.js +81 -0
- package/lib/Utils/use-multi-file-auth-state.js +125 -0
- package/lib/Utils/use-single-file-auth-state.d.ts +13 -0
- package/lib/Utils/use-single-file-auth-state.js +86 -0
- package/lib/Utils/use-sqlite-auth-state.js +187 -0
- package/lib/Utils/vCard.d.ts +71 -0
- package/lib/Utils/vCard.js +196 -0
- package/lib/Utils/validate-connection.js +253 -0
- package/lib/Utils/warmup.js +154 -0
- package/lib/WABinary/constants.js +1303 -0
- package/lib/WABinary/decode.js +270 -0
- package/lib/WABinary/encode.js +279 -0
- package/lib/WABinary/generic-utils.js +223 -0
- package/lib/WABinary/index.js +34 -0
- package/lib/WABinary/jid-utils.js +84 -0
- package/lib/WABinary/types.js +2 -0
- package/lib/WAM/BinaryInfo.js +13 -0
- package/lib/WAM/constants.js +15254 -0
- package/lib/WAM/encode.js +149 -0
- package/lib/WAM/index.js +32 -0
- package/lib/WAUSync/Protocols/USyncContactProtocol.js +37 -0
- package/lib/WAUSync/Protocols/USyncDeviceProtocol.js +71 -0
- package/lib/WAUSync/Protocols/USyncDisappearingModeProtocol.js +32 -0
- package/lib/WAUSync/Protocols/USyncStatusProtocol.js +49 -0
- package/lib/WAUSync/Protocols/USyncUsernameProtocol.js +23 -0
- package/lib/WAUSync/Protocols/UsyncBotProfileProtocol.js +58 -0
- package/lib/WAUSync/Protocols/UsyncLIDProtocol.js +24 -0
- package/lib/WAUSync/Protocols/index.js +34 -0
- package/lib/WAUSync/USyncQuery.js +99 -0
- package/lib/WAUSync/USyncUser.js +26 -0
- package/lib/WAUSync/USyncUsernameProtocol.d.ts +9 -0
- package/lib/WAUSync/USyncUsernameProtocol.js +37 -0
- package/lib/WAUSync/index.js +32 -0
- package/lib/index.js +59 -0
- package/package.json +105 -5
- package/README.md +0 -5
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
/**
|
|
3
|
+
* rich-response-utils.js
|
|
4
|
+
* Utility: tokenizeCode — buat syntax highlighting di rich message code block
|
|
5
|
+
*
|
|
6
|
+
* Export dari baileys custom:
|
|
7
|
+
* const { tokenizeCode } = require('./src/baileys/lib/Utils/rich-response-utils')
|
|
8
|
+
* // atau jika sudah di-export dari index:
|
|
9
|
+
* const { tokenizeCode } = require('@whiskeysockets/baileys')
|
|
10
|
+
*
|
|
11
|
+
* Contoh:
|
|
12
|
+
* sock.sendMessage(jid, {
|
|
13
|
+
* richResponse: [{
|
|
14
|
+
* language: 'javascript',
|
|
15
|
+
* code: tokenizeCode('const x = 42\nconsole.log(x)', 'javascript')
|
|
16
|
+
* }]
|
|
17
|
+
* })
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, '__esModule', { value: true })
|
|
20
|
+
|
|
21
|
+
// Highlight types (sesuai WAProto AIRichResponseCodeHighlightType)
|
|
22
|
+
const HIGHLIGHT = {
|
|
23
|
+
DEFAULT: 0,
|
|
24
|
+
KEYWORD: 1,
|
|
25
|
+
METHOD: 2,
|
|
26
|
+
STRING: 3,
|
|
27
|
+
NUMBER: 4,
|
|
28
|
+
COMMENT: 5
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const KEYWORDS = {
|
|
32
|
+
javascript: new Set([
|
|
33
|
+
'const',
|
|
34
|
+
'let',
|
|
35
|
+
'var',
|
|
36
|
+
'function',
|
|
37
|
+
'async',
|
|
38
|
+
'await',
|
|
39
|
+
'return',
|
|
40
|
+
'if',
|
|
41
|
+
'else',
|
|
42
|
+
'for',
|
|
43
|
+
'while',
|
|
44
|
+
'do',
|
|
45
|
+
'switch',
|
|
46
|
+
'case',
|
|
47
|
+
'break',
|
|
48
|
+
'continue',
|
|
49
|
+
'new',
|
|
50
|
+
'class',
|
|
51
|
+
'extends',
|
|
52
|
+
'import',
|
|
53
|
+
'export',
|
|
54
|
+
'default',
|
|
55
|
+
'try',
|
|
56
|
+
'catch',
|
|
57
|
+
'finally',
|
|
58
|
+
'throw',
|
|
59
|
+
'typeof',
|
|
60
|
+
'instanceof',
|
|
61
|
+
'in',
|
|
62
|
+
'of',
|
|
63
|
+
'null',
|
|
64
|
+
'undefined',
|
|
65
|
+
'true',
|
|
66
|
+
'false',
|
|
67
|
+
'this',
|
|
68
|
+
'super',
|
|
69
|
+
'delete',
|
|
70
|
+
'void',
|
|
71
|
+
'yield',
|
|
72
|
+
'static',
|
|
73
|
+
'get',
|
|
74
|
+
'set',
|
|
75
|
+
'from',
|
|
76
|
+
'as'
|
|
77
|
+
]),
|
|
78
|
+
typescript: new Set([
|
|
79
|
+
'const',
|
|
80
|
+
'let',
|
|
81
|
+
'var',
|
|
82
|
+
'function',
|
|
83
|
+
'async',
|
|
84
|
+
'await',
|
|
85
|
+
'return',
|
|
86
|
+
'if',
|
|
87
|
+
'else',
|
|
88
|
+
'for',
|
|
89
|
+
'while',
|
|
90
|
+
'do',
|
|
91
|
+
'switch',
|
|
92
|
+
'case',
|
|
93
|
+
'break',
|
|
94
|
+
'continue',
|
|
95
|
+
'new',
|
|
96
|
+
'class',
|
|
97
|
+
'extends',
|
|
98
|
+
'import',
|
|
99
|
+
'export',
|
|
100
|
+
'default',
|
|
101
|
+
'try',
|
|
102
|
+
'catch',
|
|
103
|
+
'finally',
|
|
104
|
+
'throw',
|
|
105
|
+
'typeof',
|
|
106
|
+
'instanceof',
|
|
107
|
+
'in',
|
|
108
|
+
'of',
|
|
109
|
+
'null',
|
|
110
|
+
'undefined',
|
|
111
|
+
'true',
|
|
112
|
+
'false',
|
|
113
|
+
'this',
|
|
114
|
+
'super',
|
|
115
|
+
'delete',
|
|
116
|
+
'void',
|
|
117
|
+
'yield',
|
|
118
|
+
'static',
|
|
119
|
+
'get',
|
|
120
|
+
'set',
|
|
121
|
+
'from',
|
|
122
|
+
'as',
|
|
123
|
+
'type',
|
|
124
|
+
'interface',
|
|
125
|
+
'enum',
|
|
126
|
+
'namespace',
|
|
127
|
+
'declare',
|
|
128
|
+
'abstract',
|
|
129
|
+
'implements',
|
|
130
|
+
'readonly',
|
|
131
|
+
'private',
|
|
132
|
+
'protected',
|
|
133
|
+
'public',
|
|
134
|
+
'any',
|
|
135
|
+
'never',
|
|
136
|
+
'unknown',
|
|
137
|
+
'string',
|
|
138
|
+
'number',
|
|
139
|
+
'boolean'
|
|
140
|
+
]),
|
|
141
|
+
python: new Set([
|
|
142
|
+
'def',
|
|
143
|
+
'class',
|
|
144
|
+
'import',
|
|
145
|
+
'from',
|
|
146
|
+
'as',
|
|
147
|
+
'return',
|
|
148
|
+
'if',
|
|
149
|
+
'elif',
|
|
150
|
+
'else',
|
|
151
|
+
'for',
|
|
152
|
+
'while',
|
|
153
|
+
'break',
|
|
154
|
+
'continue',
|
|
155
|
+
'pass',
|
|
156
|
+
'try',
|
|
157
|
+
'except',
|
|
158
|
+
'finally',
|
|
159
|
+
'raise',
|
|
160
|
+
'with',
|
|
161
|
+
'lambda',
|
|
162
|
+
'and',
|
|
163
|
+
'or',
|
|
164
|
+
'not',
|
|
165
|
+
'in',
|
|
166
|
+
'is',
|
|
167
|
+
'None',
|
|
168
|
+
'True',
|
|
169
|
+
'False',
|
|
170
|
+
'global',
|
|
171
|
+
'nonlocal',
|
|
172
|
+
'del',
|
|
173
|
+
'yield',
|
|
174
|
+
'async',
|
|
175
|
+
'await'
|
|
176
|
+
]),
|
|
177
|
+
java: new Set([
|
|
178
|
+
'class',
|
|
179
|
+
'interface',
|
|
180
|
+
'enum',
|
|
181
|
+
'extends',
|
|
182
|
+
'implements',
|
|
183
|
+
'import',
|
|
184
|
+
'package',
|
|
185
|
+
'public',
|
|
186
|
+
'private',
|
|
187
|
+
'protected',
|
|
188
|
+
'static',
|
|
189
|
+
'final',
|
|
190
|
+
'abstract',
|
|
191
|
+
'void',
|
|
192
|
+
'new',
|
|
193
|
+
'return',
|
|
194
|
+
'if',
|
|
195
|
+
'else',
|
|
196
|
+
'for',
|
|
197
|
+
'while',
|
|
198
|
+
'do',
|
|
199
|
+
'switch',
|
|
200
|
+
'case',
|
|
201
|
+
'break',
|
|
202
|
+
'continue',
|
|
203
|
+
'try',
|
|
204
|
+
'catch',
|
|
205
|
+
'finally',
|
|
206
|
+
'throw',
|
|
207
|
+
'throws',
|
|
208
|
+
'this',
|
|
209
|
+
'super',
|
|
210
|
+
'null',
|
|
211
|
+
'true',
|
|
212
|
+
'false',
|
|
213
|
+
'int',
|
|
214
|
+
'long',
|
|
215
|
+
'float',
|
|
216
|
+
'double',
|
|
217
|
+
'boolean',
|
|
218
|
+
'char',
|
|
219
|
+
'byte',
|
|
220
|
+
'short',
|
|
221
|
+
'String'
|
|
222
|
+
]),
|
|
223
|
+
go: new Set([
|
|
224
|
+
'func',
|
|
225
|
+
'package',
|
|
226
|
+
'import',
|
|
227
|
+
'var',
|
|
228
|
+
'const',
|
|
229
|
+
'type',
|
|
230
|
+
'struct',
|
|
231
|
+
'interface',
|
|
232
|
+
'return',
|
|
233
|
+
'if',
|
|
234
|
+
'else',
|
|
235
|
+
'for',
|
|
236
|
+
'range',
|
|
237
|
+
'switch',
|
|
238
|
+
'case',
|
|
239
|
+
'default',
|
|
240
|
+
'break',
|
|
241
|
+
'continue',
|
|
242
|
+
'go',
|
|
243
|
+
'defer',
|
|
244
|
+
'select',
|
|
245
|
+
'chan',
|
|
246
|
+
'map',
|
|
247
|
+
'make',
|
|
248
|
+
'new',
|
|
249
|
+
'nil',
|
|
250
|
+
'true',
|
|
251
|
+
'false',
|
|
252
|
+
'len',
|
|
253
|
+
'cap',
|
|
254
|
+
'append',
|
|
255
|
+
'copy',
|
|
256
|
+
'close',
|
|
257
|
+
'delete',
|
|
258
|
+
'panic',
|
|
259
|
+
'recover'
|
|
260
|
+
]),
|
|
261
|
+
rust: new Set([
|
|
262
|
+
'fn',
|
|
263
|
+
'let',
|
|
264
|
+
'mut',
|
|
265
|
+
'const',
|
|
266
|
+
'static',
|
|
267
|
+
'struct',
|
|
268
|
+
'enum',
|
|
269
|
+
'impl',
|
|
270
|
+
'trait',
|
|
271
|
+
'use',
|
|
272
|
+
'mod',
|
|
273
|
+
'pub',
|
|
274
|
+
'priv',
|
|
275
|
+
'crate',
|
|
276
|
+
'super',
|
|
277
|
+
'self',
|
|
278
|
+
'return',
|
|
279
|
+
'if',
|
|
280
|
+
'else',
|
|
281
|
+
'match',
|
|
282
|
+
'for',
|
|
283
|
+
'while',
|
|
284
|
+
'loop',
|
|
285
|
+
'break',
|
|
286
|
+
'continue',
|
|
287
|
+
'in',
|
|
288
|
+
'as',
|
|
289
|
+
'ref',
|
|
290
|
+
'true',
|
|
291
|
+
'false',
|
|
292
|
+
'None',
|
|
293
|
+
'Some',
|
|
294
|
+
'Ok',
|
|
295
|
+
'Err',
|
|
296
|
+
'async',
|
|
297
|
+
'await',
|
|
298
|
+
'move',
|
|
299
|
+
'dyn',
|
|
300
|
+
'where',
|
|
301
|
+
'type',
|
|
302
|
+
'unsafe',
|
|
303
|
+
'extern'
|
|
304
|
+
]),
|
|
305
|
+
php: new Set([
|
|
306
|
+
'function',
|
|
307
|
+
'class',
|
|
308
|
+
'interface',
|
|
309
|
+
'extends',
|
|
310
|
+
'implements',
|
|
311
|
+
'namespace',
|
|
312
|
+
'use',
|
|
313
|
+
'return',
|
|
314
|
+
'if',
|
|
315
|
+
'elseif',
|
|
316
|
+
'else',
|
|
317
|
+
'for',
|
|
318
|
+
'foreach',
|
|
319
|
+
'while',
|
|
320
|
+
'do',
|
|
321
|
+
'switch',
|
|
322
|
+
'case',
|
|
323
|
+
'break',
|
|
324
|
+
'continue',
|
|
325
|
+
'try',
|
|
326
|
+
'catch',
|
|
327
|
+
'finally',
|
|
328
|
+
'throw',
|
|
329
|
+
'new',
|
|
330
|
+
'null',
|
|
331
|
+
'true',
|
|
332
|
+
'false',
|
|
333
|
+
'echo',
|
|
334
|
+
'print',
|
|
335
|
+
'var',
|
|
336
|
+
'public',
|
|
337
|
+
'private',
|
|
338
|
+
'protected',
|
|
339
|
+
'static',
|
|
340
|
+
'abstract',
|
|
341
|
+
'final',
|
|
342
|
+
'require',
|
|
343
|
+
'include'
|
|
344
|
+
]),
|
|
345
|
+
ruby: new Set([
|
|
346
|
+
'def',
|
|
347
|
+
'class',
|
|
348
|
+
'module',
|
|
349
|
+
'end',
|
|
350
|
+
'do',
|
|
351
|
+
'if',
|
|
352
|
+
'elsif',
|
|
353
|
+
'else',
|
|
354
|
+
'unless',
|
|
355
|
+
'case',
|
|
356
|
+
'when',
|
|
357
|
+
'for',
|
|
358
|
+
'while',
|
|
359
|
+
'until',
|
|
360
|
+
'begin',
|
|
361
|
+
'rescue',
|
|
362
|
+
'ensure',
|
|
363
|
+
'raise',
|
|
364
|
+
'return',
|
|
365
|
+
'yield',
|
|
366
|
+
'self',
|
|
367
|
+
'nil',
|
|
368
|
+
'true',
|
|
369
|
+
'false',
|
|
370
|
+
'require',
|
|
371
|
+
'include',
|
|
372
|
+
'extend',
|
|
373
|
+
'attr_accessor',
|
|
374
|
+
'attr_reader',
|
|
375
|
+
'attr_writer'
|
|
376
|
+
]),
|
|
377
|
+
css: new Set(['@media', '@keyframes', '@import', '@font-face', '@charset', '!important'])
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* tokenizeCode(code, language) → Array<{ highlightType, codeContent }>
|
|
382
|
+
* Hasilnya langsung bisa dipakai sebagai `code` di richResponse item.
|
|
383
|
+
*/
|
|
384
|
+
function tokenizeCode(code, language = 'javascript') {
|
|
385
|
+
const lang = String(language || 'text')
|
|
386
|
+
.toLowerCase()
|
|
387
|
+
.trim()
|
|
388
|
+
const keywords = KEYWORDS[lang] || new Set()
|
|
389
|
+
const text = String(code || '')
|
|
390
|
+
const tokens = []
|
|
391
|
+
|
|
392
|
+
// Regex per token type
|
|
393
|
+
// Order matters: comment > string > number > keyword > method > default
|
|
394
|
+
const patterns = [
|
|
395
|
+
// Single-line comment
|
|
396
|
+
{ type: HIGHLIGHT.COMMENT, regex: /(\/\/[^\n]*|#[^\n]*)/ },
|
|
397
|
+
// Multi-line comment
|
|
398
|
+
{ type: HIGHLIGHT.COMMENT, regex: /(\/\*[\s\S]*?\*\/)/ },
|
|
399
|
+
// String (double, single, backtick)
|
|
400
|
+
{
|
|
401
|
+
type: HIGHLIGHT.STRING,
|
|
402
|
+
regex: /("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|`(?:[^`\\]|\\.)*`)/
|
|
403
|
+
},
|
|
404
|
+
// Number
|
|
405
|
+
{ type: HIGHLIGHT.NUMBER, regex: /\b(\d+(?:\.\d+)?(?:[eE][+-]?\d+)?)\b/ },
|
|
406
|
+
// Keyword
|
|
407
|
+
{ type: HIGHLIGHT.KEYWORD, regex: new RegExp(`\\b(${[...keywords].join('|')})\\b`) },
|
|
408
|
+
// Method call (word followed by open paren)
|
|
409
|
+
{ type: HIGHLIGHT.METHOD, regex: /\b([a-zA-Z_$][a-zA-Z0-9_$]*)(?=\s*\()/ }
|
|
410
|
+
]
|
|
411
|
+
|
|
412
|
+
let remaining = text
|
|
413
|
+
while (remaining.length > 0) {
|
|
414
|
+
let earliest = null
|
|
415
|
+
let earliestIndex = Infinity
|
|
416
|
+
let earliestMatch = null
|
|
417
|
+
|
|
418
|
+
for (const pat of patterns) {
|
|
419
|
+
const match = pat.regex.exec(remaining)
|
|
420
|
+
if (match && match.index < earliestIndex) {
|
|
421
|
+
earliestIndex = match.index
|
|
422
|
+
earliest = pat
|
|
423
|
+
earliestMatch = match
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
if (!earliest || earliestIndex === Infinity) {
|
|
428
|
+
// No more tokens, push rest as default
|
|
429
|
+
if (remaining) tokens.push({ highlightType: HIGHLIGHT.DEFAULT, codeContent: remaining })
|
|
430
|
+
break
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// Push text before match as default
|
|
434
|
+
if (earliestIndex > 0) {
|
|
435
|
+
tokens.push({
|
|
436
|
+
highlightType: HIGHLIGHT.DEFAULT,
|
|
437
|
+
codeContent: remaining.slice(0, earliestIndex)
|
|
438
|
+
})
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
tokens.push({ highlightType: earliest.type, codeContent: earliestMatch[0] })
|
|
442
|
+
remaining = remaining.slice(earliestIndex + earliestMatch[0].length)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
// Merge consecutive same-type tokens & remove empty
|
|
446
|
+
const merged = []
|
|
447
|
+
for (const t of tokens) {
|
|
448
|
+
if (!t.codeContent) continue
|
|
449
|
+
const last = merged[merged.length - 1]
|
|
450
|
+
if (last && last.highlightType === t.highlightType) {
|
|
451
|
+
last.codeContent += t.codeContent
|
|
452
|
+
} else {
|
|
453
|
+
merged.push({ ...t })
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
return merged.length > 0 ? merged : [{ highlightType: HIGHLIGHT.DEFAULT, codeContent: text }]
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
exports.tokenizeCode = tokenizeCode
|
|
461
|
+
exports.HIGHLIGHT_TYPE = HIGHLIGHT
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { AnyMessageContent, WAMessage } from '../Types'
|
|
2
|
+
|
|
3
|
+
/** A single scheduled message entry */
|
|
4
|
+
export interface ScheduledMessage {
|
|
5
|
+
/** Unique ID (e.g. `sched_1712400000000_a3f2b1c`) */
|
|
6
|
+
id: string
|
|
7
|
+
/** Recipient JID */
|
|
8
|
+
jid: string
|
|
9
|
+
/** Message content */
|
|
10
|
+
content: AnyMessageContent
|
|
11
|
+
/** When the message will be sent */
|
|
12
|
+
scheduledTime: Date
|
|
13
|
+
/** When the entry was created */
|
|
14
|
+
createdAt: Date
|
|
15
|
+
/** Current status */
|
|
16
|
+
status: 'pending' | 'sent' | 'failed' | 'cancelled'
|
|
17
|
+
/** Error message if status is 'failed' */
|
|
18
|
+
error?: string
|
|
19
|
+
/** WhatsApp message ID after successful send */
|
|
20
|
+
messageId?: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** Options for the scheduler */
|
|
24
|
+
export interface SchedulerOptions {
|
|
25
|
+
/** Maximum number of pending messages allowed in the queue (default: 1000) */
|
|
26
|
+
maxQueue?: number
|
|
27
|
+
/** How often (ms) the queue is checked for due messages (default: 1000) */
|
|
28
|
+
checkInterval?: number
|
|
29
|
+
/** Called when a message is successfully sent */
|
|
30
|
+
onSent?: (scheduled: ScheduledMessage, message: WAMessage) => void
|
|
31
|
+
/** Called when a message fails to send */
|
|
32
|
+
onFailed?: (scheduled: ScheduledMessage, error: Error) => void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The function signature expected by the scheduler to send messages */
|
|
36
|
+
export type SendMessageFunction = (jid: string, content: AnyMessageContent) => Promise<WAMessage | undefined>
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* In-memory message scheduler.
|
|
40
|
+
* Auto-starts the internal timer when messages are scheduled,
|
|
41
|
+
* and auto-stops when the queue becomes empty.
|
|
42
|
+
*/
|
|
43
|
+
export declare class MessageScheduler {
|
|
44
|
+
constructor(sendMessage: SendMessageFunction, options?: SchedulerOptions)
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Schedule a message to be sent at a specific Date.
|
|
48
|
+
* @throws if `scheduledTime` is not in the future
|
|
49
|
+
* @throws if the queue is full
|
|
50
|
+
*/
|
|
51
|
+
schedule(jid: string, content: AnyMessageContent, scheduledTime: Date): ScheduledMessage
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Schedule a message with a delay from now.
|
|
55
|
+
* @param delayMs - Delay in milliseconds (e.g. `30 * 60 * 1000` = 30 minutes)
|
|
56
|
+
*/
|
|
57
|
+
scheduleDelay(jid: string, content: AnyMessageContent, delayMs: number): ScheduledMessage
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Cancel a pending message by ID.
|
|
61
|
+
* @returns `true` if the message was found and cancelled
|
|
62
|
+
*/
|
|
63
|
+
cancel(id: string): boolean
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* Cancel all pending messages for a specific JID.
|
|
67
|
+
* @returns number of messages cancelled
|
|
68
|
+
*/
|
|
69
|
+
cancelForJid(jid: string): number
|
|
70
|
+
|
|
71
|
+
/** Get all currently pending scheduled messages */
|
|
72
|
+
getPending(): ScheduledMessage[]
|
|
73
|
+
|
|
74
|
+
/** Get a specific scheduled message by ID */
|
|
75
|
+
get(id: string): ScheduledMessage | undefined
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Clear all pending messages and stop the timer.
|
|
79
|
+
* @returns number of entries cleared
|
|
80
|
+
*/
|
|
81
|
+
clearAll(): number
|
|
82
|
+
|
|
83
|
+
/** Stop the internal check timer. Already-queued messages are preserved. */
|
|
84
|
+
stop(): void
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* (Re)start the timer. Only has effect if the queue is non-empty.
|
|
88
|
+
* The scheduler auto-starts on `schedule()` / `scheduleDelay()`, so you
|
|
89
|
+
* only need this after an explicit `stop()`.
|
|
90
|
+
*/
|
|
91
|
+
start(): void
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Create a ready-to-use MessageScheduler.
|
|
96
|
+
*
|
|
97
|
+
* @example
|
|
98
|
+
* ```ts
|
|
99
|
+
* import { createMessageScheduler } from '@innovatorssoft/baileys'
|
|
100
|
+
*
|
|
101
|
+
* const scheduler = createMessageScheduler(
|
|
102
|
+
* (jid, content) => sock.sendMessage(jid, content),
|
|
103
|
+
* {
|
|
104
|
+
* onSent: (s, msg) => console.log(`Sent to ${s.jid}`),
|
|
105
|
+
* onFailed: (s, err) => console.error(`Failed: ${err.message}`)
|
|
106
|
+
* }
|
|
107
|
+
* )
|
|
108
|
+
*
|
|
109
|
+
* // Schedule at a specific time
|
|
110
|
+
* const entry = scheduler.schedule(jid, { text: 'Happy Birthday! 🎂' }, new Date('2026-12-25T09:00:00'))
|
|
111
|
+
*
|
|
112
|
+
* // Schedule with delay (30 minutes from now)
|
|
113
|
+
* scheduler.scheduleDelay(jid, { text: 'Reminder!' }, 30 * 60 * 1000)
|
|
114
|
+
*
|
|
115
|
+
* // Cancel one
|
|
116
|
+
* scheduler.cancel(entry.id)
|
|
117
|
+
*
|
|
118
|
+
* // Cancel all for a JID
|
|
119
|
+
* scheduler.cancelForJid(jid)
|
|
120
|
+
*
|
|
121
|
+
* // View pending
|
|
122
|
+
* const pending = scheduler.getPending()
|
|
123
|
+
*
|
|
124
|
+
* // Stop/start
|
|
125
|
+
* scheduler.stop()
|
|
126
|
+
* scheduler.start()
|
|
127
|
+
*
|
|
128
|
+
* // Wipe everything
|
|
129
|
+
* scheduler.clearAll()
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export declare const createMessageScheduler: (
|
|
133
|
+
sendMessage: SendMessageFunction,
|
|
134
|
+
options?: SchedulerOptions
|
|
135
|
+
) => MessageScheduler
|