@open-wa/wa-automate 4.76.0 → 5.0.0-alpha.2

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 (125) hide show
  1. package/README.md +14 -165
  2. package/dist/cli-runtime-B7_3MM0c.cjs +798 -0
  3. package/dist/cli-runtime-B7_3MM0c.cjs.map +1 -0
  4. package/dist/cli-runtime-CmpYxFCk.d.cts +31 -0
  5. package/dist/cli-runtime-CmpYxFCk.d.cts.map +1 -0
  6. package/dist/cli.cjs +17 -0
  7. package/dist/cli.cjs.map +1 -0
  8. package/dist/cli.d.cts +2 -0
  9. package/dist/index.cjs +224 -0
  10. package/dist/index.cjs.map +1 -0
  11. package/dist/index.d.cts +81 -0
  12. package/dist/index.d.cts.map +1 -0
  13. package/package.json +34 -177
  14. package/CNAME +0 -1
  15. package/_tsconfig.docs.json +0 -140
  16. package/bin/config-schema.json +0 -1
  17. package/bin/oas-type-schemas.json +0 -1
  18. package/bin/server.js +0 -45
  19. package/build/build-config-json-for-bin.ts +0 -56
  20. package/build/generate-oas-types.ts +0 -31
  21. package/dist/api/Client.d.ts +0 -2255
  22. package/dist/api/Client.js +0 -4358
  23. package/dist/api/functions/exposed.enum.d.ts +0 -7
  24. package/dist/api/functions/exposed.enum.js +0 -11
  25. package/dist/api/model/aliases.d.ts +0 -110
  26. package/dist/api/model/aliases.js +0 -3
  27. package/dist/api/model/button.d.ts +0 -24
  28. package/dist/api/model/button.js +0 -2
  29. package/dist/api/model/call.d.ts +0 -51
  30. package/dist/api/model/call.js +0 -18
  31. package/dist/api/model/chat.d.ts +0 -221
  32. package/dist/api/model/chat.js +0 -52
  33. package/dist/api/model/config.d.ts +0 -836
  34. package/dist/api/model/config.js +0 -111
  35. package/dist/api/model/contact.d.ts +0 -143
  36. package/dist/api/model/contact.js +0 -2
  37. package/dist/api/model/errors.d.ts +0 -90
  38. package/dist/api/model/errors.js +0 -117
  39. package/dist/api/model/events.d.ts +0 -120
  40. package/dist/api/model/events.js +0 -127
  41. package/dist/api/model/group-metadata.d.ts +0 -124
  42. package/dist/api/model/group-metadata.js +0 -25
  43. package/dist/api/model/id.d.ts +0 -5
  44. package/dist/api/model/id.js +0 -2
  45. package/dist/api/model/index.d.ts +0 -110
  46. package/dist/api/model/index.js +0 -128
  47. package/dist/api/model/label.d.ts +0 -24
  48. package/dist/api/model/label.js +0 -2
  49. package/dist/api/model/media.d.ts +0 -93
  50. package/dist/api/model/media.js +0 -12
  51. package/dist/api/model/message.d.ts +0 -422
  52. package/dist/api/model/message.js +0 -40
  53. package/dist/api/model/product.d.ts +0 -141
  54. package/dist/api/model/product.js +0 -2
  55. package/dist/api/model/reactions.d.ts +0 -76
  56. package/dist/api/model/reactions.js +0 -2
  57. package/dist/api/model/sessionInfo.d.ts +0 -77
  58. package/dist/api/model/sessionInfo.js +0 -2
  59. package/dist/build/build-postman.d.ts +0 -1
  60. package/dist/build/build-postman.js +0 -262
  61. package/dist/cli/cli-options.d.ts +0 -9
  62. package/dist/cli/cli-options.js +0 -289
  63. package/dist/cli/collections.d.ts +0 -2
  64. package/dist/cli/collections.js +0 -251
  65. package/dist/cli/file-utils.d.ts +0 -1
  66. package/dist/cli/file-utils.js +0 -71
  67. package/dist/cli/index.d.ts +0 -1
  68. package/dist/cli/index.js +0 -231
  69. package/dist/cli/integrations/chatwoot.d.ts +0 -49
  70. package/dist/cli/integrations/chatwoot.js +0 -672
  71. package/dist/cli/integrations/cloudflare.d.ts +0 -6
  72. package/dist/cli/integrations/cloudflare.js +0 -76
  73. package/dist/cli/logo.d.ts +0 -1
  74. package/dist/cli/logo.js +0 -49
  75. package/dist/cli/server.d.ts +0 -24
  76. package/dist/cli/server.js +0 -540
  77. package/dist/cli/setup.d.ts +0 -30
  78. package/dist/cli/setup.js +0 -308
  79. package/dist/config/puppeteer.config.d.ts +0 -11
  80. package/dist/config/puppeteer.config.js +0 -65
  81. package/dist/controllers/auth.d.ts +0 -36
  82. package/dist/controllers/auth.js +0 -322
  83. package/dist/controllers/browser.d.ts +0 -17
  84. package/dist/controllers/browser.js +0 -603
  85. package/dist/controllers/events.d.ts +0 -82
  86. package/dist/controllers/events.js +0 -173
  87. package/dist/controllers/init_patch.d.ts +0 -13
  88. package/dist/controllers/init_patch.js +0 -42
  89. package/dist/controllers/initializer.d.ts +0 -22
  90. package/dist/controllers/initializer.js +0 -511
  91. package/dist/controllers/launch_checks.d.ts +0 -8
  92. package/dist/controllers/launch_checks.js +0 -130
  93. package/dist/controllers/patch_manager.d.ts +0 -37
  94. package/dist/controllers/patch_manager.js +0 -231
  95. package/dist/controllers/popup/index.d.ts +0 -3
  96. package/dist/controllers/popup/index.html +0 -168
  97. package/dist/controllers/popup/index.js +0 -148
  98. package/dist/controllers/script_preloader.d.ts +0 -17
  99. package/dist/controllers/script_preloader.js +0 -88
  100. package/dist/index.d.ts +0 -13
  101. package/dist/index.js +0 -36
  102. package/dist/lib/README.md +0 -5
  103. package/dist/lib/base64.js +0 -1
  104. package/dist/lib/hash.js +0 -1
  105. package/dist/lib/jsSha.min.js +0 -1
  106. package/dist/lib/launch.js +0 -1
  107. package/dist/lib/qr.min.js +0 -1
  108. package/dist/lib/wapi.js +0 -2163
  109. package/dist/logging/custom_transport.d.ts +0 -9
  110. package/dist/logging/custom_transport.js +0 -35
  111. package/dist/logging/logging.d.ts +0 -50
  112. package/dist/logging/logging.js +0 -196
  113. package/dist/structures/Collector.d.ts +0 -202
  114. package/dist/structures/Collector.js +0 -391
  115. package/dist/structures/Dialog.d.ts +0 -55
  116. package/dist/structures/Dialog.js +0 -21
  117. package/dist/structures/MessageCollector.d.ts +0 -78
  118. package/dist/structures/MessageCollector.js +0 -145
  119. package/dist/structures/preProcessors.d.ts +0 -58
  120. package/dist/structures/preProcessors.js +0 -181
  121. package/dist/utils/pid_utils.d.ts +0 -1
  122. package/dist/utils/pid_utils.js +0 -26
  123. package/dist/utils/tools.d.ts +0 -152
  124. package/dist/utils/tools.js +0 -494
  125. package/tos.md +0 -77
@@ -1,391 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
12
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
13
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
14
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
15
- return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
16
- function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
17
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
18
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
19
- function fulfill(value) { resume("next", value); }
20
- function reject(value) { resume("throw", value); }
21
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
22
- };
23
- Object.defineProperty(exports, "__esModule", { value: true });
24
- exports.Collector = exports.Collection = void 0;
25
- /* eslint-disable @typescript-eslint/no-unused-vars */
26
- /**
27
- * This code is a copy of the Discord Collector: https://github.com/discordjs/discord.js/blob/stable/src/structures/interfaces/Collector.js
28
- *
29
- * Please see: https://discord.js.org/#/docs/main/stable/class/Collector
30
- */
31
- // import { EventEmitter2 } from 'eventemitter2';
32
- const collection_1 = require("@discordjs/collection");
33
- const events_1 = require("events");
34
- class Collection extends collection_1.Collection {
35
- toJSON() {
36
- return this.map((e) => (typeof e.toJSON === 'function' ? e.toJSON() : e));
37
- }
38
- }
39
- exports.Collection = Collection;
40
- /**
41
- * Abstract class for defining a new Collector.
42
- * @abstract
43
- */
44
- class Collector extends events_1.EventEmitter {
45
- constructor(filter, options = {}) {
46
- super();
47
- /**
48
- * Timeouts set by {@link BaseClient#setTimeout} that are still active
49
- * @type {Set<Timeout>}
50
- * @private
51
- */
52
- this._timeouts = new Set();
53
- /**
54
- * Intervals set by {@link BaseClient#setInterval} that are still active
55
- * @type {Set<Timeout>}
56
- * @private
57
- */
58
- this._intervals = new Set();
59
- /**
60
- * Intervals set by {@link BaseClient#setImmediate} that are still active
61
- * @type {Set<Immediate>}
62
- * @private
63
- */
64
- this._immediates = new Set();
65
- /**
66
- * The filter applied to this collector
67
- * @type {CollectorFilter}
68
- */
69
- this.filter = filter;
70
- /**
71
- * The options of this collector
72
- * @type {CollectorOptions}
73
- */
74
- this.options = options;
75
- /**
76
- * The items collected by this collector
77
- * @type {Collection}
78
- */
79
- this.collected = new Collection();
80
- /**
81
- * Whether this collector has finished collecting
82
- * @type {boolean}
83
- */
84
- this.ended = false;
85
- /**
86
- * Timeout for cleanup
87
- * @type {?Timeout}
88
- * @private
89
- */
90
- this._timeout = null;
91
- /**
92
- * Timeout for cleanup due to inactivity
93
- * @type {?Timeout}
94
- * @private
95
- */
96
- this._idletimeout = null;
97
- this.handleCollect = this.handleCollect.bind(this);
98
- this.handleDispose = this.handleDispose.bind(this);
99
- if (options.time)
100
- this._timeout = this.setTimeout(() => this.stop('time'), options.time);
101
- if (options.idle)
102
- this._idletimeout = this.setTimeout(() => this.stop('idle'), options.idle);
103
- }
104
- /**
105
- * Call this to handle an event as a collectable element. Accepts any event data as parameters.
106
- * @param {...*} args The arguments emitted by the listener
107
- * @emits Collector#collect
108
- */
109
- handleCollect(...args) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const collect = this.collect(...args);
112
- if (collect && (yield this.filter(...args, this.collected))) {
113
- this.collected.set(collect, args[0]);
114
- /**
115
- * Emitted whenever an element is collected.
116
- * @event Collector#collect
117
- * @param {...*} args The arguments emitted by the listener
118
- */
119
- this.emit('collect', ...args);
120
- if (this._idletimeout) {
121
- this.clearTimeout(this._idletimeout);
122
- this._idletimeout = this.setTimeout(() => this.stop('idle'), this.options.idle);
123
- }
124
- }
125
- this.checkEnd();
126
- });
127
- }
128
- /**
129
- * Call this to remove an element from the collection. Accepts any event data as parameters.
130
- * @param {...*} args The arguments emitted by the listener
131
- * @emits Collector#dispose
132
- */
133
- handleDispose(...args) {
134
- return __awaiter(this, void 0, void 0, function* () {
135
- if (!this.options.dispose)
136
- return;
137
- const dispose = this.dispose(...args);
138
- if (!dispose || !(yield this.filter(...args)) || !this.collected.has(dispose))
139
- return;
140
- this.collected.delete(dispose);
141
- /**
142
- * Emitted whenever an element is disposed of.
143
- * @event Collector#dispose
144
- * @param {...*} args The arguments emitted by the listener
145
- */
146
- this.emit('dispose', ...args);
147
- this.checkEnd();
148
- });
149
- }
150
- /**
151
- * Returns a promise that resolves with the next collected element;
152
- * rejects with collected elements if the collector finishes without receiving a next element
153
- * @type {Promise}
154
- * @readonly
155
- */
156
- get next() {
157
- return new Promise((resolve, reject) => {
158
- if (this.ended) {
159
- reject(this.collected);
160
- return;
161
- }
162
- const cleanup = () => {
163
- this.removeListener('collect', onCollect);
164
- this.removeListener('end', onEnd);
165
- };
166
- const onCollect = item => {
167
- cleanup();
168
- resolve(item);
169
- };
170
- const onEnd = () => {
171
- cleanup();
172
- reject(this.collected); // eslint-disable-line prefer-promise-reject-errors
173
- };
174
- this.on('collect', onCollect);
175
- this.on('end', onEnd);
176
- });
177
- }
178
- /**
179
- * Stops this collector and emits the `end` event.
180
- * @param {string} [reason='user'] The reason this collector is ending
181
- * @emits Collector#end
182
- */
183
- stop(reason = 'user') {
184
- if (this.ended)
185
- return;
186
- if (this._timeout) {
187
- this.clearTimeout(this._timeout);
188
- this._timeout = null;
189
- }
190
- if (this._idletimeout) {
191
- this.clearTimeout(this._idletimeout);
192
- this._idletimeout = null;
193
- }
194
- this.ended = true;
195
- /**
196
- * Emitted when the collector is finished collecting.
197
- * @event Collector#end
198
- * @param {Collection} collected The elements collected by the collector
199
- * @param {string} reason The reason the collector ended
200
- */
201
- this.emit('end', this.collected, reason);
202
- }
203
- /**
204
- * Resets the collectors timeout and idle timer.
205
- * @param {Object} [options] Options
206
- * @param {number} [options.time] How long to run the collector for in milliseconds
207
- * @param {number} [options.idle] How long to stop the collector after inactivity in milliseconds
208
- */
209
- resetTimer({ time, idle } = {
210
- time: null,
211
- idle: null
212
- }) {
213
- if (this._timeout) {
214
- this.clearTimeout(this._timeout);
215
- this._timeout = this.setTimeout(() => this.stop('time'), time || this.options.time);
216
- }
217
- if (this._idletimeout) {
218
- this.clearTimeout(this._idletimeout);
219
- this._idletimeout = this.setTimeout(() => this.stop('idle'), idle || this.options.idle);
220
- }
221
- }
222
- /**
223
- * Checks whether the collector should end, and if so, ends it.
224
- */
225
- checkEnd() {
226
- const reason = this.endReason();
227
- if (reason)
228
- this.stop(reason);
229
- }
230
- /**
231
- * Allows collectors to be consumed with for-await-of loops
232
- * @see {@link https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of}
233
- */
234
- [Symbol.asyncIterator]() {
235
- return __asyncGenerator(this, arguments, function* _a() {
236
- const queue = [];
237
- const onCollect = item => queue.push(item);
238
- this.on('collect', onCollect);
239
- try {
240
- while (queue.length || !this.ended) {
241
- if (queue.length) {
242
- yield yield __await(queue.shift());
243
- }
244
- else {
245
- // eslint-disable-next-line no-await-in-loop
246
- yield __await(new Promise(resolve => {
247
- const tick = () => {
248
- this.removeListener('collect', tick);
249
- this.removeListener('end', tick);
250
- return resolve(true);
251
- };
252
- this.on('collect', tick);
253
- this.on('end', tick);
254
- }));
255
- }
256
- }
257
- }
258
- finally {
259
- this.removeListener('collect', onCollect);
260
- }
261
- });
262
- }
263
- /* eslint-disable no-empty-function, valid-jsdoc */
264
- /**
265
- * Handles incoming events from the `handleCollect` function. Returns null if the event should not
266
- * be collected, or returns an object describing the data that should be stored.
267
- * @see Collector#handleCollect
268
- * @param {...*} _args Any args the event listener emits
269
- * @returns the id if the object should be collected, if it shouldnt be collected then it will return null or false.
270
- * @abstract
271
- */
272
- collect(...args) {
273
- throw new Error("abstractMethod not implemented");
274
- }
275
- /**
276
- * Handles incoming events from the `handleDispose`. Returns null if the event should not
277
- * be disposed, or returns the key that should be removed.
278
- * @see Collector#handleDispose
279
- * @param {...*} args Any args the event listener emits
280
- * @returns {?*} Key to remove from the collection, if any
281
- * @abstract
282
- */
283
- dispose(...args) {
284
- throw new Error("abstractMethod not implemented");
285
- }
286
- /**
287
- * The reason this collector has ended or will end with.
288
- * @returns {?string} Reason to end the collector, if any
289
- * @abstract
290
- */
291
- endReason(...args) {
292
- throw new Error("abstractMethod not implemented");
293
- }
294
- /**
295
- * Clears a timeout.
296
- * @param {Timeout} timeout Timeout to cancel
297
- */
298
- clearTimeout(timeout) {
299
- clearTimeout(timeout);
300
- this._timeouts.delete(timeout);
301
- }
302
- /**
303
- * Sets an interval that will be automatically cancelled if the client is destroyed.
304
- * @param {Function} fn Function to execute
305
- * @param {number} delay Time to wait between executions (in milliseconds)
306
- * @param {...*} args Arguments for the function
307
- * @returns {Timeout}
308
- */
309
- setInterval(fn, delay, ...args) {
310
- const interval = setInterval(fn, delay, ...args);
311
- this._intervals.add(interval);
312
- return interval;
313
- }
314
- /**
315
- * Clears an interval.
316
- * @param {Timeout} interval Interval to cancel
317
- */
318
- clearInterval(interval) {
319
- clearInterval(interval);
320
- this._intervals.delete(interval);
321
- }
322
- /**
323
- * Sets an immediate that will be automatically cancelled if the client is destroyed.
324
- * @param {Function} fn Function to execute
325
- * @param {...*} args Arguments for the function
326
- * @returns {Immediate}
327
- */
328
- setImmediate(fn, ...args) {
329
- const immediate = setImmediate(fn, ...args);
330
- this._immediates.add(immediate);
331
- return immediate;
332
- }
333
- /**
334
- * Clears an immediate.
335
- * @param {Immediate} immediate Immediate to cancel
336
- */
337
- clearImmediate(immediate) {
338
- clearImmediate(immediate);
339
- this._immediates.delete(immediate);
340
- }
341
- /**
342
- * Increments max listeners by one, if they are not zero.
343
- * @private
344
- */
345
- incrementMaxListeners() {
346
- const maxListeners = this.getMaxListeners();
347
- if (maxListeners !== 0) {
348
- this.setMaxListeners(maxListeners + 1);
349
- }
350
- }
351
- /**
352
- * Decrements max listeners by one, if they are not zero.
353
- * @private
354
- */
355
- decrementMaxListeners() {
356
- const maxListeners = this.getMaxListeners();
357
- if (maxListeners !== 0) {
358
- this.setMaxListeners(maxListeners - 1);
359
- }
360
- }
361
- /**
362
- * Sets a timeout that will be automatically cancelled if the client is destroyed.
363
- * @param {Function} fn Function to execute
364
- * @param {number} delay Time to wait before executing (in milliseconds)
365
- * @param {...*} args Arguments for the function
366
- * @returns {Timeout}
367
- */
368
- setTimeout(fn, delay, ...args) {
369
- const timeout = setTimeout(() => {
370
- fn(...args);
371
- this._timeouts.delete(timeout);
372
- }, delay);
373
- this._timeouts.add(timeout);
374
- return timeout;
375
- }
376
- /**
377
- * Destroys all assets used by the base client.
378
- */
379
- destroy() {
380
- for (const t of this._timeouts)
381
- this.clearTimeout(t);
382
- for (const i of this._intervals)
383
- this.clearInterval(i);
384
- for (const i of this._immediates)
385
- this.clearImmediate(i);
386
- this._timeouts.clear();
387
- this._intervals.clear();
388
- this._immediates.clear();
389
- }
390
- }
391
- exports.Collector = Collector;
@@ -1,55 +0,0 @@
1
- import { Message } from "..";
2
- export interface CurrentDialogProps {
3
- [k: string]: any;
4
- }
5
- export interface DialogState {
6
- currentStep: number;
7
- currentProps: any;
8
- lastInput: any;
9
- isComplete: boolean;
10
- isError: boolean;
11
- errorMessage: string;
12
- }
13
- export interface DialogTemplate {
14
- "dialogId": string;
15
- "privateOnly": boolean;
16
- "identifier": string;
17
- "successMessage": string;
18
- "startMessage": string;
19
- "properties": {
20
- [key: string]: DialogProperty;
21
- };
22
- }
23
- export type CheckFunction = (lastReceivedMessage: Message, currentProps: CurrentDialogProps) => boolean;
24
- export interface DialogProperty {
25
- "order": number;
26
- "key": string;
27
- "prompt": string;
28
- "type": string;
29
- "skipCondition"?: CheckFunction;
30
- "options"?: DialogButtons[] | DialogListMessageSection[];
31
- "validation": DialogValidation[];
32
- }
33
- export interface DialogButtons {
34
- label: string;
35
- value: string;
36
- }
37
- export interface DialogListMessageSection {
38
- title: string;
39
- rows: DialogListMessageRow[];
40
- }
41
- export interface DialogListMessageRow {
42
- title: string;
43
- description: string;
44
- value: string;
45
- }
46
- export interface DialogValidation {
47
- "type": ValidationType;
48
- "value": string | CheckFunction;
49
- "errorMessage": string;
50
- }
51
- export declare enum ValidationType {
52
- REGEX = "regex",
53
- LENGTH = "length",
54
- CHECK = "check"
55
- }
@@ -1,21 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ValidationType = void 0;
4
- var ValidationType;
5
- (function (ValidationType) {
6
- ValidationType["REGEX"] = "regex";
7
- ValidationType["LENGTH"] = "length";
8
- ValidationType["CHECK"] = "check";
9
- })(ValidationType = exports.ValidationType || (exports.ValidationType = {}));
10
- // async function processDialog(dialog: DialogTemplate, chatId: ChatId, client: Client){
11
- // if(dialog.privateOnly && chatId.includes('g')) return;
12
- // const requiredProperties = Object.keys(dialog.properties);
13
- // const requiredPropertiesInOrder = requiredProperties.map(prop=>dialog.properties[prop]).sort((a, b) => a.order - b.order);
14
- // /**
15
- // * Send start dialog message
16
- // */
17
- // await client.sendText(chatId, dialog.startMessage);
18
- // requiredPropertiesInOrder.map((diaProp: DialogProperty) => {
19
- // diaProp.type
20
- // })
21
- // }
@@ -1,78 +0,0 @@
1
- import { EventEmitter2 } from 'eventemitter2';
2
- import { Chat, ChatId, Message, MessageId } from '../api/model';
3
- import { SimpleListener } from '../api/model/events';
4
- import { Collector, CollectorOptions } from './Collector';
5
- /**
6
- * @typedef {CollectorOptions} MessageCollectorOptions
7
- * @property {number} max The maximum amount of messages to collect
8
- * @property {number} maxProcessed The maximum amount of messages to process
9
- */
10
- /**
11
- * Collects messages on a chat.
12
- * Will automatically stop if the chat (`'chatDelete'`) is deleted.
13
- * @extends {Collector}
14
- */
15
- export declare class MessageCollector extends Collector {
16
- chat: ChatId;
17
- received: number;
18
- sessionId: string;
19
- instanceId: string;
20
- ev: EventEmitter2;
21
- /**
22
- * @param {string} sessionId The id of the session
23
- * @param {string} instanceId The id of the current instance of the session (see: client.getInstanceId)
24
- * @param {ChatId} chatId The chat
25
- * @param {CollectorFilter} filter The filter to be applied to this collector
26
- * @param {MessageCollectorOptions} options The options to be applied to this collector
27
- * @param {EventEmitter2} openWaEventEmitter The EventEmitter2 that fires all open-wa events. In local instances of the library, this is the global `ev` object.
28
- * @emits MessageCollector#Message
29
- */
30
- constructor(sessionId: string, instanceId: string, chat: ChatId, filter: (...args: any[]) => boolean | Promise<boolean>, options: CollectorOptions, openWaEventEmitter: EventEmitter2);
31
- /**
32
- * Handles a message for possible collection.
33
- * @param {Message} message The message that could be collected
34
- * @returns {?Snowflake}
35
- * @private
36
- */
37
- collect(message: Message): MessageId;
38
- /**
39
- * Handles a message for possible disposal.
40
- * @param {Message} message The message that could be disposed of
41
- * @returns {?Snowflake}
42
- */
43
- dispose(message: Message): MessageId | null;
44
- /**
45
- * Checks after un/collection to see if the collector is done.
46
- * @returns {?string}
47
- * @private
48
- */
49
- endReason(): string | null;
50
- /**
51
- * Handles checking if the chat has been deleted, and if so, stops the collector with the reason 'chatDelete'.
52
- * @private
53
- * @param {Chat} chat The chat that was deleted
54
- * @returns {void}
55
- */
56
- _handleChatDeletion(chat: Chat): void;
57
- /**
58
- * Handles checking if the chat has been deleted, and if so, stops the collector with the reason 'chatDelete'.
59
- * @private
60
- * @param {Chat} chat The group chat that the host account was removed from
61
- * @returns {void}
62
- */
63
- _handleGroupRemoval(chat: Chat): void;
64
- /**
65
- *
66
- * NOT RELATED TO WA
67
- *
68
- * Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'.
69
- * @private
70
- * @param {Guild} guild The guild that was deleted
71
- * @returns {void}
72
- */
73
- _handleGuildDeletion(guild: string): void;
74
- eventSignature(event: SimpleListener): string;
75
- wrapHandler(handler: (data: any) => any): ({ data }: {
76
- data: any;
77
- }) => any;
78
- }
@@ -1,145 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.MessageCollector = void 0;
4
- const events_1 = require("../api/model/events");
5
- const Collector_1 = require("./Collector");
6
- /**
7
- * @typedef {CollectorOptions} MessageCollectorOptions
8
- * @property {number} max The maximum amount of messages to collect
9
- * @property {number} maxProcessed The maximum amount of messages to process
10
- */
11
- /**
12
- * Collects messages on a chat.
13
- * Will automatically stop if the chat (`'chatDelete'`) is deleted.
14
- * @extends {Collector}
15
- */
16
- class MessageCollector extends Collector_1.Collector {
17
- /**
18
- * @param {string} sessionId The id of the session
19
- * @param {string} instanceId The id of the current instance of the session (see: client.getInstanceId)
20
- * @param {ChatId} chatId The chat
21
- * @param {CollectorFilter} filter The filter to be applied to this collector
22
- * @param {MessageCollectorOptions} options The options to be applied to this collector
23
- * @param {EventEmitter2} openWaEventEmitter The EventEmitter2 that fires all open-wa events. In local instances of the library, this is the global `ev` object.
24
- * @emits MessageCollector#Message
25
- */
26
- constructor(sessionId, instanceId, chat, filter, options = {}, openWaEventEmitter) {
27
- super(filter, options);
28
- this.ev = openWaEventEmitter;
29
- this.sessionId = sessionId;
30
- this.instanceId = instanceId;
31
- /**
32
- * The chat
33
- * @type {TextBasedChannel}
34
- */
35
- this.chat = chat;
36
- /**
37
- * Total number of messages that were received in the chat during message collection
38
- * @type {number}
39
- */
40
- this.received = 0;
41
- this._handleChatDeletion = this._handleChatDeletion.bind(this);
42
- this._handleGuildDeletion = this._handleGuildDeletion.bind(this);
43
- const collectHandler = this.wrapHandler(this.handleCollect);
44
- const disposeHandler = this.wrapHandler(this.handleDispose);
45
- const deleteHandler = this.wrapHandler(this._handleChatDeletion);
46
- const groupRemovalHandler = this.wrapHandler(this._handleGroupRemoval);
47
- this.incrementMaxListeners();
48
- this.ev.on(this.eventSignature(events_1.SimpleListener.Message), collectHandler);
49
- this.ev.on(this.eventSignature(events_1.SimpleListener.MessageDeleted), disposeHandler);
50
- this.ev.on(this.eventSignature(events_1.SimpleListener.ChatDeleted), deleteHandler);
51
- this.ev.on(this.eventSignature(events_1.SimpleListener.RemovedFromGroup), groupRemovalHandler);
52
- // this.ev.on(Events.GUILD_DELETE, this._handleGuildDeletion);
53
- this.once('end', () => {
54
- this.ev.removeListener(this.eventSignature(events_1.SimpleListener.Message), collectHandler);
55
- this.ev.removeListener(this.eventSignature(events_1.SimpleListener.MessageDeleted), disposeHandler);
56
- this.ev.removeListener(this.eventSignature(events_1.SimpleListener.ChatDeleted), deleteHandler);
57
- this.ev.removeListener(this.eventSignature(events_1.SimpleListener.RemovedFromGroup), groupRemovalHandler);
58
- // this.ev.removeListener(Events.GUILD_DELETE, this._handleGuildDeletion);
59
- this.decrementMaxListeners();
60
- });
61
- }
62
- /**
63
- * Handles a message for possible collection.
64
- * @param {Message} message The message that could be collected
65
- * @returns {?Snowflake}
66
- * @private
67
- */
68
- collect(message) {
69
- /**
70
- * Emitted whenever a message is collected.
71
- * @event MessageCollector#collect
72
- * @param {Message} message The message that was collected
73
- */
74
- if (message.chat.id !== this.chat)
75
- return null;
76
- this.received++;
77
- return message.id;
78
- }
79
- /**
80
- * Handles a message for possible disposal.
81
- * @param {Message} message The message that could be disposed of
82
- * @returns {?Snowflake}
83
- */
84
- dispose(message) {
85
- /**
86
- * Emitted whenever a message is disposed of.
87
- * @event MessageCollector#dispose
88
- * @param {Message} message The message that was disposed of
89
- */
90
- return message.chat.id === this.chat ? message.id : null;
91
- }
92
- /**
93
- * Checks after un/collection to see if the collector is done.
94
- * @returns {?string}
95
- * @private
96
- */
97
- endReason() {
98
- if (this.options.max && this.collected.size >= this.options.max)
99
- return 'limit';
100
- if (this.options.maxProcessed && this.received === this.options.maxProcessed)
101
- return 'processedLimit';
102
- return null;
103
- }
104
- /**
105
- * Handles checking if the chat has been deleted, and if so, stops the collector with the reason 'chatDelete'.
106
- * @private
107
- * @param {Chat} chat The chat that was deleted
108
- * @returns {void}
109
- */
110
- _handleChatDeletion(chat) {
111
- if (chat.id === this.chat) {
112
- this.stop('chatDelete');
113
- }
114
- }
115
- /**
116
- * Handles checking if the chat has been deleted, and if so, stops the collector with the reason 'chatDelete'.
117
- * @private
118
- * @param {Chat} chat The group chat that the host account was removed from
119
- * @returns {void}
120
- */
121
- _handleGroupRemoval(chat) {
122
- if (chat.id === this.chat) {
123
- this.stop('groupRemoval');
124
- }
125
- }
126
- /**
127
- *
128
- * NOT RELATED TO WA
129
- *
130
- * Handles checking if the guild has been deleted, and if so, stops the collector with the reason 'guildDelete'.
131
- * @private
132
- * @param {Guild} guild The guild that was deleted
133
- * @returns {void}
134
- */
135
- _handleGuildDeletion(guild) {
136
- console.error('This does not relate to WA', guild);
137
- }
138
- eventSignature(event) {
139
- return `${event}.${this.sessionId}.${this.instanceId}`;
140
- }
141
- wrapHandler(handler) {
142
- return ({ data }) => handler(data);
143
- }
144
- }
145
- exports.MessageCollector = MessageCollector;