@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,65 +0,0 @@
1
- /**
2
- * For message groups, apply a filter to every message in the group.
3
- * Filter will match if **all** messages match.
4
- *
5
- * > **Note**: This also applies type modification to every message in the group
6
- *
7
- * @param filter
8
- * @returns
9
- */
10
- export function every(filter) {
11
- return (ctx, state) => {
12
- let i = 0;
13
- const upds = ctx.messages;
14
- const max = upds.length;
15
- const next = () => {
16
- if (i === max)
17
- return true;
18
- const res = filter(upds[i++], state);
19
- if (typeof res === 'boolean') {
20
- if (!res)
21
- return false;
22
- return next();
23
- }
24
- return res.then((r) => {
25
- if (!r)
26
- return false;
27
- return next();
28
- });
29
- };
30
- return next();
31
- };
32
- }
33
- /**
34
- * For message groups, apply a filter to every message in the group.
35
- * Filter will match if **any** message matches.
36
- *
37
- * > **Note**: This *does not* apply type modification to any message
38
- *
39
- * @param filter
40
- * @returns
41
- */
42
- export function some(filter) {
43
- return (ctx, state) => {
44
- let i = 0;
45
- const upds = ctx.messages;
46
- const max = upds.length;
47
- const next = () => {
48
- if (i === max)
49
- return false;
50
- const res = filter(upds[i++], state);
51
- if (typeof res === 'boolean') {
52
- if (res)
53
- return true;
54
- return next();
55
- }
56
- return res.then((r) => {
57
- if (r)
58
- return true;
59
- return next();
60
- });
61
- };
62
- return next();
63
- };
64
- }
65
- //# sourceMappingURL=group.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"group.js","sourceRoot":"","sources":["../../../src/filters/group.ts"],"names":[],"mappings":"AAOA;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CACjB,MAAyC;IAQzC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAA;QAEvB,MAAM,IAAI,GAAG,GAA0B,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAA;YAE1B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;YAEpC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC3B,IAAI,CAAC,GAAG;oBAAE,OAAO,KAAK,CAAA;gBAEtB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC,CAAC;oBAAE,OAAO,KAAK,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,IAAI,CAChB,MAAyC;IAGzC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,MAAM,IAAI,GAAG,GAAG,CAAC,QAAQ,CAAA;QACzB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,CAAA;QAEvB,MAAM,IAAI,GAAG,GAA0B,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAA;YAE3B,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAA;YAEpC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC3B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAElB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC","sourcesContent":["import type { MaybePromise, Message } from '@mtcute/core'\n\nimport type { BusinessMessageContext } from '../context/business-message.js'\nimport type { MessageContext } from '../context/message.js'\n\nimport type { Modify, UpdateFilter } from './types.js'\n\n/**\n * For message groups, apply a filter to every message in the group.\n * Filter will match if **all** messages match.\n *\n * > **Note**: This also applies type modification to every message in the group\n *\n * @param filter\n * @returns\n */\nexport function every<Mod, State extends object>(\n filter: UpdateFilter<Message, Mod, State>,\n): UpdateFilter<\n MessageContext | BusinessMessageContext,\n Mod & {\n messages: Modify<MessageContext | BusinessMessageContext, Mod>[]\n },\n State\n > {\n return (ctx, state) => {\n let i = 0\n const upds = ctx.messages\n const max = upds.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return true\n\n const res = filter(upds[i++], state)\n\n if (typeof res === 'boolean') {\n if (!res) return false\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (!r) return false\n\n return next()\n })\n }\n\n return next()\n }\n}\n\n/**\n * For message groups, apply a filter to every message in the group.\n * Filter will match if **any** message matches.\n *\n * > **Note**: This *does not* apply type modification to any message\n *\n * @param filter\n * @returns\n */\nexport function some<State extends object>(\n filter: UpdateFilter<Message, any, State>,\n // eslint-disable-next-line\n): UpdateFilter<MessageContext | BusinessMessageContext, {}, State> {\n return (ctx, state) => {\n let i = 0\n const upds = ctx.messages\n const max = upds.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return false\n\n const res = filter(upds[i++], state)\n\n if (typeof res === 'boolean') {\n if (res) return true\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (r) return true\n\n return next()\n })\n }\n\n return next()\n }\n}\n"]}
@@ -1,4 +0,0 @@
1
- import * as filters from './bundle.js';
2
- import UpdateFilter = filters.UpdateFilter;
3
- export { filters };
4
- export type { UpdateFilter };
@@ -1,3 +0,0 @@
1
- import * as filters from './bundle.js';
2
- export { filters };
3
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filters/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AAItC,OAAO,EAAE,OAAO,EAAE,CAAA","sourcesContent":["import * as filters from './bundle.js'\n\nimport UpdateFilter = filters.UpdateFilter\n\nexport { filters }\nexport type { UpdateFilter }\n"]}
@@ -1,29 +0,0 @@
1
- import type { ExtractBaseMany, ExtractMod, Invert, UnionToIntersection, UpdateFilter } from './types.js';
2
- /**
3
- * Filter that matches any update
4
- */
5
- export declare const any: UpdateFilter<any>;
6
- /**
7
- * Invert a filter by applying a NOT logical operation:
8
- * `not(fn) = NOT fn`
9
- *
10
- * > **Note**: This also inverts type modification, i.e.
11
- * > if the base is `{ field: string | number | null }`
12
- * > and the modification is `{ field: string }`,
13
- * > then the negated filter will have
14
- * > inverted modification `{ field: number | null }`
15
- *
16
- * @param fn Filter to negate
17
- */
18
- export declare function not<Base, Mod, State extends object>(fn: UpdateFilter<Base, Mod, State>): UpdateFilter<Base, Invert<Base, Mod>, State>;
19
- export declare function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>): UpdateFilter<Base1 & Base2, Mod1 & Mod2, State1 | State2>;
20
- export declare function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>): UpdateFilter<Base1 & Base2 & Base3, Mod1 & Mod2 & Mod3, State1 | State2 | State3>;
21
- export declare function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object, Base4, Mod4, State4 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>, fn4: UpdateFilter<Base4, Mod4, State4>): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 & Mod2 & Mod3 & Mod4, State1 | State2 | State3 | State4>;
22
- export declare function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object, Base4, Mod4, State4 extends object, Base5, Mod5, State5 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>, fn4: UpdateFilter<Base4, Mod4, State4>, fn5: UpdateFilter<Base5, Mod5, State5>): UpdateFilter<Base1 & Base2 & Base3 & Base4 & Base5, Mod1 & Mod2 & Mod3 & Mod4 & Mod5, State1 | State2 | State3 | State4 | State5>;
23
- export declare function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object, Base4, Mod4, State4 extends object, Base5, Mod5, State5 extends object, Base6, Mod6, State6 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>, fn4: UpdateFilter<Base4, Mod4, State4>, fn5: UpdateFilter<Base5, Mod5, State5>, fn6: UpdateFilter<Base6, Mod6, State6>): UpdateFilter<Base1 & Base2 & Base3 & Base4 & Base5 & Base6, Mod1 & Mod2 & Mod3 & Mod4 & Mod5 & Mod6, State1 | State2 | State3 | State4 | State5 | State6>;
24
- export declare function and<Filters extends UpdateFilter<any, any>[]>(...fns: Filters): UpdateFilter<ExtractBaseMany<Filters>, UnionToIntersection<ExtractMod<Filters[number]>>>;
25
- export declare function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>): UpdateFilter<Base1 & Base2, Mod1 | Mod2, State1 | State2>;
26
- export declare function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>): UpdateFilter<Base1 & Base2 & Base3, Mod1 | Mod2 | Mod3, State1 | State2 | State3>;
27
- export declare function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object, Base4, Mod4, State4 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>, fn4: UpdateFilter<Base4, Mod4, State4>): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 | Mod2 | Mod3 | Mod4, State1 | State2 | State3 | State4>;
28
- export declare function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object, Base4, Mod4, State4 extends object, Base5, Mod5, State5 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>, fn4: UpdateFilter<Base4, Mod4, State4>, fn5: UpdateFilter<Base5, Mod5, State5>): UpdateFilter<Base1 & Base2 & Base3 & Base4 & Base5, Mod1 | Mod2 | Mod3 | Mod4 | Mod5, State1 | State2 | State3 | State4 | State5>;
29
- export declare function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object, Base3, Mod3, State3 extends object, Base4, Mod4, State4 extends object, Base5, Mod5, State5 extends object, Base6, Mod6, State6 extends object>(fn1: UpdateFilter<Base1, Mod1, State1>, fn2: UpdateFilter<Base2, Mod2, State2>, fn3: UpdateFilter<Base3, Mod3, State3>, fn4: UpdateFilter<Base4, Mod4, State4>, fn5: UpdateFilter<Base5, Mod5, State5>, fn6: UpdateFilter<Base6, Mod6, State6>): UpdateFilter<Base1 & Base2 & Base3 & Base4 & Base5 & Base6, Mod1 | Mod2 | Mod3 | Mod4 | Mod5 | Mod6, State1 | State2 | State3 | State4 | State5 | State6>;
@@ -1,105 +0,0 @@
1
- /**
2
- * Filter that matches any update
3
- */
4
- export const any = () => true;
5
- /**
6
- * Invert a filter by applying a NOT logical operation:
7
- * `not(fn) = NOT fn`
8
- *
9
- * > **Note**: This also inverts type modification, i.e.
10
- * > if the base is `{ field: string | number | null }`
11
- * > and the modification is `{ field: string }`,
12
- * > then the negated filter will have
13
- * > inverted modification `{ field: number | null }`
14
- *
15
- * @param fn Filter to negate
16
- */
17
- export function not(fn) {
18
- return (upd, state) => {
19
- const res = fn(upd, state);
20
- if (typeof res === 'boolean')
21
- return !res;
22
- return res.then(r => !r);
23
- };
24
- }
25
- /**
26
- * Combine multiple filters by applying an AND logical
27
- * operation between every one of them:
28
- * `and(fn1, fn2, ..., fnN) = fn1 AND fn2 AND ... AND fnN`
29
- *
30
- * > **Note**: This also combines type modifications, i.e.
31
- * > if the 1st has modification `{ field1: string }`
32
- * > and the 2nd has modification `{ field2: number }`,
33
- * > then the combined filter will have
34
- * > combined modification `{ field1: string, field2: number }`
35
- *
36
- * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),
37
- * > state type is only correctly inferred for up to 6 filters.
38
- * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),
39
- * > or combine multiple `and` calls.
40
- *
41
- * @param fns Filters to combine
42
- */
43
- export function and(...fns) {
44
- return (upd, state) => {
45
- let i = 0;
46
- const max = fns.length;
47
- const next = () => {
48
- if (i === max)
49
- return true;
50
- const res = fns[i++](upd, state);
51
- if (typeof res === 'boolean') {
52
- if (!res)
53
- return false;
54
- return next();
55
- }
56
- return res.then((r) => {
57
- if (!r)
58
- return false;
59
- return next();
60
- });
61
- };
62
- return next();
63
- };
64
- }
65
- /**
66
- * Combine multiple filters by applying an OR logical
67
- * operation between every one of them:
68
- * `or(fn1, fn2, ..., fnN) = fn1 OR fn2 OR ... OR fnN`
69
- *
70
- * > **Note**: This also combines type modifications in a union, i.e.
71
- * > if the 1st has modification `{ field1: string }`
72
- * > and the 2nd has modification `{ field2: number }`,
73
- * > then the combined filter will have
74
- * > modification `{ field1: string } | { field2: number }`.
75
- *
76
- * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),
77
- * > state type is only correctly inferred for up to 6 filters.
78
- * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),
79
- * > or combine multiple `and` calls.
80
- *
81
- * @param fns Filters to combine
82
- */
83
- export function or(...fns) {
84
- return (upd, state) => {
85
- let i = 0;
86
- const max = fns.length;
87
- const next = () => {
88
- if (i === max)
89
- return false;
90
- const res = fns[i++](upd, state);
91
- if (typeof res === 'boolean') {
92
- if (res)
93
- return true;
94
- return next();
95
- }
96
- return res.then((r) => {
97
- if (r)
98
- return true;
99
- return next();
100
- });
101
- };
102
- return next();
103
- };
104
- }
105
- //# sourceMappingURL=logic.js.map
@@ -1 +0,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;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC;AAuGD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,EAAE,CAAC,GAAG,GAAkC;IACpD,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,IAAI,CAAC,GAAG,CAAC,CAAA;QACT,MAAM,GAAG,GAAG,GAAG,CAAC,MAAM,CAAA;QAEtB,MAAM,IAAI,GAAG,GAA0B,EAAE;YACrC,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,KAAK,CAAA;YAE3B,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAEhC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE,CAAC;gBAC3B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC;YAED,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAU,EAAE,EAAE;gBAC3B,IAAI,CAAC;oBAAE,OAAO,IAAI,CAAA;gBAElB,OAAO,IAAI,EAAE,CAAA;YACjB,CAAC,CAAC,CAAA;QACN,CAAC,CAAA;QAED,OAAO,IAAI,EAAE,CAAA;IACjB,CAAC,CAAA;AACL,CAAC","sourcesContent":["import type { MaybePromise } from '@mtcute/core'\n\nimport type { ExtractBaseMany, ExtractMod, Invert, UnionToIntersection, UpdateFilter } from './types.js'\n\n/**\n * Filter that matches any update\n */\nexport const any: UpdateFilter<any> = () => true\n\n/**\n * Invert a filter by applying a NOT logical operation:\n * `not(fn) = NOT fn`\n *\n * > **Note**: This also inverts type modification, i.e.\n * > if the base is `{ field: string | number | null }`\n * > and the modification is `{ field: string }`,\n * > then the negated filter will have\n * > inverted modification `{ field: number | null }`\n *\n * @param fn Filter to negate\n */\nexport function not<Base, Mod, State extends object>(\n fn: UpdateFilter<Base, Mod, State>,\n): UpdateFilter<Base, Invert<Base, Mod>, State> {\n return (upd, state) => {\n const res = fn(upd, state)\n\n if (typeof res === 'boolean') return !res\n\n return res.then(r => !r)\n }\n}\n\n// i couldn't come up with proper types for these 😭\n// if you know how to do this better - PRs are welcome!\n\nexport function and<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n): UpdateFilter<Base1 & Base2, Mod1 & Mod2, State1 | State2>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n): UpdateFilter<Base1 & Base2 & Base3, Mod1 & Mod2 & Mod3, State1 | State2 | State3>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 & Mod2 & Mod3 & Mod4, State1 | State2 | State3 | State4>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5,\n Mod1 & Mod2 & Mod3 & Mod4 & Mod5,\n State1 | State2 | State3 | State4 | State5\n>\nexport function and<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n Base6,\n Mod6,\n State6 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n fn6: UpdateFilter<Base6, Mod6, State6>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5 & Base6,\n Mod1 & Mod2 & Mod3 & Mod4 & Mod5 & Mod6,\n State1 | State2 | State3 | State4 | State5 | State6\n>\nexport function and<Filters extends UpdateFilter<any, any>[]>(\n ...fns: Filters\n): UpdateFilter<ExtractBaseMany<Filters>, UnionToIntersection<ExtractMod<Filters[number]>>>\n\n/**\n * Combine multiple filters by applying an AND logical\n * operation between every one of them:\n * `and(fn1, fn2, ..., fnN) = fn1 AND fn2 AND ... AND fnN`\n *\n * > **Note**: This also combines type modifications, i.e.\n * > if the 1st has modification `{ field1: string }`\n * > and the 2nd has modification `{ field2: number }`,\n * > then the combined filter will have\n * > combined modification `{ field1: string, field2: number }`\n *\n * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),\n * > state type is only correctly inferred for up to 6 filters.\n * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),\n * > or combine multiple `and` calls.\n *\n * @param fns Filters to combine\n */\nexport function and(...fns: UpdateFilter<any, any, any>[]): UpdateFilter<any, any, any> {\n return (upd, state) => {\n let i = 0\n const max = fns.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return true\n\n const res = fns[i++](upd, state)\n\n if (typeof res === 'boolean') {\n if (!res) return false\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (!r) return false\n\n return next()\n })\n }\n\n return next()\n }\n}\n\nexport function or<Base1, Mod1, State1 extends object, Base2, Mod2, State2 extends object>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n): UpdateFilter<Base1 & Base2, Mod1 | Mod2, State1 | State2>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n): UpdateFilter<Base1 & Base2 & Base3, Mod1 | Mod2 | Mod3, State1 | State2 | State3>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n): UpdateFilter<Base1 & Base2 & Base3 & Base4, Mod1 | Mod2 | Mod3 | Mod4, State1 | State2 | State3 | State4>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5,\n Mod1 | Mod2 | Mod3 | Mod4 | Mod5,\n State1 | State2 | State3 | State4 | State5\n>\n\nexport function or<\n Base1,\n Mod1,\n State1 extends object,\n Base2,\n Mod2,\n State2 extends object,\n Base3,\n Mod3,\n State3 extends object,\n Base4,\n Mod4,\n State4 extends object,\n Base5,\n Mod5,\n State5 extends object,\n Base6,\n Mod6,\n State6 extends object,\n>(\n fn1: UpdateFilter<Base1, Mod1, State1>,\n fn2: UpdateFilter<Base2, Mod2, State2>,\n fn3: UpdateFilter<Base3, Mod3, State3>,\n fn4: UpdateFilter<Base4, Mod4, State4>,\n fn5: UpdateFilter<Base5, Mod5, State5>,\n fn6: UpdateFilter<Base6, Mod6, State6>,\n): UpdateFilter<\n Base1 & Base2 & Base3 & Base4 & Base5 & Base6,\n Mod1 | Mod2 | Mod3 | Mod4 | Mod5 | Mod6,\n State1 | State2 | State3 | State4 | State5 | State6\n>\n\n/**\n * Combine multiple filters by applying an OR logical\n * operation between every one of them:\n * `or(fn1, fn2, ..., fnN) = fn1 OR fn2 OR ... OR fnN`\n *\n * > **Note**: This also combines type modifications in a union, i.e.\n * > if the 1st has modification `{ field1: string }`\n * > and the 2nd has modification `{ field2: number }`,\n * > then the combined filter will have\n * > modification `{ field1: string } | { field2: number }`.\n *\n * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),\n * > state type is only correctly inferred for up to 6 filters.\n * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),\n * > or combine multiple `and` calls.\n *\n * @param fns Filters to combine\n */\nexport function or(...fns: UpdateFilter<any, any, any>[]): UpdateFilter<any, any, any> {\n return (upd, state) => {\n let i = 0\n const max = fns.length\n\n const next = (): MaybePromise<boolean> => {\n if (i === max) return false\n\n const res = fns[i++](upd, state)\n\n if (typeof res === 'boolean') {\n if (res) return true\n\n return next()\n }\n\n return res.then((r: boolean) => {\n if (r) return true\n\n return next()\n })\n }\n\n return next()\n }\n}\n"]}
@@ -1,168 +0,0 @@
1
- import { RawDocument, RawLocation, } from '@mtcute/core';
2
- /**
3
- * Filter incoming messages.
4
- *
5
- * Messages sent to yourself (i.e. Saved Messages) are also "incoming"
6
- */
7
- export const incoming = msg => !msg.isOutgoing;
8
- /**
9
- * Filter outgoing messages.
10
- *
11
- * Messages sent to yourself (i.e. Saved Messages) are **not** "outgoing"
12
- */
13
- export const outgoing = msg => msg.isOutgoing;
14
- /**
15
- * Filter for scheduled messages
16
- */
17
- export const scheduled = msg => msg.isScheduled;
18
- /**
19
- * Filter messages that are replies to some other message
20
- */
21
- export const reply = msg => msg.replyToMessage !== null;
22
- /**
23
- * Filter messages that are replies with the given origin type
24
- */
25
- export function replyOrigin(origin) {
26
- return msg => msg.replyToMessage?.originIs(origin) ?? false;
27
- } // originIs does additional checks
28
- /**
29
- * Filter messages containing some media
30
- */
31
- export const media = msg => msg.media !== null;
32
- /**
33
- * Filter messages containing media of given type
34
- */
35
- export function mediaOf(type) {
36
- return msg => msg.media?.type === type;
37
- }
38
- /** Filter messages containing a photo */
39
- export const photo = mediaOf('photo');
40
- /** Filter messages containing a dice */
41
- export const dice = mediaOf('dice');
42
- /** Filter messages containing a contact */
43
- export const contact = mediaOf('contact');
44
- /** Filter messages containing an audio file */
45
- export const audio = mediaOf('audio');
46
- /** Filter messages containing a voice message (audio-only) */
47
- export const voice = mediaOf('voice');
48
- /** Filter messages containing a sticker */
49
- export const sticker = mediaOf('sticker');
50
- /** Filter messages containing a document (a file) */
51
- export const document = mediaOf('document');
52
- /** Filter messages containing any video (videos, round messages and animations) */
53
- export const anyVideo = mediaOf('video');
54
- /** Filter messages containing a static location */
55
- export const location = mediaOf('location');
56
- /** Filter messages containing a live location */
57
- export const liveLocation = mediaOf('live_location');
58
- /** Filter messages containing a game */
59
- export const game = mediaOf('game');
60
- /** Filter messages containing a web page */
61
- export const webpage = mediaOf('webpage');
62
- /** Filter messages containing a venue */
63
- export const venue = mediaOf('venue');
64
- /** Filter messages containing a poll */
65
- export const poll = mediaOf('poll');
66
- /** Filter messages containing an invoice */
67
- export const invoice = mediaOf('invoice');
68
- /**
69
- * Filter messages containing any location (live or static).
70
- */
71
- export const anyLocation = msg => msg.media instanceof RawLocation;
72
- /**
73
- * Filter messages containing a document
74
- *
75
- * This will also match media like audio, video, voice
76
- * that also use Documents
77
- */
78
- export const anyDocument = msg => msg.media instanceof RawDocument;
79
- /**
80
- * Filter messages containing a simple video.
81
- *
82
- * This does not include round messages and animations
83
- */
84
- export const video = msg => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound;
85
- /**
86
- * Filter messages containing an animation.
87
- *
88
- * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)
89
- * > are also considered animations.
90
- */
91
- export const animation = msg => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound;
92
- /**
93
- * Filter messages containing a round message (aka video note).
94
- */
95
- export const roundMessage = msg => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound;
96
- /**
97
- * Filter messages containing a sticker by its type
98
- */
99
- export function stickerByType(type) {
100
- return msg => msg.media?.type === 'sticker' && msg.media.stickerType === type;
101
- }
102
- /**
103
- * Filter messages containing a sticker by its source file type
104
- */
105
- export function stickerBySourceType(type) {
106
- return msg => msg.media?.type === 'sticker' && msg.media.sourceType === type;
107
- }
108
- /**
109
- * Filter text-only messages non-service messages
110
- */
111
- export const text = msg => msg.media === null && !msg.isService;
112
- /**
113
- * Filter service messages
114
- */
115
- export const service = msg => msg.isService;
116
- /**
117
- * Filter service messages by action type
118
- */
119
- export function action(type) {
120
- if (Array.isArray(type)) {
121
- const index = {};
122
- type.forEach(it => (index[it] = true));
123
- return msg => msg.action?.type in index;
124
- }
125
- return msg => msg.action?.type === type;
126
- }
127
- export function sender(type) {
128
- return msg => msg.sender.type === type;
129
- }
130
- /**
131
- * Filter that matches messages that are replies to some other message that can be fetched
132
- * (i.e. not `private` origin, and has not been deleted)
133
- *
134
- * Optionally, you can pass a filter that will be applied to the replied message.
135
- */
136
- export function replyTo(filter) {
137
- return async (msg, state) => {
138
- if (!msg.replyToMessage?.id)
139
- return false;
140
- const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo;
141
- if (!reply)
142
- return false;
143
- if (msg._name === 'new_message') {
144
- msg.getReplyTo = () => Promise.resolve(reply);
145
- }
146
- if (!filter)
147
- return true;
148
- return filter(reply, state);
149
- };
150
- }
151
- /**
152
- * Middleware-like filter that will fetch the sender of the message
153
- * and make it available to further filters, as well as the handler itself.
154
- */
155
- export function withCompleteSender(filter) {
156
- return async (msg, state) => {
157
- try {
158
- await msg.getCompleteSender();
159
- }
160
- catch {
161
- return false;
162
- }
163
- if (!filter)
164
- return true;
165
- return filter(msg, state);
166
- };
167
- }
168
- //# sourceMappingURL=message.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":"AA4BA,OAAO,EACH,WAAW,EACX,WAAW,GACd,MAAM,cAAc,CAAA;AAOrB;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAiD,GAAG,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAA;AAE5F;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAgD,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,UAAU,CAAA;AAE1F;;GAEG;AACH,MAAM,CAAC,MAAM,SAAS,GAAiD,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,CAAA;AAE7F;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAkE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,cAAc,KAAK,IAAI,CAAA;AAEtH;;GAEG;AACH,MAAM,UAAU,WAAW,CAAiC,MAAS;IAMjE,OAAO,GAAG,CAAC,EAAE,CACT,GAAG,CAAC,cAAc,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,KAAK,CAAA;AACrD,CAAC,CAAC,kCAAkC;AAEpC;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAsE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC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,aAAa,CAAC,CAAC,CAAC,MAAM,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAA;QAChF,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAA;QAExB,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,EAAE,CAAC;YAC9B,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QACjD,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;IAC/B,CAAC,CAAA;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,kBAAkB,CAC9B,MAAiD;IAEjD,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACxB,IAAI,CAAC;YACD,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;QACjC,CAAC;QAAC,MAAM,CAAC;YACL,OAAO,KAAK,CAAA;QAChB,CAAC;QAED,IAAI,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QAExB,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;IAC7B,CAAC,CAAA;AACL,CAAC","sourcesContent":["import type {\n Audio,\n Contact,\n Dice,\n Document,\n Game,\n Invoice,\n LiveLocation,\n Location,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n Peer,\n Photo,\n Poll,\n RepliedMessageInfo,\n RepliedMessageOrigin,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Venue,\n Video,\n Voice,\n WebPage,\n _RepliedMessageAssertionsByOrigin,\n} from '@mtcute/core'\nimport {\n RawDocument,\n RawLocation,\n} from '@mtcute/core'\n\nimport type { BusinessMessageContext } from '../context/business-message.js'\nimport type { MessageContext } from '../index.js'\n\nimport type { Modify, UpdateFilter } from './types.js'\n\n/**\n * Filter incoming messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are also \"incoming\"\n */\nexport const incoming: UpdateFilter<Message, { isOutgoing: false }> = msg => !msg.isOutgoing\n\n/**\n * Filter outgoing messages.\n *\n * Messages sent to yourself (i.e. Saved Messages) are **not** \"outgoing\"\n */\nexport const outgoing: UpdateFilter<Message, { isOutgoing: true }> = msg => msg.isOutgoing\n\n/**\n * Filter for scheduled messages\n */\nexport const scheduled: UpdateFilter<Message, { isScheduled: true }> = msg => msg.isScheduled\n\n/**\n * Filter messages that are replies to some other message\n */\nexport const reply: UpdateFilter<Message, { replyToMessage: RepliedMessageInfo }> = msg => msg.replyToMessage !== null\n\n/**\n * Filter messages that are replies with the given origin type\n */\nexport function replyOrigin<T extends RepliedMessageOrigin>(origin: T): UpdateFilter<\n Message,\n {\n replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & { origin: T }>\n }\n> {\n return msg =>\n msg.replyToMessage?.originIs(origin) ?? false\n} // originIs does additional checks\n\n/**\n * Filter messages containing some media\n */\nexport const media: UpdateFilter<Message, { media: Exclude<Message['media'], null> }> = msg => msg.media !== null\n\n/**\n * Filter messages containing media of given type\n */\nexport function mediaOf<T extends MessageMediaType>(type: T): UpdateFilter<\n Message,\n { media: Extract<Message['media'], { type: T }> }\n> {\n return msg =>\n msg.media?.type === type\n}\n\n/** Filter messages containing a photo */\nexport const photo: UpdateFilter<Message, { media: Photo }> = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice: UpdateFilter<Message, { media: Dice }> = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact: UpdateFilter<Message, { media: Contact }> = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio: UpdateFilter<Message, { media: Audio }> = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice: UpdateFilter<Message, { media: Voice }> = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker: UpdateFilter<Message, { media: Sticker }> = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document: UpdateFilter<Message, { media: Document }> = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo: UpdateFilter<Message, { media: Video }> = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location: UpdateFilter<Message, { media: Location }> = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation: UpdateFilter<Message, { media: LiveLocation }> = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game: UpdateFilter<Message, { media: Game }> = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage: UpdateFilter<Message, { media: WebPage }> = mediaOf('webpage')\n/** Filter messages containing a venue */\nexport const venue: UpdateFilter<Message, { media: Venue }> = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll: UpdateFilter<Message, { media: Poll }> = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const invoice: UpdateFilter<Message, { media: Invoice }> = mediaOf('invoice')\n\n/**\n * Filter messages containing any location (live or static).\n */\nexport const anyLocation: UpdateFilter<Message, { media: Location }> = msg => msg.media instanceof RawLocation\n\n/**\n * Filter messages containing a document\n *\n * This will also match media like audio, video, voice\n * that also use Documents\n */\nexport const anyDocument: UpdateFilter<Message, { media: RawDocument }> = msg => msg.media instanceof RawDocument\n\n/**\n * Filter messages containing a simple video.\n *\n * This does not include round messages and animations\n */\nexport const video: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: false\n }\n >\n }\n> = msg => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing an animation.\n *\n * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)\n * > are also considered animations.\n */\nexport const animation: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: false\n isAnimation: true\n }\n >\n }\n> = msg => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound\n\n/**\n * Filter messages containing a round message (aka video note).\n */\nexport const roundMessage: UpdateFilter<\n Message,\n {\n media: Modify<\n Video,\n {\n isRound: true\n isAnimation: false\n }\n >\n }\n> = msg => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound\n\n/**\n * Filter messages containing a sticker by its type\n */\nexport function stickerByType(type: StickerType): UpdateFilter<Message, { media: Sticker }> {\n return msg =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n}\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport function stickerBySourceType(type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> {\n return msg =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\n}\n\n/**\n * Filter text-only messages non-service messages\n */\nexport const text: UpdateFilter<\n Message,\n {\n media: null\n isService: false\n }\n> = msg => msg.media === null && !msg.isService\n\n/**\n * Filter service messages\n */\nexport const service: UpdateFilter<Message, { isService: true }> = msg => msg.isService\n\n/**\n * Filter service messages by action type\n */\nexport function action<T extends Exclude<MessageAction, null>['type']>(type: MaybeArray<T>): UpdateFilter<\n Message,\n {\n action: Extract<MessageAction, { type: T }>\n sender: T extends 'user_joined_link' | 'user_removed' | 'history_cleared' | 'contact_joined' | 'bot_allowed'\n ? User\n : Peer\n }\n> {\n if (Array.isArray(type)) {\n const index: Partial<Record<T, true>> = {}\n type.forEach(it => (index[it] = true))\n\n return msg => (msg.action?.type as any) in index\n }\n\n return msg => msg.action?.type === type\n}\n\nexport function sender<T extends Message['sender']['type']>(type: T): UpdateFilter<\n Message,\n { sender: Extract<Message['sender'], { type: T }> }\n> {\n return msg =>\n msg.sender.type === type\n}\n\n/**\n * Filter that matches messages that are replies to some other message that can be fetched\n * (i.e. not `private` origin, and has not been deleted)\n *\n * Optionally, you can pass a filter that will be applied to the replied message.\n */\nexport function replyTo<Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n): UpdateFilter<\n MessageContext | BusinessMessageContext,\n { getReplyTo: () => Promise<Message & Mod> },\n State\n > {\n return async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = msg._name === 'new_message' ? await msg.getReplyTo() : msg.replyTo\n if (!reply) return false\n\n if (msg._name === 'new_message') {\n msg.getReplyTo = () => Promise.resolve(reply)\n }\n\n if (!filter) return true\n\n return filter(reply, state)\n }\n}\n\n/**\n * Middleware-like filter that will fetch the sender of the message\n * and make it available to further filters, as well as the handler itself.\n */\nexport function withCompleteSender<Mod, State extends object>(\n filter?: UpdateFilter<MessageContext, Mod, State>,\n): UpdateFilter<MessageContext, Mod, State> {\n return async (msg, state) => {\n try {\n await msg.getCompleteSender()\n } catch {\n return false\n }\n\n if (!filter) return true\n\n return filter(msg, state)\n }\n}\n"]}
@@ -1,15 +0,0 @@
1
- import type { MaybePromise } from '@mtcute/core';
2
- import type { UpdateFilter } from './types.js';
3
- /**
4
- * Create a filter for the cases when the state is empty
5
- */
6
- export declare const stateEmpty: UpdateFilter<any>;
7
- /**
8
- * Create a filter based on state predicate
9
- *
10
- * If state exists and matches `predicate`, update passes
11
- * this filter, otherwise it doesn't
12
- *
13
- * @param predicate State predicate
14
- */
15
- export declare function state<T extends object>(predicate: (state: T) => MaybePromise<boolean>): UpdateFilter<any, {}, T>;
@@ -1,28 +0,0 @@
1
- /**
2
- * Create a filter for the cases when the state is empty
3
- */
4
- export const stateEmpty = async (upd, state) => {
5
- if (!state)
6
- return false;
7
- return !(await state.get());
8
- };
9
- /**
10
- * Create a filter based on state predicate
11
- *
12
- * If state exists and matches `predicate`, update passes
13
- * this filter, otherwise it doesn't
14
- *
15
- * @param predicate State predicate
16
- */
17
- // eslint-disable-next-line ts/no-empty-object-type
18
- export function state(predicate) {
19
- return async (upd, state) => {
20
- if (!state)
21
- return false;
22
- const data = await state.get();
23
- if (!data)
24
- return false;
25
- return predicate(data);
26
- };
27
- }
28
- //# sourceMappingURL=state.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"state.js","sourceRoot":"","sources":["../../../src/filters/state.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,CAAC,MAAM,UAAU,GAAsB,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IAC9D,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,OAAO,CAAC,CAAC,MAAM,KAAK,CAAC,GAAG,EAAE,CAAC,CAAA;AAC/B,CAAC,CAAA;AAED;;;;;;;GAOG;AACH,mDAAmD;AACnD,MAAM,UAAU,KAAK,CAAmB,SAA8C;IAClF,OAAO,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;QACxB,IAAI,CAAC,KAAK;YAAE,OAAO,KAAK,CAAA;QACxB,MAAM,IAAI,GAAG,MAAM,KAAK,CAAC,GAAG,EAAE,CAAA;QAC9B,IAAI,CAAC,IAAI;YAAE,OAAO,KAAK,CAAA;QAEvB,OAAO,SAAS,CAAC,IAAI,CAAC,CAAA;IAC1B,CAAC,CAAA;AACL,CAAC","sourcesContent":["import type { MaybePromise } from '@mtcute/core'\n\nimport type { UpdateFilter } from './types.js'\n\n/**\n * Create a filter for the cases when the state is empty\n */\nexport const stateEmpty: UpdateFilter<any> = async (upd, state) => {\n if (!state) return false\n\n return !(await state.get())\n}\n\n/**\n * Create a filter based on state predicate\n *\n * If state exists and matches `predicate`, update passes\n * this filter, otherwise it doesn't\n *\n * @param predicate State predicate\n */\n// eslint-disable-next-line ts/no-empty-object-type\nexport function state<T extends object>(predicate: (state: T) => MaybePromise<boolean>): UpdateFilter<any, {}, T> {\n return async (upd, state) => {\n if (!state) return false\n const data = await state.get()\n if (!data) return false\n\n return predicate(data)\n }\n}\n"]}
@@ -1,129 +0,0 @@
1
- function extractText(obj) {
2
- switch (obj._name) {
3
- case 'new_message':
4
- case 'new_business_message':
5
- return obj.text;
6
- case 'inline_query':
7
- return obj.query;
8
- case 'chosen_inline_result':
9
- return obj.id;
10
- case 'callback_query':
11
- case 'inline_callback_query':
12
- case 'business_callback_query':
13
- if (obj.raw.data)
14
- return obj.dataStr;
15
- }
16
- return null;
17
- }
18
- /**
19
- * Filter objects that match a given regular expression
20
- * - for `Message`, `Message.text` is used
21
- * - for `InlineQuery`, `InlineQuery.query` is used
22
- * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used
23
- * - for callback queries, `dataStr` is used
24
- *
25
- * When a regex matches, the match array is stored in a
26
- * type-safe extension field `.match` of the object
27
- *
28
- * @param regex Regex to be matched
29
- */
30
- export function regex(regex) {
31
- return (obj) => {
32
- const txt = extractText(obj);
33
- if (!txt)
34
- return false;
35
- const m = txt.match(regex);
36
- if (m) {
37
- obj.match = m;
38
- return true;
39
- }
40
- return false;
41
- };
42
- }
43
- /**
44
- * Filter objects which contain the exact text given
45
- * - for `Message`, `Message.text` is used
46
- * - for `InlineQuery`, `InlineQuery.query` is used
47
- * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
48
- * - for callback queries, `dataStr` is used
49
- *
50
- * @param str String to be matched
51
- * @param ignoreCase Whether string case should be ignored
52
- */
53
- export function equals(str, ignoreCase = false) {
54
- if (ignoreCase) {
55
- str = str.toLowerCase();
56
- return obj => extractText(obj)?.toLowerCase() === str;
57
- }
58
- return obj => extractText(obj) === str;
59
- }
60
- /**
61
- * Filter objects which contain the text given (as a substring)
62
- * - for `Message`, `Message.text` is used
63
- * - for `InlineQuery`, `InlineQuery.query` is used
64
- * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
65
- * - for callback queries, `dataStr` is used
66
- *
67
- * @param str Substring to be matched
68
- * @param ignoreCase Whether string case should be ignored
69
- */
70
- export function contains(str, ignoreCase = false) {
71
- if (ignoreCase) {
72
- str = str.toLowerCase();
73
- return (obj) => {
74
- const txt = extractText(obj);
75
- return txt != null && txt.toLowerCase().includes(str);
76
- };
77
- }
78
- return (obj) => {
79
- const txt = extractText(obj);
80
- return txt != null && txt.includes(str);
81
- };
82
- }
83
- /**
84
- * Filter objects which contain the text starting with a given string
85
- * - for `Message`, `Message.text` is used
86
- * - for `InlineQuery`, `InlineQuery.query` is used
87
- * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
88
- * - for callback queries, `dataStr` is used
89
- *
90
- * @param str Substring to be matched
91
- * @param ignoreCase Whether string case should be ignored
92
- */
93
- export function startsWith(str, ignoreCase = false) {
94
- if (ignoreCase) {
95
- str = str.toLowerCase();
96
- return (obj) => {
97
- const txt = extractText(obj);
98
- return txt != null && txt.toLowerCase().substring(0, str.length) === str;
99
- };
100
- }
101
- return (obj) => {
102
- const txt = extractText(obj);
103
- return txt != null && txt.substring(0, str.length) === str;
104
- };
105
- }
106
- /**
107
- * Filter objects which contain the text ending with a given string
108
- * - for `Message`, `Message.text` is used
109
- * - for `InlineQuery`, `InlineQuery.query` is used
110
- * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
111
- * - for callback queries, `dataStr` is used
112
- *
113
- * @param str Substring to be matched
114
- * @param ignoreCase Whether string case should be ignored
115
- */
116
- export function endsWith(str, ignoreCase = false) {
117
- if (ignoreCase) {
118
- str = str.toLowerCase();
119
- return (obj) => {
120
- const txt = extractText(obj);
121
- return txt != null && txt.toLowerCase().substring(0, str.length) === str;
122
- };
123
- }
124
- return (obj) => {
125
- const txt = extractText(obj);
126
- return txt != null && txt.substring(0, str.length) === str;
127
- };
128
- }
129
- //# sourceMappingURL=text.js.map