@mtkruto/node 0.1.114 → 0.1.116
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/0_utilities.d.ts +1 -0
- package/esm/client/0_utilities.js +64 -0
- package/esm/client/0_utilities_test.d.ts +1 -0
- package/esm/client/3_types.d.ts +4 -0
- package/esm/client/4_composer.d.ts +6 -1
- package/esm/client/4_composer.js +29 -1
- package/esm/client/5_client.d.ts +6 -4
- package/esm/client/5_client.js +118 -89
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/0_utilities.d.ts +1 -0
- package/script/client/0_utilities.js +66 -1
- package/script/client/0_utilities_test.d.ts +1 -0
- package/script/client/3_types.d.ts +4 -0
- package/script/client/4_composer.d.ts +6 -1
- package/script/client/4_composer.js +29 -1
- package/script/client/5_client.d.ts +6 -4
- package/script/client/5_client.js +116 -87
|
@@ -15,6 +15,7 @@ declare const getMessageWithReply: unique symbol;
|
|
|
15
15
|
export interface Context extends Update {
|
|
16
16
|
/** The client that received the update. */
|
|
17
17
|
client: Client;
|
|
18
|
+
me: undefined extends this["connectionState"] ? undefined extends this["authorizationState"] ? User : (User | undefined) : (User | undefined);
|
|
18
19
|
/** Resolves to `ctx.message ?? ctx.editedMessage ?? ctx.callbackQuery?.message`. */
|
|
19
20
|
msg: undefined extends this["message"] ? undefined extends this["editedMessage"] ? undefined extends this["callbackQuery"] ? never : this["callbackQuery"] extends With<CallbackQuery, "message"> ? this["callbackQuery"]["message"] : this["callbackQuery"] extends With<CallbackQuery, "inlineMessageId"> ? never : (Message | undefined) : this["editedMessage"] : this["message"];
|
|
20
21
|
/** Resolves to `effectiveMessage?.chat`. */
|
|
@@ -135,7 +136,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
135
136
|
* Alias for `invoke` with its second parameter being `true`.
|
|
136
137
|
*/
|
|
137
138
|
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
138
|
-
checkGap(pts: number, ptsCount: number
|
|
139
|
+
checkGap(pts: number, ptsCount: number): Promise<void>;
|
|
139
140
|
getUserAccessHash(userId: bigint): Promise<bigint>;
|
|
140
141
|
getInputPeer(id: ChatID): Promise<types.InputPeerChat | types.InputPeerUser | types.InputPeerChannel>;
|
|
141
142
|
private [getEntity];
|
|
@@ -282,9 +283,10 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
282
283
|
answerInlineQuery(id: string, results: InlineQueryResult[], params?: AnswerInlineQueryParams): Promise<void>;
|
|
283
284
|
use(...middleware: Middleware<C>[]): Composer<C>;
|
|
284
285
|
branch(predicate: (ctx: C) => MaybePromise<boolean>, trueHandler_: Middleware<C>, falseHandler_: Middleware<C>): Composer<C>;
|
|
285
|
-
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]):
|
|
286
|
-
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]):
|
|
287
|
-
on<T extends keyof Update, F extends keyof NonNullable<Update[T]>>(filter: T extends FilterableUpdates ? T | [T, F, ...F[]] : T, ...middleawre: Middleware<FilterUpdate<C, T, F>>[]):
|
|
286
|
+
filter<D extends C>(predicate: (ctx: C) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
|
|
287
|
+
filter(predicate: (ctx: C) => MaybePromise<boolean>, ...middleware: Middleware<C>[]): Composer<C>;
|
|
288
|
+
on<T extends keyof Update, F extends keyof NonNullable<Update[T]>>(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)[], ...middleawre: Middleware<FilterUpdate<C, "message", "text">>[]): Composer<FilterUpdate<C, "message", "text">>;
|
|
288
290
|
/**
|
|
289
291
|
* Set the bot's description in the given language. Bot-only.
|
|
290
292
|
*
|
|
@@ -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_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_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_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;
|
|
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");
|
|
@@ -124,7 +124,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
124
124
|
});
|
|
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_constructContext.set(this, async (update) => {
|
|
128
129
|
const msg = update.message ?? update.editedMessage ?? update.callbackQuery?.message;
|
|
129
130
|
const mustGetMsg = () => {
|
|
130
131
|
if (msg !== undefined) {
|
|
@@ -142,9 +143,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
142
143
|
const replyToMessageId = shouldQuote ? effectiveMessage.id : undefined;
|
|
143
144
|
return replyToMessageId;
|
|
144
145
|
};
|
|
145
|
-
|
|
146
|
+
const me = update.connectionState !== undefined ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : (update.authorizationState !== undefined && !update.authorizationState.authorized) ? __classPrivateFieldGet(this, _Client_lastGetMe, "f") : await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMe).call(this);
|
|
147
|
+
return (0, _1_utilities_js_1.cleanObject)({
|
|
146
148
|
...update,
|
|
147
149
|
client: this,
|
|
150
|
+
me: me == null ? undefined : me,
|
|
148
151
|
msg,
|
|
149
152
|
chat,
|
|
150
153
|
from,
|
|
@@ -221,7 +224,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
221
224
|
get toJSON() {
|
|
222
225
|
return () => update;
|
|
223
226
|
},
|
|
224
|
-
};
|
|
227
|
+
});
|
|
225
228
|
});
|
|
226
229
|
_Client_lastPropagatedConnectionState.set(this, null);
|
|
227
230
|
Object.defineProperty(this, "stateChangeHandler", {
|
|
@@ -281,6 +284,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
281
284
|
});
|
|
282
285
|
_Client_handleUpdateQueue.set(this, new _1_utilities_js_1.Queue("handleUpdate"));
|
|
283
286
|
_Client_processUpdatesQueue.set(this, new _1_utilities_js_1.Queue("processUpdates"));
|
|
287
|
+
_Client_lastGetMe.set(this, null);
|
|
284
288
|
_Client_usernameResolver.set(this, async (v) => {
|
|
285
289
|
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
286
290
|
return new _2_tl_js_1.types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
|
|
@@ -297,6 +301,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
297
301
|
this.systemVersion = params?.systemVersion ?? _4_constants_js_1.SYSTEM_VERSION;
|
|
298
302
|
__classPrivateFieldSet(this, _Client_publicKeys, params?.publicKeys, "f");
|
|
299
303
|
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
304
|
+
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
300
305
|
if (params?.defaultHandlers ?? true) {
|
|
301
306
|
this.on("connectionState", ({ connectionState }, next) => {
|
|
302
307
|
(0, _1_utilities_js_1.drop)((async () => {
|
|
@@ -406,9 +411,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
406
411
|
release();
|
|
407
412
|
}
|
|
408
413
|
}
|
|
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_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_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
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) {
|
|
410
415
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
411
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), _0_utilities_js_1.resolve);
|
|
416
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), _0_utilities_js_1.resolve);
|
|
412
417
|
});
|
|
413
418
|
}, _Client_setAuth = async function _Client_setAuth(key) {
|
|
414
419
|
const hash = await (0, _1_utilities_js_1.sha1)(key);
|
|
@@ -644,24 +649,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
644
649
|
send(function_) {
|
|
645
650
|
return this.invoke(function_, true);
|
|
646
651
|
}
|
|
647
|
-
async checkGap(pts, ptsCount
|
|
652
|
+
async checkGap(pts, ptsCount) {
|
|
648
653
|
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
649
654
|
if (localState.pts + ptsCount < pts) {
|
|
650
|
-
|
|
651
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
652
|
-
}
|
|
653
|
-
else {
|
|
654
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "processUpdates");
|
|
655
|
-
}
|
|
655
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "processUpdates");
|
|
656
656
|
}
|
|
657
657
|
}
|
|
658
658
|
async getUserAccessHash(userId) {
|
|
659
659
|
const users = await this.invoke(new _2_tl_js_1.functions.UsersGetUsers({ id: [new _2_tl_js_1.types.InputUser({ userId, accessHash: 0n })] }));
|
|
660
|
-
return users[0][_2_tl_js_1.as](_2_tl_js_1.types.User).accessHash ?? 0n;
|
|
660
|
+
return users[0]?.[_2_tl_js_1.as](_2_tl_js_1.types.User).accessHash ?? 0n;
|
|
661
661
|
}
|
|
662
662
|
async getInputPeer(id) {
|
|
663
663
|
const inputPeer = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getInputPeerInner).call(this, id);
|
|
664
|
-
if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser || inputPeer instanceof _2_tl_js_1.types.InputPeerChannel && inputPeer.accessHash == 0n && await this.storage.getAccountType() == "bot") {
|
|
664
|
+
if ((inputPeer instanceof _2_tl_js_1.types.InputPeerUser || inputPeer instanceof _2_tl_js_1.types.InputPeerChannel && inputPeer.accessHash == 0n) && await this.storage.getAccountType() == "bot") {
|
|
665
665
|
if ("channelId" in inputPeer) {
|
|
666
666
|
inputPeer.accessHash = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getChannelAccessHash).call(this, inputPeer.channelId);
|
|
667
667
|
}
|
|
@@ -692,7 +692,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
692
692
|
}
|
|
693
693
|
}, _Client_propagateAuthorizationState = async function _Client_propagateAuthorizationState(authorized) {
|
|
694
694
|
if (__classPrivateFieldGet(this, _Client_lastPropagatedAuthorizationState, "f") != authorized) {
|
|
695
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { authorizationState: { authorized } }), _0_utilities_js_1.resolve);
|
|
695
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { authorizationState: { authorized } }), _0_utilities_js_1.resolve);
|
|
696
696
|
__classPrivateFieldSet(this, _Client_lastPropagatedAuthorizationState, authorized, "f");
|
|
697
697
|
}
|
|
698
698
|
}, _Client_getSelfId = async function _Client_getSelfId() {
|
|
@@ -728,7 +728,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
728
728
|
}
|
|
729
729
|
dRecv("received %s", body.constructor.name);
|
|
730
730
|
if (body instanceof _2_tl_js_1.types._TypeUpdates || body instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
731
|
-
__classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(() => __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, body));
|
|
731
|
+
__classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(() => __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, body, true));
|
|
732
732
|
}
|
|
733
733
|
else if (body instanceof _2_tl_js_1.types.NewSessionCreated) {
|
|
734
734
|
__classPrivateFieldGet(this, _Client_state, "f").salt = body.serverSalt;
|
|
@@ -760,7 +760,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
760
760
|
};
|
|
761
761
|
if (result instanceof _2_tl_js_1.types._TypeUpdates || result instanceof _2_tl_js_1.types._TypeUpdate) {
|
|
762
762
|
__classPrivateFieldGet(this, _Client_processUpdatesQueue, "f").add(async () => {
|
|
763
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result);
|
|
763
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, result, true);
|
|
764
764
|
resolvePromise();
|
|
765
765
|
});
|
|
766
766
|
}
|
|
@@ -916,20 +916,15 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
916
916
|
}
|
|
917
917
|
}
|
|
918
918
|
}
|
|
919
|
-
}, _Client_checkChannelGap = async function _Client_checkChannelGap(channelId, pts, ptsCount
|
|
919
|
+
}, _Client_checkChannelGap = async function _Client_checkChannelGap(channelId, pts, ptsCount) {
|
|
920
920
|
let localPts = await this.storage.getChannelPts(channelId);
|
|
921
921
|
if (!localPts) {
|
|
922
922
|
localPts = pts - ptsCount;
|
|
923
923
|
}
|
|
924
924
|
if (localPts + ptsCount < pts) {
|
|
925
|
-
|
|
926
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
927
|
-
}
|
|
928
|
-
else {
|
|
929
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
930
|
-
}
|
|
925
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
931
926
|
}
|
|
932
|
-
}, _Client_processUpdates = async function _Client_processUpdates(updates_,
|
|
927
|
+
}, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap) {
|
|
933
928
|
/// First, individual updates (Update[1]) and updateShort* are extracted from Updates.[2]
|
|
934
929
|
///
|
|
935
930
|
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
@@ -971,7 +966,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
971
966
|
if (update.pts == 0) {
|
|
972
967
|
continue;
|
|
973
968
|
}
|
|
974
|
-
|
|
969
|
+
if (checkGap) {
|
|
970
|
+
await this.checkGap(update.pts, update.ptsCount);
|
|
971
|
+
}
|
|
975
972
|
localState ??= await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
976
973
|
originalPts ??= localState.pts;
|
|
977
974
|
if (localState.pts + update.ptsCount > update.pts) {
|
|
@@ -987,7 +984,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
987
984
|
}
|
|
988
985
|
const ptsCount = update.ptsCount;
|
|
989
986
|
const channelId = update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage ? update.message.peerId[_2_tl_js_1.as](_2_tl_js_1.types.PeerChannel).channelId : update.channelId;
|
|
990
|
-
|
|
987
|
+
if (checkGap) {
|
|
988
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkChannelGap).call(this, channelId, update.pts, ptsCount);
|
|
989
|
+
}
|
|
991
990
|
let currentPts = channelPtsMap.get(channelId);
|
|
992
991
|
if (currentPts === undefined) {
|
|
993
992
|
currentPts = await this.storage.getChannelPts(channelId);
|
|
@@ -1001,14 +1000,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1001
1000
|
}
|
|
1002
1001
|
}
|
|
1003
1002
|
}
|
|
1004
|
-
if (!assertNoGap) {
|
|
1005
|
-
if (localState != null && originalPts != null && localState.pts != originalPts) {
|
|
1006
|
-
await this.storage.setState(localState);
|
|
1007
|
-
}
|
|
1008
|
-
for (const [channelId, pts] of channelPtsMap.entries()) {
|
|
1009
|
-
await this.storage.setChannelPts(channelId, pts);
|
|
1010
|
-
}
|
|
1011
|
-
}
|
|
1012
1003
|
/// We process the updates when we are sure there is no gap.
|
|
1013
1004
|
if (updates_ instanceof _2_tl_js_1.types.Updates || updates_ instanceof _2_tl_js_1.types.UpdatesCombined) {
|
|
1014
1005
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, updates_.chats);
|
|
@@ -1087,10 +1078,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1087
1078
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
1088
1079
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1089
1080
|
for (const message of difference.newMessages) {
|
|
1090
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewMessage({ message, pts: 0, ptsCount: 0 }),
|
|
1081
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewMessage({ message, pts: 0, ptsCount: 0 }), false);
|
|
1091
1082
|
}
|
|
1092
1083
|
for (const update of difference.otherUpdates) {
|
|
1093
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update,
|
|
1084
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, false);
|
|
1094
1085
|
}
|
|
1095
1086
|
if (difference instanceof _2_tl_js_1.types.UpdatesDifference) {
|
|
1096
1087
|
await this.storage.setState(difference.state);
|
|
@@ -1138,10 +1129,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1138
1129
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
1139
1130
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1140
1131
|
for (const message of difference.newMessages) {
|
|
1141
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }),
|
|
1132
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), false);
|
|
1142
1133
|
}
|
|
1143
1134
|
for (const update of difference.otherUpdates) {
|
|
1144
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update,
|
|
1135
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, update, false);
|
|
1145
1136
|
}
|
|
1146
1137
|
await this.storage.setChannelPts(channelId, difference.pts);
|
|
1147
1138
|
dGapC("recovered from update gap [%o, %s]", channelId, source);
|
|
@@ -1153,7 +1144,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1153
1144
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, difference.chats);
|
|
1154
1145
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, difference.users);
|
|
1155
1146
|
for (const message of difference.messages) {
|
|
1156
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }),
|
|
1147
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUpdates).call(this, new _2_tl_js_1.types.UpdateNewChannelMessage({ message, pts: 0, ptsCount: 0 }), false);
|
|
1157
1148
|
}
|
|
1158
1149
|
const pts_ = difference.dialog[_2_tl_js_1.as](_2_tl_js_1.types.Dialog).pts;
|
|
1159
1150
|
if (pts_ != undefined) {
|
|
@@ -1174,52 +1165,44 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1174
1165
|
return channels.chats[0][_2_tl_js_1.as](_2_tl_js_1.types.Channel).accessHash ?? 0n;
|
|
1175
1166
|
}, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
|
|
1176
1167
|
if (typeof id === "string") {
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
let userId = 0n;
|
|
1186
|
-
let channelId = 0n;
|
|
1187
|
-
const maybeUsername = await this.storage.getUsername(id);
|
|
1188
|
-
if (maybeUsername != null && Date.now() - maybeUsername[2].getTime() < _4_constants_js_1.USERNAME_TTL) {
|
|
1189
|
-
const [type, id] = maybeUsername;
|
|
1190
|
-
if (type == "user") {
|
|
1191
|
-
userId = id;
|
|
1192
|
-
}
|
|
1193
|
-
else {
|
|
1194
|
-
channelId = id;
|
|
1195
|
-
}
|
|
1168
|
+
id = (0, _0_utilities_js_1.getUsername)(id);
|
|
1169
|
+
let userId = 0n;
|
|
1170
|
+
let channelId = 0n;
|
|
1171
|
+
const maybeUsername = await this.storage.getUsername(id);
|
|
1172
|
+
if (maybeUsername != null && Date.now() - maybeUsername[2].getTime() < _4_constants_js_1.USERNAME_TTL) {
|
|
1173
|
+
const [type, id] = maybeUsername;
|
|
1174
|
+
if (type == "user") {
|
|
1175
|
+
userId = id;
|
|
1196
1176
|
}
|
|
1197
1177
|
else {
|
|
1198
|
-
|
|
1199
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, resolved.chats);
|
|
1200
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, resolved.users);
|
|
1201
|
-
if (resolved.peer instanceof _2_tl_js_1.types.PeerUser) {
|
|
1202
|
-
userId = resolved.peer.userId;
|
|
1203
|
-
}
|
|
1204
|
-
else if (resolved.peer instanceof _2_tl_js_1.types.PeerChannel) {
|
|
1205
|
-
channelId = resolved.peer.channelId;
|
|
1206
|
-
}
|
|
1207
|
-
else {
|
|
1208
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1209
|
-
}
|
|
1178
|
+
channelId = id;
|
|
1210
1179
|
}
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1180
|
+
}
|
|
1181
|
+
else {
|
|
1182
|
+
const resolved = await this.invoke(new _2_tl_js_1.functions.ContactsResolveUsername({ username: id }));
|
|
1183
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processChats).call(this, resolved.chats);
|
|
1184
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_processUsers).call(this, resolved.users);
|
|
1185
|
+
if (resolved.peer instanceof _2_tl_js_1.types.PeerUser) {
|
|
1186
|
+
userId = resolved.peer.userId;
|
|
1214
1187
|
}
|
|
1215
|
-
else if (
|
|
1216
|
-
|
|
1217
|
-
return new _2_tl_js_1.types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
1188
|
+
else if (resolved.peer instanceof _2_tl_js_1.types.PeerChannel) {
|
|
1189
|
+
channelId = resolved.peer.channelId;
|
|
1218
1190
|
}
|
|
1219
1191
|
else {
|
|
1220
1192
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1221
1193
|
}
|
|
1222
1194
|
}
|
|
1195
|
+
if (userId) {
|
|
1196
|
+
const accessHash = await this.storage.getUserAccessHash(userId);
|
|
1197
|
+
return new _2_tl_js_1.types.InputPeerUser({ userId, accessHash: accessHash ?? 0n });
|
|
1198
|
+
}
|
|
1199
|
+
else if (channelId) {
|
|
1200
|
+
const accessHash = await this.storage.getChannelAccessHash(channelId);
|
|
1201
|
+
return new _2_tl_js_1.types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
|
|
1202
|
+
}
|
|
1203
|
+
else {
|
|
1204
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1205
|
+
}
|
|
1223
1206
|
}
|
|
1224
1207
|
else if (id > 0) {
|
|
1225
1208
|
const id_ = BigInt(id);
|
|
@@ -1602,7 +1585,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1602
1585
|
if (users.length < 1) {
|
|
1603
1586
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
1604
1587
|
}
|
|
1605
|
-
|
|
1588
|
+
const user = (0, _3_types_js_1.constructUser)(users[0][_2_tl_js_1.as](_2_tl_js_1.types.User));
|
|
1589
|
+
__classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
|
|
1590
|
+
return user;
|
|
1606
1591
|
}
|
|
1607
1592
|
/**
|
|
1608
1593
|
* Answer a callback query. Bot-only.
|
|
@@ -1873,7 +1858,9 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1873
1858
|
});
|
|
1874
1859
|
}
|
|
1875
1860
|
filter(predicate, ...middleware) {
|
|
1876
|
-
|
|
1861
|
+
const composer = new _4_composer_js_1.Composer(...middleware);
|
|
1862
|
+
this.branch(predicate, composer, _4_composer_js_1.skip);
|
|
1863
|
+
return composer;
|
|
1877
1864
|
}
|
|
1878
1865
|
on(filter, ...middleawre) {
|
|
1879
1866
|
const type = typeof filter === "string" ? filter : filter[0];
|
|
@@ -1896,6 +1883,32 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1896
1883
|
}
|
|
1897
1884
|
}, ...middleawre);
|
|
1898
1885
|
}
|
|
1886
|
+
command(commands, ...middleawre) {
|
|
1887
|
+
const commands_ = Array.isArray(commands) ? commands : [commands];
|
|
1888
|
+
return this.on(["message", "text"]).filter((ctx) => {
|
|
1889
|
+
const botCommand = ctx.message.entities?.find((v) => v.type == "botCommand");
|
|
1890
|
+
if (!botCommand) {
|
|
1891
|
+
return false;
|
|
1892
|
+
}
|
|
1893
|
+
const cmd = ctx.message.text.slice(botCommand.offset, botCommand.offset + botCommand.length);
|
|
1894
|
+
if (cmd.includes("@")) {
|
|
1895
|
+
const username = cmd.split("@")[1];
|
|
1896
|
+
if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
|
|
1897
|
+
return false;
|
|
1898
|
+
}
|
|
1899
|
+
}
|
|
1900
|
+
const command_ = cmd.split("@")[0].split("/")[1].toLowerCase();
|
|
1901
|
+
for (const command of commands_) {
|
|
1902
|
+
if (typeof command === "string" && (command.toLowerCase() == command_)) {
|
|
1903
|
+
return true;
|
|
1904
|
+
}
|
|
1905
|
+
else if (command instanceof RegExp && command.test(command_)) {
|
|
1906
|
+
return true;
|
|
1907
|
+
}
|
|
1908
|
+
}
|
|
1909
|
+
return false;
|
|
1910
|
+
}, ...middleawre);
|
|
1911
|
+
}
|
|
1899
1912
|
/**
|
|
1900
1913
|
* Set the bot's description in the given language. Bot-only.
|
|
1901
1914
|
*
|
|
@@ -2050,7 +2063,16 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2050
2063
|
}
|
|
2051
2064
|
}
|
|
2052
2065
|
exports.Client = Client;
|
|
2053
|
-
_a = Client,
|
|
2066
|
+
_a = Client, _Client_getMe = async function _Client_getMe() {
|
|
2067
|
+
if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
|
|
2068
|
+
return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
|
|
2069
|
+
}
|
|
2070
|
+
else {
|
|
2071
|
+
const user = await this.getMe();
|
|
2072
|
+
__classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
|
|
2073
|
+
return user;
|
|
2074
|
+
}
|
|
2075
|
+
}, _Client_handleUpdate =
|
|
2054
2076
|
// TODO: log errors
|
|
2055
2077
|
async function _Client_handleUpdate(update) {
|
|
2056
2078
|
if (update instanceof _2_tl_js_1.types.UpdateShortMessage) {
|
|
@@ -2108,8 +2130,15 @@ async function _Client_handleUpdate(update) {
|
|
|
2108
2130
|
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
2109
2131
|
const key = update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ? "message" : "editedMessage";
|
|
2110
2132
|
if (!(update.message instanceof _2_tl_js_1.types.MessageEmpty)) {
|
|
2111
|
-
const
|
|
2112
|
-
|
|
2133
|
+
const isOutgoing = update.message.out;
|
|
2134
|
+
let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
|
|
2135
|
+
if (__classPrivateFieldGet(this, _Client_ignoreOutgoing, "f") != null && isOutgoing) {
|
|
2136
|
+
shouldIgnore = __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f");
|
|
2137
|
+
}
|
|
2138
|
+
if (!shouldIgnore) {
|
|
2139
|
+
const message = await (0, _3_types_js_1.constructMessage)(update.message, this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
|
|
2140
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { [key]: message }), _0_utilities_js_1.resolve);
|
|
2141
|
+
}
|
|
2113
2142
|
}
|
|
2114
2143
|
}
|
|
2115
2144
|
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
@@ -2125,7 +2154,7 @@ async function _Client_handleUpdate(update) {
|
|
|
2125
2154
|
}
|
|
2126
2155
|
}
|
|
2127
2156
|
if (deletedMessages.length > 0) {
|
|
2128
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), _0_utilities_js_1.resolve);
|
|
2157
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), _0_utilities_js_1.resolve);
|
|
2129
2158
|
}
|
|
2130
2159
|
}
|
|
2131
2160
|
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
@@ -2139,14 +2168,14 @@ async function _Client_handleUpdate(update) {
|
|
|
2139
2168
|
await this.storage.setMessage(chatId, messageId, null);
|
|
2140
2169
|
}
|
|
2141
2170
|
if (deletedMessages.length > 0) {
|
|
2142
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), _0_utilities_js_1.resolve);
|
|
2171
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { deletedMessages: deletedMessages }), _0_utilities_js_1.resolve);
|
|
2143
2172
|
}
|
|
2144
2173
|
}
|
|
2145
2174
|
if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
|
|
2146
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), _0_utilities_js_1.resolve);
|
|
2175
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), this[getMessageWithReply].bind(this)) }), _0_utilities_js_1.resolve);
|
|
2147
2176
|
}
|
|
2148
2177
|
else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
|
|
2149
|
-
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve);
|
|
2178
|
+
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }), _0_utilities_js_1.resolve);
|
|
2150
2179
|
}
|
|
2151
2180
|
}, _Client_constructReplyMarkup = async function _Client_constructReplyMarkup(params) {
|
|
2152
2181
|
if (params?.replyMarkup) {
|