@mtkruto/node 0.1.142 → 0.1.144

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.
Files changed (59) hide show
  1. package/esm/3_types.d.ts +1 -0
  2. package/esm/3_types.js +1 -0
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/0_message.js +9 -9
  6. package/esm/client/0_types.d.ts +1 -0
  7. package/esm/client/1_bot_info_manager.d.ts +30 -0
  8. package/esm/client/1_bot_info_manager.js +66 -0
  9. package/esm/client/1_file_manager.js +1 -1
  10. package/esm/client/1_network_statistics_manager.d.ts +19 -0
  11. package/esm/client/1_network_statistics_manager.js +48 -0
  12. package/esm/client/2_client_plain.js +4 -4
  13. package/esm/client/2_message_manager.d.ts +11 -2
  14. package/esm/client/2_message_manager.js +170 -1
  15. package/esm/client/3_callback_query_manager.js +1 -1
  16. package/esm/client/3_inline_query_manager.js +2 -1
  17. package/esm/client/4_client.d.ts +21 -12
  18. package/esm/client/4_client.js +134 -311
  19. package/esm/storage/0_storage.js +1 -1
  20. package/esm/tl/0_tl_raw_reader.js +3 -2
  21. package/esm/tl/0_tl_raw_writer.js +3 -3
  22. package/esm/transport/0_obfuscation.js +2 -2
  23. package/esm/transport/1_transport_abridged.js +1 -1
  24. package/esm/transport/1_transport_intermediate.js +1 -1
  25. package/esm/types/0__file_id.js +2 -2
  26. package/esm/types/0_chat_member_rights.d.ts +3 -0
  27. package/esm/types/0_chat_member_rights.js +45 -1
  28. package/esm/types/2_chat_member.d.ts +46 -0
  29. package/esm/types/2_chat_member.js +89 -0
  30. package/package.json +1 -1
  31. package/script/3_types.d.ts +1 -0
  32. package/script/3_types.js +1 -0
  33. package/script/4_constants.d.ts +1 -1
  34. package/script/4_constants.js +1 -1
  35. package/script/client/0_message.js +9 -9
  36. package/script/client/0_types.d.ts +1 -0
  37. package/script/client/1_bot_info_manager.d.ts +30 -0
  38. package/script/client/1_bot_info_manager.js +70 -0
  39. package/script/client/1_file_manager.js +1 -1
  40. package/script/client/1_network_statistics_manager.d.ts +19 -0
  41. package/script/client/1_network_statistics_manager.js +52 -0
  42. package/script/client/2_client_plain.js +4 -4
  43. package/script/client/2_message_manager.d.ts +11 -2
  44. package/script/client/2_message_manager.js +169 -0
  45. package/script/client/3_callback_query_manager.js +1 -1
  46. package/script/client/3_inline_query_manager.js +2 -1
  47. package/script/client/4_client.d.ts +21 -12
  48. package/script/client/4_client.js +131 -308
  49. package/script/storage/0_storage.js +1 -1
  50. package/script/tl/0_tl_raw_reader.js +3 -2
  51. package/script/tl/0_tl_raw_writer.js +3 -3
  52. package/script/transport/0_obfuscation.js +2 -2
  53. package/script/transport/1_transport_abridged.js +1 -1
  54. package/script/transport/1_transport_intermediate.js +1 -1
  55. package/script/types/0__file_id.js +2 -2
  56. package/script/types/0_chat_member_rights.d.ts +3 -0
  57. package/script/types/0_chat_member_rights.js +48 -0
  58. package/script/types/2_chat_member.d.ts +46 -0
  59. package/script/types/2_chat_member.js +93 -0
@@ -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);
@@ -324,6 +327,10 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
324
327
  }
325
328
  return this.setChatMemberRights(chatId, senderId, params);
326
329
  },
330
+ getChatAdministrators: () => {
331
+ const { chatId } = mustGetMsg();
332
+ return this.getChatAdministrators(chatId);
333
+ },
327
334
  react: (reactions, params) => {
328
335
  const { chatId, messageId } = mustGetMsg();
329
336
  return this.setReactions(chatId, messageId, reactions, params);
@@ -561,9 +568,12 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
561
568
  disconnect: client.disconnect.bind(client),
562
569
  };
563
570
  },
571
+ cdn: params?.cdn ?? false,
564
572
  ignoreOutgoing: __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f"),
565
573
  };
566
574
  __classPrivateFieldSet(this, _Client_updateManager, new _1_update_manager_js_1.UpdateManager(c), "f");
575
+ __classPrivateFieldSet(this, _Client_networkStatisticsManager, new _1_network_statistics_manager_js_1.NetworkStatisticsManager(c), "f");
576
+ __classPrivateFieldSet(this, _Client_botInfoManager, new _1_bot_info_manager_js_1.BotInfoManager(c), "f");
567
577
  __classPrivateFieldSet(this, _Client_fileManager, new _1_file_manager_js_1.FileManager(c), "f");
568
578
  __classPrivateFieldSet(this, _Client_reactionManager, new _1_reaction_manager_js_1.ReactionManager(c), "f");
569
579
  __classPrivateFieldSet(this, _Client_messageManager, new _2_message_manager_js_1.MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
@@ -574,16 +584,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
574
584
  const transportProvider = this.transportProvider;
575
585
  this.transportProvider = (params) => {
576
586
  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
- };
587
+ transport.connection.callback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback();
587
588
  return transport;
588
589
  };
589
590
  if (params?.defaultHandlers ?? true) {
@@ -693,7 +694,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
693
694
  release();
694
695
  }
695
696
  }
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) {
697
+ 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
698
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
698
699
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
699
700
  }, _Client_setAuth = async function _Client_setAuth(key) {
@@ -745,16 +746,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
745
746
  if (!this.apiHash) {
746
747
  throw new Error("apiHash not set");
747
748
  }
748
- if (typeof params === "undefined") {
749
- const loginType = (0, _1_utilities_js_1.mustPromptOneOf)("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
750
- if (loginType == "b") {
751
- params = (0, _1_utilities_js_1.mustPrompt)("Bot token:");
752
- }
753
- else {
754
- params = { phone: () => (0, _1_utilities_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_utilities_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_utilities_js_1.mustPrompt)("Password:") };
755
- }
756
- }
757
- dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof _2_tl_js_1.types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
758
749
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
759
750
  try {
760
751
  await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
@@ -768,6 +759,16 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
768
759
  throw err;
769
760
  }
770
761
  }
762
+ if (typeof params === "undefined") {
763
+ const loginType = (0, _1_utilities_js_1.mustPromptOneOf)("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
764
+ if (loginType == "b") {
765
+ params = (0, _1_utilities_js_1.mustPrompt)("Bot token:");
766
+ }
767
+ else {
768
+ params = { phone: () => (0, _1_utilities_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_utilities_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_utilities_js_1.mustPrompt)("Password:") };
769
+ }
770
+ }
771
+ dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof _2_tl_js_1.types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
771
772
  if (typeof params === "string") {
772
773
  while (true) {
773
774
  try {
@@ -905,7 +906,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
905
906
  */
906
907
  async start(params) {
907
908
  await this.connect();
908
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
909
909
  await this.authorize(params);
910
910
  }
911
911
  /**
@@ -1230,6 +1230,77 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1230
1230
  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
1231
  return this.storage.getEntity(type, id);
1232
1232
  }
1233
+ use(...middleware) {
1234
+ const composer = new _1_composer_js_1.Composer(...middleware);
1235
+ __classPrivateFieldSet(this, _Client_handle, (0, _1_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _1_composer_js_1.flatten)(composer)), "f");
1236
+ return composer;
1237
+ }
1238
+ branch(predicate, trueHandler_, falseHandler_) {
1239
+ const trueHandler = (0, _1_composer_js_1.flatten)(trueHandler_);
1240
+ const falseHandler = (0, _1_composer_js_1.flatten)(falseHandler_);
1241
+ return this.use(async (upd, next) => {
1242
+ if (await predicate(upd)) {
1243
+ await trueHandler(upd, next);
1244
+ }
1245
+ else {
1246
+ await falseHandler(upd, next);
1247
+ }
1248
+ });
1249
+ }
1250
+ filter(predicate, ...middleware) {
1251
+ const composer = new _1_composer_js_1.Composer(...middleware);
1252
+ this.branch(predicate, composer, _1_composer_js_1.skip);
1253
+ return composer;
1254
+ }
1255
+ on(filter, ...middleawre) {
1256
+ return this.filter((ctx) => {
1257
+ return (0, _0_filters_js_1.match)(filter, ctx);
1258
+ }, ...middleawre);
1259
+ }
1260
+ command(commands, ...middleawre) {
1261
+ const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1262
+ const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1263
+ const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1264
+ const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1265
+ for (const left of prefixes) {
1266
+ for (const right of prefixes) {
1267
+ if (left == right) {
1268
+ continue;
1269
+ }
1270
+ if (left.startsWith(right) || right.startsWith(left)) {
1271
+ throw new Error("Intersecting prefixes");
1272
+ }
1273
+ }
1274
+ }
1275
+ return this.on("message:text").filter((ctx) => {
1276
+ const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1277
+ if (prefixes_.length == 0) {
1278
+ return false;
1279
+ }
1280
+ const cmd = ctx.message.text.split(/\s/, 1)[0];
1281
+ const prefix = prefixes_.find((v) => cmd.startsWith(v));
1282
+ if (prefix === undefined) {
1283
+ return false;
1284
+ }
1285
+ if (cmd.includes("@")) {
1286
+ const username = cmd.split("@", 2)[1];
1287
+ if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1288
+ return false;
1289
+ }
1290
+ }
1291
+ const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1292
+ for (const command of commands_) {
1293
+ if (typeof command === "string" && (command.toLowerCase() == command_)) {
1294
+ return true;
1295
+ }
1296
+ else if (command instanceof RegExp && command.test(command_)) {
1297
+ return true;
1298
+ }
1299
+ }
1300
+ return false;
1301
+ }, ...middleawre);
1302
+ }
1303
+ //#endregion
1233
1304
  /**
1234
1305
  * Send a text message.
1235
1306
  *
@@ -1347,77 +1418,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1347
1418
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1348
1419
  return user;
1349
1420
  }
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
1421
  /**
1422
1422
  * Answer a callback query. Bot-only.
1423
1423
  *
@@ -1448,45 +1448,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1448
1448
  * @param messageThreadId The thread to send the chat action to.
1449
1449
  */
1450
1450
  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 });
1451
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").sendChatAction(chatId, action, params);
1490
1452
  }
1491
1453
  /**
1492
1454
  * Upload a file.
@@ -1504,21 +1466,13 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1504
1466
  * @param commands The commands to set.
1505
1467
  */
1506
1468
  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
- });
1469
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyCommands(commands, params);
1512
1470
  }
1513
1471
  /**
1514
1472
  * Get the bot's commands in the given scope and/or language. Bot-only.
1515
1473
  */
1516
1474
  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 }));
1475
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyCommands(params);
1522
1476
  }
1523
1477
  /**
1524
1478
  * Answer an inline query. Bot-only.
@@ -1536,8 +1490,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1536
1490
  * @method
1537
1491
  */
1538
1492
  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 ?? "" });
1493
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyDescription(params);
1541
1494
  }
1542
1495
  /**
1543
1496
  * Set the bot's name in the given language. Bot-only.
@@ -1545,8 +1498,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1545
1498
  * @method
1546
1499
  */
1547
1500
  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 ?? "" });
1501
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyName(params);
1550
1502
  }
1551
1503
  /**
1552
1504
  * Set the bot's short description in the given language. Bot-only.
@@ -1554,8 +1506,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1554
1506
  * @method
1555
1507
  */
1556
1508
  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 ?? "" });
1509
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyShortDescription(params);
1559
1510
  }
1560
1511
  /**
1561
1512
  * Get the bot's description in the given language. Bot-only.
@@ -1563,8 +1514,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1563
1514
  * @method
1564
1515
  */
1565
1516
  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);
1517
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyDescription(params);
1568
1518
  }
1569
1519
  /**
1570
1520
  * Set the bot's name in the given language. Bot-only.
@@ -1572,8 +1522,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1572
1522
  * @method
1573
1523
  */
1574
1524
  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);
1525
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyName(params);
1577
1526
  }
1578
1527
  /**
1579
1528
  * Get the bot's short description in the given language. Bot-only.
@@ -1581,8 +1530,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1581
1530
  * @method
1582
1531
  */
1583
1532
  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);
1533
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyShortDescription(params);
1586
1534
  }
1587
1535
  /**
1588
1536
  * Delete multiple messages.
@@ -1724,21 +1672,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1724
1672
  * @method
1725
1673
  */
1726
1674
  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 };
1675
+ return await __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getNetworkStatistics();
1742
1676
  }
1743
1677
  /**
1744
1678
  * Get chats from a chat list. User-only.
@@ -1825,19 +1759,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1825
1759
  * @param photo A photo to set as the chat's photo.
1826
1760
  */
1827
1761
  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
- }
1762
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatPhoto(chatId, photo, params);
1841
1763
  }
1842
1764
  /**
1843
1765
  * Delete a chat's photo.
@@ -1846,16 +1768,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1846
1768
  * @param chatId The identifier of the chat.
1847
1769
  */
1848
1770
  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
- }
1771
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteChatPhoto(chatId);
1859
1772
  }
1860
1773
  /**
1861
1774
  * Delete all messages sent by a specific member of a chat.
@@ -1904,46 +1817,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1904
1817
  * @param memberId The identifier of the member.
1905
1818
  */
1906
1819
  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
- }
1820
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId, params);
1947
1821
  }
1948
1822
  /**
1949
1823
  * Unban a member from a chat.
@@ -1953,16 +1827,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1953
1827
  * @param memberId The identifier of the member.
1954
1828
  */
1955
1829
  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
- });
1830
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
1966
1831
  }
1967
1832
  /**
1968
1833
  * Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.
@@ -1972,8 +1837,8 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1972
1837
  * @param memberId The identifier of the member.
1973
1838
  */
1974
1839
  async kickChatMember(chatId, memberId) {
1975
- await this.banChatMember(chatId, memberId);
1976
- await this.unbanChatMember(chatId, memberId);
1840
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId);
1841
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
1977
1842
  }
1978
1843
  /**
1979
1844
  * Set the rights of a chat member.
@@ -1983,67 +1848,20 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1983
1848
  * @param memberId The identifier of a member.
1984
1849
  */
1985
1850
  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
- });
1851
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatMemberRights(chatId, memberId, params);
1852
+ }
1853
+ /**
1854
+ * Get the administrators of a chat.
1855
+ *
1856
+ * @method
1857
+ * @param chatId The identifier of the chat.
1858
+ */
1859
+ async getChatAdministrators(chatId) {
1860
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").getChatAdministrators(chatId);
2015
1861
  }
2016
1862
  }
2017
1863
  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) {
1864
+ _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
2047
1865
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), _0_utilities_js_1.resolve);
2048
1866
  }, _Client_queueHandleCtxUpdate = function _Client_queueHandleCtxUpdate(update) {
2049
1867
  __classPrivateFieldGet(this, _Client_updateManager, "f").getHandleUpdateQueue(_1_update_manager_js_1.UpdateManager.MAIN_BOX_ID).add(async () => {
@@ -2096,8 +1914,13 @@ _Client_parseText = function _Client_parseText(text, params) {
2096
1914
  await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdate(update);
2097
1915
  }
2098
1916
  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 ?? "" });
1917
+ }, _Client_getMe = async function _Client_getMe() {
1918
+ if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
1919
+ return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
1920
+ }
1921
+ else {
1922
+ const user = await this.getMe();
1923
+ __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1924
+ return user;
1925
+ }
2103
1926
  };
@@ -305,7 +305,7 @@ class Storage {
305
305
  exports.Storage = Storage;
306
306
  _Storage_authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
307
307
  if (authKey != null) {
308
- __classPrivateFieldSet(this, _Storage_authKeyId, await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false)), "f");
308
+ __classPrivateFieldSet(this, _Storage_authKeyId, await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.subarray(-8), true, false)), "f");
309
309
  }
310
310
  else {
311
311
  __classPrivateFieldSet(this, _Storage_authKeyId, null, "f");