@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.
@@ -9,23 +9,24 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
9
9
  if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
10
10
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
11
11
  };
12
- var _Client_instances, _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;
12
+ 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;
13
13
  import { debug, gunzip, Mutex } from "../0_deps.js";
14
- import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, sha1, toUnixTimestamp, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
14
+ import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
15
15
  import { as, functions, Message_, MessageContainer, name, RPCResult, TLError, TLReader, types } from "../2_tl.js";
16
16
  import { StorageMemory } from "../3_storage.js";
17
- import { botCommandScopeToTlObject, constructUser, messageEntityToTlObject } from "../3_types.js";
17
+ import { constructUser } from "../3_types.js";
18
18
  import { ACK_THRESHOLD, APP_VERSION, DEVICE_MODEL, LANG_CODE, LANG_PACK, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, SYSTEM_LANG_CODE, SYSTEM_VERSION, USERNAME_TTL } from "../4_constants.js";
19
19
  import { AuthKeyUnregistered, FloodWait, Migrate, PasswordHashInvalid, PhoneNumberInvalid, SessionPasswordNeeded, upgradeInstance } from "../4_errors.js";
20
20
  import { ClientAbstract } from "./0_client_abstract.js";
21
21
  import { match } from "./0_filters.js";
22
- import { parseHtml } from "./0_html.js";
23
22
  import { decryptMessage, encryptMessage, getMessageId } from "./0_message.js";
24
23
  import { checkPassword } from "./0_password.js";
25
24
  import { ConnectionError } from "./0_types.js";
26
- import { getFileContents, getUsername, resolve } from "./0_utilities.js";
25
+ import { getUsername, resolve } from "./0_utilities.js";
26
+ import { BotInfoManager } from "./1_bot_info_manager.js";
27
27
  import { Composer, concat, flatten, skip } from "./1_composer.js";
28
28
  import { FileManager } from "./1_file_manager.js";
29
+ import { NetworkStatisticsManager } from "./1_network_statistics_manager.js";
29
30
  import { ReactionManager } from "./1_reaction_manager.js";
30
31
  import { UpdateManager } from "./1_update_manager.js";
31
32
  import { ClientPlain } from "./2_client_plain.js";
@@ -73,6 +74,8 @@ export class Client extends ClientAbstract {
73
74
  _Client_toAcknowledge.set(this, new Set());
74
75
  _Client_guaranteeUpdateDelivery.set(this, void 0);
75
76
  _Client_updateManager.set(this, void 0);
77
+ _Client_networkStatisticsManager.set(this, void 0);
78
+ _Client_botInfoManager.set(this, void 0);
76
79
  _Client_fileManager.set(this, void 0);
77
80
  _Client_reactionManager.set(this, void 0);
78
81
  _Client_messageManager.set(this, void 0);
@@ -557,9 +560,12 @@ export class Client extends ClientAbstract {
557
560
  disconnect: client.disconnect.bind(client),
558
561
  };
559
562
  },
563
+ cdn: params?.cdn ?? false,
560
564
  ignoreOutgoing: __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f"),
561
565
  };
562
566
  __classPrivateFieldSet(this, _Client_updateManager, new UpdateManager(c), "f");
567
+ __classPrivateFieldSet(this, _Client_networkStatisticsManager, new NetworkStatisticsManager(c), "f");
568
+ __classPrivateFieldSet(this, _Client_botInfoManager, new BotInfoManager(c), "f");
563
569
  __classPrivateFieldSet(this, _Client_fileManager, new FileManager(c), "f");
564
570
  __classPrivateFieldSet(this, _Client_reactionManager, new ReactionManager(c), "f");
565
571
  __classPrivateFieldSet(this, _Client_messageManager, new MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
@@ -570,16 +576,7 @@ export class Client extends ClientAbstract {
570
576
  const transportProvider = this.transportProvider;
571
577
  this.transportProvider = (params) => {
572
578
  const transport = transportProvider(params);
573
- transport.connection.callback = {
574
- read: async (count) => {
575
- const key = params.cdn ? "netstat_cdn_read" : "netstat_messages_read";
576
- await this.storage.incr([key], count);
577
- },
578
- write: async (count) => {
579
- const key = params.cdn ? "netstat_cdn_write" : "netstat_messages_write";
580
- await this.storage.incr([key], count);
581
- },
582
- };
579
+ transport.connection.callback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback();
583
580
  return transport;
584
581
  };
585
582
  if (params?.defaultHandlers ?? true) {
@@ -689,7 +686,7 @@ export class Client extends ClientAbstract {
689
686
  release();
690
687
  }
691
688
  }
692
- 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) {
689
+ 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) {
693
690
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
694
691
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
695
692
  }, _Client_setAuth = async function _Client_setAuth(key) {
@@ -1226,6 +1223,77 @@ export class Client extends ClientAbstract {
1226
1223
  const id = peer instanceof types.PeerUser ? peer.user_id : peer instanceof types.PeerChat ? peer.chat_id : peer instanceof types.PeerChannel ? peer.channel_id : UNREACHABLE();
1227
1224
  return this.storage.getEntity(type, id);
1228
1225
  }
1226
+ use(...middleware) {
1227
+ const composer = new Composer(...middleware);
1228
+ __classPrivateFieldSet(this, _Client_handle, concat(__classPrivateFieldGet(this, _Client_handle, "f"), flatten(composer)), "f");
1229
+ return composer;
1230
+ }
1231
+ branch(predicate, trueHandler_, falseHandler_) {
1232
+ const trueHandler = flatten(trueHandler_);
1233
+ const falseHandler = flatten(falseHandler_);
1234
+ return this.use(async (upd, next) => {
1235
+ if (await predicate(upd)) {
1236
+ await trueHandler(upd, next);
1237
+ }
1238
+ else {
1239
+ await falseHandler(upd, next);
1240
+ }
1241
+ });
1242
+ }
1243
+ filter(predicate, ...middleware) {
1244
+ const composer = new Composer(...middleware);
1245
+ this.branch(predicate, composer, skip);
1246
+ return composer;
1247
+ }
1248
+ on(filter, ...middleawre) {
1249
+ return this.filter((ctx) => {
1250
+ return match(filter, ctx);
1251
+ }, ...middleawre);
1252
+ }
1253
+ command(commands, ...middleawre) {
1254
+ const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1255
+ const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1256
+ const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1257
+ const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1258
+ for (const left of prefixes) {
1259
+ for (const right of prefixes) {
1260
+ if (left == right) {
1261
+ continue;
1262
+ }
1263
+ if (left.startsWith(right) || right.startsWith(left)) {
1264
+ throw new Error("Intersecting prefixes");
1265
+ }
1266
+ }
1267
+ }
1268
+ return this.on("message:text").filter((ctx) => {
1269
+ const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1270
+ if (prefixes_.length == 0) {
1271
+ return false;
1272
+ }
1273
+ const cmd = ctx.message.text.split(/\s/, 1)[0];
1274
+ const prefix = prefixes_.find((v) => cmd.startsWith(v));
1275
+ if (prefix === undefined) {
1276
+ return false;
1277
+ }
1278
+ if (cmd.includes("@")) {
1279
+ const username = cmd.split("@", 2)[1];
1280
+ if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1281
+ return false;
1282
+ }
1283
+ }
1284
+ const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1285
+ for (const command of commands_) {
1286
+ if (typeof command === "string" && (command.toLowerCase() == command_)) {
1287
+ return true;
1288
+ }
1289
+ else if (command instanceof RegExp && command.test(command_)) {
1290
+ return true;
1291
+ }
1292
+ }
1293
+ return false;
1294
+ }, ...middleawre);
1295
+ }
1296
+ //#endregion
1229
1297
  /**
1230
1298
  * Send a text message.
1231
1299
  *
@@ -1343,77 +1411,6 @@ export class Client extends ClientAbstract {
1343
1411
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1344
1412
  return user;
1345
1413
  }
1346
- use(...middleware) {
1347
- const composer = new Composer(...middleware);
1348
- __classPrivateFieldSet(this, _Client_handle, concat(__classPrivateFieldGet(this, _Client_handle, "f"), flatten(composer)), "f");
1349
- return composer;
1350
- }
1351
- branch(predicate, trueHandler_, falseHandler_) {
1352
- const trueHandler = flatten(trueHandler_);
1353
- const falseHandler = flatten(falseHandler_);
1354
- return this.use(async (upd, next) => {
1355
- if (await predicate(upd)) {
1356
- await trueHandler(upd, next);
1357
- }
1358
- else {
1359
- await falseHandler(upd, next);
1360
- }
1361
- });
1362
- }
1363
- filter(predicate, ...middleware) {
1364
- const composer = new Composer(...middleware);
1365
- this.branch(predicate, composer, skip);
1366
- return composer;
1367
- }
1368
- on(filter, ...middleawre) {
1369
- return this.filter((ctx) => {
1370
- return match(filter, ctx);
1371
- }, ...middleawre);
1372
- }
1373
- command(commands, ...middleawre) {
1374
- const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1375
- const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1376
- const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1377
- const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1378
- for (const left of prefixes) {
1379
- for (const right of prefixes) {
1380
- if (left == right) {
1381
- continue;
1382
- }
1383
- if (left.startsWith(right) || right.startsWith(left)) {
1384
- throw new Error("Intersecting prefixes");
1385
- }
1386
- }
1387
- }
1388
- return this.on("message:text").filter((ctx) => {
1389
- const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1390
- if (prefixes_.length == 0) {
1391
- return false;
1392
- }
1393
- const cmd = ctx.message.text.split(/\s/, 1)[0];
1394
- const prefix = prefixes_.find((v) => cmd.startsWith(v));
1395
- if (prefix === undefined) {
1396
- return false;
1397
- }
1398
- if (cmd.includes("@")) {
1399
- const username = cmd.split("@", 2)[1];
1400
- if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1401
- return false;
1402
- }
1403
- }
1404
- const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1405
- for (const command of commands_) {
1406
- if (typeof command === "string" && (command.toLowerCase() == command_)) {
1407
- return true;
1408
- }
1409
- else if (command instanceof RegExp && command.test(command_)) {
1410
- return true;
1411
- }
1412
- }
1413
- return false;
1414
- }, ...middleawre);
1415
- }
1416
- //#endregion
1417
1414
  /**
1418
1415
  * Answer a callback query. Bot-only.
1419
1416
  *
@@ -1444,45 +1441,7 @@ export class Client extends ClientAbstract {
1444
1441
  * @param messageThreadId The thread to send the chat action to.
1445
1442
  */
1446
1443
  async sendChatAction(chatId, action, params) {
1447
- let action_;
1448
- switch (action) {
1449
- case "type":
1450
- action_ = new types.SendMessageTypingAction();
1451
- break;
1452
- case "uploadPhoto":
1453
- action_ = new types.SendMessageUploadPhotoAction({ progress: 0 });
1454
- break;
1455
- case "recordVideo":
1456
- action_ = new types.SendMessageRecordVideoAction();
1457
- break;
1458
- case "uploadVideo":
1459
- action_ = new types.SendMessageRecordVideoAction();
1460
- break;
1461
- case "recordVoice":
1462
- action_ = new types.SendMessageRecordAudioAction();
1463
- break;
1464
- case "uploadAudio":
1465
- action_ = new types.SendMessageUploadAudioAction({ progress: 0 });
1466
- break;
1467
- case "uploadDocument":
1468
- action_ = new types.SendMessageUploadDocumentAction({ progress: 0 });
1469
- break;
1470
- case "chooseSticker":
1471
- action_ = new types.SendMessageChooseStickerAction();
1472
- break;
1473
- case "findLocation":
1474
- action_ = new types.SendMessageGeoLocationAction();
1475
- break;
1476
- case "recordVideoNote":
1477
- action_ = new types.SendMessageRecordRoundAction();
1478
- break;
1479
- case "uploadVideoNote":
1480
- action_ = new types.SendMessageUploadRoundAction({ progress: 0 });
1481
- break;
1482
- default:
1483
- throw new Error("Invalid chat action: " + action);
1484
- }
1485
- await this.api.messages.setTyping({ peer: await this.getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId });
1444
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendChatAction(chatId, action, params);
1486
1445
  }
1487
1446
  /**
1488
1447
  * Upload a file.
@@ -1500,21 +1459,13 @@ export class Client extends ClientAbstract {
1500
1459
  * @param commands The commands to set.
1501
1460
  */
1502
1461
  async setMyCommands(commands, params) {
1503
- await this.api.bots.setBotCommands({
1504
- commands: commands.map((v) => new types.BotCommand(v)),
1505
- lang_code: params?.languageCode ?? "",
1506
- scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
1507
- });
1462
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyCommands(commands, params);
1508
1463
  }
1509
1464
  /**
1510
1465
  * Get the bot's commands in the given scope and/or language. Bot-only.
1511
1466
  */
1512
1467
  async getMyCommands(params) {
1513
- const commands_ = await this.api.bots.getBotCommands({
1514
- lang_code: params?.languageCode ?? "",
1515
- scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
1516
- });
1517
- return commands_.map((v) => ({ command: v.command, description: v.description }));
1468
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyCommands(params);
1518
1469
  }
1519
1470
  /**
1520
1471
  * Answer an inline query. Bot-only.
@@ -1532,8 +1483,7 @@ export class Client extends ClientAbstract {
1532
1483
  * @method
1533
1484
  */
1534
1485
  async setMyDescription(params) {
1535
- await this.storage.assertBot("setMyDescription");
1536
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
1486
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyDescription(params);
1537
1487
  }
1538
1488
  /**
1539
1489
  * Set the bot's name in the given language. Bot-only.
@@ -1541,8 +1491,7 @@ export class Client extends ClientAbstract {
1541
1491
  * @method
1542
1492
  */
1543
1493
  async setMyName(params) {
1544
- await this.storage.assertBot("setMyName");
1545
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
1494
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyName(params);
1546
1495
  }
1547
1496
  /**
1548
1497
  * Set the bot's short description in the given language. Bot-only.
@@ -1550,8 +1499,7 @@ export class Client extends ClientAbstract {
1550
1499
  * @method
1551
1500
  */
1552
1501
  async setMyShortDescription(params) {
1553
- await this.storage.assertBot("setMyShortDescription");
1554
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
1502
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyShortDescription(params);
1555
1503
  }
1556
1504
  /**
1557
1505
  * Get the bot's description in the given language. Bot-only.
@@ -1559,8 +1507,7 @@ export class Client extends ClientAbstract {
1559
1507
  * @method
1560
1508
  */
1561
1509
  async getMyDescription(params) {
1562
- await this.storage.assertBot("getMyDescription");
1563
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
1510
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyDescription(params);
1564
1511
  }
1565
1512
  /**
1566
1513
  * Set the bot's name in the given language. Bot-only.
@@ -1568,8 +1515,7 @@ export class Client extends ClientAbstract {
1568
1515
  * @method
1569
1516
  */
1570
1517
  async getMyName(params) {
1571
- await this.storage.assertBot("getMyName");
1572
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
1518
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyName(params);
1573
1519
  }
1574
1520
  /**
1575
1521
  * Get the bot's short description in the given language. Bot-only.
@@ -1577,8 +1523,7 @@ export class Client extends ClientAbstract {
1577
1523
  * @method
1578
1524
  */
1579
1525
  async getMyShortDescription(params) {
1580
- await this.storage.assertBot("getMyShortDescription");
1581
- return await __classPrivateFieldGet(this, _Client_instances, "m", _Client_getMyInfo).call(this, params?.languageCode).then((v) => v.about);
1526
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyShortDescription(params);
1582
1527
  }
1583
1528
  /**
1584
1529
  * Delete multiple messages.
@@ -1720,21 +1665,7 @@ export class Client extends ClientAbstract {
1720
1665
  * @method
1721
1666
  */
1722
1667
  async getNetworkStatistics() {
1723
- const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
1724
- this.storage.get(["netstat_messages_read"]),
1725
- this.storage.get(["netstat_messages_write"]),
1726
- this.storage.get(["netstat_cdn_read"]),
1727
- this.storage.get(["netstat_cdn_write"]),
1728
- ]);
1729
- const messages = {
1730
- sent: Number(messagesWrite || 0),
1731
- received: Number(messagesRead || 0),
1732
- };
1733
- const cdn = {
1734
- sent: Number(cdnWrite || 0),
1735
- received: Number(cdnRead || 0),
1736
- };
1737
- return { messages, cdn };
1668
+ return await __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getNetworkStatistics();
1738
1669
  }
1739
1670
  /**
1740
1671
  * Get chats from a chat list. User-only.
@@ -1821,19 +1752,7 @@ export class Client extends ClientAbstract {
1821
1752
  * @param photo A photo to set as the chat's photo.
1822
1753
  */
1823
1754
  async setChatPhoto(chatId, photo, params) {
1824
- const peer = await this.getInputPeer(chatId);
1825
- if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
1826
- UNREACHABLE();
1827
- }
1828
- const [contents, fileName] = await getFileContents(photo);
1829
- const file = await this.upload(contents, { fileName: params?.fileName ?? fileName, chunkSize: params?.chunkSize, signal: params?.signal });
1830
- const photo_ = new types.InputChatUploadedPhoto({ file });
1831
- if (peer instanceof types.InputPeerChannel) {
1832
- await this.api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: photo_ });
1833
- }
1834
- else if (peer instanceof types.InputPeerChat) {
1835
- await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: photo_ });
1836
- }
1755
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatPhoto(chatId, photo, params);
1837
1756
  }
1838
1757
  /**
1839
1758
  * Delete a chat's photo.
@@ -1842,16 +1761,7 @@ export class Client extends ClientAbstract {
1842
1761
  * @param chatId The identifier of the chat.
1843
1762
  */
1844
1763
  async deleteChatPhoto(chatId) {
1845
- const peer = await this.getInputPeer(chatId);
1846
- if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
1847
- UNREACHABLE();
1848
- }
1849
- if (peer instanceof types.InputPeerChannel) {
1850
- await this.api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: new types.InputChatPhotoEmpty() });
1851
- }
1852
- else if (peer instanceof types.InputPeerChat) {
1853
- await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: new types.InputChatPhotoEmpty() });
1854
- }
1764
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteChatPhoto(chatId);
1855
1765
  }
1856
1766
  /**
1857
1767
  * Delete all messages sent by a specific member of a chat.
@@ -1900,46 +1810,7 @@ export class Client extends ClientAbstract {
1900
1810
  * @param memberId The identifier of the member.
1901
1811
  */
1902
1812
  async banChatMember(chatId, memberId, params) {
1903
- const chat = await this.getInputPeer(chatId);
1904
- if (!(chat instanceof types.InputPeerChannel) && !(chat instanceof types.InputPeerChat)) {
1905
- throw new Error("Invalid chat ID");
1906
- }
1907
- const member = await this.getInputPeer(memberId);
1908
- if (chat instanceof types.InputPeerChannel) {
1909
- if (params?.deleteMessages) {
1910
- try {
1911
- await this.deleteChatMemberMessages(chatId, memberId);
1912
- }
1913
- catch {
1914
- //
1915
- }
1916
- }
1917
- await this.api.channels.editBanned({
1918
- channel: new types.InputChannel(chat),
1919
- participant: member,
1920
- banned_rights: new types.ChatBannedRights({
1921
- until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
1922
- view_messages: true,
1923
- send_messages: true,
1924
- send_media: true,
1925
- send_stickers: true,
1926
- send_gifs: true,
1927
- send_games: true,
1928
- send_inline: true,
1929
- embed_links: true,
1930
- }),
1931
- });
1932
- }
1933
- else if (chat instanceof types.InputPeerChat) {
1934
- if (!(member instanceof types.InputPeerUser)) {
1935
- throw new Error("Invalid user ID");
1936
- }
1937
- await this.api.messages.deleteChatUser({
1938
- chat_id: chat.chat_id,
1939
- user_id: new types.InputUser(member),
1940
- revoke_history: params?.deleteMessages ? true : undefined,
1941
- });
1942
- }
1813
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId, params);
1943
1814
  }
1944
1815
  /**
1945
1816
  * Unban a member from a chat.
@@ -1949,16 +1820,7 @@ export class Client extends ClientAbstract {
1949
1820
  * @param memberId The identifier of the member.
1950
1821
  */
1951
1822
  async unbanChatMember(chatId, memberId) {
1952
- const chat = await this.getInputPeer(chatId);
1953
- if (!(chat instanceof types.InputPeerChannel)) {
1954
- throw new Error("Invalid chat ID");
1955
- }
1956
- const member = await this.getInputPeer(memberId);
1957
- await this.api.channels.editBanned({
1958
- channel: new types.InputChannel(chat),
1959
- participant: member,
1960
- banned_rights: new types.ChatBannedRights({ until_date: 0 }),
1961
- });
1823
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
1962
1824
  }
1963
1825
  /**
1964
1826
  * Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.
@@ -1968,8 +1830,8 @@ export class Client extends ClientAbstract {
1968
1830
  * @param memberId The identifier of the member.
1969
1831
  */
1970
1832
  async kickChatMember(chatId, memberId) {
1971
- await this.banChatMember(chatId, memberId);
1972
- await this.unbanChatMember(chatId, memberId);
1833
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId);
1834
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
1973
1835
  }
1974
1836
  /**
1975
1837
  * Set the rights of a chat member.
@@ -1979,66 +1841,10 @@ export class Client extends ClientAbstract {
1979
1841
  * @param memberId The identifier of a member.
1980
1842
  */
1981
1843
  async setChatMemberRights(chatId, memberId, params) {
1982
- const chat = await this.getInputPeer(chatId);
1983
- if (!(chat instanceof types.InputPeerChannel)) {
1984
- throw new Error("Invalid chat ID");
1985
- }
1986
- const member = await this.getInputPeer(memberId);
1987
- await this.api.channels.editBanned({
1988
- channel: new types.InputChannel(chat),
1989
- participant: member,
1990
- banned_rights: new types.ChatBannedRights({
1991
- until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
1992
- send_messages: params?.rights?.canSendMessages ? true : undefined,
1993
- send_audios: params?.rights?.canSendAudio ? true : undefined,
1994
- send_docs: params?.rights?.canSendDocuments ? true : undefined,
1995
- send_photos: params?.rights?.canSendPhotos ? true : undefined,
1996
- send_videos: params?.rights?.canSendVideos ? true : undefined,
1997
- send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
1998
- send_voices: params?.rights?.canSendVoice ? true : undefined,
1999
- send_polls: params?.rights?.canSendPolls ? true : undefined,
2000
- send_stickers: params?.rights?.canSendStickers ? true : undefined,
2001
- send_gifs: params?.rights?.canSendAnimations ? true : undefined,
2002
- send_games: params?.rights?.canSendGames ? true : undefined,
2003
- send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
2004
- embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
2005
- change_info: params?.rights?.canChangeInfo ? true : undefined,
2006
- invite_users: params?.rights?.canInviteUsers ? true : undefined,
2007
- pin_messages: params?.rights?.canPinMessages ? true : undefined,
2008
- manage_topics: params?.rights?.canManageTopics ? true : undefined,
2009
- }),
2010
- });
1844
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatMemberRights(chatId, memberId, params);
2011
1845
  }
2012
1846
  }
2013
- _Client_parseText = function _Client_parseText(text, params) {
2014
- const entities_ = params?.entities ?? [];
2015
- const parseMode = params?.parseMode ?? __classPrivateFieldGet(this, _Client_parseMode, "f");
2016
- switch (parseMode) {
2017
- case null:
2018
- break;
2019
- case "HTML": {
2020
- const [newText, entitiesToPush] = parseHtml(text);
2021
- text = newText;
2022
- for (const entity of entitiesToPush) {
2023
- entities_.push(entity);
2024
- }
2025
- break;
2026
- }
2027
- default:
2028
- UNREACHABLE();
2029
- }
2030
- const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
2031
- return [text, entities];
2032
- }, _Client_getMe = async function _Client_getMe() {
2033
- if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
2034
- return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
2035
- }
2036
- else {
2037
- const user = await this.getMe();
2038
- __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2039
- return user;
2040
- }
2041
- }, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
1847
+ _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
2042
1848
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
2043
1849
  }, _Client_queueHandleCtxUpdate = function _Client_queueHandleCtxUpdate(update) {
2044
1850
  __classPrivateFieldGet(this, _Client_updateManager, "f").getHandleUpdateQueue(UpdateManager.MAIN_BOX_ID).add(async () => {
@@ -2091,8 +1897,13 @@ _Client_parseText = function _Client_parseText(text, params) {
2091
1897
  await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdate(update);
2092
1898
  }
2093
1899
  return () => Promise.all(promises);
2094
- }, _Client_setMyInfo = async function _Client_setMyInfo(info) {
2095
- await this.api.bots.setBotInfo({ bot: new types.InputUserSelf(), ...info });
2096
- }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
2097
- return this.api.bots.getBotInfo({ bot: new types.InputUserSelf(), lang_code: languageCode ?? "" });
1900
+ }, _Client_getMe = async function _Client_getMe() {
1901
+ if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
1902
+ return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
1903
+ }
1904
+ else {
1905
+ const user = await this.getMe();
1906
+ __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1907
+ return user;
1908
+ }
2098
1909
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtkruto/node",
3
- "version": "0.1.142",
3
+ "version": "0.1.143",
4
4
  "description": "MTKruto for Node.js",
5
5
  "author": "Roj <rojvv@icloud.com>",
6
6
  "repository": {
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
6
  export declare const LAYER = 169;
7
- export declare const APP_VERSION = "MTKruto 0.1.142";
7
+ export declare const APP_VERSION = "MTKruto 0.1.143";
8
8
  export declare const DEVICE_MODEL: string;
9
9
  export declare const LANG_CODE: string;
10
10
  export declare const LANG_PACK = "";
@@ -79,7 +79,7 @@ exports.PUBLIC_KEYS = Object.freeze([
79
79
  ]);
80
80
  exports.INITIAL_DC = "2";
81
81
  exports.LAYER = 169;
82
- exports.APP_VERSION = "MTKruto 0.1.142";
82
+ exports.APP_VERSION = "MTKruto 0.1.143";
83
83
  // @ts-ignore: lib
84
84
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
85
85
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -34,6 +34,7 @@ export interface C {
34
34
  parseMode: ParseMode;
35
35
  apiFactory: ApiFactory;
36
36
  ignoreOutgoing: boolean | null;
37
+ cdn: boolean;
37
38
  }
38
39
  export declare class ConnectionError extends Error {
39
40
  }
@@ -0,0 +1,30 @@
1
+ import { BotCommand } from "../3_types.js";
2
+ import { GetMyCommandsParams, SetMyCommandsParams } from "./0_params.js";
3
+ import { C } from "./0_types.js";
4
+ export declare class BotInfoManager {
5
+ #private;
6
+ constructor(c: C);
7
+ setMyDescription(params?: {
8
+ description?: string;
9
+ languageCode?: string;
10
+ }): Promise<void>;
11
+ setMyName(params?: {
12
+ name?: string;
13
+ languageCode?: string;
14
+ }): Promise<void>;
15
+ setMyShortDescription(params?: {
16
+ shortDescription?: string;
17
+ languageCode?: string;
18
+ }): Promise<void>;
19
+ getMyDescription(params?: {
20
+ languageCode?: string;
21
+ }): Promise<string>;
22
+ getMyName(params?: {
23
+ languageCode?: string;
24
+ }): Promise<string>;
25
+ getMyShortDescription(params?: {
26
+ languageCode?: string;
27
+ }): Promise<string>;
28
+ getMyCommands(params?: GetMyCommandsParams): Promise<BotCommand[]>;
29
+ setMyCommands(commands: BotCommand[], params?: SetMyCommandsParams): Promise<void>;
30
+ }