@mtcute/dispatcher 0.16.7 → 0.16.13

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 (237) hide show
  1. package/{cjs/callback-data-builder.d.ts → callback-data-builder.d.ts} +2 -2
  2. package/callback-data-builder.test.d.ts +1 -0
  3. package/{esm/context → context}/base.d.ts +2 -2
  4. package/{esm/context → context}/business-message.d.ts +5 -6
  5. package/{esm/context → context}/callback-query.d.ts +6 -7
  6. package/{cjs/context → context}/chat-join-request.d.ts +3 -3
  7. package/{esm/context → context}/chosen-inline-result.d.ts +3 -3
  8. package/{esm/context → context}/inline-query.d.ts +4 -5
  9. package/{cjs/context → context}/message.d.ts +11 -6
  10. package/{cjs/context → context}/parse.d.ts +3 -3
  11. package/{esm/context → context}/pre-checkout-query.d.ts +3 -3
  12. package/{esm/context → context}/scene-transition.d.ts +1 -1
  13. package/{cjs/dispatcher.d.ts → dispatcher.d.ts} +9 -10
  14. package/{cjs/filters → filters}/bots.d.ts +4 -4
  15. package/filters/bots.test.d.ts +1 -0
  16. package/{cjs/filters → filters}/chat.d.ts +3 -3
  17. package/{esm/filters → filters}/group.d.ts +4 -4
  18. package/{cjs/filters → filters}/logic.d.ts +1 -1
  19. package/filters/logic.test.d.ts +1 -0
  20. package/{esm/filters → filters}/message.d.ts +9 -5
  21. package/{cjs/filters → filters}/state.d.ts +2 -2
  22. package/{esm/filters → filters}/text.d.ts +3 -3
  23. package/{cjs/filters → filters}/types.d.ts +2 -2
  24. package/{cjs/filters → filters}/updates.d.ts +2 -2
  25. package/{cjs/filters → filters}/user.d.ts +3 -4
  26. package/{cjs/handler.d.ts → handler.d.ts} +5 -5
  27. package/index.cjs +2534 -0
  28. package/index.d.ts +8 -1
  29. package/index.js +2529 -1
  30. package/package.json +28 -24
  31. package/{cjs/state → state}/key.d.ts +3 -3
  32. package/state/provider.d.ts +5 -0
  33. package/{cjs/state → state}/providers/memory.d.ts +3 -4
  34. package/{esm/state → state}/providers/sqlite.d.ts +3 -3
  35. package/{cjs/state → state}/repository.d.ts +1 -1
  36. package/{esm/state → state}/service.d.ts +2 -2
  37. package/{cjs/state → state}/update-state.d.ts +2 -2
  38. package/{esm/wizard.d.ts → wizard.d.ts} +5 -6
  39. package/cjs/callback-data-builder.js +0 -141
  40. package/cjs/callback-data-builder.js.map +0 -1
  41. package/cjs/context/base.d.ts +0 -9
  42. package/cjs/context/base.js +0 -3
  43. package/cjs/context/base.js.map +0 -1
  44. package/cjs/context/business-message.d.ts +0 -61
  45. package/cjs/context/business-message.js +0 -146
  46. package/cjs/context/business-message.js.map +0 -1
  47. package/cjs/context/callback-query.d.ts +0 -63
  48. package/cjs/context/callback-query.js +0 -109
  49. package/cjs/context/callback-query.js.map +0 -1
  50. package/cjs/context/chat-join-request.js +0 -35
  51. package/cjs/context/chat-join-request.js.map +0 -1
  52. package/cjs/context/chosen-inline-result.d.ts +0 -22
  53. package/cjs/context/chosen-inline-result.js +0 -36
  54. package/cjs/context/chosen-inline-result.js.map +0 -1
  55. package/cjs/context/index.js +0 -25
  56. package/cjs/context/index.js.map +0 -1
  57. package/cjs/context/inline-query.d.ts +0 -16
  58. package/cjs/context/inline-query.js +0 -23
  59. package/cjs/context/inline-query.js.map +0 -1
  60. package/cjs/context/message.js +0 -171
  61. package/cjs/context/message.js.map +0 -1
  62. package/cjs/context/parse.js +0 -42
  63. package/cjs/context/parse.js.map +0 -1
  64. package/cjs/context/pre-checkout-query.d.ts +0 -17
  65. package/cjs/context/pre-checkout-query.js +0 -27
  66. package/cjs/context/pre-checkout-query.js.map +0 -1
  67. package/cjs/context/scene-transition.d.ts +0 -24
  68. package/cjs/context/scene-transition.js +0 -52
  69. package/cjs/context/scene-transition.js.map +0 -1
  70. package/cjs/dispatcher.js +0 -908
  71. package/cjs/dispatcher.js.map +0 -1
  72. package/cjs/filters/bots.js +0 -135
  73. package/cjs/filters/bots.js.map +0 -1
  74. package/cjs/filters/bundle.js +0 -27
  75. package/cjs/filters/bundle.js.map +0 -1
  76. package/cjs/filters/chat.js +0 -56
  77. package/cjs/filters/chat.js.map +0 -1
  78. package/cjs/filters/group.d.ts +0 -26
  79. package/cjs/filters/group.js +0 -69
  80. package/cjs/filters/group.js.map +0 -1
  81. package/cjs/filters/index.js +0 -29
  82. package/cjs/filters/index.js.map +0 -1
  83. package/cjs/filters/logic.js +0 -112
  84. package/cjs/filters/logic.js.map +0 -1
  85. package/cjs/filters/message.d.ts +0 -215
  86. package/cjs/filters/message.js +0 -191
  87. package/cjs/filters/message.js.map +0 -1
  88. package/cjs/filters/state.js +0 -33
  89. package/cjs/filters/state.js.map +0 -1
  90. package/cjs/filters/text.d.ts +0 -64
  91. package/cjs/filters/text.js +0 -136
  92. package/cjs/filters/text.js.map +0 -1
  93. package/cjs/filters/types.js +0 -3
  94. package/cjs/filters/types.js.map +0 -1
  95. package/cjs/filters/updates.js +0 -40
  96. package/cjs/filters/updates.js.map +0 -1
  97. package/cjs/filters/user.js +0 -77
  98. package/cjs/filters/user.js.map +0 -1
  99. package/cjs/handler.js +0 -4
  100. package/cjs/handler.js.map +0 -1
  101. package/cjs/index.js +0 -31
  102. package/cjs/index.js.map +0 -1
  103. package/cjs/package.json +0 -3
  104. package/cjs/propagation.js +0 -27
  105. package/cjs/propagation.js.map +0 -1
  106. package/cjs/state/index.js +0 -22
  107. package/cjs/state/index.js.map +0 -1
  108. package/cjs/state/key.js +0 -43
  109. package/cjs/state/key.js.map +0 -1
  110. package/cjs/state/provider.d.ts +0 -5
  111. package/cjs/state/provider.js +0 -3
  112. package/cjs/state/provider.js.map +0 -1
  113. package/cjs/state/providers/index.js +0 -19
  114. package/cjs/state/providers/index.js.map +0 -1
  115. package/cjs/state/providers/memory.js +0 -81
  116. package/cjs/state/providers/memory.js.map +0 -1
  117. package/cjs/state/providers/sqlite.d.ts +0 -28
  118. package/cjs/state/providers/sqlite.js +0 -100
  119. package/cjs/state/providers/sqlite.js.map +0 -1
  120. package/cjs/state/repository.js +0 -3
  121. package/cjs/state/repository.js.map +0 -1
  122. package/cjs/state/service.d.ts +0 -20
  123. package/cjs/state/service.js +0 -70
  124. package/cjs/state/service.js.map +0 -1
  125. package/cjs/state/update-state.js +0 -219
  126. package/cjs/state/update-state.js.map +0 -1
  127. package/cjs/wizard.d.ts +0 -65
  128. package/cjs/wizard.js +0 -105
  129. package/cjs/wizard.js.map +0 -1
  130. package/esm/callback-data-builder.d.ts +0 -49
  131. package/esm/callback-data-builder.js +0 -137
  132. package/esm/callback-data-builder.js.map +0 -1
  133. package/esm/context/base.js +0 -2
  134. package/esm/context/base.js.map +0 -1
  135. package/esm/context/business-message.js +0 -142
  136. package/esm/context/business-message.js.map +0 -1
  137. package/esm/context/callback-query.js +0 -103
  138. package/esm/context/callback-query.js.map +0 -1
  139. package/esm/context/chat-join-request.d.ts +0 -17
  140. package/esm/context/chat-join-request.js +0 -31
  141. package/esm/context/chat-join-request.js.map +0 -1
  142. package/esm/context/chosen-inline-result.js +0 -32
  143. package/esm/context/chosen-inline-result.js.map +0 -1
  144. package/esm/context/index.d.ts +0 -9
  145. package/esm/context/index.js +0 -9
  146. package/esm/context/index.js.map +0 -1
  147. package/esm/context/inline-query.js +0 -19
  148. package/esm/context/inline-query.js.map +0 -1
  149. package/esm/context/message.d.ts +0 -77
  150. package/esm/context/message.js +0 -167
  151. package/esm/context/message.js.map +0 -1
  152. package/esm/context/parse.d.ts +0 -13
  153. package/esm/context/parse.js +0 -39
  154. package/esm/context/parse.js.map +0 -1
  155. package/esm/context/pre-checkout-query.js +0 -23
  156. package/esm/context/pre-checkout-query.js.map +0 -1
  157. package/esm/context/scene-transition.js +0 -48
  158. package/esm/context/scene-transition.js.map +0 -1
  159. package/esm/dispatcher.d.ts +0 -881
  160. package/esm/dispatcher.js +0 -904
  161. package/esm/dispatcher.js.map +0 -1
  162. package/esm/filters/bots.d.ts +0 -64
  163. package/esm/filters/bots.js +0 -131
  164. package/esm/filters/bots.js.map +0 -1
  165. package/esm/filters/bundle.d.ts +0 -10
  166. package/esm/filters/bundle.js +0 -11
  167. package/esm/filters/bundle.js.map +0 -1
  168. package/esm/filters/chat.d.ts +0 -27
  169. package/esm/filters/chat.js +0 -51
  170. package/esm/filters/chat.js.map +0 -1
  171. package/esm/filters/group.js +0 -65
  172. package/esm/filters/group.js.map +0 -1
  173. package/esm/filters/index.d.ts +0 -4
  174. package/esm/filters/index.js +0 -3
  175. package/esm/filters/index.js.map +0 -1
  176. package/esm/filters/logic.d.ts +0 -29
  177. package/esm/filters/logic.js +0 -105
  178. package/esm/filters/logic.js.map +0 -1
  179. package/esm/filters/message.js +0 -168
  180. package/esm/filters/message.js.map +0 -1
  181. package/esm/filters/state.d.ts +0 -15
  182. package/esm/filters/state.js +0 -28
  183. package/esm/filters/state.js.map +0 -1
  184. package/esm/filters/text.js +0 -129
  185. package/esm/filters/text.js.map +0 -1
  186. package/esm/filters/types.d.ts +0 -91
  187. package/esm/filters/types.js +0 -2
  188. package/esm/filters/types.js.map +0 -1
  189. package/esm/filters/updates.d.ts +0 -39
  190. package/esm/filters/updates.js +0 -34
  191. package/esm/filters/updates.js.map +0 -1
  192. package/esm/filters/user.d.ts +0 -25
  193. package/esm/filters/user.js +0 -71
  194. package/esm/filters/user.js.map +0 -1
  195. package/esm/handler.d.ts +0 -41
  196. package/esm/handler.js +0 -3
  197. package/esm/handler.js.map +0 -1
  198. package/esm/index.d.ts +0 -8
  199. package/esm/index.js +0 -9
  200. package/esm/index.js.map +0 -1
  201. package/esm/propagation.d.ts +0 -22
  202. package/esm/propagation.js +0 -24
  203. package/esm/propagation.js.map +0 -1
  204. package/esm/state/index.d.ts +0 -5
  205. package/esm/state/index.js +0 -6
  206. package/esm/state/index.js.map +0 -1
  207. package/esm/state/key.d.ts +0 -24
  208. package/esm/state/key.js +0 -39
  209. package/esm/state/key.js.map +0 -1
  210. package/esm/state/provider.d.ts +0 -5
  211. package/esm/state/provider.js +0 -2
  212. package/esm/state/provider.js.map +0 -1
  213. package/esm/state/providers/index.d.ts +0 -2
  214. package/esm/state/providers/index.js +0 -3
  215. package/esm/state/providers/index.js.map +0 -1
  216. package/esm/state/providers/memory.d.ts +0 -30
  217. package/esm/state/providers/memory.js +0 -77
  218. package/esm/state/providers/memory.js.map +0 -1
  219. package/esm/state/providers/sqlite.js +0 -96
  220. package/esm/state/providers/sqlite.js.map +0 -1
  221. package/esm/state/repository.d.ts +0 -62
  222. package/esm/state/repository.js +0 -2
  223. package/esm/state/repository.js.map +0 -1
  224. package/esm/state/service.js +0 -66
  225. package/esm/state/service.js.map +0 -1
  226. package/esm/state/update-state.d.ts +0 -151
  227. package/esm/state/update-state.js +0 -214
  228. package/esm/state/update-state.js.map +0 -1
  229. package/esm/wizard.js +0 -101
  230. package/esm/wizard.js.map +0 -1
  231. /package/{cjs/context → context}/index.d.ts +0 -0
  232. /package/{cjs/filters → filters}/bundle.d.ts +0 -0
  233. /package/{cjs/filters → filters}/index.d.ts +0 -0
  234. /package/{cjs/index.d.ts → index.d.cts} +0 -0
  235. /package/{cjs/propagation.d.ts → propagation.d.ts} +0 -0
  236. /package/{cjs/state → state}/index.d.ts +0 -0
  237. /package/{cjs/state → state}/providers/index.d.ts +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n BusinessCallbackQuery,\n BusinessMessage,\n CallbackQuery,\n ChosenInlineResult,\n InlineCallbackQuery,\n InlineQuery,\n Message,\n} from '@mtcute/core'\n\nimport type { UpdateContextDistributed } from '../context/base.js'\n\nimport type { UpdateFilter } from './types.js'\n\ntype UpdatesWithText = UpdateContextDistributed<\n | Message\n | BusinessMessage\n | InlineQuery\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n>\n\nfunction extractText(obj: UpdatesWithText): string | null {\n switch (obj._name) {\n case 'new_message':\n case 'new_business_message':\n return obj.text\n case 'inline_query':\n return obj.query\n case 'chosen_inline_result':\n return obj.id\n case 'callback_query':\n case 'inline_callback_query':\n case 'business_callback_query':\n if (obj.raw.data) return obj.dataStr\n }\n\n return null\n}\n\n/**\n * Filter objects that match a given regular expression\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used\n * - for callback queries, `dataStr` is used\n *\n * When a regex matches, the match array is stored in a\n * type-safe extension field `.match` of the object\n *\n * @param regex Regex to be matched\n */\nexport function regex(regex: RegExp): UpdateFilter<UpdatesWithText, { match: RegExpMatchArray }> {\n return (obj) => {\n const txt = extractText(obj)\n if (!txt) return false\n\n const m = txt.match(regex)\n\n if (m) {\n (obj as typeof obj & { match: RegExpMatchArray }).match = m\n\n return true\n }\n\n return false\n }\n}\n\n/**\n * Filter objects which contain the exact text given\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str String to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function equals(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return obj => extractText(obj)?.toLowerCase() === str\n }\n\n return obj => extractText(obj) === str\n}\n\n/**\n * Filter objects which contain the text given (as a substring)\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function contains(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().includes(str)\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.includes(str)\n }\n}\n\n/**\n * Filter objects which contain the text starting with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function startsWith(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n\n/**\n * Filter objects which contain the text ending with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function endsWith(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n"]}
@@ -1,91 +0,0 @@
1
- import type { MaybePromise } from '@mtcute/core';
2
- import type { UpdateState } from '../state/update-state.js';
3
- /**
4
- * Type describing a primitive filter, which is a function taking some `Base`
5
- * and a {@link TelegramClient}, checking it against some condition
6
- * and returning a boolean.
7
- *
8
- * If `true` is returned, the filter is considered
9
- * to be matched, and the appropriate update handler function is called,
10
- * otherwise next registered handler is checked.
11
- *
12
- * Additionally, filter might contain a type modification
13
- * to `Base` for better code insights. If it is present,
14
- * it is used to overwrite types (!) of some of the `Base` fields
15
- * to given (note that this is entirely compile-time! object is not modified)
16
- *
17
- * For parametrized filters (like {@link filters.regex}),
18
- * type modification can also be used to add additional fields
19
- * (in case of `regex`, its match array is added to `.match`)
20
- *
21
- * Example without type mod:
22
- * ```typescript
23
- *
24
- * const hasPhoto: UpdateFilter<Message> = msg => msg.media?.type === 'photo'
25
- *
26
- * // ..later..
27
- * tg.onNewMessage(hasPhoto, async (msg) => {
28
- * // `hasPhoto` filter matched, so we can safely assume
29
- * // that `msg.media` is a Photo.
30
- * //
31
- * // but it is very redundant, verbose and error-rome,
32
- * // wonder if we could make typescript do this automagically and safely...
33
- * await (msg.media as Photo).downloadToFile(`${msg.id}.jpg`)
34
- * })
35
- * ```
36
- *
37
- * Example with type mod:
38
- * ```typescript
39
- *
40
- * const hasPhoto: UpdateFilter<Message, { media: Photo }> = msg => msg.media?.type === 'photo'
41
- *
42
- * // ..later..
43
- * tg.onNewMessage(hasPhoto, async (msg) => {
44
- * // since `hasPhoto` filter matched,
45
- * // we have applied the modification to `msg`,
46
- * // and `msg.media` now has type `Photo`
47
- * //
48
- * // no more redundancy and type casts!
49
- * await msg.media.downloadToFile(`${msg.id}.jpg`)
50
- * })
51
- * ```
52
- *
53
- * > **Note**: Type modification can contain anything, even totally unrelated types
54
- * > and it is *your* task to keep track that everything is correct.
55
- * >
56
- * > Bad example:
57
- * > ```typescript
58
- * > // we check for `Photo`, but type contains `Audio`. this will be a problem!
59
- * > const hasPhoto: UpdateFilter<Message, { media: Audio }> = msg => msg.media?.type === 'photo'
60
- * >
61
- * > // ..later..
62
- * > tg.onNewMessage(hasPhoto, async (msg) => {
63
- * > // oops! `msg.media` is `Audio` and does not have `.width`!
64
- * > console.log(msg.media.width)
65
- * > })
66
- * > ```
67
- *
68
- * > **Warning!** Do not use the generics provided in functions
69
- * > like `and`, `or`, etc. Those are meant to be inferred by the compiler!
70
- */
71
- export type UpdateFilter<Base, Mod = {}, State extends object = never> = (update: Base, state?: UpdateState<State>) => MaybePromise<boolean>;
72
- export type Modify<Base, Mod> = Omit<Base, keyof Mod> & Mod;
73
- export type Invert<Base, Mod> = {
74
- [P in keyof Mod & keyof Base]: Exclude<Base[P], Mod[P]>;
75
- };
76
- export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
77
- export type ExtractBase<Filter> = Filter extends UpdateFilter<infer I, any> ? I : never;
78
- export type ExtractMod<Filter> = Filter extends UpdateFilter<any, infer I> ? I : never;
79
- export type ExtractState<Filter> = Filter extends UpdateFilter<any, any, infer I> ? I : never;
80
- export type TupleKeys<T extends any[]> = Exclude<keyof T, keyof []>;
81
- export type WrapBase<T extends any[]> = {
82
- [K in TupleKeys<T>]: {
83
- base: ExtractBase<T[K]>;
84
- };
85
- };
86
- export type Values<T> = T[keyof T];
87
- export type UnwrapBase<T> = T extends {
88
- base: any;
89
- } ? T['base'] : never;
90
- export type ExtractBaseMany<Filters extends any[]> = UnwrapBase<UnionToIntersection<Values<WrapBase<Filters>>>>;
91
- export type EmptyObject = Record<never, never>;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/filters/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MaybePromise } from '@mtcute/core'\n\nimport type { UpdateState } from '../state/update-state.js'\n/**\n * Type describing a primitive filter, which is a function taking some `Base`\n * and a {@link TelegramClient}, checking it against some condition\n * and returning a boolean.\n *\n * If `true` is returned, the filter is considered\n * to be matched, and the appropriate update handler function is called,\n * otherwise next registered handler is checked.\n *\n * Additionally, filter might contain a type modification\n * to `Base` for better code insights. If it is present,\n * it is used to overwrite types (!) of some of the `Base` fields\n * to given (note that this is entirely compile-time! object is not modified)\n *\n * For parametrized filters (like {@link filters.regex}),\n * type modification can also be used to add additional fields\n * (in case of `regex`, its match array is added to `.match`)\n *\n * Example without type mod:\n * ```typescript\n *\n * const hasPhoto: UpdateFilter<Message> = msg => msg.media?.type === 'photo'\n *\n * // ..later..\n * tg.onNewMessage(hasPhoto, async (msg) => {\n * // `hasPhoto` filter matched, so we can safely assume\n * // that `msg.media` is a Photo.\n * //\n * // but it is very redundant, verbose and error-rome,\n * // wonder if we could make typescript do this automagically and safely...\n * await (msg.media as Photo).downloadToFile(`${msg.id}.jpg`)\n * })\n * ```\n *\n * Example with type mod:\n * ```typescript\n *\n * const hasPhoto: UpdateFilter<Message, { media: Photo }> = msg => msg.media?.type === 'photo'\n *\n * // ..later..\n * tg.onNewMessage(hasPhoto, async (msg) => {\n * // since `hasPhoto` filter matched,\n * // we have applied the modification to `msg`,\n * // and `msg.media` now has type `Photo`\n * //\n * // no more redundancy and type casts!\n * await msg.media.downloadToFile(`${msg.id}.jpg`)\n * })\n * ```\n *\n * > **Note**: Type modification can contain anything, even totally unrelated types\n * > and it is *your* task to keep track that everything is correct.\n * >\n * > Bad example:\n * > ```typescript\n * > // we check for `Photo`, but type contains `Audio`. this will be a problem!\n * > const hasPhoto: UpdateFilter<Message, { media: Audio }> = msg => msg.media?.type === 'photo'\n * >\n * > // ..later..\n * > tg.onNewMessage(hasPhoto, async (msg) => {\n * > // oops! `msg.media` is `Audio` and does not have `.width`!\n * > console.log(msg.media.width)\n * > })\n * > ```\n *\n * > **Warning!** Do not use the generics provided in functions\n * > like `and`, `or`, etc. Those are meant to be inferred by the compiler!\n */\n// we need the second parameter because it carries meta information\n// eslint-disable-next-line unused-imports/no-unused-vars, ts/no-empty-object-type\nexport type UpdateFilter<Base, Mod = {}, State extends object = never> = (\n update: Base,\n state?: UpdateState<State>,\n) => MaybePromise<boolean>\n\nexport type Modify<Base, Mod> = Omit<Base, keyof Mod> & Mod\nexport type Invert<Base, Mod> = {\n [P in keyof Mod & keyof Base]: Exclude<Base[P], Mod[P]>\n}\n\nexport type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never\n\nexport type ExtractBase<Filter> = Filter extends UpdateFilter<infer I, any> ? I : never\n\nexport type ExtractMod<Filter> = Filter extends UpdateFilter<any, infer I> ? I : never\n\nexport type ExtractState<Filter> = Filter extends UpdateFilter<any, any, infer I> ? I : never\n\nexport type TupleKeys<T extends any[]> = Exclude<keyof T, keyof []>\nexport type WrapBase<T extends any[]> = {\n [K in TupleKeys<T>]: { base: ExtractBase<T[K]> }\n}\nexport type Values<T> = T[keyof T]\nexport type UnwrapBase<T> = T extends { base: any } ? T['base'] : never\nexport type ExtractBaseMany<Filters extends any[]> = UnwrapBase<UnionToIntersection<Values<WrapBase<Filters>>>>\n\nexport type EmptyObject = Record<never, never>\n"]}
@@ -1,39 +0,0 @@
1
- import type { ChatMemberUpdate, ChatMemberUpdateType, UserStatus, UserStatusUpdate } from '@mtcute/core';
2
- import type { UpdateFilter } from './types.js';
3
- /**
4
- * Create a filter for {@link ChatMemberUpdate} by update type
5
- *
6
- * @param types Update type(s)
7
- * @link ChatMemberUpdate.Type
8
- */
9
- export declare const chatMember: {
10
- <T extends ChatMemberUpdateType>(type: T): UpdateFilter<ChatMemberUpdate, {
11
- type: T;
12
- }>;
13
- <T extends ChatMemberUpdateType[]>(types: T): UpdateFilter<ChatMemberUpdate, {
14
- type: T[number];
15
- }>;
16
- };
17
- /**
18
- * Create a filter for {@link UserStatusUpdate} by new user status
19
- *
20
- * @param statuses Update type(s)
21
- * @link User.Status
22
- */
23
- export declare const userStatus: {
24
- <T extends UserStatus>(status: T): UpdateFilter<UserStatusUpdate, {
25
- type: T;
26
- lastOnline: T extends 'offline' ? Date : null;
27
- nextOffline: T extends 'online' ? Date : null;
28
- }>;
29
- <T extends UserStatus[]>(statuses: T): UpdateFilter<UserStatusUpdate, {
30
- type: T[number];
31
- }>;
32
- };
33
- /**
34
- * Create a filter for {@link ChatMemberUpdate} for updates
35
- * regarding current user
36
- */
37
- export declare const chatMemberSelf: UpdateFilter<ChatMemberUpdate, {
38
- isSelf: true;
39
- }>;
@@ -1,34 +0,0 @@
1
- /**
2
- * Create a filter for {@link ChatMemberUpdate} by update type
3
- *
4
- * @param types Update type(s)
5
- * @link ChatMemberUpdate.Type
6
- */
7
- export const chatMember = (types) => {
8
- if (Array.isArray(types)) {
9
- const index = {};
10
- types.forEach(typ => (index[typ] = true));
11
- return upd => upd.type in index;
12
- }
13
- return upd => upd.type === types;
14
- };
15
- /**
16
- * Create a filter for {@link UserStatusUpdate} by new user status
17
- *
18
- * @param statuses Update type(s)
19
- * @link User.Status
20
- */
21
- export const userStatus = (statuses) => {
22
- if (Array.isArray(statuses)) {
23
- const index = {};
24
- statuses.forEach(typ => (index[typ] = true));
25
- return upd => upd.status in index;
26
- }
27
- return upd => upd.status === statuses;
28
- };
29
- /**
30
- * Create a filter for {@link ChatMemberUpdate} for updates
31
- * regarding current user
32
- */
33
- export const chatMemberSelf = upd => upd.isSelf;
34
- //# sourceMappingURL=updates.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"updates.js","sourceRoot":"","sources":["../../../src/filters/updates.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAGnB,CAAC,KAAuC,EAAkC,EAAE;IAC5E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,KAAK,GAAgD,EAAE,CAAA;QAC7D,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAEzC,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,CAAA;IACnC,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAA;AACpC,CAAC,CAAA;AAED;;;;;GAKG;AACH,MAAM,CAAC,MAAM,UAAU,GAYnB,CAAC,QAAgC,EAAkC,EAAE;IACrE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAsC,EAAE,CAAA;QACnD,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAE5C,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,CAAA;IACrC,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAA;AACzC,CAAC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAAqD,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAA","sourcesContent":["import type { ChatMemberUpdate, ChatMemberUpdateType, MaybeArray, UserStatus, UserStatusUpdate } from '@mtcute/core'\n\nimport type { UpdateFilter } from './types.js'\n\n/**\n * Create a filter for {@link ChatMemberUpdate} by update type\n *\n * @param types Update type(s)\n * @link ChatMemberUpdate.Type\n */\nexport const chatMember: {\n <T extends ChatMemberUpdateType>(type: T): UpdateFilter<ChatMemberUpdate, { type: T }>\n <T extends ChatMemberUpdateType[]>(types: T): UpdateFilter<ChatMemberUpdate, { type: T[number] }>\n} = (types: MaybeArray<ChatMemberUpdateType>): UpdateFilter<ChatMemberUpdate> => {\n if (Array.isArray(types)) {\n const index: Partial<Record<ChatMemberUpdateType, true>> = {}\n types.forEach(typ => (index[typ] = true))\n\n return upd => upd.type in index\n }\n\n return upd => upd.type === types\n}\n\n/**\n * Create a filter for {@link UserStatusUpdate} by new user status\n *\n * @param statuses Update type(s)\n * @link User.Status\n */\nexport const userStatus: {\n <T extends UserStatus>(\n status: T,\n ): UpdateFilter<\n UserStatusUpdate,\n {\n type: T\n lastOnline: T extends 'offline' ? Date : null\n nextOffline: T extends 'online' ? Date : null\n }\n >\n <T extends UserStatus[]>(statuses: T): UpdateFilter<UserStatusUpdate, { type: T[number] }>\n} = (statuses: MaybeArray<UserStatus>): UpdateFilter<UserStatusUpdate> => {\n if (Array.isArray(statuses)) {\n const index: Partial<Record<UserStatus, true>> = {}\n statuses.forEach(typ => (index[typ] = true))\n\n return upd => upd.status in index\n }\n\n return upd => upd.status === statuses\n}\n\n/**\n * Create a filter for {@link ChatMemberUpdate} for updates\n * regarding current user\n */\nexport const chatMemberSelf: UpdateFilter<ChatMemberUpdate, { isSelf: true }> = upd => upd.isSelf\n"]}
@@ -1,25 +0,0 @@
1
- import type { BotChatJoinRequestUpdate, BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChatMemberUpdate, ChosenInlineResult, DeleteStoryUpdate, HistoryReadUpdate, InlineCallbackQuery, InlineQuery, MaybeArray, Message, PollVoteUpdate, StoryUpdate, UserStatusUpdate, UserTypingUpdate } from '@mtcute/core';
2
- import { User } from '@mtcute/core';
3
- import type { UpdateContextDistributed } from '../context/base.js';
4
- import type { UpdateFilter } from './types.js';
5
- /**
6
- * Filter messages generated by yourself (including Saved Messages)
7
- */
8
- export declare const me: UpdateFilter<Message, {
9
- sender: User;
10
- }>;
11
- /**
12
- * Filter messages sent by bots
13
- */
14
- export declare const bot: UpdateFilter<Message, {
15
- sender: User;
16
- }>;
17
- /**
18
- * Filter updates by user ID(s) or username(s)
19
- *
20
- * Note that only some updates support filtering by username.
21
- */
22
- export declare const userId: {
23
- (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<Message | BusinessMessage | StoryUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
24
- (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<Message | BusinessMessage | UserStatusUpdate | UserTypingUpdate | StoryUpdate | HistoryReadUpdate | DeleteStoryUpdate | InlineQuery | ChatMemberUpdate | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery | PollVoteUpdate | BotChatJoinRequestUpdate>>;
25
- };
@@ -1,71 +0,0 @@
1
- import { User, } from '@mtcute/core';
2
- /**
3
- * Filter messages generated by yourself (including Saved Messages)
4
- */
5
- export const me = msg => (msg.sender.type === 'user' && msg.sender.isSelf) || msg.isOutgoing;
6
- /**
7
- * Filter messages sent by bots
8
- */
9
- export const bot = msg => msg.sender.constructor === User && msg.sender.isBot;
10
- /**
11
- * Filter updates by user ID(s) or username(s)
12
- *
13
- * Note that only some updates support filtering by username.
14
- */
15
- export const userId = (id) => {
16
- const indexId = new Set();
17
- const indexUsername = new Set();
18
- let matchSelf = false;
19
- if (!Array.isArray(id))
20
- id = [id];
21
- id.forEach((id) => {
22
- if (id === 'me' || id === 'self') {
23
- matchSelf = true;
24
- }
25
- else if (typeof id === 'string') {
26
- indexUsername.add(id);
27
- }
28
- else {
29
- indexId.add(id);
30
- }
31
- });
32
- return (upd) => {
33
- switch (upd._name) {
34
- case 'new_message':
35
- case 'edit_message':
36
- case 'new_business_message':
37
- case 'edit_business_message': {
38
- const sender = upd.sender;
39
- return (matchSelf && sender.isSelf)
40
- || indexId.has(sender.id)
41
- || indexUsername.has(sender.username);
42
- }
43
- case 'user_status':
44
- case 'user_typing': {
45
- const id = upd.userId;
46
- return (matchSelf && id === upd.client.storage.self.getCached()?.userId)
47
- || indexId.has(id);
48
- }
49
- case 'poll_vote':
50
- case 'story':
51
- case 'delete_story': {
52
- const peer = upd.peer;
53
- if (peer.type !== 'user')
54
- return false;
55
- return (matchSelf && peer.isSelf)
56
- || indexId.has(peer.id)
57
- || Boolean(peer.usernames?.some(u => indexUsername.has(u.username)));
58
- }
59
- case 'history_read': {
60
- const id = upd.chatId;
61
- return (matchSelf && id === upd.client.storage.self.getCached()?.userId)
62
- || indexId.has(id);
63
- }
64
- }
65
- const user = upd.user;
66
- return ((matchSelf && user.isSelf)
67
- || indexId.has(user.id)
68
- || Boolean(user.usernames?.some(u => indexUsername.has(u.username))));
69
- };
70
- };
71
- //# sourceMappingURL=user.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":"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","sourcesContent":["import type {\n BotChatJoinRequestUpdate,\n BusinessCallbackQuery,\n BusinessMessage,\n CallbackQuery,\n ChatMemberUpdate,\n ChosenInlineResult,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n InlineCallbackQuery,\n InlineQuery,\n MaybeArray,\n Message,\n PollVoteUpdate,\n StoryUpdate,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/core'\nimport {\n User,\n} from '@mtcute/core'\n\nimport type { UpdateContextDistributed } from '../context/base.js'\n\nimport type { UpdateFilter } from './types.js'\n\n/**\n * Filter messages generated by yourself (including Saved Messages)\n */\nexport const me: UpdateFilter<Message, { sender: User }> = msg =>\n (msg.sender.type === 'user' && msg.sender.isSelf) || msg.isOutgoing\n\n/**\n * Filter messages sent by bots\n */\nexport const bot: UpdateFilter<Message, { sender: User }> = msg => msg.sender.constructor === User && msg.sender.isBot\n\n/**\n * Filter updates by user ID(s) or username(s)\n *\n * Note that only some updates support filtering by username.\n */\nexport const userId: {\n (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<\n | Message\n | BusinessMessage\n | StoryUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<\n | Message\n | BusinessMessage\n | UserStatusUpdate\n | UserTypingUpdate\n | StoryUpdate\n | HistoryReadUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n} = (id) => {\n const indexId = new Set<number>()\n const indexUsername = new Set<string>()\n let matchSelf = false\n\n if (!Array.isArray(id)) id = [id]\n id.forEach((id) => {\n if (id === 'me' || id === 'self') {\n matchSelf = true\n } else if (typeof id === 'string') {\n indexUsername.add(id)\n } else {\n indexId.add(id)\n }\n })\n\n return (upd) => {\n switch (upd._name) {\n case 'new_message':\n case 'edit_message':\n case 'new_business_message':\n case 'edit_business_message': {\n const sender = upd.sender\n\n return (matchSelf && sender.isSelf)\n || indexId.has(sender.id)\n || indexUsername.has(sender.username!)\n }\n case 'user_status':\n case 'user_typing': {\n const id = upd.userId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId)\n || indexId.has(id)\n }\n case 'poll_vote':\n case 'story':\n case 'delete_story': {\n const peer = upd.peer\n if (peer.type !== 'user') return false\n\n return (matchSelf && peer.isSelf)\n || indexId.has(peer.id)\n || Boolean(peer.usernames?.some(u => indexUsername.has(u.username)))\n }\n case 'history_read': {\n const id = upd.chatId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId)\n || indexId.has(id)\n }\n }\n\n const user = upd.user\n\n return (\n (matchSelf && user.isSelf)\n || indexId.has(user.id)\n || Boolean(user.usernames?.some(u => indexUsername.has(u.username)))\n )\n }\n}\n"]}
package/esm/handler.d.ts DELETED
@@ -1,41 +0,0 @@
1
- import type { BotReactionCountUpdate, BotReactionUpdate, BotStoppedUpdate, BusinessConnection, ChatJoinRequestUpdate, ChatMemberUpdate, DeleteBusinessMessageUpdate, DeleteMessageUpdate, DeleteStoryUpdate, HistoryReadUpdate, MaybePromise, PeersIndex, PollUpdate, PollVoteUpdate, StoryUpdate, UserStatusUpdate, UserTypingUpdate, tl } from '@mtcute/core';
2
- import type { TelegramClient } from '@mtcute/core/client.js';
3
- import type { UpdateContext } from './context/base.js';
4
- import type { BusinessCallbackQueryContext, BusinessMessageContext, CallbackQueryContext, ChatJoinRequestUpdateContext, ChosenInlineResultContext, InlineCallbackQueryContext, InlineQueryContext, MessageContext, PreCheckoutQueryContext } from './context/index.js';
5
- import type { PropagationAction } from './propagation.js';
6
- export interface BaseUpdateHandler<Name, Handler, Checker> {
7
- name: Name;
8
- callback: Handler;
9
- check?: Checker;
10
- }
11
- export type ParsedUpdateHandler<Name, Update, State = never> = BaseUpdateHandler<Name, (update: Update, state: State) => MaybePromise<void | PropagationAction>, (update: Update, state: State) => MaybePromise<boolean>>;
12
- export type RawUpdateHandler = BaseUpdateHandler<'raw', (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybePromise<void | PropagationAction>, (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybePromise<boolean>>;
13
- export type NewMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'new_message', T, S>;
14
- export type EditMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'edit_message', T, S>;
15
- export type MessageGroupHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'message_group', T, S>;
16
- export type DeleteMessageHandler<T = UpdateContext<DeleteMessageUpdate>> = ParsedUpdateHandler<'delete_message', T>;
17
- export type ChatMemberUpdateHandler<T = UpdateContext<ChatMemberUpdate>> = ParsedUpdateHandler<'chat_member', T>;
18
- export type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'inline_query', T>;
19
- export type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>;
20
- export type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>;
21
- export type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<'inline_callback_query', T, S>;
22
- export type BusinessCallbackQueryHandler<T = BusinessCallbackQueryContext, S = never> = ParsedUpdateHandler<'business_callback_query', T, S>;
23
- export type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>;
24
- export type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>;
25
- export type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>;
26
- export type UserTypingHandler<T = UpdateContext<UserTypingUpdate>> = ParsedUpdateHandler<'user_typing', T>;
27
- export type HistoryReadHandler<T = UpdateContext<HistoryReadUpdate>> = ParsedUpdateHandler<'history_read', T>;
28
- export type BotStoppedHandler<T = UpdateContext<BotStoppedUpdate>> = ParsedUpdateHandler<'bot_stopped', T>;
29
- export type BotChatJoinRequestHandler<T = ChatJoinRequestUpdateContext> = ParsedUpdateHandler<'bot_chat_join_request', T>;
30
- export type ChatJoinRequestHandler<T = UpdateContext<ChatJoinRequestUpdate>> = ParsedUpdateHandler<'chat_join_request', T>;
31
- export type PreCheckoutQueryHandler<T = PreCheckoutQueryContext> = ParsedUpdateHandler<'pre_checkout_query', T>;
32
- export type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHandler<'story', T>;
33
- export type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>;
34
- export type BotReactionUpdateHandler<T = UpdateContext<BotReactionUpdate>> = ParsedUpdateHandler<'bot_reaction', T>;
35
- export type BotReactionCountUpdateHandler<T = UpdateContext<BotReactionCountUpdate>> = ParsedUpdateHandler<'bot_reaction_count', T>;
36
- export type BusinessConnectionUpdateHandler<T = UpdateContext<BusinessConnection>> = ParsedUpdateHandler<'business_connection', T>;
37
- export type NewBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'new_business_message', T, S>;
38
- export type EditBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'edit_business_message', T, S>;
39
- export type BusinessMessageGroupHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<'business_message_group', T, S>;
40
- export type DeleteBusinessMessageHandler<T = UpdateContext<DeleteBusinessMessageUpdate>> = ParsedUpdateHandler<'delete_business_message', T>;
41
- export type UpdateHandler = RawUpdateHandler | NewMessageHandler | EditMessageHandler | MessageGroupHandler | DeleteMessageHandler | ChatMemberUpdateHandler | InlineQueryHandler | ChosenInlineResultHandler | CallbackQueryHandler | InlineCallbackQueryHandler | BusinessCallbackQueryHandler | PollUpdateHandler | PollVoteHandler | UserStatusUpdateHandler | UserTypingHandler | HistoryReadHandler | BotStoppedHandler | BotChatJoinRequestHandler | ChatJoinRequestHandler | PreCheckoutQueryHandler | StoryUpdateHandler | DeleteStoryHandler | BotReactionUpdateHandler | BotReactionCountUpdateHandler | BusinessConnectionUpdateHandler | NewBusinessMessageHandler | EditBusinessMessageHandler | BusinessMessageGroupHandler | DeleteBusinessMessageHandler;
package/esm/handler.js DELETED
@@ -1,3 +0,0 @@
1
- export {};
2
- // end-codegen
3
- //# sourceMappingURL=handler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";AA2JA,cAAc","sourcesContent":["import type {\n BotReactionCountUpdate,\n BotReactionUpdate,\n BotStoppedUpdate,\n BusinessConnection,\n ChatJoinRequestUpdate,\n ChatMemberUpdate,\n DeleteBusinessMessageUpdate,\n DeleteMessageUpdate,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n MaybePromise,\n PeersIndex,\n PollUpdate,\n PollVoteUpdate,\n StoryUpdate,\n UserStatusUpdate,\n UserTypingUpdate,\n tl,\n} from '@mtcute/core'\nimport type { TelegramClient } from '@mtcute/core/client.js'\n\nimport type { UpdateContext } from './context/base.js'\nimport type {\n BusinessCallbackQueryContext,\n BusinessMessageContext,\n CallbackQueryContext,\n ChatJoinRequestUpdateContext,\n ChosenInlineResultContext,\n InlineCallbackQueryContext,\n InlineQueryContext,\n MessageContext,\n PreCheckoutQueryContext,\n} from './context/index.js'\nimport type { PropagationAction } from './propagation.js'\n\nexport interface BaseUpdateHandler<Name, Handler, Checker> {\n name: Name\n callback: Handler\n\n check?: Checker\n}\n\nexport type ParsedUpdateHandler<Name, Update, State = never> = BaseUpdateHandler<\n Name,\n (update: Update, state: State) => MaybePromise<void | PropagationAction>,\n (update: Update, state: State) => MaybePromise<boolean>\n>\n\nexport type RawUpdateHandler = BaseUpdateHandler<\n 'raw',\n (\n client: TelegramClient,\n update: tl.TypeUpdate | tl.TypeMessage,\n peers: PeersIndex,\n ) => MaybePromise<void | PropagationAction>,\n (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybePromise<boolean>\n>\n\n// begin-codegen\nexport type NewMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'new_message', T, S>\nexport type EditMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'edit_message', T, S>\nexport type MessageGroupHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'message_group', T, S>\nexport type DeleteMessageHandler<T = UpdateContext<DeleteMessageUpdate>> = ParsedUpdateHandler<'delete_message', T>\nexport type ChatMemberUpdateHandler<T = UpdateContext<ChatMemberUpdate>> = ParsedUpdateHandler<'chat_member', T>\nexport type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'inline_query', T>\nexport type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>\nexport type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>\nexport type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'inline_callback_query',\n T,\n S\n>\nexport type BusinessCallbackQueryHandler<T = BusinessCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'business_callback_query',\n T,\n S\n>\nexport type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>\nexport type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>\nexport type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>\nexport type UserTypingHandler<T = UpdateContext<UserTypingUpdate>> = ParsedUpdateHandler<'user_typing', T>\nexport type HistoryReadHandler<T = UpdateContext<HistoryReadUpdate>> = ParsedUpdateHandler<'history_read', T>\nexport type BotStoppedHandler<T = UpdateContext<BotStoppedUpdate>> = ParsedUpdateHandler<'bot_stopped', T>\nexport type BotChatJoinRequestHandler<T = ChatJoinRequestUpdateContext> = ParsedUpdateHandler<\n 'bot_chat_join_request',\n T\n>\nexport type ChatJoinRequestHandler<T = UpdateContext<ChatJoinRequestUpdate>> = ParsedUpdateHandler<\n 'chat_join_request',\n T\n>\nexport type PreCheckoutQueryHandler<T = PreCheckoutQueryContext> = ParsedUpdateHandler<'pre_checkout_query', T>\nexport type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHandler<'story', T>\nexport type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>\nexport type BotReactionUpdateHandler<T = UpdateContext<BotReactionUpdate>> = ParsedUpdateHandler<'bot_reaction', T>\nexport type BotReactionCountUpdateHandler<T = UpdateContext<BotReactionCountUpdate>> = ParsedUpdateHandler<\n 'bot_reaction_count',\n T\n>\nexport type BusinessConnectionUpdateHandler<T = UpdateContext<BusinessConnection>> = ParsedUpdateHandler<\n 'business_connection',\n T\n>\nexport type NewBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'new_business_message',\n T,\n S\n>\nexport type EditBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'edit_business_message',\n T,\n S\n>\nexport type BusinessMessageGroupHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'business_message_group',\n T,\n S\n>\nexport type DeleteBusinessMessageHandler<T = UpdateContext<DeleteBusinessMessageUpdate>> = ParsedUpdateHandler<\n 'delete_business_message',\n T\n>\n\nexport type UpdateHandler =\n | RawUpdateHandler\n | NewMessageHandler\n | EditMessageHandler\n | MessageGroupHandler\n | DeleteMessageHandler\n | ChatMemberUpdateHandler\n | InlineQueryHandler\n | ChosenInlineResultHandler\n | CallbackQueryHandler\n | InlineCallbackQueryHandler\n | BusinessCallbackQueryHandler\n | PollUpdateHandler\n | PollVoteHandler\n | UserStatusUpdateHandler\n | UserTypingHandler\n | HistoryReadHandler\n | BotStoppedHandler\n | BotChatJoinRequestHandler\n | ChatJoinRequestHandler\n | PreCheckoutQueryHandler\n | StoryUpdateHandler\n | DeleteStoryHandler\n | BotReactionUpdateHandler\n | BotReactionCountUpdateHandler\n | BusinessConnectionUpdateHandler\n | NewBusinessMessageHandler\n | EditBusinessMessageHandler\n | BusinessMessageGroupHandler\n | DeleteBusinessMessageHandler\n\n// end-codegen\n"]}
package/esm/index.d.ts DELETED
@@ -1,8 +0,0 @@
1
- export * from './callback-data-builder.js';
2
- export * from './context/index.js';
3
- export * from './dispatcher.js';
4
- export * from './filters/index.js';
5
- export * from './handler.js';
6
- export * from './propagation.js';
7
- export * from './state/index.js';
8
- export * from './wizard.js';
package/esm/index.js DELETED
@@ -1,9 +0,0 @@
1
- export * from './callback-data-builder.js';
2
- export * from './context/index.js';
3
- export * from './dispatcher.js';
4
- export * from './filters/index.js';
5
- export * from './handler.js';
6
- export * from './propagation.js';
7
- export * from './state/index.js';
8
- export * from './wizard.js';
9
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oBAAoB,CAAA;AAClC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,cAAc,CAAA;AAC5B,cAAc,kBAAkB,CAAA;AAChC,cAAc,kBAAkB,CAAA;AAChC,cAAc,aAAa,CAAA","sourcesContent":["export * from './callback-data-builder.js'\nexport * from './context/index.js'\nexport * from './dispatcher.js'\nexport * from './filters/index.js'\nexport * from './handler.js'\nexport * from './propagation.js'\nexport * from './state/index.js'\nexport * from './wizard.js'\n"]}
@@ -1,22 +0,0 @@
1
- /**
2
- * Propagation action.
3
- *
4
- * `Stop`: Stop the propagation of the event through any handler groups
5
- * in the current dispatcher. Does not prevent child dispatchers from
6
- * being executed.
7
- *
8
- * `StopChildren`: Stop the propagation of the event through any handler groups
9
- * in the current dispatcher, and any of its children. If current dispatcher
10
- * is a child, does not prevent from propagating to its siblings.
11
- *
12
- * `Continue`: Continue propagating the event inside the same handler group.
13
- *
14
- * `ToScene`: Used after using `state.enter()` to dispatch the update to the scene,
15
- * or after `state.exit()` to dispatch the update to the root dispatcher.
16
- */
17
- export declare enum PropagationAction {
18
- Stop = "stop",
19
- StopChildren = "stop-children",
20
- Continue = "continue",
21
- ToScene = "scene"
22
- }
@@ -1,24 +0,0 @@
1
- /**
2
- * Propagation action.
3
- *
4
- * `Stop`: Stop the propagation of the event through any handler groups
5
- * in the current dispatcher. Does not prevent child dispatchers from
6
- * being executed.
7
- *
8
- * `StopChildren`: Stop the propagation of the event through any handler groups
9
- * in the current dispatcher, and any of its children. If current dispatcher
10
- * is a child, does not prevent from propagating to its siblings.
11
- *
12
- * `Continue`: Continue propagating the event inside the same handler group.
13
- *
14
- * `ToScene`: Used after using `state.enter()` to dispatch the update to the scene,
15
- * or after `state.exit()` to dispatch the update to the root dispatcher.
16
- */
17
- export var PropagationAction;
18
- (function (PropagationAction) {
19
- PropagationAction["Stop"] = "stop";
20
- PropagationAction["StopChildren"] = "stop-children";
21
- PropagationAction["Continue"] = "continue";
22
- PropagationAction["ToScene"] = "scene";
23
- })(PropagationAction || (PropagationAction = {}));
24
- //# sourceMappingURL=propagation.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"propagation.js","sourceRoot":"","sources":["../../src/propagation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAN,IAAY,iBAKX;AALD,WAAY,iBAAiB;IACzB,kCAAa,CAAA;IACb,mDAA8B,CAAA;IAC9B,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;AACrB,CAAC,EALW,iBAAiB,KAAjB,iBAAiB,QAK5B","sourcesContent":["/**\n * Propagation action.\n *\n * `Stop`: Stop the propagation of the event through any handler groups\n * in the current dispatcher. Does not prevent child dispatchers from\n * being executed.\n *\n * `StopChildren`: Stop the propagation of the event through any handler groups\n * in the current dispatcher, and any of its children. If current dispatcher\n * is a child, does not prevent from propagating to its siblings.\n *\n * `Continue`: Continue propagating the event inside the same handler group.\n *\n * `ToScene`: Used after using `state.enter()` to dispatch the update to the scene,\n * or after `state.exit()` to dispatch the update to the root dispatcher.\n */\nexport enum PropagationAction {\n Stop = 'stop',\n StopChildren = 'stop-children',\n Continue = 'continue',\n ToScene = 'scene',\n}\n"]}
@@ -1,5 +0,0 @@
1
- export * from './key.js';
2
- export * from './provider.js';
3
- export * from './providers/index.js';
4
- export * from './repository.js';
5
- export * from './update-state.js';
@@ -1,6 +0,0 @@
1
- export * from './key.js';
2
- export * from './provider.js';
3
- export * from './providers/index.js';
4
- export * from './repository.js';
5
- export * from './update-state.js';
6
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/state/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,eAAe,CAAA;AAC7B,cAAc,sBAAsB,CAAA;AACpC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,mBAAmB,CAAA","sourcesContent":["export * from './key.js'\nexport * from './provider.js'\nexport * from './providers/index.js'\nexport * from './repository.js'\nexport * from './update-state.js'\n"]}
@@ -1,24 +0,0 @@
1
- import type { MaybePromise, Peer } from '@mtcute/core';
2
- import type { BusinessMessageContext } from '../context/business-message.js';
3
- import type { CallbackQueryContext, MessageContext } from '../context/index.js';
4
- /**
5
- * Function that determines how the state key is derived.
6
- *
7
- * The key is additionally prefixed with current scene, if any.
8
- *
9
- * @param msg Message or callback from which to derive the key
10
- * @param scene Current scene UID, or `null` if none
11
- */
12
- export type StateKeyDelegate = (upd: MessageContext | BusinessMessageContext | CallbackQueryContext | Peer) => MaybePromise<string | null>;
13
- /**
14
- * Default state key delegate.
15
- *
16
- * Derives key as follows:
17
- * - If private chat, `msg.chat.id`
18
- * - If group chat, `msg.chat.id + '_' + msg.sender.id`
19
- * - If channel, `msg.chat.id`
20
- * - If non-inline callback query:
21
- * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`
22
- * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`
23
- */
24
- export declare const defaultStateKeyDelegate: StateKeyDelegate;
package/esm/state/key.js DELETED
@@ -1,39 +0,0 @@
1
- import { assertNever } from '@mtcute/core';
2
- /**
3
- * Default state key delegate.
4
- *
5
- * Derives key as follows:
6
- * - If private chat, `msg.chat.id`
7
- * - If group chat, `msg.chat.id + '_' + msg.sender.id`
8
- * - If channel, `msg.chat.id`
9
- * - If non-inline callback query:
10
- * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`
11
- * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`
12
- */
13
- export const defaultStateKeyDelegate = (upd) => {
14
- if ('type' in upd) {
15
- // User | Chat
16
- return String(upd.id);
17
- }
18
- if (upd._name === 'new_message' || upd._name === 'new_business_message') {
19
- switch (upd.chat.chatType) {
20
- case 'private':
21
- case 'bot':
22
- case 'channel':
23
- return String(upd.chat.id);
24
- case 'group':
25
- case 'supergroup':
26
- case 'gigagroup':
27
- return `${upd.chat.id}_${upd.sender.id}`;
28
- default:
29
- assertNever(upd.chat.chatType);
30
- }
31
- }
32
- if (upd._name === 'callback_query') {
33
- if (upd.chat.chatType === 'private')
34
- return `${upd.user.id}`;
35
- return `${upd.chat.id}_${upd.user.id}`;
36
- }
37
- return null;
38
- };
39
- //# sourceMappingURL=key.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAA;AAiB1C;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAqB,CAAC,GAAG,EAAiB,EAAE;IAC5E,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,cAAc;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,IAAI,GAAG,CAAC,KAAK,KAAK,sBAAsB,EAAE,CAAC;QACtE,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,SAAS,CAAC;YACf,KAAK,KAAK,CAAC;YACX,KAAK,SAAS;gBACV,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC9B,KAAK,OAAO,CAAC;YACb,KAAK,YAAY,CAAC;YAClB,KAAK,WAAW;gBACZ,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;YAC5C;gBACI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtC,CAAC;IACL,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;QACjC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;QAE5D,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;IAC1C,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA","sourcesContent":["import type { MaybePromise, Peer } from '@mtcute/core'\nimport { assertNever } from '@mtcute/core'\n\nimport type { BusinessMessageContext } from '../context/business-message.js'\nimport type { CallbackQueryContext, MessageContext } from '../context/index.js'\n\n/**\n * Function that determines how the state key is derived.\n *\n * The key is additionally prefixed with current scene, if any.\n *\n * @param msg Message or callback from which to derive the key\n * @param scene Current scene UID, or `null` if none\n */\nexport type StateKeyDelegate = (\n upd: MessageContext | BusinessMessageContext | CallbackQueryContext | Peer,\n) => MaybePromise<string | null>\n\n/**\n * Default state key delegate.\n *\n * Derives key as follows:\n * - If private chat, `msg.chat.id`\n * - If group chat, `msg.chat.id + '_' + msg.sender.id`\n * - If channel, `msg.chat.id`\n * - If non-inline callback query:\n * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`\n * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`\n */\nexport const defaultStateKeyDelegate: StateKeyDelegate = (upd): string | null => {\n if ('type' in upd) {\n // User | Chat\n return String(upd.id)\n }\n\n if (upd._name === 'new_message' || upd._name === 'new_business_message') {\n switch (upd.chat.chatType) {\n case 'private':\n case 'bot':\n case 'channel':\n return String(upd.chat.id)\n case 'group':\n case 'supergroup':\n case 'gigagroup':\n return `${upd.chat.id}_${upd.sender.id}`\n default:\n assertNever(upd.chat.chatType)\n }\n }\n\n if (upd._name === 'callback_query') {\n if (upd.chat.chatType === 'private') return `${upd.user.id}`\n\n return `${upd.chat.id}_${upd.user.id}`\n }\n\n return null\n}\n"]}
@@ -1,5 +0,0 @@
1
- import type { IStorageProvider } from '@mtcute/core';
2
- import type { IStateRepository } from './repository.js';
3
- export type IStateStorageProvider = IStorageProvider<{
4
- state: IStateRepository;
5
- }>;
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=provider.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/state/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { IStorageProvider } from '@mtcute/core'\n\nimport type { IStateRepository } from './repository.js'\n\nexport type IStateStorageProvider = IStorageProvider<{\n state: IStateRepository\n}>\n"]}
@@ -1,2 +0,0 @@
1
- export * from './memory.js';
2
- export * from './sqlite.js';
@@ -1,3 +0,0 @@
1
- export * from './memory.js';
2
- export * from './sqlite.js';
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/state/providers/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA","sourcesContent":["export * from './memory.js'\nexport * from './sqlite.js'\n"]}
@@ -1,30 +0,0 @@
1
- import type { MaybePromise } from '@mtcute/core';
2
- import { MemoryStorageDriver } from '@mtcute/core';
3
- import type { IStateStorageProvider } from '../provider.js';
4
- import type { IStateRepository } from '../repository.js';
5
- interface StateDto {
6
- value: string;
7
- expiresAt?: number;
8
- }
9
- interface RateLimitDto {
10
- reset: number;
11
- remaining: number;
12
- }
13
- declare class MemoryStateRepository implements IStateRepository {
14
- readonly _driver: MemoryStorageDriver;
15
- readonly state: Map<string, StateDto>;
16
- readonly rl: Map<string, RateLimitDto>;
17
- constructor(_driver: MemoryStorageDriver);
18
- setState(key: string, state: string, ttl?: number | undefined): void;
19
- getState(key: string, now: number): string | null;
20
- deleteState(key: string): void;
21
- vacuum(now: number): void;
22
- getRateLimit(key: string, now: number, limit: number, window: number): [number, number];
23
- resetRateLimit(key: string): MaybePromise<void>;
24
- }
25
- export declare class MemoryStateStorage implements IStateStorageProvider {
26
- readonly driver: MemoryStorageDriver;
27
- readonly state: MemoryStateRepository;
28
- constructor(driver?: MemoryStorageDriver);
29
- }
30
- export {};