@mtcute/dispatcher 0.6.0 → 0.7.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.
Files changed (183) hide show
  1. package/cjs/callback-data-builder.d.ts +1 -1
  2. package/cjs/callback-data-builder.js +5 -5
  3. package/cjs/callback-data-builder.js.map +1 -1
  4. package/cjs/callback-data-builder.test.js +8 -8
  5. package/cjs/callback-data-builder.test.js.map +1 -1
  6. package/cjs/context/base.d.ts +1 -1
  7. package/cjs/context/base.js.map +1 -1
  8. package/cjs/context/callback-query.d.ts +2 -2
  9. package/cjs/context/callback-query.js +3 -3
  10. package/cjs/context/callback-query.js.map +1 -1
  11. package/cjs/context/chat-join-request.d.ts +1 -1
  12. package/cjs/context/chat-join-request.js +2 -2
  13. package/cjs/context/chat-join-request.js.map +1 -1
  14. package/cjs/context/chosen-inline-result.d.ts +1 -1
  15. package/cjs/context/chosen-inline-result.js +3 -3
  16. package/cjs/context/chosen-inline-result.js.map +1 -1
  17. package/cjs/context/inline-query.d.ts +1 -1
  18. package/cjs/context/inline-query.js +2 -2
  19. package/cjs/context/inline-query.js.map +1 -1
  20. package/cjs/context/message.d.ts +6 -6
  21. package/cjs/context/message.js +3 -3
  22. package/cjs/context/message.js.map +1 -1
  23. package/cjs/context/parse.js.map +1 -1
  24. package/cjs/context/pre-checkout-query.d.ts +1 -1
  25. package/cjs/context/pre-checkout-query.js +2 -2
  26. package/cjs/context/pre-checkout-query.js.map +1 -1
  27. package/cjs/dispatcher.d.ts +14 -9
  28. package/cjs/dispatcher.js +41 -78
  29. package/cjs/dispatcher.js.map +1 -1
  30. package/cjs/filters/bots.d.ts +6 -6
  31. package/cjs/filters/bots.js +2 -2
  32. package/cjs/filters/bots.js.map +1 -1
  33. package/cjs/filters/bots.test.js +6 -5
  34. package/cjs/filters/bots.test.js.map +1 -1
  35. package/cjs/filters/chat.d.ts +1 -1
  36. package/cjs/filters/chat.js +1 -1
  37. package/cjs/filters/chat.js.map +1 -1
  38. package/cjs/filters/group.d.ts +1 -1
  39. package/cjs/filters/group.js.map +1 -1
  40. package/cjs/filters/logic.js.map +1 -1
  41. package/cjs/filters/message.d.ts +75 -67
  42. package/cjs/filters/message.js +3 -3
  43. package/cjs/filters/message.js.map +1 -1
  44. package/cjs/filters/state.d.ts +2 -2
  45. package/cjs/filters/state.js.map +1 -1
  46. package/cjs/filters/text.d.ts +1 -1
  47. package/cjs/filters/text.js.map +1 -1
  48. package/cjs/filters/types.d.ts +2 -2
  49. package/cjs/filters/types.js.map +1 -1
  50. package/cjs/filters/updates.d.ts +1 -1
  51. package/cjs/filters/updates.js.map +1 -1
  52. package/cjs/filters/user.d.ts +1 -1
  53. package/cjs/filters/user.js +4 -4
  54. package/cjs/filters/user.js.map +1 -1
  55. package/cjs/handler.d.ts +3 -3
  56. package/cjs/handler.js.map +1 -1
  57. package/cjs/propagation.js +1 -1
  58. package/cjs/propagation.js.map +1 -1
  59. package/cjs/state/index.d.ts +3 -1
  60. package/cjs/state/index.js +3 -1
  61. package/cjs/state/index.js.map +1 -1
  62. package/cjs/state/key.d.ts +2 -2
  63. package/cjs/state/key.js +2 -2
  64. package/cjs/state/key.js.map +1 -1
  65. package/cjs/state/provider.d.ts +5 -0
  66. package/cjs/state/provider.js +3 -0
  67. package/cjs/state/provider.js.map +1 -0
  68. package/cjs/state/providers/index.d.ts +2 -0
  69. package/cjs/state/providers/index.js +19 -0
  70. package/cjs/state/providers/index.js.map +1 -0
  71. package/cjs/state/providers/memory.d.ts +29 -0
  72. package/cjs/state/providers/memory.js +76 -0
  73. package/cjs/state/providers/memory.js.map +1 -0
  74. package/cjs/state/providers/sqlite.d.ts +29 -0
  75. package/cjs/state/providers/sqlite.js +89 -0
  76. package/cjs/state/providers/sqlite.js.map +1 -0
  77. package/cjs/state/repository.d.ts +62 -0
  78. package/cjs/state/repository.js +3 -0
  79. package/cjs/state/repository.js.map +1 -0
  80. package/cjs/state/service.d.ts +19 -0
  81. package/cjs/state/service.js +68 -0
  82. package/cjs/state/service.js.map +1 -0
  83. package/cjs/state/update-state.d.ts +3 -3
  84. package/cjs/state/update-state.js +7 -7
  85. package/cjs/state/update-state.js.map +1 -1
  86. package/cjs/wizard.d.ts +2 -2
  87. package/cjs/wizard.js +1 -1
  88. package/cjs/wizard.js.map +1 -1
  89. package/esm/callback-data-builder.d.ts +1 -1
  90. package/esm/callback-data-builder.js +1 -1
  91. package/esm/callback-data-builder.js.map +1 -1
  92. package/esm/callback-data-builder.test.js +2 -2
  93. package/esm/callback-data-builder.test.js.map +1 -1
  94. package/esm/context/base.d.ts +1 -1
  95. package/esm/context/base.js.map +1 -1
  96. package/esm/context/callback-query.d.ts +2 -2
  97. package/esm/context/callback-query.js +1 -1
  98. package/esm/context/callback-query.js.map +1 -1
  99. package/esm/context/chat-join-request.d.ts +1 -1
  100. package/esm/context/chat-join-request.js +1 -1
  101. package/esm/context/chat-join-request.js.map +1 -1
  102. package/esm/context/chosen-inline-result.d.ts +1 -1
  103. package/esm/context/chosen-inline-result.js +1 -1
  104. package/esm/context/chosen-inline-result.js.map +1 -1
  105. package/esm/context/inline-query.d.ts +1 -1
  106. package/esm/context/inline-query.js +1 -1
  107. package/esm/context/inline-query.js.map +1 -1
  108. package/esm/context/message.d.ts +6 -6
  109. package/esm/context/message.js +1 -1
  110. package/esm/context/message.js.map +1 -1
  111. package/esm/context/parse.js.map +1 -1
  112. package/esm/context/pre-checkout-query.d.ts +1 -1
  113. package/esm/context/pre-checkout-query.js +1 -1
  114. package/esm/context/pre-checkout-query.js.map +1 -1
  115. package/esm/dispatcher.d.ts +14 -9
  116. package/esm/dispatcher.js +29 -66
  117. package/esm/dispatcher.js.map +1 -1
  118. package/esm/filters/bots.d.ts +6 -6
  119. package/esm/filters/bots.js +2 -2
  120. package/esm/filters/bots.js.map +1 -1
  121. package/esm/filters/bots.test.js +4 -3
  122. package/esm/filters/bots.test.js.map +1 -1
  123. package/esm/filters/chat.d.ts +2 -2
  124. package/esm/filters/chat.js +1 -1
  125. package/esm/filters/chat.js.map +1 -1
  126. package/esm/filters/group.d.ts +1 -1
  127. package/esm/filters/group.js.map +1 -1
  128. package/esm/filters/logic.js.map +1 -1
  129. package/esm/filters/message.d.ts +77 -69
  130. package/esm/filters/message.js +1 -1
  131. package/esm/filters/message.js.map +1 -1
  132. package/esm/filters/state.d.ts +2 -2
  133. package/esm/filters/state.js.map +1 -1
  134. package/esm/filters/text.d.ts +1 -1
  135. package/esm/filters/text.js.map +1 -1
  136. package/esm/filters/types.d.ts +2 -2
  137. package/esm/filters/types.js.map +1 -1
  138. package/esm/filters/updates.d.ts +1 -1
  139. package/esm/filters/updates.js.map +1 -1
  140. package/esm/filters/user.d.ts +1 -1
  141. package/esm/filters/user.js +3 -3
  142. package/esm/filters/user.js.map +1 -1
  143. package/esm/handler.d.ts +3 -3
  144. package/esm/handler.js.map +1 -1
  145. package/esm/propagation.js +1 -1
  146. package/esm/propagation.js.map +1 -1
  147. package/esm/state/index.d.ts +3 -1
  148. package/esm/state/index.js +3 -1
  149. package/esm/state/index.js.map +1 -1
  150. package/esm/state/key.d.ts +2 -2
  151. package/esm/state/key.js +1 -1
  152. package/esm/state/key.js.map +1 -1
  153. package/esm/state/provider.d.ts +5 -0
  154. package/esm/state/provider.js +2 -0
  155. package/esm/state/provider.js.map +1 -0
  156. package/esm/state/providers/index.d.ts +2 -0
  157. package/esm/state/providers/index.js +3 -0
  158. package/esm/state/providers/index.js.map +1 -0
  159. package/esm/state/providers/memory.d.ts +29 -0
  160. package/esm/state/providers/memory.js +72 -0
  161. package/esm/state/providers/memory.js.map +1 -0
  162. package/esm/state/providers/sqlite.d.ts +29 -0
  163. package/esm/state/providers/sqlite.js +85 -0
  164. package/esm/state/providers/sqlite.js.map +1 -0
  165. package/esm/state/repository.d.ts +62 -0
  166. package/esm/state/repository.js +2 -0
  167. package/esm/state/repository.js.map +1 -0
  168. package/esm/state/service.d.ts +19 -0
  169. package/esm/state/service.js +64 -0
  170. package/esm/state/service.js.map +1 -0
  171. package/esm/state/update-state.d.ts +3 -3
  172. package/esm/state/update-state.js +2 -2
  173. package/esm/state/update-state.js.map +1 -1
  174. package/esm/wizard.d.ts +2 -2
  175. package/esm/wizard.js +1 -1
  176. package/esm/wizard.js.map +1 -1
  177. package/package.json +10 -3
  178. package/cjs/state/storage.d.ts +0 -96
  179. package/cjs/state/storage.js +0 -17
  180. package/cjs/state/storage.js.map +0 -1
  181. package/esm/state/storage.d.ts +0 -96
  182. package/esm/state/storage.js +0 -13
  183. package/esm/state/storage.js.map +0 -1
@@ -0,0 +1,19 @@
1
+ import { IStateStorageProvider } from './provider.js';
2
+ export declare class StateService {
3
+ readonly provider: IStateStorageProvider;
4
+ constructor(provider: IStateStorageProvider);
5
+ private _cache;
6
+ private _vacuumTimer?;
7
+ private _loaded;
8
+ private _load;
9
+ load(): Promise<void>;
10
+ destroy(): Promise<void>;
11
+ getState<T>(key: string): Promise<T | null>;
12
+ setState<T>(key: string, state: T, ttl?: number): Promise<void>;
13
+ deleteState(key: string): Promise<void>;
14
+ getCurrentScene(key: string): Promise<string | null>;
15
+ setCurrentScene(key: string, scene: string, ttl?: number): Promise<void>;
16
+ deleteCurrentScene(key: string): Promise<void>;
17
+ getRateLimit(key: string, limit: number, window: number): import("@mtcute/core").MaybePromise<[number, number]>;
18
+ resetRateLimit(key: string): import("@mtcute/core").MaybePromise<void>;
19
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.StateService = void 0;
4
+ const utils_js_1 = require("@mtcute/core/utils.js");
5
+ const makeCurrentSceneKey = (key) => `$current_scene_${key}`;
6
+ class StateService {
7
+ constructor(provider) {
8
+ this.provider = provider;
9
+ this._cache = new utils_js_1.LruMap(100);
10
+ this._loaded = false;
11
+ this._load = (0, utils_js_1.asyncResettable)(async () => {
12
+ await this.provider.driver.load?.();
13
+ this._loaded = true;
14
+ });
15
+ }
16
+ async load() {
17
+ await this._load.run();
18
+ this._vacuumTimer = setInterval(() => {
19
+ Promise.resolve(this.provider.state.vacuum(Date.now())).catch(() => { });
20
+ }, 300000);
21
+ }
22
+ async destroy() {
23
+ await this.provider.driver.save?.();
24
+ await this.provider.driver.destroy?.();
25
+ clearInterval(this._vacuumTimer);
26
+ this._loaded = false;
27
+ }
28
+ async getState(key) {
29
+ if (!this._loaded)
30
+ await this.load();
31
+ const cached = this._cache.get(key);
32
+ if (cached)
33
+ return cached;
34
+ const state = await this.provider.state.getState(key, Date.now());
35
+ if (!state)
36
+ return null;
37
+ return JSON.parse(state);
38
+ }
39
+ async setState(key, state, ttl) {
40
+ if (!this._loaded)
41
+ await this.load();
42
+ this._cache.set(key, state);
43
+ await this.provider.state.setState(key, JSON.stringify(state), ttl);
44
+ }
45
+ async deleteState(key) {
46
+ if (!this._loaded)
47
+ await this.load();
48
+ this._cache.delete(key);
49
+ await this.provider.state.deleteState(key);
50
+ }
51
+ getCurrentScene(key) {
52
+ return this.getState(makeCurrentSceneKey(key));
53
+ }
54
+ setCurrentScene(key, scene, ttl) {
55
+ return this.setState(makeCurrentSceneKey(key), scene, ttl);
56
+ }
57
+ deleteCurrentScene(key) {
58
+ return this.deleteState(makeCurrentSceneKey(key));
59
+ }
60
+ getRateLimit(key, limit, window) {
61
+ return this.provider.state.getRateLimit(key, Date.now(), limit, window);
62
+ }
63
+ resetRateLimit(key) {
64
+ return this.provider.state.resetRateLimit(key);
65
+ }
66
+ }
67
+ exports.StateService = StateService;
68
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../src/state/service.ts"],"names":[],"mappings":";;;AAAA,oDAA+D;AAI/D,MAAM,mBAAmB,GAAG,CAAC,GAAW,EAAE,EAAE,CAAC,kBAAkB,GAAG,EAAE,CAAA;AAEpE,MAAa,YAAY;IACrB,YAAqB,QAA+B;QAA/B,aAAQ,GAAR,QAAQ,CAAuB;QAE5C,WAAM,GAA4B,IAAI,iB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KAAK,CAAC,YAAY,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;IAC3E,CAAC;IAED,cAAc,CAAC,GAAW;QACtB,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IAClD,CAAC;CACJ;AAtED,oCAsEC","sourcesContent":["import { asyncResettable, LruMap } from '@mtcute/core/utils.js'\n\nimport { IStateStorageProvider } from './provider.js'\n\nconst makeCurrentSceneKey = (key: string) => `$current_scene_${key}`\n\nexport class StateService {\n constructor(readonly provider: IStateStorageProvider) {}\n\n private _cache: LruMap<string, unknown> = new LruMap(100)\n private _vacuumTimer?: NodeJS.Timeout\n\n private _loaded = false\n private _load = asyncResettable(async () => {\n await this.provider.driver.load?.()\n this._loaded = true\n })\n async load() {\n await this._load.run()\n this._vacuumTimer = setInterval(() => {\n Promise.resolve(this.provider.state.vacuum(Date.now())).catch(() => {})\n }, 300_000)\n }\n\n async destroy() {\n await this.provider.driver.save?.()\n await this.provider.driver.destroy?.()\n clearInterval(this._vacuumTimer)\n this._loaded = false\n }\n\n async getState<T>(key: string): Promise<T | null> {\n if (!this._loaded) await this.load()\n\n const cached = this._cache.get(key)\n if (cached) return cached as T\n\n const state = await this.provider.state.getState(key, Date.now())\n if (!state) return null\n\n return JSON.parse(state) as T\n }\n\n async setState<T>(key: string, state: T, ttl?: number): Promise<void> {\n if (!this._loaded) await this.load()\n\n this._cache.set(key, state)\n await this.provider.state.setState(key, JSON.stringify(state), ttl)\n }\n\n async deleteState(key: string): Promise<void> {\n if (!this._loaded) await this.load()\n\n this._cache.delete(key)\n await this.provider.state.deleteState(key)\n }\n\n getCurrentScene(key: string): Promise<string | null> {\n return this.getState(makeCurrentSceneKey(key))\n }\n\n setCurrentScene(key: string, scene: string, ttl?: number): Promise<void> {\n return this.setState(makeCurrentSceneKey(key), scene, ttl)\n }\n\n deleteCurrentScene(key: string): Promise<void> {\n return this.deleteState(makeCurrentSceneKey(key))\n }\n\n getRateLimit(key: string, limit: number, window: number) {\n return this.provider.state.getRateLimit(key, Date.now(), limit, window)\n }\n\n resetRateLimit(key: string) {\n return this.provider.state.resetRateLimit(key)\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
- import { MtcuteError } from '@mtcute/client';
1
+ import { MtcuteError } from '@mtcute/core';
2
2
  import type { Dispatcher } from '../dispatcher.js';
3
- import { IStateStorage } from './storage.js';
3
+ import { StateService } from './service.js';
4
4
  /**
5
5
  * Error thrown by `.rateLimit()`
6
6
  */
@@ -23,7 +23,7 @@ export declare class UpdateState<State extends object> {
23
23
  private _cached?;
24
24
  private _localStorage;
25
25
  private _localKeyBase;
26
- constructor(storage: IStateStorage, key: string, scene: string | null, scoped?: boolean, customStorage?: IStateStorage, customKey?: string);
26
+ constructor(storage: StateService, key: string, scene: string | null, scoped?: boolean, customStorage?: StateService, customKey?: string);
27
27
  /** Name of the current scene */
28
28
  get scene(): string | null;
29
29
  private _updateLocalKey;
@@ -3,12 +3,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.UpdateState = exports.RateLimitError = void 0;
4
4
  /* eslint-disable dot-notation */
5
5
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
- const client_1 = require("@mtcute/client");
7
- const utils_js_1 = require("@mtcute/client/utils.js");
6
+ const core_1 = require("@mtcute/core");
7
+ const utils_js_1 = require("@mtcute/core/utils.js");
8
8
  /**
9
9
  * Error thrown by `.rateLimit()`
10
10
  */
11
- class RateLimitError extends client_1.MtcuteError {
11
+ class RateLimitError extends core_1.MtcuteError {
12
12
  constructor(reset) {
13
13
  super('You are being rate limited.');
14
14
  this.reset = reset;
@@ -89,7 +89,7 @@ class UpdateState {
89
89
  const old = await this.get(forceLoad);
90
90
  if (!old) {
91
91
  if (!fallback) {
92
- throw new client_1.MtArgumentError('Cannot use merge on empty state without fallback.');
92
+ throw new core_1.MtArgumentError('Cannot use merge on empty state without fallback.');
93
93
  }
94
94
  const fallback_ = typeof fallback === 'function' ? fallback() : fallback;
95
95
  await this.set({ ...fallback_, ...state }, ttl);
@@ -115,10 +115,10 @@ class UpdateState {
115
115
  if (reset && this._scoped)
116
116
  await this.delete();
117
117
  if (!scene['_scene']) {
118
- throw new client_1.MtArgumentError('Cannot enter a non-scene Dispatcher');
118
+ throw new core_1.MtArgumentError('Cannot enter a non-scene Dispatcher');
119
119
  }
120
120
  if (!scene['_parent']) {
121
- throw new client_1.MtArgumentError('This scene has not been registered');
121
+ throw new core_1.MtArgumentError('This scene has not been registered');
122
122
  }
123
123
  this._scene = scene['_scene'];
124
124
  this._scoped = scene['_sceneScoped'];
@@ -126,7 +126,7 @@ class UpdateState {
126
126
  await this._storage.setCurrentScene(this._key, this._scene, ttl);
127
127
  if (with_) {
128
128
  if (scene['_customStateKeyDelegate']) {
129
- throw new client_1.MtArgumentError('Cannot use `with` parameter when the scene uses a custom state key delegate');
129
+ throw new core_1.MtArgumentError('Cannot use `with` parameter when the scene uses a custom state key delegate');
130
130
  }
131
131
  await scene.getState(this._key).set(with_, ttl);
132
132
  }
@@ -1 +1 @@
1
- {"version":3,"file":"update-state.js","sourceRoot":"","sources":["../../../src/state/update-state.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,uDAAuD;AACvD,2CAA6D;AAC7D,sDAA+C;AAK/C;;GAEG;AACH,MAAa,cAAe,SAAQ,oBAAW;IAC3C,YAAqB,KAAa;QAC9B,KAAK,CAAC,6BAA6B,CAAC,CAAA;QADnB,UAAK,GAAL,KAAK,CAAQ;IAElC,CAAC;CACJ;AAJD,wCAIC;AAED;;;;;GAKG;AACH,MAAa,WAAW;IAapB,YACI,OAAsB,EACtB,GAAW,EACX,KAAoB,EACpB,MAAgB,EAChB,aAA6B,EAC7B,SAAkB;QAElB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;QACf,IAAI,CAAC,MAAM,GAAG,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port { MtArgumentError, MtcuteError } from '@mtcute/client'\nimport { sleep } from '@mtcute/client/utils.js'\n\nimport type { Dispatcher } from '../dispatcher.js'\nimport { IStateStorage } from './storage.js'\n\n/**\n * Error thrown by `.rateLimit()`\n */\nexport class RateLimitError extends MtcuteError {\n constructor(readonly reset: number) {\n super('You are being rate limited.')\n }\n}\n\n/**\n * State of the current update.\n *\n * @template State Type that represents the state\n * @template SceneName Possible scene names\n */\nexport class UpdateState<State extends object> {\n private _key: string\n private _localKey!: string\n\n private _storage: IStateStorage\n\n private _scene: string | null\n private _scoped?: boolean\n private _cached?: State | null\n\n private _localStorage: IStateStorage\n private _localKeyBase: string\n\n constructor(\n storage: IStateStorage,\n key: string,\n scene: string | null,\n scoped?: boolean,\n customStorage?: IStateStorage,\n customKey?: string,\n ) {\n this._storage = storage\n this._key = key\n this._scene = scene\n this._scoped = scoped\n\n this._localStorage = customStorage ?? storage\n this._localKeyBase = customKey ?? key\n\n this._updateLocalKey()\n }\n\n /** Name of the current scene */\n get scene(): string | null {\n return this._scene\n }\n\n private _updateLocalKey(): void {\n if (!this._scoped) this._localKey = this._localKeyBase\n else {\n this._localKey = this._scene ? this._scene + '_' + this._localKeyBase : this._localKeyBase\n }\n }\n\n /**\n * Retrieve the state from the storage, falling back to default\n * if not found\n *\n * @param fallback Default state value\n * @param force Whether to ignore cached state (def. `false`)\n */\n async get(fallback: State | (() => State), force?: boolean): Promise<State>\n\n /**\n * Retrieve the state from the storage, falling back to default\n * if not found\n *\n * @param fallback Default state value\n * @param force Whether to ignore cached state (def. `false`)\n */\n async get(fallback?: State | (() => State), force?: boolean): Promise<State | null>\n /**\n * Retrieve the state from the storage\n *\n * @param force Whether to ignore cached state (def. `false`)\n */\n async get(force?: boolean): Promise<State | null>\n async get(fallback?: State | (() => State) | boolean, force?: boolean): Promise<State | null> {\n if (typeof fallback === 'boolean') {\n force = fallback\n fallback = undefined\n }\n\n if (!force && this._cached !== undefined) {\n if (!this._cached && fallback) {\n return typeof fallback === 'function' ? fallback() : fallback\n }\n\n return this._cached\n }\n\n let res = (await this._localStorage.getState(this._localKey)) as State | null\n\n if (!res && fallback) {\n res = typeof fallback === 'function' ? fallback() : fallback\n }\n this._cached = res\n\n return res\n }\n\n /**\n * Set new state to the storage\n *\n * @param state New state\n * @param ttl TTL for the new state (in seconds)\n */\n async set(state: State, ttl?: number): Promise<void> {\n this._cached = state\n await this._localStorage.setState(this._localKey, state, ttl)\n }\n\n /**\n * Merge the given object to the current state.\n *\n * > **Note**: If the storage currently has no state,\n * > then `fallback` must be provided.\n *\n * Basically a shorthand to calling `.get()`,\n * modifying and then calling `.set()`\n *\n * @param state State to be merged\n * @param fallback Default state\n * @param ttl TTL for the new state (in seconds)\n * @param forceLoad Whether to force load the old state from storage\n */\n async merge(\n state: Partial<State>,\n params: {\n fallback?: State | (() => State)\n ttl?: number\n forceLoad?: boolean\n } = {},\n ): Promise<State> {\n const { fallback, ttl, forceLoad } = params\n\n const old = await this.get(forceLoad)\n\n if (!old) {\n if (!fallback) {\n throw new MtArgumentError('Cannot use merge on empty state without fallback.')\n }\n\n const fallback_ = typeof fallback === 'function' ? fallback() : fallback\n\n await this.set({ ...fallback_, ...state }, ttl)\n } else {\n await this.set({ ...old, ...state }, ttl)\n }\n\n // _cached is set by .set()\n\n return this._cached!\n }\n\n /**\n * Delete the state from the storage\n */\n async delete(): Promise<void> {\n this._cached = null\n await this._localStorage.deleteState(this._localKey)\n }\n\n /**\n * Enter some scene\n */\n async enter<SceneState extends object, Scene extends Dispatcher<SceneState>>(\n scene: Scene,\n params?: {\n /**\n * Initial state for the scene\n *\n * Note that this will only work if the scene uses the same key delegate as this state.\n */\n with?: SceneState\n\n /** TTL for the scene (in seconds) */\n ttl?: number\n\n /**\n * If currently in a scoped scene, whether to reset the state\n *\n * @default true\n */\n reset?: boolean\n },\n ): Promise<void> {\n const { with: with_, ttl, reset = true } = params ?? {}\n\n if (reset && this._scoped) await this.delete()\n\n if (!scene['_scene']) {\n throw new MtArgumentError('Cannot enter a non-scene Dispatcher')\n }\n\n if (!scene['_parent']) {\n throw new MtArgumentError('This scene has not been registered')\n }\n\n this._scene = scene['_scene']\n this._scoped = scene['_sceneScoped']\n this._updateLocalKey()\n\n await this._storage.setCurrentScene(this._key, this._scene, ttl)\n\n if (with_) {\n if (scene['_customStateKeyDelegate']) {\n throw new MtArgumentError('Cannot use `with` parameter when the scene uses a custom state key delegate')\n }\n\n await scene.getState(this._key).set(with_, ttl)\n }\n }\n\n /**\n * Exit from current scene to the root\n *\n * @param reset\n * Whether to reset scene state (only applicable in case this is a scoped scene)\n */\n async exit(reset = true): Promise<void> {\n if (reset && this._scoped) await this.delete()\n this._scene = null\n this._updateLocalKey()\n await this._storage.deleteCurrentScene(this._key)\n }\n\n /**\n * Rate limit some handler.\n *\n * When the rate limit exceeds, {@link RateLimitError} is thrown.\n *\n * This is a simple rate-limiting solution that uses\n * the same key as the state. If you need something more\n * sophisticated and/or customizable, you'll have to implement\n * your own rate-limiter.\n *\n * > **Note**: `key` is used to prefix the local key\n * > derived using the given key delegate.\n *\n * @param key Key of the rate limit\n * @param limit Maximum number of requests in `window`\n * @param window Window size in seconds\n * @returns Tuple containing the number of remaining and\n * unix time in ms when the user can try again\n */\n async rateLimit(key: string, limit: number, window: number): Promise<[number, number]> {\n const [remaining, reset] = await this._localStorage.getRateLimit(`${key}:${this._localKey}`, limit, window)\n\n if (!remaining) {\n throw new RateLimitError(reset)\n }\n\n return [remaining - 1, reset]\n }\n\n /**\n * Throttle some handler.\n *\n * When the rate limit exceeds, this function waits for it to reset.\n *\n * This is a simple wrapper over {@link rateLimit}, and follows the same logic.\n *\n * > **Note**: `key` is used to prefix the local key\n * > derived using the given key delegate.\n *\n * @param key Key of the rate limit\n * @param limit Maximum number of requests in `window`\n * @param window Window size in seconds\n * @returns Tuple containing the number of remaining and\n * unix time in ms when the user can try again\n */\n async throttle(key: string, limit: number, window: number): Promise<[number, number]> {\n try {\n return await this.rateLimit(key, limit, window)\n } catch (e: unknown) {\n if (e instanceof RateLimitError) {\n await sleep(e.reset - Date.now())\n\n return this.throttle(key, limit, window)\n }\n\n throw e\n }\n }\n\n /**\n * Reset the rate limit\n *\n * @param key Key of the rate limit\n */\n async resetRateLimit(key: string): Promise<void> {\n await this._localStorage.resetRateLimit(`${key}:${this._localKey}`)\n }\n}\n"]}
1
+ {"version":3,"file":"update-state.js","sourceRoot":"","sources":["../../../src/state/update-state.ts"],"names":[],"mappings":";;;AAAA,iCAAiC;AACjC,uDAAuD;AACvD,uCAA2D;AAC3D,oDAA6C;AAK7C;;GAEG;AACH,MAAa,cAAe,SAAQ,kBAAW;IAC3C,YAAqB,KAAa;QAC9B,KAAK,CAAC,6BAA6B,CAAC,CAAA;QADnB,UAAK,GAAL,KAAK,CAAQ;IAElC,CAAC;CACJ;AAJD,wCAIC;AAED;;;;;GAKG;AACH,MAAa,WAAW;IAapB,YACI,OAAqB,EACrB,GAAW,EACX,KAAoB,EACpB,MAAgB,EAChB,aAA4B,EAC5B,SAAkB;QAElB,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAA;QACvB,IAAI,CAAC,IAAI,GAAG,GAAG,CAAA;QACf,IAAI,CAAC,MAAM,GAAG,KAAK,CAAA;QACnB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;QAErB,IAAI,CAAC,aAAa,GAAG,aAAa,IAAI,OAAO,CAAA;QAC7C,IAAI,CAAC,aAAa,GAAG,SAAS,IAAI,GAAG,CAAA;QAErC,IAAI,CAAC,eAAe,EAAE,CAAA;IAC1B,CAAC;IAED,gCAAgC;IAChC,IAAI,KAAK;QACL,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAEO,eAAe;QACnB,IAAI,CAAC,IAAI,CAAC,OAAO;YAAE,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,aAAa,CAAA;aACjD;YACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,GAA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K,CAAC,CAAA;IACjC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,KAAK,CAAC,QAAQ,CAAC,GAAW,EAAE,KAAa,EAAE,MAAc;QACrD,IAAI;YACA,OAAO,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;SAClD;QAAC,OAAO,CAAU,EAAE;YACjB,IAAI,CAAC,YAAY,cAAc,EAAE;gBAC7B,MAAM,IAAA,gBAAK,EAAC,CAAC,CAAC,KAAK,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,CAAA;gBAEjC,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAA;aAC3C;YAED,MAAM,CAAC,CAAA;SACV;IACL,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,cAAc,CAAC,GAAW;QAC5B,MAAM,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,GAAG,GAAG,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC,CAAA;IACvE,CAAC;CACJ;AA5RD,kCA4RC","sourcesContent":["/* eslint-disable dot-notation */\n/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { MtArgumentError, MtcuteError } from '@mtcute/core'\nimport { sleep } from '@mtcute/core/utils.js'\n\nimport type { Dispatcher } from '../dispatcher.js'\nimport { StateService } from './service.js'\n\n/**\n * Error thrown by `.rateLimit()`\n */\nexport class RateLimitError extends MtcuteError {\n constructor(readonly reset: number) {\n super('You are being rate limited.')\n }\n}\n\n/**\n * State of the current update.\n *\n * @template State Type that represents the state\n * @template SceneName Possible scene names\n */\nexport class UpdateState<State extends object> {\n private _key: string\n private _localKey!: string\n\n private _storage: StateService\n\n private _scene: string | null\n private _scoped?: boolean\n private _cached?: State | null\n\n private _localStorage: StateService\n private _localKeyBase: string\n\n constructor(\n storage: StateService,\n key: string,\n scene: string | null,\n scoped?: boolean,\n customStorage?: StateService,\n customKey?: string,\n ) {\n this._storage = storage\n this._key = key\n this._scene = scene\n this._scoped = scoped\n\n this._localStorage = customStorage ?? storage\n this._localKeyBase = customKey ?? key\n\n this._updateLocalKey()\n }\n\n /** Name of the current scene */\n get scene(): string | null {\n return this._scene\n }\n\n private _updateLocalKey(): void {\n if (!this._scoped) this._localKey = this._localKeyBase\n else {\n this._localKey = this._scene ? this._scene + '_' + this._localKeyBase : this._localKeyBase\n }\n }\n\n /**\n * Retrieve the state from the storage, falling back to default\n * if not found\n *\n * @param fallback Default state value\n * @param force Whether to ignore cached state (def. `false`)\n */\n async get(fallback: State | (() => State), force?: boolean): Promise<State>\n\n /**\n * Retrieve the state from the storage, falling back to default\n * if not found\n *\n * @param fallback Default state value\n * @param force Whether to ignore cached state (def. `false`)\n */\n async get(fallback?: State | (() => State), force?: boolean): Promise<State | null>\n /**\n * Retrieve the state from the storage\n *\n * @param force Whether to ignore cached state (def. `false`)\n */\n async get(force?: boolean): Promise<State | null>\n async get(fallback?: State | (() => State) | boolean, force?: boolean): Promise<State | null> {\n if (typeof fallback === 'boolean') {\n force = fallback\n fallback = undefined\n }\n\n if (!force && this._cached !== undefined) {\n if (!this._cached && fallback) {\n return typeof fallback === 'function' ? fallback() : fallback\n }\n\n return this._cached\n }\n\n let res = (await this._localStorage.getState(this._localKey)) as State | null\n\n if (!res && fallback) {\n res = typeof fallback === 'function' ? fallback() : fallback\n }\n this._cached = res\n\n return res\n }\n\n /**\n * Set new state to the storage\n *\n * @param state New state\n * @param ttl TTL for the new state (in seconds)\n */\n async set(state: State, ttl?: number): Promise<void> {\n this._cached = state\n await this._localStorage.setState(this._localKey, state, ttl)\n }\n\n /**\n * Merge the given object to the current state.\n *\n * > **Note**: If the storage currently has no state,\n * > then `fallback` must be provided.\n *\n * Basically a shorthand to calling `.get()`,\n * modifying and then calling `.set()`\n *\n * @param state State to be merged\n * @param fallback Default state\n * @param ttl TTL for the new state (in seconds)\n * @param forceLoad Whether to force load the old state from storage\n */\n async merge(\n state: Partial<State>,\n params: {\n fallback?: State | (() => State)\n ttl?: number\n forceLoad?: boolean\n } = {},\n ): Promise<State> {\n const { fallback, ttl, forceLoad } = params\n\n const old = await this.get(forceLoad)\n\n if (!old) {\n if (!fallback) {\n throw new MtArgumentError('Cannot use merge on empty state without fallback.')\n }\n\n const fallback_ = typeof fallback === 'function' ? fallback() : fallback\n\n await this.set({ ...fallback_, ...state }, ttl)\n } else {\n await this.set({ ...old, ...state }, ttl)\n }\n\n // _cached is set by .set()\n\n return this._cached!\n }\n\n /**\n * Delete the state from the storage\n */\n async delete(): Promise<void> {\n this._cached = null\n await this._localStorage.deleteState(this._localKey)\n }\n\n /**\n * Enter some scene\n */\n async enter<SceneState extends object, Scene extends Dispatcher<SceneState>>(\n scene: Scene,\n params?: {\n /**\n * Initial state for the scene\n *\n * Note that this will only work if the scene uses the same key delegate as this state.\n */\n with?: SceneState\n\n /** TTL for the scene (in seconds) */\n ttl?: number\n\n /**\n * If currently in a scoped scene, whether to reset the state\n *\n * @default true\n */\n reset?: boolean\n },\n ): Promise<void> {\n const { with: with_, ttl, reset = true } = params ?? {}\n\n if (reset && this._scoped) await this.delete()\n\n if (!scene['_scene']) {\n throw new MtArgumentError('Cannot enter a non-scene Dispatcher')\n }\n\n if (!scene['_parent']) {\n throw new MtArgumentError('This scene has not been registered')\n }\n\n this._scene = scene['_scene']\n this._scoped = scene['_sceneScoped']\n this._updateLocalKey()\n\n await this._storage.setCurrentScene(this._key, this._scene, ttl)\n\n if (with_) {\n if (scene['_customStateKeyDelegate']) {\n throw new MtArgumentError('Cannot use `with` parameter when the scene uses a custom state key delegate')\n }\n\n await scene.getState(this._key).set(with_, ttl)\n }\n }\n\n /**\n * Exit from current scene to the root\n *\n * @param reset\n * Whether to reset scene state (only applicable in case this is a scoped scene)\n */\n async exit(reset = true): Promise<void> {\n if (reset && this._scoped) await this.delete()\n this._scene = null\n this._updateLocalKey()\n await this._storage.deleteCurrentScene(this._key)\n }\n\n /**\n * Rate limit some handler.\n *\n * When the rate limit exceeds, {@link RateLimitError} is thrown.\n *\n * This is a simple rate-limiting solution that uses\n * the same key as the state. If you need something more\n * sophisticated and/or customizable, you'll have to implement\n * your own rate-limiter.\n *\n * > **Note**: `key` is used to prefix the local key\n * > derived using the given key delegate.\n *\n * @param key Key of the rate limit\n * @param limit Maximum number of requests in `window`\n * @param window Window size in seconds\n * @returns Tuple containing the number of remaining and\n * unix time in ms when the user can try again\n */\n async rateLimit(key: string, limit: number, window: number): Promise<[number, number]> {\n const [remaining, reset] = await this._localStorage.getRateLimit(`${key}:${this._localKey}`, limit, window)\n\n if (!remaining) {\n throw new RateLimitError(reset)\n }\n\n return [remaining - 1, reset]\n }\n\n /**\n * Throttle some handler.\n *\n * When the rate limit exceeds, this function waits for it to reset.\n *\n * This is a simple wrapper over {@link rateLimit}, and follows the same logic.\n *\n * > **Note**: `key` is used to prefix the local key\n * > derived using the given key delegate.\n *\n * @param key Key of the rate limit\n * @param limit Maximum number of requests in `window`\n * @param window Window size in seconds\n * @returns Tuple containing the number of remaining and\n * unix time in ms when the user can try again\n */\n async throttle(key: string, limit: number, window: number): Promise<[number, number]> {\n try {\n return await this.rateLimit(key, limit, window)\n } catch (e: unknown) {\n if (e instanceof RateLimitError) {\n await sleep(e.reset - Date.now())\n\n return this.throttle(key, limit, window)\n }\n\n throw e\n }\n }\n\n /**\n * Reset the rate limit\n *\n * @param key Key of the rate limit\n */\n async resetRateLimit(key: string): Promise<void> {\n await this._localStorage.resetRateLimit(`${key}:${this._localKey}`)\n }\n}\n"]}
package/cjs/wizard.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { MaybeAsync } from '@mtcute/client';
1
+ import { MaybePromise } from '@mtcute/core';
2
2
  import { MessageContext } from './context/message.js';
3
3
  import { Dispatcher } from './dispatcher.js';
4
4
  import { filters } from './filters/index.js';
@@ -55,6 +55,6 @@ export declare class WizardScene<State extends object> extends Dispatcher<State
55
55
  /**
56
56
  * Add a step to the wizard
57
57
  */
58
- addStep(handler: (msg: MessageContext, state: UpdateState<State & WizardInternalState>) => MaybeAsync<WizardSceneAction | number>): void;
58
+ addStep(handler: (msg: MessageContext, state: UpdateState<State & WizardInternalState>) => MaybePromise<WizardSceneAction | number>): void;
59
59
  }
60
60
  export {};
package/cjs/wizard.js CHANGED
@@ -20,7 +20,7 @@ var WizardSceneAction;
20
20
  WizardSceneAction["Next"] = "next";
21
21
  WizardSceneAction["Stay"] = "stay";
22
22
  WizardSceneAction["Exit"] = "exit";
23
- })(WizardSceneAction = exports.WizardSceneAction || (exports.WizardSceneAction = {}));
23
+ })(WizardSceneAction || (exports.WizardSceneAction = WizardSceneAction = {}));
24
24
  /**
25
25
  * Wizard is a special type of Dispatcher
26
26
  * that can be used to simplify implementing
package/cjs/wizard.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"wizard.js","sourceRoot":"","sources":["../../src/wizard.ts"],"names":[],"mappings":";;;AAGA,mDAA4C;AAC5C,iDAA4C;AAG5C;;;;;;;;;;;GAWG;AACH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,kCAAa,CAAA;IACb,kCAAa,CAAA;IACb,kCAAa,CAAA;AACjB,CAAC,EAJW,iBAAiB,GAAjB,yBAAiB,KAAjB,yBAAiB,QAI5B;AAMD;;;;GAIG;AACH,MAAa,WAAkC,SAAQ,0BAAuC;IAA9F;;QACY,WAAM,GAAG,CAAC,CAAA;QAEV,kBAAa,GAAgC,EAAiC,CAAA;IAmF1F,CAAC;IAjFG,eAAe,CAAC,YAAmB;QAC/B,IAAI,CAAC,aAAa,GAAG,YAA2C,CAAA;IACpE,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAuC,EAAE,IAAY;QAChE,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;YACrB,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;SACrB;aAAM;YACH,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CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;gBAElC,OAAM;aACT;YAED,QAAQ,MAAM,EAAE;gBACZ,KAAK,MAAM,CAAC,CAAC;oBACT,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;oBACpC,MAAK;iBACR;gBACD,KAAK,MAAM;oBACP,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;oBAClB,MAAK;aACZ;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAtFD,kCAsFC","sourcesContent":["import { MaybeAsync } from '@mtcute/client'\n\nimport { MessageContext } from './context/message.js'\nimport { Dispatcher } from './dispatcher.js'\nimport { filters } from './filters/index.js'\nimport { UpdateState } from './state/update-state.js'\n\n/**\n * Action for the wizard scene.\n *\n * `Next`: Continue to the next registered step\n * (or exit, if this is the last step)\n *\n * `Stay`: Stay on the same step\n *\n * `Exit`: Exit from the wizard scene\n *\n * You can also return a `number` to jump to that step\n */\nexport enum WizardSceneAction {\n Next = 'next',\n Stay = 'stay',\n Exit = 'exit',\n}\n\ninterface WizardInternalState {\n $step?: number\n}\n\n/**\n * Wizard is a special type of Dispatcher\n * that can be used to simplify implementing\n * step-by-step scenes.\n */\nexport class WizardScene<State extends object> extends Dispatcher<State & WizardInternalState> {\n private _steps = 0\n\n private _defaultState: State & WizardInternalState = {} as State & WizardInternalState\n\n setDefaultState(defaultState: State): void {\n this._defaultState = defaultState as State & WizardInternalState\n }\n\n /**\n * Get the total number of registered steps\n */\n get totalSteps(): number {\n return this._steps\n }\n\n /**\n * Go to the Nth step\n */\n async goToStep(state: UpdateState<WizardInternalState>, step: number) {\n if (step >= this._steps) {\n await state.exit()\n } else {\n await state.merge({ $step: step }, this._defaultState)\n }\n }\n\n /**\n * Skip N steps\n */\n async skip(state: UpdateState<WizardInternalState>, count = 1) {\n const { $step } = (await state.get()) || {}\n if ($step === undefined) throw new Error('Wizard state is not initialized')\n\n return this.goToStep(state, $step + count)\n }\n\n /**\n * Filter that will only pass if the current step is `step`\n */\n static onNthStep(step: number) {\n const filter = filters.state<WizardInternalState>((it) => it.$step === step)\n\n if (step === 0) return filters.or(filters.stateEmpty, filter)\n\n return filter\n }\n\n /**\n * Filter that will only pass if the current step is the one after last one added\n */\n onCurrentStep() {\n return WizardScene.onNthStep(this._steps)\n }\n\n /**\n * Add a step to the wizard\n */\n addStep(\n handler: (\n msg: MessageContext,\n state: UpdateState<State & WizardInternalState>,\n ) => MaybeAsync<WizardSceneAction | number>,\n ): void {\n const step = this._steps++\n\n this.onNewMessage(WizardScene.onNthStep(step), async (msg, state) => {\n const result = await handler(msg, state)\n\n if (typeof result === 'number') {\n await this.goToStep(state, result)\n\n return\n }\n\n switch (result) {\n case 'next': {\n await this.goToStep(state, step + 1)\n break\n }\n case 'exit':\n await state.exit()\n break\n }\n })\n }\n}\n"]}
1
+ {"version":3,"file":"wizard.js","sourceRoot":"","sources":["../../src/wizard.ts"],"names":[],"mappings":";;;AAGA,mDAA4C;AAC5C,iDAA4C;AAG5C;;;;;;;;;;;GAWG;AACH,IAAY,iBAIX;AAJD,WAAY,iBAAiB;IACzB,kCAAa,CAAA;IACb,kCAAa,CAAA;IACb,kCAAa,CAAA;AACjB,CAAC,EAJW,iBAAiB,iCAAjB,iBAAiB,QAI5B;AAMD;;;;GAIG;AACH,MAAa,WAAkC,SAAQ,0BAAuC;IAA9F;;QACY,WAAM,GAAG,CAAC,CAAA;QAEV,kBAAa,GAAgC,EAAiC,CAAA;IAmF1F,CAAC;IAjFG,eAAe,CAAC,YAAmB;QAC/B,IAAI,CAAC,aAAa,GAAG,YAA2C,CAAA;IACpE,CAAC;IAED;;OAEG;IACH,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,MAAM,CAAA;IACtB,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,QAAQ,CAAC,KAAuC,EAAE,IAAY;QAChE,IAAI,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE;YACrB,MAAM,KAAK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,EAAE;gBAC5B,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;gBAElC,OAAM;aACT;YAED,QAAQ,MAAM,EAAE;gBACZ,KAAK,MAAM,CAAC,CAAC;oBACT,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,GAAG,CAAC,CAAC,CAAA;oBACpC,MAAK;iBACR;gBACD,KAAK,MAAM;oBACP,MAAM,KAAK,CAAC,IAAI,EAAE,CAAA;oBAClB,MAAK;aACZ;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AAtFD,kCAsFC","sourcesContent":["import { MaybePromise } from '@mtcute/core'\n\nimport { MessageContext } from './context/message.js'\nimport { Dispatcher } from './dispatcher.js'\nimport { filters } from './filters/index.js'\nimport { UpdateState } from './state/update-state.js'\n\n/**\n * Action for the wizard scene.\n *\n * `Next`: Continue to the next registered step\n * (or exit, if this is the last step)\n *\n * `Stay`: Stay on the same step\n *\n * `Exit`: Exit from the wizard scene\n *\n * You can also return a `number` to jump to that step\n */\nexport enum WizardSceneAction {\n Next = 'next',\n Stay = 'stay',\n Exit = 'exit',\n}\n\ninterface WizardInternalState {\n $step?: number\n}\n\n/**\n * Wizard is a special type of Dispatcher\n * that can be used to simplify implementing\n * step-by-step scenes.\n */\nexport class WizardScene<State extends object> extends Dispatcher<State & WizardInternalState> {\n private _steps = 0\n\n private _defaultState: State & WizardInternalState = {} as State & WizardInternalState\n\n setDefaultState(defaultState: State): void {\n this._defaultState = defaultState as State & WizardInternalState\n }\n\n /**\n * Get the total number of registered steps\n */\n get totalSteps(): number {\n return this._steps\n }\n\n /**\n * Go to the Nth step\n */\n async goToStep(state: UpdateState<WizardInternalState>, step: number) {\n if (step >= this._steps) {\n await state.exit()\n } else {\n await state.merge({ $step: step }, this._defaultState)\n }\n }\n\n /**\n * Skip N steps\n */\n async skip(state: UpdateState<WizardInternalState>, count = 1) {\n const { $step } = (await state.get()) || {}\n if ($step === undefined) throw new Error('Wizard state is not initialized')\n\n return this.goToStep(state, $step + count)\n }\n\n /**\n * Filter that will only pass if the current step is `step`\n */\n static onNthStep(step: number) {\n const filter = filters.state<WizardInternalState>((it) => it.$step === step)\n\n if (step === 0) return filters.or(filters.stateEmpty, filter)\n\n return filter\n }\n\n /**\n * Filter that will only pass if the current step is the one after last one added\n */\n onCurrentStep() {\n return WizardScene.onNthStep(this._steps)\n }\n\n /**\n * Add a step to the wizard\n */\n addStep(\n handler: (\n msg: MessageContext,\n state: UpdateState<State & WizardInternalState>,\n ) => MaybePromise<WizardSceneAction | number>,\n ): void {\n const step = this._steps++\n\n this.onNewMessage(WizardScene.onNthStep(step), async (msg, state) => {\n const result = await handler(msg, state)\n\n if (typeof result === 'number') {\n await this.goToStep(state, result)\n\n return\n }\n\n switch (result) {\n case 'next': {\n await this.goToStep(state, step + 1)\n break\n }\n case 'exit':\n await state.exit()\n break\n }\n })\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { CallbackQuery, MaybeArray } from '@mtcute/client';
1
+ import { CallbackQuery, MaybeArray } from '@mtcute/core';
2
2
  import { UpdateFilter } from './filters/types.js';
3
3
  /**
4
4
  * Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).
@@ -1,4 +1,4 @@
1
- import { MtArgumentError } from '@mtcute/client';
1
+ import { MtArgumentError } from '@mtcute/core';
2
2
  /**
3
3
  * Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"callback-data-builder.js","sourceRoot":"","sources":["../../src/callback-data-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAI3E;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IAK5B;;;OAGG;IACH,YACW,MAAc,EACrB,GAAG,MAAW;QADP,WAAM,GAAN,MAAM,CAAQ;QAPzB,QAAG,GAAG,GAAG,CAAA;QAUL,IAAI,CAAC,OAAO,G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ACrC,IAAI,CAAC,CAAC;gBAAE,OAAO,KAAK,CACnB;YACG,KAGH,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAE1B,OAAO,IAAI,CAAA;QACf,CAAC,CAAA;IACL,CAAC;CACJ","sourcesContent":["import { CallbackQuery, MaybeArray, MtArgumentError } from '@mtcute/client'\n\nimport { UpdateFilter } from './filters/types.js'\n\n/**\n * Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).\n *\n * This can be used to simplify management of different callbacks.\n *\n * [Learn more in the docs](/guide/topics/keyboards.html#callback-data-builders)\n */\nexport class CallbackDataBuilder<T extends string> {\n private readonly _fields: T[]\n\n sep = ':'\n\n /**\n * @param prefix Prefix for the data. Use something unique across your bot.\n * @param fields Field names in the order they will be serialized.\n */\n constructor(\n public prefix: string,\n ...fields: T[]\n ) {\n this._fields = fields\n }\n\n /**\n * Build a callback data string\n *\n * @param obj Object containing the data\n */\n build(obj: Record<T, string>): string {\n const ret =\n this.prefix +\n this.sep +\n this._fields\n .map((f) => {\n const val = obj[f]\n\n if (val.includes(this.sep)) {\n throw new MtArgumentError(\n `Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`,\n )\n }\n\n return val\n })\n .join(this.sep)\n\n if (ret.length > 64) {\n throw new MtArgumentError('Resulting callback data is too long.')\n }\n\n return ret\n }\n\n /**\n * Parse callback data to object\n *\n * @param data Callback data as string\n */\n parse(data: string): Record<T, string> {\n const parts = data.split(this.sep)\n\n if (parts[0] !== this.prefix) {\n throw new MtArgumentError('Invalid data passed')\n }\n\n if (parts.length !== this._fields.length + 1) {\n throw new MtArgumentError('Invalid data passed')\n }\n\n const ret = {} as Record<T, string>\n parts.forEach((it, idx) => {\n if (idx === 0) return // skip prefix\n\n ret[this._fields[idx - 1]] = it\n })\n\n return ret\n }\n\n /**\n * Create a filter for this callback data.\n *\n * > **Note**: `params` object will be compiled to a RegExp,\n * > so avoid using characters that have special meaning in regex,\n * > or use RegExp directly to let the IDE guide you.\n *\n * @param params\n */\n filter(params: Partial<Record<T, MaybeArray<string | RegExp>>> = {}): UpdateFilter<\n CallbackQuery,\n {\n match: Record<T, string>\n }\n > {\n const parts: string[] = []\n\n this._fields.forEach((field) => {\n if (!(field in params)) {\n parts.push(`[^${this.sep}]*?`)\n\n return\n }\n\n const value = params[field]\n\n if (Array.isArray(value)) {\n parts.push(`(${value.map((i) => (typeof i === 'string' ? i : i.source)).join('|')})`)\n } else {\n // noinspection SuspiciousTypeOfGuard\n parts.push(typeof value === 'string' ? value : (value as RegExp).source)\n }\n })\n\n const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`)\n\n return (query) => {\n const m = query.dataStr?.match(regex)\n if (!m) return false\n ;(\n query as CallbackQuery & {\n match: Record<T, string>\n }\n ).match = this.parse(m[0])\n\n return true\n }\n }\n}\n"]}
1
+ {"version":3,"file":"callback-data-builder.js","sourceRoot":"","sources":["../../src/callback-data-builder.ts"],"names":[],"mappings":"AAAA,OAAO,EAA6B,eAAe,EAAE,MAAM,cAAc,CAAA;AAIzE;;;;;;GAMG;AACH,MAAM,OAAO,mBAAmB;IAK5B;;;OAGG;IACH,YACW,MAAc,EACrB,GAAG,MAAW;QADP,WAAM,GAAN,MAAM,CAAQ;QAPzB,QAAG,GAAG,GAAG,CAAA;QAUL,IAAI,CAAC,OAAO,GAAG,MAAM,CAAA;IACzB,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,GAAsB;QACxB,MAAM,GAAG,GACL,IAAI,CAAC,MAAM;YACX,IAAI,CAAC,GAAG;YACR,IAAI,CAAC,OAAO;iBACP,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBACP,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;gBAElB,IAAI,GAAG,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;oBACxB,MAAM,IAAI,eAAe,CACrB,aAAa,CAAC,IA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,CAAC,GAAG,KAAK,CAAC,CAAA;gBAE9B,OAAM;aACT;YAED,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAA;YAE3B,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;gBACtB,KAAK,CAAC,IAAI,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;aACxF;iBAAM;gBACH,qCAAqC;gBACrC,KAAK,CAAC,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAE,KAAgB,CAAC,MAAM,CAAC,CAAA;aAC3E;QACL,CAAC,CAAC,CAAA;QAEF,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA;QAE9E,OAAO,CAAC,KAAK,EAAE,EAAE;YACb,MAAM,CAAC,GAAG,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,KAAK,CAAC,CAAA;YACrC,IAAI,CAAC,CAAC;gBAAE,OAAO,KAAK,CACnB;YACG,KAGH,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAE1B,OAAO,IAAI,CAAA;QACf,CAAC,CAAA;IACL,CAAC;CACJ","sourcesContent":["import { CallbackQuery, MaybeArray, MtArgumentError } from '@mtcute/core'\n\nimport { UpdateFilter } from './filters/types.js'\n\n/**\n * Callback data builder, inspired by [aiogram](https://github.com/aiogram/aiogram).\n *\n * This can be used to simplify management of different callbacks.\n *\n * [Learn more in the docs](/guide/topics/keyboards.html#callback-data-builders)\n */\nexport class CallbackDataBuilder<T extends string> {\n private readonly _fields: T[]\n\n sep = ':'\n\n /**\n * @param prefix Prefix for the data. Use something unique across your bot.\n * @param fields Field names in the order they will be serialized.\n */\n constructor(\n public prefix: string,\n ...fields: T[]\n ) {\n this._fields = fields\n }\n\n /**\n * Build a callback data string\n *\n * @param obj Object containing the data\n */\n build(obj: Record<T, string>): string {\n const ret =\n this.prefix +\n this.sep +\n this._fields\n .map((f) => {\n const val = obj[f]\n\n if (val.includes(this.sep)) {\n throw new MtArgumentError(\n `Value for ${f} ${val} contains separator ${this.sep} and cannot be used.`,\n )\n }\n\n return val\n })\n .join(this.sep)\n\n if (ret.length > 64) {\n throw new MtArgumentError('Resulting callback data is too long.')\n }\n\n return ret\n }\n\n /**\n * Parse callback data to object\n *\n * @param data Callback data as string\n */\n parse(data: string): Record<T, string> {\n const parts = data.split(this.sep)\n\n if (parts[0] !== this.prefix) {\n throw new MtArgumentError('Invalid data passed')\n }\n\n if (parts.length !== this._fields.length + 1) {\n throw new MtArgumentError('Invalid data passed')\n }\n\n const ret = {} as Record<T, string>\n parts.forEach((it, idx) => {\n if (idx === 0) return // skip prefix\n\n ret[this._fields[idx - 1]] = it\n })\n\n return ret\n }\n\n /**\n * Create a filter for this callback data.\n *\n * > **Note**: `params` object will be compiled to a RegExp,\n * > so avoid using characters that have special meaning in regex,\n * > or use RegExp directly to let the IDE guide you.\n *\n * @param params\n */\n filter(params: Partial<Record<T, MaybeArray<string | RegExp>>> = {}): UpdateFilter<\n CallbackQuery,\n {\n match: Record<T, string>\n }\n > {\n const parts: string[] = []\n\n this._fields.forEach((field) => {\n if (!(field in params)) {\n parts.push(`[^${this.sep}]*?`)\n\n return\n }\n\n const value = params[field]\n\n if (Array.isArray(value)) {\n parts.push(`(${value.map((i) => (typeof i === 'string' ? i : i.source)).join('|')})`)\n } else {\n // noinspection SuspiciousTypeOfGuard\n parts.push(typeof value === 'string' ? value : (value as RegExp).source)\n }\n })\n\n const regex = new RegExp(`^${this.prefix}${this.sep}${parts.join(this.sep)}$`)\n\n return (query) => {\n const m = query.dataStr?.match(regex)\n if (!m) return false\n ;(\n query as CallbackQuery & {\n match: Record<T, string>\n }\n ).match = this.parse(m[0])\n\n return true\n }\n }\n}\n"]}
@@ -1,6 +1,6 @@
1
1
  import { describe, expect, it } from 'vitest';
2
- import { CallbackQuery, MtArgumentError, PeersIndex } from '@mtcute/client';
3
- import { utf8EncodeToBuffer } from '@mtcute/client/utils.js';
2
+ import { CallbackQuery, MtArgumentError, PeersIndex } from '@mtcute/core';
3
+ import { utf8EncodeToBuffer } from '@mtcute/core/utils.js';
4
4
  import { createStub } from '@mtcute/test';
5
5
  import { CallbackDataBuilder } from './callback-data-builder.js';
6
6
  describe('CallbackDataBuilder', () => {
@@ -1 +1 @@
1
- {"version":3,"file":"callback-data-builder.test.js","sourceRoot":"","sources":["../../src/callback-data-builder.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAGhE,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAE3D,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,gBAAgB,C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,CAAC,CAAA;QAC5E,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC1C,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YAE3D,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzE,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,KAAK;aACb,CAAC,CAAA;YACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAChD,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YAE3D,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzE,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,KAAK;aACb,CAAC,CAAA;YACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { CallbackQuery, MtArgumentError, PeersIndex } from '@mtcute/client'\nimport { utf8EncodeToBuffer } from '@mtcute/client/utils.js'\nimport { createStub } from '@mtcute/test'\n\nimport { CallbackDataBuilder } from './callback-data-builder.js'\nimport { UpdateFilter } from './filters/index.js'\n\ndescribe('CallbackDataBuilder', () => {\n it('should correctly build data', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(cdb.build({ foo: 'foo', bar: 'bar' })).toEqual('prefix:foo:bar')\n })\n\n it('should correctly throw on invalid data when building', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.build({ foo: 'foo:1', bar: 'bar' })).toThrow(MtArgumentError)\n })\n\n it('should correctly throw on too long data when building', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() =>\n cdb.build({\n foo: 'foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo',\n bar: 'bar',\n }),\n ).toThrow(MtArgumentError)\n })\n\n it('should correctly parse data', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(cdb.parse('prefix:foo:bar')).toEqual({ foo: 'foo', bar: 'bar' })\n })\n\n it('should throw on invalid prefix when parsing', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.parse('123:foo:bar')).toThrow(MtArgumentError)\n })\n\n it('should throw on invalid parts count when parsing', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.parse('prefix:foo:bar:baz')).toThrow(MtArgumentError)\n })\n\n describe('filter', () => {\n const createCb = (data: string) =>\n new CallbackQuery(\n createStub('updateBotCallbackQuery', {\n data: utf8EncodeToBuffer(data),\n }),\n new PeersIndex(),\n )\n\n const getFilterMatch = (filter: UpdateFilter<CallbackQuery>, data: string) => {\n const cb = createCb(data)\n\n const matched = filter(cb)\n if (!matched) return null\n\n // eslint-disable-next-line\n return (cb as any).match\n }\n\n it('should create a filter without params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter(), 'prefix:foo:bar')).toEqual({\n foo: 'foo',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter(), 'prefix:foo:bar:baz')).toEqual(null)\n })\n\n it('should create a filter with params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter({ foo: 'foo' }), 'prefix:foo:bar')).toEqual({\n foo: 'foo',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter({ foo: 'foo' }), 'prefix:bar:bar')).toEqual(null)\n })\n\n it('should create a filter with regex params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter({ foo: /\\d+/ }), 'prefix:123:bar')).toEqual({\n foo: '123',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter({ foo: /\\d+/ }), 'prefix:bar:bar')).toEqual(null)\n })\n })\n})\n"]}
1
+ {"version":3,"file":"callback-data-builder.test.js","sourceRoot":"","sources":["../../src/callback-data-builder.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAE7C,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAC1D,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEzC,OAAO,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AAGhE,QAAQ,CAAC,qBAAqB,EAAE,GAAG,EAAE;IACjC,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACnC,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;QAE3D,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,OAAO,C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AO,CAAC,IAAI,CAAC,CAAA;QAC5E,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,oCAAoC,EAAE,GAAG,EAAE;YAC1C,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YAE3D,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzE,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,KAAK;aACb,CAAC,CAAA;YACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;QAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;YAChD,MAAM,GAAG,GAAG,IAAI,mBAAmB,CAAC,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,CAAA;YAE3D,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC;gBACzE,GAAG,EAAE,KAAK;gBACV,GAAG,EAAE,KAAK;aACb,CAAC,CAAA;YACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,CAAC,CAAA;QACtF,CAAC,CAAC,CAAA;IACN,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import { describe, expect, it } from 'vitest'\n\nimport { CallbackQuery, MtArgumentError, PeersIndex } from '@mtcute/core'\nimport { utf8EncodeToBuffer } from '@mtcute/core/utils.js'\nimport { createStub } from '@mtcute/test'\n\nimport { CallbackDataBuilder } from './callback-data-builder.js'\nimport { UpdateFilter } from './filters/index.js'\n\ndescribe('CallbackDataBuilder', () => {\n it('should correctly build data', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(cdb.build({ foo: 'foo', bar: 'bar' })).toEqual('prefix:foo:bar')\n })\n\n it('should correctly throw on invalid data when building', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.build({ foo: 'foo:1', bar: 'bar' })).toThrow(MtArgumentError)\n })\n\n it('should correctly throw on too long data when building', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() =>\n cdb.build({\n foo: 'foooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo',\n bar: 'bar',\n }),\n ).toThrow(MtArgumentError)\n })\n\n it('should correctly parse data', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(cdb.parse('prefix:foo:bar')).toEqual({ foo: 'foo', bar: 'bar' })\n })\n\n it('should throw on invalid prefix when parsing', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.parse('123:foo:bar')).toThrow(MtArgumentError)\n })\n\n it('should throw on invalid parts count when parsing', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(() => cdb.parse('prefix:foo:bar:baz')).toThrow(MtArgumentError)\n })\n\n describe('filter', () => {\n const createCb = (data: string) =>\n new CallbackQuery(\n createStub('updateBotCallbackQuery', {\n data: utf8EncodeToBuffer(data),\n }),\n new PeersIndex(),\n )\n\n const getFilterMatch = (filter: UpdateFilter<CallbackQuery>, data: string) => {\n const cb = createCb(data)\n\n const matched = filter(cb)\n if (!matched) return null\n\n // eslint-disable-next-line\n return (cb as any).match\n }\n\n it('should create a filter without params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter(), 'prefix:foo:bar')).toEqual({\n foo: 'foo',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter(), 'prefix:foo:bar:baz')).toEqual(null)\n })\n\n it('should create a filter with params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter({ foo: 'foo' }), 'prefix:foo:bar')).toEqual({\n foo: 'foo',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter({ foo: 'foo' }), 'prefix:bar:bar')).toEqual(null)\n })\n\n it('should create a filter with regex params', () => {\n const cdb = new CallbackDataBuilder('prefix', 'foo', 'bar')\n\n expect(getFilterMatch(cdb.filter({ foo: /\\d+/ }), 'prefix:123:bar')).toEqual({\n foo: '123',\n bar: 'bar',\n })\n expect(getFilterMatch(cdb.filter({ foo: /\\d+/ }), 'prefix:bar:bar')).toEqual(null)\n })\n })\n})\n"]}
@@ -1,4 +1,4 @@
1
- import { ParsedUpdate, TelegramClient } from '@mtcute/client';
1
+ import { ParsedUpdate, TelegramClient } from '@mtcute/core';
2
2
  export type UpdateContext<T> = T & {
3
3
  client: TelegramClient;
4
4
  _name: Extract<ParsedUpdate, {
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate, TelegramClient } from '@mtcute/client'\n\nexport type UpdateContext<T> = T & {\n client: TelegramClient\n _name: Extract<ParsedUpdate, { data: T }>['name']\n}\n\nexport type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/context/base.ts"],"names":[],"mappings":"","sourcesContent":["import { ParsedUpdate, TelegramClient } from '@mtcute/core'\n\nexport type UpdateContext<T> = T & {\n client: TelegramClient\n _name: Extract<ParsedUpdate, { data: T }>['name']\n}\n\nexport type UpdateContextDistributed<T> = T extends never ? never : UpdateContext<T>\n"]}
@@ -1,4 +1,4 @@
1
- import { CallbackQuery, InlineCallbackQuery, MaybeAsync, Message, TelegramClient } from '@mtcute/client';
1
+ import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message, TelegramClient } from '@mtcute/core';
2
2
  import { UpdateContext } from './base.js';
3
3
  /**
4
4
  * Context of a callback query update.
@@ -25,7 +25,7 @@ export declare class CallbackQueryContext extends CallbackQuery implements Updat
25
25
  /**
26
26
  * Shortcut for getting the message and editing it.
27
27
  */
28
- editMessageWith(handler: (msg: Message) => MaybeAsync<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<Message | undefined>;
28
+ editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>): Promise<Message | undefined>;
29
29
  }
30
30
  /**
31
31
  * Context of an inline-originated callback query update.
@@ -1,4 +1,4 @@
1
- import { CallbackQuery, InlineCallbackQuery } from '@mtcute/client';
1
+ import { CallbackQuery, InlineCallbackQuery } from '@mtcute/core';
2
2
  /**
3
3
  * Context of a callback query update.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAuC,MAAM,gBAAgB,CAAA;AAIxG;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAGnD,YACa,MAAsB,EAC/B,KAAoB;QAEpB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,gBAAgB,CAAA;IAOjC,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU;QACZ,OAAO,IAAI,CAAC,MA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Query, MaybeAsync, Message, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Get the message containing the callback button being clicked.\n *\n * Note that the message may have been deleted, in which case\n * `null` will be returned.\n */\n async getMessage(): Promise<Message | null> {\n return this.client.getCallbackQueryMessage(this)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n\n /**\n * Shortcut for getting the message and editing it.\n */\n async editMessageWith(handler: (msg: Message) => MaybeAsync<Parameters<CallbackQueryContext['editMessage']>[0]>) {\n const msg = await this.getMessage()\n if (!msg) return\n\n const res = await handler(msg)\n if (!res) return\n\n return this.editMessage(res)\n }\n}\n\n/**\n * Context of an inline-originated callback query update.\n *\n * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.\n */\nexport class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {\n readonly _name = 'inline_callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineCallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"callback-query.js","sourceRoot":"","sources":["../../../src/context/callback-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAyC,MAAM,cAAc,CAAA;AAIxG;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,aAAa;IAGnD,YACa,MAAsB,EAC/B,KAAoB;QAEpB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,gBAAgB,CAAA;IAOjC,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;;;;OAKG;IACH,KAAK,CAAC,UAAU;QACZ,OAAO,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAA;IACpD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;YAC3B,MAAM,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI;YACrB,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;YACvB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,eAAe,CAAC,OAA2F;QAC7G,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,UAAU,EAAE,CAAA;QACnC,IAAI,CAAC,GAAG;YAAE,OAAM;QAEhB,MAAM,GAAG,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,CAAA;QAC9B,IAAI,CAAC,GAAG;YAAE,OAAM;QAEhB,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;CACJ;AAED;;;;GAIG;AACH,MAAM,OAAO,0BAA2B,SAAQ,mBAAmB;IAG/D,YACa,MAAsB,EAC/B,KAA0B;QAE1B,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,uBAAuB,CAAA;IAOxC,CAAC;IAED,oCAAoC;IACpC,MAAM,CAAC,MAA4D;QAC/D,OAAO,IAAI,CAAC,MAAM,CAAC,mBAAmB,CAAC,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW,CAAC,MAA6E;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;YACzB,GAAG,MAAM;SACZ,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { CallbackQuery, InlineCallbackQuery, MaybePromise, Message, TelegramClient } from '@mtcute/core'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a callback query update.\n *\n * This is a subclass of {@link CallbackQuery}, so all its fields are also available.\n */\nexport class CallbackQueryContext extends CallbackQuery implements UpdateContext<CallbackQuery> {\n readonly _name = 'callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: CallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Get the message containing the callback button being clicked.\n *\n * Note that the message may have been deleted, in which case\n * `null` will be returned.\n */\n async getMessage(): Promise<Message | null> {\n return this.client.getCallbackQueryMessage(this)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editMessage({\n chatId: this.raw.peer,\n message: this.raw.msgId,\n ...params,\n })\n }\n\n /**\n * Shortcut for getting the message and editing it.\n */\n async editMessageWith(handler: (msg: Message) => MaybePromise<Parameters<CallbackQueryContext['editMessage']>[0]>) {\n const msg = await this.getMessage()\n if (!msg) return\n\n const res = await handler(msg)\n if (!res) return\n\n return this.editMessage(res)\n }\n}\n\n/**\n * Context of an inline-originated callback query update.\n *\n * This is a subclass of {@link InlineCallbackQuery}, so all its fields are also available.\n */\nexport class InlineCallbackQueryContext extends InlineCallbackQuery implements UpdateContext<InlineCallbackQuery> {\n readonly _name = 'inline_callback_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineCallbackQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this callback query */\n answer(params: Parameters<TelegramClient['answerCallbackQuery']>[1]) {\n return this.client.answerCallbackQuery(this.id, params)\n }\n\n /**\n * Edit the message that contained the callback button that was clicked.\n */\n async editMessage(params: Omit<Parameters<TelegramClient['editInlineMessage']>[0], 'messageId'>) {\n return this.client.editInlineMessage({\n messageId: this.raw.msgId,\n ...params,\n })\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/client';
1
+ import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/core';
2
2
  import { UpdateContext } from './base.js';
3
3
  /**
4
4
  * Context of a chat join request update (for bots).
@@ -1,4 +1,4 @@
1
- import { BotChatJoinRequestUpdate } from '@mtcute/client';
1
+ import { BotChatJoinRequestUpdate } from '@mtcute/core';
2
2
  /**
3
3
  * Context of a chat join request update (for bots).
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAkB,MAAM,gBAAgB,CAAA;AAIzE;;;;GAIG;AACH,MAAM,OAAO,4BACT,SAAQ,wBAAwB;IAIhC,YACa,MAAsB,EAC/B,MAAgC;QAEhC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,uBAAuB,CAAA;IAOxC,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chat join request update (for bots).\n *\n * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.\n */\nexport class ChatJoinRequestUpdateContext\n extends BotChatJoinRequestUpdate\n implements UpdateContext<BotChatJoinRequestUpdate> {\n readonly _name = 'bot_chat_join_request'\n\n constructor(\n readonly client: TelegramClient,\n update: BotChatJoinRequestUpdate,\n ) {\n super(update.raw, update._peers)\n }\n\n /** Approve the request */\n approve(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'approve',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n\n /** Decline the request */\n decline(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'decline',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"chat-join-request.js","sourceRoot":"","sources":["../../../src/context/chat-join-request.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAkB,MAAM,cAAc,CAAA;AAIvE;;;;GAIG;AACH,MAAM,OAAO,4BACT,SAAQ,wBAAwB;IAIhC,YACa,MAAsB,EAC/B,MAAgC;QAEhC,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,uBAAuB,CAAA;IAOxC,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;IAED,0BAA0B;IAC1B,OAAO;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC;YAC/B,MAAM,EAAE,SAAS;YACjB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;YACzB,MAAM,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS;SAC9B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { BotChatJoinRequestUpdate, TelegramClient } from '@mtcute/core'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chat join request update (for bots).\n *\n * This is a subclass of {@link BotChatJoinRequestUpdate}, so all its fields are also available.\n */\nexport class ChatJoinRequestUpdateContext\n extends BotChatJoinRequestUpdate\n implements UpdateContext<BotChatJoinRequestUpdate> {\n readonly _name = 'bot_chat_join_request'\n\n constructor(\n readonly client: TelegramClient,\n update: BotChatJoinRequestUpdate,\n ) {\n super(update.raw, update._peers)\n }\n\n /** Approve the request */\n approve(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'approve',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n\n /** Decline the request */\n decline(): Promise<void> {\n return this.client.hideJoinRequest({\n action: 'decline',\n user: this.user.inputPeer,\n chatId: this.chat.inputPeer,\n })\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { ChosenInlineResult, TelegramClient } from '@mtcute/client';
1
+ import { ChosenInlineResult, TelegramClient } from '@mtcute/core';
2
2
  import { UpdateContext } from './base.js';
3
3
  /**
4
4
  * Context of a chosen inline result update.
@@ -1,4 +1,4 @@
1
- import { ChosenInlineResult, MtArgumentError } from '@mtcute/client';
1
+ import { ChosenInlineResult, MtArgumentError } from '@mtcute/core';
2
2
  /**
3
3
  * Context of a chosen inline result update.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAkB,MAAM,gBAAgB,CAAA;AAIpF;;;;;;;GAOG;AACH,MAAM,OAAO,yBAA0B,SAAQ,kBAAkB;IAG7D,YACa,MAAsB,EAC/B,MAA0B;QAE1B,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,sBAAsB,CAAA;IAOvC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,MAA0D;QACxE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;YACjB,MAAM,IAAI,eAAe,CAAC,0DAA0D,CAAC,CAAA;SACxF;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;SAC5B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { ChosenInlineResult, MtArgumentError, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chosen inline result update.\n *\n * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.\n *\n * > **Note**: To receive these updates, you must enable\n * > Inline feedback in [@BotFather](//t.me/botfather)\n */\nexport class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {\n readonly _name = 'chosen_inline_result'\n\n constructor(\n readonly client: TelegramClient,\n result: ChosenInlineResult,\n ) {\n super(result.raw, result._peers)\n }\n\n /**\n * Edit the message that was sent when this inline result that was chosen.\n *\n * > **Note**: This method can only be used if the message contained a reply markup\n */\n async editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void> {\n if (!this.raw.msgId) {\n throw new MtArgumentError('No message ID, make sure you have included reply markup!')\n }\n\n return this.client.editInlineMessage({\n ...params,\n messageId: this.raw.msgId,\n })\n }\n}\n"]}
1
+ {"version":3,"file":"chosen-inline-result.js","sourceRoot":"","sources":["../../../src/context/chosen-inline-result.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAkB,MAAM,cAAc,CAAA;AAIlF;;;;;;;GAOG;AACH,MAAM,OAAO,yBAA0B,SAAQ,kBAAkB;IAG7D,YACa,MAAsB,EAC/B,MAA0B;QAE1B,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAA;QAHvB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,sBAAsB,CAAA;IAOvC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,WAAW,CAAC,MAA0D;QACxE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE;YACjB,MAAM,IAAI,eAAe,CAAC,0DAA0D,CAAC,CAAA;SACxF;QAED,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC;YACjC,GAAG,MAAM;YACT,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,KAAK;SAC5B,CAAC,CAAA;IACN,CAAC;CACJ","sourcesContent":["import { ChosenInlineResult, MtArgumentError, TelegramClient } from '@mtcute/core'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of a chosen inline result update.\n *\n * This is a subclass of {@link ChosenInlineResult}, so all its fields are also available.\n *\n * > **Note**: To receive these updates, you must enable\n * > Inline feedback in [@BotFather](//t.me/botfather)\n */\nexport class ChosenInlineResultContext extends ChosenInlineResult implements UpdateContext<ChosenInlineResult> {\n readonly _name = 'chosen_inline_result'\n\n constructor(\n readonly client: TelegramClient,\n result: ChosenInlineResult,\n ) {\n super(result.raw, result._peers)\n }\n\n /**\n * Edit the message that was sent when this inline result that was chosen.\n *\n * > **Note**: This method can only be used if the message contained a reply markup\n */\n async editMessage(params: Parameters<TelegramClient['editInlineMessage']>[0]): Promise<void> {\n if (!this.raw.msgId) {\n throw new MtArgumentError('No message ID, make sure you have included reply markup!')\n }\n\n return this.client.editInlineMessage({\n ...params,\n messageId: this.raw.msgId,\n })\n }\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/client';
1
+ import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/core';
2
2
  import { UpdateContext } from './base.js';
3
3
  /**
4
4
  * Context of an inline query update.
@@ -1,4 +1,4 @@
1
- import { InlineQuery } from '@mtcute/client';
1
+ import { InlineQuery } from '@mtcute/core';
2
2
  /**
3
3
  * Context of an inline query update.
4
4
  *
@@ -1 +1 @@
1
- {"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmC,MAAM,gBAAgB,CAAA;AAI7E;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAG/C,YACa,MAAsB,EAC/B,KAAkB;QAElB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,cAAc,CAAA;IAO/B,CAAC;IAED,kCAAkC;IAClC,MAAM,CAAC,GAAG,MAA4D;QAClE,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5D,CAAC;CACJ","sourcesContent":["import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/client'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of an inline query update.\n *\n * This is a subclass of {@link InlineQuery}, so all its fields are also available.\n */\nexport class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {\n readonly _name = 'inline_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this inline query */\n answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>) {\n return this.client.answerInlineQuery(this.id, ...params)\n }\n}\n"]}
1
+ {"version":3,"file":"inline-query.js","sourceRoot":"","sources":["../../../src/context/inline-query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAmC,MAAM,cAAc,CAAA;AAI3E;;;;GAIG;AACH,MAAM,OAAO,kBAAmB,SAAQ,WAAW;IAG/C,YACa,MAAsB,EAC/B,KAAkB;QAElB,KAAK,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,MAAM,CAAC,CAAA;QAHrB,WAAM,GAAN,MAAM,CAAgB;QAH1B,UAAK,GAAG,cAAc,CAAA;IAO/B,CAAC;IAED,kCAAkC;IAClC,MAAM,CAAC,GAAG,MAA4D;QAClE,OAAO,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,IAAI,CAAC,EAAE,EAAE,GAAG,MAAM,CAAC,CAAA;IAC5D,CAAC;CACJ","sourcesContent":["import { InlineQuery, ParametersSkip1, TelegramClient } from '@mtcute/core'\n\nimport { UpdateContext } from './base.js'\n\n/**\n * Context of an inline query update.\n *\n * This is a subclass of {@link InlineQuery}, so all its fields are also available.\n */\nexport class InlineQueryContext extends InlineQuery implements UpdateContext<InlineQuery> {\n readonly _name = 'inline_query'\n\n constructor(\n readonly client: TelegramClient,\n query: InlineQuery,\n ) {\n super(query.raw, query._peers)\n }\n\n /** Answer to this inline query */\n answer(...params: ParametersSkip1<TelegramClient['answerInlineQuery']>) {\n return this.client.answerInlineQuery(this.id, ...params)\n }\n}\n"]}
@@ -1,8 +1,8 @@
1
- import { Message, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/client';
2
- import { DeleteMessagesParams } from '@mtcute/client/methods/messages/delete-messages.js';
3
- import { ForwardMessageOptions } from '@mtcute/client/methods/messages/forward-messages.js';
4
- import { SendCopyParams } from '@mtcute/client/methods/messages/send-copy.js';
5
- import { SendCopyGroupParams } from '@mtcute/client/methods/messages/send-copy-group.js';
1
+ import { Message, OmitInputMessageId, ParametersSkip1, Peer, TelegramClient } from '@mtcute/core';
2
+ import { DeleteMessagesParams } from '@mtcute/core/highlevel/methods/messages/delete-messages.js';
3
+ import { ForwardMessageOptions } from '@mtcute/core/highlevel/methods/messages/forward-messages.js';
4
+ import { SendCopyParams } from '@mtcute/core/highlevel/methods/messages/send-copy.js';
5
+ import { SendCopyGroupParams } from '@mtcute/core/highlevel/methods/messages/send-copy-group.js';
6
6
  import { UpdateContext } from './base.js';
7
7
  /**
8
8
  * Context of a message-related update.
@@ -36,7 +36,7 @@ export declare class MessageContext extends Message implements UpdateContext<Mes
36
36
  /** If this is a channel post, get its automatic forward in the discussion group */
37
37
  getDiscussionMessage(): Promise<Message | null>;
38
38
  /** Get all custom emojis contained in this message (message group), if any */
39
- getCustomEmojis(): Promise<import("@mtcute/client").Sticker[]>;
39
+ getCustomEmojis(): Promise<import("@mtcute/core").Sticker[]>;
40
40
  /** Send a text message to the same chat (and topic, if applicable) as a given message */
41
41
  answerText(...params: ParametersSkip1<TelegramClient['answerText']>): Promise<Message>;
42
42
  /** Send a media to the same chat (and topic, if applicable) as a given message */
@@ -1,4 +1,4 @@
1
- import { Message, MtPeerNotFoundError } from '@mtcute/client';
1
+ import { Message, MtPeerNotFoundError } from '@mtcute/core';
2
2
  /**
3
3
  * Context of a message-related update.
4
4
  *