@mtkruto/node 0.1.140 → 0.1.142

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 (45) hide show
  1. package/esm/4_constants.d.ts +1 -1
  2. package/esm/4_constants.js +1 -1
  3. package/esm/5_client.d.ts +1 -0
  4. package/esm/5_client.js +1 -0
  5. package/esm/client/0_types.d.ts +1 -0
  6. package/esm/client/1_reaction_manager.d.ts +9 -0
  7. package/esm/client/1_reaction_manager.js +84 -0
  8. package/esm/client/2_message_manager.d.ts +13 -1
  9. package/esm/client/2_message_manager.js +130 -29
  10. package/esm/client/3_callback_query_manager.d.ts +16 -0
  11. package/esm/client/3_callback_query_manager.js +36 -0
  12. package/esm/client/3_chat_list_manager.d.ts +5 -9
  13. package/esm/client/3_chat_list_manager.js +190 -103
  14. package/esm/client/3_inline_query_manager.d.ts +16 -0
  15. package/esm/client/3_inline_query_manager.js +48 -0
  16. package/esm/client/4_client.d.ts +10 -10
  17. package/esm/client/4_client.js +128 -315
  18. package/esm/client/5_session_string.d.ts +3 -0
  19. package/esm/client/5_session_string.js +22 -0
  20. package/esm/connection/1_connection_web_socket.js +1 -1
  21. package/package.json +1 -1
  22. package/script/4_constants.d.ts +1 -1
  23. package/script/4_constants.js +1 -1
  24. package/script/5_client.d.ts +1 -0
  25. package/script/5_client.js +1 -0
  26. package/script/client/0_types.d.ts +1 -0
  27. package/script/client/1_reaction_manager.d.ts +9 -0
  28. package/script/client/1_reaction_manager.js +88 -0
  29. package/script/client/2_message_manager.d.ts +13 -1
  30. package/script/client/2_message_manager.js +129 -28
  31. package/script/client/3_callback_query_manager.d.ts +16 -0
  32. package/script/client/3_callback_query_manager.js +40 -0
  33. package/script/client/3_chat_list_manager.d.ts +5 -9
  34. package/script/client/3_chat_list_manager.js +187 -100
  35. package/script/client/3_inline_query_manager.d.ts +16 -0
  36. package/script/client/3_inline_query_manager.js +52 -0
  37. package/script/client/4_client.d.ts +10 -10
  38. package/script/client/4_client.js +126 -313
  39. package/script/client/5_session_string.d.ts +3 -0
  40. package/script/client/5_session_string.js +27 -0
  41. package/script/connection/1_connection_web_socket.js +1 -1
  42. package/esm/client/3_reaction_manager.d.ts +0 -16
  43. package/esm/client/3_reaction_manager.js +0 -61
  44. package/script/client/3_reaction_manager.d.ts +0 -16
  45. package/script/client/3_reaction_manager.js +0 -65
@@ -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_messageManager, _Client_chatListManager, _Client_reactionManager, _Client_parseMode, _Client_publicKeys, _Client_autoStart, _Client_ignoreOutgoing, _Client_prefixes, _Client_namespaceProxies, _Client_constructContext, _Client_propagateConnectionState, _Client_lastPropagatedConnectionState, _Client_storageInited, _Client_setAuth, _Client_authKeyWasCreated, _Client_connectMutex, _Client_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_usernameResolver, _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_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;
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");
@@ -29,11 +29,13 @@ const _0_types_js_1 = require("./0_types.js");
29
29
  const _0_utilities_js_1 = require("./0_utilities.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_reaction_manager_js_1 = require("./1_reaction_manager.js");
32
33
  const _1_update_manager_js_1 = require("./1_update_manager.js");
33
34
  const _2_client_plain_js_1 = require("./2_client_plain.js");
34
35
  const _2_message_manager_js_1 = require("./2_message_manager.js");
36
+ const _3_callback_query_manager_js_1 = require("./3_callback_query_manager.js");
35
37
  const _3_chat_list_manager_js_1 = require("./3_chat_list_manager.js");
36
- const _3_reaction_manager_js_1 = require("./3_reaction_manager.js");
38
+ const _3_inline_query_manager_js_1 = require("./3_inline_query_manager.js");
37
39
  const d = (0, _0_deps_js_1.debug)("Client");
38
40
  const dAuth = (0, _0_deps_js_1.debug)("Client/authorize");
39
41
  const dRecv = (0, _0_deps_js_1.debug)("Client/receiveLoop");
@@ -76,9 +78,11 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
76
78
  _Client_guaranteeUpdateDelivery.set(this, void 0);
77
79
  _Client_updateManager.set(this, void 0);
78
80
  _Client_fileManager.set(this, void 0);
81
+ _Client_reactionManager.set(this, void 0);
79
82
  _Client_messageManager.set(this, void 0);
83
+ _Client_callbackQueryManager.set(this, void 0);
84
+ _Client_inlineQueryManager.set(this, void 0);
80
85
  _Client_chatListManager.set(this, void 0);
81
- _Client_reactionManager.set(this, void 0);
82
86
  Object.defineProperty(this, "storage", {
83
87
  enumerable: true,
84
88
  configurable: true,
@@ -451,7 +455,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
451
455
  }).bind(this)
452
456
  });
453
457
  _Client_storageInited.set(this, false);
454
- _Client_authKeyWasCreated.set(this, true);
455
458
  _Client_connectMutex.set(this, new _0_deps_js_1.Mutex());
456
459
  _Client_connectionInited.set(this, false);
457
460
  _Client_lastPropagatedAuthorizationState.set(this, null);
@@ -489,10 +492,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
489
492
  })
490
493
  });
491
494
  _Client_lastGetMe.set(this, null);
492
- _Client_usernameResolver.set(this, async (v) => {
493
- const inputPeer = await this.getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
494
- return new _2_tl_js_1.types.InputUser(inputPeer);
495
- });
496
495
  //#region Composer
497
496
  _Client_handle.set(this, _1_composer_js_1.skip);
498
497
  this.storage = storage ?? new _3_storage_js_1.StorageMemory();
@@ -550,7 +549,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
550
549
  api: client.api,
551
550
  connect: async () => {
552
551
  await client.connect();
553
- if (dcId != this.dcId) {
552
+ if (dcId && dcId != this.dcId) {
554
553
  let dc = String(dcId);
555
554
  if (this.dcId < 0) {
556
555
  dc += "-test";
@@ -562,12 +561,15 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
562
561
  disconnect: client.disconnect.bind(client),
563
562
  };
564
563
  },
564
+ ignoreOutgoing: __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f"),
565
565
  };
566
566
  __classPrivateFieldSet(this, _Client_updateManager, new _1_update_manager_js_1.UpdateManager(c), "f");
567
567
  __classPrivateFieldSet(this, _Client_fileManager, new _1_file_manager_js_1.FileManager(c), "f");
568
+ __classPrivateFieldSet(this, _Client_reactionManager, new _1_reaction_manager_js_1.ReactionManager(c), "f");
568
569
  __classPrivateFieldSet(this, _Client_messageManager, new _2_message_manager_js_1.MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
570
+ __classPrivateFieldSet(this, _Client_callbackQueryManager, new _3_callback_query_manager_js_1.CallbackQueryManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
571
+ __classPrivateFieldSet(this, _Client_inlineQueryManager, new _3_inline_query_manager_js_1.InlineQueryManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
569
572
  __classPrivateFieldSet(this, _Client_chatListManager, new _3_chat_list_manager_js_1.ChatListManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
570
- __classPrivateFieldSet(this, _Client_reactionManager, new _3_reaction_manager_js_1.ReactionManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
571
573
  __classPrivateFieldGet(this, _Client_updateManager, "f").setUpdateHandler(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).bind(this));
572
574
  const transportProvider = this.transportProvider;
573
575
  this.transportProvider = (params) => {
@@ -632,10 +634,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
632
634
  * @param dc The DC to change to.
633
635
  */
634
636
  async setDc(dc) {
635
- if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
636
- await this.storage.initialize();
637
- __classPrivateFieldSet(this, _Client_storageInited, true, "f");
638
- }
637
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
639
638
  if (await this.storage.getDc() != dc) {
640
639
  await this.storage.setDc(dc);
641
640
  await this.storage.setAuthKey(null);
@@ -654,13 +653,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
654
653
  }
655
654
  const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
656
655
  try {
657
- if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
658
- await this.storage.initialize();
659
- if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
660
- await this.storage.deleteUpdates();
661
- }
662
- __classPrivateFieldSet(this, _Client_storageInited, true, "f");
663
- }
656
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
664
657
  const authKey = await this.storage.getAuthKey();
665
658
  if (authKey == null) {
666
659
  const plain = new _2_client_plain_js_1.ClientPlain({ initialDc: this.initialDc, transportProvider: this.transportProvider, cdn: this.cdn, publicKeys: __classPrivateFieldGet(this, _Client_publicKeys, "f") });
@@ -681,7 +674,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
681
674
  __classPrivateFieldGet(this, _Client_state, "f").salt = await this.storage.getServerSalt() ?? 0n;
682
675
  }
683
676
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAuth).call(this, authKey);
684
- __classPrivateFieldSet(this, _Client_authKeyWasCreated, false, "f");
685
677
  }
686
678
  const dc = await this.storage.getDc();
687
679
  if (dc != null) {
@@ -701,13 +693,21 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
701
693
  release();
702
694
  }
703
695
  }
704
- 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_messageManager = new WeakMap(), _Client_chatListManager = new WeakMap(), _Client_reactionManager = 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_authKeyWasCreated = new WeakMap(), _Client_connectMutex = new WeakMap(), _Client_connectionInited = new WeakMap(), _Client_lastPropagatedAuthorizationState = new WeakMap(), _Client_selfId = new WeakMap(), _Client_pingLoopAbortSignal = new WeakMap(), _Client_pingInterval = new WeakMap(), _Client_lastUpdates = new WeakMap(), _Client_pingLoopStarted = new WeakMap(), _Client_autoStarted = new WeakMap(), _Client_lastMsgId = new WeakMap(), _Client_handleInvokeError = new WeakMap(), _Client_lastGetMe = new WeakMap(), _Client_usernameResolver = new WeakMap(), _Client_handle = new WeakMap(), _Client_instances = new WeakSet(), _Client_propagateConnectionState = function _Client_propagateConnectionState(connectionState) {
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) {
705
697
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
706
698
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
707
699
  }, _Client_setAuth = async function _Client_setAuth(key) {
708
700
  const hash = await (0, _1_utilities_js_1.sha1)(key);
709
701
  const id = (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false);
710
702
  __classPrivateFieldSet(this, _Client_auth, { key, id }, "f");
703
+ }, _Client_initStorage = async function _Client_initStorage() {
704
+ if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
705
+ await this.storage.initialize();
706
+ if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
707
+ await this.storage.deleteUpdates();
708
+ }
709
+ __classPrivateFieldSet(this, _Client_storageInited, true, "f");
710
+ }
711
711
  }, exports.handleMigrationError)](err) {
712
712
  let newDc = String(err.dc);
713
713
  if (Math.abs(this.dcId) >= 10000) {
@@ -901,16 +901,11 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
901
901
  }
902
902
  }
903
903
  /**
904
- * Same as calling `.connect()` followed by `.authorize(params)` if the session didn't have an auth key.
904
+ * Same as calling `.connect()` followed by `.authorize(params)`.
905
905
  */
906
906
  async start(params) {
907
907
  await this.connect();
908
908
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
909
- if (!__classPrivateFieldGet(this, _Client_authKeyWasCreated, "f")) {
910
- (0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("start"));
911
- (0, _1_utilities_js_1.drop)(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("start"));
912
- return;
913
- }
914
909
  await this.authorize(params);
915
910
  }
916
911
  /**
@@ -1170,6 +1165,10 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1170
1165
  const channels = await this.api.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel({ channel_id: channelId, access_hash: 0n })] });
1171
1166
  return channels.chats[0][_2_tl_js_1.as](_2_tl_js_1.types.Channel).access_hash ?? 0n;
1172
1167
  }, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
1168
+ const idn = Number(id);
1169
+ if (!isNaN(idn)) {
1170
+ id = idn;
1171
+ }
1173
1172
  if (typeof id === "string") {
1174
1173
  id = (0, _0_utilities_js_1.getUsername)(id);
1175
1174
  let userId = 0n;
@@ -1348,6 +1347,77 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1348
1347
  __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1349
1348
  return user;
1350
1349
  }
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
1351
1421
  /**
1352
1422
  * Answer a callback query. Bot-only.
1353
1423
  *
@@ -1355,13 +1425,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1355
1425
  * @param id ID of the callback query to answer.
1356
1426
  */
1357
1427
  async answerCallbackQuery(id, params) {
1358
- await this.storage.assertBot("answerCallbackQuery");
1359
- await this.api.messages.setBotCallbackAnswer({
1360
- query_id: BigInt(id),
1361
- cache_time: params?.cacheTime ?? 0,
1362
- message: params?.text,
1363
- alert: params?.alert ? true : undefined,
1364
- });
1428
+ await __classPrivateFieldGet(this, _Client_callbackQueryManager, "f").answerCallbackQuery(id, params);
1365
1429
  }
1366
1430
  /**
1367
1431
  * Send a poll.
@@ -1464,86 +1528,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1464
1528
  * @param results The results to answer with.
1465
1529
  */
1466
1530
  async answerInlineQuery(id, results, params) {
1467
- await this.api.messages.setInlineBotResults({
1468
- query_id: BigInt(id),
1469
- results: await Promise.all(results.map((v) => (0, _3_types_js_1.inlineQueryResultToTlObject)(v, __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).bind(this), __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this)))),
1470
- cache_time: params?.cacheTime ?? 300,
1471
- private: params?.isPersonal ? true : undefined,
1472
- switch_webview: params?.button && params.button.webApp ? new _2_tl_js_1.types.InlineBotWebView({ text: params.button.text, url: params.button.webApp.url }) : undefined,
1473
- switch_pm: params?.button && params.button.startParameter ? new _2_tl_js_1.types.InlineBotSwitchPM({ text: params.button.text, start_param: params.button.startParameter }) : undefined,
1474
- gallery: params?.isGallery ? true : undefined,
1475
- next_offset: params?.nextOffset,
1476
- });
1477
- }
1478
- use(...middleware) {
1479
- const composer = new _1_composer_js_1.Composer(...middleware);
1480
- __classPrivateFieldSet(this, _Client_handle, (0, _1_composer_js_1.concat)(__classPrivateFieldGet(this, _Client_handle, "f"), (0, _1_composer_js_1.flatten)(composer)), "f");
1481
- return composer;
1482
- }
1483
- branch(predicate, trueHandler_, falseHandler_) {
1484
- const trueHandler = (0, _1_composer_js_1.flatten)(trueHandler_);
1485
- const falseHandler = (0, _1_composer_js_1.flatten)(falseHandler_);
1486
- return this.use(async (upd, next) => {
1487
- if (await predicate(upd)) {
1488
- await trueHandler(upd, next);
1489
- }
1490
- else {
1491
- await falseHandler(upd, next);
1492
- }
1493
- });
1494
- }
1495
- filter(predicate, ...middleware) {
1496
- const composer = new _1_composer_js_1.Composer(...middleware);
1497
- this.branch(predicate, composer, _1_composer_js_1.skip);
1498
- return composer;
1499
- }
1500
- on(filter, ...middleawre) {
1501
- return this.filter((ctx) => {
1502
- return (0, _0_filters_js_1.match)(filter, ctx);
1503
- }, ...middleawre);
1504
- }
1505
- command(commands, ...middleawre) {
1506
- const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1507
- const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1508
- const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1509
- const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1510
- for (const left of prefixes) {
1511
- for (const right of prefixes) {
1512
- if (left == right) {
1513
- continue;
1514
- }
1515
- if (left.startsWith(right) || right.startsWith(left)) {
1516
- throw new Error("Intersecting prefixes");
1517
- }
1518
- }
1519
- }
1520
- return this.on("message:text").filter((ctx) => {
1521
- const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1522
- if (prefixes_.length == 0) {
1523
- return false;
1524
- }
1525
- const cmd = ctx.message.text.split(/\s/, 1)[0];
1526
- const prefix = prefixes_.find((v) => cmd.startsWith(v));
1527
- if (prefix === undefined) {
1528
- return false;
1529
- }
1530
- if (cmd.includes("@")) {
1531
- const username = cmd.split("@", 2)[1];
1532
- if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1533
- return false;
1534
- }
1535
- }
1536
- const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1537
- for (const command of commands_) {
1538
- if (typeof command === "string" && (command.toLowerCase() == command_)) {
1539
- return true;
1540
- }
1541
- else if (command instanceof RegExp && command.test(command_)) {
1542
- return true;
1543
- }
1544
- }
1545
- return false;
1546
- }, ...middleawre);
1531
+ await __classPrivateFieldGet(this, _Client_inlineQueryManager, "f").answerInlineQuery(id, results, params);
1547
1532
  }
1548
1533
  /**
1549
1534
  * Set the bot's description in the given language. Bot-only.
@@ -1769,69 +1754,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1769
1754
  * @method
1770
1755
  */
1771
1756
  async getChat(chatId) {
1772
- if (await this.storage.getAccountType() == "user") {
1773
- let maybeChatId = null;
1774
- if (typeof chatId === "number") {
1775
- maybeChatId = chatId;
1776
- }
1777
- else if (typeof chatId === "string") {
1778
- maybeChatId = __classPrivateFieldGet(this, _Client_chatListManager, "f").tryGetChatId((0, _0_utilities_js_1.getUsername)(chatId));
1779
- }
1780
- else {
1781
- (0, _1_utilities_js_1.UNREACHABLE)();
1782
- }
1783
- if (maybeChatId != null) {
1784
- const [chat] = __classPrivateFieldGet(this, _Client_chatListManager, "f").getChatAnywhere(maybeChatId);
1785
- if (chat !== undefined) {
1786
- return chat;
1787
- }
1788
- }
1789
- }
1790
- let inputPeer = null;
1791
- if (typeof chatId === "number") {
1792
- const chat = await (0, _3_types_js_1.constructChat3)(chatId, -1, undefined, this[getEntity].bind(this));
1793
- if (chat != null) {
1794
- return chat;
1795
- }
1796
- }
1797
- else {
1798
- inputPeer = await this.getInputPeer(chatId);
1799
- const chatId_ = (0, _2_tl_js_1.peerToChatId)(inputPeer);
1800
- const chat = await (0, _3_types_js_1.constructChat3)(chatId_, -1, undefined, this[getEntity].bind(this));
1801
- if (chat != null) {
1802
- return chat;
1803
- }
1804
- }
1805
- if (inputPeer == null) {
1806
- inputPeer = await this.getInputPeer(chatId);
1807
- }
1808
- if (inputPeer instanceof _2_tl_js_1.types.InputPeerChat) {
1809
- const chats = await this.api.messages.getChats({ id: [inputPeer.chat_id] }).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.messages.Chats));
1810
- const chat = chats.chats[0];
1811
- if (chat instanceof _2_tl_js_1.types.ChatEmpty) {
1812
- (0, _1_utilities_js_1.UNREACHABLE)();
1813
- }
1814
- return (0, _3_types_js_1.constructChat2)(chat, -1, undefined);
1815
- }
1816
- else if (inputPeer instanceof _2_tl_js_1.types.InputPeerChannel) {
1817
- const channels = await this.api.channels.getChannels({ id: [new _2_tl_js_1.types.InputChannel(inputPeer)] });
1818
- const channel = channels.chats[0];
1819
- if (channel instanceof _2_tl_js_1.types.ChatEmpty) {
1820
- (0, _1_utilities_js_1.UNREACHABLE)();
1821
- }
1822
- return (0, _3_types_js_1.constructChat2)(channel, -1, undefined);
1823
- }
1824
- else if (inputPeer instanceof _2_tl_js_1.types.InputPeerUser) {
1825
- const users = await this.api.users.getUsers({ id: [new _2_tl_js_1.types.InputUser(inputPeer)] });
1826
- const user = users[0];
1827
- if (user instanceof _2_tl_js_1.types.UserEmpty) {
1828
- (0, _1_utilities_js_1.UNREACHABLE)();
1829
- }
1830
- return (0, _3_types_js_1.constructChat2)(user, -1, undefined);
1831
- }
1832
- else {
1833
- (0, _1_utilities_js_1.UNREACHABLE)();
1834
- }
1757
+ return await __classPrivateFieldGet(this, _Client_chatListManager, "f").getChat(chatId);
1835
1758
  }
1836
1759
  /**
1837
1760
  * Get chat history. User-only.
@@ -1859,7 +1782,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1859
1782
  * @param availableReactions The new available reactions.
1860
1783
  */
1861
1784
  async setAvailableReactions(chatId, availableReactions) {
1862
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").setAvailableReactions(chatId, availableReactions);
1785
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setAvailableReactions(chatId, availableReactions);
1863
1786
  }
1864
1787
  /**
1865
1788
  * Change reactions made to a message.
@@ -1870,7 +1793,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1870
1793
  * @param reactions The new reactions.
1871
1794
  */
1872
1795
  async setReactions(chatId, messageId, reactions, params) {
1873
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").setReactions(chatId, messageId, reactions, params);
1796
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setReactions(chatId, messageId, reactions, params);
1874
1797
  }
1875
1798
  /**
1876
1799
  * Make a reaction to a message.
@@ -1881,7 +1804,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1881
1804
  * @param reaction The reaction to add.
1882
1805
  */
1883
1806
  async addReaction(chatId, messageId, reaction, params) {
1884
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").addReaction(chatId, messageId, reaction, params);
1807
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").addReaction(chatId, messageId, reaction, params);
1885
1808
  }
1886
1809
  /**
1887
1810
  * Undo a reaction made to a message.
@@ -1892,7 +1815,7 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1892
1815
  * @param reaction The reaction to remove.
1893
1816
  */
1894
1817
  async removeReaction(chatId, messageId, reaction) {
1895
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").removeReaction(chatId, messageId, reaction);
1818
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").removeReaction(chatId, messageId, reaction);
1896
1819
  }
1897
1820
  /**
1898
1821
  * Set a chat's photo.
@@ -2139,151 +2062,41 @@ _Client_parseText = function _Client_parseText(text, params) {
2139
2062
  await this.storage.setEntity(entity);
2140
2063
  }
2141
2064
  }
2142
- if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
2143
- if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
2144
- const chatId = (0, _2_tl_js_1.peerToChatId)(update.message.peer_id);
2145
- await this.storage.setMessage(chatId, update.message.id, update.message);
2146
- promises.push(__classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId));
2147
- }
2148
- }
2149
- if (update instanceof _2_tl_js_1.types.UpdateMessageReactions) {
2150
- const chatId = (0, _2_tl_js_1.peerToChatId)(update.peer);
2151
- const message = await this.storage.getMessage(chatId, update.msg_id);
2152
- if (message instanceof _2_tl_js_1.types.Message) {
2153
- message.reactions = update.reactions;
2154
- await this.storage.setMessage(chatId, update.msg_id, message);
2155
- const views = message.views ?? 0;
2156
- const forwards = message.forwards ?? 0;
2157
- const recentReactions = update.reactions.recent_reactions ?? [];
2158
- const reactions = update.reactions.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions));
2159
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } }));
2160
- }
2161
- }
2162
- else if (update instanceof _2_tl_js_1.types.UpdateChannelMessageViews || update instanceof _2_tl_js_1.types.UpdateChannelMessageForwards) {
2163
- const chatId = (0, _2_tl_js_1.peerToChatId)(new _2_tl_js_1.types.PeerChannel(update));
2164
- const message = await this.storage.getMessage(chatId, update.id);
2165
- if (message instanceof _2_tl_js_1.types.Message) {
2166
- if ("views" in update) {
2167
- message.views = update.views;
2168
- }
2169
- if ("forwards" in update) {
2170
- message.forwards = update.forwards;
2171
- }
2172
- const views = message.views ?? 0;
2173
- const forwards = message.forwards ?? 0;
2174
- const recentReactions = message.reactions?.recent_reactions ?? [];
2175
- const reactions = message.reactions?.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions)) ?? [];
2176
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } }));
2177
- }
2178
- }
2179
- if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
2180
- update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
2181
- update instanceof _2_tl_js_1.types.UpdateEditMessage ||
2182
- update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
2183
- if (!(update.message instanceof _2_tl_js_1.types.MessageEmpty)) {
2184
- const isOutgoing = update.message.out;
2185
- let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
2186
- if (__classPrivateFieldGet(this, _Client_ignoreOutgoing, "f") != null && isOutgoing) {
2187
- shouldIgnore = __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f");
2188
- }
2189
- if (!shouldIgnore) {
2190
- const message = await __classPrivateFieldGet(this, _Client_messageManager, "f").constructMessage(update.message);
2191
- promises.push((async () => {
2192
- if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
2193
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { message });
2194
- }
2195
- else {
2196
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { editedMessage: message });
2197
- }
2198
- })());
2199
- }
2200
- }
2201
- }
2202
- if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
2203
- const deletedMessages = new Array();
2204
- for (const messageId of update.messages) {
2205
- const chatId = await this.storage.getMessageChat(messageId);
2206
- if (chatId) {
2207
- deletedMessages.push({ chatId, messageId });
2208
- }
2209
- }
2210
- if (deletedMessages.length > 0) {
2065
+ if (_2_message_manager_js_1.MessageManager.canHandleUpdate(update)) {
2066
+ const update_ = await __classPrivateFieldGet(this, _Client_messageManager, "f").handleUpdate(update);
2067
+ if (update_) {
2211
2068
  promises.push((async () => {
2212
2069
  try {
2213
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { deletedMessages });
2070
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, update_);
2214
2071
  }
2215
2072
  finally {
2216
- for (const { chatId, messageId } of deletedMessages) {
2217
- await this.storage.setMessage(chatId, messageId, null);
2218
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
2219
- }
2220
- }
2221
- })());
2222
- }
2223
- }
2224
- else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
2225
- const chatId = (0, _2_tl_js_1.getChannelChatId)(update.channel_id);
2226
- const deletedMessages = new Array();
2227
- for (const messageId of update.messages) {
2228
- const message = await this.storage.getMessage(chatId, messageId);
2229
- if (message != null) {
2230
- deletedMessages.push({ chatId, messageId });
2231
- }
2232
- }
2233
- if (deletedMessages.length > 0) {
2234
- promises.push((async () => {
2235
- try {
2236
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { deletedMessages });
2237
- }
2238
- finally {
2239
- for (const { chatId, messageId } of deletedMessages) {
2240
- await this.storage.setMessage(chatId, messageId, null);
2241
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
2073
+ if ("deletedMessages" in update_) {
2074
+ for (const { chatId, messageId } of update_.deletedMessages) {
2075
+ await this.storage.setMessage(chatId, messageId, null);
2076
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
2077
+ }
2242
2078
  }
2243
2079
  }
2244
2080
  })());
2245
2081
  }
2246
2082
  }
2247
- if (update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery) {
2248
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, this[getEntity].bind(this), __classPrivateFieldGet(this, _Client_messageManager, "f").getMessageWithReply.bind(this)) }));
2249
- }
2250
- else if (update instanceof _2_tl_js_1.types.UpdateBotInlineQuery) {
2251
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { inlineQuery: await (0, _3_types_js_1.constructInlineQuery)(update, this[getEntity].bind(this)) }));
2083
+ if (_3_callback_query_manager_js_1.CallbackQueryManager.canHandleUpdate(update)) {
2084
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, await __classPrivateFieldGet(this, _Client_callbackQueryManager, "f").handleUpdate(update)));
2252
2085
  }
2253
- else if (update instanceof _2_tl_js_1.types.UpdateBotInlineSend) {
2254
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { chosenInlineResult: await (0, _3_types_js_1.constructChosenInlineResult)(update, this[getEntity].bind(this)) }));
2086
+ if (_3_inline_query_manager_js_1.InlineQueryManager.canHandleUpdate(update)) {
2087
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, await __classPrivateFieldGet(this, _Client_inlineQueryManager, "f").handleUpdate(update)));
2255
2088
  }
2256
- else if (update instanceof _2_tl_js_1.types.UpdateBotMessageReactions) {
2257
- const messageReactionCount = await (0, _3_types_js_1.constructMessageReactionCount)(update, this[getEntity].bind(this));
2258
- if (messageReactionCount) {
2259
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageReactionCount }));
2089
+ if (_1_reaction_manager_js_1.ReactionManager.canHandleUpdate(update)) {
2090
+ const upd = await __classPrivateFieldGet(this, _Client_reactionManager, "f").handleUpdate(update);
2091
+ if (upd) {
2092
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, upd));
2260
2093
  }
2261
2094
  }
2262
- else if (update instanceof _2_tl_js_1.types.UpdateBotMessageReaction) {
2263
- const messageReactions = await (0, _3_types_js_1.constructMessageReactions)(update, this[getEntity].bind(this));
2264
- if (messageReactions) {
2265
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageReactions }));
2266
- }
2267
- }
2268
- if (update instanceof _2_tl_js_1.types.UpdatePinnedDialogs) {
2269
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdatePinnedDialogs(update);
2270
- }
2271
- else if (update instanceof _2_tl_js_1.types.UpdateFolderPeers) {
2272
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handelUpdateFolderPeers(update);
2273
- }
2274
- if (update instanceof _2_tl_js_1.types.UpdateChannel) {
2275
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChannel(update);
2276
- }
2277
- else if (update instanceof _2_tl_js_1.types.UpdateChat) {
2278
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChat(update);
2279
- }
2280
- else if (update instanceof _2_tl_js_1.types.UpdateUser || update instanceof _2_tl_js_1.types.UpdateUserName) {
2281
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateUser(update);
2095
+ if (_3_chat_list_manager_js_1.ChatListManager.canHandleUpdate(update)) {
2096
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdate(update);
2282
2097
  }
2283
2098
  return () => Promise.all(promises);
2284
- }, _Client_setMyInfo =
2285
- //#endregion
2286
- async function _Client_setMyInfo(info) {
2099
+ }, _Client_setMyInfo = async function _Client_setMyInfo(info) {
2287
2100
  await this.api.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info });
2288
2101
  }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
2289
2102
  return this.api.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" });
@@ -0,0 +1,3 @@
1
+ import { Client } from "./4_client.js";
2
+ export declare function exportSessionString(client: Client): Promise<string>;
3
+ export declare function importSessionString(client: Client, string: string): Promise<void>;