@mtcute/dispatcher 0.22.0 → 0.22.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.
package/dispatcher.cjs CHANGED
@@ -146,7 +146,14 @@ class Dispatcher {
146
146
  */
147
147
  dispatchRawUpdate({ update, peers }) {
148
148
  if (!this._client) return;
149
- this.dispatchRawUpdateNow(update, peers).catch((err) => this._client.onError.emit(utils.unknownToError(err)));
149
+ this.dispatchRawUpdateNow(update, peers).catch((err) => {
150
+ err = utils.unknownToError(err);
151
+ if (this._client.onError.length > 0) {
152
+ this._client.onError.emit(err);
153
+ } else {
154
+ console.error(err);
155
+ }
156
+ });
150
157
  }
151
158
  /**
152
159
  * Process a raw update right now in the current stack.
@@ -204,7 +211,14 @@ class Dispatcher {
204
211
  */
205
212
  dispatchUpdate(update) {
206
213
  if (!this._client) return;
207
- this.dispatchUpdateNow(update).catch((err) => this._client.onError.emit(utils.unknownToError(err)));
214
+ this.dispatchUpdateNow(update).catch((err) => {
215
+ err = utils.unknownToError(err);
216
+ if (this._client.onError.length > 0) {
217
+ this._client.onError.emit(err);
218
+ } else {
219
+ console.error(err);
220
+ }
221
+ });
208
222
  }
209
223
  /**
210
224
  * Process an update right now in the current stack.
@@ -393,8 +407,10 @@ class Dispatcher {
393
407
  if (handler === "all") {
394
408
  if (group === null) {
395
409
  this._groups = /* @__PURE__ */ new Map();
410
+ this._groupsOrder = [];
396
411
  } else {
397
412
  this._groups.delete(group);
413
+ this._groupsOrder = this._groupsOrder.filter((g) => g !== group);
398
414
  }
399
415
  } else if (group !== null) {
400
416
  this._groups.get(group).delete(handler);
package/dispatcher.d.cts CHANGED
@@ -260,7 +260,7 @@ export declare class Dispatcher<State extends object = never> {
260
260
  * @param scene Dispatcher representing the scene
261
261
  * @param scoped Whether to use scoped FSM storage for the scene (defaults to `true`)
262
262
  */
263
- addScene(scene: Dispatcher<any>, scoped?: true): void;
263
+ addScene(scene: Dispatcher<any> | Dispatcher<never>, scoped?: true): void;
264
264
  /**
265
265
  * Remove a child dispatcher.
266
266
  *
@@ -272,7 +272,7 @@ export declare class Dispatcher<State extends object = never> {
272
272
  *
273
273
  * @param child Other dispatcher
274
274
  */
275
- removeChild(child: Dispatcher<any>): void;
275
+ removeChild(child: Dispatcher<any> | Dispatcher<never>): void;
276
276
  private _unparent;
277
277
  /**
278
278
  * Extend current dispatcher by copying other dispatcher's
package/dispatcher.d.ts CHANGED
@@ -260,7 +260,7 @@ export declare class Dispatcher<State extends object = never> {
260
260
  * @param scene Dispatcher representing the scene
261
261
  * @param scoped Whether to use scoped FSM storage for the scene (defaults to `true`)
262
262
  */
263
- addScene(scene: Dispatcher<any>, scoped?: true): void;
263
+ addScene(scene: Dispatcher<any> | Dispatcher<never>, scoped?: true): void;
264
264
  /**
265
265
  * Remove a child dispatcher.
266
266
  *
@@ -272,7 +272,7 @@ export declare class Dispatcher<State extends object = never> {
272
272
  *
273
273
  * @param child Other dispatcher
274
274
  */
275
- removeChild(child: Dispatcher<any>): void;
275
+ removeChild(child: Dispatcher<any> | Dispatcher<never>): void;
276
276
  private _unparent;
277
277
  /**
278
278
  * Extend current dispatcher by copying other dispatcher's
package/dispatcher.js CHANGED
@@ -139,7 +139,14 @@ class Dispatcher {
139
139
  */
140
140
  dispatchRawUpdate({ update, peers }) {
141
141
  if (!this._client) return;
142
- this.dispatchRawUpdateNow(update, peers).catch((err) => this._client.onError.emit(unknownToError(err)));
142
+ this.dispatchRawUpdateNow(update, peers).catch((err) => {
143
+ err = unknownToError(err);
144
+ if (this._client.onError.length > 0) {
145
+ this._client.onError.emit(err);
146
+ } else {
147
+ console.error(err);
148
+ }
149
+ });
143
150
  }
144
151
  /**
145
152
  * Process a raw update right now in the current stack.
@@ -197,7 +204,14 @@ class Dispatcher {
197
204
  */
198
205
  dispatchUpdate(update) {
199
206
  if (!this._client) return;
200
- this.dispatchUpdateNow(update).catch((err) => this._client.onError.emit(unknownToError(err)));
207
+ this.dispatchUpdateNow(update).catch((err) => {
208
+ err = unknownToError(err);
209
+ if (this._client.onError.length > 0) {
210
+ this._client.onError.emit(err);
211
+ } else {
212
+ console.error(err);
213
+ }
214
+ });
201
215
  }
202
216
  /**
203
217
  * Process an update right now in the current stack.
@@ -386,8 +400,10 @@ class Dispatcher {
386
400
  if (handler === "all") {
387
401
  if (group === null) {
388
402
  this._groups = /* @__PURE__ */ new Map();
403
+ this._groupsOrder = [];
389
404
  } else {
390
405
  this._groups.delete(group);
406
+ this._groupsOrder = this._groupsOrder.filter((g) => g !== group);
391
407
  }
392
408
  } else if (group !== null) {
393
409
  this._groups.get(group).delete(handler);
package/filters/bots.cjs CHANGED
@@ -36,7 +36,7 @@ function command(commands, {
36
36
  const lastGroup = m[m.length - 1];
37
37
  if (lastGroup) {
38
38
  const self = msg.client.storage.self.getCached();
39
- if (self && self.isBot && !self.usernames.includes(lastGroup)) {
39
+ if (self && self.isBot && !self.usernames.some((u) => u.toLowerCase() === lastGroup.toLowerCase())) {
40
40
  return false;
41
41
  }
42
42
  }
package/filters/bots.js CHANGED
@@ -29,7 +29,7 @@ function command(commands, {
29
29
  const lastGroup = m[m.length - 1];
30
30
  if (lastGroup) {
31
31
  const self = msg.client.storage.self.getCached();
32
- if (self && self.isBot && !self.usernames.includes(lastGroup)) {
32
+ if (self && self.isBot && !self.usernames.some((u) => u.toLowerCase() === lastGroup.toLowerCase())) {
33
33
  return false;
34
34
  }
35
35
  }
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@mtcute/dispatcher",
3
3
  "type": "module",
4
- "version": "0.22.0",
4
+ "version": "0.22.2",
5
5
  "description": "Updates dispatcher and bot framework for @mtcute/client",
6
6
  "license": "MIT",
7
7
  "scripts": {},
8
8
  "dependencies": {
9
- "@mtcute/core": "^0.22.0",
9
+ "@mtcute/core": "^0.22.2",
10
10
  "@fuman/utils": "0.0.4"
11
11
  },
12
12
  "exports": {