@mtkruto/node 0.1.142 → 0.1.143

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.
@@ -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, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_fileManager, _Client_reactionManager, _Client_messageManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_parseMode, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_setAuth, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_lastUpdates, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_parseText, _Client_lastGetMe, _Client_getMe, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_handle, _Client_setMyInfo, _Client_getMyInfo;
13
+ var _Client_instances, _Client_auth, _Client_sessionId, _Client_state, _Client_promises, _Client_toAcknowledge, _Client_guaranteeUpdateDelivery, _Client_updateManager, _Client_networkStatisticsManager, _Client_botInfoManager, _Client_fileManager, _Client_reactionManager, _Client_messageManager, _Client_callbackQueryManager, _Client_inlineQueryManager, _Client_chatListManager, _Client_parseMode, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_setAuth, _Client_storageInited, _Client_initStorage, _Client_connectMutex, _Client_connectionInited, _Client_initConnection, _Client_lastPropagatedAuthorizationState, _Client_propagateAuthorizationState, _Client_selfId, _Client_getSelfId, _Client_receiveLoop, _Client_pingLoopAbortSignal, _Client_pingInterval, _Client_lastUpdates, _Client_pingLoop, _Client_pingLoopStarted, _Client_autoStarted, _Client_lastMsgId, _Client_invoke, _Client_handleInvokeError, _Client_getUserAccessHash, _Client_getChannelAccessHash, _Client_getInputPeerInner, _Client_handleCtxUpdate, _Client_queueHandleCtxUpdate, _Client_handleUpdate, _Client_lastGetMe, _Client_getMe, _Client_handle;
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Client = exports.restartAuth = exports.skipInvoke = exports.handleMigrationError = void 0;
16
16
  const _0_deps_js_1 = require("../0_deps.js");
@@ -22,13 +22,14 @@ const _4_constants_js_1 = require("../4_constants.js");
22
22
  const _4_errors_js_1 = require("../4_errors.js");
23
23
  const _0_client_abstract_js_1 = require("./0_client_abstract.js");
24
24
  const _0_filters_js_1 = require("./0_filters.js");
25
- const _0_html_js_1 = require("./0_html.js");
26
25
  const _0_message_js_1 = require("./0_message.js");
27
26
  const _0_password_js_1 = require("./0_password.js");
28
27
  const _0_types_js_1 = require("./0_types.js");
29
28
  const _0_utilities_js_1 = require("./0_utilities.js");
29
+ const _1_bot_info_manager_js_1 = require("./1_bot_info_manager.js");
30
30
  const _1_composer_js_1 = require("./1_composer.js");
31
31
  const _1_file_manager_js_1 = require("./1_file_manager.js");
32
+ const _1_network_statistics_manager_js_1 = require("./1_network_statistics_manager.js");
32
33
  const _1_reaction_manager_js_1 = require("./1_reaction_manager.js");
33
34
  const _1_update_manager_js_1 = require("./1_update_manager.js");
34
35
  const _2_client_plain_js_1 = require("./2_client_plain.js");
@@ -77,6 +78,8 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
77
78
  _Client_toAcknowledge.set(this, new Set());
78
79
  _Client_guaranteeUpdateDelivery.set(this, void 0);
79
80
  _Client_updateManager.set(this, void 0);
81
+ _Client_networkStatisticsManager.set(this, void 0);
82
+ _Client_botInfoManager.set(this, void 0);
80
83
  _Client_fileManager.set(this, void 0);
81
84
  _Client_reactionManager.set(this, void 0);
82
85
  _Client_messageManager.set(this, void 0);
@@ -561,9 +564,12 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
561
564
  disconnect: client.disconnect.bind(client),
562
565
  };
563
566
  },
567
+ cdn: params?.cdn ?? false,
564
568
  ignoreOutgoing: __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f"),
565
569
  };
566
570
  __classPrivateFieldSet(this, _Client_updateManager, new _1_update_manager_js_1.UpdateManager(c), "f");
571
+ __classPrivateFieldSet(this, _Client_networkStatisticsManager, new _1_network_statistics_manager_js_1.NetworkStatisticsManager(c), "f");
572
+ __classPrivateFieldSet(this, _Client_botInfoManager, new _1_bot_info_manager_js_1.BotInfoManager(c), "f");
567
573
  __classPrivateFieldSet(this, _Client_fileManager, new _1_file_manager_js_1.FileManager(c), "f");
568
574
  __classPrivateFieldSet(this, _Client_reactionManager, new _1_reaction_manager_js_1.ReactionManager(c), "f");
569
575
  __classPrivateFieldSet(this, _Client_messageManager, new _2_message_manager_js_1.MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
@@ -574,16 +580,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
574
580
  const transportProvider = this.transportProvider;
575
581
  this.transportProvider = (params) => {
576
582
  const transport = transportProvider(params);
577
- transport.connection.callback = {
578
- read: async (count) => {
579
- const key = params.cdn ? "netstat_cdn_read" : "netstat_messages_read";
580
- await this.storage.incr([key], count);
581
- },
582
- write: async (count) => {
583
- const key = params.cdn ? "netstat_cdn_write" : "netstat_messages_write";
584
- await this.storage.incr([key], count);
585
- },
586
- };
583
+ transport.connection.callback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback();
587
584
  return transport;
588
585
  };
589
586
  if (params?.defaultHandlers ?? true) {
@@ -693,7 +690,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
693
690
  release();
694
691
  }
695
692
  }
696
- async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_parseMode = 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_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
693
+ async [(_Client_auth = new WeakMap(), _Client_sessionId = new WeakMap(), _Client_state = new WeakMap(), _Client_promises = new WeakMap(), _Client_toAcknowledge = new WeakMap(), _Client_guaranteeUpdateDelivery = new WeakMap(), _Client_updateManager = new WeakMap(), _Client_networkStatisticsManager = new WeakMap(), _Client_botInfoManager = new WeakMap(), _Client_fileManager = new WeakMap(), _Client_reactionManager = new WeakMap(), _Client_messageManager = new WeakMap(), _Client_callbackQueryManager = new WeakMap(), _Client_inlineQueryManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_parseMode = 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_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
697
694
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
698
695
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
699
696
  }, _Client_setAuth = async function _Client_setAuth(key) {
@@ -1230,6 +1227,77 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1230
1227
  const id = peer instanceof _2_tl_js_1.types.PeerUser ? peer.user_id : peer instanceof _2_tl_js_1.types.PeerChat ? peer.chat_id : peer instanceof _2_tl_js_1.types.PeerChannel ? peer.channel_id : (0, _1_utilities_js_1.UNREACHABLE)();
1231
1228
  return this.storage.getEntity(type, id);
1232
1229
  }
1230
+ use(...middleware) {
1231
+ const composer = new _1_composer_js_1.Composer(...middleware);
1232
+ __classPrivateFieldSet(this, _Client_handle, (0, _1_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _1_composer_js_1.flatten)(composer)), "f");
1233
+ return composer;
1234
+ }
1235
+ branch(predicate, trueHandler_, falseHandler_) {
1236
+ const trueHandler = (0, _1_composer_js_1.flatten)(trueHandler_);
1237
+ const falseHandler = (0, _1_composer_js_1.flatten)(falseHandler_);
1238
+ return this.use(async (upd, next) => {
1239
+ if (await predicate(upd)) {
1240
+ await trueHandler(upd, next);
1241
+ }
1242
+ else {
1243
+ await falseHandler(upd, next);
1244
+ }
1245
+ });
1246
+ }
1247
+ filter(predicate, ...middleware) {
1248
+ const composer = new _1_composer_js_1.Composer(...middleware);
1249
+ this.branch(predicate, composer, _1_composer_js_1.skip);
1250
+ return composer;
1251
+ }
1252
+ on(filter, ...middleawre) {
1253
+ return this.filter((ctx) => {
1254
+ return (0, _0_filters_js_1.match)(filter, ctx);
1255
+ }, ...middleawre);
1256
+ }
1257
+ command(commands, ...middleawre) {
1258
+ const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1259
+ const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1260
+ const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1261
+ const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1262
+ for (const left of prefixes) {
1263
+ for (const right of prefixes) {
1264
+ if (left == right) {
1265
+ continue;
1266
+ }
1267
+ if (left.startsWith(right) || right.startsWith(left)) {
1268
+ throw new Error("Intersecting prefixes");
1269
+ }
1270
+ }
1271
+ }
1272
+ return this.on("message:text").filter((ctx) => {
1273
+ const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1274
+ if (prefixes_.length == 0) {
1275
+ return false;
1276
+ }
1277
+ const cmd = ctx.message.text.split(/\s/, 1)[0];
1278
+ const prefix = prefixes_.find((v) => cmd.startsWith(v));
1279
+ if (prefix === undefined) {
1280
+ return false;
1281
+ }
1282
+ if (cmd.includes("@")) {
1283
+ const username = cmd.split("@", 2)[1];
1284
+ if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1285
+ return false;
1286
+ }
1287
+ }
1288
+ const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1289
+ for (const command of commands_) {
1290
+ if (typeof command === "string" && (command.toLowerCase() == command_)) {
1291
+ return true;
1292
+ }
1293
+ else if (command instanceof RegExp && command.test(command_)) {
1294
+ return true;
1295
+ }
1296
+ }
1297
+ return false;
1298
+ }, ...middleawre);
1299
+ }
1300
+ //#endregion
1233
1301
  /**
1234
1302
  * Send a text message.
1235
1303
  *
@@ -1347,77 +1415,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1347
1415
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1348
1416
  return user;
1349
1417
  }
1350
- use(...middleware) {
1351
- const composer = new _1_composer_js_1.Composer(...middleware);
1352
- __classPrivateFieldSet(this, _Client_handle, (0, _1_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _1_composer_js_1.flatten)(composer)), "f");
1353
- return composer;
1354
- }
1355
- branch(predicate, trueHandler_, falseHandler_) {
1356
- const trueHandler = (0, _1_composer_js_1.flatten)(trueHandler_);
1357
- const falseHandler = (0, _1_composer_js_1.flatten)(falseHandler_);
1358
- return this.use(async (upd, next) => {
1359
- if (await predicate(upd)) {
1360
- await trueHandler(upd, next);
1361
- }
1362
- else {
1363
- await falseHandler(upd, next);
1364
- }
1365
- });
1366
- }
1367
- filter(predicate, ...middleware) {
1368
- const composer = new _1_composer_js_1.Composer(...middleware);
1369
- this.branch(predicate, composer, _1_composer_js_1.skip);
1370
- return composer;
1371
- }
1372
- on(filter, ...middleawre) {
1373
- return this.filter((ctx) => {
1374
- return (0, _0_filters_js_1.match)(filter, ctx);
1375
- }, ...middleawre);
1376
- }
1377
- command(commands, ...middleawre) {
1378
- const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1379
- const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1380
- const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1381
- const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1382
- for (const left of prefixes) {
1383
- for (const right of prefixes) {
1384
- if (left == right) {
1385
- continue;
1386
- }
1387
- if (left.startsWith(right) || right.startsWith(left)) {
1388
- throw new Error("Intersecting prefixes");
1389
- }
1390
- }
1391
- }
1392
- return this.on("message:text").filter((ctx) => {
1393
- const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1394
- if (prefixes_.length == 0) {
1395
- return false;
1396
- }
1397
- const cmd = ctx.message.text.split(/\s/, 1)[0];
1398
- const prefix = prefixes_.find((v) => cmd.startsWith(v));
1399
- if (prefix === undefined) {
1400
- return false;
1401
- }
1402
- if (cmd.includes("@")) {
1403
- const username = cmd.split("@", 2)[1];
1404
- if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1405
- return false;
1406
- }
1407
- }
1408
- const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1409
- for (const command of commands_) {
1410
- if (typeof command === "string" && (command.toLowerCase() == command_)) {
1411
- return true;
1412
- }
1413
- else if (command instanceof RegExp && command.test(command_)) {
1414
- return true;
1415
- }
1416
- }
1417
- return false;
1418
- }, ...middleawre);
1419
- }
1420
- //#endregion
1421
1418
  /**
1422
1419
  * Answer a callback query. Bot-only.
1423
1420
  *
@@ -1448,45 +1445,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1448
1445
  * @param messageThreadId The thread to send the chat action to.
1449
1446
  */
1450
1447
  async sendChatAction(chatId, action, params) {
1451
- let action_;
1452
- switch (action) {
1453
- case "type":
1454
- action_ = new _2_tl_js_1.types.SendMessageTypingAction();
1455
- break;
1456
- case "uploadPhoto":
1457
- action_ = new _2_tl_js_1.types.SendMessageUploadPhotoAction({ progress: 0 });
1458
- break;
1459
- case "recordVideo":
1460
- action_ = new _2_tl_js_1.types.SendMessageRecordVideoAction();
1461
- break;
1462
- case "uploadVideo":
1463
- action_ = new _2_tl_js_1.types.SendMessageRecordVideoAction();
1464
- break;
1465
- case "recordVoice":
1466
- action_ = new _2_tl_js_1.types.SendMessageRecordAudioAction();
1467
- break;
1468
- case "uploadAudio":
1469
- action_ = new _2_tl_js_1.types.SendMessageUploadAudioAction({ progress: 0 });
1470
- break;
1471
- case "uploadDocument":
1472
- action_ = new _2_tl_js_1.types.SendMessageUploadDocumentAction({ progress: 0 });
1473
- break;
1474
- case "chooseSticker":
1475
- action_ = new _2_tl_js_1.types.SendMessageChooseStickerAction();
1476
- break;
1477
- case "findLocation":
1478
- action_ = new _2_tl_js_1.types.SendMessageGeoLocationAction();
1479
- break;
1480
- case "recordVideoNote":
1481
- action_ = new _2_tl_js_1.types.SendMessageRecordRoundAction();
1482
- break;
1483
- case "uploadVideoNote":
1484
- action_ = new _2_tl_js_1.types.SendMessageUploadRoundAction({ progress: 0 });
1485
- break;
1486
- default:
1487
- throw new Error("Invalid chat action: " + action);
1488
- }
1489
- await this.api.messages.setTyping({ peer: await this.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId });
1448
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendChatAction(chatId, action, params);
1490
1449
  }
1491
1450
  /**
1492
1451
  * Upload a file.
@@ -1504,21 +1463,13 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1504
1463
  * @param commands The commands to set.
1505
1464
  */
1506
1465
  async setMyCommands(commands, params) {
1507
- await this.api.bots.setBotCommands({
1508
- commands: commands.map((v) => new _2_tl_js_1.types.BotCommand(v)),
1509
- lang_code: params?.languageCode ?? "",
1510
- scope: await (0, _3_types_js_1.botCommandScopeToTlObject)(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
1511
- });
1466
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyCommands(commands, params);
1512
1467
  }
1513
1468
  /**
1514
1469
  * Get the bot's commands in the given scope and/or language. Bot-only.
1515
1470
  */
1516
1471
  async getMyCommands(params) {
1517
- const commands_ = await this.api.bots.getBotCommands({
1518
- lang_code: params?.languageCode ?? "",
1519
- scope: await (0, _3_types_js_1.botCommandScopeToTlObject)(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
1520
- });
1521
- return commands_.map((v) => ({ command: v.command, description: v.description }));
1472
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyCommands(params);
1522
1473
  }
1523
1474
  /**
1524
1475
  * Answer an inline query. Bot-only.
@@ -1536,8 +1487,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1536
1487
  * @method
1537
1488
  */
1538
1489
  async setMyDescription(params) {
1539
- await this.storage.assertBot("setMyDescription");
1540
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
1490
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyDescription(params);
1541
1491
  }
1542
1492
  /**
1543
1493
  * Set the bot's name in the given language. Bot-only.
@@ -1545,8 +1495,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1545
1495
  * @method
1546
1496
  */
1547
1497
  async setMyName(params) {
1548
- await this.storage.assertBot("setMyName");
1549
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
1498
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyName(params);
1550
1499
  }
1551
1500
  /**
1552
1501
  * Set the bot's short description in the given language. Bot-only.
@@ -1554,8 +1503,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1554
1503
  * @method
1555
1504
  */
1556
1505
  async setMyShortDescription(params) {
1557
- await this.storage.assertBot("setMyShortDescription");
1558
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
1506
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyShortDescription(params);
1559
1507
  }
1560
1508
  /**
1561
1509
  * Get the bot's description in the given language. Bot-only.
@@ -1563,8 +1511,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1563
1511
  * @method
1564
1512
  */
1565
1513
  async getMyDescription(params) {
1566
- await this.storage.assertBot("getMyDescription");
1567
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
1514
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyDescription(params);
1568
1515
  }
1569
1516
  /**
1570
1517
  * Set the bot's name in the given language. Bot-only.
@@ -1572,8 +1519,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1572
1519
  * @method
1573
1520
  */
1574
1521
  async getMyName(params) {
1575
- await this.storage.assertBot("getMyName");
1576
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
1522
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyName(params);
1577
1523
  }
1578
1524
  /**
1579
1525
  * Get the bot's short description in the given language. Bot-only.
@@ -1581,8 +1527,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1581
1527
  * @method
1582
1528
  */
1583
1529
  async getMyShortDescription(params) {
1584
- await this.storage.assertBot("getMyShortDescription");
1585
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.about);
1530
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyShortDescription(params);
1586
1531
  }
1587
1532
  /**
1588
1533
  * Delete multiple messages.
@@ -1724,21 +1669,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1724
1669
  * @method
1725
1670
  */
1726
1671
  async getNetworkStatistics() {
1727
- const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
1728
- this.storage.get(["netstat_messages_read"]),
1729
- this.storage.get(["netstat_messages_write"]),
1730
- this.storage.get(["netstat_cdn_read"]),
1731
- this.storage.get(["netstat_cdn_write"]),
1732
- ]);
1733
- const messages = {
1734
- sent: Number(messagesWrite || 0),
1735
- received: Number(messagesRead || 0),
1736
- };
1737
- const cdn = {
1738
- sent: Number(cdnWrite || 0),
1739
- received: Number(cdnRead || 0),
1740
- };
1741
- return { messages, cdn };
1672
+ return await __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getNetworkStatistics();
1742
1673
  }
1743
1674
  /**
1744
1675
  * Get chats from a chat list. User-only.
@@ -1825,19 +1756,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1825
1756
  * @param photo A photo to set as the chat's photo.
1826
1757
  */
1827
1758
  async setChatPhoto(chatId, photo, params) {
1828
- const peer = await this.getInputPeer(chatId);
1829
- if (!(peer instanceof _2_tl_js_1.types.InputPeerChannel) && !(peer instanceof _2_tl_js_1.types.InputPeerChat)) {
1830
- (0, _1_utilities_js_1.UNREACHABLE)();
1831
- }
1832
- const [contents, fileName] = await (0, _0_utilities_js_1.getFileContents)(photo);
1833
- const file = await this.upload(contents, { fileName: params?.fileName ?? fileName, chunkSize: params?.chunkSize, signal: params?.signal });
1834
- const photo_ = new _2_tl_js_1.types.InputChatUploadedPhoto({ file });
1835
- if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
1836
- await this.api.channels.editPhoto({ channel: new _2_tl_js_1.types.InputChannel(peer), photo: photo_ });
1837
- }
1838
- else if (peer instanceof _2_tl_js_1.types.InputPeerChat) {
1839
- await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: photo_ });
1840
- }
1759
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatPhoto(chatId, photo, params);
1841
1760
  }
1842
1761
  /**
1843
1762
  * Delete a chat's photo.
@@ -1846,16 +1765,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1846
1765
  * @param chatId The identifier of the chat.
1847
1766
  */
1848
1767
  async deleteChatPhoto(chatId) {
1849
- const peer = await this.getInputPeer(chatId);
1850
- if (!(peer instanceof _2_tl_js_1.types.InputPeerChannel) && !(peer instanceof _2_tl_js_1.types.InputPeerChat)) {
1851
- (0, _1_utilities_js_1.UNREACHABLE)();
1852
- }
1853
- if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
1854
- await this.api.channels.editPhoto({ channel: new _2_tl_js_1.types.InputChannel(peer), photo: new _2_tl_js_1.types.InputChatPhotoEmpty() });
1855
- }
1856
- else if (peer instanceof _2_tl_js_1.types.InputPeerChat) {
1857
- await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: new _2_tl_js_1.types.InputChatPhotoEmpty() });
1858
- }
1768
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteChatPhoto(chatId);
1859
1769
  }
1860
1770
  /**
1861
1771
  * Delete all messages sent by a specific member of a chat.
@@ -1904,46 +1814,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1904
1814
  * @param memberId The identifier of the member.
1905
1815
  */
1906
1816
  async banChatMember(chatId, memberId, params) {
1907
- const chat = await this.getInputPeer(chatId);
1908
- if (!(chat instanceof _2_tl_js_1.types.InputPeerChannel) && !(chat instanceof _2_tl_js_1.types.InputPeerChat)) {
1909
- throw new Error("Invalid chat ID");
1910
- }
1911
- const member = await this.getInputPeer(memberId);
1912
- if (chat instanceof _2_tl_js_1.types.InputPeerChannel) {
1913
- if (params?.deleteMessages) {
1914
- try {
1915
- await this.deleteChatMemberMessages(chatId, memberId);
1916
- }
1917
- catch {
1918
- //
1919
- }
1920
- }
1921
- await this.api.channels.editBanned({
1922
- channel: new _2_tl_js_1.types.InputChannel(chat),
1923
- participant: member,
1924
- banned_rights: new _2_tl_js_1.types.ChatBannedRights({
1925
- until_date: params?.untilDate ? (0, _1_utilities_js_1.toUnixTimestamp)(params.untilDate) : 0,
1926
- view_messages: true,
1927
- send_messages: true,
1928
- send_media: true,
1929
- send_stickers: true,
1930
- send_gifs: true,
1931
- send_games: true,
1932
- send_inline: true,
1933
- embed_links: true,
1934
- }),
1935
- });
1936
- }
1937
- else if (chat instanceof _2_tl_js_1.types.InputPeerChat) {
1938
- if (!(member instanceof _2_tl_js_1.types.InputPeerUser)) {
1939
- throw new Error("Invalid user ID");
1940
- }
1941
- await this.api.messages.deleteChatUser({
1942
- chat_id: chat.chat_id,
1943
- user_id: new _2_tl_js_1.types.InputUser(member),
1944
- revoke_history: params?.deleteMessages ? true : undefined,
1945
- });
1946
- }
1817
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId, params);
1947
1818
  }
1948
1819
  /**
1949
1820
  * Unban a member from a chat.
@@ -1953,16 +1824,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1953
1824
  * @param memberId The identifier of the member.
1954
1825
  */
1955
1826
  async unbanChatMember(chatId, memberId) {
1956
- const chat = await this.getInputPeer(chatId);
1957
- if (!(chat instanceof _2_tl_js_1.types.InputPeerChannel)) {
1958
- throw new Error("Invalid chat ID");
1959
- }
1960
- const member = await this.getInputPeer(memberId);
1961
- await this.api.channels.editBanned({
1962
- channel: new _2_tl_js_1.types.InputChannel(chat),
1963
- participant: member,
1964
- banned_rights: new _2_tl_js_1.types.ChatBannedRights({ until_date: 0 }),
1965
- });
1827
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
1966
1828
  }
1967
1829
  /**
1968
1830
  * Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.
@@ -1972,8 +1834,8 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1972
1834
  * @param memberId The identifier of the member.
1973
1835
  */
1974
1836
  async kickChatMember(chatId, memberId) {
1975
- await this.banChatMember(chatId, memberId);
1976
- await this.unbanChatMember(chatId, memberId);
1837
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId);
1838
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
1977
1839
  }
1978
1840
  /**
1979
1841
  * Set the rights of a chat member.
@@ -1983,67 +1845,11 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1983
1845
  * @param memberId The identifier of a member.
1984
1846
  */
1985
1847
  async setChatMemberRights(chatId, memberId, params) {
1986
- const chat = await this.getInputPeer(chatId);
1987
- if (!(chat instanceof _2_tl_js_1.types.InputPeerChannel)) {
1988
- throw new Error("Invalid chat ID");
1989
- }
1990
- const member = await this.getInputPeer(memberId);
1991
- await this.api.channels.editBanned({
1992
- channel: new _2_tl_js_1.types.InputChannel(chat),
1993
- participant: member,
1994
- banned_rights: new _2_tl_js_1.types.ChatBannedRights({
1995
- until_date: params?.untilDate ? (0, _1_utilities_js_1.toUnixTimestamp)(params.untilDate) : 0,
1996
- send_messages: params?.rights?.canSendMessages ? true : undefined,
1997
- send_audios: params?.rights?.canSendAudio ? true : undefined,
1998
- send_docs: params?.rights?.canSendDocuments ? true : undefined,
1999
- send_photos: params?.rights?.canSendPhotos ? true : undefined,
2000
- send_videos: params?.rights?.canSendVideos ? true : undefined,
2001
- send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
2002
- send_voices: params?.rights?.canSendVoice ? true : undefined,
2003
- send_polls: params?.rights?.canSendPolls ? true : undefined,
2004
- send_stickers: params?.rights?.canSendStickers ? true : undefined,
2005
- send_gifs: params?.rights?.canSendAnimations ? true : undefined,
2006
- send_games: params?.rights?.canSendGames ? true : undefined,
2007
- send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
2008
- embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
2009
- change_info: params?.rights?.canChangeInfo ? true : undefined,
2010
- invite_users: params?.rights?.canInviteUsers ? true : undefined,
2011
- pin_messages: params?.rights?.canPinMessages ? true : undefined,
2012
- manage_topics: params?.rights?.canManageTopics ? true : undefined,
2013
- }),
2014
- });
1848
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatMemberRights(chatId, memberId, params);
2015
1849
  }
2016
1850
  }
2017
1851
  exports.Client = Client;
2018
- _Client_parseText = function _Client_parseText(text, params) {
2019
- const entities_ = params?.entities ?? [];
2020
- const parseMode = params?.parseMode ?? __classPrivateFieldGet(this, _Client_parseMode, "f");
2021
- switch (parseMode) {
2022
- case null:
2023
- break;
2024
- case "HTML": {
2025
- const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
2026
- text = newText;
2027
- for (const entity of entitiesToPush) {
2028
- entities_.push(entity);
2029
- }
2030
- break;
2031
- }
2032
- default:
2033
- (0, _1_utilities_js_1.UNREACHABLE)();
2034
- }
2035
- const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
2036
- return [text, entities];
2037
- }, _Client_getMe = async function _Client_getMe() {
2038
- if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
2039
- return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
2040
- }
2041
- else {
2042
- const user = await this.getMe();
2043
- __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2044
- return user;
2045
- }
2046
- }, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
1852
+ _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
2047
1853
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
2048
1854
  }, _Client_queueHandleCtxUpdate = function _Client_queueHandleCtxUpdate(update) {
2049
1855
  __classPrivateFieldGet(this, _Client_updateManager, "f").getHandleUpdateQueue(_1_update_manager_js_1.UpdateManager.MAIN_BOX_ID).add(async () => {
@@ -2096,8 +1902,13 @@ _Client_parseText = function _Client_parseText(text, params) {
2096
1902
  await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdate(update);
2097
1903
  }
2098
1904
  return () => Promise.all(promises);
2099
- }, _Client_setMyInfo = async function _Client_setMyInfo(info) {
2100
- await this.api.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info });
2101
- }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
2102
- return this.api.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" });
1905
+ }, _Client_getMe = async function _Client_getMe() {
1906
+ if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
1907
+ return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
1908
+ }
1909
+ else {
1910
+ const user = await this.getMe();
1911
+ __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1912
+ return user;
1913
+ }
2103
1914
  };