@mtkruto/node 0.1.141 → 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.
Files changed (53) 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 +2 -0
  6. package/esm/client/1_bot_info_manager.d.ts +30 -0
  7. package/esm/client/1_bot_info_manager.js +66 -0
  8. package/esm/client/1_network_statistics_manager.d.ts +19 -0
  9. package/esm/client/1_network_statistics_manager.js +48 -0
  10. package/esm/client/1_reaction_manager.d.ts +9 -0
  11. package/esm/client/1_reaction_manager.js +84 -0
  12. package/esm/client/2_message_manager.d.ts +22 -2
  13. package/esm/client/2_message_manager.js +282 -28
  14. package/esm/client/3_callback_query_manager.d.ts +16 -0
  15. package/esm/client/3_callback_query_manager.js +36 -0
  16. package/esm/client/3_chat_list_manager.d.ts +5 -9
  17. package/esm/client/3_chat_list_manager.js +190 -103
  18. package/esm/client/3_inline_query_manager.d.ts +16 -0
  19. package/esm/client/3_inline_query_manager.js +49 -0
  20. package/esm/client/4_client.d.ts +12 -12
  21. package/esm/client/4_client.js +162 -538
  22. package/esm/client/5_session_string.d.ts +3 -0
  23. package/esm/client/5_session_string.js +22 -0
  24. package/esm/connection/1_connection_web_socket.js +1 -1
  25. package/package.json +1 -1
  26. package/script/4_constants.d.ts +1 -1
  27. package/script/4_constants.js +1 -1
  28. package/script/5_client.d.ts +1 -0
  29. package/script/5_client.js +1 -0
  30. package/script/client/0_types.d.ts +2 -0
  31. package/script/client/1_bot_info_manager.d.ts +30 -0
  32. package/script/client/1_bot_info_manager.js +70 -0
  33. package/script/client/1_network_statistics_manager.d.ts +19 -0
  34. package/script/client/1_network_statistics_manager.js +52 -0
  35. package/script/client/1_reaction_manager.d.ts +9 -0
  36. package/script/client/1_reaction_manager.js +88 -0
  37. package/script/client/2_message_manager.d.ts +22 -2
  38. package/script/client/2_message_manager.js +281 -27
  39. package/script/client/3_callback_query_manager.d.ts +16 -0
  40. package/script/client/3_callback_query_manager.js +40 -0
  41. package/script/client/3_chat_list_manager.d.ts +5 -9
  42. package/script/client/3_chat_list_manager.js +187 -100
  43. package/script/client/3_inline_query_manager.d.ts +16 -0
  44. package/script/client/3_inline_query_manager.js +53 -0
  45. package/script/client/4_client.d.ts +12 -12
  46. package/script/client/4_client.js +158 -534
  47. package/script/client/5_session_string.d.ts +3 -0
  48. package/script/client/5_session_string.js +27 -0
  49. package/script/connection/1_connection_web_socket.js +1 -1
  50. package/esm/client/3_reaction_manager.d.ts +0 -16
  51. package/esm/client/3_reaction_manager.js +0 -61
  52. package/script/client/3_reaction_manager.d.ts +0 -16
  53. package/script/client/3_reaction_manager.js +0 -65
@@ -9,28 +9,31 @@ 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_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;
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";
15
- import { as, functions, getChannelChatId, Message_, MessageContainer, name, peerToChatId, RPCResult, TLError, TLReader, types } from "../2_tl.js";
14
+ import { bigIntFromBuffer, cleanObject, drop, getRandomBigInt, getRandomId, mustPrompt, mustPromptOneOf, sha1, UNREACHABLE, ZERO_CHANNEL_ID } from "../1_utilities.js";
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, constructCallbackQuery, constructChat2, constructChat3, constructChosenInlineResult, constructInlineQuery, constructMessageReaction, constructMessageReactionCount, constructMessageReactions, constructUser, inlineQueryResultToTlObject, 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";
30
+ import { ReactionManager } from "./1_reaction_manager.js";
29
31
  import { UpdateManager } from "./1_update_manager.js";
30
32
  import { ClientPlain } from "./2_client_plain.js";
31
33
  import { MessageManager } from "./2_message_manager.js";
34
+ import { CallbackQueryManager } from "./3_callback_query_manager.js";
32
35
  import { ChatListManager } from "./3_chat_list_manager.js";
33
- import { ReactionManager } from "./3_reaction_manager.js";
36
+ import { InlineQueryManager } from "./3_inline_query_manager.js";
34
37
  const d = debug("Client");
35
38
  const dAuth = debug("Client/authorize");
36
39
  const dRecv = debug("Client/receiveLoop");
@@ -71,10 +74,14 @@ export class Client extends ClientAbstract {
71
74
  _Client_toAcknowledge.set(this, new Set());
72
75
  _Client_guaranteeUpdateDelivery.set(this, void 0);
73
76
  _Client_updateManager.set(this, void 0);
77
+ _Client_networkStatisticsManager.set(this, void 0);
78
+ _Client_botInfoManager.set(this, void 0);
74
79
  _Client_fileManager.set(this, void 0);
80
+ _Client_reactionManager.set(this, void 0);
75
81
  _Client_messageManager.set(this, void 0);
82
+ _Client_callbackQueryManager.set(this, void 0);
83
+ _Client_inlineQueryManager.set(this, void 0);
76
84
  _Client_chatListManager.set(this, void 0);
77
- _Client_reactionManager.set(this, void 0);
78
85
  Object.defineProperty(this, "storage", {
79
86
  enumerable: true,
80
87
  configurable: true,
@@ -447,7 +454,6 @@ export class Client extends ClientAbstract {
447
454
  }).bind(this)
448
455
  });
449
456
  _Client_storageInited.set(this, false);
450
- _Client_authKeyWasCreated.set(this, true);
451
457
  _Client_connectMutex.set(this, new Mutex());
452
458
  _Client_connectionInited.set(this, false);
453
459
  _Client_lastPropagatedAuthorizationState.set(this, null);
@@ -485,10 +491,6 @@ export class Client extends ClientAbstract {
485
491
  })
486
492
  });
487
493
  _Client_lastGetMe.set(this, null);
488
- _Client_usernameResolver.set(this, async (v) => {
489
- const inputPeer = await this.getInputPeer(v).then((v) => v[as](types.InputPeerUser));
490
- return new types.InputUser(inputPeer);
491
- });
492
494
  //#region Composer
493
495
  _Client_handle.set(this, skip);
494
496
  this.storage = storage ?? new StorageMemory();
@@ -558,26 +560,23 @@ export class Client extends ClientAbstract {
558
560
  disconnect: client.disconnect.bind(client),
559
561
  };
560
562
  },
563
+ cdn: params?.cdn ?? false,
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");
570
+ __classPrivateFieldSet(this, _Client_reactionManager, new ReactionManager(c), "f");
564
571
  __classPrivateFieldSet(this, _Client_messageManager, new MessageManager({ ...c, fileManager: __classPrivateFieldGet(this, _Client_fileManager, "f") }), "f");
572
+ __classPrivateFieldSet(this, _Client_callbackQueryManager, new CallbackQueryManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
573
+ __classPrivateFieldSet(this, _Client_inlineQueryManager, new InlineQueryManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
565
574
  __classPrivateFieldSet(this, _Client_chatListManager, new ChatListManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
566
- __classPrivateFieldSet(this, _Client_reactionManager, new ReactionManager({ ...c, messageManager: __classPrivateFieldGet(this, _Client_messageManager, "f") }), "f");
567
575
  __classPrivateFieldGet(this, _Client_updateManager, "f").setUpdateHandler(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleUpdate).bind(this));
568
576
  const transportProvider = this.transportProvider;
569
577
  this.transportProvider = (params) => {
570
578
  const transport = transportProvider(params);
571
- transport.connection.callback = {
572
- read: async (count) => {
573
- const key = params.cdn ? "netstat_cdn_read" : "netstat_messages_read";
574
- await this.storage.incr([key], count);
575
- },
576
- write: async (count) => {
577
- const key = params.cdn ? "netstat_cdn_write" : "netstat_messages_write";
578
- await this.storage.incr([key], count);
579
- },
580
- };
579
+ transport.connection.callback = __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getTransportReadWriteCallback();
581
580
  return transport;
582
581
  };
583
582
  if (params?.defaultHandlers ?? true) {
@@ -628,10 +627,7 @@ export class Client extends ClientAbstract {
628
627
  * @param dc The DC to change to.
629
628
  */
630
629
  async setDc(dc) {
631
- if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
632
- await this.storage.initialize();
633
- __classPrivateFieldSet(this, _Client_storageInited, true, "f");
634
- }
630
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
635
631
  if (await this.storage.getDc() != dc) {
636
632
  await this.storage.setDc(dc);
637
633
  await this.storage.setAuthKey(null);
@@ -650,13 +646,7 @@ export class Client extends ClientAbstract {
650
646
  }
651
647
  const release = await __classPrivateFieldGet(this, _Client_connectMutex, "f").acquire();
652
648
  try {
653
- if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
654
- await this.storage.initialize();
655
- if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
656
- await this.storage.deleteUpdates();
657
- }
658
- __classPrivateFieldSet(this, _Client_storageInited, true, "f");
659
- }
649
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initStorage).call(this);
660
650
  const authKey = await this.storage.getAuthKey();
661
651
  if (authKey == null) {
662
652
  const plain = new ClientPlain({ initialDc: this.initialDc, transportProvider: this.transportProvider, cdn: this.cdn, publicKeys: __classPrivateFieldGet(this, _Client_publicKeys, "f") });
@@ -677,7 +667,6 @@ export class Client extends ClientAbstract {
677
667
  __classPrivateFieldGet(this, _Client_state, "f").salt = await this.storage.getServerSalt() ?? 0n;
678
668
  }
679
669
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_setAuth).call(this, authKey);
680
- __classPrivateFieldSet(this, _Client_authKeyWasCreated, false, "f");
681
670
  }
682
671
  const dc = await this.storage.getDc();
683
672
  if (dc != null) {
@@ -697,13 +686,21 @@ export class Client extends ClientAbstract {
697
686
  release();
698
687
  }
699
688
  }
700
- 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) {
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) {
701
690
  __classPrivateFieldGet(this, _Client_instances, "m", _Client_queueHandleCtxUpdate).call(this, { connectionState });
702
691
  __classPrivateFieldSet(this, _Client_lastPropagatedConnectionState, connectionState, "f");
703
692
  }, _Client_setAuth = async function _Client_setAuth(key) {
704
693
  const hash = await sha1(key);
705
694
  const id = bigIntFromBuffer(hash.slice(-8), true, false);
706
695
  __classPrivateFieldSet(this, _Client_auth, { key, id }, "f");
696
+ }, _Client_initStorage = async function _Client_initStorage() {
697
+ if (!__classPrivateFieldGet(this, _Client_storageInited, "f")) {
698
+ await this.storage.initialize();
699
+ if (!__classPrivateFieldGet(this, _Client_guaranteeUpdateDelivery, "f")) {
700
+ await this.storage.deleteUpdates();
701
+ }
702
+ __classPrivateFieldSet(this, _Client_storageInited, true, "f");
703
+ }
707
704
  }, handleMigrationError)](err) {
708
705
  let newDc = String(err.dc);
709
706
  if (Math.abs(this.dcId) >= 10000) {
@@ -897,16 +894,11 @@ export class Client extends ClientAbstract {
897
894
  }
898
895
  }
899
896
  /**
900
- * Same as calling `.connect()` followed by `.authorize(params)` if the session didn't have an auth key.
897
+ * Same as calling `.connect()` followed by `.authorize(params)`.
901
898
  */
902
899
  async start(params) {
903
900
  await this.connect();
904
901
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
905
- if (!__classPrivateFieldGet(this, _Client_authKeyWasCreated, "f")) {
906
- drop(__classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("start"));
907
- drop(__classPrivateFieldGet(this, _Client_updateManager, "f").recoverUpdateGap("start"));
908
- return;
909
- }
910
902
  await this.authorize(params);
911
903
  }
912
904
  /**
@@ -1166,6 +1158,10 @@ export class Client extends ClientAbstract {
1166
1158
  const channels = await this.api.channels.getChannels({ id: [new types.InputChannel({ channel_id: channelId, access_hash: 0n })] });
1167
1159
  return channels.chats[0][as](types.Channel).access_hash ?? 0n;
1168
1160
  }, _Client_getInputPeerInner = async function _Client_getInputPeerInner(id) {
1161
+ const idn = Number(id);
1162
+ if (!isNaN(idn)) {
1163
+ id = idn;
1164
+ }
1169
1165
  if (typeof id === "string") {
1170
1166
  id = getUsername(id);
1171
1167
  let userId = 0n;
@@ -1227,6 +1223,77 @@ export class Client extends ClientAbstract {
1227
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();
1228
1224
  return this.storage.getEntity(type, id);
1229
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
1230
1297
  /**
1231
1298
  * Send a text message.
1232
1299
  *
@@ -1351,13 +1418,7 @@ export class Client extends ClientAbstract {
1351
1418
  * @param id ID of the callback query to answer.
1352
1419
  */
1353
1420
  async answerCallbackQuery(id, params) {
1354
- await this.storage.assertBot("answerCallbackQuery");
1355
- await this.api.messages.setBotCallbackAnswer({
1356
- query_id: BigInt(id),
1357
- cache_time: params?.cacheTime ?? 0,
1358
- message: params?.text,
1359
- alert: params?.alert ? true : undefined,
1360
- });
1421
+ await __classPrivateFieldGet(this, _Client_callbackQueryManager, "f").answerCallbackQuery(id, params);
1361
1422
  }
1362
1423
  /**
1363
1424
  * Send a poll.
@@ -1380,45 +1441,7 @@ export class Client extends ClientAbstract {
1380
1441
  * @param messageThreadId The thread to send the chat action to.
1381
1442
  */
1382
1443
  async sendChatAction(chatId, action, params) {
1383
- let action_;
1384
- switch (action) {
1385
- case "type":
1386
- action_ = new types.SendMessageTypingAction();
1387
- break;
1388
- case "uploadPhoto":
1389
- action_ = new types.SendMessageUploadPhotoAction({ progress: 0 });
1390
- break;
1391
- case "recordVideo":
1392
- action_ = new types.SendMessageRecordVideoAction();
1393
- break;
1394
- case "uploadVideo":
1395
- action_ = new types.SendMessageRecordVideoAction();
1396
- break;
1397
- case "recordVoice":
1398
- action_ = new types.SendMessageRecordAudioAction();
1399
- break;
1400
- case "uploadAudio":
1401
- action_ = new types.SendMessageUploadAudioAction({ progress: 0 });
1402
- break;
1403
- case "uploadDocument":
1404
- action_ = new types.SendMessageUploadDocumentAction({ progress: 0 });
1405
- break;
1406
- case "chooseSticker":
1407
- action_ = new types.SendMessageChooseStickerAction();
1408
- break;
1409
- case "findLocation":
1410
- action_ = new types.SendMessageGeoLocationAction();
1411
- break;
1412
- case "recordVideoNote":
1413
- action_ = new types.SendMessageRecordRoundAction();
1414
- break;
1415
- case "uploadVideoNote":
1416
- action_ = new types.SendMessageUploadRoundAction({ progress: 0 });
1417
- break;
1418
- default:
1419
- throw new Error("Invalid chat action: " + action);
1420
- }
1421
- 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);
1422
1445
  }
1423
1446
  /**
1424
1447
  * Upload a file.
@@ -1436,21 +1459,13 @@ export class Client extends ClientAbstract {
1436
1459
  * @param commands The commands to set.
1437
1460
  */
1438
1461
  async setMyCommands(commands, params) {
1439
- await this.api.bots.setBotCommands({
1440
- commands: commands.map((v) => new types.BotCommand(v)),
1441
- lang_code: params?.languageCode ?? "",
1442
- scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
1443
- });
1462
+ await __classPrivateFieldGet(this, _Client_botInfoManager, "f").setMyCommands(commands, params);
1444
1463
  }
1445
1464
  /**
1446
1465
  * Get the bot's commands in the given scope and/or language. Bot-only.
1447
1466
  */
1448
1467
  async getMyCommands(params) {
1449
- const commands_ = await this.api.bots.getBotCommands({
1450
- lang_code: params?.languageCode ?? "",
1451
- scope: await botCommandScopeToTlObject(params?.scope ?? { type: "default" }, this.getInputPeer.bind(this)),
1452
- });
1453
- return commands_.map((v) => ({ command: v.command, description: v.description }));
1468
+ return await __classPrivateFieldGet(this, _Client_botInfoManager, "f").getMyCommands(params);
1454
1469
  }
1455
1470
  /**
1456
1471
  * Answer an inline query. Bot-only.
@@ -1460,86 +1475,7 @@ export class Client extends ClientAbstract {
1460
1475
  * @param results The results to answer with.
1461
1476
  */
1462
1477
  async answerInlineQuery(id, results, params) {
1463
- await this.api.messages.setInlineBotResults({
1464
- query_id: BigInt(id),
1465
- results: await Promise.all(results.map((v) => inlineQueryResultToTlObject(v, __classPrivateFieldGet(this, _Client_instances, "m", _Client_parseText).bind(this), __classPrivateFieldGet(this, _Client_usernameResolver, "f").bind(this)))),
1466
- cache_time: params?.cacheTime ?? 300,
1467
- private: params?.isPersonal ? true : undefined,
1468
- switch_webview: params?.button && params.button.webApp ? new types.InlineBotWebView({ text: params.button.text, url: params.button.webApp.url }) : undefined,
1469
- switch_pm: params?.button && params.button.startParameter ? new types.InlineBotSwitchPM({ text: params.button.text, start_param: params.button.startParameter }) : undefined,
1470
- gallery: params?.isGallery ? true : undefined,
1471
- next_offset: params?.nextOffset,
1472
- });
1473
- }
1474
- use(...middleware) {
1475
- const composer = new Composer(...middleware);
1476
- __classPrivateFieldSet(this, _Client_handle, concat(__classPrivateFieldGet(this, _Client_handle, "f"), flatten(composer)), "f");
1477
- return composer;
1478
- }
1479
- branch(predicate, trueHandler_, falseHandler_) {
1480
- const trueHandler = flatten(trueHandler_);
1481
- const falseHandler = flatten(falseHandler_);
1482
- return this.use(async (upd, next) => {
1483
- if (await predicate(upd)) {
1484
- await trueHandler(upd, next);
1485
- }
1486
- else {
1487
- await falseHandler(upd, next);
1488
- }
1489
- });
1490
- }
1491
- filter(predicate, ...middleware) {
1492
- const composer = new Composer(...middleware);
1493
- this.branch(predicate, composer, skip);
1494
- return composer;
1495
- }
1496
- on(filter, ...middleawre) {
1497
- return this.filter((ctx) => {
1498
- return match(filter, ctx);
1499
- }, ...middleawre);
1500
- }
1501
- command(commands, ...middleawre) {
1502
- const commands__ = typeof commands === "object" && "names" in commands ? commands.names : commands;
1503
- const commands_ = Array.isArray(commands__) ? commands__ : [commands__];
1504
- const prefixes_ = typeof commands === "object" && "prefixes" in commands ? commands.prefixes : (__classPrivateFieldGet(this, _Client_prefixes, "f") ?? []);
1505
- const prefixes = Array.isArray(prefixes_) ? prefixes_ : [prefixes_];
1506
- for (const left of prefixes) {
1507
- for (const right of prefixes) {
1508
- if (left == right) {
1509
- continue;
1510
- }
1511
- if (left.startsWith(right) || right.startsWith(left)) {
1512
- throw new Error("Intersecting prefixes");
1513
- }
1514
- }
1515
- }
1516
- return this.on("message:text").filter((ctx) => {
1517
- const prefixes_ = prefixes.length == 0 ? [!ctx.me?.isBot ? "\\" : "/"] : prefixes;
1518
- if (prefixes_.length == 0) {
1519
- return false;
1520
- }
1521
- const cmd = ctx.message.text.split(/\s/, 1)[0];
1522
- const prefix = prefixes_.find((v) => cmd.startsWith(v));
1523
- if (prefix === undefined) {
1524
- return false;
1525
- }
1526
- if (cmd.includes("@")) {
1527
- const username = cmd.split("@", 2)[1];
1528
- if (username.toLowerCase() !== ctx.me.username?.toLowerCase()) {
1529
- return false;
1530
- }
1531
- }
1532
- const command_ = cmd.split("@", 1)[0].split(prefix, 2)[1].toLowerCase();
1533
- for (const command of commands_) {
1534
- if (typeof command === "string" && (command.toLowerCase() == command_)) {
1535
- return true;
1536
- }
1537
- else if (command instanceof RegExp && command.test(command_)) {
1538
- return true;
1539
- }
1540
- }
1541
- return false;
1542
- }, ...middleawre);
1478
+ await __classPrivateFieldGet(this, _Client_inlineQueryManager, "f").answerInlineQuery(id, results, params);
1543
1479
  }
1544
1480
  /**
1545
1481
  * Set the bot's description in the given language. Bot-only.
@@ -1547,8 +1483,7 @@ export class Client extends ClientAbstract {
1547
1483
  * @method
1548
1484
  */
1549
1485
  async setMyDescription(params) {
1550
- await this.storage.assertBot("setMyDescription");
1551
- 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);
1552
1487
  }
1553
1488
  /**
1554
1489
  * Set the bot's name in the given language. Bot-only.
@@ -1556,8 +1491,7 @@ export class Client extends ClientAbstract {
1556
1491
  * @method
1557
1492
  */
1558
1493
  async setMyName(params) {
1559
- await this.storage.assertBot("setMyName");
1560
- 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);
1561
1495
  }
1562
1496
  /**
1563
1497
  * Set the bot's short description in the given language. Bot-only.
@@ -1565,8 +1499,7 @@ export class Client extends ClientAbstract {
1565
1499
  * @method
1566
1500
  */
1567
1501
  async setMyShortDescription(params) {
1568
- await this.storage.assertBot("setMyShortDescription");
1569
- 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);
1570
1503
  }
1571
1504
  /**
1572
1505
  * Get the bot's description in the given language. Bot-only.
@@ -1574,8 +1507,7 @@ export class Client extends ClientAbstract {
1574
1507
  * @method
1575
1508
  */
1576
1509
  async getMyDescription(params) {
1577
- await this.storage.assertBot("getMyDescription");
1578
- 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);
1579
1511
  }
1580
1512
  /**
1581
1513
  * Set the bot's name in the given language. Bot-only.
@@ -1583,8 +1515,7 @@ export class Client extends ClientAbstract {
1583
1515
  * @method
1584
1516
  */
1585
1517
  async getMyName(params) {
1586
- await this.storage.assertBot("getMyName");
1587
- 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);
1588
1519
  }
1589
1520
  /**
1590
1521
  * Get the bot's short description in the given language. Bot-only.
@@ -1592,8 +1523,7 @@ export class Client extends ClientAbstract {
1592
1523
  * @method
1593
1524
  */
1594
1525
  async getMyShortDescription(params) {
1595
- await this.storage.assertBot("getMyShortDescription");
1596
- 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);
1597
1527
  }
1598
1528
  /**
1599
1529
  * Delete multiple messages.
@@ -1735,21 +1665,7 @@ export class Client extends ClientAbstract {
1735
1665
  * @method
1736
1666
  */
1737
1667
  async getNetworkStatistics() {
1738
- const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
1739
- this.storage.get(["netstat_messages_read"]),
1740
- this.storage.get(["netstat_messages_write"]),
1741
- this.storage.get(["netstat_cdn_read"]),
1742
- this.storage.get(["netstat_cdn_write"]),
1743
- ]);
1744
- const messages = {
1745
- sent: Number(messagesWrite || 0),
1746
- received: Number(messagesRead || 0),
1747
- };
1748
- const cdn = {
1749
- sent: Number(cdnWrite || 0),
1750
- received: Number(cdnRead || 0),
1751
- };
1752
- return { messages, cdn };
1668
+ return await __classPrivateFieldGet(this, _Client_networkStatisticsManager, "f").getNetworkStatistics();
1753
1669
  }
1754
1670
  /**
1755
1671
  * Get chats from a chat list. User-only.
@@ -1765,69 +1681,7 @@ export class Client extends ClientAbstract {
1765
1681
  * @method
1766
1682
  */
1767
1683
  async getChat(chatId) {
1768
- if (await this.storage.getAccountType() == "user") {
1769
- let maybeChatId = null;
1770
- if (typeof chatId === "number") {
1771
- maybeChatId = chatId;
1772
- }
1773
- else if (typeof chatId === "string") {
1774
- maybeChatId = __classPrivateFieldGet(this, _Client_chatListManager, "f").tryGetChatId(getUsername(chatId));
1775
- }
1776
- else {
1777
- UNREACHABLE();
1778
- }
1779
- if (maybeChatId != null) {
1780
- const [chat] = __classPrivateFieldGet(this, _Client_chatListManager, "f").getChatAnywhere(maybeChatId);
1781
- if (chat !== undefined) {
1782
- return chat;
1783
- }
1784
- }
1785
- }
1786
- let inputPeer = null;
1787
- if (typeof chatId === "number") {
1788
- const chat = await constructChat3(chatId, -1, undefined, this[getEntity].bind(this));
1789
- if (chat != null) {
1790
- return chat;
1791
- }
1792
- }
1793
- else {
1794
- inputPeer = await this.getInputPeer(chatId);
1795
- const chatId_ = peerToChatId(inputPeer);
1796
- const chat = await constructChat3(chatId_, -1, undefined, this[getEntity].bind(this));
1797
- if (chat != null) {
1798
- return chat;
1799
- }
1800
- }
1801
- if (inputPeer == null) {
1802
- inputPeer = await this.getInputPeer(chatId);
1803
- }
1804
- if (inputPeer instanceof types.InputPeerChat) {
1805
- const chats = await this.api.messages.getChats({ id: [inputPeer.chat_id] }).then((v) => v[as](types.messages.Chats));
1806
- const chat = chats.chats[0];
1807
- if (chat instanceof types.ChatEmpty) {
1808
- UNREACHABLE();
1809
- }
1810
- return constructChat2(chat, -1, undefined);
1811
- }
1812
- else if (inputPeer instanceof types.InputPeerChannel) {
1813
- const channels = await this.api.channels.getChannels({ id: [new types.InputChannel(inputPeer)] });
1814
- const channel = channels.chats[0];
1815
- if (channel instanceof types.ChatEmpty) {
1816
- UNREACHABLE();
1817
- }
1818
- return constructChat2(channel, -1, undefined);
1819
- }
1820
- else if (inputPeer instanceof types.InputPeerUser) {
1821
- const users = await this.api.users.getUsers({ id: [new types.InputUser(inputPeer)] });
1822
- const user = users[0];
1823
- if (user instanceof types.UserEmpty) {
1824
- UNREACHABLE();
1825
- }
1826
- return constructChat2(user, -1, undefined);
1827
- }
1828
- else {
1829
- UNREACHABLE();
1830
- }
1684
+ return await __classPrivateFieldGet(this, _Client_chatListManager, "f").getChat(chatId);
1831
1685
  }
1832
1686
  /**
1833
1687
  * Get chat history. User-only.
@@ -1855,7 +1709,7 @@ export class Client extends ClientAbstract {
1855
1709
  * @param availableReactions The new available reactions.
1856
1710
  */
1857
1711
  async setAvailableReactions(chatId, availableReactions) {
1858
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").setAvailableReactions(chatId, availableReactions);
1712
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setAvailableReactions(chatId, availableReactions);
1859
1713
  }
1860
1714
  /**
1861
1715
  * Change reactions made to a message.
@@ -1866,7 +1720,7 @@ export class Client extends ClientAbstract {
1866
1720
  * @param reactions The new reactions.
1867
1721
  */
1868
1722
  async setReactions(chatId, messageId, reactions, params) {
1869
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").setReactions(chatId, messageId, reactions, params);
1723
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setReactions(chatId, messageId, reactions, params);
1870
1724
  }
1871
1725
  /**
1872
1726
  * Make a reaction to a message.
@@ -1877,7 +1731,7 @@ export class Client extends ClientAbstract {
1877
1731
  * @param reaction The reaction to add.
1878
1732
  */
1879
1733
  async addReaction(chatId, messageId, reaction, params) {
1880
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").addReaction(chatId, messageId, reaction, params);
1734
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").addReaction(chatId, messageId, reaction, params);
1881
1735
  }
1882
1736
  /**
1883
1737
  * Undo a reaction made to a message.
@@ -1888,7 +1742,7 @@ export class Client extends ClientAbstract {
1888
1742
  * @param reaction The reaction to remove.
1889
1743
  */
1890
1744
  async removeReaction(chatId, messageId, reaction) {
1891
- await __classPrivateFieldGet(this, _Client_reactionManager, "f").removeReaction(chatId, messageId, reaction);
1745
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").removeReaction(chatId, messageId, reaction);
1892
1746
  }
1893
1747
  /**
1894
1748
  * Set a chat's photo.
@@ -1898,19 +1752,7 @@ export class Client extends ClientAbstract {
1898
1752
  * @param photo A photo to set as the chat's photo.
1899
1753
  */
1900
1754
  async setChatPhoto(chatId, photo, params) {
1901
- const peer = await this.getInputPeer(chatId);
1902
- if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
1903
- UNREACHABLE();
1904
- }
1905
- const [contents, fileName] = await getFileContents(photo);
1906
- const file = await this.upload(contents, { fileName: params?.fileName ?? fileName, chunkSize: params?.chunkSize, signal: params?.signal });
1907
- const photo_ = new types.InputChatUploadedPhoto({ file });
1908
- if (peer instanceof types.InputPeerChannel) {
1909
- await this.api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: photo_ });
1910
- }
1911
- else if (peer instanceof types.InputPeerChat) {
1912
- await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: photo_ });
1913
- }
1755
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatPhoto(chatId, photo, params);
1914
1756
  }
1915
1757
  /**
1916
1758
  * Delete a chat's photo.
@@ -1919,16 +1761,7 @@ export class Client extends ClientAbstract {
1919
1761
  * @param chatId The identifier of the chat.
1920
1762
  */
1921
1763
  async deleteChatPhoto(chatId) {
1922
- const peer = await this.getInputPeer(chatId);
1923
- if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
1924
- UNREACHABLE();
1925
- }
1926
- if (peer instanceof types.InputPeerChannel) {
1927
- await this.api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: new types.InputChatPhotoEmpty() });
1928
- }
1929
- else if (peer instanceof types.InputPeerChat) {
1930
- await this.api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: new types.InputChatPhotoEmpty() });
1931
- }
1764
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").deleteChatPhoto(chatId);
1932
1765
  }
1933
1766
  /**
1934
1767
  * Delete all messages sent by a specific member of a chat.
@@ -1977,46 +1810,7 @@ export class Client extends ClientAbstract {
1977
1810
  * @param memberId The identifier of the member.
1978
1811
  */
1979
1812
  async banChatMember(chatId, memberId, params) {
1980
- const chat = await this.getInputPeer(chatId);
1981
- if (!(chat instanceof types.InputPeerChannel) && !(chat instanceof types.InputPeerChat)) {
1982
- throw new Error("Invalid chat ID");
1983
- }
1984
- const member = await this.getInputPeer(memberId);
1985
- if (chat instanceof types.InputPeerChannel) {
1986
- if (params?.deleteMessages) {
1987
- try {
1988
- await this.deleteChatMemberMessages(chatId, memberId);
1989
- }
1990
- catch {
1991
- //
1992
- }
1993
- }
1994
- await this.api.channels.editBanned({
1995
- channel: new types.InputChannel(chat),
1996
- participant: member,
1997
- banned_rights: new types.ChatBannedRights({
1998
- until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
1999
- view_messages: true,
2000
- send_messages: true,
2001
- send_media: true,
2002
- send_stickers: true,
2003
- send_gifs: true,
2004
- send_games: true,
2005
- send_inline: true,
2006
- embed_links: true,
2007
- }),
2008
- });
2009
- }
2010
- else if (chat instanceof types.InputPeerChat) {
2011
- if (!(member instanceof types.InputPeerUser)) {
2012
- throw new Error("Invalid user ID");
2013
- }
2014
- await this.api.messages.deleteChatUser({
2015
- chat_id: chat.chat_id,
2016
- user_id: new types.InputUser(member),
2017
- revoke_history: params?.deleteMessages ? true : undefined,
2018
- });
2019
- }
1813
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").banChatMember(chatId, memberId, params);
2020
1814
  }
2021
1815
  /**
2022
1816
  * Unban a member from a chat.
@@ -2026,16 +1820,7 @@ export class Client extends ClientAbstract {
2026
1820
  * @param memberId The identifier of the member.
2027
1821
  */
2028
1822
  async unbanChatMember(chatId, memberId) {
2029
- const chat = await this.getInputPeer(chatId);
2030
- if (!(chat instanceof types.InputPeerChannel)) {
2031
- throw new Error("Invalid chat ID");
2032
- }
2033
- const member = await this.getInputPeer(memberId);
2034
- await this.api.channels.editBanned({
2035
- channel: new types.InputChannel(chat),
2036
- participant: member,
2037
- banned_rights: new types.ChatBannedRights({ until_date: 0 }),
2038
- });
1823
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").unbanChatMember(chatId, memberId);
2039
1824
  }
2040
1825
  /**
2041
1826
  * Kick a member from a chat. Same as a banChatMember call followed by unbanChatMember.
@@ -2045,8 +1830,8 @@ export class Client extends ClientAbstract {
2045
1830
  * @param memberId The identifier of the member.
2046
1831
  */
2047
1832
  async kickChatMember(chatId, memberId) {
2048
- await this.banChatMember(chatId, memberId);
2049
- 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);
2050
1835
  }
2051
1836
  /**
2052
1837
  * Set the rights of a chat member.
@@ -2056,66 +1841,10 @@ export class Client extends ClientAbstract {
2056
1841
  * @param memberId The identifier of a member.
2057
1842
  */
2058
1843
  async setChatMemberRights(chatId, memberId, params) {
2059
- const chat = await this.getInputPeer(chatId);
2060
- if (!(chat instanceof types.InputPeerChannel)) {
2061
- throw new Error("Invalid chat ID");
2062
- }
2063
- const member = await this.getInputPeer(memberId);
2064
- await this.api.channels.editBanned({
2065
- channel: new types.InputChannel(chat),
2066
- participant: member,
2067
- banned_rights: new types.ChatBannedRights({
2068
- until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
2069
- send_messages: params?.rights?.canSendMessages ? true : undefined,
2070
- send_audios: params?.rights?.canSendAudio ? true : undefined,
2071
- send_docs: params?.rights?.canSendDocuments ? true : undefined,
2072
- send_photos: params?.rights?.canSendPhotos ? true : undefined,
2073
- send_videos: params?.rights?.canSendVideos ? true : undefined,
2074
- send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
2075
- send_voices: params?.rights?.canSendVoice ? true : undefined,
2076
- send_polls: params?.rights?.canSendPolls ? true : undefined,
2077
- send_stickers: params?.rights?.canSendStickers ? true : undefined,
2078
- send_gifs: params?.rights?.canSendAnimations ? true : undefined,
2079
- send_games: params?.rights?.canSendGames ? true : undefined,
2080
- send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
2081
- embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
2082
- change_info: params?.rights?.canChangeInfo ? true : undefined,
2083
- invite_users: params?.rights?.canInviteUsers ? true : undefined,
2084
- pin_messages: params?.rights?.canPinMessages ? true : undefined,
2085
- manage_topics: params?.rights?.canManageTopics ? true : undefined,
2086
- }),
2087
- });
1844
+ await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatMemberRights(chatId, memberId, params);
2088
1845
  }
2089
1846
  }
2090
- _Client_parseText = function _Client_parseText(text, params) {
2091
- const entities_ = params?.entities ?? [];
2092
- const parseMode = params?.parseMode ?? __classPrivateFieldGet(this, _Client_parseMode, "f");
2093
- switch (parseMode) {
2094
- case null:
2095
- break;
2096
- case "HTML": {
2097
- const [newText, entitiesToPush] = parseHtml(text);
2098
- text = newText;
2099
- for (const entity of entitiesToPush) {
2100
- entities_.push(entity);
2101
- }
2102
- break;
2103
- }
2104
- default:
2105
- UNREACHABLE();
2106
- }
2107
- const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
2108
- return [text, entities];
2109
- }, _Client_getMe = async function _Client_getMe() {
2110
- if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
2111
- return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
2112
- }
2113
- else {
2114
- const user = await this.getMe();
2115
- __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
2116
- return user;
2117
- }
2118
- }, _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
1847
+ _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
2119
1848
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
2120
1849
  }, _Client_queueHandleCtxUpdate = function _Client_queueHandleCtxUpdate(update) {
2121
1850
  __classPrivateFieldGet(this, _Client_updateManager, "f").getHandleUpdateQueue(UpdateManager.MAIN_BOX_ID).add(async () => {
@@ -2134,152 +1863,47 @@ _Client_parseText = function _Client_parseText(text, params) {
2134
1863
  await this.storage.setEntity(entity);
2135
1864
  }
2136
1865
  }
2137
- if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditMessage || update instanceof types.UpdateEditChannelMessage) {
2138
- if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
2139
- const chatId = peerToChatId(update.message.peer_id);
2140
- await this.storage.setMessage(chatId, update.message.id, update.message);
2141
- promises.push(__classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId));
2142
- }
2143
- }
2144
- if (update instanceof types.UpdateMessageReactions) {
2145
- const chatId = peerToChatId(update.peer);
2146
- const message = await this.storage.getMessage(chatId, update.msg_id);
2147
- if (message instanceof types.Message) {
2148
- message.reactions = update.reactions;
2149
- await this.storage.setMessage(chatId, update.msg_id, message);
2150
- const views = message.views ?? 0;
2151
- const forwards = message.forwards ?? 0;
2152
- const recentReactions = update.reactions.recent_reactions ?? [];
2153
- const reactions = update.reactions.results.map((v) => constructMessageReaction(v, recentReactions));
2154
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } }));
2155
- }
2156
- }
2157
- else if (update instanceof types.UpdateChannelMessageViews || update instanceof types.UpdateChannelMessageForwards) {
2158
- const chatId = peerToChatId(new types.PeerChannel(update));
2159
- const message = await this.storage.getMessage(chatId, update.id);
2160
- if (message instanceof types.Message) {
2161
- if ("views" in update) {
2162
- message.views = update.views;
2163
- }
2164
- if ("forwards" in update) {
2165
- message.forwards = update.forwards;
2166
- }
2167
- const views = message.views ?? 0;
2168
- const forwards = message.forwards ?? 0;
2169
- const recentReactions = message.reactions?.recent_reactions ?? [];
2170
- const reactions = message.reactions?.results.map((v) => constructMessageReaction(v, recentReactions)) ?? [];
2171
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } }));
2172
- }
2173
- }
2174
- if (update instanceof types.UpdateNewMessage ||
2175
- update instanceof types.UpdateNewChannelMessage ||
2176
- update instanceof types.UpdateEditMessage ||
2177
- update instanceof types.UpdateEditChannelMessage) {
2178
- if (!(update.message instanceof types.MessageEmpty)) {
2179
- const isOutgoing = update.message.out;
2180
- let shouldIgnore = isOutgoing ? (await this.storage.getAccountType()) == "user" ? false : true : false;
2181
- if (__classPrivateFieldGet(this, _Client_ignoreOutgoing, "f") != null && isOutgoing) {
2182
- shouldIgnore = __classPrivateFieldGet(this, _Client_ignoreOutgoing, "f");
2183
- }
2184
- if (!shouldIgnore) {
2185
- const message = await __classPrivateFieldGet(this, _Client_messageManager, "f").constructMessage(update.message);
2186
- promises.push((async () => {
2187
- if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage) {
2188
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { message });
2189
- }
2190
- else {
2191
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { editedMessage: message });
2192
- }
2193
- })());
2194
- }
2195
- }
2196
- }
2197
- if (update instanceof types.UpdateDeleteMessages) {
2198
- const deletedMessages = new Array();
2199
- for (const messageId of update.messages) {
2200
- const chatId = await this.storage.getMessageChat(messageId);
2201
- if (chatId) {
2202
- deletedMessages.push({ chatId, messageId });
2203
- }
2204
- }
2205
- if (deletedMessages.length > 0) {
2206
- promises.push((async () => {
2207
- try {
2208
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { deletedMessages });
2209
- }
2210
- finally {
2211
- for (const { chatId, messageId } of deletedMessages) {
2212
- await this.storage.setMessage(chatId, messageId, null);
2213
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
2214
- }
2215
- }
2216
- })());
2217
- }
2218
- }
2219
- else if (update instanceof types.UpdateDeleteChannelMessages) {
2220
- const chatId = getChannelChatId(update.channel_id);
2221
- const deletedMessages = new Array();
2222
- for (const messageId of update.messages) {
2223
- const message = await this.storage.getMessage(chatId, messageId);
2224
- if (message != null) {
2225
- deletedMessages.push({ chatId, messageId });
2226
- }
2227
- }
2228
- if (deletedMessages.length > 0) {
1866
+ if (MessageManager.canHandleUpdate(update)) {
1867
+ const update_ = await __classPrivateFieldGet(this, _Client_messageManager, "f").handleUpdate(update);
1868
+ if (update_) {
2229
1869
  promises.push((async () => {
2230
1870
  try {
2231
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { deletedMessages });
1871
+ await __classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, update_);
2232
1872
  }
2233
1873
  finally {
2234
- for (const { chatId, messageId } of deletedMessages) {
2235
- await this.storage.setMessage(chatId, messageId, null);
2236
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
1874
+ if ("deletedMessages" in update_) {
1875
+ for (const { chatId, messageId } of update_.deletedMessages) {
1876
+ await this.storage.setMessage(chatId, messageId, null);
1877
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").reassignChatLastMessage(chatId);
1878
+ }
2237
1879
  }
2238
1880
  }
2239
1881
  })());
2240
1882
  }
2241
1883
  }
2242
- if (update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery) {
2243
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { callbackQuery: await constructCallbackQuery(update, this[getEntity].bind(this), __classPrivateFieldGet(this, _Client_messageManager, "f").getMessageWithReply.bind(this)) }));
1884
+ if (CallbackQueryManager.canHandleUpdate(update)) {
1885
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, await __classPrivateFieldGet(this, _Client_callbackQueryManager, "f").handleUpdate(update)));
2244
1886
  }
2245
- else if (update instanceof types.UpdateBotInlineQuery) {
2246
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { inlineQuery: await constructInlineQuery(update, this[getEntity].bind(this)) }));
1887
+ if (InlineQueryManager.canHandleUpdate(update)) {
1888
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, await __classPrivateFieldGet(this, _Client_inlineQueryManager, "f").handleUpdate(update)));
2247
1889
  }
2248
- else if (update instanceof types.UpdateBotInlineSend) {
2249
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { chosenInlineResult: await constructChosenInlineResult(update, this[getEntity].bind(this)) }));
2250
- }
2251
- else if (update instanceof types.UpdateBotMessageReactions) {
2252
- const messageReactionCount = await constructMessageReactionCount(update, this[getEntity].bind(this));
2253
- if (messageReactionCount) {
2254
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageReactionCount }));
1890
+ if (ReactionManager.canHandleUpdate(update)) {
1891
+ const upd = await __classPrivateFieldGet(this, _Client_reactionManager, "f").handleUpdate(update);
1892
+ if (upd) {
1893
+ promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, upd));
2255
1894
  }
2256
1895
  }
2257
- else if (update instanceof types.UpdateBotMessageReaction) {
2258
- const messageReactions = await constructMessageReactions(update, this[getEntity].bind(this));
2259
- if (messageReactions) {
2260
- promises.push(__classPrivateFieldGet(this, _Client_instances, "m", _Client_handleCtxUpdate).call(this, { messageReactions }));
2261
- }
1896
+ if (ChatListManager.canHandleUpdate(update)) {
1897
+ await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdate(update);
2262
1898
  }
2263
- if (update instanceof types.UpdatePinnedDialogs) {
2264
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdatePinnedDialogs(update);
2265
- }
2266
- else if (update instanceof types.UpdateFolderPeers) {
2267
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handelUpdateFolderPeers(update);
2268
- }
2269
- if (update instanceof types.UpdateChannel) {
2270
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChannel(update);
2271
- }
2272
- else if (update instanceof types.UpdateChat) {
2273
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateChat(update);
1899
+ return () => Promise.all(promises);
1900
+ }, _Client_getMe = async function _Client_getMe() {
1901
+ if (__classPrivateFieldGet(this, _Client_lastGetMe, "f") != null) {
1902
+ return __classPrivateFieldGet(this, _Client_lastGetMe, "f");
2274
1903
  }
2275
- else if (update instanceof types.UpdateUser || update instanceof types.UpdateUserName) {
2276
- await __classPrivateFieldGet(this, _Client_chatListManager, "f").handleUpdateUser(update);
1904
+ else {
1905
+ const user = await this.getMe();
1906
+ __classPrivateFieldSet(this, _Client_lastGetMe, user, "f");
1907
+ return user;
2277
1908
  }
2278
- return () => Promise.all(promises);
2279
- }, _Client_setMyInfo =
2280
- //#endregion
2281
- async function _Client_setMyInfo(info) {
2282
- await this.api.bots.setBotInfo({ bot: new types.InputUserSelf(), ...info });
2283
- }, _Client_getMyInfo = function _Client_getMyInfo(languageCode) {
2284
- return this.api.bots.getBotInfo({ bot: new types.InputUserSelf(), lang_code: languageCode ?? "" });
2285
1909
  };