@mtcute/dispatcher 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (190) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +26 -0
  3. package/cjs/callback-data-builder.d.ts +43 -0
  4. package/cjs/callback-data-builder.js +99 -0
  5. package/cjs/callback-data-builder.js.map +1 -0
  6. package/cjs/context/base.d.ts +8 -0
  7. package/cjs/context/base.js +3 -0
  8. package/cjs/context/base.js.map +1 -0
  9. package/cjs/context/callback-query.d.ts +27 -0
  10. package/cjs/context/callback-query.js +56 -0
  11. package/cjs/context/callback-query.js.map +1 -0
  12. package/cjs/context/chat-join-request.d.ts +16 -0
  13. package/cjs/context/chat-join-request.js +34 -0
  14. package/cjs/context/chat-join-request.js.map +1 -0
  15. package/cjs/context/chosen-inline-result.d.ts +21 -0
  16. package/cjs/context/chosen-inline-result.js +35 -0
  17. package/cjs/context/chosen-inline-result.js.map +1 -0
  18. package/cjs/context/index.d.ts +8 -0
  19. package/cjs/context/index.js +24 -0
  20. package/cjs/context/index.js.map +1 -0
  21. package/cjs/context/inline-query.d.ts +14 -0
  22. package/cjs/context/inline-query.js +22 -0
  23. package/cjs/context/inline-query.js.map +1 -0
  24. package/cjs/context/message.d.ts +72 -0
  25. package/cjs/context/message.js +142 -0
  26. package/cjs/context/message.js.map +1 -0
  27. package/cjs/context/parse.d.ts +1 -0
  28. package/cjs/context/parse.js +34 -0
  29. package/cjs/context/parse.js.map +1 -0
  30. package/cjs/context/pre-checkout-query.d.ts +16 -0
  31. package/cjs/context/pre-checkout-query.js +26 -0
  32. package/cjs/context/pre-checkout-query.js.map +1 -0
  33. package/cjs/dispatcher.d.ts +641 -0
  34. package/cjs/dispatcher.js +765 -0
  35. package/cjs/dispatcher.js.map +1 -0
  36. package/cjs/filters/bots.d.ts +70 -0
  37. package/cjs/filters/bots.js +129 -0
  38. package/cjs/filters/bots.js.map +1 -0
  39. package/cjs/filters/bundle.d.ts +10 -0
  40. package/cjs/filters/bundle.js +27 -0
  41. package/cjs/filters/bundle.js.map +1 -0
  42. package/cjs/filters/chat.d.ts +27 -0
  43. package/cjs/filters/chat.js +55 -0
  44. package/cjs/filters/chat.js.map +1 -0
  45. package/cjs/filters/group.d.ts +25 -0
  46. package/cjs/filters/group.js +72 -0
  47. package/cjs/filters/group.js.map +1 -0
  48. package/cjs/filters/index.d.ts +3 -0
  49. package/cjs/filters/index.js +29 -0
  50. package/cjs/filters/index.js.map +1 -0
  51. package/cjs/filters/logic.d.ts +29 -0
  52. package/cjs/filters/logic.js +114 -0
  53. package/cjs/filters/logic.js.map +1 -0
  54. package/cjs/filters/message.d.ts +295 -0
  55. package/cjs/filters/message.js +150 -0
  56. package/cjs/filters/message.js.map +1 -0
  57. package/cjs/filters/state.d.ts +15 -0
  58. package/cjs/filters/state.js +32 -0
  59. package/cjs/filters/state.js.map +1 -0
  60. package/cjs/filters/text.d.ts +64 -0
  61. package/cjs/filters/text.js +132 -0
  62. package/cjs/filters/text.js.map +1 -0
  63. package/cjs/filters/types.d.ts +91 -0
  64. package/cjs/filters/types.js +6 -0
  65. package/cjs/filters/types.js.map +1 -0
  66. package/cjs/filters/updates.d.ts +46 -0
  67. package/cjs/filters/updates.js +46 -0
  68. package/cjs/filters/updates.js.map +1 -0
  69. package/cjs/filters/user.d.ts +24 -0
  70. package/cjs/filters/user.js +76 -0
  71. package/cjs/filters/user.js.map +1 -0
  72. package/cjs/handler.d.ts +31 -0
  73. package/cjs/handler.js +4 -0
  74. package/cjs/handler.js.map +1 -0
  75. package/cjs/index.d.ts +8 -0
  76. package/cjs/index.js +25 -0
  77. package/cjs/index.js.map +1 -0
  78. package/cjs/package.json +3 -0
  79. package/cjs/propagation.d.ts +21 -0
  80. package/cjs/propagation.js +26 -0
  81. package/cjs/propagation.js.map +1 -0
  82. package/cjs/state/index.d.ts +3 -0
  83. package/cjs/state/index.js +20 -0
  84. package/cjs/state/index.js.map +1 -0
  85. package/cjs/state/key.d.ts +23 -0
  86. package/cjs/state/key.js +45 -0
  87. package/cjs/state/key.js.map +1 -0
  88. package/cjs/state/storage.d.ts +75 -0
  89. package/cjs/state/storage.js +17 -0
  90. package/cjs/state/storage.js.map +1 -0
  91. package/cjs/state/update-state.d.ts +151 -0
  92. package/cjs/state/update-state.js +211 -0
  93. package/cjs/state/update-state.js.map +1 -0
  94. package/cjs/wizard.d.ts +60 -0
  95. package/cjs/wizard.js +103 -0
  96. package/cjs/wizard.js.map +1 -0
  97. package/esm/callback-data-builder.d.ts +43 -0
  98. package/esm/callback-data-builder.js +95 -0
  99. package/esm/callback-data-builder.js.map +1 -0
  100. package/esm/context/base.d.ts +8 -0
  101. package/esm/context/base.js +2 -0
  102. package/esm/context/base.js.map +1 -0
  103. package/esm/context/callback-query.d.ts +27 -0
  104. package/esm/context/callback-query.js +52 -0
  105. package/esm/context/callback-query.js.map +1 -0
  106. package/esm/context/chat-join-request.d.ts +16 -0
  107. package/esm/context/chat-join-request.js +30 -0
  108. package/esm/context/chat-join-request.js.map +1 -0
  109. package/esm/context/chosen-inline-result.d.ts +21 -0
  110. package/esm/context/chosen-inline-result.js +31 -0
  111. package/esm/context/chosen-inline-result.js.map +1 -0
  112. package/esm/context/index.d.ts +8 -0
  113. package/esm/context/index.js +8 -0
  114. package/esm/context/index.js.map +1 -0
  115. package/esm/context/inline-query.d.ts +14 -0
  116. package/esm/context/inline-query.js +18 -0
  117. package/esm/context/inline-query.js.map +1 -0
  118. package/esm/context/message.d.ts +72 -0
  119. package/esm/context/message.js +138 -0
  120. package/esm/context/message.js.map +1 -0
  121. package/esm/context/parse.d.ts +1 -0
  122. package/esm/context/parse.js +30 -0
  123. package/esm/context/parse.js.map +1 -0
  124. package/esm/context/pre-checkout-query.d.ts +16 -0
  125. package/esm/context/pre-checkout-query.js +22 -0
  126. package/esm/context/pre-checkout-query.js.map +1 -0
  127. package/esm/dispatcher.d.ts +641 -0
  128. package/esm/dispatcher.js +761 -0
  129. package/esm/dispatcher.js.map +1 -0
  130. package/esm/filters/bots.d.ts +70 -0
  131. package/esm/filters/bots.js +125 -0
  132. package/esm/filters/bots.js.map +1 -0
  133. package/esm/filters/bundle.d.ts +10 -0
  134. package/esm/filters/bundle.js +11 -0
  135. package/esm/filters/bundle.js.map +1 -0
  136. package/esm/filters/chat.d.ts +27 -0
  137. package/esm/filters/chat.js +50 -0
  138. package/esm/filters/chat.js.map +1 -0
  139. package/esm/filters/group.d.ts +25 -0
  140. package/esm/filters/group.js +67 -0
  141. package/esm/filters/group.js.map +1 -0
  142. package/esm/filters/index.d.ts +3 -0
  143. package/esm/filters/index.js +3 -0
  144. package/esm/filters/index.js.map +1 -0
  145. package/esm/filters/logic.d.ts +29 -0
  146. package/esm/filters/logic.js +107 -0
  147. package/esm/filters/logic.js.map +1 -0
  148. package/esm/filters/message.d.ts +295 -0
  149. package/esm/filters/message.js +130 -0
  150. package/esm/filters/message.js.map +1 -0
  151. package/esm/filters/state.d.ts +15 -0
  152. package/esm/filters/state.js +27 -0
  153. package/esm/filters/state.js.map +1 -0
  154. package/esm/filters/text.d.ts +64 -0
  155. package/esm/filters/text.js +124 -0
  156. package/esm/filters/text.js.map +1 -0
  157. package/esm/filters/types.d.ts +91 -0
  158. package/esm/filters/types.js +5 -0
  159. package/esm/filters/types.js.map +1 -0
  160. package/esm/filters/updates.d.ts +46 -0
  161. package/esm/filters/updates.js +39 -0
  162. package/esm/filters/updates.js.map +1 -0
  163. package/esm/filters/user.d.ts +24 -0
  164. package/esm/filters/user.js +70 -0
  165. package/esm/filters/user.js.map +1 -0
  166. package/esm/handler.d.ts +31 -0
  167. package/esm/handler.js +3 -0
  168. package/esm/handler.js.map +1 -0
  169. package/esm/index.d.ts +8 -0
  170. package/esm/index.js +9 -0
  171. package/esm/index.js.map +1 -0
  172. package/esm/propagation.d.ts +21 -0
  173. package/esm/propagation.js +23 -0
  174. package/esm/propagation.js.map +1 -0
  175. package/esm/state/index.d.ts +3 -0
  176. package/esm/state/index.js +4 -0
  177. package/esm/state/index.js.map +1 -0
  178. package/esm/state/key.d.ts +23 -0
  179. package/esm/state/key.js +41 -0
  180. package/esm/state/key.js.map +1 -0
  181. package/esm/state/storage.d.ts +75 -0
  182. package/esm/state/storage.js +13 -0
  183. package/esm/state/storage.js.map +1 -0
  184. package/esm/state/update-state.d.ts +151 -0
  185. package/esm/state/update-state.js +206 -0
  186. package/esm/state/update-state.js.map +1 -0
  187. package/esm/wizard.d.ts +60 -0
  188. package/esm/wizard.js +99 -0
  189. package/esm/wizard.js.map +1 -0
  190. package/package.json +21 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"group.js","sourceRoot":"","sources":["../../../src/filters/group.ts"],"names":[],"mappings":";;;AAKA;;;;;;;;GAQG;AACH,SAAgB,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,GAAwB,EAAE;YACnC,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;gBAC1B,IAAI,CAAC,GAAG;oBAAE,OAAO,KAAK,CAAA;gBAEtB,OAAO,IAAI,EAAE,CAAA;aAChB;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;AAlCD,sBAkCC;AAED;;;;;;;;GAQG;AACH,SAAgB,IAAI;AAChB,2BAA2B;AAC3B,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,GAAwB,EAAE;YACnC,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;gBAC1B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;aAChB;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;AA9BD,oBA8BC","sourcesContent":["import { MaybeAsync, Message } from '@mtcute/client'\n\nimport { MessageContext } from '../context/message.js'\nimport { 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,\n Mod & {\n messages: Modify<MessageContext, 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 = (): MaybeAsync<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 // eslint-disable-next-line\n filter: UpdateFilter<Message, any, State>,\n // eslint-disable-next-line\n): UpdateFilter<MessageContext, {}, State> {\n return (ctx, state) => {\n let i = 0\n const upds = ctx.messages\n const max = upds.length\n\n const next = (): MaybeAsync<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"]}
@@ -0,0 +1,3 @@
1
+ import * as filters from './bundle.js';
2
+ import UpdateFilter = filters.UpdateFilter;
3
+ export { filters, UpdateFilter };
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.filters = void 0;
27
+ const filters = __importStar(require("./bundle.js"));
28
+ exports.filters = filters;
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filters/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,qDAAsC;AAE7B,0BAAO","sourcesContent":["import * as filters from './bundle.js'\nimport UpdateFilter = filters.UpdateFilter\nexport { filters, UpdateFilter }\n"]}
@@ -0,0 +1,29 @@
1
+ import { 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>;
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ /* eslint-disable @typescript-eslint/no-explicit-any */
3
+ // ^^ will be looked into in MTQ-29
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.or = exports.and = exports.not = exports.any = void 0;
6
+ /**
7
+ * Filter that matches any update
8
+ */
9
+ const any = () => true;
10
+ exports.any = any;
11
+ /**
12
+ * Invert a filter by applying a NOT logical operation:
13
+ * `not(fn) = NOT fn`
14
+ *
15
+ * > **Note**: This also inverts type modification, i.e.
16
+ * > if the base is `{ field: string | number | null }`
17
+ * > and the modification is `{ field: string }`,
18
+ * > then the negated filter will have
19
+ * > inverted modification `{ field: number | null }`
20
+ *
21
+ * @param fn Filter to negate
22
+ */
23
+ function not(fn) {
24
+ return (upd, state) => {
25
+ const res = fn(upd, state);
26
+ if (typeof res === 'boolean')
27
+ return !res;
28
+ return res.then((r) => !r);
29
+ };
30
+ }
31
+ exports.not = not;
32
+ /**
33
+ * Combine multiple filters by applying an AND logical
34
+ * operation between every one of them:
35
+ * `and(fn1, fn2, ..., fnN) = fn1 AND fn2 AND ... AND fnN`
36
+ *
37
+ * > **Note**: This also combines type modifications, i.e.
38
+ * > if the 1st has modification `{ field1: string }`
39
+ * > and the 2nd has modification `{ field2: number }`,
40
+ * > then the combined filter will have
41
+ * > combined modification `{ field1: string, field2: number }`
42
+ *
43
+ * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),
44
+ * > state type is only correctly inferred for up to 6 filters.
45
+ * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),
46
+ * > or combine multiple `and` calls.
47
+ *
48
+ * @param fns Filters to combine
49
+ */
50
+ function and(...fns) {
51
+ return (upd, state) => {
52
+ let i = 0;
53
+ const max = fns.length;
54
+ const next = () => {
55
+ if (i === max)
56
+ return true;
57
+ const res = fns[i++](upd, state);
58
+ if (typeof res === 'boolean') {
59
+ if (!res)
60
+ return false;
61
+ return next();
62
+ }
63
+ return res.then((r) => {
64
+ if (!r)
65
+ return false;
66
+ return next();
67
+ });
68
+ };
69
+ return next();
70
+ };
71
+ }
72
+ exports.and = and;
73
+ /**
74
+ * Combine multiple filters by applying an OR logical
75
+ * operation between every one of them:
76
+ * `or(fn1, fn2, ..., fnN) = fn1 OR fn2 OR ... OR fnN`
77
+ *
78
+ * > **Note**: This also combines type modifications in a union, i.e.
79
+ * > if the 1st has modification `{ field1: string }`
80
+ * > and the 2nd has modification `{ field2: number }`,
81
+ * > then the combined filter will have
82
+ * > modification `{ field1: string } | { field2: number }`.
83
+ *
84
+ * > **Note**: Due to TypeScript limitations (or more likely my lack of brain cells),
85
+ * > state type is only correctly inferred for up to 6 filters.
86
+ * > If you need more, either provide type explicitly (e.g. `filters.state<SomeState>(...)`),
87
+ * > or combine multiple `and` calls.
88
+ *
89
+ * @param fns Filters to combine
90
+ */
91
+ function or(...fns) {
92
+ return (upd, state) => {
93
+ let i = 0;
94
+ const max = fns.length;
95
+ const next = () => {
96
+ if (i === max)
97
+ return false;
98
+ const res = fns[i++](upd, state);
99
+ if (typeof res === 'boolean') {
100
+ if (res)
101
+ return true;
102
+ return next();
103
+ }
104
+ return res.then((r) => {
105
+ if (r)
106
+ return true;
107
+ return next();
108
+ });
109
+ };
110
+ return next();
111
+ };
112
+ }
113
+ exports.or = or;
114
+ //# sourceMappingURL=logic.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logic.js","sourceRoot":"","sources":["../../../src/filters/logic.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD,mCAAmC;;;AAMnC;;GAEG;AACI,MAAM,GAAG,GAAsB,GAAG,EAAE,CAAC,IAAI,CAAA;AAAnC,QAAA,GAAG,OAAgC;AAEhD;;;;;;;;;;;GAWG;AACH,SAAgB,GAAG,CACf,EAAkC;IAElC,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE;QAClB,MAAM,GAAG,GAAG,EAAE,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;QAE1B,IAAI,OAAO,GAAG,KAAK,SAAS;YAAE,OAAO,CAAC,GAAG,CAAA;QAEzC,OAAO,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;IAC9B,CAAC,CAAA;AACL,CAAC;AAVD,kBAUC;AAyGD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,GAAG,CAAC,GAAG,GAAkC;IACrD,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,GAAwB,EAAE;YACnC,IAAI,CAAC,KAAK,GAAG;gBAAE,OAAO,IAAI,CAAA;YAE1B,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;YAEhC,IAAI,OAAO,GAAG,KAAK,SAAS,EAAE;gBAC1B,IAAI,CAAC,GAAG;oBAAE,OAAO,KAAK,CAAA;gBAEtB,OAAO,IAAI,EAAE,CAAA;aAChB;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;AAzBD,kBAyBC;AAuGD;;;;;;;;;;;;;;;;;GAiBG;AACH,SAAgB,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,GAAwB,EAAE;YACnC,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;gBAC1B,IAAI,GAAG;oBAAE,OAAO,IAAI,CAAA;gBAEpB,OAAO,IAAI,EAAE,CAAA;aAChB;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;AAzBD,gBAyBC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\n\nimport { MaybeAsync } from '@mtcute/client'\n\nimport { 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 = (): MaybeAsync<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 = (): MaybeAsync<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"]}
@@ -0,0 +1,295 @@
1
+ import { Chat, MaybeArray, Message, MessageAction, MessageReplyInfo, RawDocument, Sticker, StickerSourceType, StickerType, User, Video } from '@mtcute/client';
2
+ import { MessageContext } from '../index.js';
3
+ import { Modify, UpdateFilter } from './types.js';
4
+ /**
5
+ * Filter incoming messages.
6
+ *
7
+ * Messages sent to yourself (i.e. Saved Messages) are also "incoming"
8
+ */
9
+ export declare const incoming: UpdateFilter<Message, {
10
+ isOutgoing: false;
11
+ }>;
12
+ /**
13
+ * Filter outgoing messages.
14
+ *
15
+ * Messages sent to yourself (i.e. Saved Messages) are **not** "outgoing"
16
+ */
17
+ export declare const outgoing: UpdateFilter<Message, {
18
+ isOutgoing: true;
19
+ }>;
20
+ /**
21
+ * Filter messages that are replies to some other message
22
+ */
23
+ export declare const reply: UpdateFilter<Message, {
24
+ replyToMessage: MessageReplyInfo;
25
+ }>;
26
+ /**
27
+ * Filter messages containing some media
28
+ */
29
+ export declare const media: UpdateFilter<Message, {
30
+ media: Exclude<Message['media'], null>;
31
+ }>;
32
+ /**
33
+ * Filter messages containing media of given type
34
+ */
35
+ export declare const mediaOf: <T extends "poll" | "contact" | "game" | "sticker" | "photo" | "location" | "dice" | "audio" | "voice" | "document" | "video" | "live_location" | "web_page" | "venue" | "invoice">(type: T) => UpdateFilter<Message, {
36
+ media: Extract<import("@mtcute/client").Photo, {
37
+ type: T;
38
+ }> | Extract<import("@mtcute/client").Dice, {
39
+ type: T;
40
+ }> | Extract<import("@mtcute/client").Contact, {
41
+ type: T;
42
+ }> | Extract<import("@mtcute/client").Audio, {
43
+ type: T;
44
+ }> | Extract<import("@mtcute/client").Voice, {
45
+ type: T;
46
+ }> | Extract<Sticker, {
47
+ type: T;
48
+ }> | Extract<import("@mtcute/client").Document, {
49
+ type: T;
50
+ }> | Extract<Video, {
51
+ type: T;
52
+ }> | Extract<import("@mtcute/client").Location, {
53
+ type: T;
54
+ }> | Extract<import("@mtcute/client").LiveLocation, {
55
+ type: T;
56
+ }> | Extract<import("@mtcute/client").Game, {
57
+ type: T;
58
+ }> | Extract<import("@mtcute/client").WebPage, {
59
+ type: T;
60
+ }> | Extract<import("@mtcute/client").Venue, {
61
+ type: T;
62
+ }> | Extract<import("@mtcute/client").Poll, {
63
+ type: T;
64
+ }> | Extract<import("@mtcute/client").Invoice, {
65
+ type: T;
66
+ }>;
67
+ }>;
68
+ /** Filter messages containing a photo */
69
+ export declare const photo: UpdateFilter<Message, {
70
+ media: import("@mtcute/client").Photo;
71
+ }>;
72
+ /** Filter messages containing a dice */
73
+ export declare const dice: UpdateFilter<Message, {
74
+ media: import("@mtcute/client").Dice;
75
+ }>;
76
+ /** Filter messages containing a contact */
77
+ export declare const contact: UpdateFilter<Message, {
78
+ media: import("@mtcute/client").Contact;
79
+ }>;
80
+ /** Filter messages containing an audio file */
81
+ export declare const audio: UpdateFilter<Message, {
82
+ media: import("@mtcute/client").Audio;
83
+ }>;
84
+ /** Filter messages containing a voice message (audio-only) */
85
+ export declare const voice: UpdateFilter<Message, {
86
+ media: import("@mtcute/client").Voice;
87
+ }>;
88
+ /** Filter messages containing a sticker */
89
+ export declare const sticker: UpdateFilter<Message, {
90
+ media: Sticker;
91
+ }>;
92
+ /** Filter messages containing a document (a file) */
93
+ export declare const document: UpdateFilter<Message, {
94
+ media: import("@mtcute/client").Document;
95
+ }>;
96
+ /** Filter messages containing any video (videos, round messages and animations) */
97
+ export declare const anyVideo: UpdateFilter<Message, {
98
+ media: Video;
99
+ }>;
100
+ /** Filter messages containing a static location */
101
+ export declare const location: UpdateFilter<Message, {
102
+ media: import("@mtcute/client").Location;
103
+ }>;
104
+ /** Filter messages containing a live location */
105
+ export declare const liveLocation: UpdateFilter<Message, {
106
+ media: import("@mtcute/client").LiveLocation;
107
+ }>;
108
+ /** Filter messages containing a game */
109
+ export declare const game: UpdateFilter<Message, {
110
+ media: import("@mtcute/client").Game;
111
+ }>;
112
+ /** Filter messages containing a web page */
113
+ export declare const webpage: UpdateFilter<Message, {
114
+ media: import("@mtcute/client").WebPage;
115
+ }>;
116
+ /** Filter messages containing a venue */
117
+ export declare const venue: UpdateFilter<Message, {
118
+ media: import("@mtcute/client").Venue;
119
+ }>;
120
+ /** Filter messages containing a poll */
121
+ export declare const poll: UpdateFilter<Message, {
122
+ media: import("@mtcute/client").Poll;
123
+ }>;
124
+ /** Filter messages containing an invoice */
125
+ export declare const invoice: UpdateFilter<Message, {
126
+ media: import("@mtcute/client").Invoice;
127
+ }>;
128
+ /**
129
+ * Filter messages containing any location (live or static).
130
+ */
131
+ export declare const anyLocation: UpdateFilter<Message, {
132
+ media: Location;
133
+ }>;
134
+ /**
135
+ * Filter messages containing a document
136
+ *
137
+ * This will also match media like audio, video, voice
138
+ * that also use Documents
139
+ */
140
+ export declare const anyDocument: UpdateFilter<Message, {
141
+ media: RawDocument;
142
+ }>;
143
+ /**
144
+ * Filter messages containing a simple video.
145
+ *
146
+ * This does not include round messages and animations
147
+ */
148
+ export declare const video: UpdateFilter<Message, {
149
+ media: Modify<Video, {
150
+ isRound: false;
151
+ isAnimation: false;
152
+ }>;
153
+ }>;
154
+ /**
155
+ * Filter messages containing an animation.
156
+ *
157
+ * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)
158
+ * > are also considered animations.
159
+ */
160
+ export declare const animation: UpdateFilter<Message, {
161
+ media: Modify<Video, {
162
+ isRound: false;
163
+ isAnimation: true;
164
+ }>;
165
+ }>;
166
+ /**
167
+ * Filter messages containing a round message (aka video note).
168
+ */
169
+ export declare const roundMessage: UpdateFilter<Message, {
170
+ media: Modify<Video, {
171
+ isRound: true;
172
+ isAnimation: false;
173
+ }>;
174
+ }>;
175
+ /**
176
+ * Filter messages containing a sticker by its type
177
+ */
178
+ export declare const stickerByType: (type: StickerType) => UpdateFilter<Message, {
179
+ media: Sticker;
180
+ }>;
181
+ /**
182
+ * Filter messages containing a sticker by its source file type
183
+ */
184
+ export declare const stickerBySourceType: (type: StickerSourceType) => UpdateFilter<Message, {
185
+ media: Sticker;
186
+ }>;
187
+ /**
188
+ * Filter text-only messages non-service messages
189
+ */
190
+ export declare const text: UpdateFilter<Message, {
191
+ media: null;
192
+ isService: false;
193
+ }>;
194
+ /**
195
+ * Filter service messages
196
+ */
197
+ export declare const service: UpdateFilter<Message, {
198
+ isService: true;
199
+ }>;
200
+ /**
201
+ * Filter service messages by action type
202
+ */
203
+ export declare const action: <T extends "chat_created" | "channel_created" | "chat_migrate_to" | "channel_migrate_from" | "message_pinned" | "history_cleared" | "game_score" | "contact_joined" | "title_changed" | "photo_changed" | "photo_deleted" | "users_added" | "user_left" | "user_removed" | "user_joined_link" | "payment_received" | "payment_sent" | "call" | "screenshot_taken" | "bot_allowed" | "geo_proximity" | "group_call_started" | "group_call_ended" | "group_call_scheduled" | "group_call_invite" | "ttl_changed" | "topic_created" | "topic_edited" | "custom" | "theme_changed" | "user_joined_approved" | "webview_sent" | "webview_received" | "premium_gifted" | "photo_suggested" | "peer_chosen" | "wallpaper_changed">(type: MaybeArray<T>) => UpdateFilter<Message, {
204
+ action: Extract<import("@mtcute/client").ActionChatCreated, {
205
+ type: T;
206
+ }> | Extract<import("@mtcute/client").ActionChannelCreated, {
207
+ type: T;
208
+ }> | Extract<import("@mtcute/client").ActionChatMigrateTo, {
209
+ type: T;
210
+ }> | Extract<import("@mtcute/client").ActionChannelMigrateFrom, {
211
+ type: T;
212
+ }> | Extract<import("@mtcute/client").ActionMessagePinned, {
213
+ type: T;
214
+ }> | Extract<import("@mtcute/client").ActionHistoryCleared, {
215
+ type: T;
216
+ }> | Extract<import("@mtcute/client").ActionGameScore, {
217
+ type: T;
218
+ }> | Extract<import("@mtcute/client").ActionContactJoined, {
219
+ type: T;
220
+ }> | Extract<import("@mtcute/client").ActionTitleChanged, {
221
+ type: T;
222
+ }> | Extract<import("@mtcute/client").ActionPhotoChanged, {
223
+ type: T;
224
+ }> | Extract<import("@mtcute/client").ActionPhotoDeleted, {
225
+ type: T;
226
+ }> | Extract<import("@mtcute/client").ActionUsersAdded, {
227
+ type: T;
228
+ }> | Extract<import("@mtcute/client").ActionUserLeft, {
229
+ type: T;
230
+ }> | Extract<import("@mtcute/client").ActionUserRemoved, {
231
+ type: T;
232
+ }> | Extract<import("@mtcute/client").ActionUserJoinedLink, {
233
+ type: T;
234
+ }> | Extract<import("@mtcute/client").ActionPaymentReceived, {
235
+ type: T;
236
+ }> | Extract<import("@mtcute/client").ActionPaymentSent, {
237
+ type: T;
238
+ }> | Extract<import("@mtcute/client").ActionCall, {
239
+ type: T;
240
+ }> | Extract<import("@mtcute/client").ActionScreenshotTaken, {
241
+ type: T;
242
+ }> | Extract<import("@mtcute/client").ActionBotAllowed, {
243
+ type: T;
244
+ }> | Extract<import("@mtcute/client").ActionGeoProximity, {
245
+ type: T;
246
+ }> | Extract<import("@mtcute/client").ActionGroupCallStarted, {
247
+ type: T;
248
+ }> | Extract<import("@mtcute/client").ActionGroupCallEnded, {
249
+ type: T;
250
+ }> | Extract<import("@mtcute/client").ActionGroupCallScheduled, {
251
+ type: T;
252
+ }> | Extract<import("@mtcute/client").ActionGroupInvite, {
253
+ type: T;
254
+ }> | Extract<import("@mtcute/client").ActionTtlChanged, {
255
+ type: T;
256
+ }> | Extract<import("@mtcute/client").ActionTopicCreated, {
257
+ type: T;
258
+ }> | Extract<import("@mtcute/client").ActionTopicEdited, {
259
+ type: T;
260
+ }> | Extract<import("@mtcute/client").ActionCustom, {
261
+ type: T;
262
+ }> | Extract<import("@mtcute/client").ActionThemeChanged, {
263
+ type: T;
264
+ }> | Extract<import("@mtcute/client").ActionUserJoinedApproved, {
265
+ type: T;
266
+ }> | Extract<import("@mtcute/client").ActionWebviewDataSent, {
267
+ type: T;
268
+ }> | Extract<import("@mtcute/client").ActionWebviewDataReceived, {
269
+ type: T;
270
+ }> | Extract<import("@mtcute/client").ActionPremiumGifted, {
271
+ type: T;
272
+ }> | Extract<import("@mtcute/client").ActionPhotoSuggested, {
273
+ type: T;
274
+ }> | Extract<import("@mtcute/client").ActionPeerChosen, {
275
+ type: T;
276
+ }> | Extract<import("@mtcute/client").ActionWallpaperChanged, {
277
+ type: T;
278
+ }>;
279
+ sender: T extends "history_cleared" | "contact_joined" | "user_removed" | "user_joined_link" | "bot_allowed" ? User : User | Chat;
280
+ }>;
281
+ export declare const sender: <T extends "user" | "chat">(type: T) => UpdateFilter<Message, {
282
+ sender: Extract<User, {
283
+ type: T;
284
+ }> | Extract<Chat, {
285
+ type: T;
286
+ }>;
287
+ }>;
288
+ /**
289
+ * Filter that matches messages that are replies to some other message.
290
+ *
291
+ * Optionally, you can pass a filter that will be applied to the replied message.
292
+ */
293
+ export declare const replyTo: <Mod, State extends object>(filter?: UpdateFilter<Message, Mod, State> | undefined) => UpdateFilter<MessageContext, {
294
+ getReplyTo: () => Promise<Message & Mod>;
295
+ }, State>;
@@ -0,0 +1,150 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.replyTo = exports.sender = exports.action = exports.service = exports.text = exports.stickerBySourceType = exports.stickerByType = exports.roundMessage = exports.animation = exports.video = exports.anyDocument = exports.anyLocation = exports.invoice = exports.poll = exports.venue = exports.webpage = exports.game = exports.liveLocation = exports.location = exports.anyVideo = exports.document = exports.sticker = exports.voice = exports.audio = exports.contact = exports.dice = exports.photo = exports.mediaOf = exports.media = exports.reply = exports.outgoing = exports.incoming = void 0;
4
+ /* eslint-disable @typescript-eslint/no-explicit-any */
5
+ // ^^ will be looked into in MTQ-29
6
+ const client_1 = require("@mtcute/client");
7
+ /**
8
+ * Filter incoming messages.
9
+ *
10
+ * Messages sent to yourself (i.e. Saved Messages) are also "incoming"
11
+ */
12
+ const incoming = (msg) => !msg.isOutgoing;
13
+ exports.incoming = incoming;
14
+ /**
15
+ * Filter outgoing messages.
16
+ *
17
+ * Messages sent to yourself (i.e. Saved Messages) are **not** "outgoing"
18
+ */
19
+ const outgoing = (msg) => msg.isOutgoing;
20
+ exports.outgoing = outgoing;
21
+ /**
22
+ * Filter messages that are replies to some other message
23
+ */
24
+ const reply = (msg) => msg.replyToMessage !== null;
25
+ exports.reply = reply;
26
+ /**
27
+ * Filter messages containing some media
28
+ */
29
+ const media = (msg) => msg.media !== null;
30
+ exports.media = media;
31
+ /**
32
+ * Filter messages containing media of given type
33
+ */
34
+ const mediaOf = (type) => (msg) => msg.media?.type === type;
35
+ exports.mediaOf = mediaOf;
36
+ /** Filter messages containing a photo */
37
+ exports.photo = (0, exports.mediaOf)('photo');
38
+ /** Filter messages containing a dice */
39
+ exports.dice = (0, exports.mediaOf)('dice');
40
+ /** Filter messages containing a contact */
41
+ exports.contact = (0, exports.mediaOf)('contact');
42
+ /** Filter messages containing an audio file */
43
+ exports.audio = (0, exports.mediaOf)('audio');
44
+ /** Filter messages containing a voice message (audio-only) */
45
+ exports.voice = (0, exports.mediaOf)('voice');
46
+ /** Filter messages containing a sticker */
47
+ exports.sticker = (0, exports.mediaOf)('sticker');
48
+ /** Filter messages containing a document (a file) */
49
+ exports.document = (0, exports.mediaOf)('document');
50
+ /** Filter messages containing any video (videos, round messages and animations) */
51
+ exports.anyVideo = (0, exports.mediaOf)('video');
52
+ /** Filter messages containing a static location */
53
+ exports.location = (0, exports.mediaOf)('location');
54
+ /** Filter messages containing a live location */
55
+ exports.liveLocation = (0, exports.mediaOf)('live_location');
56
+ /** Filter messages containing a game */
57
+ exports.game = (0, exports.mediaOf)('game');
58
+ /** Filter messages containing a web page */
59
+ exports.webpage = (0, exports.mediaOf)('web_page');
60
+ /** Filter messages containing a venue */
61
+ exports.venue = (0, exports.mediaOf)('venue');
62
+ /** Filter messages containing a poll */
63
+ exports.poll = (0, exports.mediaOf)('poll');
64
+ /** Filter messages containing an invoice */
65
+ exports.invoice = (0, exports.mediaOf)('invoice');
66
+ /**
67
+ * Filter messages containing any location (live or static).
68
+ */
69
+ const anyLocation = (msg) => msg.media instanceof client_1.RawLocation;
70
+ exports.anyLocation = anyLocation;
71
+ /**
72
+ * Filter messages containing a document
73
+ *
74
+ * This will also match media like audio, video, voice
75
+ * that also use Documents
76
+ */
77
+ const anyDocument = (msg) => msg.media instanceof client_1.RawDocument;
78
+ exports.anyDocument = anyDocument;
79
+ /**
80
+ * Filter messages containing a simple video.
81
+ *
82
+ * This does not include round messages and animations
83
+ */
84
+ const video = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && !msg.media.isRound;
85
+ exports.video = video;
86
+ /**
87
+ * Filter messages containing an animation.
88
+ *
89
+ * > **Note**: Legacy GIFs (i.e. documents with `image/gif` MIME)
90
+ * > are also considered animations.
91
+ */
92
+ const animation = (msg) => msg.media?.type === 'video' && msg.media.isAnimation && !msg.media.isRound;
93
+ exports.animation = animation;
94
+ /**
95
+ * Filter messages containing a round message (aka video note).
96
+ */
97
+ const roundMessage = (msg) => msg.media?.type === 'video' && !msg.media.isAnimation && msg.media.isRound;
98
+ exports.roundMessage = roundMessage;
99
+ /**
100
+ * Filter messages containing a sticker by its type
101
+ */
102
+ const stickerByType = (type) => (msg) => msg.media?.type === 'sticker' && msg.media.stickerType === type;
103
+ exports.stickerByType = stickerByType;
104
+ /**
105
+ * Filter messages containing a sticker by its source file type
106
+ */
107
+ const stickerBySourceType = (type) => (msg) => msg.media?.type === 'sticker' && msg.media.sourceType === type;
108
+ exports.stickerBySourceType = stickerBySourceType;
109
+ /**
110
+ * Filter text-only messages non-service messages
111
+ */
112
+ const text = (msg) => msg.media === null && !msg.isService;
113
+ exports.text = text;
114
+ /**
115
+ * Filter service messages
116
+ */
117
+ const service = (msg) => msg.isService;
118
+ exports.service = service;
119
+ /**
120
+ * Filter service messages by action type
121
+ */
122
+ const action = (type) => {
123
+ if (Array.isArray(type)) {
124
+ const index = {};
125
+ type.forEach((it) => (index[it] = true));
126
+ return (msg) => msg.action?.type in index;
127
+ }
128
+ return (msg) => msg.action?.type === type;
129
+ };
130
+ exports.action = action;
131
+ const sender = (type) => (msg) => msg.sender.type === type;
132
+ exports.sender = sender;
133
+ /**
134
+ * Filter that matches messages that are replies to some other message.
135
+ *
136
+ * Optionally, you can pass a filter that will be applied to the replied message.
137
+ */
138
+ const replyTo = (filter) => async (msg, state) => {
139
+ if (!msg.replyToMessage?.id)
140
+ return false;
141
+ const reply = await msg.getReplyTo();
142
+ if (!reply)
143
+ return false;
144
+ msg.getReplyTo = () => Promise.resolve(reply);
145
+ if (!filter)
146
+ return true;
147
+ return filter(reply, state);
148
+ };
149
+ exports.replyTo = replyTo;
150
+ //# sourceMappingURL=message.js.map