@mtkruto/node 0.1.123 → 0.1.125
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/0_deps.d.ts +1 -0
- package/esm/0_deps.js +1 -0
- package/esm/1_utilities.d.ts +1 -1
- package/esm/1_utilities.js +1 -1
- package/esm/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/1_client_abstract.d.ts +1 -1
- package/esm/client/3_types.d.ts +56 -0
- package/esm/client/5_client.d.ts +17 -2
- package/esm/client/5_client.js +165 -57
- package/esm/connection/0_connection.d.ts +4 -0
- package/esm/connection/0_connection.js +6 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_db.d.ts +5 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_db.js +33 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_util.d.ts +21 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/_util.js +122 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/content_type.d.ts +38 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/content_type.js +60 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/format_media_type.d.ts +16 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/format_media_type.js +61 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/get_charset.d.ts +15 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/get_charset.js +37 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/parse_media_type.d.ts +37 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/parse_media_type.js +122 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.d.ts +8518 -0
- package/esm/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.js +8555 -0
- package/esm/storage/0_storage.d.ts +1 -0
- package/esm/storage/1_storage_indexed_db.d.ts +4 -3
- package/esm/storage/1_storage_indexed_db.js +17 -8
- package/esm/storage/1_storage_local_storage.d.ts +2 -2
- package/esm/storage/1_storage_local_storage.js +3 -0
- package/esm/storage/1_storage_memory.d.ts +1 -0
- package/esm/storage/1_storage_memory.js +3 -0
- package/esm/storage/1_storage_session_storage.d.ts +1 -0
- package/esm/storage/1_storage_session_storage.js +3 -0
- package/esm/transport/0_transport.d.ts +1 -1
- package/esm/transport/0_transport.js +0 -6
- package/esm/transport/1_transport_abridged.d.ts +1 -0
- package/esm/transport/1_transport_abridged.js +9 -5
- package/esm/transport/1_transport_intermediate.d.ts +1 -0
- package/esm/transport/1_transport_intermediate.js +8 -4
- package/esm/types/1_chat.d.ts +2 -15
- package/esm/types/1_chat.js +3 -14
- package/esm/types/1_user.js +4 -2
- package/esm/types/3_message.d.ts +2 -2
- package/esm/types/3_message.js +6 -6
- package/esm/utilities/{0_base64.js → 1_base64.js} +2 -1
- package/package.json +1 -1
- package/script/0_deps.d.ts +1 -0
- package/script/0_deps.js +3 -1
- package/script/1_utilities.d.ts +1 -1
- package/script/1_utilities.js +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/1_client_abstract.d.ts +1 -1
- package/script/client/3_types.d.ts +56 -0
- package/script/client/5_client.d.ts +17 -2
- package/script/client/5_client.js +164 -56
- package/script/connection/0_connection.d.ts +4 -0
- package/script/connection/0_connection.js +6 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_db.d.ts +5 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_db.js +39 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_util.d.ts +21 -0
- package/script/deps/deno.land/std@0.208.0/media_types/_util.js +132 -0
- package/script/deps/deno.land/std@0.208.0/media_types/content_type.d.ts +38 -0
- package/script/deps/deno.land/std@0.208.0/media_types/content_type.js +64 -0
- package/script/deps/deno.land/std@0.208.0/media_types/format_media_type.d.ts +16 -0
- package/script/deps/deno.land/std@0.208.0/media_types/format_media_type.js +65 -0
- package/script/deps/deno.land/std@0.208.0/media_types/get_charset.d.ts +15 -0
- package/script/deps/deno.land/std@0.208.0/media_types/get_charset.js +41 -0
- package/script/deps/deno.land/std@0.208.0/media_types/parse_media_type.d.ts +37 -0
- package/script/deps/deno.land/std@0.208.0/media_types/parse_media_type.js +126 -0
- package/script/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.d.ts +8518 -0
- package/script/deps/deno.land/std@0.208.0/media_types/vendor/mime-db.v1.52.0.js +8557 -0
- package/script/storage/0_storage.d.ts +1 -0
- package/script/storage/1_storage_indexed_db.d.ts +4 -3
- package/script/storage/1_storage_indexed_db.js +17 -8
- package/script/storage/1_storage_local_storage.d.ts +2 -2
- package/script/storage/1_storage_local_storage.js +3 -0
- package/script/storage/1_storage_memory.d.ts +1 -0
- package/script/storage/1_storage_memory.js +3 -0
- package/script/storage/1_storage_session_storage.d.ts +1 -0
- package/script/storage/1_storage_session_storage.js +3 -0
- package/script/transport/0_transport.d.ts +1 -1
- package/script/transport/0_transport.js +0 -6
- package/script/transport/1_transport_abridged.d.ts +1 -0
- package/script/transport/1_transport_abridged.js +9 -5
- package/script/transport/1_transport_intermediate.d.ts +1 -0
- package/script/transport/1_transport_intermediate.js +8 -4
- package/script/types/1_chat.d.ts +2 -15
- package/script/types/1_chat.js +3 -14
- package/script/types/1_user.js +4 -2
- package/script/types/3_message.d.ts +2 -2
- package/script/types/3_message.js +6 -6
- package/script/utilities/{0_base64.js → 1_base64.js} +2 -1
- /package/esm/utilities/{0_base64.d.ts → 1_base64.d.ts} +0 -0
- /package/script/utilities/{0_base64.d.ts → 1_base64.d.ts} +0 -0
|
@@ -6,7 +6,7 @@ import { BotCommand, CallbackQuery, ChatAction, ChatID, InlineQuery, InlineQuery
|
|
|
6
6
|
import { Migrate } from "../4_errors.js";
|
|
7
7
|
import { FileSource, With } from "./0_utilities.js";
|
|
8
8
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
9
|
-
import { AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, ClientParams, DeleteMessageParams, DeleteMessagesParams, DownloadParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, GetMyCommandsParams, InvokeErrorHandler, ReplyParams, SendMessageParams, SendPhotoParams, SendPollParams, SetMyCommandsParams, Update, UploadParams } from "./3_types.js";
|
|
9
|
+
import { AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, ClientParams, DeleteMessageParams, DeleteMessagesParams, DownloadParams, EditMessageParams, FilterableUpdates, FilterUpdate, ForwardMessagesParams, GetMyCommandsParams, InvokeErrorHandler, NetworkStatistics, ReplyParams, SendDocumentParams, SendMessageParams, SendPhotoParams, SendPollParams, SetMyCommandsParams, Update, UploadParams } from "./3_types.js";
|
|
10
10
|
import { Composer, Middleware } from "./4_composer.js";
|
|
11
11
|
declare const getEntity: unique symbol;
|
|
12
12
|
declare const getStickerSetName: unique symbol;
|
|
@@ -43,6 +43,8 @@ export interface Context extends Update {
|
|
|
43
43
|
replyPoll: (question: string, options: [string, string, ...string[]], params?: Omit<SendPollParams, "replyToMessageId"> & ReplyParams) => Promise<With<Message, "poll">>;
|
|
44
44
|
/** Reply the received message with a photo. */
|
|
45
45
|
replyPhoto: (photo: FileSource, params?: Omit<SendPhotoParams, "replyToMessageId"> & ReplyParams) => Promise<With<Message, "photo">>;
|
|
46
|
+
/** Reply the received message with a document. */
|
|
47
|
+
replyDocument: (document: FileSource, params?: Omit<SendDocumentParams, "replyToMessageId"> & ReplyParams) => Promise<With<Message, "document">>;
|
|
46
48
|
/** Delete the received message. */
|
|
47
49
|
delete: () => Promise<void>;
|
|
48
50
|
/** Forward the received message. */
|
|
@@ -150,7 +152,6 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
150
152
|
* Alias for `invoke` with its second parameter being `true`.
|
|
151
153
|
*/
|
|
152
154
|
send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
|
|
153
|
-
checkGap(pts: number, ptsCount: number): Promise<void>;
|
|
154
155
|
getUserAccessHash(userId: bigint): Promise<bigint>;
|
|
155
156
|
getInputPeer(id: ChatID): Promise<import("../tl/2_types.js").InputPeerChat_ | import("../tl/2_types.js").InputPeerUser_ | import("../tl/2_types.js").InputPeerChannel_>;
|
|
156
157
|
private [getEntity];
|
|
@@ -379,5 +380,19 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
|
|
|
379
380
|
* @param photo The photo to send.
|
|
380
381
|
*/
|
|
381
382
|
sendPhoto(chatId: ChatID, photo: FileSource, params?: SendPhotoParams): Promise<With<Message, "photo">>;
|
|
383
|
+
/**
|
|
384
|
+
* Send a document.
|
|
385
|
+
*
|
|
386
|
+
* @method
|
|
387
|
+
* @param chatId The chat to send the document to.
|
|
388
|
+
* @param document The document to send.
|
|
389
|
+
*/
|
|
390
|
+
sendDocument(chatId: ChatID, document: FileSource, params?: SendDocumentParams): Promise<With<Message, "document">>;
|
|
391
|
+
/**
|
|
392
|
+
* Get network statistics. This might not always be available.
|
|
393
|
+
*
|
|
394
|
+
* @method
|
|
395
|
+
*/
|
|
396
|
+
getNetworkStatistics(): Promise<NetworkStatistics>;
|
|
382
397
|
}
|
|
383
398
|
export {};
|
|
@@ -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_prefixes, _Client_namespaceProxies, _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
|
+
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_namespaceProxies, _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_pingLoopAbortSignal, _Client_pingInterval, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_processChats, _Client_processUsers, _Client_handleUpdateQueue, _Client_processUpdatesQueue, _Client_checkGap, _Client_checkChannelGap, _Client_lastUpdates, _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, _Client_resolveFileId, _Client_sendMedia;
|
|
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");
|
|
@@ -225,6 +225,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
225
225
|
const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
|
|
226
226
|
return this.sendPhoto(effectiveMessage.chat.id, photo, { ...params, replyToMessageId });
|
|
227
227
|
},
|
|
228
|
+
replyDocument: (document, params) => {
|
|
229
|
+
const effectiveMessage = mustGetMsg();
|
|
230
|
+
const replyToMessageId = getReplyToMessageId(params?.quote, effectiveMessage);
|
|
231
|
+
return this.sendDocument(effectiveMessage.chat.id, document, { ...params, replyToMessageId });
|
|
232
|
+
},
|
|
228
233
|
delete: () => {
|
|
229
234
|
const effectiveMessage = mustGetMsg();
|
|
230
235
|
return this.deleteMessage(effectiveMessage.chat.id, effectiveMessage.id);
|
|
@@ -310,6 +315,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
310
315
|
_Client_connectionInited.set(this, false);
|
|
311
316
|
_Client_lastPropagatedAuthorizationState.set(this, null);
|
|
312
317
|
_Client_selfId.set(this, null);
|
|
318
|
+
_Client_pingLoopAbortSignal.set(this, null);
|
|
313
319
|
_Client_pingInterval.set(this, 60 * 1000); // 60 seconds
|
|
314
320
|
_Client_pingLoopStarted.set(this, false);
|
|
315
321
|
_Client_autoStarted.set(this, false);
|
|
@@ -342,6 +348,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
342
348
|
});
|
|
343
349
|
_Client_handleUpdateQueue.set(this, new _1_utilities_js_1.Queue("handleUpdate"));
|
|
344
350
|
_Client_processUpdatesQueue.set(this, new _1_utilities_js_1.Queue("processUpdates"));
|
|
351
|
+
_Client_lastUpdates.set(this, new Date());
|
|
345
352
|
_Client_lastGetMe.set(this, null);
|
|
346
353
|
_Client_usernameResolver.set(this, async (v) => {
|
|
347
354
|
const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
@@ -361,16 +368,36 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
361
368
|
__classPrivateFieldSet(this, _Client_autoStart, params?.autoStart ?? true, "f");
|
|
362
369
|
__classPrivateFieldSet(this, _Client_ignoreOutgoing, params?.ignoreOutgoing ?? null, "f");
|
|
363
370
|
__classPrivateFieldSet(this, _Client_prefixes, params?.prefixes, "f");
|
|
371
|
+
const transportProvider = this.transportProvider;
|
|
372
|
+
this.transportProvider = (params) => {
|
|
373
|
+
const transport = transportProvider(params);
|
|
374
|
+
transport.connection.callback = {
|
|
375
|
+
read: async (count) => {
|
|
376
|
+
const key = params.cdn ? "netstat_cdn_read" : "netstat_messages_read";
|
|
377
|
+
await this.storage.incr([key], count);
|
|
378
|
+
},
|
|
379
|
+
write: async (count) => {
|
|
380
|
+
const key = params.cdn ? "netstat_cdn_write" : "netstat_messages_write";
|
|
381
|
+
await this.storage.incr([key], count);
|
|
382
|
+
},
|
|
383
|
+
};
|
|
384
|
+
return transport;
|
|
385
|
+
};
|
|
364
386
|
if (params?.defaultHandlers ?? true) {
|
|
365
387
|
this.on("connectionState", ({ connectionState }, next) => {
|
|
366
388
|
(0, _1_utilities_js_1.drop)((async () => {
|
|
367
389
|
if (connectionState == "notConnected") {
|
|
390
|
+
if (!this.transport?.transport.initialized) {
|
|
391
|
+
d("not reconnecting");
|
|
392
|
+
return;
|
|
393
|
+
}
|
|
368
394
|
let delay = 5;
|
|
369
395
|
while (!this.connected) {
|
|
370
396
|
d("reconnecting");
|
|
371
397
|
try {
|
|
372
398
|
await this.connect();
|
|
373
399
|
d("reconnected");
|
|
400
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "reconnect"));
|
|
374
401
|
break;
|
|
375
402
|
}
|
|
376
403
|
catch (err) {
|
|
@@ -470,7 +497,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
470
497
|
release();
|
|
471
498
|
}
|
|
472
499
|
}
|
|
473
|
-
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_namespaceProxies = 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) {
|
|
500
|
+
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_namespaceProxies = 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_pingLoopAbortSignal = 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_lastUpdates = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
|
|
474
501
|
__classPrivateFieldGet(this, _Client_handleUpdateQueue, "f").add(async () => {
|
|
475
502
|
await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, { connectionState }), _0_utilities_js_1.resolve);
|
|
476
503
|
});
|
|
@@ -498,9 +525,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
498
525
|
await this.reconnect(newDc);
|
|
499
526
|
d("migrated to DC%s", newDc);
|
|
500
527
|
}
|
|
501
|
-
disconnect() {
|
|
528
|
+
async disconnect() {
|
|
502
529
|
__classPrivateFieldSet(this, _Client_connectionInited, false, "f");
|
|
503
|
-
|
|
530
|
+
await super.disconnect();
|
|
531
|
+
__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f")?.abort();
|
|
504
532
|
}
|
|
505
533
|
/**
|
|
506
534
|
* Calls [initConnection](1) and authorizes the client with one of the following:
|
|
@@ -687,6 +715,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
687
715
|
await this.connect();
|
|
688
716
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
|
|
689
717
|
if (!__classPrivateFieldGet(this, _Client_authKeyWasCreated, "f")) {
|
|
718
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_fetchState).call(this, "start"));
|
|
690
719
|
return;
|
|
691
720
|
}
|
|
692
721
|
try {
|
|
@@ -708,12 +737,6 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
708
737
|
send(function_) {
|
|
709
738
|
return this.invoke(function_, true);
|
|
710
739
|
}
|
|
711
|
-
async checkGap(pts, ptsCount) {
|
|
712
|
-
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
713
|
-
if (localState.pts + ptsCount < pts) {
|
|
714
|
-
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "processUpdates");
|
|
715
|
-
}
|
|
716
|
-
}
|
|
717
740
|
async getUserAccessHash(userId) {
|
|
718
741
|
const users = await this.invoke(new _2_tl_js_1.functions.users.getUsers({ id: [new _2_tl_js_1.types.InputUser({ user_id: userId, access_hash: 0n })] }));
|
|
719
742
|
return users[0]?.[_2_tl_js_1.as](_2_tl_js_1.types.User).access_hash ?? 0n;
|
|
@@ -870,10 +893,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
870
893
|
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
871
894
|
}
|
|
872
895
|
}, _Client_pingLoop = async function _Client_pingLoop() {
|
|
896
|
+
__classPrivateFieldSet(this, _Client_pingLoopAbortSignal, new AbortController(), "f");
|
|
873
897
|
while (this.connected) {
|
|
874
|
-
await new Promise((r) => setTimeout(r, __classPrivateFieldGet(this, _Client_pingInterval, "f")));
|
|
875
898
|
try {
|
|
876
|
-
await
|
|
899
|
+
await new Promise((resolve, reject) => {
|
|
900
|
+
setTimeout(resolve, __classPrivateFieldGet(this, _Client_pingInterval, "f"));
|
|
901
|
+
__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f").signal.onabort = () => {
|
|
902
|
+
reject(__classPrivateFieldGet(this, _Client_pingLoopAbortSignal, "f")?.signal.reason);
|
|
903
|
+
};
|
|
904
|
+
});
|
|
905
|
+
await this.invoke(new _2_tl_js_1.functions.ping_delay_disconnect({ ping_id: (0, _1_utilities_js_1.getRandomId)(), disconnect_delay: __classPrivateFieldGet(this, _Client_pingInterval, "f") / 1000 + 15 }));
|
|
906
|
+
if (Date.now() - __classPrivateFieldGet(this, _Client_lastUpdates, "f").getTime() >= 15 * 60 * 1000) {
|
|
907
|
+
(0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "lastUpdates"));
|
|
908
|
+
}
|
|
877
909
|
}
|
|
878
910
|
catch (err) {
|
|
879
911
|
d("ping loop error: %o", err);
|
|
@@ -975,6 +1007,11 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
975
1007
|
}
|
|
976
1008
|
}
|
|
977
1009
|
}
|
|
1010
|
+
}, _Client_checkGap = async function _Client_checkGap(pts, ptsCount) {
|
|
1011
|
+
const localState = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1012
|
+
if (localState.pts + ptsCount < pts) {
|
|
1013
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverUpdateGap).call(this, "processUpdates");
|
|
1014
|
+
}
|
|
978
1015
|
}, _Client_checkChannelGap = async function _Client_checkChannelGap(channelId, pts, ptsCount) {
|
|
979
1016
|
let localPts = await this.storage.getChannelPts(channelId);
|
|
980
1017
|
if (!localPts) {
|
|
@@ -984,6 +1021,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
984
1021
|
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_recoverChannelUpdateGap).call(this, channelId, "processUpdates");
|
|
985
1022
|
}
|
|
986
1023
|
}, _Client_processUpdates = async function _Client_processUpdates(updates_, checkGap) {
|
|
1024
|
+
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
987
1025
|
/// First, individual updates (Update[1]) and updateShort* are extracted from Updates.[2]
|
|
988
1026
|
///
|
|
989
1027
|
/// If an updatesTooLong[3] was received, an update gap recovery is initiated and no further action will be taken.
|
|
@@ -1054,7 +1092,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1054
1092
|
continue;
|
|
1055
1093
|
}
|
|
1056
1094
|
if (checkGap) {
|
|
1057
|
-
await this.
|
|
1095
|
+
await __classPrivateFieldGet(this, _Client_instances, "m", _Client_checkGap).call(this, update.pts, update.pts_count);
|
|
1058
1096
|
}
|
|
1059
1097
|
localState ??= await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getLocalState).call(this);
|
|
1060
1098
|
originalPts ??= localState.pts;
|
|
@@ -1218,6 +1256,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1218
1256
|
}
|
|
1219
1257
|
finally {
|
|
1220
1258
|
this.stateChangeHandler(this.connected);
|
|
1259
|
+
__classPrivateFieldSet(this, _Client_lastUpdates, new Date(), "f");
|
|
1221
1260
|
}
|
|
1222
1261
|
}, _Client_recoverChannelUpdateGap = async function _Client_recoverChannelUpdateGap(channelId, source) {
|
|
1223
1262
|
dGapC("recovering channel update gap [%o, %s]", channelId, source);
|
|
@@ -2123,26 +2162,10 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2123
2162
|
let media = null;
|
|
2124
2163
|
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
2125
2164
|
if (typeof photo === "string") {
|
|
2126
|
-
|
|
2127
|
-
try {
|
|
2128
|
-
fileId = _3_types_js_1.FileID.decode(photo);
|
|
2129
|
-
}
|
|
2130
|
-
catch (err) {
|
|
2131
|
-
d("fileId: %o", err);
|
|
2132
|
-
}
|
|
2165
|
+
const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, photo, _3_types_js_1.FileType.Photo);
|
|
2133
2166
|
if (fileId != null) {
|
|
2134
|
-
if (fileId.fileType != _3_types_js_1.FileType.Photo) {
|
|
2135
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
2136
|
-
}
|
|
2137
|
-
if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined) {
|
|
2138
|
-
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
2139
|
-
}
|
|
2140
2167
|
media = new _2_tl_js_1.types.InputMediaPhoto({
|
|
2141
|
-
id: new _2_tl_js_1.types.InputPhoto(
|
|
2142
|
-
id: fileId.params.mediaId,
|
|
2143
|
-
access_hash: fileId.params.accessHash,
|
|
2144
|
-
file_reference: fileId.params.fileReference,
|
|
2145
|
-
}),
|
|
2168
|
+
id: new _2_tl_js_1.types.InputPhoto(fileId),
|
|
2146
2169
|
spoiler,
|
|
2147
2170
|
});
|
|
2148
2171
|
}
|
|
@@ -2157,33 +2180,70 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
2157
2180
|
media = new _2_tl_js_1.types.InputMediaUploadedPhoto({ file, spoiler });
|
|
2158
2181
|
}
|
|
2159
2182
|
}
|
|
2160
|
-
const
|
|
2161
|
-
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
2162
|
-
const silent = params?.disableNotification ? true : undefined;
|
|
2163
|
-
const noforwards = params?.protectContent ? true : undefined;
|
|
2164
|
-
const replyToMsgId = params?.replyToMessageId;
|
|
2165
|
-
const topMsgId = params?.messageThreadId;
|
|
2166
|
-
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2167
|
-
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2168
|
-
const caption_ = params?.caption;
|
|
2169
|
-
const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
2170
|
-
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
2171
|
-
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
2172
|
-
const result = await this.invoke(new _2_tl_js_1.functions.messages.sendMedia({
|
|
2173
|
-
peer,
|
|
2174
|
-
random_id: randomId,
|
|
2175
|
-
silent,
|
|
2176
|
-
noforwards,
|
|
2177
|
-
reply_markup: replyMarkup,
|
|
2178
|
-
reply_to: replyToMsgId !== undefined ? new _2_tl_js_1.types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
|
|
2179
|
-
send_as: sendAs,
|
|
2180
|
-
media,
|
|
2181
|
-
message: caption ?? "",
|
|
2182
|
-
entities: captionEntities,
|
|
2183
|
-
}));
|
|
2184
|
-
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2183
|
+
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
2185
2184
|
return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "photo");
|
|
2186
2185
|
}
|
|
2186
|
+
/**
|
|
2187
|
+
* Send a document.
|
|
2188
|
+
*
|
|
2189
|
+
* @method
|
|
2190
|
+
* @param chatId The chat to send the document to.
|
|
2191
|
+
* @param document The document to send.
|
|
2192
|
+
*/
|
|
2193
|
+
async sendDocument(chatId, document, params) {
|
|
2194
|
+
let media = null;
|
|
2195
|
+
const spoiler = params?.hasSpoiler ? true : undefined;
|
|
2196
|
+
if (typeof document === "string") {
|
|
2197
|
+
const fileId = __classPrivateFieldGet(this, _Client_instances, "m", _Client_resolveFileId).call(this, document, _3_types_js_1.FileType.Document);
|
|
2198
|
+
if (fileId != null) {
|
|
2199
|
+
media = new _2_tl_js_1.types.InputMediaDocument({
|
|
2200
|
+
id: new _2_tl_js_1.types.InputDocument(fileId),
|
|
2201
|
+
spoiler,
|
|
2202
|
+
});
|
|
2203
|
+
}
|
|
2204
|
+
}
|
|
2205
|
+
if (media == null) {
|
|
2206
|
+
if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
|
|
2207
|
+
media = new _2_tl_js_1.types.InputMediaDocumentExternal({ url: document, spoiler });
|
|
2208
|
+
}
|
|
2209
|
+
else {
|
|
2210
|
+
const [contents, fileName_] = await (0, _0_utilities_js_1.getFileContents)(document);
|
|
2211
|
+
const fileName = params?.fileName ?? fileName_;
|
|
2212
|
+
const mimeType = params?.mimeType ?? (0, _0_deps_js_1.contentType)(fileName.split(".").slice(-1)[0]) ?? "application/octet-stream";
|
|
2213
|
+
const file = await this.upload(contents, { fileName, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
2214
|
+
media = new _2_tl_js_1.types.InputMediaUploadedDocument({
|
|
2215
|
+
file,
|
|
2216
|
+
spoiler,
|
|
2217
|
+
attributes: [new _2_tl_js_1.types.DocumentAttributeFilename({ file_name: fileName })],
|
|
2218
|
+
mime_type: mimeType,
|
|
2219
|
+
});
|
|
2220
|
+
}
|
|
2221
|
+
}
|
|
2222
|
+
const message = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_sendMedia).call(this, chatId, media, params);
|
|
2223
|
+
return __classPrivateFieldGet(_a, _a, "m", _Client_assertMsgHas).call(_a, message, "document");
|
|
2224
|
+
}
|
|
2225
|
+
/**
|
|
2226
|
+
* Get network statistics. This might not always be available.
|
|
2227
|
+
*
|
|
2228
|
+
* @method
|
|
2229
|
+
*/
|
|
2230
|
+
async getNetworkStatistics() {
|
|
2231
|
+
const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
|
|
2232
|
+
this.storage.get(["netstat_messages_read"]),
|
|
2233
|
+
this.storage.get(["netstat_messages_write"]),
|
|
2234
|
+
this.storage.get(["netstat_cdn_read"]),
|
|
2235
|
+
this.storage.get(["netstat_cdn_write"]),
|
|
2236
|
+
]);
|
|
2237
|
+
const messages = {
|
|
2238
|
+
sent: Number(messagesWrite || 0),
|
|
2239
|
+
received: Number(messagesRead || 0),
|
|
2240
|
+
};
|
|
2241
|
+
const cdn = {
|
|
2242
|
+
sent: Number(cdnWrite || 0),
|
|
2243
|
+
received: Number(cdnRead || 0),
|
|
2244
|
+
};
|
|
2245
|
+
return { messages, cdn };
|
|
2246
|
+
}
|
|
2187
2247
|
}
|
|
2188
2248
|
exports.Client = Client;
|
|
2189
2249
|
_a = Client, _Client_getMe = async function _Client_getMe() {
|
|
@@ -2319,4 +2379,52 @@ async function _Client_setMyInfo(info) {
|
|
|
2319
2379
|
await this.invoke(new _2_tl_js_1.functions.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info }));
|
|
2320
2380
|
}, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
|
|
2321
2381
|
return this.invoke(new _2_tl_js_1.functions.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" }));
|
|
2382
|
+
}, _Client_resolveFileId = function _Client_resolveFileId(maybeFileId, expectedFileType) {
|
|
2383
|
+
let fileId = null;
|
|
2384
|
+
try {
|
|
2385
|
+
fileId = _3_types_js_1.FileID.decode(maybeFileId);
|
|
2386
|
+
}
|
|
2387
|
+
catch (err) {
|
|
2388
|
+
d("fileId: %o", err);
|
|
2389
|
+
}
|
|
2390
|
+
if (fileId != null) {
|
|
2391
|
+
if (fileId.fileType != expectedFileType) {
|
|
2392
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
2393
|
+
}
|
|
2394
|
+
if (fileId.params.mediaId == undefined || fileId.params.accessHash == undefined || fileId.params.fileReference == undefined) {
|
|
2395
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
2396
|
+
}
|
|
2397
|
+
return {
|
|
2398
|
+
id: fileId.params.mediaId,
|
|
2399
|
+
access_hash: fileId.params.accessHash,
|
|
2400
|
+
file_reference: fileId.params.fileReference,
|
|
2401
|
+
};
|
|
2402
|
+
}
|
|
2403
|
+
return null;
|
|
2404
|
+
}, _Client_sendMedia = async function _Client_sendMedia(chatId, media, params) {
|
|
2405
|
+
const peer = await this.getInputPeer(chatId);
|
|
2406
|
+
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
2407
|
+
const silent = params?.disableNotification ? true : undefined;
|
|
2408
|
+
const noforwards = params?.protectContent ? true : undefined;
|
|
2409
|
+
const replyToMsgId = params?.replyToMessageId;
|
|
2410
|
+
const topMsgId = params?.messageThreadId;
|
|
2411
|
+
const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
2412
|
+
const replyMarkup = await __classPrivateFieldGet(this, _Client_instances, "m", _Client_constructReplyMarkup).call(this, params);
|
|
2413
|
+
const caption_ = params?.caption;
|
|
2414
|
+
const parseResult = caption_ !== undefined ? __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).call(this, caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
2415
|
+
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
2416
|
+
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
2417
|
+
const result = await this.invoke(new _2_tl_js_1.functions.messages.sendMedia({
|
|
2418
|
+
peer,
|
|
2419
|
+
random_id: randomId,
|
|
2420
|
+
silent,
|
|
2421
|
+
noforwards,
|
|
2422
|
+
reply_markup: replyMarkup,
|
|
2423
|
+
reply_to: replyToMsgId !== undefined ? new _2_tl_js_1.types.InputReplyToMessage({ reply_to_msg_id: replyToMsgId, top_msg_id: topMsgId }) : undefined,
|
|
2424
|
+
send_as: sendAs,
|
|
2425
|
+
media,
|
|
2426
|
+
message: caption ?? "",
|
|
2427
|
+
entities: captionEntities,
|
|
2428
|
+
}));
|
|
2429
|
+
return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
2322
2430
|
};
|
|
@@ -5,6 +5,10 @@ declare abstract class Foundation {
|
|
|
5
5
|
abstract open(): MaybePromise<void>;
|
|
6
6
|
abstract write(p: Uint8Array): MaybePromise<void>;
|
|
7
7
|
abstract close(): MaybePromise<void>;
|
|
8
|
+
callback?: {
|
|
9
|
+
read(count: number): void;
|
|
10
|
+
write(count: number): void;
|
|
11
|
+
};
|
|
8
12
|
}
|
|
9
13
|
export declare abstract class ConnectionUnframed extends Foundation {
|
|
10
14
|
readonly type: "framed";
|