@mtcute/dispatcher 0.16.7 → 0.16.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{cjs/callback-data-builder.d.ts → callback-data-builder.d.ts} +2 -2
- package/callback-data-builder.test.d.ts +1 -0
- package/{esm/context → context}/base.d.ts +2 -2
- package/{esm/context → context}/business-message.d.ts +5 -6
- package/{esm/context → context}/callback-query.d.ts +6 -7
- package/{cjs/context → context}/chat-join-request.d.ts +3 -3
- package/{esm/context → context}/chosen-inline-result.d.ts +3 -3
- package/{esm/context → context}/inline-query.d.ts +4 -5
- package/{cjs/context → context}/message.d.ts +11 -6
- package/{cjs/context → context}/parse.d.ts +3 -3
- package/{esm/context → context}/pre-checkout-query.d.ts +3 -3
- package/{esm/context → context}/scene-transition.d.ts +1 -1
- package/{cjs/dispatcher.d.ts → dispatcher.d.ts} +9 -10
- package/{cjs/filters → filters}/bots.d.ts +4 -4
- package/filters/bots.test.d.ts +1 -0
- package/{cjs/filters → filters}/chat.d.ts +3 -3
- package/{esm/filters → filters}/group.d.ts +4 -4
- package/{cjs/filters → filters}/logic.d.ts +1 -1
- package/filters/logic.test.d.ts +1 -0
- package/{esm/filters → filters}/message.d.ts +9 -5
- package/{cjs/filters → filters}/state.d.ts +2 -2
- package/{esm/filters → filters}/text.d.ts +3 -3
- package/{cjs/filters → filters}/types.d.ts +2 -2
- package/{cjs/filters → filters}/updates.d.ts +2 -2
- package/{cjs/filters → filters}/user.d.ts +3 -4
- package/{cjs/handler.d.ts → handler.d.ts} +5 -5
- package/index.cjs +2534 -0
- package/index.d.ts +8 -1
- package/index.js +2529 -1
- package/package.json +28 -24
- package/{cjs/state → state}/key.d.ts +3 -3
- package/state/provider.d.ts +5 -0
- package/{cjs/state → state}/providers/memory.d.ts +3 -4
- package/{esm/state → state}/providers/sqlite.d.ts +3 -3
- package/{cjs/state → state}/repository.d.ts +1 -1
- package/{esm/state → state}/service.d.ts +2 -2
- package/{cjs/state → state}/update-state.d.ts +2 -2
- package/{esm/wizard.d.ts → wizard.d.ts} +5 -6
- package/cjs/callback-data-builder.js +0 -141
- package/cjs/callback-data-builder.js.map +0 -1
- package/cjs/context/base.d.ts +0 -9
- package/cjs/context/base.js +0 -3
- package/cjs/context/base.js.map +0 -1
- package/cjs/context/business-message.d.ts +0 -61
- package/cjs/context/business-message.js +0 -146
- package/cjs/context/business-message.js.map +0 -1
- package/cjs/context/callback-query.d.ts +0 -63
- package/cjs/context/callback-query.js +0 -109
- package/cjs/context/callback-query.js.map +0 -1
- package/cjs/context/chat-join-request.js +0 -35
- package/cjs/context/chat-join-request.js.map +0 -1
- package/cjs/context/chosen-inline-result.d.ts +0 -22
- package/cjs/context/chosen-inline-result.js +0 -36
- package/cjs/context/chosen-inline-result.js.map +0 -1
- package/cjs/context/index.js +0 -25
- package/cjs/context/index.js.map +0 -1
- package/cjs/context/inline-query.d.ts +0 -16
- package/cjs/context/inline-query.js +0 -23
- package/cjs/context/inline-query.js.map +0 -1
- package/cjs/context/message.js +0 -171
- package/cjs/context/message.js.map +0 -1
- package/cjs/context/parse.js +0 -42
- package/cjs/context/parse.js.map +0 -1
- package/cjs/context/pre-checkout-query.d.ts +0 -17
- package/cjs/context/pre-checkout-query.js +0 -27
- package/cjs/context/pre-checkout-query.js.map +0 -1
- package/cjs/context/scene-transition.d.ts +0 -24
- package/cjs/context/scene-transition.js +0 -52
- package/cjs/context/scene-transition.js.map +0 -1
- package/cjs/dispatcher.js +0 -908
- package/cjs/dispatcher.js.map +0 -1
- package/cjs/filters/bots.js +0 -135
- package/cjs/filters/bots.js.map +0 -1
- package/cjs/filters/bundle.js +0 -27
- package/cjs/filters/bundle.js.map +0 -1
- package/cjs/filters/chat.js +0 -56
- package/cjs/filters/chat.js.map +0 -1
- package/cjs/filters/group.d.ts +0 -26
- package/cjs/filters/group.js +0 -69
- package/cjs/filters/group.js.map +0 -1
- package/cjs/filters/index.js +0 -29
- package/cjs/filters/index.js.map +0 -1
- package/cjs/filters/logic.js +0 -112
- package/cjs/filters/logic.js.map +0 -1
- package/cjs/filters/message.d.ts +0 -215
- package/cjs/filters/message.js +0 -191
- package/cjs/filters/message.js.map +0 -1
- package/cjs/filters/state.js +0 -33
- package/cjs/filters/state.js.map +0 -1
- package/cjs/filters/text.d.ts +0 -64
- package/cjs/filters/text.js +0 -136
- package/cjs/filters/text.js.map +0 -1
- package/cjs/filters/types.js +0 -3
- package/cjs/filters/types.js.map +0 -1
- package/cjs/filters/updates.js +0 -40
- package/cjs/filters/updates.js.map +0 -1
- package/cjs/filters/user.js +0 -77
- package/cjs/filters/user.js.map +0 -1
- package/cjs/handler.js +0 -4
- package/cjs/handler.js.map +0 -1
- package/cjs/index.js +0 -31
- package/cjs/index.js.map +0 -1
- package/cjs/package.json +0 -3
- package/cjs/propagation.js +0 -27
- package/cjs/propagation.js.map +0 -1
- package/cjs/state/index.js +0 -22
- package/cjs/state/index.js.map +0 -1
- package/cjs/state/key.js +0 -43
- package/cjs/state/key.js.map +0 -1
- package/cjs/state/provider.d.ts +0 -5
- package/cjs/state/provider.js +0 -3
- package/cjs/state/provider.js.map +0 -1
- package/cjs/state/providers/index.js +0 -19
- package/cjs/state/providers/index.js.map +0 -1
- package/cjs/state/providers/memory.js +0 -81
- package/cjs/state/providers/memory.js.map +0 -1
- package/cjs/state/providers/sqlite.d.ts +0 -28
- package/cjs/state/providers/sqlite.js +0 -100
- package/cjs/state/providers/sqlite.js.map +0 -1
- package/cjs/state/repository.js +0 -3
- package/cjs/state/repository.js.map +0 -1
- package/cjs/state/service.d.ts +0 -20
- package/cjs/state/service.js +0 -70
- package/cjs/state/service.js.map +0 -1
- package/cjs/state/update-state.js +0 -219
- package/cjs/state/update-state.js.map +0 -1
- package/cjs/wizard.d.ts +0 -65
- package/cjs/wizard.js +0 -105
- package/cjs/wizard.js.map +0 -1
- package/esm/callback-data-builder.d.ts +0 -49
- package/esm/callback-data-builder.js +0 -137
- package/esm/callback-data-builder.js.map +0 -1
- package/esm/context/base.js +0 -2
- package/esm/context/base.js.map +0 -1
- package/esm/context/business-message.js +0 -142
- package/esm/context/business-message.js.map +0 -1
- package/esm/context/callback-query.js +0 -103
- package/esm/context/callback-query.js.map +0 -1
- package/esm/context/chat-join-request.d.ts +0 -17
- package/esm/context/chat-join-request.js +0 -31
- package/esm/context/chat-join-request.js.map +0 -1
- package/esm/context/chosen-inline-result.js +0 -32
- package/esm/context/chosen-inline-result.js.map +0 -1
- package/esm/context/index.d.ts +0 -9
- package/esm/context/index.js +0 -9
- package/esm/context/index.js.map +0 -1
- package/esm/context/inline-query.js +0 -19
- package/esm/context/inline-query.js.map +0 -1
- package/esm/context/message.d.ts +0 -77
- package/esm/context/message.js +0 -167
- package/esm/context/message.js.map +0 -1
- package/esm/context/parse.d.ts +0 -13
- package/esm/context/parse.js +0 -39
- package/esm/context/parse.js.map +0 -1
- package/esm/context/pre-checkout-query.js +0 -23
- package/esm/context/pre-checkout-query.js.map +0 -1
- package/esm/context/scene-transition.js +0 -48
- package/esm/context/scene-transition.js.map +0 -1
- package/esm/dispatcher.d.ts +0 -881
- package/esm/dispatcher.js +0 -904
- package/esm/dispatcher.js.map +0 -1
- package/esm/filters/bots.d.ts +0 -64
- package/esm/filters/bots.js +0 -131
- package/esm/filters/bots.js.map +0 -1
- package/esm/filters/bundle.d.ts +0 -10
- package/esm/filters/bundle.js +0 -11
- package/esm/filters/bundle.js.map +0 -1
- package/esm/filters/chat.d.ts +0 -27
- package/esm/filters/chat.js +0 -51
- package/esm/filters/chat.js.map +0 -1
- package/esm/filters/group.js +0 -65
- package/esm/filters/group.js.map +0 -1
- package/esm/filters/index.d.ts +0 -4
- package/esm/filters/index.js +0 -3
- package/esm/filters/index.js.map +0 -1
- package/esm/filters/logic.d.ts +0 -29
- package/esm/filters/logic.js +0 -105
- package/esm/filters/logic.js.map +0 -1
- package/esm/filters/message.js +0 -168
- package/esm/filters/message.js.map +0 -1
- package/esm/filters/state.d.ts +0 -15
- package/esm/filters/state.js +0 -28
- package/esm/filters/state.js.map +0 -1
- package/esm/filters/text.js +0 -129
- package/esm/filters/text.js.map +0 -1
- package/esm/filters/types.d.ts +0 -91
- package/esm/filters/types.js +0 -2
- package/esm/filters/types.js.map +0 -1
- package/esm/filters/updates.d.ts +0 -39
- package/esm/filters/updates.js +0 -34
- package/esm/filters/updates.js.map +0 -1
- package/esm/filters/user.d.ts +0 -25
- package/esm/filters/user.js +0 -71
- package/esm/filters/user.js.map +0 -1
- package/esm/handler.d.ts +0 -41
- package/esm/handler.js +0 -3
- package/esm/handler.js.map +0 -1
- package/esm/index.d.ts +0 -8
- package/esm/index.js +0 -9
- package/esm/index.js.map +0 -1
- package/esm/propagation.d.ts +0 -22
- package/esm/propagation.js +0 -24
- package/esm/propagation.js.map +0 -1
- package/esm/state/index.d.ts +0 -5
- package/esm/state/index.js +0 -6
- package/esm/state/index.js.map +0 -1
- package/esm/state/key.d.ts +0 -24
- package/esm/state/key.js +0 -39
- package/esm/state/key.js.map +0 -1
- package/esm/state/provider.d.ts +0 -5
- package/esm/state/provider.js +0 -2
- package/esm/state/provider.js.map +0 -1
- package/esm/state/providers/index.d.ts +0 -2
- package/esm/state/providers/index.js +0 -3
- package/esm/state/providers/index.js.map +0 -1
- package/esm/state/providers/memory.d.ts +0 -30
- package/esm/state/providers/memory.js +0 -77
- package/esm/state/providers/memory.js.map +0 -1
- package/esm/state/providers/sqlite.js +0 -96
- package/esm/state/providers/sqlite.js.map +0 -1
- package/esm/state/repository.d.ts +0 -62
- package/esm/state/repository.js +0 -2
- package/esm/state/repository.js.map +0 -1
- package/esm/state/service.js +0 -66
- package/esm/state/service.js.map +0 -1
- package/esm/state/update-state.d.ts +0 -151
- package/esm/state/update-state.js +0 -214
- package/esm/state/update-state.js.map +0 -1
- package/esm/wizard.js +0 -101
- package/esm/wizard.js.map +0 -1
- /package/{cjs/context → context}/index.d.ts +0 -0
- /package/{cjs/filters → filters}/bundle.d.ts +0 -0
- /package/{cjs/filters → filters}/index.d.ts +0 -0
- /package/{cjs/index.d.ts → index.d.cts} +0 -0
- /package/{cjs/propagation.d.ts → propagation.d.ts} +0 -0
- /package/{cjs/state → state}/index.d.ts +0 -0
- /package/{cjs/state → state}/providers/index.d.ts +0 -0
package/cjs/filters/text.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { BusinessCallbackQuery, BusinessMessage, CallbackQuery, ChosenInlineResult, InlineCallbackQuery, InlineQuery, Message } from '@mtcute/core';
|
|
2
|
-
import type { UpdateContextDistributed } from '../context/base.js';
|
|
3
|
-
import type { UpdateFilter } from './types.js';
|
|
4
|
-
type UpdatesWithText = UpdateContextDistributed<Message | BusinessMessage | InlineQuery | ChosenInlineResult | CallbackQuery | InlineCallbackQuery | BusinessCallbackQuery>;
|
|
5
|
-
/**
|
|
6
|
-
* Filter objects that match a given regular expression
|
|
7
|
-
* - for `Message`, `Message.text` is used
|
|
8
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
9
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used
|
|
10
|
-
* - for callback queries, `dataStr` is used
|
|
11
|
-
*
|
|
12
|
-
* When a regex matches, the match array is stored in a
|
|
13
|
-
* type-safe extension field `.match` of the object
|
|
14
|
-
*
|
|
15
|
-
* @param regex Regex to be matched
|
|
16
|
-
*/
|
|
17
|
-
export declare function regex(regex: RegExp): UpdateFilter<UpdatesWithText, {
|
|
18
|
-
match: RegExpMatchArray;
|
|
19
|
-
}>;
|
|
20
|
-
/**
|
|
21
|
-
* Filter objects which contain the exact text given
|
|
22
|
-
* - for `Message`, `Message.text` is used
|
|
23
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
24
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
25
|
-
* - for callback queries, `dataStr` is used
|
|
26
|
-
*
|
|
27
|
-
* @param str String to be matched
|
|
28
|
-
* @param ignoreCase Whether string case should be ignored
|
|
29
|
-
*/
|
|
30
|
-
export declare function equals(str: string, ignoreCase?: boolean): UpdateFilter<UpdatesWithText>;
|
|
31
|
-
/**
|
|
32
|
-
* Filter objects which contain the text given (as a substring)
|
|
33
|
-
* - for `Message`, `Message.text` is used
|
|
34
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
35
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
36
|
-
* - for callback queries, `dataStr` is used
|
|
37
|
-
*
|
|
38
|
-
* @param str Substring to be matched
|
|
39
|
-
* @param ignoreCase Whether string case should be ignored
|
|
40
|
-
*/
|
|
41
|
-
export declare function contains(str: string, ignoreCase?: boolean): UpdateFilter<UpdatesWithText>;
|
|
42
|
-
/**
|
|
43
|
-
* Filter objects which contain the text starting with a given string
|
|
44
|
-
* - for `Message`, `Message.text` is used
|
|
45
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
46
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
47
|
-
* - for callback queries, `dataStr` is used
|
|
48
|
-
*
|
|
49
|
-
* @param str Substring to be matched
|
|
50
|
-
* @param ignoreCase Whether string case should be ignored
|
|
51
|
-
*/
|
|
52
|
-
export declare function startsWith(str: string, ignoreCase?: boolean): UpdateFilter<UpdatesWithText>;
|
|
53
|
-
/**
|
|
54
|
-
* Filter objects which contain the text ending with a given string
|
|
55
|
-
* - for `Message`, `Message.text` is used
|
|
56
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
57
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
58
|
-
* - for callback queries, `dataStr` is used
|
|
59
|
-
*
|
|
60
|
-
* @param str Substring to be matched
|
|
61
|
-
* @param ignoreCase Whether string case should be ignored
|
|
62
|
-
*/
|
|
63
|
-
export declare function endsWith(str: string, ignoreCase?: boolean): UpdateFilter<UpdatesWithText>;
|
|
64
|
-
export {};
|
package/cjs/filters/text.js
DELETED
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.regex = regex;
|
|
4
|
-
exports.equals = equals;
|
|
5
|
-
exports.contains = contains;
|
|
6
|
-
exports.startsWith = startsWith;
|
|
7
|
-
exports.endsWith = endsWith;
|
|
8
|
-
function extractText(obj) {
|
|
9
|
-
switch (obj._name) {
|
|
10
|
-
case 'new_message':
|
|
11
|
-
case 'new_business_message':
|
|
12
|
-
return obj.text;
|
|
13
|
-
case 'inline_query':
|
|
14
|
-
return obj.query;
|
|
15
|
-
case 'chosen_inline_result':
|
|
16
|
-
return obj.id;
|
|
17
|
-
case 'callback_query':
|
|
18
|
-
case 'inline_callback_query':
|
|
19
|
-
case 'business_callback_query':
|
|
20
|
-
if (obj.raw.data)
|
|
21
|
-
return obj.dataStr;
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* Filter objects that match a given regular expression
|
|
27
|
-
* - for `Message`, `Message.text` is used
|
|
28
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
29
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used
|
|
30
|
-
* - for callback queries, `dataStr` is used
|
|
31
|
-
*
|
|
32
|
-
* When a regex matches, the match array is stored in a
|
|
33
|
-
* type-safe extension field `.match` of the object
|
|
34
|
-
*
|
|
35
|
-
* @param regex Regex to be matched
|
|
36
|
-
*/
|
|
37
|
-
function regex(regex) {
|
|
38
|
-
return (obj) => {
|
|
39
|
-
const txt = extractText(obj);
|
|
40
|
-
if (!txt)
|
|
41
|
-
return false;
|
|
42
|
-
const m = txt.match(regex);
|
|
43
|
-
if (m) {
|
|
44
|
-
obj.match = m;
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
return false;
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Filter objects which contain the exact text given
|
|
52
|
-
* - for `Message`, `Message.text` is used
|
|
53
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
54
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
55
|
-
* - for callback queries, `dataStr` is used
|
|
56
|
-
*
|
|
57
|
-
* @param str String to be matched
|
|
58
|
-
* @param ignoreCase Whether string case should be ignored
|
|
59
|
-
*/
|
|
60
|
-
function equals(str, ignoreCase = false) {
|
|
61
|
-
if (ignoreCase) {
|
|
62
|
-
str = str.toLowerCase();
|
|
63
|
-
return obj => extractText(obj)?.toLowerCase() === str;
|
|
64
|
-
}
|
|
65
|
-
return obj => extractText(obj) === str;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* Filter objects which contain the text given (as a substring)
|
|
69
|
-
* - for `Message`, `Message.text` is used
|
|
70
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
71
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
72
|
-
* - for callback queries, `dataStr` is used
|
|
73
|
-
*
|
|
74
|
-
* @param str Substring to be matched
|
|
75
|
-
* @param ignoreCase Whether string case should be ignored
|
|
76
|
-
*/
|
|
77
|
-
function contains(str, ignoreCase = false) {
|
|
78
|
-
if (ignoreCase) {
|
|
79
|
-
str = str.toLowerCase();
|
|
80
|
-
return (obj) => {
|
|
81
|
-
const txt = extractText(obj);
|
|
82
|
-
return txt != null && txt.toLowerCase().includes(str);
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
return (obj) => {
|
|
86
|
-
const txt = extractText(obj);
|
|
87
|
-
return txt != null && txt.includes(str);
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Filter objects which contain the text starting with a given string
|
|
92
|
-
* - for `Message`, `Message.text` is used
|
|
93
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
94
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
95
|
-
* - for callback queries, `dataStr` is used
|
|
96
|
-
*
|
|
97
|
-
* @param str Substring to be matched
|
|
98
|
-
* @param ignoreCase Whether string case should be ignored
|
|
99
|
-
*/
|
|
100
|
-
function startsWith(str, ignoreCase = false) {
|
|
101
|
-
if (ignoreCase) {
|
|
102
|
-
str = str.toLowerCase();
|
|
103
|
-
return (obj) => {
|
|
104
|
-
const txt = extractText(obj);
|
|
105
|
-
return txt != null && txt.toLowerCase().substring(0, str.length) === str;
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
return (obj) => {
|
|
109
|
-
const txt = extractText(obj);
|
|
110
|
-
return txt != null && txt.substring(0, str.length) === str;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Filter objects which contain the text ending with a given string
|
|
115
|
-
* - for `Message`, `Message.text` is used
|
|
116
|
-
* - for `InlineQuery`, `InlineQuery.query` is used
|
|
117
|
-
* - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used
|
|
118
|
-
* - for callback queries, `dataStr` is used
|
|
119
|
-
*
|
|
120
|
-
* @param str Substring to be matched
|
|
121
|
-
* @param ignoreCase Whether string case should be ignored
|
|
122
|
-
*/
|
|
123
|
-
function endsWith(str, ignoreCase = false) {
|
|
124
|
-
if (ignoreCase) {
|
|
125
|
-
str = str.toLowerCase();
|
|
126
|
-
return (obj) => {
|
|
127
|
-
const txt = extractText(obj);
|
|
128
|
-
return txt != null && txt.toLowerCase().substring(0, str.length) === str;
|
|
129
|
-
};
|
|
130
|
-
}
|
|
131
|
-
return (obj) => {
|
|
132
|
-
const txt = extractText(obj);
|
|
133
|
-
return txt != null && txt.substring(0, str.length) === str;
|
|
134
|
-
};
|
|
135
|
-
}
|
|
136
|
-
//# sourceMappingURL=text.js.map
|
package/cjs/filters/text.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../../src/filters/text.ts"],"names":[],"mappings":";;AAsDA,sBAeC;AAYD,wBAQC;AAY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C,CAAA;AACL,CAAC;AAED;;;;;;;;;GASG;AACH,SAAgB,QAAQ,CAAC,GAAW,EAAE,UAAU,GAAG,KAAK;IACpD,IAAI,UAAU,EAAE,CAAC;QACb,GAAG,GAAG,GAAG,CAAC,WAAW,EAAE,CAAA;QAEvB,OAAO,CAAC,GAAG,EAAE,EAAE;YACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;YAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,WAAW,EAAE,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;QAC5E,CAAC,CAAA;IACL,CAAC;IAED,OAAO,CAAC,GAAG,EAAE,EAAE;QACX,MAAM,GAAG,GAAG,WAAW,CAAC,GAAG,CAAC,CAAA;QAE5B,OAAO,GAAG,IAAI,IAAI,IAAI,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,KAAK,GAAG,CAAA;IAC9D,CAAC,CAAA;AACL,CAAC","sourcesContent":["import type {\n BusinessCallbackQuery,\n BusinessMessage,\n CallbackQuery,\n ChosenInlineResult,\n InlineCallbackQuery,\n InlineQuery,\n Message,\n} from '@mtcute/core'\n\nimport type { UpdateContextDistributed } from '../context/base.js'\n\nimport type { UpdateFilter } from './types.js'\n\ntype UpdatesWithText = UpdateContextDistributed<\n | Message\n | BusinessMessage\n | InlineQuery\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n>\n\nfunction extractText(obj: UpdatesWithText): string | null {\n switch (obj._name) {\n case 'new_message':\n case 'new_business_message':\n return obj.text\n case 'inline_query':\n return obj.query\n case 'chosen_inline_result':\n return obj.id\n case 'callback_query':\n case 'inline_callback_query':\n case 'business_callback_query':\n if (obj.raw.data) return obj.dataStr\n }\n\n return null\n}\n\n/**\n * Filter objects that match a given regular expression\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult#id} is used\n * - for callback queries, `dataStr` is used\n *\n * When a regex matches, the match array is stored in a\n * type-safe extension field `.match` of the object\n *\n * @param regex Regex to be matched\n */\nexport function regex(regex: RegExp): UpdateFilter<UpdatesWithText, { match: RegExpMatchArray }> {\n return (obj) => {\n const txt = extractText(obj)\n if (!txt) return false\n\n const m = txt.match(regex)\n\n if (m) {\n (obj as typeof obj & { match: RegExpMatchArray }).match = m\n\n return true\n }\n\n return false\n }\n}\n\n/**\n * Filter objects which contain the exact text given\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str String to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function equals(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return obj => extractText(obj)?.toLowerCase() === str\n }\n\n return obj => extractText(obj) === str\n}\n\n/**\n * Filter objects which contain the text given (as a substring)\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function contains(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().includes(str)\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.includes(str)\n }\n}\n\n/**\n * Filter objects which contain the text starting with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function startsWith(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n\n/**\n * Filter objects which contain the text ending with a given string\n * - for `Message`, `Message.text` is used\n * - for `InlineQuery`, `InlineQuery.query` is used\n * - for {@link ChosenInlineResult}, {@link ChosenInlineResult.id} is used\n * - for callback queries, `dataStr` is used\n *\n * @param str Substring to be matched\n * @param ignoreCase Whether string case should be ignored\n */\nexport function endsWith(str: string, ignoreCase = false): UpdateFilter<UpdatesWithText> {\n if (ignoreCase) {\n str = str.toLowerCase()\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.toLowerCase().substring(0, str.length) === str\n }\n }\n\n return (obj) => {\n const txt = extractText(obj)\n\n return txt != null && txt.substring(0, str.length) === str\n }\n}\n"]}
|
package/cjs/filters/types.js
DELETED
package/cjs/filters/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/filters/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { MaybePromise } from '@mtcute/core'\n\nimport type { UpdateState } from '../state/update-state.js'\n/**\n * Type describing a primitive filter, which is a function taking some `Base`\n * and a {@link TelegramClient}, checking it against some condition\n * and returning a boolean.\n *\n * If `true` is returned, the filter is considered\n * to be matched, and the appropriate update handler function is called,\n * otherwise next registered handler is checked.\n *\n * Additionally, filter might contain a type modification\n * to `Base` for better code insights. If it is present,\n * it is used to overwrite types (!) of some of the `Base` fields\n * to given (note that this is entirely compile-time! object is not modified)\n *\n * For parametrized filters (like {@link filters.regex}),\n * type modification can also be used to add additional fields\n * (in case of `regex`, its match array is added to `.match`)\n *\n * Example without type mod:\n * ```typescript\n *\n * const hasPhoto: UpdateFilter<Message> = msg => msg.media?.type === 'photo'\n *\n * // ..later..\n * tg.onNewMessage(hasPhoto, async (msg) => {\n * // `hasPhoto` filter matched, so we can safely assume\n * // that `msg.media` is a Photo.\n * //\n * // but it is very redundant, verbose and error-rome,\n * // wonder if we could make typescript do this automagically and safely...\n * await (msg.media as Photo).downloadToFile(`${msg.id}.jpg`)\n * })\n * ```\n *\n * Example with type mod:\n * ```typescript\n *\n * const hasPhoto: UpdateFilter<Message, { media: Photo }> = msg => msg.media?.type === 'photo'\n *\n * // ..later..\n * tg.onNewMessage(hasPhoto, async (msg) => {\n * // since `hasPhoto` filter matched,\n * // we have applied the modification to `msg`,\n * // and `msg.media` now has type `Photo`\n * //\n * // no more redundancy and type casts!\n * await msg.media.downloadToFile(`${msg.id}.jpg`)\n * })\n * ```\n *\n * > **Note**: Type modification can contain anything, even totally unrelated types\n * > and it is *your* task to keep track that everything is correct.\n * >\n * > Bad example:\n * > ```typescript\n * > // we check for `Photo`, but type contains `Audio`. this will be a problem!\n * > const hasPhoto: UpdateFilter<Message, { media: Audio }> = msg => msg.media?.type === 'photo'\n * >\n * > // ..later..\n * > tg.onNewMessage(hasPhoto, async (msg) => {\n * > // oops! `msg.media` is `Audio` and does not have `.width`!\n * > console.log(msg.media.width)\n * > })\n * > ```\n *\n * > **Warning!** Do not use the generics provided in functions\n * > like `and`, `or`, etc. Those are meant to be inferred by the compiler!\n */\n// we need the second parameter because it carries meta information\n// eslint-disable-next-line unused-imports/no-unused-vars, ts/no-empty-object-type\nexport type UpdateFilter<Base, Mod = {}, State extends object = never> = (\n update: Base,\n state?: UpdateState<State>,\n) => MaybePromise<boolean>\n\nexport type Modify<Base, Mod> = Omit<Base, keyof Mod> & Mod\nexport type Invert<Base, Mod> = {\n [P in keyof Mod & keyof Base]: Exclude<Base[P], Mod[P]>\n}\n\nexport type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never\n\nexport type ExtractBase<Filter> = Filter extends UpdateFilter<infer I, any> ? I : never\n\nexport type ExtractMod<Filter> = Filter extends UpdateFilter<any, infer I> ? I : never\n\nexport type ExtractState<Filter> = Filter extends UpdateFilter<any, any, infer I> ? I : never\n\nexport type TupleKeys<T extends any[]> = Exclude<keyof T, keyof []>\nexport type WrapBase<T extends any[]> = {\n [K in TupleKeys<T>]: { base: ExtractBase<T[K]> }\n}\nexport type Values<T> = T[keyof T]\nexport type UnwrapBase<T> = T extends { base: any } ? T['base'] : never\nexport type ExtractBaseMany<Filters extends any[]> = UnwrapBase<UnionToIntersection<Values<WrapBase<Filters>>>>\n\nexport type EmptyObject = Record<never, never>\n"]}
|
package/cjs/filters/updates.js
DELETED
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.chatMemberSelf = exports.userStatus = exports.chatMember = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Create a filter for {@link ChatMemberUpdate} by update type
|
|
6
|
-
*
|
|
7
|
-
* @param types Update type(s)
|
|
8
|
-
* @link ChatMemberUpdate.Type
|
|
9
|
-
*/
|
|
10
|
-
const chatMember = (types) => {
|
|
11
|
-
if (Array.isArray(types)) {
|
|
12
|
-
const index = {};
|
|
13
|
-
types.forEach(typ => (index[typ] = true));
|
|
14
|
-
return upd => upd.type in index;
|
|
15
|
-
}
|
|
16
|
-
return upd => upd.type === types;
|
|
17
|
-
};
|
|
18
|
-
exports.chatMember = chatMember;
|
|
19
|
-
/**
|
|
20
|
-
* Create a filter for {@link UserStatusUpdate} by new user status
|
|
21
|
-
*
|
|
22
|
-
* @param statuses Update type(s)
|
|
23
|
-
* @link User.Status
|
|
24
|
-
*/
|
|
25
|
-
const userStatus = (statuses) => {
|
|
26
|
-
if (Array.isArray(statuses)) {
|
|
27
|
-
const index = {};
|
|
28
|
-
statuses.forEach(typ => (index[typ] = true));
|
|
29
|
-
return upd => upd.status in index;
|
|
30
|
-
}
|
|
31
|
-
return upd => upd.status === statuses;
|
|
32
|
-
};
|
|
33
|
-
exports.userStatus = userStatus;
|
|
34
|
-
/**
|
|
35
|
-
* Create a filter for {@link ChatMemberUpdate} for updates
|
|
36
|
-
* regarding current user
|
|
37
|
-
*/
|
|
38
|
-
const chatMemberSelf = upd => upd.isSelf;
|
|
39
|
-
exports.chatMemberSelf = chatMemberSelf;
|
|
40
|
-
//# sourceMappingURL=updates.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updates.js","sourceRoot":"","sources":["../../../src/filters/updates.ts"],"names":[],"mappings":";;;AAIA;;;;;GAKG;AACI,MAAM,UAAU,GAGnB,CAAC,KAAuC,EAAkC,EAAE;IAC5E,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACvB,MAAM,KAAK,GAAgD,EAAE,CAAA;QAC7D,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAEzC,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,IAAI,KAAK,CAAA;IACnC,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,KAAK,KAAK,CAAA;AACpC,CAAC,CAAA;AAZY,QAAA,UAAU,cAYtB;AAED;;;;;GAKG;AACI,MAAM,UAAU,GAYnB,CAAC,QAAgC,EAAkC,EAAE;IACrE,IAAI,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC1B,MAAM,KAAK,GAAsC,EAAE,CAAA;QACnD,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC,CAAA;QAE5C,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,IAAI,KAAK,CAAA;IACrC,CAAC;IAED,OAAO,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,KAAK,QAAQ,CAAA;AACzC,CAAC,CAAA;AArBY,QAAA,UAAU,cAqBtB;AAED;;;GAGG;AACI,MAAM,cAAc,GAAqD,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,MAAM,CAAA;AAApF,QAAA,cAAc,kBAAsE","sourcesContent":["import type { ChatMemberUpdate, ChatMemberUpdateType, MaybeArray, UserStatus, UserStatusUpdate } from '@mtcute/core'\n\nimport type { UpdateFilter } from './types.js'\n\n/**\n * Create a filter for {@link ChatMemberUpdate} by update type\n *\n * @param types Update type(s)\n * @link ChatMemberUpdate.Type\n */\nexport const chatMember: {\n <T extends ChatMemberUpdateType>(type: T): UpdateFilter<ChatMemberUpdate, { type: T }>\n <T extends ChatMemberUpdateType[]>(types: T): UpdateFilter<ChatMemberUpdate, { type: T[number] }>\n} = (types: MaybeArray<ChatMemberUpdateType>): UpdateFilter<ChatMemberUpdate> => {\n if (Array.isArray(types)) {\n const index: Partial<Record<ChatMemberUpdateType, true>> = {}\n types.forEach(typ => (index[typ] = true))\n\n return upd => upd.type in index\n }\n\n return upd => upd.type === types\n}\n\n/**\n * Create a filter for {@link UserStatusUpdate} by new user status\n *\n * @param statuses Update type(s)\n * @link User.Status\n */\nexport const userStatus: {\n <T extends UserStatus>(\n status: T,\n ): UpdateFilter<\n UserStatusUpdate,\n {\n type: T\n lastOnline: T extends 'offline' ? Date : null\n nextOffline: T extends 'online' ? Date : null\n }\n >\n <T extends UserStatus[]>(statuses: T): UpdateFilter<UserStatusUpdate, { type: T[number] }>\n} = (statuses: MaybeArray<UserStatus>): UpdateFilter<UserStatusUpdate> => {\n if (Array.isArray(statuses)) {\n const index: Partial<Record<UserStatus, true>> = {}\n statuses.forEach(typ => (index[typ] = true))\n\n return upd => upd.status in index\n }\n\n return upd => upd.status === statuses\n}\n\n/**\n * Create a filter for {@link ChatMemberUpdate} for updates\n * regarding current user\n */\nexport const chatMemberSelf: UpdateFilter<ChatMemberUpdate, { isSelf: true }> = upd => upd.isSelf\n"]}
|
package/cjs/filters/user.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.userId = exports.bot = exports.me = void 0;
|
|
4
|
-
const core_1 = require("@mtcute/core");
|
|
5
|
-
/**
|
|
6
|
-
* Filter messages generated by yourself (including Saved Messages)
|
|
7
|
-
*/
|
|
8
|
-
const me = msg => (msg.sender.type === 'user' && msg.sender.isSelf) || msg.isOutgoing;
|
|
9
|
-
exports.me = me;
|
|
10
|
-
/**
|
|
11
|
-
* Filter messages sent by bots
|
|
12
|
-
*/
|
|
13
|
-
const bot = msg => msg.sender.constructor === core_1.User && msg.sender.isBot;
|
|
14
|
-
exports.bot = bot;
|
|
15
|
-
/**
|
|
16
|
-
* Filter updates by user ID(s) or username(s)
|
|
17
|
-
*
|
|
18
|
-
* Note that only some updates support filtering by username.
|
|
19
|
-
*/
|
|
20
|
-
const userId = (id) => {
|
|
21
|
-
const indexId = new Set();
|
|
22
|
-
const indexUsername = new Set();
|
|
23
|
-
let matchSelf = false;
|
|
24
|
-
if (!Array.isArray(id))
|
|
25
|
-
id = [id];
|
|
26
|
-
id.forEach((id) => {
|
|
27
|
-
if (id === 'me' || id === 'self') {
|
|
28
|
-
matchSelf = true;
|
|
29
|
-
}
|
|
30
|
-
else if (typeof id === 'string') {
|
|
31
|
-
indexUsername.add(id);
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
indexId.add(id);
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return (upd) => {
|
|
38
|
-
switch (upd._name) {
|
|
39
|
-
case 'new_message':
|
|
40
|
-
case 'edit_message':
|
|
41
|
-
case 'new_business_message':
|
|
42
|
-
case 'edit_business_message': {
|
|
43
|
-
const sender = upd.sender;
|
|
44
|
-
return (matchSelf && sender.isSelf)
|
|
45
|
-
|| indexId.has(sender.id)
|
|
46
|
-
|| indexUsername.has(sender.username);
|
|
47
|
-
}
|
|
48
|
-
case 'user_status':
|
|
49
|
-
case 'user_typing': {
|
|
50
|
-
const id = upd.userId;
|
|
51
|
-
return (matchSelf && id === upd.client.storage.self.getCached()?.userId)
|
|
52
|
-
|| indexId.has(id);
|
|
53
|
-
}
|
|
54
|
-
case 'poll_vote':
|
|
55
|
-
case 'story':
|
|
56
|
-
case 'delete_story': {
|
|
57
|
-
const peer = upd.peer;
|
|
58
|
-
if (peer.type !== 'user')
|
|
59
|
-
return false;
|
|
60
|
-
return (matchSelf && peer.isSelf)
|
|
61
|
-
|| indexId.has(peer.id)
|
|
62
|
-
|| Boolean(peer.usernames?.some(u => indexUsername.has(u.username)));
|
|
63
|
-
}
|
|
64
|
-
case 'history_read': {
|
|
65
|
-
const id = upd.chatId;
|
|
66
|
-
return (matchSelf && id === upd.client.storage.self.getCached()?.userId)
|
|
67
|
-
|| indexId.has(id);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
const user = upd.user;
|
|
71
|
-
return ((matchSelf && user.isSelf)
|
|
72
|
-
|| indexId.has(user.id)
|
|
73
|
-
|| Boolean(user.usernames?.some(u => indexUsername.has(u.username))));
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
exports.userId = userId;
|
|
77
|
-
//# sourceMappingURL=user.js.map
|
package/cjs/filters/user.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"user.js","sourceRoot":"","sources":["../../../src/filters/user.ts"],"names":[],"mappings":";;;AAkBA,uCAEqB;AAMrB;;GAEG;AACI,MAAM,EAAE,GAA4C,GAAG,CAAC,EAAE,CAC7D,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,KAAK,MAAM,IAAI,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,UAAU,CAAA;AAD1D,QAAA,EAAE,MACwD;AAEvE;;GAEG;AACI,MAAM,GAAG,GAA4C,GAAG,CAAC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CAAC,CAAC,CAAC,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CACvE,CAAA;IACL,CAAC,CAAA;AACL,CAAC,CAAA;AA7FY,QAAA,MAAM,UA6FlB","sourcesContent":["import type {\n BotChatJoinRequestUpdate,\n BusinessCallbackQuery,\n BusinessMessage,\n CallbackQuery,\n ChatMemberUpdate,\n ChosenInlineResult,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n InlineCallbackQuery,\n InlineQuery,\n MaybeArray,\n Message,\n PollVoteUpdate,\n StoryUpdate,\n UserStatusUpdate,\n UserTypingUpdate,\n} from '@mtcute/core'\nimport {\n User,\n} from '@mtcute/core'\n\nimport type { UpdateContextDistributed } from '../context/base.js'\n\nimport type { UpdateFilter } from './types.js'\n\n/**\n * Filter messages generated by yourself (including Saved Messages)\n */\nexport const me: UpdateFilter<Message, { sender: User }> = msg =>\n (msg.sender.type === 'user' && msg.sender.isSelf) || msg.isOutgoing\n\n/**\n * Filter messages sent by bots\n */\nexport const bot: UpdateFilter<Message, { sender: User }> = msg => msg.sender.constructor === User && msg.sender.isBot\n\n/**\n * Filter updates by user ID(s) or username(s)\n *\n * Note that only some updates support filtering by username.\n */\nexport const userId: {\n (id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<\n | Message\n | BusinessMessage\n | StoryUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n (id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<\n | Message\n | BusinessMessage\n | UserStatusUpdate\n | UserTypingUpdate\n | StoryUpdate\n | HistoryReadUpdate\n | DeleteStoryUpdate\n | InlineQuery\n | ChatMemberUpdate\n | ChosenInlineResult\n | CallbackQuery\n | InlineCallbackQuery\n | BusinessCallbackQuery\n | PollVoteUpdate\n | BotChatJoinRequestUpdate\n >>\n} = (id) => {\n const indexId = new Set<number>()\n const indexUsername = new Set<string>()\n let matchSelf = false\n\n if (!Array.isArray(id)) id = [id]\n id.forEach((id) => {\n if (id === 'me' || id === 'self') {\n matchSelf = true\n } else if (typeof id === 'string') {\n indexUsername.add(id)\n } else {\n indexId.add(id)\n }\n })\n\n return (upd) => {\n switch (upd._name) {\n case 'new_message':\n case 'edit_message':\n case 'new_business_message':\n case 'edit_business_message': {\n const sender = upd.sender\n\n return (matchSelf && sender.isSelf)\n || indexId.has(sender.id)\n || indexUsername.has(sender.username!)\n }\n case 'user_status':\n case 'user_typing': {\n const id = upd.userId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId)\n || indexId.has(id)\n }\n case 'poll_vote':\n case 'story':\n case 'delete_story': {\n const peer = upd.peer\n if (peer.type !== 'user') return false\n\n return (matchSelf && peer.isSelf)\n || indexId.has(peer.id)\n || Boolean(peer.usernames?.some(u => indexUsername.has(u.username)))\n }\n case 'history_read': {\n const id = upd.chatId\n\n return (matchSelf && id === upd.client.storage.self.getCached()?.userId)\n || indexId.has(id)\n }\n }\n\n const user = upd.user\n\n return (\n (matchSelf && user.isSelf)\n || indexId.has(user.id)\n || Boolean(user.usernames?.some(u => indexUsername.has(u.username)))\n )\n }\n}\n"]}
|
package/cjs/handler.js
DELETED
package/cjs/handler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"handler.js","sourceRoot":"","sources":["../../src/handler.ts"],"names":[],"mappings":";;AA2JA,cAAc","sourcesContent":["import type {\n BotReactionCountUpdate,\n BotReactionUpdate,\n BotStoppedUpdate,\n BusinessConnection,\n ChatJoinRequestUpdate,\n ChatMemberUpdate,\n DeleteBusinessMessageUpdate,\n DeleteMessageUpdate,\n DeleteStoryUpdate,\n HistoryReadUpdate,\n MaybePromise,\n PeersIndex,\n PollUpdate,\n PollVoteUpdate,\n StoryUpdate,\n UserStatusUpdate,\n UserTypingUpdate,\n tl,\n} from '@mtcute/core'\nimport type { TelegramClient } from '@mtcute/core/client.js'\n\nimport type { UpdateContext } from './context/base.js'\nimport type {\n BusinessCallbackQueryContext,\n BusinessMessageContext,\n CallbackQueryContext,\n ChatJoinRequestUpdateContext,\n ChosenInlineResultContext,\n InlineCallbackQueryContext,\n InlineQueryContext,\n MessageContext,\n PreCheckoutQueryContext,\n} from './context/index.js'\nimport type { PropagationAction } from './propagation.js'\n\nexport interface BaseUpdateHandler<Name, Handler, Checker> {\n name: Name\n callback: Handler\n\n check?: Checker\n}\n\nexport type ParsedUpdateHandler<Name, Update, State = never> = BaseUpdateHandler<\n Name,\n (update: Update, state: State) => MaybePromise<void | PropagationAction>,\n (update: Update, state: State) => MaybePromise<boolean>\n>\n\nexport type RawUpdateHandler = BaseUpdateHandler<\n 'raw',\n (\n client: TelegramClient,\n update: tl.TypeUpdate | tl.TypeMessage,\n peers: PeersIndex,\n ) => MaybePromise<void | PropagationAction>,\n (client: TelegramClient, update: tl.TypeUpdate | tl.TypeMessage, peers: PeersIndex) => MaybePromise<boolean>\n>\n\n// begin-codegen\nexport type NewMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'new_message', T, S>\nexport type EditMessageHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'edit_message', T, S>\nexport type MessageGroupHandler<T = MessageContext, S = never> = ParsedUpdateHandler<'message_group', T, S>\nexport type DeleteMessageHandler<T = UpdateContext<DeleteMessageUpdate>> = ParsedUpdateHandler<'delete_message', T>\nexport type ChatMemberUpdateHandler<T = UpdateContext<ChatMemberUpdate>> = ParsedUpdateHandler<'chat_member', T>\nexport type InlineQueryHandler<T = InlineQueryContext> = ParsedUpdateHandler<'inline_query', T>\nexport type ChosenInlineResultHandler<T = ChosenInlineResultContext> = ParsedUpdateHandler<'chosen_inline_result', T>\nexport type CallbackQueryHandler<T = CallbackQueryContext, S = never> = ParsedUpdateHandler<'callback_query', T, S>\nexport type InlineCallbackQueryHandler<T = InlineCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'inline_callback_query',\n T,\n S\n>\nexport type BusinessCallbackQueryHandler<T = BusinessCallbackQueryContext, S = never> = ParsedUpdateHandler<\n 'business_callback_query',\n T,\n S\n>\nexport type PollUpdateHandler<T = UpdateContext<PollUpdate>> = ParsedUpdateHandler<'poll', T>\nexport type PollVoteHandler<T = UpdateContext<PollVoteUpdate>> = ParsedUpdateHandler<'poll_vote', T>\nexport type UserStatusUpdateHandler<T = UpdateContext<UserStatusUpdate>> = ParsedUpdateHandler<'user_status', T>\nexport type UserTypingHandler<T = UpdateContext<UserTypingUpdate>> = ParsedUpdateHandler<'user_typing', T>\nexport type HistoryReadHandler<T = UpdateContext<HistoryReadUpdate>> = ParsedUpdateHandler<'history_read', T>\nexport type BotStoppedHandler<T = UpdateContext<BotStoppedUpdate>> = ParsedUpdateHandler<'bot_stopped', T>\nexport type BotChatJoinRequestHandler<T = ChatJoinRequestUpdateContext> = ParsedUpdateHandler<\n 'bot_chat_join_request',\n T\n>\nexport type ChatJoinRequestHandler<T = UpdateContext<ChatJoinRequestUpdate>> = ParsedUpdateHandler<\n 'chat_join_request',\n T\n>\nexport type PreCheckoutQueryHandler<T = PreCheckoutQueryContext> = ParsedUpdateHandler<'pre_checkout_query', T>\nexport type StoryUpdateHandler<T = UpdateContext<StoryUpdate>> = ParsedUpdateHandler<'story', T>\nexport type DeleteStoryHandler<T = UpdateContext<DeleteStoryUpdate>> = ParsedUpdateHandler<'delete_story', T>\nexport type BotReactionUpdateHandler<T = UpdateContext<BotReactionUpdate>> = ParsedUpdateHandler<'bot_reaction', T>\nexport type BotReactionCountUpdateHandler<T = UpdateContext<BotReactionCountUpdate>> = ParsedUpdateHandler<\n 'bot_reaction_count',\n T\n>\nexport type BusinessConnectionUpdateHandler<T = UpdateContext<BusinessConnection>> = ParsedUpdateHandler<\n 'business_connection',\n T\n>\nexport type NewBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'new_business_message',\n T,\n S\n>\nexport type EditBusinessMessageHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'edit_business_message',\n T,\n S\n>\nexport type BusinessMessageGroupHandler<T = BusinessMessageContext, S = never> = ParsedUpdateHandler<\n 'business_message_group',\n T,\n S\n>\nexport type DeleteBusinessMessageHandler<T = UpdateContext<DeleteBusinessMessageUpdate>> = ParsedUpdateHandler<\n 'delete_business_message',\n T\n>\n\nexport type UpdateHandler =\n | RawUpdateHandler\n | NewMessageHandler\n | EditMessageHandler\n | MessageGroupHandler\n | DeleteMessageHandler\n | ChatMemberUpdateHandler\n | InlineQueryHandler\n | ChosenInlineResultHandler\n | CallbackQueryHandler\n | InlineCallbackQueryHandler\n | BusinessCallbackQueryHandler\n | PollUpdateHandler\n | PollVoteHandler\n | UserStatusUpdateHandler\n | UserTypingHandler\n | HistoryReadHandler\n | BotStoppedHandler\n | BotChatJoinRequestHandler\n | ChatJoinRequestHandler\n | PreCheckoutQueryHandler\n | StoryUpdateHandler\n | DeleteStoryHandler\n | BotReactionUpdateHandler\n | BotReactionCountUpdateHandler\n | BusinessConnectionUpdateHandler\n | NewBusinessMessageHandler\n | EditBusinessMessageHandler\n | BusinessMessageGroupHandler\n | DeleteBusinessMessageHandler\n\n// end-codegen\n"]}
|
package/cjs/index.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
if (typeof globalThis !== 'undefined' && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
3
|
-
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true
|
|
4
|
-
console.warn("[@mtcute/dispatcher] CommonJS support is deprecated and will be removed soon. Please consider switching to ESM, it's "+(new Date()).getFullYear()+" already.")
|
|
5
|
-
console.warn("[@mtcute/dispatcher] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c")
|
|
6
|
-
}
|
|
7
|
-
"use strict";
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
__exportStar(require("./callback-data-builder.js"), exports);
|
|
24
|
-
__exportStar(require("./context/index.js"), exports);
|
|
25
|
-
__exportStar(require("./dispatcher.js"), exports);
|
|
26
|
-
__exportStar(require("./filters/index.js"), exports);
|
|
27
|
-
__exportStar(require("./handler.js"), exports);
|
|
28
|
-
__exportStar(require("./propagation.js"), exports);
|
|
29
|
-
__exportStar(require("./state/index.js"), exports);
|
|
30
|
-
__exportStar(require("./wizard.js"), exports);
|
|
31
|
-
//# sourceMappingURL=index.js.map
|
package/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,6DAA0C;AAC1C,qDAAkC;AAClC,kDAA+B;AAC/B,qDAAkC;AAClC,+CAA4B;AAC5B,mDAAgC;AAChC,mDAAgC;AAChC,8CAA2B","sourcesContent":["export * from './callback-data-builder.js'\nexport * from './context/index.js'\nexport * from './dispatcher.js'\nexport * from './filters/index.js'\nexport * from './handler.js'\nexport * from './propagation.js'\nexport * from './state/index.js'\nexport * from './wizard.js'\n"]}
|
package/cjs/package.json
DELETED
package/cjs/propagation.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PropagationAction = void 0;
|
|
4
|
-
/**
|
|
5
|
-
* Propagation action.
|
|
6
|
-
*
|
|
7
|
-
* `Stop`: Stop the propagation of the event through any handler groups
|
|
8
|
-
* in the current dispatcher. Does not prevent child dispatchers from
|
|
9
|
-
* being executed.
|
|
10
|
-
*
|
|
11
|
-
* `StopChildren`: Stop the propagation of the event through any handler groups
|
|
12
|
-
* in the current dispatcher, and any of its children. If current dispatcher
|
|
13
|
-
* is a child, does not prevent from propagating to its siblings.
|
|
14
|
-
*
|
|
15
|
-
* `Continue`: Continue propagating the event inside the same handler group.
|
|
16
|
-
*
|
|
17
|
-
* `ToScene`: Used after using `state.enter()` to dispatch the update to the scene,
|
|
18
|
-
* or after `state.exit()` to dispatch the update to the root dispatcher.
|
|
19
|
-
*/
|
|
20
|
-
var PropagationAction;
|
|
21
|
-
(function (PropagationAction) {
|
|
22
|
-
PropagationAction["Stop"] = "stop";
|
|
23
|
-
PropagationAction["StopChildren"] = "stop-children";
|
|
24
|
-
PropagationAction["Continue"] = "continue";
|
|
25
|
-
PropagationAction["ToScene"] = "scene";
|
|
26
|
-
})(PropagationAction || (exports.PropagationAction = PropagationAction = {}));
|
|
27
|
-
//# sourceMappingURL=propagation.js.map
|
package/cjs/propagation.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"propagation.js","sourceRoot":"","sources":["../../src/propagation.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;;GAeG;AACH,IAAY,iBAKX;AALD,WAAY,iBAAiB;IACzB,kCAAa,CAAA;IACb,mDAA8B,CAAA;IAC9B,0CAAqB,CAAA;IACrB,sCAAiB,CAAA;AACrB,CAAC,EALW,iBAAiB,iCAAjB,iBAAiB,QAK5B","sourcesContent":["/**\n * Propagation action.\n *\n * `Stop`: Stop the propagation of the event through any handler groups\n * in the current dispatcher. Does not prevent child dispatchers from\n * being executed.\n *\n * `StopChildren`: Stop the propagation of the event through any handler groups\n * in the current dispatcher, and any of its children. If current dispatcher\n * is a child, does not prevent from propagating to its siblings.\n *\n * `Continue`: Continue propagating the event inside the same handler group.\n *\n * `ToScene`: Used after using `state.enter()` to dispatch the update to the scene,\n * or after `state.exit()` to dispatch the update to the root dispatcher.\n */\nexport enum PropagationAction {\n Stop = 'stop',\n StopChildren = 'stop-children',\n Continue = 'continue',\n ToScene = 'scene',\n}\n"]}
|
package/cjs/state/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./key.js"), exports);
|
|
18
|
-
__exportStar(require("./provider.js"), exports);
|
|
19
|
-
__exportStar(require("./providers/index.js"), exports);
|
|
20
|
-
__exportStar(require("./repository.js"), exports);
|
|
21
|
-
__exportStar(require("./update-state.js"), exports);
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/cjs/state/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/state/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAwB;AACxB,gDAA6B;AAC7B,uDAAoC;AACpC,kDAA+B;AAC/B,oDAAiC","sourcesContent":["export * from './key.js'\nexport * from './provider.js'\nexport * from './providers/index.js'\nexport * from './repository.js'\nexport * from './update-state.js'\n"]}
|
package/cjs/state/key.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.defaultStateKeyDelegate = void 0;
|
|
4
|
-
const core_1 = require("@mtcute/core");
|
|
5
|
-
/**
|
|
6
|
-
* Default state key delegate.
|
|
7
|
-
*
|
|
8
|
-
* Derives key as follows:
|
|
9
|
-
* - If private chat, `msg.chat.id`
|
|
10
|
-
* - If group chat, `msg.chat.id + '_' + msg.sender.id`
|
|
11
|
-
* - If channel, `msg.chat.id`
|
|
12
|
-
* - If non-inline callback query:
|
|
13
|
-
* - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`
|
|
14
|
-
* - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`
|
|
15
|
-
*/
|
|
16
|
-
const defaultStateKeyDelegate = (upd) => {
|
|
17
|
-
if ('type' in upd) {
|
|
18
|
-
// User | Chat
|
|
19
|
-
return String(upd.id);
|
|
20
|
-
}
|
|
21
|
-
if (upd._name === 'new_message' || upd._name === 'new_business_message') {
|
|
22
|
-
switch (upd.chat.chatType) {
|
|
23
|
-
case 'private':
|
|
24
|
-
case 'bot':
|
|
25
|
-
case 'channel':
|
|
26
|
-
return String(upd.chat.id);
|
|
27
|
-
case 'group':
|
|
28
|
-
case 'supergroup':
|
|
29
|
-
case 'gigagroup':
|
|
30
|
-
return `${upd.chat.id}_${upd.sender.id}`;
|
|
31
|
-
default:
|
|
32
|
-
(0, core_1.assertNever)(upd.chat.chatType);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
if (upd._name === 'callback_query') {
|
|
36
|
-
if (upd.chat.chatType === 'private')
|
|
37
|
-
return `${upd.user.id}`;
|
|
38
|
-
return `${upd.chat.id}_${upd.user.id}`;
|
|
39
|
-
}
|
|
40
|
-
return null;
|
|
41
|
-
};
|
|
42
|
-
exports.defaultStateKeyDelegate = defaultStateKeyDelegate;
|
|
43
|
-
//# sourceMappingURL=key.js.map
|
package/cjs/state/key.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"key.js","sourceRoot":"","sources":["../../../src/state/key.ts"],"names":[],"mappings":";;;AACA,uCAA0C;AAiB1C;;;;;;;;;;GAUG;AACI,MAAM,uBAAuB,GAAqB,CAAC,GAAG,EAAiB,EAAE;IAC5E,IAAI,MAAM,IAAI,GAAG,EAAE,CAAC;QAChB,cAAc;QACd,OAAO,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACzB,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,aAAa,IAAI,GAAG,CAAC,KAAK,KAAK,sBAAsB,EAAE,CAAC;QACtE,QAAQ,GAAG,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;YACxB,KAAK,SAAS,CAAC;YACf,KAAK,KAAK,CAAC;YACX,KAAK,SAAS;gBACV,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;YAC9B,KAAK,OAAO,CAAC;YACb,KAAK,YAAY,CAAC;YAClB,KAAK,WAAW;gBACZ,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,CAAA;YAC5C;gBACI,IAAA,kBAAW,EAAC,GAAG,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;QACtC,CAAC;IACL,CAAC;IAED,IAAI,GAAG,CAAC,KAAK,KAAK,gBAAgB,EAAE,CAAC;QACjC,IAAI,GAAG,CAAC,IAAI,CAAC,QAAQ,KAAK,SAAS;YAAE,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;QAE5D,OAAO,GAAG,GAAG,CAAC,IAAI,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,CAAA;IAC1C,CAAC;IAED,OAAO,IAAI,CAAA;AACf,CAAC,CAAA;AA5BY,QAAA,uBAAuB,2BA4BnC","sourcesContent":["import type { MaybePromise, Peer } from '@mtcute/core'\nimport { assertNever } from '@mtcute/core'\n\nimport type { BusinessMessageContext } from '../context/business-message.js'\nimport type { CallbackQueryContext, MessageContext } from '../context/index.js'\n\n/**\n * Function that determines how the state key is derived.\n *\n * The key is additionally prefixed with current scene, if any.\n *\n * @param msg Message or callback from which to derive the key\n * @param scene Current scene UID, or `null` if none\n */\nexport type StateKeyDelegate = (\n upd: MessageContext | BusinessMessageContext | CallbackQueryContext | Peer,\n) => MaybePromise<string | null>\n\n/**\n * Default state key delegate.\n *\n * Derives key as follows:\n * - If private chat, `msg.chat.id`\n * - If group chat, `msg.chat.id + '_' + msg.sender.id`\n * - If channel, `msg.chat.id`\n * - If non-inline callback query:\n * - If in private chat (i.e. `upd.chatType === 'user'`), `upd.user.id`\n * - If in group/channel/supergroup (i.e. `upd.chatType !== 'user'`), `upd.chatId + '_' + upd.user.id`\n */\nexport const defaultStateKeyDelegate: StateKeyDelegate = (upd): string | null => {\n if ('type' in upd) {\n // User | Chat\n return String(upd.id)\n }\n\n if (upd._name === 'new_message' || upd._name === 'new_business_message') {\n switch (upd.chat.chatType) {\n case 'private':\n case 'bot':\n case 'channel':\n return String(upd.chat.id)\n case 'group':\n case 'supergroup':\n case 'gigagroup':\n return `${upd.chat.id}_${upd.sender.id}`\n default:\n assertNever(upd.chat.chatType)\n }\n }\n\n if (upd._name === 'callback_query') {\n if (upd.chat.chatType === 'private') return `${upd.user.id}`\n\n return `${upd.chat.id}_${upd.user.id}`\n }\n\n return null\n}\n"]}
|
package/cjs/state/provider.d.ts
DELETED
package/cjs/state/provider.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../../../src/state/provider.ts"],"names":[],"mappings":"","sourcesContent":["import type { IStorageProvider } from '@mtcute/core'\n\nimport type { IStateRepository } from './repository.js'\n\nexport type IStateStorageProvider = IStorageProvider<{\n state: IStateRepository\n}>\n"]}
|
|
@@ -1,19 +0,0 @@
|
|
|
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./memory.js"), exports);
|
|
18
|
-
__exportStar(require("./sqlite.js"), exports);
|
|
19
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/state/providers/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,8CAA2B;AAC3B,8CAA2B","sourcesContent":["export * from './memory.js'\nexport * from './sqlite.js'\n"]}
|