@mtcute/dispatcher 0.17.2 → 0.18.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/callback-data-builder.cjs +126 -0
- package/callback-data-builder.d.cts +49 -0
- package/callback-data-builder.js +121 -0
- package/callback-data-builder.test.d.cts +1 -0
- package/context/base.d.cts +9 -0
- package/context/business-message.cjs +143 -0
- package/context/business-message.d.cts +60 -0
- package/context/business-message.js +138 -0
- package/context/callback-query.cjs +92 -0
- package/context/callback-query.d.cts +62 -0
- package/context/callback-query.js +87 -0
- package/context/chat-join-request.cjs +32 -0
- package/context/chat-join-request.d.cts +17 -0
- package/context/chat-join-request.d.ts +1 -1
- package/context/chat-join-request.js +27 -0
- package/context/chosen-inline-result.cjs +30 -0
- package/context/chosen-inline-result.d.cts +22 -0
- package/context/chosen-inline-result.d.ts +1 -1
- package/context/chosen-inline-result.js +25 -0
- package/context/index.d.cts +9 -0
- package/context/inline-query.cjs +20 -0
- package/context/inline-query.d.cts +15 -0
- package/context/inline-query.js +15 -0
- package/context/message.cjs +182 -0
- package/context/message.d.cts +82 -0
- package/context/message.d.ts +2 -2
- package/context/message.js +177 -0
- package/context/parse.cjs +45 -0
- package/context/parse.d.cts +13 -0
- package/context/parse.js +40 -0
- package/context/pre-checkout-query.cjs +24 -0
- package/context/pre-checkout-query.d.cts +17 -0
- package/context/pre-checkout-query.d.ts +1 -1
- package/context/pre-checkout-query.js +19 -0
- package/context/scene-transition.cjs +52 -0
- package/context/scene-transition.d.cts +24 -0
- package/context/scene-transition.d.ts +1 -1
- package/context/scene-transition.js +47 -0
- package/dispatcher.cjs +860 -0
- package/dispatcher.d.cts +880 -0
- package/dispatcher.d.ts +4 -4
- package/dispatcher.js +855 -0
- package/filters/bots.cjs +94 -0
- package/filters/bots.d.cts +62 -0
- package/filters/bots.d.ts +2 -4
- package/filters/bots.js +89 -0
- package/filters/bots.test.d.cts +1 -0
- package/filters/bundle.cjs +79 -0
- package/filters/bundle.d.cts +10 -0
- package/filters/bundle.js +74 -0
- package/filters/chat.cjs +43 -0
- package/filters/chat.d.cts +29 -0
- package/filters/chat.d.ts +8 -6
- package/filters/chat.js +38 -0
- package/filters/group.cjs +49 -0
- package/filters/group.d.cts +26 -0
- package/filters/group.js +44 -0
- package/filters/index.d.cts +4 -0
- package/filters/logic.cjs +57 -0
- package/filters/logic.d.cts +29 -0
- package/filters/logic.js +52 -0
- package/filters/logic.test.d.cts +1 -0
- package/filters/message.cjs +130 -0
- package/filters/message.d.cts +223 -0
- package/filters/message.d.ts +5 -1
- package/filters/message.js +125 -0
- package/filters/state.cjs +21 -0
- package/filters/state.d.cts +15 -0
- package/filters/state.js +16 -0
- package/filters/text.cjs +87 -0
- package/filters/text.d.cts +64 -0
- package/filters/text.d.ts +2 -2
- package/filters/text.js +82 -0
- package/filters/types.d.cts +91 -0
- package/filters/updates.cjs +27 -0
- package/filters/updates.d.cts +39 -0
- package/filters/updates.js +22 -0
- package/filters/user.cjs +57 -0
- package/filters/user.d.cts +24 -0
- package/filters/user.js +52 -0
- package/handler.d.cts +41 -0
- package/handler.d.ts +1 -1
- package/index.cjs +37 -2528
- package/index.js +16 -2507
- package/package.json +10 -9
- package/propagation.cjs +15 -0
- package/propagation.d.cts +22 -0
- package/propagation.js +10 -0
- package/state/index.d.cts +5 -0
- package/state/key.cjs +32 -0
- package/state/key.d.cts +24 -0
- package/state/key.js +27 -0
- package/state/provider.d.cts +5 -0
- package/state/providers/index.d.cts +2 -0
- package/state/providers/memory.cjs +79 -0
- package/state/providers/memory.d.cts +29 -0
- package/state/providers/memory.js +74 -0
- package/state/providers/sqlite.cjs +99 -0
- package/state/providers/sqlite.d.cts +28 -0
- package/state/providers/sqlite.js +94 -0
- package/state/repository.d.cts +62 -0
- package/state/service.cjs +69 -0
- package/state/service.d.cts +20 -0
- package/state/service.js +64 -0
- package/state/update-state.cjs +206 -0
- package/state/update-state.d.cts +151 -0
- package/state/update-state.d.ts +1 -1
- package/state/update-state.js +201 -0
- package/wizard.cjs +90 -0
- package/wizard.d.cts +64 -0
- package/wizard.js +85 -0
package/filters/bots.cjs
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const chat = require("./chat.cjs");
|
|
9
|
+
const logic = require("./logic.cjs");
|
|
10
|
+
function command(commands, {
|
|
11
|
+
prefixes = "/",
|
|
12
|
+
caseSensitive = false
|
|
13
|
+
} = {}) {
|
|
14
|
+
if (!Array.isArray(commands)) commands = [commands];
|
|
15
|
+
if (!caseSensitive) {
|
|
16
|
+
commands = commands.map((i) => typeof i === "string" ? i.toLowerCase() : i);
|
|
17
|
+
}
|
|
18
|
+
const argumentsRe = /(["'])(.*?)(?<!\\)\1|(\S+)/g;
|
|
19
|
+
const unescapeRe = /\\(['"])/;
|
|
20
|
+
const commandsRe = [];
|
|
21
|
+
commands.forEach((cmd) => {
|
|
22
|
+
if (typeof cmd !== "string") cmd = cmd.source;
|
|
23
|
+
commandsRe.push(new RegExp(`^(${cmd})(?:\\s|$|@([a-zA-Z0-9_]+?bot)(?:\\s|$))`, caseSensitive ? "" : "i"));
|
|
24
|
+
});
|
|
25
|
+
if (prefixes === null) prefixes = [];
|
|
26
|
+
if (typeof prefixes === "string") prefixes = [prefixes];
|
|
27
|
+
const _prefixes = prefixes;
|
|
28
|
+
const check = (msg) => {
|
|
29
|
+
if (msg.isMessageGroup) return check(msg.messages[0]);
|
|
30
|
+
for (const pref of _prefixes) {
|
|
31
|
+
if (!msg.text.startsWith(pref)) continue;
|
|
32
|
+
const withoutPrefix = msg.text.slice(pref.length);
|
|
33
|
+
for (const regex of commandsRe) {
|
|
34
|
+
const m = withoutPrefix.match(regex);
|
|
35
|
+
if (!m) continue;
|
|
36
|
+
const lastGroup = m[m.length - 1];
|
|
37
|
+
if (lastGroup) {
|
|
38
|
+
const self = msg.client.storage.self.getCached();
|
|
39
|
+
if (self && self.isBot && !self.usernames.includes(lastGroup)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
const match = m.slice(1, -1);
|
|
44
|
+
if (!caseSensitive) match[0] = match[0].toLowerCase();
|
|
45
|
+
withoutPrefix.slice(m[0].length).replace(argumentsRe, ($0, $1, $2, $3) => {
|
|
46
|
+
match.push(($2 || $3 || "").replace(unescapeRe, "$1"));
|
|
47
|
+
return "";
|
|
48
|
+
});
|
|
49
|
+
msg.command = match;
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
};
|
|
55
|
+
return check;
|
|
56
|
+
}
|
|
57
|
+
const start = logic.and(chat.chat("user"), command("start"));
|
|
58
|
+
const startGroup = logic.and(logic.or(chat.chat("supergroup"), chat.chat("group")), command("start"));
|
|
59
|
+
function deeplinkBase(base) {
|
|
60
|
+
return (params) => {
|
|
61
|
+
if (!Array.isArray(params)) {
|
|
62
|
+
return logic.and(start, (_msg) => {
|
|
63
|
+
const msg = _msg;
|
|
64
|
+
if (msg.command.length !== 2) return false;
|
|
65
|
+
const p = msg.command[1];
|
|
66
|
+
if (typeof params === "string" && p === params) return true;
|
|
67
|
+
const m = p.match(params);
|
|
68
|
+
if (!m) return false;
|
|
69
|
+
msg.command.push(...m.slice(1));
|
|
70
|
+
return true;
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return logic.and(base, (_msg) => {
|
|
74
|
+
const msg = _msg;
|
|
75
|
+
if (msg.command.length !== 2) return false;
|
|
76
|
+
const p = msg.command[1];
|
|
77
|
+
for (const param of params) {
|
|
78
|
+
if (typeof param === "string" && p === param) return true;
|
|
79
|
+
const m = p.match(param);
|
|
80
|
+
if (!m) continue;
|
|
81
|
+
msg.command.push(...m.slice(1));
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
const deeplink = deeplinkBase(start);
|
|
89
|
+
const deeplinkGroup = deeplinkBase(startGroup);
|
|
90
|
+
exports.command = command;
|
|
91
|
+
exports.deeplink = deeplink;
|
|
92
|
+
exports.deeplinkGroup = deeplinkGroup;
|
|
93
|
+
exports.start = start;
|
|
94
|
+
exports.startGroup = startGroup;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { Chat, MaybeArray, User } from '@mtcute/core';
|
|
2
|
+
import { BusinessMessageContext } from '../context/business-message.js';
|
|
3
|
+
import { MessageContext } from '../context/message.js';
|
|
4
|
+
import { Modify, UpdateFilter } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Filter messages that call the given command(s)..
|
|
7
|
+
*
|
|
8
|
+
* When a command matches, the match array is stored in a
|
|
9
|
+
* type-safe extension field `.commmand` of the {@link Message} object.
|
|
10
|
+
* First element is the command itself, then the arguments.
|
|
11
|
+
*
|
|
12
|
+
* If the matched command was a RegExp, the first element is the
|
|
13
|
+
* command, then the groups from the command regex, then the arguments.
|
|
14
|
+
*
|
|
15
|
+
* @param commands Command(s) the filter should look for (w/out prefix)
|
|
16
|
+
* @param prefixes
|
|
17
|
+
* Prefix(es) the filter should look for (default: `/`).
|
|
18
|
+
* Can be `null` to disable prefixes altogether
|
|
19
|
+
* @param caseSensitive
|
|
20
|
+
*/
|
|
21
|
+
export declare function command(commands: MaybeArray<string | RegExp>, { prefixes, caseSensitive, }?: {
|
|
22
|
+
prefixes?: MaybeArray<string> | null;
|
|
23
|
+
caseSensitive?: boolean;
|
|
24
|
+
}): UpdateFilter<MessageContext | BusinessMessageContext, {
|
|
25
|
+
command: string[];
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
* Shorthand filter that matches /start commands sent to bot's
|
|
29
|
+
* private messages.
|
|
30
|
+
*/
|
|
31
|
+
export declare const start: UpdateFilter<MessageContext | BusinessMessageContext, {
|
|
32
|
+
chat: User;
|
|
33
|
+
command: string[];
|
|
34
|
+
}>;
|
|
35
|
+
/**
|
|
36
|
+
* Shorthand filter that matches /start commands
|
|
37
|
+
* sent in groups (i.e. using `?startgroup` parameter).
|
|
38
|
+
*/
|
|
39
|
+
export declare const startGroup: UpdateFilter<MessageContext | BusinessMessageContext, {
|
|
40
|
+
chat: Modify<Chat, {
|
|
41
|
+
chatType: 'group' | 'supergroup';
|
|
42
|
+
}>;
|
|
43
|
+
command: string[];
|
|
44
|
+
}, never>;
|
|
45
|
+
/**
|
|
46
|
+
* Filter for deep links (i.e. `/start <deeplink_parameter>`).
|
|
47
|
+
*
|
|
48
|
+
* If the parameter is a regex, groups are added to `msg.command`,
|
|
49
|
+
* meaning that the first group is available in `msg.command[2]`.
|
|
50
|
+
*/
|
|
51
|
+
export declare const deeplink: (params: MaybeArray<string | RegExp>) => UpdateFilter<MessageContext | BusinessMessageContext, {
|
|
52
|
+
command: string[];
|
|
53
|
+
}>;
|
|
54
|
+
/**
|
|
55
|
+
* Filter for group deep links (i.e. `/start <deeplink_parameter>`).
|
|
56
|
+
*
|
|
57
|
+
* If the parameter is a regex, groups are added to `msg.command`,
|
|
58
|
+
* meaning that the first group is available in `msg.command[2]`.
|
|
59
|
+
*/
|
|
60
|
+
export declare const deeplinkGroup: (params: MaybeArray<string | RegExp>) => UpdateFilter<MessageContext | BusinessMessageContext, {
|
|
61
|
+
command: string[];
|
|
62
|
+
}>;
|
package/filters/bots.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Chat, MaybeArray } from '@mtcute/core';
|
|
1
|
+
import { Chat, MaybeArray, User } from '@mtcute/core';
|
|
2
2
|
import { BusinessMessageContext } from '../context/business-message.js';
|
|
3
3
|
import { MessageContext } from '../context/message.js';
|
|
4
4
|
import { Modify, UpdateFilter } from './types.js';
|
|
@@ -29,9 +29,7 @@ export declare function command(commands: MaybeArray<string | RegExp>, { prefixe
|
|
|
29
29
|
* private messages.
|
|
30
30
|
*/
|
|
31
31
|
export declare const start: UpdateFilter<MessageContext | BusinessMessageContext, {
|
|
32
|
-
chat:
|
|
33
|
-
chatType: 'private';
|
|
34
|
-
}>;
|
|
32
|
+
chat: User;
|
|
35
33
|
command: string[];
|
|
36
34
|
}>;
|
|
37
35
|
/**
|
package/filters/bots.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { chat } from "./chat.js";
|
|
2
|
+
import { and, or } from "./logic.js";
|
|
3
|
+
function command(commands, {
|
|
4
|
+
prefixes = "/",
|
|
5
|
+
caseSensitive = false
|
|
6
|
+
} = {}) {
|
|
7
|
+
if (!Array.isArray(commands)) commands = [commands];
|
|
8
|
+
if (!caseSensitive) {
|
|
9
|
+
commands = commands.map((i) => typeof i === "string" ? i.toLowerCase() : i);
|
|
10
|
+
}
|
|
11
|
+
const argumentsRe = /(["'])(.*?)(?<!\\)\1|(\S+)/g;
|
|
12
|
+
const unescapeRe = /\\(['"])/;
|
|
13
|
+
const commandsRe = [];
|
|
14
|
+
commands.forEach((cmd) => {
|
|
15
|
+
if (typeof cmd !== "string") cmd = cmd.source;
|
|
16
|
+
commandsRe.push(new RegExp(`^(${cmd})(?:\\s|$|@([a-zA-Z0-9_]+?bot)(?:\\s|$))`, caseSensitive ? "" : "i"));
|
|
17
|
+
});
|
|
18
|
+
if (prefixes === null) prefixes = [];
|
|
19
|
+
if (typeof prefixes === "string") prefixes = [prefixes];
|
|
20
|
+
const _prefixes = prefixes;
|
|
21
|
+
const check = (msg) => {
|
|
22
|
+
if (msg.isMessageGroup) return check(msg.messages[0]);
|
|
23
|
+
for (const pref of _prefixes) {
|
|
24
|
+
if (!msg.text.startsWith(pref)) continue;
|
|
25
|
+
const withoutPrefix = msg.text.slice(pref.length);
|
|
26
|
+
for (const regex of commandsRe) {
|
|
27
|
+
const m = withoutPrefix.match(regex);
|
|
28
|
+
if (!m) continue;
|
|
29
|
+
const lastGroup = m[m.length - 1];
|
|
30
|
+
if (lastGroup) {
|
|
31
|
+
const self = msg.client.storage.self.getCached();
|
|
32
|
+
if (self && self.isBot && !self.usernames.includes(lastGroup)) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
const match = m.slice(1, -1);
|
|
37
|
+
if (!caseSensitive) match[0] = match[0].toLowerCase();
|
|
38
|
+
withoutPrefix.slice(m[0].length).replace(argumentsRe, ($0, $1, $2, $3) => {
|
|
39
|
+
match.push(($2 || $3 || "").replace(unescapeRe, "$1"));
|
|
40
|
+
return "";
|
|
41
|
+
});
|
|
42
|
+
msg.command = match;
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
};
|
|
48
|
+
return check;
|
|
49
|
+
}
|
|
50
|
+
const start = and(chat("user"), command("start"));
|
|
51
|
+
const startGroup = and(or(chat("supergroup"), chat("group")), command("start"));
|
|
52
|
+
function deeplinkBase(base) {
|
|
53
|
+
return (params) => {
|
|
54
|
+
if (!Array.isArray(params)) {
|
|
55
|
+
return and(start, (_msg) => {
|
|
56
|
+
const msg = _msg;
|
|
57
|
+
if (msg.command.length !== 2) return false;
|
|
58
|
+
const p = msg.command[1];
|
|
59
|
+
if (typeof params === "string" && p === params) return true;
|
|
60
|
+
const m = p.match(params);
|
|
61
|
+
if (!m) return false;
|
|
62
|
+
msg.command.push(...m.slice(1));
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return and(base, (_msg) => {
|
|
67
|
+
const msg = _msg;
|
|
68
|
+
if (msg.command.length !== 2) return false;
|
|
69
|
+
const p = msg.command[1];
|
|
70
|
+
for (const param of params) {
|
|
71
|
+
if (typeof param === "string" && p === param) return true;
|
|
72
|
+
const m = p.match(param);
|
|
73
|
+
if (!m) continue;
|
|
74
|
+
msg.command.push(...m.slice(1));
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
const deeplink = deeplinkBase(start);
|
|
82
|
+
const deeplinkGroup = deeplinkBase(startGroup);
|
|
83
|
+
export {
|
|
84
|
+
command,
|
|
85
|
+
deeplink,
|
|
86
|
+
deeplinkGroup,
|
|
87
|
+
start,
|
|
88
|
+
startGroup
|
|
89
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
const bots = require("./bots.cjs");
|
|
9
|
+
const chat = require("./chat.cjs");
|
|
10
|
+
const group = require("./group.cjs");
|
|
11
|
+
const logic = require("./logic.cjs");
|
|
12
|
+
const message = require("./message.cjs");
|
|
13
|
+
const state = require("./state.cjs");
|
|
14
|
+
const text = require("./text.cjs");
|
|
15
|
+
const updates = require("./updates.cjs");
|
|
16
|
+
const user = require("./user.cjs");
|
|
17
|
+
exports.command = bots.command;
|
|
18
|
+
exports.deeplink = bots.deeplink;
|
|
19
|
+
exports.deeplinkGroup = bots.deeplinkGroup;
|
|
20
|
+
exports.start = bots.start;
|
|
21
|
+
exports.startGroup = bots.startGroup;
|
|
22
|
+
exports.chat = chat.chat;
|
|
23
|
+
exports.chatId = chat.chatId;
|
|
24
|
+
exports.every = group.every;
|
|
25
|
+
exports.some = group.some;
|
|
26
|
+
exports.and = logic.and;
|
|
27
|
+
exports.any = logic.any;
|
|
28
|
+
exports.not = logic.not;
|
|
29
|
+
exports.or = logic.or;
|
|
30
|
+
exports.action = message.action;
|
|
31
|
+
exports.animation = message.animation;
|
|
32
|
+
exports.anyDocument = message.anyDocument;
|
|
33
|
+
exports.anyLocation = message.anyLocation;
|
|
34
|
+
exports.anyVideo = message.anyVideo;
|
|
35
|
+
exports.audio = message.audio;
|
|
36
|
+
exports.contact = message.contact;
|
|
37
|
+
exports.dice = message.dice;
|
|
38
|
+
exports.document = message.document;
|
|
39
|
+
exports.game = message.game;
|
|
40
|
+
exports.incoming = message.incoming;
|
|
41
|
+
exports.invoice = message.invoice;
|
|
42
|
+
exports.liveLocation = message.liveLocation;
|
|
43
|
+
exports.location = message.location;
|
|
44
|
+
exports.media = message.media;
|
|
45
|
+
exports.mediaOf = message.mediaOf;
|
|
46
|
+
exports.outgoing = message.outgoing;
|
|
47
|
+
exports.photo = message.photo;
|
|
48
|
+
exports.poll = message.poll;
|
|
49
|
+
exports.reply = message.reply;
|
|
50
|
+
exports.replyOrigin = message.replyOrigin;
|
|
51
|
+
exports.replyTo = message.replyTo;
|
|
52
|
+
exports.roundMessage = message.roundMessage;
|
|
53
|
+
exports.scheduled = message.scheduled;
|
|
54
|
+
exports.sender = message.sender;
|
|
55
|
+
exports.service = message.service;
|
|
56
|
+
exports.sticker = message.sticker;
|
|
57
|
+
exports.stickerBySourceType = message.stickerBySourceType;
|
|
58
|
+
exports.stickerByType = message.stickerByType;
|
|
59
|
+
exports.story = message.story;
|
|
60
|
+
exports.text = message.text;
|
|
61
|
+
exports.venue = message.venue;
|
|
62
|
+
exports.video = message.video;
|
|
63
|
+
exports.voice = message.voice;
|
|
64
|
+
exports.webpage = message.webpage;
|
|
65
|
+
exports.withCompleteChat = message.withCompleteChat;
|
|
66
|
+
exports.withCompleteSender = message.withCompleteSender;
|
|
67
|
+
exports.state = state.state;
|
|
68
|
+
exports.stateEmpty = state.stateEmpty;
|
|
69
|
+
exports.contains = text.contains;
|
|
70
|
+
exports.endsWith = text.endsWith;
|
|
71
|
+
exports.equals = text.equals;
|
|
72
|
+
exports.regex = text.regex;
|
|
73
|
+
exports.startsWith = text.startsWith;
|
|
74
|
+
exports.chatMember = updates.chatMember;
|
|
75
|
+
exports.chatMemberSelf = updates.chatMemberSelf;
|
|
76
|
+
exports.userStatus = updates.userStatus;
|
|
77
|
+
exports.bot = user.bot;
|
|
78
|
+
exports.me = user.me;
|
|
79
|
+
exports.userId = user.userId;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './bots.js';
|
|
2
|
+
export * from './chat.js';
|
|
3
|
+
export * from './group.js';
|
|
4
|
+
export * from './logic.js';
|
|
5
|
+
export * from './message.js';
|
|
6
|
+
export * from './state.js';
|
|
7
|
+
export * from './text.js';
|
|
8
|
+
export * from './types.js';
|
|
9
|
+
export * from './updates.js';
|
|
10
|
+
export * from './user.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { command, deeplink, deeplinkGroup, start, startGroup } from "./bots.js";
|
|
2
|
+
import { chat, chatId } from "./chat.js";
|
|
3
|
+
import { every, some } from "./group.js";
|
|
4
|
+
import { and, any, not, or } from "./logic.js";
|
|
5
|
+
import { action, animation, anyDocument, anyLocation, anyVideo, audio, contact, dice, document, game, incoming, invoice, liveLocation, location, media, mediaOf, outgoing, photo, poll, reply, replyOrigin, replyTo, roundMessage, scheduled, sender, service, sticker, stickerBySourceType, stickerByType, story, text, venue, video, voice, webpage, withCompleteChat, withCompleteSender } from "./message.js";
|
|
6
|
+
import { state, stateEmpty } from "./state.js";
|
|
7
|
+
import { contains, endsWith, equals, regex, startsWith } from "./text.js";
|
|
8
|
+
import { chatMember, chatMemberSelf, userStatus } from "./updates.js";
|
|
9
|
+
import { bot, me, userId } from "./user.js";
|
|
10
|
+
export {
|
|
11
|
+
action,
|
|
12
|
+
and,
|
|
13
|
+
animation,
|
|
14
|
+
any,
|
|
15
|
+
anyDocument,
|
|
16
|
+
anyLocation,
|
|
17
|
+
anyVideo,
|
|
18
|
+
audio,
|
|
19
|
+
bot,
|
|
20
|
+
chat,
|
|
21
|
+
chatId,
|
|
22
|
+
chatMember,
|
|
23
|
+
chatMemberSelf,
|
|
24
|
+
command,
|
|
25
|
+
contact,
|
|
26
|
+
contains,
|
|
27
|
+
deeplink,
|
|
28
|
+
deeplinkGroup,
|
|
29
|
+
dice,
|
|
30
|
+
document,
|
|
31
|
+
endsWith,
|
|
32
|
+
equals,
|
|
33
|
+
every,
|
|
34
|
+
game,
|
|
35
|
+
incoming,
|
|
36
|
+
invoice,
|
|
37
|
+
liveLocation,
|
|
38
|
+
location,
|
|
39
|
+
me,
|
|
40
|
+
media,
|
|
41
|
+
mediaOf,
|
|
42
|
+
not,
|
|
43
|
+
or,
|
|
44
|
+
outgoing,
|
|
45
|
+
photo,
|
|
46
|
+
poll,
|
|
47
|
+
regex,
|
|
48
|
+
reply,
|
|
49
|
+
replyOrigin,
|
|
50
|
+
replyTo,
|
|
51
|
+
roundMessage,
|
|
52
|
+
scheduled,
|
|
53
|
+
sender,
|
|
54
|
+
service,
|
|
55
|
+
some,
|
|
56
|
+
start,
|
|
57
|
+
startGroup,
|
|
58
|
+
startsWith,
|
|
59
|
+
state,
|
|
60
|
+
stateEmpty,
|
|
61
|
+
sticker,
|
|
62
|
+
stickerBySourceType,
|
|
63
|
+
stickerByType,
|
|
64
|
+
story,
|
|
65
|
+
text,
|
|
66
|
+
userId,
|
|
67
|
+
userStatus,
|
|
68
|
+
venue,
|
|
69
|
+
video,
|
|
70
|
+
voice,
|
|
71
|
+
webpage,
|
|
72
|
+
withCompleteChat,
|
|
73
|
+
withCompleteSender
|
|
74
|
+
};
|
package/filters/chat.cjs
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
function chat(type) {
|
|
9
|
+
if (type === "user") return (msg) => msg.chat.type === "user";
|
|
10
|
+
return (msg) => msg.chat.type === "chat" && msg.chat.chatType === type;
|
|
11
|
+
}
|
|
12
|
+
const chatId = (id) => {
|
|
13
|
+
const indexId = /* @__PURE__ */ new Set();
|
|
14
|
+
const indexUsername = /* @__PURE__ */ new Set();
|
|
15
|
+
let matchSelf = false;
|
|
16
|
+
if (!Array.isArray(id)) id = [id];
|
|
17
|
+
id.forEach((id2) => {
|
|
18
|
+
if (id2 === "me" || id2 === "self") {
|
|
19
|
+
matchSelf = true;
|
|
20
|
+
} else if (typeof id2 === "number") {
|
|
21
|
+
indexId.add(id2);
|
|
22
|
+
} else {
|
|
23
|
+
indexUsername.add(id2);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return (upd) => {
|
|
27
|
+
switch (upd._name) {
|
|
28
|
+
case "poll_vote": {
|
|
29
|
+
const peer = upd.peer;
|
|
30
|
+
return peer.type === "chat" && (indexId.has(peer.id) || Boolean(peer.usernames?.some((u) => indexUsername.has(u.username))));
|
|
31
|
+
}
|
|
32
|
+
case "history_read":
|
|
33
|
+
case "user_typing": {
|
|
34
|
+
const id2 = upd.chatId;
|
|
35
|
+
return matchSelf && id2 === upd.client.storage.self.getCached()?.userId || indexId.has(id2);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
const chat2 = upd.chat;
|
|
39
|
+
return matchSelf && chat2.type === "user" && chat2.isSelf || indexId.has(chat2.id) || Boolean(chat2.usernames?.some((u) => indexUsername.has(u.username)));
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
exports.chat = chat;
|
|
43
|
+
exports.chatId = chatId;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BotChatJoinRequestUpdate, BusinessMessage, Chat, ChatMemberUpdate, ChatType, DeleteBusinessMessageUpdate, HistoryReadUpdate, MaybeArray, Message, Peer, PollVoteUpdate, User, UserTypingUpdate } from '@mtcute/core';
|
|
2
|
+
import { UpdateContextDistributed } from '../context/base.js';
|
|
3
|
+
import { EmptyObject, Modify, UpdateFilter } from './types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Filter updates by type of the chat where they happened
|
|
6
|
+
*/
|
|
7
|
+
export declare function chat<T extends ChatType | 'user', Obj extends {
|
|
8
|
+
chat: Peer;
|
|
9
|
+
}>(type: T): UpdateFilter<Obj, {
|
|
10
|
+
chat: T extends 'user' ? User : Modify<Chat, {
|
|
11
|
+
chatType: T;
|
|
12
|
+
}>;
|
|
13
|
+
} & (Obj extends Message ? T extends 'user' | 'group' ? {
|
|
14
|
+
sender: User;
|
|
15
|
+
} : {
|
|
16
|
+
sender: Chat;
|
|
17
|
+
} : EmptyObject)>;
|
|
18
|
+
/**
|
|
19
|
+
* Filter updates by marked chat ID(s) or username(s)
|
|
20
|
+
*
|
|
21
|
+
* Note that only some updates support filtering by username.
|
|
22
|
+
*
|
|
23
|
+
* For messages, this filter checks for chat where the message
|
|
24
|
+
* was sent to, NOT the chat sender.
|
|
25
|
+
*/
|
|
26
|
+
export declare const chatId: {
|
|
27
|
+
(id: MaybeArray<number>): UpdateFilter<UpdateContextDistributed<Message | BusinessMessage | ChatMemberUpdate | PollVoteUpdate | BotChatJoinRequestUpdate>>;
|
|
28
|
+
(id: MaybeArray<number | string>): UpdateFilter<UpdateContextDistributed<Message | BusinessMessage | ChatMemberUpdate | UserTypingUpdate | HistoryReadUpdate | PollVoteUpdate | BotChatJoinRequestUpdate | DeleteBusinessMessageUpdate>>;
|
|
29
|
+
};
|
package/filters/chat.d.ts
CHANGED
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { BotChatJoinRequestUpdate, BusinessMessage, Chat, ChatMemberUpdate, ChatType, DeleteBusinessMessageUpdate, HistoryReadUpdate, MaybeArray, Message, PollVoteUpdate, User, UserTypingUpdate } from '@mtcute/core';
|
|
1
|
+
import { BotChatJoinRequestUpdate, BusinessMessage, Chat, ChatMemberUpdate, ChatType, DeleteBusinessMessageUpdate, HistoryReadUpdate, MaybeArray, Message, Peer, PollVoteUpdate, User, UserTypingUpdate } from '@mtcute/core';
|
|
2
2
|
import { UpdateContextDistributed } from '../context/base.js';
|
|
3
3
|
import { EmptyObject, Modify, UpdateFilter } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* Filter updates by type of the chat where they happened
|
|
6
6
|
*/
|
|
7
|
-
export declare function chat<T extends ChatType, Obj extends {
|
|
8
|
-
chat:
|
|
7
|
+
export declare function chat<T extends ChatType | 'user', Obj extends {
|
|
8
|
+
chat: Peer;
|
|
9
9
|
}>(type: T): UpdateFilter<Obj, {
|
|
10
|
-
chat: Modify<Chat, {
|
|
10
|
+
chat: T extends 'user' ? User : Modify<Chat, {
|
|
11
11
|
chatType: T;
|
|
12
12
|
}>;
|
|
13
|
-
} & (Obj extends Message ? T extends '
|
|
13
|
+
} & (Obj extends Message ? T extends 'user' | 'group' ? {
|
|
14
14
|
sender: User;
|
|
15
|
-
} :
|
|
15
|
+
} : {
|
|
16
|
+
sender: Chat;
|
|
17
|
+
} : EmptyObject)>;
|
|
16
18
|
/**
|
|
17
19
|
* Filter updates by marked chat ID(s) or username(s)
|
|
18
20
|
*
|
package/filters/chat.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
function chat(type) {
|
|
2
|
+
if (type === "user") return (msg) => msg.chat.type === "user";
|
|
3
|
+
return (msg) => msg.chat.type === "chat" && msg.chat.chatType === type;
|
|
4
|
+
}
|
|
5
|
+
const chatId = (id) => {
|
|
6
|
+
const indexId = /* @__PURE__ */ new Set();
|
|
7
|
+
const indexUsername = /* @__PURE__ */ new Set();
|
|
8
|
+
let matchSelf = false;
|
|
9
|
+
if (!Array.isArray(id)) id = [id];
|
|
10
|
+
id.forEach((id2) => {
|
|
11
|
+
if (id2 === "me" || id2 === "self") {
|
|
12
|
+
matchSelf = true;
|
|
13
|
+
} else if (typeof id2 === "number") {
|
|
14
|
+
indexId.add(id2);
|
|
15
|
+
} else {
|
|
16
|
+
indexUsername.add(id2);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return (upd) => {
|
|
20
|
+
switch (upd._name) {
|
|
21
|
+
case "poll_vote": {
|
|
22
|
+
const peer = upd.peer;
|
|
23
|
+
return peer.type === "chat" && (indexId.has(peer.id) || Boolean(peer.usernames?.some((u) => indexUsername.has(u.username))));
|
|
24
|
+
}
|
|
25
|
+
case "history_read":
|
|
26
|
+
case "user_typing": {
|
|
27
|
+
const id2 = upd.chatId;
|
|
28
|
+
return matchSelf && id2 === upd.client.storage.self.getCached()?.userId || indexId.has(id2);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const chat2 = upd.chat;
|
|
32
|
+
return matchSelf && chat2.type === "user" && chat2.isSelf || indexId.has(chat2.id) || Boolean(chat2.usernames?.some((u) => indexUsername.has(u.username)));
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export {
|
|
36
|
+
chat,
|
|
37
|
+
chatId
|
|
38
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
|
|
2
|
+
globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
|
|
3
|
+
console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
|
|
4
|
+
console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
|
|
5
|
+
}
|
|
6
|
+
"use strict";
|
|
7
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
8
|
+
function every(filter) {
|
|
9
|
+
return (ctx, state) => {
|
|
10
|
+
let i = 0;
|
|
11
|
+
const upds = ctx.messages;
|
|
12
|
+
const max = upds.length;
|
|
13
|
+
const next = () => {
|
|
14
|
+
if (i === max) return true;
|
|
15
|
+
const res = filter(upds[i++], state);
|
|
16
|
+
if (typeof res === "boolean") {
|
|
17
|
+
if (!res) return false;
|
|
18
|
+
return next();
|
|
19
|
+
}
|
|
20
|
+
return res.then((r) => {
|
|
21
|
+
if (!r) return false;
|
|
22
|
+
return next();
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
return next();
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
function some(filter) {
|
|
29
|
+
return (ctx, state) => {
|
|
30
|
+
let i = 0;
|
|
31
|
+
const upds = ctx.messages;
|
|
32
|
+
const max = upds.length;
|
|
33
|
+
const next = () => {
|
|
34
|
+
if (i === max) return false;
|
|
35
|
+
const res = filter(upds[i++], state);
|
|
36
|
+
if (typeof res === "boolean") {
|
|
37
|
+
if (res) return true;
|
|
38
|
+
return next();
|
|
39
|
+
}
|
|
40
|
+
return res.then((r) => {
|
|
41
|
+
if (r) return true;
|
|
42
|
+
return next();
|
|
43
|
+
});
|
|
44
|
+
};
|
|
45
|
+
return next();
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
exports.every = every;
|
|
49
|
+
exports.some = some;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Message } from '@mtcute/core';
|
|
2
|
+
import { BusinessMessageContext } from '../context/business-message.js';
|
|
3
|
+
import { MessageContext } from '../context/message.js';
|
|
4
|
+
import { Modify, UpdateFilter } from './types.js';
|
|
5
|
+
/**
|
|
6
|
+
* For message groups, apply a filter to every message in the group.
|
|
7
|
+
* Filter will match if **all** messages match.
|
|
8
|
+
*
|
|
9
|
+
* > **Note**: This also applies type modification to every message in the group
|
|
10
|
+
*
|
|
11
|
+
* @param filter
|
|
12
|
+
* @returns
|
|
13
|
+
*/
|
|
14
|
+
export declare function every<Mod, State extends object>(filter: UpdateFilter<Message, Mod, State>): UpdateFilter<MessageContext | BusinessMessageContext, Mod & {
|
|
15
|
+
messages: Modify<MessageContext | BusinessMessageContext, Mod>[];
|
|
16
|
+
}, State>;
|
|
17
|
+
/**
|
|
18
|
+
* For message groups, apply a filter to every message in the group.
|
|
19
|
+
* Filter will match if **any** message matches.
|
|
20
|
+
*
|
|
21
|
+
* > **Note**: This *does not* apply type modification to any message
|
|
22
|
+
*
|
|
23
|
+
* @param filter
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
export declare function some<State extends object>(filter: UpdateFilter<Message, any, State>): UpdateFilter<MessageContext | BusinessMessageContext, {}, State>;
|