@mtkruto/node 0.1.118 → 0.1.119
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/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/3_types.d.ts +4 -0
- package/esm/client/4_composer.d.ts +5 -1
- package/esm/client/4_composer.js +37 -13
- package/esm/client/5_client.d.ts +4 -1
- package/esm/client/5_client.js +75 -9
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/3_types.d.ts +4 -0
- package/script/client/4_composer.d.ts +5 -1
- package/script/client/4_composer.js +37 -13
- package/script/client/5_client.d.ts +4 -1
- package/script/client/5_client.js +75 -9
package/esm/4_constants.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
|
|
|
5
5
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
6
6
|
export declare const INITIAL_DC: DC;
|
|
7
7
|
export declare const LAYER = 166;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.1.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.1.119";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/esm/4_constants.js
CHANGED
|
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
|
|
|
54
54
|
export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
55
55
|
export const INITIAL_DC = "2";
|
|
56
56
|
export const LAYER = 166;
|
|
57
|
-
export const APP_VERSION = "MTKruto 0.1.
|
|
57
|
+
export const APP_VERSION = "MTKruto 0.1.119";
|
|
58
58
|
// @ts-ignore: lib
|
|
59
59
|
export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
60
60
|
export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/esm/client/3_types.d.ts
CHANGED
|
@@ -44,6 +44,10 @@ export interface ClientParams extends ClientPlainParams {
|
|
|
44
44
|
* Whether to ignore outgoing messages. Defaults to `true` for bots, and `false` for users.
|
|
45
45
|
*/
|
|
46
46
|
ignoreOutgoing?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Default command prefixes. Defaults to `"/"` for bots and `"\"` for users. This option must be set separately for nested composers.
|
|
49
|
+
*/
|
|
50
|
+
prefixes?: string | string[];
|
|
47
51
|
}
|
|
48
52
|
export interface AnswerCallbackQueryParams {
|
|
49
53
|
/** A text to be shown to the user. */
|
|
@@ -15,6 +15,7 @@ export declare function concat<C extends Update = Update>(left: MiddlewareFn<C>,
|
|
|
15
15
|
export declare const skip: MiddlewareFn;
|
|
16
16
|
export declare class Composer<C extends Update> implements MiddlewareObj<C> {
|
|
17
17
|
#private;
|
|
18
|
+
set prefixes(value: string | string[]);
|
|
18
19
|
constructor(...middleware: Middleware<C>[]);
|
|
19
20
|
middleware(): MiddlewareFn<C>;
|
|
20
21
|
use(...middleware: Middleware<C>[]): Composer<C>;
|
|
@@ -22,6 +23,9 @@ export declare class Composer<C extends Update> implements MiddlewareObj<C> {
|
|
|
22
23
|
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
|
|
23
24
|
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]): Composer<C>;
|
|
24
25
|
on<T extends keyof Update_, F extends string>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...middleawre: Middleware<FilterUpdate<C, T, F>>[]): Composer<FilterUpdate<C, T, F>>;
|
|
25
|
-
command(commands: string | RegExp | (string | RegExp)[]
|
|
26
|
+
command(commands: string | RegExp | (string | RegExp)[] | {
|
|
27
|
+
names: string | RegExp | (string | RegExp)[];
|
|
28
|
+
prefixes: string | string[];
|
|
29
|
+
}, ...middleawre: Middleware<FilterUpdate<C, "message", "text">>[]): Composer<FilterUpdate<C, "message", "text">>;
|
|
26
30
|
}
|
|
27
31
|
export {};
|
package/esm/client/4_composer.js
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
+
};
|
|
1
6
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
7
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
8
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
5
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
11
|
};
|
|
7
|
-
var
|
|
8
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
-
};
|
|
12
|
-
var _Composer_handle;
|
|
12
|
+
var _Composer_handle, _Composer_prefixes;
|
|
13
13
|
export function flatten(mw) {
|
|
14
14
|
return typeof mw === "function" ? mw : (ctx, next) => mw.middleware()(ctx, next);
|
|
15
15
|
}
|
|
@@ -29,8 +29,15 @@ export function concat(left, right) {
|
|
|
29
29
|
}
|
|
30
30
|
export const skip = (_ctx, next) => next();
|
|
31
31
|
export class Composer {
|
|
32
|
+
set prefixes(value) {
|
|
33
|
+
if (__classPrivateFieldGet(this, _Composer_prefixes, "f") !== undefined) {
|
|
34
|
+
throw new Error("Prefixes already set");
|
|
35
|
+
}
|
|
36
|
+
__classPrivateFieldSet(this, _Composer_prefixes, value, "f");
|
|
37
|
+
}
|
|
32
38
|
constructor(...middleware) {
|
|
33
39
|
_Composer_handle.set(this, void 0);
|
|
40
|
+
_Composer_prefixes.set(this, void 0);
|
|
34
41
|
__classPrivateFieldSet(this, _Composer_handle, middleware.length == 0 ? skip : middleware.map(flatten).reduce(concat), "f");
|
|
35
42
|
}
|
|
36
43
|
middleware() {
|
|
@@ -80,20 +87,37 @@ export class Composer {
|
|
|
80
87
|
}, ...middleawre);
|
|
81
88
|
}
|
|
82
89
|
command(commands, ...middleawre) {
|
|
83
|
-
const
|
|
90
|
+
const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
|
|
91
|
+
const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
|
|
92
|
+
const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Composer_prefixes, "f") ?? []);
|
|
93
|
+
const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
|
|
94
|
+
for (const left of prefixes) {
|
|
95
|
+
for (const right of prefixes) {
|
|
96
|
+
if (left == right) {
|
|
97
|
+
continue;
|
|
98
|
+
}
|
|
99
|
+
if (left.startsWith(right) || right.startsWith(left)) {
|
|
100
|
+
throw new Error("Intersecting prefixes");
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
84
104
|
return this.on(["message", "text"]).filter((ctx) => {
|
|
85
|
-
const
|
|
86
|
-
if (
|
|
105
|
+
const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
|
|
106
|
+
if (prefixes_.length == 0) {
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
const cmd = ctx.message.text.split(/\s/, 1)[0];
|
|
110
|
+
const prefix = prefixes_.find((v) => cmd.startsWith(v));
|
|
111
|
+
if (prefix === undefined) {
|
|
87
112
|
return false;
|
|
88
113
|
}
|
|
89
|
-
const cmd = ctx.message.text.slice(botCommand.offset, botCommand.offset + botCommand.length);
|
|
90
114
|
if (cmd.includes("@")) {
|
|
91
|
-
const username = cmd.split("@")[1];
|
|
115
|
+
const username = cmd.split("@", 2)[1];
|
|
92
116
|
if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
|
|
93
117
|
return false;
|
|
94
118
|
}
|
|
95
119
|
}
|
|
96
|
-
const command_ = cmd.split("@")[0].split(
|
|
120
|
+
const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
|
|
97
121
|
for (const command of commands_) {
|
|
98
122
|
if (typeof command === "string" && (command.toLowerCase() == command_)) {
|
|
99
123
|
return true;
|
|
@@ -106,4 +130,4 @@ export class Composer {
|
|
|
106
130
|
}, ...middleawre);
|
|
107
131
|
}
|
|
108
132
|
}
|
|
109
|
-
_Composer_handle = new WeakMap();
|
|
133
|
+
_Composer_handle = new WeakMap(), _Composer_prefixes = new WeakMap();
|
package/esm/client/5_client.d.ts
CHANGED
|
@@ -286,7 +286,10 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
286
286
|
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
|
|
287
287
|
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]): Composer<C>;
|
|
288
288
|
on<T extends keyof Update, F extends string>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...middleawre: Middleware<FilterUpdate<C, T, F>>[]): Composer<FilterUpdate<C, T, F>>;
|
|
289
|
-
command(commands: string | RegExp | (string | RegExp)[]
|
|
289
|
+
command(commands: string | RegExp | (string | RegExp)[] | {
|
|
290
|
+
names: string | RegExp | (string | RegExp)[];
|
|
291
|
+
prefixes: string | string[];
|
|
292
|
+
}, ...middleawre: Middleware<FilterUpdate<C, "message", "text">>[]): Composer<FilterUpdate<C, "message", "text">>;
|
|
290
293
|
/**
|
|
291
294
|
* Set the bot's description in the given language. Bot-only.
|
|
292
295
|
*
|
package/esm/client/5_client.js
CHANGED
|
@@ -9,7 +9,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkChannelGap, _Client_processUpdates, _Client_setUpdateStateDate, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
12
|
+
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkChannelGap, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
13
13
|
import { debug, gunzip, Mutex } from "../0_deps.js";
|
|
14
14
|
import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mod, mustPrompt, mustPromptOneOf, Queue, sha1, UNREACHABLE } from "../1_utilities.js";
|
|
15
15
|
import { as, functions, getChannelChatId, Message_, MessageContainer, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
|
|
@@ -120,6 +120,7 @@ export class Client extends ClientAbstract {
|
|
|
120
120
|
_Client_publicKeys.set(this, void 0);
|
|
121
121
|
_Client_autoStart.set(this, void 0);
|
|
122
122
|
_Client_ignoreOutgoing.set(this, void 0);
|
|
123
|
+
_Client_prefixes.set(this, void 0);
|
|
123
124
|
_Client_constructContext.set(this, async (update) => {
|
|
124
125
|
const msg = update.message ?? update.editedMessage ?? update.callbackQuery?.message;
|
|
125
126
|
const mustGetMsg = () => {
|
|
@@ -297,6 +298,7 @@ export class Client extends ClientAbstract {
|
|
|
297
298
|
__classPrivateFieldSet(this, _Client_publicKeys, params?.publicKeys, "f");
|
|
298
299
|
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
299
300
|
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
301
|
+
__classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
|
|
300
302
|
if (params?.defaultHandlers ?? true) {
|
|
301
303
|
this.on("connectionState", ({ connectionState }, next) => {
|
|
302
304
|
drop((async () => {
|
|
@@ -406,7 +408,7 @@ export class Client extends ClientAbstract {
|
|
|
406
408
|
release();
|
|
407
409
|
}
|
|
408
410
|
}
|
|
409
|
-
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
411
|
+
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
410
412
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
411
413
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), resolve);
|
|
412
414
|
});
|
|
@@ -594,7 +596,7 @@ export class Client extends ClientAbstract {
|
|
|
594
596
|
dAuth("authorized as user");
|
|
595
597
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
596
598
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
597
|
-
|
|
599
|
+
return;
|
|
598
600
|
}
|
|
599
601
|
catch (err) {
|
|
600
602
|
if (err instanceof PasswordHashInvalid) {
|
|
@@ -930,6 +932,34 @@ export class Client extends ClientAbstract {
|
|
|
930
932
|
let updates;
|
|
931
933
|
if (updates_ instanceof types.UpdatesCombined || updates_ instanceof types.Updates) {
|
|
932
934
|
updates = updates_.updates;
|
|
935
|
+
const seq = updates_.seq;
|
|
936
|
+
const seqStart = "seqStart" in updates_ ? updates_.seqStart : updates_.seq;
|
|
937
|
+
if (checkGap) {
|
|
938
|
+
if (seqStart == 0) {
|
|
939
|
+
checkGap = false;
|
|
940
|
+
d("seqStart=0");
|
|
941
|
+
}
|
|
942
|
+
else {
|
|
943
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
944
|
+
const localSeq = localState.seq;
|
|
945
|
+
if (localSeq + 1 == seqStart) {
|
|
946
|
+
// The updates can be applied.
|
|
947
|
+
localState.seq = seq;
|
|
948
|
+
localState.date = updates_.date;
|
|
949
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
950
|
+
await this.storage.setState(localState);
|
|
951
|
+
}
|
|
952
|
+
else if (localSeq + 1 > seqStart) {
|
|
953
|
+
// The updates were already applied, and must be ignored.
|
|
954
|
+
d("localSeq + 1 > seqStart");
|
|
955
|
+
return;
|
|
956
|
+
}
|
|
957
|
+
else if (localSeq + 1 < seqStart) {
|
|
958
|
+
// There's an updates gap that must be filled.
|
|
959
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "localSeq + 1 < seqStart");
|
|
960
|
+
}
|
|
961
|
+
}
|
|
962
|
+
}
|
|
933
963
|
}
|
|
934
964
|
else if (updates_ instanceof types.UpdateShort) {
|
|
935
965
|
updates = [updates_.update];
|
|
@@ -1029,6 +1059,21 @@ export class Client extends ClientAbstract {
|
|
|
1029
1059
|
UNREACHABLE();
|
|
1030
1060
|
}
|
|
1031
1061
|
}
|
|
1062
|
+
if (isPtsUpdate(update)) {
|
|
1063
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
|
|
1064
|
+
}
|
|
1065
|
+
else if (isChannelPtsUpdate(update)) {
|
|
1066
|
+
let channelId = null;
|
|
1067
|
+
if ("channelId" in update) {
|
|
1068
|
+
channelId = update.channelId;
|
|
1069
|
+
}
|
|
1070
|
+
else if ("peerId" in update.message && update.message.peerId !== undefined && "channelId" in update.message.peerId) {
|
|
1071
|
+
channelId = update.message.peerId.channelId;
|
|
1072
|
+
}
|
|
1073
|
+
if (channelId != null) {
|
|
1074
|
+
await this.storage.setChannelPts(channelId, update.pts);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1032
1077
|
/// If there were any Update, they will be passed to the update handling queue.
|
|
1033
1078
|
if (update instanceof types._TypeUpdate) {
|
|
1034
1079
|
updatesToHandle.push(update);
|
|
@@ -1043,6 +1088,10 @@ export class Client extends ClientAbstract {
|
|
|
1043
1088
|
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1044
1089
|
localState.date = date;
|
|
1045
1090
|
await this.storage.setState(localState);
|
|
1091
|
+
}, _Client_setUpdatePts = async function _Client_setUpdatePts(pts) {
|
|
1092
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1093
|
+
localState.pts = pts;
|
|
1094
|
+
await this.storage.setState(localState);
|
|
1046
1095
|
}, _Client_getLocalState = async function _Client_getLocalState() {
|
|
1047
1096
|
let localState = await this.storage.getState();
|
|
1048
1097
|
if (!localState) {
|
|
@@ -1879,20 +1928,37 @@ export class Client extends ClientAbstract {
|
|
|
1879
1928
|
}, ...middleawre);
|
|
1880
1929
|
}
|
|
1881
1930
|
command(commands, ...middleawre) {
|
|
1882
|
-
const
|
|
1931
|
+
const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
|
|
1932
|
+
const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
|
|
1933
|
+
const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
|
|
1934
|
+
const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
|
|
1935
|
+
for (const left of prefixes) {
|
|
1936
|
+
for (const right of prefixes) {
|
|
1937
|
+
if (left == right) {
|
|
1938
|
+
continue;
|
|
1939
|
+
}
|
|
1940
|
+
if (left.startsWith(right) || right.startsWith(left)) {
|
|
1941
|
+
throw new Error("Intersecting prefixes");
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1944
|
+
}
|
|
1883
1945
|
return this.on(["message", "text"]).filter((ctx) => {
|
|
1884
|
-
const
|
|
1885
|
-
if (
|
|
1946
|
+
const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
|
|
1947
|
+
if (prefixes_.length == 0) {
|
|
1948
|
+
return false;
|
|
1949
|
+
}
|
|
1950
|
+
const cmd = ctx.message.text.split(/\s/, 1)[0];
|
|
1951
|
+
const prefix = prefixes_.find((v) => cmd.startsWith(v));
|
|
1952
|
+
if (prefix === undefined) {
|
|
1886
1953
|
return false;
|
|
1887
1954
|
}
|
|
1888
|
-
const cmd = ctx.message.text.slice(botCommand.offset, botCommand.offset + botCommand.length);
|
|
1889
1955
|
if (cmd.includes("@")) {
|
|
1890
|
-
const username = cmd.split("@")[1];
|
|
1956
|
+
const username = cmd.split("@", 2)[1];
|
|
1891
1957
|
if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
|
|
1892
1958
|
return false;
|
|
1893
1959
|
}
|
|
1894
1960
|
}
|
|
1895
|
-
const command_ = cmd.split("@")[0].split(
|
|
1961
|
+
const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
|
|
1896
1962
|
for (const command of commands_) {
|
|
1897
1963
|
if (typeof command === "string" && (command.toLowerCase() == command_)) {
|
|
1898
1964
|
return true;
|
package/package.json
CHANGED
package/script/4_constants.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
|
|
|
5
5
|
export declare const VECTOR_CONSTRUCTOR = 481674261;
|
|
6
6
|
export declare const INITIAL_DC: DC;
|
|
7
7
|
export declare const LAYER = 166;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.1.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.1.119";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/script/4_constants.js
CHANGED
|
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
80
80
|
exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
|
|
81
81
|
exports.INITIAL_DC = "2";
|
|
82
82
|
exports.LAYER = 166;
|
|
83
|
-
exports.APP_VERSION = "MTKruto 0.1.
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.1.119";
|
|
84
84
|
// @ts-ignore: lib
|
|
85
85
|
exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
86
86
|
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
|
@@ -44,6 +44,10 @@ export interface ClientParams extends ClientPlainParams {
|
|
|
44
44
|
* Whether to ignore outgoing messages. Defaults to `true` for bots, and `false` for users.
|
|
45
45
|
*/
|
|
46
46
|
ignoreOutgoing?: boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Default command prefixes. Defaults to `"/"` for bots and `"\"` for users. This option must be set separately for nested composers.
|
|
49
|
+
*/
|
|
50
|
+
prefixes?: string | string[];
|
|
47
51
|
}
|
|
48
52
|
export interface AnswerCallbackQueryParams {
|
|
49
53
|
/** A text to be shown to the user. */
|
|
@@ -15,6 +15,7 @@ export declare function concat<C extends Update = Update>(left: MiddlewareFn<C>,
|
|
|
15
15
|
export declare const skip: MiddlewareFn;
|
|
16
16
|
export declare class Composer<C extends Update> implements MiddlewareObj<C> {
|
|
17
17
|
#private;
|
|
18
|
+
set prefixes(value: string | string[]);
|
|
18
19
|
constructor(...middleware: Middleware<C>[]);
|
|
19
20
|
middleware(): MiddlewareFn<C>;
|
|
20
21
|
use(...middleware: Middleware<C>[]): Composer<C>;
|
|
@@ -22,6 +23,9 @@ export declare class Composer<C extends Update> implements MiddlewareObj<C> {
|
|
|
22
23
|
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
|
|
23
24
|
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]): Composer<C>;
|
|
24
25
|
on<T extends keyof Update_, F extends string>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...middleawre: Middleware<FilterUpdate<C, T, F>>[]): Composer<FilterUpdate<C, T, F>>;
|
|
25
|
-
command(commands: string | RegExp | (string | RegExp)[]
|
|
26
|
+
command(commands: string | RegExp | (string | RegExp)[] | {
|
|
27
|
+
names: string | RegExp | (string | RegExp)[];
|
|
28
|
+
prefixes: string | string[];
|
|
29
|
+
}, ...middleawre: Middleware<FilterUpdate<C, "message", "text">>[]): Composer<FilterUpdate<C, "message", "text">>;
|
|
26
30
|
}
|
|
27
31
|
export {};
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
+
};
|
|
2
7
|
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
8
|
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
9
|
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
11
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
12
|
};
|
|
8
|
-
var
|
|
9
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
-
};
|
|
13
|
-
var _Composer_handle;
|
|
13
|
+
var _Composer_handle, _Composer_prefixes;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Composer = exports.skip = exports.concat = exports.flatten = void 0;
|
|
16
16
|
function flatten(mw) {
|
|
@@ -35,8 +35,15 @@ exports.concat = concat;
|
|
|
35
35
|
const skip = (_ctx, next) => next();
|
|
36
36
|
exports.skip = skip;
|
|
37
37
|
class Composer {
|
|
38
|
+
set prefixes(value) {
|
|
39
|
+
if (__classPrivateFieldGet(this, _Composer_prefixes, "f") !== undefined) {
|
|
40
|
+
throw new Error("Prefixes already set");
|
|
41
|
+
}
|
|
42
|
+
__classPrivateFieldSet(this, _Composer_prefixes, value, "f");
|
|
43
|
+
}
|
|
38
44
|
constructor(...middleware) {
|
|
39
45
|
_Composer_handle.set(this, void 0);
|
|
46
|
+
_Composer_prefixes.set(this, void 0);
|
|
40
47
|
__classPrivateFieldSet(this, _Composer_handle, middleware.length == 0 ? exports.skip : middleware.map(flatten).reduce(concat), "f");
|
|
41
48
|
}
|
|
42
49
|
middleware() {
|
|
@@ -86,20 +93,37 @@ class Composer {
|
|
|
86
93
|
}, ...middleawre);
|
|
87
94
|
}
|
|
88
95
|
command(commands, ...middleawre) {
|
|
89
|
-
const
|
|
96
|
+
const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
|
|
97
|
+
const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
|
|
98
|
+
const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Composer_prefixes, "f") ?? []);
|
|
99
|
+
const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
|
|
100
|
+
for (const left of prefixes) {
|
|
101
|
+
for (const right of prefixes) {
|
|
102
|
+
if (left == right) {
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (left.startsWith(right) || right.startsWith(left)) {
|
|
106
|
+
throw new Error("Intersecting prefixes");
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
90
110
|
return this.on(["message", "text"]).filter((ctx) => {
|
|
91
|
-
const
|
|
92
|
-
if (
|
|
111
|
+
const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
|
|
112
|
+
if (prefixes_.length == 0) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
const cmd = ctx.message.text.split(/\s/, 1)[0];
|
|
116
|
+
const prefix = prefixes_.find((v) => cmd.startsWith(v));
|
|
117
|
+
if (prefix === undefined) {
|
|
93
118
|
return false;
|
|
94
119
|
}
|
|
95
|
-
const cmd = ctx.message.text.slice(botCommand.offset, botCommand.offset + botCommand.length);
|
|
96
120
|
if (cmd.includes("@")) {
|
|
97
|
-
const username = cmd.split("@")[1];
|
|
121
|
+
const username = cmd.split("@", 2)[1];
|
|
98
122
|
if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
|
|
99
123
|
return false;
|
|
100
124
|
}
|
|
101
125
|
}
|
|
102
|
-
const command_ = cmd.split("@")[0].split(
|
|
126
|
+
const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
|
|
103
127
|
for (const command of commands_) {
|
|
104
128
|
if (typeof command === "string" && (command.toLowerCase() == command_)) {
|
|
105
129
|
return true;
|
|
@@ -113,4 +137,4 @@ class Composer {
|
|
|
113
137
|
}
|
|
114
138
|
}
|
|
115
139
|
exports.Composer = Composer;
|
|
116
|
-
_Composer_handle = new WeakMap();
|
|
140
|
+
_Composer_handle = new WeakMap(), _Composer_prefixes = new WeakMap();
|
|
@@ -286,7 +286,10 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
286
286
|
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
|
|
287
287
|
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]): Composer<C>;
|
|
288
288
|
on<T extends keyof Update, F extends string>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...middleawre: Middleware<FilterUpdate<C, T, F>>[]): Composer<FilterUpdate<C, T, F>>;
|
|
289
|
-
command(commands: string | RegExp | (string | RegExp)[]
|
|
289
|
+
command(commands: string | RegExp | (string | RegExp)[] | {
|
|
290
|
+
names: string | RegExp | (string | RegExp)[];
|
|
291
|
+
prefixes: string | string[];
|
|
292
|
+
}, ...middleawre: Middleware<FilterUpdate<C, "message", "text">>[]): Composer<FilterUpdate<C, "message", "text">>;
|
|
290
293
|
/**
|
|
291
294
|
* Set the bot's description in the given language. Bot-only.
|
|
292
295
|
*
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkChannelGap, _Client_processUpdates, _Client_setUpdateStateDate, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
13
|
+
var _Client_instances, _a, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_updateState, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_assertUser, _Client_assertBot, _Client_fetchState, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkChannelGap, _Client_processUpdates, _Client_setUpdateStateDate, _Client_setUpdatePts, _Client_getLocalState, _Client_recoverUpdateGap, _Client_recoverChannelUpdateGap, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_updatesToMessages, _Client_resolveSendAs, _Client_parseText, _Client_getMessagesInner, _Client_downloadInner, _Client_lastGetMe, _Client_getMe, _Client_handleUpdate, _Client_usernameResolver, _Client_constructReplyMarkup, _Client_assertMsgHas, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Client = exports.ConnectionError = exports.restartAuth = exports.skipInvoke = exports.handleMigrationError = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -125,6 +125,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
125
125
|
_Client_publicKeys.set(this, void 0);
|
|
126
126
|
_Client_autoStart.set(this, void 0);
|
|
127
127
|
_Client_ignoreOutgoing.set(this, void 0);
|
|
128
|
+
_Client_prefixes.set(this, void 0);
|
|
128
129
|
_Client_constructContext.set(this, async (update) => {
|
|
129
130
|
const msg = update.message ?? update.editedMessage ?? update.callbackQuery?.message;
|
|
130
131
|
const mustGetMsg = () => {
|
|
@@ -302,6 +303,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
302
303
|
__classPrivateFieldSet(this, _Client_publicKeys, params?.publicKeys, "f");
|
|
303
304
|
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
304
305
|
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
306
|
+
__classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
|
|
305
307
|
if (params?.defaultHandlers ?? true) {
|
|
306
308
|
this.on("connectionState", ({ connectionState }, next) => {
|
|
307
309
|
(0, _1_utilities_js_1.drop)((async () => {
|
|
@@ -411,7 +413,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
411
413
|
release();
|
|
412
414
|
}
|
|
413
415
|
}
|
|
414
|
-
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
416
|
+
async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_updateState = new WeakMap(), _Client_publicKeys = new WeakMap(), _Client_autoStart = new WeakMap(), _Client_ignoreOutgoing = new WeakMap(), _Client_prefixes = new WeakMap(), _Client_constructContext = new WeakMap(), _Client_lastPropagatedConnectionState = new WeakMap(), _Client_storageInited = new WeakMap(), _Client_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_handleUpdateQueue = new WeakMap(), _Client_processUpdatesQueue = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
415
417
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
416
418
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), _0_utilities_js_1.resolve);
|
|
417
419
|
});
|
|
@@ -599,7 +601,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
599
601
|
dAuth("authorized as user");
|
|
600
602
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_propagateAuthorizationState).call(this, true);
|
|
601
603
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "authorize");
|
|
602
|
-
|
|
604
|
+
return;
|
|
603
605
|
}
|
|
604
606
|
catch (err) {
|
|
605
607
|
if (err instanceof _4_errors_js_1.PasswordHashInvalid) {
|
|
@@ -935,6 +937,34 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
935
937
|
let updates;
|
|
936
938
|
if (updates_ instanceof _2_tl_js_1.types.UpdatesCombined || updates_ instanceof _2_tl_js_1.types.Updates) {
|
|
937
939
|
updates = updates_.updates;
|
|
940
|
+
const seq = updates_.seq;
|
|
941
|
+
const seqStart = "seqStart" in updates_ ? updates_.seqStart : updates_.seq;
|
|
942
|
+
if (checkGap) {
|
|
943
|
+
if (seqStart == 0) {
|
|
944
|
+
checkGap = false;
|
|
945
|
+
d("seqStart=0");
|
|
946
|
+
}
|
|
947
|
+
else {
|
|
948
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
949
|
+
const localSeq = localState.seq;
|
|
950
|
+
if (localSeq + 1 == seqStart) {
|
|
951
|
+
// The updates can be applied.
|
|
952
|
+
localState.seq = seq;
|
|
953
|
+
localState.date = updates_.date;
|
|
954
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdateStateDate).call(this, updates_.date);
|
|
955
|
+
await this.storage.setState(localState);
|
|
956
|
+
}
|
|
957
|
+
else if (localSeq + 1 > seqStart) {
|
|
958
|
+
// The updates were already applied, and must be ignored.
|
|
959
|
+
d("localSeq + 1 > seqStart");
|
|
960
|
+
return;
|
|
961
|
+
}
|
|
962
|
+
else if (localSeq + 1 < seqStart) {
|
|
963
|
+
// There's an updates gap that must be filled.
|
|
964
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "localSeq + 1 < seqStart");
|
|
965
|
+
}
|
|
966
|
+
}
|
|
967
|
+
}
|
|
938
968
|
}
|
|
939
969
|
else if (updates_ instanceof _2_tl_js_1.types.UpdateShort) {
|
|
940
970
|
updates = [updates_.update];
|
|
@@ -1034,6 +1064,21 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1034
1064
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1035
1065
|
}
|
|
1036
1066
|
}
|
|
1067
|
+
if ((0, _0_utilities_js_1.isPtsUpdate)(update)) {
|
|
1068
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setUpdatePts).call(this, update.pts);
|
|
1069
|
+
}
|
|
1070
|
+
else if ((0, _0_utilities_js_1.isChannelPtsUpdate)(update)) {
|
|
1071
|
+
let channelId = null;
|
|
1072
|
+
if ("channelId" in update) {
|
|
1073
|
+
channelId = update.channelId;
|
|
1074
|
+
}
|
|
1075
|
+
else if ("peerId" in update.message && update.message.peerId !== undefined && "channelId" in update.message.peerId) {
|
|
1076
|
+
channelId = update.message.peerId.channelId;
|
|
1077
|
+
}
|
|
1078
|
+
if (channelId != null) {
|
|
1079
|
+
await this.storage.setChannelPts(channelId, update.pts);
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1037
1082
|
/// If there were any Update, they will be passed to the update handling queue.
|
|
1038
1083
|
if (update instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
1039
1084
|
updatesToHandle.push(update);
|
|
@@ -1048,6 +1093,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1048
1093
|
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1049
1094
|
localState.date = date;
|
|
1050
1095
|
await this.storage.setState(localState);
|
|
1096
|
+
}, _Client_setUpdatePts = async function _Client_setUpdatePts(pts) {
|
|
1097
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1098
|
+
localState.pts = pts;
|
|
1099
|
+
await this.storage.setState(localState);
|
|
1051
1100
|
}, _Client_getLocalState = async function _Client_getLocalState() {
|
|
1052
1101
|
let localState = await this.storage.getState();
|
|
1053
1102
|
if (!localState) {
|
|
@@ -1884,20 +1933,37 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1884
1933
|
}, ...middleawre);
|
|
1885
1934
|
}
|
|
1886
1935
|
command(commands, ...middleawre) {
|
|
1887
|
-
const
|
|
1936
|
+
const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
|
|
1937
|
+
const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
|
|
1938
|
+
const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
|
|
1939
|
+
const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
|
|
1940
|
+
for (const left of prefixes) {
|
|
1941
|
+
for (const right of prefixes) {
|
|
1942
|
+
if (left == right) {
|
|
1943
|
+
continue;
|
|
1944
|
+
}
|
|
1945
|
+
if (left.startsWith(right) || right.startsWith(left)) {
|
|
1946
|
+
throw new Error("Intersecting prefixes");
|
|
1947
|
+
}
|
|
1948
|
+
}
|
|
1949
|
+
}
|
|
1888
1950
|
return this.on(["message", "text"]).filter((ctx) => {
|
|
1889
|
-
const
|
|
1890
|
-
if (
|
|
1951
|
+
const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
|
|
1952
|
+
if (prefixes_.length == 0) {
|
|
1953
|
+
return false;
|
|
1954
|
+
}
|
|
1955
|
+
const cmd = ctx.message.text.split(/\s/, 1)[0];
|
|
1956
|
+
const prefix = prefixes_.find((v) => cmd.startsWith(v));
|
|
1957
|
+
if (prefix === undefined) {
|
|
1891
1958
|
return false;
|
|
1892
1959
|
}
|
|
1893
|
-
const cmd = ctx.message.text.slice(botCommand.offset, botCommand.offset + botCommand.length);
|
|
1894
1960
|
if (cmd.includes("@")) {
|
|
1895
|
-
const username = cmd.split("@")[1];
|
|
1961
|
+
const username = cmd.split("@", 2)[1];
|
|
1896
1962
|
if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
|
|
1897
1963
|
return false;
|
|
1898
1964
|
}
|
|
1899
1965
|
}
|
|
1900
|
-
const command_ = cmd.split("@")[0].split(
|
|
1966
|
+
const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
|
|
1901
1967
|
for (const command of commands_) {
|
|
1902
1968
|
if (typeof command === "string" && (command.toLowerCase() == command_)) {
|
|
1903
1969
|
return true;
|