@mtcute/dispatcher 0.1.2 → 0.2.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.
- package/cjs/callback-data-builder.js +2 -0
- package/cjs/callback-data-builder.js.map +1 -1
- package/cjs/callback-data-builder.test.d.ts +1 -0
- package/cjs/callback-data-builder.test.js +74 -0
- package/cjs/callback-data-builder.test.js.map +1 -0
- package/cjs/context/callback-query.d.ts +7 -3
- package/cjs/context/callback-query.js +12 -0
- package/cjs/context/callback-query.js.map +1 -1
- package/cjs/context/index.d.ts +1 -1
- package/cjs/context/index.js.map +1 -1
- package/cjs/context/message.d.ts +7 -1
- package/cjs/context/message.js +20 -0
- package/cjs/context/message.js.map +1 -1
- package/cjs/dispatcher.d.ts +5 -12
- package/cjs/dispatcher.js +112 -63
- package/cjs/dispatcher.js.map +1 -1
- package/cjs/filters/bots.d.ts +4 -1
- package/cjs/filters/bots.js +6 -2
- package/cjs/filters/bots.js.map +1 -1
- package/cjs/filters/bots.test.d.ts +1 -0
- package/cjs/filters/bots.test.js +120 -0
- package/cjs/filters/bots.test.js.map +1 -0
- package/cjs/filters/index.d.ts +2 -1
- package/cjs/filters/index.js.map +1 -1
- package/cjs/filters/logic.test.d.ts +1 -0
- package/cjs/filters/logic.test.js +169 -0
- package/cjs/filters/logic.test.js.map +1 -0
- package/cjs/filters/message.d.ts +22 -6
- package/cjs/filters/message.js +25 -3
- package/cjs/filters/message.js.map +1 -1
- package/cjs/state/key.d.ts +2 -2
- package/cjs/state/key.js.map +1 -1
- package/cjs/state/storage.d.ts +21 -0
- package/cjs/state/storage.js.map +1 -1
- package/esm/callback-data-builder.js +2 -0
- package/esm/callback-data-builder.js.map +1 -1
- package/esm/callback-data-builder.test.d.ts +1 -0
- package/esm/callback-data-builder.test.js +72 -0
- package/esm/callback-data-builder.test.js.map +1 -0
- package/esm/context/callback-query.d.ts +7 -3
- package/esm/context/callback-query.js +13 -1
- package/esm/context/callback-query.js.map +1 -1
- package/esm/context/index.d.ts +1 -1
- package/esm/context/index.js.map +1 -1
- package/esm/context/message.d.ts +7 -1
- package/esm/context/message.js +21 -1
- package/esm/context/message.js.map +1 -1
- package/esm/dispatcher.d.ts +5 -12
- package/esm/dispatcher.js +112 -63
- package/esm/dispatcher.js.map +1 -1
- package/esm/filters/bots.d.ts +4 -1
- package/esm/filters/bots.js +6 -2
- package/esm/filters/bots.js.map +1 -1
- package/esm/filters/bots.test.d.ts +1 -0
- package/esm/filters/bots.test.js +118 -0
- package/esm/filters/bots.test.js.map +1 -0
- package/esm/filters/index.d.ts +2 -1
- package/esm/filters/index.js.map +1 -1
- package/esm/filters/logic.test.d.ts +1 -0
- package/esm/filters/logic.test.js +167 -0
- package/esm/filters/logic.test.js.map +1 -0
- package/esm/filters/message.d.ts +22 -6
- package/esm/filters/message.js +22 -2
- package/esm/filters/message.js.map +1 -1
- package/esm/state/key.d.ts +2 -2
- package/esm/state/key.js.map +1 -1
- package/esm/state/storage.d.ts +21 -0
- package/esm/state/storage.js.map +1 -1
- package/package.json +3 -2
package/esm/filters/index.d.ts
CHANGED
package/esm/filters/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filters/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/filters/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,OAAO,MAAM,aAAa,CAAA;AAEtC,OAAO,EAAE,OAAO,EAAE,CAAA","sourcesContent":["import * as filters from './bundle.js'\nimport UpdateFilter = filters.UpdateFilter\nexport { filters }\nexport type { UpdateFilter }\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { describe, expect, it, vi } from 'vitest';
|
|
2
|
+
import { and, not, or } from './logic.js';
|
|
3
|
+
describe('filters.not', () => {
|
|
4
|
+
it('should negate a given sync filter', () => {
|
|
5
|
+
const filter = vi.fn().mockReturnValue(true);
|
|
6
|
+
const negated = not(filter);
|
|
7
|
+
expect(negated(1)).toBe(false);
|
|
8
|
+
expect(filter).toHaveBeenCalledTimes(1);
|
|
9
|
+
expect(filter).toHaveBeenCalledWith(1, undefined);
|
|
10
|
+
});
|
|
11
|
+
it('should negate a given async filter', async () => {
|
|
12
|
+
const filter = vi.fn().mockResolvedValue(true);
|
|
13
|
+
const negated = not(filter);
|
|
14
|
+
await expect(negated(1)).resolves.toBe(false);
|
|
15
|
+
expect(filter).toHaveBeenCalledTimes(1);
|
|
16
|
+
expect(filter).toHaveBeenCalledWith(1, undefined);
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
describe('filters.and', () => {
|
|
20
|
+
it.each([
|
|
21
|
+
['sync', 'sync'],
|
|
22
|
+
['sync', 'async'],
|
|
23
|
+
['async', 'sync'],
|
|
24
|
+
['async', 'async'],
|
|
25
|
+
])('should combine %s and %s filters', async (aType, bType) => {
|
|
26
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? true : Promise.resolve(true));
|
|
27
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
28
|
+
const combined = and(a, b);
|
|
29
|
+
expect(await combined(1)).toBe(true);
|
|
30
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
31
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
32
|
+
expect(b).toHaveBeenCalledTimes(1);
|
|
33
|
+
expect(b).toHaveBeenCalledWith(1, undefined);
|
|
34
|
+
});
|
|
35
|
+
it.each([
|
|
36
|
+
['sync', 'sync'],
|
|
37
|
+
['sync', 'async'],
|
|
38
|
+
['async', 'sync'],
|
|
39
|
+
['async', 'async'],
|
|
40
|
+
])('should not continue execution after false (%s and %s filters)', async (aType, bType) => {
|
|
41
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false));
|
|
42
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
43
|
+
const combined = and(a, b);
|
|
44
|
+
expect(await combined(1)).toBe(false);
|
|
45
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
46
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
47
|
+
expect(b).not.toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
it.each([
|
|
50
|
+
['sync', 'sync', 'sync'],
|
|
51
|
+
['sync', 'sync', 'async'],
|
|
52
|
+
['sync', 'async', 'sync'],
|
|
53
|
+
['sync', 'async', 'async'],
|
|
54
|
+
['async', 'sync', 'sync'],
|
|
55
|
+
['async', 'sync', 'async'],
|
|
56
|
+
['async', 'async', 'sync'],
|
|
57
|
+
['async', 'async', 'async'],
|
|
58
|
+
])('should combine %s, %s and %s filters', async (aType, bType) => {
|
|
59
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? true : Promise.resolve(true));
|
|
60
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
61
|
+
const c = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
62
|
+
const combined = and(a, b, c);
|
|
63
|
+
expect(await combined(1)).toBe(true);
|
|
64
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
65
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
66
|
+
expect(b).toHaveBeenCalledTimes(1);
|
|
67
|
+
expect(b).toHaveBeenCalledWith(1, undefined);
|
|
68
|
+
expect(c).toHaveBeenCalledTimes(1);
|
|
69
|
+
expect(c).toHaveBeenCalledWith(1, undefined);
|
|
70
|
+
});
|
|
71
|
+
it.each([
|
|
72
|
+
['sync', 'sync', 'sync'],
|
|
73
|
+
['sync', 'sync', 'async'],
|
|
74
|
+
['sync', 'async', 'sync'],
|
|
75
|
+
['sync', 'async', 'async'],
|
|
76
|
+
['async', 'sync', 'sync'],
|
|
77
|
+
['async', 'sync', 'async'],
|
|
78
|
+
['async', 'async', 'sync'],
|
|
79
|
+
['async', 'async', 'async'],
|
|
80
|
+
])('should not continue execution after false (%s, %s and %s filters)', async (aType, bType) => {
|
|
81
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? true : Promise.resolve(true));
|
|
82
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false));
|
|
83
|
+
const c = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
84
|
+
const combined = and(a, b, c);
|
|
85
|
+
expect(await combined(1)).toBe(false);
|
|
86
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
87
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
88
|
+
expect(b).toHaveBeenCalledTimes(1);
|
|
89
|
+
expect(b).toHaveBeenCalledWith(1, undefined);
|
|
90
|
+
expect(c).not.toHaveBeenCalled();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
describe('filters.or', () => {
|
|
94
|
+
it.each([
|
|
95
|
+
['sync', 'sync'],
|
|
96
|
+
['sync', 'async'],
|
|
97
|
+
['async', 'sync'],
|
|
98
|
+
['async', 'async'],
|
|
99
|
+
])('should combine %s and %s filters', async (aType, bType) => {
|
|
100
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false));
|
|
101
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false));
|
|
102
|
+
const combined = or(a, b);
|
|
103
|
+
expect(await combined(1)).toBe(false);
|
|
104
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
105
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
106
|
+
expect(b).toHaveBeenCalledTimes(1);
|
|
107
|
+
expect(b).toHaveBeenCalledWith(1, undefined);
|
|
108
|
+
});
|
|
109
|
+
it.each([
|
|
110
|
+
['sync', 'sync'],
|
|
111
|
+
['sync', 'async'],
|
|
112
|
+
['async', 'sync'],
|
|
113
|
+
['async', 'async'],
|
|
114
|
+
])('should not continue execution after true (%s and %s filters)', async (aType, bType) => {
|
|
115
|
+
const a = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
116
|
+
const b = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false));
|
|
117
|
+
const combined = or(a, b);
|
|
118
|
+
expect(await combined(1)).toBe(true);
|
|
119
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
120
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
121
|
+
expect(b).not.toHaveBeenCalled();
|
|
122
|
+
});
|
|
123
|
+
it.each([
|
|
124
|
+
['sync', 'sync', 'sync'],
|
|
125
|
+
['sync', 'sync', 'async'],
|
|
126
|
+
['sync', 'async', 'sync'],
|
|
127
|
+
['sync', 'async', 'async'],
|
|
128
|
+
['async', 'sync', 'sync'],
|
|
129
|
+
['async', 'sync', 'async'],
|
|
130
|
+
['async', 'async', 'sync'],
|
|
131
|
+
['async', 'async', 'async'],
|
|
132
|
+
])('should combine %s, %s and %s filters', async (aType, bType) => {
|
|
133
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false));
|
|
134
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false));
|
|
135
|
+
const c = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false));
|
|
136
|
+
const combined = or(a, b, c);
|
|
137
|
+
expect(await combined(1)).toBe(false);
|
|
138
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
139
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
140
|
+
expect(b).toHaveBeenCalledTimes(1);
|
|
141
|
+
expect(b).toHaveBeenCalledWith(1, undefined);
|
|
142
|
+
expect(c).toHaveBeenCalledTimes(1);
|
|
143
|
+
expect(c).toHaveBeenCalledWith(1, undefined);
|
|
144
|
+
});
|
|
145
|
+
it.each([
|
|
146
|
+
['sync', 'sync', 'sync'],
|
|
147
|
+
['sync', 'sync', 'async'],
|
|
148
|
+
['sync', 'async', 'sync'],
|
|
149
|
+
['sync', 'async', 'async'],
|
|
150
|
+
['async', 'sync', 'sync'],
|
|
151
|
+
['async', 'sync', 'async'],
|
|
152
|
+
['async', 'async', 'sync'],
|
|
153
|
+
['async', 'async', 'async'],
|
|
154
|
+
])('should not continue execution after true (%s, %s and %s filters)', async (aType, bType) => {
|
|
155
|
+
const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false));
|
|
156
|
+
const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true));
|
|
157
|
+
const c = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false));
|
|
158
|
+
const combined = or(a, b, c);
|
|
159
|
+
expect(await combined(1)).toBe(true);
|
|
160
|
+
expect(a).toHaveBeenCalledTimes(1);
|
|
161
|
+
expect(a).toHaveBeenCalledWith(1, undefined);
|
|
162
|
+
expect(b).toHaveBeenCalledTimes(1);
|
|
163
|
+
expect(b).toHaveBeenCalledWith(1, undefined);
|
|
164
|
+
expect(c).not.toHaveBeenCalled();
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
//# sourceMappingURL=logic.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic.test.js","sourceRoot":"","sources":["../../../src/filters/logic.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAA;AAEjD,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,MAAM,YAAY,CAAA;AAEzC,QAAQ,CAAC,aAAa,EAAE,GAAG,EAAE;IACzB,EAAE,CAAC,mCAAmC,EAAE,GAAG,EAAE;QACzC,MAAM,MAAM,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,eAAe,CAAC,IAAI,CAAC,CAAA;QAC5C,MAAM,OAAO,GAAG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MAAM,CAAC,MAAM,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACpC,MAAM,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QAClC,MAAM,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;QAC5C,MAAM,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QAClC,MAAM,CAAC,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,EAAE,SAAS,CAAC,CAAA;QAC5C,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,gBAAgB,EAAE,CAAA;IACpC,CAAC,CAAC,CAAA;AACN,CAAC,CAAC,CAAA","sourcesContent":["import { describe, expect, it, vi } from 'vitest'\n\nimport { and, not, or } from './logic.js'\n\ndescribe('filters.not', () => {\n it('should negate a given sync filter', () => {\n const filter = vi.fn().mockReturnValue(true)\n const negated = not(filter)\n\n expect(negated(1)).toBe(false)\n expect(filter).toHaveBeenCalledTimes(1)\n expect(filter).toHaveBeenCalledWith(1, undefined)\n })\n\n it('should negate a given async filter', async () => {\n const filter = vi.fn().mockResolvedValue(true)\n const negated = not(filter)\n\n await expect(negated(1)).resolves.toBe(false)\n expect(filter).toHaveBeenCalledTimes(1)\n expect(filter).toHaveBeenCalledWith(1, undefined)\n })\n})\n\ndescribe('filters.and', () => {\n it.each([\n ['sync', 'sync'],\n ['sync', 'async'],\n ['async', 'sync'],\n ['async', 'async'],\n ])('should combine %s and %s filters', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? true : Promise.resolve(true))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n\n const combined = and(a, b)\n\n expect(await combined(1)).toBe(true)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).toHaveBeenCalledTimes(1)\n expect(b).toHaveBeenCalledWith(1, undefined)\n })\n\n it.each([\n ['sync', 'sync'],\n ['sync', 'async'],\n ['async', 'sync'],\n ['async', 'async'],\n ])('should not continue execution after false (%s and %s filters)', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n\n const combined = and(a, b)\n\n expect(await combined(1)).toBe(false)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).not.toHaveBeenCalled()\n })\n\n it.each([\n ['sync', 'sync', 'sync'],\n ['sync', 'sync', 'async'],\n ['sync', 'async', 'sync'],\n ['sync', 'async', 'async'],\n ['async', 'sync', 'sync'],\n ['async', 'sync', 'async'],\n ['async', 'async', 'sync'],\n ['async', 'async', 'async'],\n ])('should combine %s, %s and %s filters', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? true : Promise.resolve(true))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n const c = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n\n const combined = and(a, b, c)\n\n expect(await combined(1)).toBe(true)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).toHaveBeenCalledTimes(1)\n expect(b).toHaveBeenCalledWith(1, undefined)\n expect(c).toHaveBeenCalledTimes(1)\n expect(c).toHaveBeenCalledWith(1, undefined)\n })\n\n it.each([\n ['sync', 'sync', 'sync'],\n ['sync', 'sync', 'async'],\n ['sync', 'async', 'sync'],\n ['sync', 'async', 'async'],\n ['async', 'sync', 'sync'],\n ['async', 'sync', 'async'],\n ['async', 'async', 'sync'],\n ['async', 'async', 'async'],\n ])('should not continue execution after false (%s, %s and %s filters)', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? true : Promise.resolve(true))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false))\n const c = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n\n const combined = and(a, b, c)\n\n expect(await combined(1)).toBe(false)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).toHaveBeenCalledTimes(1)\n expect(b).toHaveBeenCalledWith(1, undefined)\n expect(c).not.toHaveBeenCalled()\n })\n})\n\ndescribe('filters.or', () => {\n it.each([\n ['sync', 'sync'],\n ['sync', 'async'],\n ['async', 'sync'],\n ['async', 'async'],\n ])('should combine %s and %s filters', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false))\n\n const combined = or(a, b)\n\n expect(await combined(1)).toBe(false)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).toHaveBeenCalledTimes(1)\n expect(b).toHaveBeenCalledWith(1, undefined)\n })\n\n it.each([\n ['sync', 'sync'],\n ['sync', 'async'],\n ['async', 'sync'],\n ['async', 'async'],\n ])('should not continue execution after true (%s and %s filters)', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n const b = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false))\n\n const combined = or(a, b)\n\n expect(await combined(1)).toBe(true)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).not.toHaveBeenCalled()\n })\n\n it.each([\n ['sync', 'sync', 'sync'],\n ['sync', 'sync', 'async'],\n ['sync', 'async', 'sync'],\n ['sync', 'async', 'async'],\n ['async', 'sync', 'sync'],\n ['async', 'sync', 'async'],\n ['async', 'async', 'sync'],\n ['async', 'async', 'async'],\n ])('should combine %s, %s and %s filters', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false))\n const c = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false))\n\n const combined = or(a, b, c)\n\n expect(await combined(1)).toBe(false)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).toHaveBeenCalledTimes(1)\n expect(b).toHaveBeenCalledWith(1, undefined)\n expect(c).toHaveBeenCalledTimes(1)\n expect(c).toHaveBeenCalledWith(1, undefined)\n })\n\n it.each([\n ['sync', 'sync', 'sync'],\n ['sync', 'sync', 'async'],\n ['sync', 'async', 'sync'],\n ['sync', 'async', 'async'],\n ['async', 'sync', 'sync'],\n ['async', 'sync', 'async'],\n ['async', 'async', 'sync'],\n ['async', 'async', 'async'],\n ])('should not continue execution after true (%s, %s and %s filters)', async (aType, bType) => {\n const a = vi.fn().mockReturnValue(aType === 'sync' ? false : Promise.resolve(false))\n const b = vi.fn().mockReturnValue(bType === 'sync' ? true : Promise.resolve(true))\n const c = vi.fn().mockReturnValue(bType === 'sync' ? false : Promise.resolve(false))\n\n const combined = or(a, b, c)\n\n expect(await combined(1)).toBe(true)\n expect(a).toHaveBeenCalledTimes(1)\n expect(a).toHaveBeenCalledWith(1, undefined)\n expect(b).toHaveBeenCalledTimes(1)\n expect(b).toHaveBeenCalledWith(1, undefined)\n expect(c).not.toHaveBeenCalled()\n })\n})\n"]}
|
package/esm/filters/message.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { _RepliedMessageAssertionsByOrigin, MaybeArray, Message, MessageAction, Peer, RawDocument, RepliedMessageInfo, RepliedMessageOrigin, Sticker, StickerSourceType, StickerType, User, Video } from '@mtcute/client';
|
|
2
2
|
import { MessageContext } from '../index.js';
|
|
3
3
|
import { Modify, UpdateFilter } from './types.js';
|
|
4
4
|
/**
|
|
@@ -21,7 +21,15 @@ export declare const outgoing: UpdateFilter<Message, {
|
|
|
21
21
|
* Filter messages that are replies to some other message
|
|
22
22
|
*/
|
|
23
23
|
export declare const reply: UpdateFilter<Message, {
|
|
24
|
-
replyToMessage:
|
|
24
|
+
replyToMessage: RepliedMessageInfo;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Filter messages that are replies with the given origin type
|
|
28
|
+
*/
|
|
29
|
+
export declare const replyOrigin: <T extends RepliedMessageOrigin>(origin: T) => UpdateFilter<Message, {
|
|
30
|
+
replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & {
|
|
31
|
+
origin: T;
|
|
32
|
+
}>;
|
|
25
33
|
}>;
|
|
26
34
|
/**
|
|
27
35
|
* Filter messages containing some media
|
|
@@ -32,7 +40,7 @@ export declare const media: UpdateFilter<Message, {
|
|
|
32
40
|
/**
|
|
33
41
|
* Filter messages containing media of given type
|
|
34
42
|
*/
|
|
35
|
-
export declare const mediaOf: <T extends "photo" | "location" | "poll" | "contact" | "game" | "sticker" | "dice" | "audio" | "voice" | "document" | "video" | "live_location" | "
|
|
43
|
+
export declare const mediaOf: <T extends "photo" | "location" | "poll" | "story" | "contact" | "game" | "sticker" | "dice" | "audio" | "voice" | "document" | "video" | "live_location" | "webpage" | "venue" | "invoice">(type: T) => UpdateFilter<Message, {
|
|
36
44
|
media: Extract<import("@mtcute/client").Photo, {
|
|
37
45
|
type: T;
|
|
38
46
|
}> | Extract<import("@mtcute/client").Dice, {
|
|
@@ -63,6 +71,8 @@ export declare const mediaOf: <T extends "photo" | "location" | "poll" | "contac
|
|
|
63
71
|
type: T;
|
|
64
72
|
}> | Extract<import("@mtcute/client").Invoice, {
|
|
65
73
|
type: T;
|
|
74
|
+
}> | Extract<import("@mtcute/client").MediaStory, {
|
|
75
|
+
type: T;
|
|
66
76
|
}>;
|
|
67
77
|
}>;
|
|
68
78
|
/** Filter messages containing a photo */
|
|
@@ -276,20 +286,26 @@ export declare const action: <T extends "chat_created" | "channel_created" | "ch
|
|
|
276
286
|
}> | Extract<import("@mtcute/client").ActionWallpaperChanged, {
|
|
277
287
|
type: T;
|
|
278
288
|
}>;
|
|
279
|
-
sender: T extends "history_cleared" | "contact_joined" | "user_removed" | "user_joined_link" | "bot_allowed" ? User :
|
|
289
|
+
sender: T extends "history_cleared" | "contact_joined" | "user_removed" | "user_joined_link" | "bot_allowed" ? User : Peer;
|
|
280
290
|
}>;
|
|
281
291
|
export declare const sender: <T extends "user" | "chat">(type: T) => UpdateFilter<Message, {
|
|
282
292
|
sender: Extract<User, {
|
|
283
293
|
type: T;
|
|
284
|
-
}> | Extract<Chat, {
|
|
294
|
+
}> | Extract<import("@mtcute/client").Chat, {
|
|
285
295
|
type: T;
|
|
286
296
|
}>;
|
|
287
297
|
}>;
|
|
288
298
|
/**
|
|
289
|
-
* Filter that matches messages that are replies to some other message
|
|
299
|
+
* Filter that matches messages that are replies to some other message that can be fetched
|
|
300
|
+
* (i.e. not `private` origin, and has not been deleted)
|
|
290
301
|
*
|
|
291
302
|
* Optionally, you can pass a filter that will be applied to the replied message.
|
|
292
303
|
*/
|
|
293
304
|
export declare const replyTo: <Mod, State extends object>(filter?: UpdateFilter<Message, Mod, State> | undefined) => UpdateFilter<MessageContext, {
|
|
294
305
|
getReplyTo: () => Promise<Message & Mod>;
|
|
295
306
|
}, State>;
|
|
307
|
+
/**
|
|
308
|
+
* Middleware-like filter that will fetch the sender of the message
|
|
309
|
+
* and make it available to further filters, as well as the handler itself.
|
|
310
|
+
*/
|
|
311
|
+
export declare const withCompleteSender: <Mod, State extends object>(filter?: UpdateFilter<MessageContext, Mod, State> | undefined) => UpdateFilter<MessageContext, Mod, State>;
|
package/esm/filters/message.js
CHANGED
|
@@ -17,6 +17,10 @@ export const outgoing = (msg) => msg.isOutgoing;
|
|
|
17
17
|
* Filter messages that are replies to some other message
|
|
18
18
|
*/
|
|
19
19
|
export const reply = (msg) => msg.replyToMessage !== null;
|
|
20
|
+
/**
|
|
21
|
+
* Filter messages that are replies with the given origin type
|
|
22
|
+
*/
|
|
23
|
+
export const replyOrigin = (origin) => (msg) => msg.replyToMessage?.originIs(origin) ?? false; // originIs does additional checks
|
|
20
24
|
/**
|
|
21
25
|
* Filter messages containing some media
|
|
22
26
|
*/
|
|
@@ -48,7 +52,7 @@ export const liveLocation = mediaOf('live_location');
|
|
|
48
52
|
/** Filter messages containing a game */
|
|
49
53
|
export const game = mediaOf('game');
|
|
50
54
|
/** Filter messages containing a web page */
|
|
51
|
-
export const webpage = mediaOf('
|
|
55
|
+
export const webpage = mediaOf('webpage');
|
|
52
56
|
/** Filter messages containing a venue */
|
|
53
57
|
export const venue = mediaOf('venue');
|
|
54
58
|
/** Filter messages containing a poll */
|
|
@@ -112,7 +116,8 @@ export const action = (type) => {
|
|
|
112
116
|
};
|
|
113
117
|
export const sender = (type) => (msg) => msg.sender.type === type;
|
|
114
118
|
/**
|
|
115
|
-
* Filter that matches messages that are replies to some other message
|
|
119
|
+
* Filter that matches messages that are replies to some other message that can be fetched
|
|
120
|
+
* (i.e. not `private` origin, and has not been deleted)
|
|
116
121
|
*
|
|
117
122
|
* Optionally, you can pass a filter that will be applied to the replied message.
|
|
118
123
|
*/
|
|
@@ -127,4 +132,19 @@ export const replyTo = (filter) => async (msg, state) => {
|
|
|
127
132
|
return true;
|
|
128
133
|
return filter(reply, state);
|
|
129
134
|
};
|
|
135
|
+
/**
|
|
136
|
+
* Middleware-like filter that will fetch the sender of the message
|
|
137
|
+
* and make it available to further filters, as well as the handler itself.
|
|
138
|
+
*/
|
|
139
|
+
export const withCompleteSender = (filter) => async (msg, state) => {
|
|
140
|
+
try {
|
|
141
|
+
await msg.getCompleteSender();
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (!filter)
|
|
147
|
+
return true;
|
|
148
|
+
return filter(msg, state);
|
|
149
|
+
};
|
|
130
150
|
//# sourceMappingURL=message.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.js","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AAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAExC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAE,GAAG,CAAC,MAAM,EAAE,IAAY,IAAI,KAAK,CAAA;KACrD;IAED,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,KAAK,IAAI,CAAA;AAC7C,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,MAAM,GACf,CACI,IAAO,EACmE,EAAE,CAC5E,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAA;AAEpC;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAChB,CACI,MAA0C,EACuC,EAAE,CACnF,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACjB,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE;QAAE,OAAO,KAAK,CAAA;IAEzC,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,UAAU,EAAE,CAAA;IACpC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\nimport {\n Chat,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n MessageReplyInfo,\n RawDocument,\n RawLocation,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Video,\n} from '@mtcute/client'\n\nimport { MessageContext } from '../index.js'\nimport { 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 messages that are replies to some other message\n */\nexport const reply: UpdateFilter<Message, { replyToMessage: MessageReplyInfo }> = (msg) => msg.replyToMessage !== null\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 const mediaOf =\n <T extends MessageMediaType>(type: T): UpdateFilter<Message, { media: Extract<Message['media'], { type: T }> }> =>\n (msg) =>\n msg.media?.type === type\n\n/** Filter messages containing a photo */\nexport const photo = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage = mediaOf('web_page')\n/** Filter messages containing a venue */\nexport const venue = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const 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 const stickerByType =\n (type: StickerType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport const stickerBySourceType =\n (type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\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 const action = <T extends Exclude<MessageAction, null>['type']>(\n type: MaybeArray<T>,\n): 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 : User | Chat\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 const sender =\n <T extends Message['sender']['type']>(\n type: T,\n ): UpdateFilter<Message, { sender: Extract<Message['sender'], { type: T }> }> =>\n (msg) =>\n msg.sender.type === type\n\n/**\n * Filter that matches messages that are replies to some other message.\n *\n * Optionally, you can pass a filter that will be applied to the replied message.\n */\nexport const replyTo =\n <Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n ): UpdateFilter<MessageContext, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = await msg.getReplyTo()\n if (!reply) return false\n\n msg.getReplyTo = () => Promise.resolve(reply)\n\n if (!filter) return true\n\n return filter(reply, state)\n }\n"]}
|
|
1
|
+
{"version":3,"file":"message.js","sourceRoot":"","sources":["../../../src/filters/message.ts"],"names":[],"mappings":"AAAA,uDAAuD;AACvD,mCAAmC;AACnC,OAAO,EAOH,WAAW,EACX,WAAW,GAQd,MAAM,gBAAgB,CAAA;AAKvB;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAiD,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,UAAU,CAAA;AAE9F;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAgD,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,UAAU,CAAA;AAE5F;;GAEG;AACH,MAAM,CAAC,MAAM,KAAK,GAAkE,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,cAAc,KAAK,IAAI,CAAA;AAExH;;GAEG;AACH,MAAM,CAAC,MAAM,WAAW,GACpB,CAC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,GACf,CACI,IAAO,EACmE,EAAE,CAC5E,CAAC,GAAG,EAAE,EAAE,CACJ,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,IAAI,CAAA;AAEpC;;;;;GAKG;AACH,MAAM,CAAC,MAAM,OAAO,GAChB,CACI,MAA0C,EACuC,EAAE,CACnF,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACjB,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,EAAE;QAAE,OAAO,KAAK,CAAA;IAEzC,MAAM,KAAK,GAAG,MAAM,GAAG,CAAC,UAAU,EAAE,CAAA;IACpC,IAAI,CAAC,KAAK;QAAE,OAAO,KAAK,CAAA;IAExB,GAAG,CAAC,UAAU,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAE7C,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,CAAA;AAC/B,CAAC,CAAA;AAET;;;GAGG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAC3B,CACI,MAAiD,EACT,EAAE,CAC1C,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE;IACjB,IAAI;QACA,MAAM,GAAG,CAAC,iBAAiB,EAAE,CAAA;KAChC;IAAC,OAAO,CAAC,EAAE;QACR,OAAO,KAAK,CAAA;KACf;IAED,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IAExB,OAAO,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,CAAA;AAC7B,CAAC,CAAA","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n// ^^ will be looked into in MTQ-29\nimport {\n _RepliedMessageAssertionsByOrigin,\n MaybeArray,\n Message,\n MessageAction,\n MessageMediaType,\n Peer,\n RawDocument,\n RawLocation,\n RepliedMessageInfo,\n RepliedMessageOrigin,\n Sticker,\n StickerSourceType,\n StickerType,\n User,\n Video,\n} from '@mtcute/client'\n\nimport { MessageContext } from '../index.js'\nimport { 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 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 const replyOrigin =\n <T extends RepliedMessageOrigin>(\n origin: T,\n ): UpdateFilter<\n Message,\n {\n replyToMessage: Modify<RepliedMessageInfo, _RepliedMessageAssertionsByOrigin[T] & { origin: T }>\n }\n > =>\n (msg) =>\n msg.replyToMessage?.originIs(origin) ?? false // 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 const mediaOf =\n <T extends MessageMediaType>(type: T): UpdateFilter<Message, { media: Extract<Message['media'], { type: T }> }> =>\n (msg) =>\n msg.media?.type === type\n\n/** Filter messages containing a photo */\nexport const photo = mediaOf('photo')\n/** Filter messages containing a dice */\nexport const dice = mediaOf('dice')\n/** Filter messages containing a contact */\nexport const contact = mediaOf('contact')\n/** Filter messages containing an audio file */\nexport const audio = mediaOf('audio')\n/** Filter messages containing a voice message (audio-only) */\nexport const voice = mediaOf('voice')\n/** Filter messages containing a sticker */\nexport const sticker = mediaOf('sticker')\n/** Filter messages containing a document (a file) */\nexport const document = mediaOf('document')\n/** Filter messages containing any video (videos, round messages and animations) */\nexport const anyVideo = mediaOf('video')\n/** Filter messages containing a static location */\nexport const location = mediaOf('location')\n/** Filter messages containing a live location */\nexport const liveLocation = mediaOf('live_location')\n/** Filter messages containing a game */\nexport const game = mediaOf('game')\n/** Filter messages containing a web page */\nexport const webpage = mediaOf('webpage')\n/** Filter messages containing a venue */\nexport const venue = mediaOf('venue')\n/** Filter messages containing a poll */\nexport const poll = mediaOf('poll')\n/** Filter messages containing an invoice */\nexport const 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 const stickerByType =\n (type: StickerType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.stickerType === type\n\n/**\n * Filter messages containing a sticker by its source file type\n */\nexport const stickerBySourceType =\n (type: StickerSourceType): UpdateFilter<Message, { media: Sticker }> =>\n (msg) =>\n msg.media?.type === 'sticker' && msg.media.sourceType === type\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 const action = <T extends Exclude<MessageAction, null>['type']>(\n type: MaybeArray<T>,\n): 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 const sender =\n <T extends Message['sender']['type']>(\n type: T,\n ): UpdateFilter<Message, { sender: Extract<Message['sender'], { type: T }> }> =>\n (msg) =>\n msg.sender.type === type\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 const replyTo =\n <Mod, State extends object>(\n filter?: UpdateFilter<Message, Mod, State>,\n ): UpdateFilter<MessageContext, { getReplyTo: () => Promise<Message & Mod> }, State> =>\n async (msg, state) => {\n if (!msg.replyToMessage?.id) return false\n\n const reply = await msg.getReplyTo()\n if (!reply) return false\n\n msg.getReplyTo = () => Promise.resolve(reply)\n\n if (!filter) return true\n\n return filter(reply, state)\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 const withCompleteSender =\n <Mod, State extends object>(\n filter?: UpdateFilter<MessageContext, Mod, State>,\n ): UpdateFilter<MessageContext, Mod, State> =>\n async (msg, state) => {\n try {\n await msg.getCompleteSender()\n } catch (e) {\n return false\n }\n\n if (!filter) return true\n\n return filter(msg, state)\n }\n"]}
|
package/esm/state/key.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { MaybeAsync, Peer } from '@mtcute/client';
|
|
2
2
|
import { CallbackQueryContext, MessageContext } from '../context/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Function that determines how the state key is derived.
|
|
@@ -8,7 +8,7 @@ import { CallbackQueryContext, MessageContext } from '../context/index.js';
|
|
|
8
8
|
* @param msg Message or callback from which to derive the key
|
|
9
9
|
* @param scene Current scene UID, or `null` if none
|
|
10
10
|
*/
|
|
11
|
-
export type StateKeyDelegate = (upd: MessageContext | CallbackQueryContext |
|
|
11
|
+
export type StateKeyDelegate = (upd: MessageContext | CallbackQueryContext | Peer) => MaybeAsync<string | null>;
|
|
12
12
|
/**
|
|
13
13
|
* Default state key delegate.
|
|
14
14
|
*
|
package/esm/state/key.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAoB,MAAM,gBAAgB,CAAA;AAc9D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAqB,CAAC,GAAG,EAAiB,EAAE;IAC5E,IAAI,MAAM,IAAI,GAAG,EAAE;QACf,cAAc;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;KACxB;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,EAAE;QAC7B,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE;YACvB,KAAK,SAAS,CAAC;YACf,KAAK,KAAK,CAAC;YACX,KAAK,SAAS;gBACV,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC9B,KAAK,OAAO,CAAC;YACb,KAAK,YAAY,CAAC;YAClB,KAAK,WAAW;gBACZ,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;YAC5C;gBACI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;SACrC;KACJ;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,gBAAgB,EAAE;QAChC,IAAI,GAAG,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAA;QAC7B,IAAI,GAAG,CAAC,QAAQ,KAAK,MAAM;YAAE,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;QAEpD,OAAO,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;KACxC;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA","sourcesContent":["import { assertNever, MaybeAsync, Peer } from '@mtcute/client'\n\nimport { CallbackQueryContext, MessageContext } from '../context/index.js'\n\n/**\n * Function that determines how the state key is derived.\n *\n * The key is additionally prefixed with current scene, if any.\n *\n * @param msg Message or callback from which to derive the key\n * @param scene Current scene UID, or `null` if none\n */\nexport type StateKeyDelegate = (upd: MessageContext | CallbackQueryContext | Peer) => MaybeAsync<string | null>\n\n/**\n * Default state key delegate.\n *\n * Derives key as follows:\n * - If private chat, `msg.chat.id`\n * - If group chat, `msg.chat.id + '_' + msg.sender.id`\n * - If channel, `msg.chat.id`\n * - If non-inline callback query:\n * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`\n * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`\n */\nexport const defaultStateKeyDelegate: StateKeyDelegate = (upd): string | null => {\n if ('type' in upd) {\n // User | Chat\n return String(upd.id)\n }\n\n if (upd._name === 'new_message') {\n switch (upd.chat.chatType) {\n case 'private':\n case 'bot':\n case 'channel':\n return String(upd.chat.id)\n case 'group':\n case 'supergroup':\n case 'gigagroup':\n return `${upd.chat.id}_${upd.sender.id}`\n default:\n assertNever(upd.chat.chatType)\n }\n }\n\n if (upd._name === 'callback_query') {\n if (upd.isInline) return null\n if (upd.chatType === 'user') return `${upd.user.id}`\n\n return `${upd.chatId}_${upd.user.id}`\n }\n\n return null\n}\n"]}
|
package/esm/state/storage.d.ts
CHANGED
|
@@ -12,6 +12,27 @@ import { MaybeAsync } from '@mtcute/client';
|
|
|
12
12
|
* Alternatively, you can store them as simple strings
|
|
13
13
|
*/
|
|
14
14
|
export interface IStateStorage {
|
|
15
|
+
/**
|
|
16
|
+
* Load state from some external storage.
|
|
17
|
+
* Should be used either to load session content from file/network/etc
|
|
18
|
+
* to memory, or to open required connections to fetch session content later
|
|
19
|
+
*
|
|
20
|
+
* This method may be called multiple times and should handle that.
|
|
21
|
+
*/
|
|
22
|
+
load?(): MaybeAsync<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Save state to some external storage.
|
|
25
|
+
* Should be used to commit pending changes in the session.
|
|
26
|
+
* For example, saving session content to file/network/etc,
|
|
27
|
+
* or committing a database transaction
|
|
28
|
+
*/
|
|
29
|
+
save?(): MaybeAsync<void>;
|
|
30
|
+
/**
|
|
31
|
+
* Cleanup storage and release all used resources.
|
|
32
|
+
*
|
|
33
|
+
* This method may be called multiple times and should handle that.
|
|
34
|
+
*/
|
|
35
|
+
destroy?(): MaybeAsync<void>;
|
|
15
36
|
/**
|
|
16
37
|
* Retrieve state from the storage
|
|
17
38
|
*
|
package/esm/state/storage.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/state/storage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"storage.js","sourceRoot":"","sources":["../../../src/state/storage.ts"],"names":[],"mappings":"AA4GA,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAChD,OAAO,CACH,OAAO,OAAO,KAAK,QAAQ;QAC3B,OAAO,KAAK,IAAI;QAChB,UAAU,IAAI,OAAO;QACrB,UAAU,IAAI,OAAO;QACrB,aAAa,IAAI,OAAO;QACxB,iBAAiB,IAAI,OAAO;QAC5B,iBAAiB,IAAI,OAAO;QAC5B,oBAAoB,IAAI,OAAO;QAC/B,cAAc,IAAI,OAAO;QACzB,gBAAgB,IAAI,OAAO,CAC9B,CAAA;AACL,CAAC","sourcesContent":["import { MaybeAsync } from '@mtcute/client'\n\n// ⚠️ Important: when modifying the below interface, also update it\n// in packages/core/src/storage/storage.test-utils.ts\n\n/**\n * Interface for FSM storage for the dispatcher.\n *\n * All of the officially supported storages already implement\n * this interface, so you can just re-use it.\n *\n * Current scene is a special case of a `string` state,\n * Most of the time you can just store it the same way\n * as normal state, prefixing with something like `$current_state_`\n * (scene name can't start with `$`).\n * Alternatively, you can store them as simple strings\n */\nexport interface IStateStorage {\n /**\n * Load state from some external storage.\n * Should be used either to load session content from file/network/etc\n * to memory, or to open required connections to fetch session content later\n *\n * This method may be called multiple times and should handle that.\n */\n load?(): MaybeAsync<void>\n /**\n * Save state to some external storage.\n * Should be used to commit pending changes in the session.\n * For example, saving session content to file/network/etc,\n * or committing a database transaction\n */\n save?(): MaybeAsync<void>\n /**\n * Cleanup storage and release all used resources.\n *\n * This method may be called multiple times and should handle that.\n */\n destroy?(): MaybeAsync<void>\n\n /**\n * Retrieve state from the storage\n *\n * @param key Key of the state, as defined by {@link StateKeyDelegate}\n */\n getState(key: string): MaybeAsync<unknown>\n\n /**\n * Save state to the storage\n *\n * @param key Key of the state, as defined by {@link StateKeyDelegate}\n * @param state Object representing the state\n * @param ttl TTL for the state, in seconds\n */\n setState(key: string, state: unknown, ttl?: number): MaybeAsync<void>\n\n /**\n * Delete state from the storage\n *\n * @param key Key of the state, as defined by {@link StateKeyDelegate}\n */\n deleteState(key: string): MaybeAsync<void>\n\n /**\n * Retrieve the current scene UID from the storage\n *\n * @param key Key of the state, as defined by {@link StateKeyDelegate}\n */\n getCurrentScene(key: string): MaybeAsync<string | null>\n\n /**\n * Change current scene's UID from the storage\n *\n * @param key Key of the state, as defined by {@link StateKeyDelegate}\n * @param scene New scene\n * @param ttl TTL for the scene, in seconds\n */\n setCurrentScene(key: string, scene: string, ttl?: number): MaybeAsync<void>\n\n /**\n * Delete current scene from the storage, effectively \"exiting\" to root.\n *\n * @param key Key of the state, as defined by {@link StateKeyDelegate}\n */\n deleteCurrentScene(key: string): MaybeAsync<void>\n\n /**\n * Get information about a rate limit.\n *\n * It is recommended that you use sliding window or leaky bucket\n * to implement rate limiting ([learn more](https://konghq.com/blog/how-to-design-a-scalable-rate-limiting-algorithm/)),\n *\n * @param key Key of the rate limit\n * @param limit Maximum number of requests in `window`\n * @param window Window size in seconds\n * @returns Tuple containing the number of remaining and\n * unix time in ms when the user can try again\n */\n getRateLimit(key: string, limit: number, window: number): MaybeAsync<[number, number]>\n\n /**\n * Reset a rate limit.\n *\n * @param key Key of the rate limit\n */\n resetRateLimit(key: string): MaybeAsync<void>\n}\n\nexport function isCompatibleStorage(storage: unknown): storage is IStateStorage {\n return (\n typeof storage === 'object' &&\n storage !== null &&\n 'getState' in storage &&\n 'setState' in storage &&\n 'deleteState' in storage &&\n 'getCurrentScene' in storage &&\n 'setCurrentScene' in storage &&\n 'deleteCurrentScene' in storage &&\n 'getRateLimit' in storage &&\n 'resetRateLimit' in storage\n )\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mtcute/dispatcher",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "Updates dispatcher and bot framework for @mtcute/client",
|
|
5
5
|
"author": "Alina Sireneva <alina@tei.su>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"type": "module",
|
|
9
9
|
"scripts": {},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@mtcute/client": "^0.
|
|
11
|
+
"@mtcute/client": "^0.2.0",
|
|
12
|
+
"@mtcute/test": "^0.2.0",
|
|
12
13
|
"events": "3.2.0"
|
|
13
14
|
},
|
|
14
15
|
"module": "esm/index.js",
|