@mtkruto/node 0.1.155 → 0.1.156

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 (85) hide show
  1. package/esm/4_constants.d.ts +1 -1
  2. package/esm/4_constants.js +1 -1
  3. package/esm/4_errors.d.ts +1 -1
  4. package/esm/client/0_params.d.ts +20 -0
  5. package/esm/client/0_password.d.ts +2 -2
  6. package/esm/client/0_types.d.ts +1 -0
  7. package/esm/client/1_composer.d.ts +3 -3
  8. package/esm/client/2_client_plain.d.ts +1 -4
  9. package/esm/client/2_client_plain.js +1 -4
  10. package/esm/client/2_message_manager.d.ts +9 -36
  11. package/esm/client/2_message_manager.js +73 -1
  12. package/esm/client/4_client.d.ts +90 -15
  13. package/esm/client/4_client.js +123 -12
  14. package/esm/storage/0_storage.d.ts +38 -38
  15. package/esm/storage/0_storage.js +2 -2
  16. package/esm/storage/0_utilities.d.ts +2 -2
  17. package/esm/storage/1_storage_indexed_db.d.ts +1 -1
  18. package/esm/storage/1_storage_local_storage.d.ts +1 -1
  19. package/esm/storage/1_storage_memory.d.ts +3 -3
  20. package/esm/storage/1_storage_session_storage.d.ts +1 -1
  21. package/esm/tl/0_tl_raw_writer.d.ts +9 -9
  22. package/esm/tl/1_tl_object.d.ts +1 -1
  23. package/esm/tl/1_tl_object.js +3 -3
  24. package/esm/tl/3_functions.d.ts +28 -28
  25. package/esm/tl/3_functions.js +586 -586
  26. package/esm/tl/3_utilities.d.ts +3 -3
  27. package/esm/tl/4_tl_writer.d.ts +1 -1
  28. package/esm/types/0_chat_administrator_rights.d.ts +2 -2
  29. package/esm/types/0_chat_member_rights.d.ts +1 -1
  30. package/esm/types/0_message_entity.d.ts +1 -1
  31. package/esm/types/0_message_search_filter.d.ts +2 -1
  32. package/esm/types/1_bot_command_scope.d.ts +2 -1
  33. package/esm/types/1_keyboard_button.d.ts +1 -1
  34. package/esm/types/1_story_interactive_area.d.ts +1 -1
  35. package/esm/types/2_inline_keyboard_button.d.ts +1 -1
  36. package/esm/types/2_invite_link.d.ts +6 -6
  37. package/esm/types/2_invite_link.js +4 -4
  38. package/esm/types/3_reply_markup.d.ts +2 -2
  39. package/esm/types/4_inline_query_result.d.ts +2 -1
  40. package/esm/types/4_message.d.ts +1 -60
  41. package/esm/types/5_callback_query.d.ts +2 -2
  42. package/esm/utilities/0_cache_map.d.ts +1 -1
  43. package/package.json +1 -1
  44. package/script/4_constants.d.ts +1 -1
  45. package/script/4_constants.js +1 -1
  46. package/script/4_errors.d.ts +1 -1
  47. package/script/client/0_params.d.ts +20 -0
  48. package/script/client/0_password.d.ts +2 -2
  49. package/script/client/0_types.d.ts +1 -0
  50. package/script/client/1_composer.d.ts +3 -3
  51. package/script/client/2_client_plain.d.ts +1 -4
  52. package/script/client/2_client_plain.js +1 -4
  53. package/script/client/2_message_manager.d.ts +9 -36
  54. package/script/client/2_message_manager.js +72 -0
  55. package/script/client/4_client.d.ts +90 -15
  56. package/script/client/4_client.js +123 -12
  57. package/script/storage/0_storage.d.ts +38 -38
  58. package/script/storage/0_storage.js +2 -2
  59. package/script/storage/0_utilities.d.ts +2 -2
  60. package/script/storage/1_storage_indexed_db.d.ts +1 -1
  61. package/script/storage/1_storage_local_storage.d.ts +1 -1
  62. package/script/storage/1_storage_memory.d.ts +3 -3
  63. package/script/storage/1_storage_session_storage.d.ts +1 -1
  64. package/script/tl/0_tl_raw_writer.d.ts +9 -9
  65. package/script/tl/1_tl_object.d.ts +1 -1
  66. package/script/tl/1_tl_object.js +3 -3
  67. package/script/tl/3_functions.d.ts +28 -28
  68. package/script/tl/3_functions.js +586 -586
  69. package/script/tl/3_utilities.d.ts +3 -3
  70. package/script/tl/4_tl_writer.d.ts +1 -1
  71. package/script/types/0_chat_administrator_rights.d.ts +2 -2
  72. package/script/types/0_chat_member_rights.d.ts +1 -1
  73. package/script/types/0_message_entity.d.ts +1 -1
  74. package/script/types/0_message_search_filter.d.ts +2 -1
  75. package/script/types/1_bot_command_scope.d.ts +2 -1
  76. package/script/types/1_keyboard_button.d.ts +1 -1
  77. package/script/types/1_story_interactive_area.d.ts +1 -1
  78. package/script/types/2_inline_keyboard_button.d.ts +1 -1
  79. package/script/types/2_invite_link.d.ts +6 -6
  80. package/script/types/2_invite_link.js +4 -4
  81. package/script/types/3_reply_markup.d.ts +2 -2
  82. package/script/types/4_inline_query_result.d.ts +2 -1
  83. package/script/types/4_message.d.ts +1 -60
  84. package/script/types/5_callback_query.d.ts +2 -2
  85. package/script/utilities/0_cache_map.d.ts +1 -1
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
6
  export declare const LAYER = 174;
7
- export declare const APP_VERSION = "MTKruto 0.1.155";
7
+ export declare const APP_VERSION = "MTKruto 0.1.156";
8
8
  export declare const DEVICE_MODEL: string;
9
9
  export declare const LANG_CODE: string;
10
10
  export declare const LANG_PACK = "";
@@ -53,7 +53,7 @@ export const PUBLIC_KEYS = Object.freeze([
53
53
  ]);
54
54
  export const INITIAL_DC = "2";
55
55
  export const LAYER = 174;
56
- export const APP_VERSION = "MTKruto 0.1.155";
56
+ export const APP_VERSION = "MTKruto 0.1.156";
57
57
  // @ts-ignore: lib
58
58
  export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
59
59
  export const LANG_CODE = typeof navigator === "undefined" || typeof navigator.language !== "string" ? "en" : navigator.language.split("-")[0];
package/esm/4_errors.d.ts CHANGED
@@ -17,4 +17,4 @@ export declare class FileMigrate extends Migrate {
17
17
  }
18
18
  export declare class StatsMigrate extends Migrate {
19
19
  }
20
- export declare function upgradeInstance(error: types.Rpc_error, call: TLObject): import("./tl/2_types.js").Rpc_error_;
20
+ export declare function upgradeInstance(error: types.Rpc_error, call: TLObject): types.Rpc_error;
@@ -287,3 +287,23 @@ export interface SearchMessagesParams {
287
287
  /** The maximum number of results to return. Must be in the range of 1-100. Defaults to 100. */
288
288
  limit?: number;
289
289
  }
290
+ export interface CreateInviteLinkParams {
291
+ /** An optional title to be attached to the link that can only be seen by admins. */
292
+ title?: string;
293
+ /** The point of time in which the invite link must no longer work. */
294
+ expireAt?: Date;
295
+ /** The times the invite link can be used. Cannot be specified while `requireApproval` is `true`. */
296
+ limit?: number;
297
+ /** Whether an admin must explicitly approve join requests originating from this invite link. Cannot be `true` while `limit` is specified. */
298
+ requireApproval?: boolean;
299
+ }
300
+ export interface GetCreatedInviteLinksParams {
301
+ /** The identifier of an admin. If specified, only invite links created by this admin will be returned. */
302
+ by?: ID;
303
+ /** The maximum number of results to return. Must be in the range 1-100. Defaults to 100. */
304
+ limit?: number;
305
+ /** Whether only revoked invite links must be returned. */
306
+ revoked?: boolean;
307
+ afterDate?: Date;
308
+ afterInviteLink?: string;
309
+ }
@@ -1,5 +1,5 @@
1
1
  import { sha256 } from "../1_utilities.js";
2
- import { enums } from "../2_tl.js";
2
+ import { enums, types } from "../2_tl.js";
3
3
  export declare function isSafePrime(primeBytes: Uint8Array, g: number): boolean;
4
4
  export declare const h: typeof sha256;
5
5
  export declare const sh: (data: Uint8Array, salt: Uint8Array) => Promise<Uint8Array>;
@@ -8,4 +8,4 @@ export declare function pbkdf2(password: Uint8Array, salt: Uint8Array, iteration
8
8
  export declare const ph2: (password: Uint8Array, salt1: Uint8Array, salt2: Uint8Array) => Promise<Uint8Array>;
9
9
  export declare function isGoodModExpFirst(modexp: bigint, prime: bigint): boolean;
10
10
  export declare function pad(bigint: number | bigint | Uint8Array): Uint8Array;
11
- export declare function checkPassword(password_: string, ap: enums.account.Password): Promise<import("../tl/2_types.js").InputCheckPasswordSRP_>;
11
+ export declare function checkPassword(password_: string, ap: enums.account.Password): Promise<types.InputCheckPasswordSRP>;
@@ -32,6 +32,7 @@ export interface C {
32
32
  getSelfId: () => Promise<number>;
33
33
  getInputPeer: (id: ID) => Promise<enums.InputPeer>;
34
34
  getInputChannel: (id: ID) => Promise<types.InputChannel>;
35
+ getInputUser: (id: ID) => Promise<types.InputUser>;
35
36
  getEntity: EntityGetter;
36
37
  handleUpdate: (update: Update) => void;
37
38
  parseMode: ParseMode;
@@ -17,14 +17,14 @@ export declare class Composer<C extends {
17
17
  set prefixes(value: string | string[]);
18
18
  constructor(...middleware: Middleware<C>[]);
19
19
  middleware(): MiddlewareFn<C>;
20
- use(...middleware: Middleware<UpdateIntersection<C>>[]): Composer<UpdateIntersection<C>>;
21
- branch(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, trueHandler_: Middleware<UpdateIntersection<C>>, falseHandler_: Middleware<UpdateIntersection<C>>): Composer<UpdateIntersection<C>>;
20
+ use(...middleware: Middleware<UpdateIntersection<C>>[]): Composer<C>;
21
+ branch(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, trueHandler_: Middleware<UpdateIntersection<C>>, falseHandler_: Middleware<UpdateIntersection<C>>): Composer<C>;
22
22
  filter<D extends C>(predicate: (ctx: UpdateIntersection<C>) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
23
23
  filter(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, ...middleware: Middleware<UpdateIntersection<C>>[]): Composer<C>;
24
24
  on<Q extends FilterQuery>(filter: Q, ...middleawre: Middleware<WithFilter<C, Q>>[]): Composer<UpdateIntersection<WithFilter<C, Q>>>;
25
25
  command(commands: string | RegExp | (string | RegExp)[] | {
26
26
  names: string | RegExp | (string | RegExp)[];
27
27
  prefixes: string | string[];
28
- }, ...middleawre: Middleware<WithFilter<C, "message:text">>[]): Composer<UpdateIntersection<WithFilter<C, "message:text">>>;
28
+ }, ...middleawre: Middleware<WithFilter<C, "message:text">>[]): Composer<WithFilter<C, "message:text">>;
29
29
  }
30
30
  export {};
@@ -11,8 +11,5 @@ export declare class ClientPlain extends ClientAbstract {
11
11
  #private;
12
12
  constructor(params?: ClientPlainParams);
13
13
  invoke<T extends functions.Function<unknown>>(function_: T): Promise<T["__R"]>;
14
- createAuthKey(): Promise<{
15
- authKey: Uint8Array;
16
- salt: bigint;
17
- }>;
14
+ createAuthKey(): Promise<[Uint8Array, bigint]>;
18
15
  }
@@ -142,10 +142,7 @@ export class ClientPlain extends ClientAbstract {
142
142
  const authKey_ = modExp(gA, b, dhPrime);
143
143
  const authKey = bufferFromBigInt(authKey_, 256, false, false);
144
144
  LcreateAuthKey.debug("auth key created");
145
- return {
146
- authKey,
147
- salt: bigIntFromBuffer(salt, true, false),
148
- };
145
+ return [authKey, bigIntFromBuffer(salt, true, false)];
149
146
  }
150
147
  }
151
148
  _ClientPlain_publicKeys = new WeakMap(), _ClientPlain_lastMsgId = new WeakMap();
@@ -1,8 +1,6 @@
1
1
  import { enums, types } from "../2_tl.js";
2
2
  import { ChatAction, ChatMember, FileSource, FileType, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
3
- import { BanChatMemberParams, DeleteMessagesParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetHistoryParams, PinMessageParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams, SetChatMemberRightsParams, SetChatPhotoParams } from "./0_params.js";
4
- import { SearchMessagesParams } from "./0_params.js";
5
- import { AddReactionParams, SetReactionsParams } from "./0_params.js";
3
+ import { AddReactionParams, BanChatMemberParams, CreateInviteLinkParams, DeleteMessagesParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetCreatedInviteLinksParams, GetHistoryParams, PinMessageParams, SearchMessagesParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams, SetChatMemberRightsParams, SetChatPhotoParams, SetReactionsParams } from "./0_params.js";
6
4
  import { C as C_ } from "./0_types.js";
7
5
  import { FileManager } from "./1_file_manager.js";
8
6
  interface C extends C_ {
@@ -18,40 +16,9 @@ export declare class MessageManager {
18
16
  parseText(text: string, params?: {
19
17
  parseMode?: ParseMode;
20
18
  entities?: MessageEntity[];
21
- }): Promise<readonly [string, (import("../tl/2_types.js").MessageEntityMention_ | import("../tl/2_types.js").MessageEntityHashtag_ | import("../tl/2_types.js").MessageEntityBotCommand_ | import("../tl/2_types.js").MessageEntityUrl_ | import("../tl/2_types.js").MessageEntityEmail_ | import("../tl/2_types.js").MessageEntityBold_ | import("../tl/2_types.js").MessageEntityItalic_ | import("../tl/2_types.js").MessageEntityCode_ | import("../tl/2_types.js").MessageEntityPre_ | import("../tl/2_types.js").MessageEntityTextUrl_ | import("../tl/2_types.js").InputMessageEntityMentionName_ | import("../tl/2_types.js").MessageEntityPhone_ | import("../tl/2_types.js").MessageEntityCashtag_ | import("../tl/2_types.js").MessageEntityUnderline_ | import("../tl/2_types.js").MessageEntityStrike_ | import("../tl/2_types.js").MessageEntityBankCard_ | import("../tl/2_types.js").MessageEntitySpoiler_ | import("../tl/2_types.js").MessageEntityCustomEmoji_ | import("../tl/2_types.js").MessageEntityBlockquote_)[] | undefined]>;
19
+ }): Promise<readonly [string, enums.MessageEntity[] | undefined]>;
22
20
  getStickerSetName(inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
23
- constructMessage(message_: enums.Message, r?: boolean): Promise<import("../3_types.js").MessageLink | import("../3_types.js").MessagePhoto | import("../3_types.js").MessageDocument | import("../3_types.js").MessageVideo | import("../3_types.js").MessageSticker | import("../3_types.js").MessageAnimation | import("../3_types.js").MessageVoice | import("../3_types.js").MessageAudio | import("../3_types.js").MessageDice | import("../3_types.js").MessageVideoNote | import("../3_types.js").MessageContact | import("../3_types.js").MessageGame | import("../3_types.js").MessagePoll | import("../3_types.js").MessageVenue | import("../3_types.js").MessageLocation | import("../3_types.js").MessageNewChatMembers | import("../3_types.js").MessageLeftChatMember | import("../3_types.js").MessageNewChatTitle | import("../3_types.js").MessageNewChatPhoto | import("../3_types.js").MessageDeletedChatPhoto | import("../3_types.js").MessageSupergroupCreated | import("../3_types.js").MessageChannelCreated | import("../3_types.js").MessageAutoDeleteTimerChanged | import("../3_types.js").MessageChatMigratedTo | import("../3_types.js").MessageChatMigratedFrom | import("../3_types.js").MessagePinnedMessage | import("../3_types.js").MessageUserShared | import("../3_types.js").MessageWriteAccessAllowed | import("../3_types.js").MessageForumTopicCreated | import("../3_types.js").MessageForumTopicEdited | import("../3_types.js").MessageForumTopicClosed | import("../3_types.js").MessageForumTopicReopened | import("../3_types.js").MessageVideoChatScheduled | import("../3_types.js").MessageVideoChatStarted | import("../3_types.js").MessageVideoChatEnded | import("../3_types.js").MessageGiveaway | import("../3_types.js").MessageUnsupported | {
24
- text: string;
25
- entities: NonNullable<MessageEntity | null>[];
26
- out: boolean;
27
- id: number;
28
- threadId?: number | undefined;
29
- from?: import("../3_types.js").User | undefined;
30
- senderChat?: import("../3_types.js").ChatP | undefined;
31
- date: Date;
32
- chat: import("../3_types.js").ChatP;
33
- link?: string | undefined;
34
- forwardFrom?: import("../3_types.js").User | undefined;
35
- forwardFromChat?: import("../3_types.js").ChatP | undefined;
36
- forwardId?: number | undefined;
37
- forwardSignature?: string | undefined;
38
- forwardSenderName?: string | undefined;
39
- forwardDate?: Date | undefined;
40
- isTopicMessage: boolean;
41
- isAutomaticForward?: boolean | undefined;
42
- replyToMessage?: Message | undefined;
43
- replyToMessageId?: number | undefined;
44
- reactions?: import("../3_types.js").MessageReaction[] | undefined;
45
- replyQuote?: import("../3_types.js").ReplyQuote | undefined;
46
- viaBot?: import("../3_types.js").User | undefined;
47
- editDate?: Date | undefined;
48
- hasProtectedContent?: boolean | undefined;
49
- mediaGroupId?: string | undefined;
50
- authorSignature?: string | undefined;
51
- views?: number | undefined;
52
- forwards?: number | undefined;
53
- replyMarkup?: import("../3_types.js").ReplyMarkup | undefined;
54
- }>;
21
+ constructMessage(message_: enums.Message, r?: boolean): Promise<Message>;
55
22
  forwardMessages(from: ID, to: ID, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
56
23
  getHistory(chatId: ID, params?: GetHistoryParams): Promise<Message[]>;
57
24
  usernameResolver: UsernameResolver;
@@ -101,5 +68,11 @@ export declare class MessageManager {
101
68
  disableJoinRequests(chatId: ID): Promise<void>;
102
69
  searchMessages(chatId: ID, query: string, params?: SearchMessagesParams): Promise<Message[]>;
103
70
  setBoostsRequiredToCircumventRestrictions(chatId: ID, boosts: number): Promise<void>;
71
+ createInviteLink(chatId: ID, params?: CreateInviteLinkParams): Promise<import("../3_types.js").InviteLink>;
72
+ getCreatedInviteLinks(chatId: ID, params?: GetCreatedInviteLinksParams): Promise<import("../3_types.js").InviteLink[]>;
73
+ joinChat(chatId: ID): Promise<void>;
74
+ leaveChat(chatId: ID): Promise<void>;
75
+ blockUser(userId: ID): Promise<void>;
76
+ unblockUser(userId: ID): Promise<void>;
104
77
  }
105
78
  export {};
@@ -13,7 +13,7 @@ var _MessageManager_instances, _MessageManager_c, _MessageManager_LresolveFileId
13
13
  import { contentType } from "../0_deps.js";
14
14
  import { getLogger, getRandomId, toUnixTimestamp, UNREACHABLE } from "../1_utilities.js";
15
15
  import { as, getChannelChatId, peerToChatId, types } from "../2_tl.js";
16
- import { constructChatMemberUpdated } from "../3_types.js";
16
+ import { constructChatMemberUpdated, constructInviteLink } from "../3_types.js";
17
17
  import { assertMessageType, chatMemberRightsToTlObject, constructChatMember, constructMessage as constructMessage_, deserializeInlineMessageId, FileID, FileType, messageEntityToTlObject, reactionEqual, reactionToTlObject, replyMarkupToTlObject } from "../3_types.js";
18
18
  import { STICKER_SET_NAME_TTL } from "../4_constants.js";
19
19
  import { messageSearchFilterToTlObject } from "../types/0_message_search_filter.js";
@@ -899,6 +899,78 @@ export class MessageManager {
899
899
  const channel = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputChannel(chatId);
900
900
  await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.setBoostsToUnblockRestrictions({ channel, boosts });
901
901
  }
902
+ async createInviteLink(chatId, params) {
903
+ if (params?.requireApproval && params?.limit) {
904
+ throw new Error("createInviteLink: requireApproval cannot be true while limit is specified");
905
+ }
906
+ const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.exportChatInvite({
907
+ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
908
+ title: params?.title,
909
+ expire_date: params?.expireAt ? toUnixTimestamp(params.expireAt) : undefined,
910
+ request_needed: params?.requireApproval ? true : undefined,
911
+ usage_limit: params?.limit,
912
+ });
913
+ return await constructInviteLink(result[as](types.ChatInviteExported), __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity);
914
+ }
915
+ async getCreatedInviteLinks(chatId, params) {
916
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("getCreatedInviteLinks");
917
+ const { invites } = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.getExportedChatInvites({
918
+ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
919
+ revoked: params?.revoked ? true : undefined,
920
+ admin_id: params?.by ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputUser(params.by) : new types.InputUserEmpty(),
921
+ limit: params?.limit ?? 100,
922
+ offset_date: params?.afterDate ? toUnixTimestamp(params.afterDate) : undefined,
923
+ offset_link: params?.afterInviteLink,
924
+ });
925
+ return await Promise.all(invites.map((v) => v[as](types.ChatInviteExported)).map((v) => constructInviteLink(v, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity)));
926
+ }
927
+ async joinChat(chatId) {
928
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("joinChat");
929
+ const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
930
+ if (peer instanceof types.InputPeerUser) {
931
+ throw new Error("joinChat: cannot join private chats");
932
+ }
933
+ else if (peer instanceof types.InputPeerChannel) {
934
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.joinChannel({ channel: new types.InputChannel(peer) });
935
+ }
936
+ else if (peer instanceof types.InputPeerChat) {
937
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.addChatUser({ chat_id: peer.chat_id, user_id: new types.InputUserSelf(), fwd_limit: 0 }); // TODO: use potential high-level method for adding participants to chats
938
+ }
939
+ else {
940
+ UNREACHABLE();
941
+ }
942
+ }
943
+ async leaveChat(chatId) {
944
+ const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
945
+ if (peer instanceof types.InputPeerUser) {
946
+ throw new Error("leaveChat: cannot leave private chats");
947
+ }
948
+ else if (peer instanceof types.InputPeerChannel) {
949
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.leaveChannel({ channel: new types.InputChannel(peer) });
950
+ }
951
+ else if (peer instanceof types.InputPeerChat) {
952
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.deleteChatUser({ chat_id: peer.chat_id, user_id: new types.InputUserSelf() }); // TODO: use potential high-level method for adding participants to chats
953
+ }
954
+ else {
955
+ UNREACHABLE();
956
+ }
957
+ }
958
+ async blockUser(userId) {
959
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("blockUser");
960
+ const id = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(userId);
961
+ if (!(id instanceof types.User)) {
962
+ throw new Error("blockUser: only users can be blocked or unblocked");
963
+ }
964
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").api.contacts.block({ id });
965
+ }
966
+ async unblockUser(userId) {
967
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("unblockUser");
968
+ const id = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(userId);
969
+ if (!(id instanceof types.User)) {
970
+ throw new Error("unblockUser: only users can be blocked or unblocked");
971
+ }
972
+ await __classPrivateFieldGet(this, _MessageManager_c, "f").api.contacts.unblock({ id });
973
+ }
902
974
  }
903
975
  _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
904
976
  const messages = new Array();
@@ -1,13 +1,13 @@
1
1
  import { MaybePromise } from "../1_utilities.js";
2
- import { functions, types } from "../2_tl.js";
2
+ import { enums, functions, types } from "../2_tl.js";
3
3
  import { Storage } from "../3_storage.js";
4
4
  import { DC } from "../3_transport.js";
5
5
  import { InactiveChat } from "../3_types.js";
6
- import { BotCommand, Chat, ChatAction, ChatMember, ChatP, Document, FileSource, ID, InlineQueryResult, InputStoryContent, Message, MessageAnimation, MessageAudio, MessageContact, MessageDice, MessageDocument, MessageLocation, MessagePhoto, MessagePoll, MessageText, MessageVenue, MessageVideo, MessageVideoNote, MessageVoice, NetworkStatistics, ParseMode, Reaction, Story, Update, UpdateIntersection, User } from "../3_types.js";
6
+ import { BotCommand, Chat, ChatAction, ChatMember, ChatP, Document, FileSource, ID, InlineQueryResult, InputStoryContent, InviteLink, Message, MessageAnimation, MessageAudio, MessageContact, MessageDice, MessageDocument, MessageLocation, MessagePhoto, MessagePoll, MessageText, MessageVenue, MessageVideo, MessageVideoNote, MessageVoice, NetworkStatistics, ParseMode, Reaction, Story, Update, UpdateIntersection, User } from "../3_types.js";
7
7
  import { Migrate } from "../4_errors.js";
8
8
  import { ClientAbstract } from "./0_client_abstract.js";
9
9
  import { FilterQuery, WithFilter } from "./0_filters.js";
10
- import { AddReactionParams, AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, BanChatMemberParams, CreateStoryParams, DeleteMessageParams, DeleteMessagesParams, DownloadParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetChatsParams, GetHistoryParams, GetMyCommandsParams, PinMessageParams, ReplyParams, SearchMessagesParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams, SetChatMemberRightsParams, SetChatPhotoParams, SetMyCommandsParams, SetReactionsParams, UploadParams } from "./0_params.js";
10
+ import { AddReactionParams, AnswerCallbackQueryParams, AnswerInlineQueryParams, AuthorizeUserParams, BanChatMemberParams, CreateInviteLinkParams, CreateStoryParams, DeleteMessageParams, DeleteMessagesParams, DownloadParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetChatsParams, GetCreatedInviteLinksParams, GetHistoryParams, GetMyCommandsParams, PinMessageParams, ReplyParams, SearchMessagesParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams, SetChatMemberRightsParams, SetChatPhotoParams, SetMyCommandsParams, SetReactionsParams, UploadParams } from "./0_params.js";
11
11
  import { Api } from "./0_types.js";
12
12
  import { Composer, Middleware } from "./1_composer.js";
13
13
  import { ClientPlainParams } from "./2_client_plain.js";
@@ -137,6 +137,16 @@ export interface Context {
137
137
  searchMessages: (query: string, params?: SearchMessagesParams) => Promise<Message[]>;
138
138
  /** Set the number of boosts required to circument the chat's default restrictions. */
139
139
  setBoostsRequiredToCircumventRestrictions: (boosts: number) => Promise<void>;
140
+ /** Create an invite link for the chat which the message was received from. */
141
+ createInviteLink: (params?: CreateInviteLinkParams) => Promise<InviteLink>;
142
+ /** Get the invite links that were created for the chat which the message was received from. */
143
+ getCreatedInviteLinks: (params?: GetCreatedInviteLinksParams) => Promise<InviteLink[]>;
144
+ /** Leave the chat which the message was received from. */
145
+ leave: () => Promise<void>;
146
+ /** Block the user who sent the message. User-only. */
147
+ block: () => Promise<void>;
148
+ /** Unblock the user who sent the message. */
149
+ unblock: () => Promise<void>;
140
150
  toJSON: () => Update;
141
151
  }
142
152
  export declare function skipInvoke<C extends Context>(): InvokeErrorHandler<Client<C>>;
@@ -237,10 +247,10 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
237
247
  * @param function_ The function to invoke.
238
248
  */
239
249
  invoke: {
240
- <T extends import("../tl/2_types.js").Type_ | functions.Function<unknown> = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>;
241
- <T_1 extends import("../tl/2_types.js").Type_ | functions.Function<unknown> = functions.Function<unknown>>(function_: T_1, noWait: true): Promise<void>;
242
- } & {
243
- use: (handler: InvokeErrorHandler<Client<C>>) => void;
250
+ <T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<T extends functions.Function<unknown> ? T["__R"] : void>;
251
+ <T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait: true): Promise<void>;
252
+ <T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T, noWait?: boolean): Promise<T | void>;
253
+ use(handler: InvokeErrorHandler<Client<C>>): void;
244
254
  };
245
255
  /**
246
256
  * Alias for `invoke` with its second parameter being `true`.
@@ -248,22 +258,22 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
248
258
  send<T extends (functions.Function<unknown> | types.Type) = functions.Function<unknown>>(function_: T): Promise<void>;
249
259
  exportAuthString(): Promise<string>;
250
260
  importAuthString(authString: string): Promise<void>;
251
- getInputPeer(id: ID): Promise<import("../tl/2_types.js").InputPeerSelf_ | import("../tl/2_types.js").InputPeerChat_ | import("../tl/2_types.js").InputPeerUser_ | import("../tl/2_types.js").InputPeerChannel_>;
252
- getInputChannel(id: ID): Promise<import("../tl/2_types.js").InputChannel_>;
253
- getInputUser(id: ID): Promise<import("../tl/2_types.js").InputUser_>;
261
+ getInputPeer(id: ID): Promise<enums.InputPeer>;
262
+ getInputChannel(id: ID): Promise<types.InputChannel>;
263
+ getInputUser(id: ID): Promise<types.InputUser>;
254
264
  private [getEntity];
255
265
  private [getEntity];
256
266
  private [getEntity];
257
267
  private [getEntity];
258
- use(...middleware: Middleware<UpdateIntersection<C>>[]): Composer<UpdateIntersection<C>>;
259
- branch(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, trueHandler_: Middleware<UpdateIntersection<C>>, falseHandler_: Middleware<UpdateIntersection<C>>): Composer<UpdateIntersection<C>>;
268
+ use(...middleware: Middleware<UpdateIntersection<C>>[]): Composer<C>;
269
+ branch(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, trueHandler_: Middleware<UpdateIntersection<C>>, falseHandler_: Middleware<UpdateIntersection<C>>): Composer<C>;
260
270
  filter<D extends C>(predicate: (ctx: UpdateIntersection<C>) => ctx is D, ...middleware: Middleware<D>[]): Composer<D>;
261
271
  filter(predicate: (ctx: UpdateIntersection<C>) => MaybePromise<boolean>, ...middleware: Middleware<UpdateIntersection<C>>[]): Composer<C>;
262
272
  on<Q extends FilterQuery>(filter: Q, ...middleawre: Middleware<WithFilter<C, Q>>[]): Composer<UpdateIntersection<WithFilter<C, Q>>>;
263
273
  command(commands: string | RegExp | (string | RegExp)[] | {
264
274
  names: string | RegExp | (string | RegExp)[];
265
275
  prefixes: string | string[];
266
- }, ...middleawre: Middleware<WithFilter<C, "message:text">>[]): Composer<UpdateIntersection<WithFilter<C, "message:text">>>;
276
+ }, ...middleawre: Middleware<WithFilter<C, "message:text">>[]): Composer<WithFilter<C, "message:text">>;
267
277
  /**
268
278
  * Send a text message.
269
279
  *
@@ -403,8 +413,9 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
403
413
  *
404
414
  * @method fs
405
415
  * @param contents The contents of the file.
416
+ * @returns The uploaded file.
406
417
  */
407
- upload(contents: Uint8Array, params?: UploadParams): Promise<import("../tl/2_types.js").InputFile_ | import("../tl/2_types.js").InputFileBig_>;
418
+ upload(contents: Uint8Array, params?: UploadParams): Promise<any>;
408
419
  /**
409
420
  * Set the bot's commands in the given scope and/or language. Bot-only.
410
421
  *
@@ -416,6 +427,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
416
427
  * Get the bot's commands in the given scope and/or language. Bot-only.
417
428
  *
418
429
  * @method bs
430
+ * @returns The current bot's commands in the specified language.
419
431
  */
420
432
  getMyCommands(params?: GetMyCommandsParams): Promise<BotCommand[]>;
421
433
  /**
@@ -457,14 +469,16 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
457
469
  * Get the bot's description in the given language. Bot-only.
458
470
  *
459
471
  * @method bs
472
+ * @returns The current bot's description in the specified language.
460
473
  */
461
474
  getMyDescription(params?: {
462
475
  languageCode?: string;
463
476
  }): Promise<string>;
464
477
  /**
465
- * Set the bot's name in the given language. Bot-only.
478
+ * Get the bot's name in the given language. Bot-only.
466
479
  *
467
480
  * @method bs
481
+ * @returns The current bot's name in the specified language.
468
482
  */
469
483
  getMyName(params?: {
470
484
  languageCode?: string;
@@ -473,6 +487,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
473
487
  * Get the bot's short description in the given language. Bot-only.
474
488
  *
475
489
  * @method bs
490
+ * @returns The current bot's short description in the specified language.
476
491
  */
477
492
  getMyShortDescription(params?: {
478
493
  languageCode?: string;
@@ -499,6 +514,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
499
514
  * @method ms
500
515
  * @param chatId The chat to send the photo to.
501
516
  * @param photo The photo to send.
517
+ * @returns The sent photo.
502
518
  */
503
519
  sendPhoto(chatId: ID, photo: FileSource, params?: SendPhotoParams): Promise<MessagePhoto>;
504
520
  /**
@@ -507,6 +523,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
507
523
  * @method ms
508
524
  * @param chatId The chat to send the document to.
509
525
  * @param document The document to send.
526
+ * @returns The sent document.
510
527
  */
511
528
  sendDocument(chatId: ID, document: FileSource, params?: SendDocumentParams): Promise<MessageDocument>;
512
529
  /**
@@ -515,6 +532,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
515
532
  * @method ms
516
533
  * @param chatId The chat to send the video to.
517
534
  * @param video The video to send.
535
+ * @returns The sent video.
518
536
  */
519
537
  sendVideo(chatId: ID, video: FileSource, params?: SendVideoParams): Promise<MessageVideo>;
520
538
  /**
@@ -523,6 +541,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
523
541
  * @method ms
524
542
  * @param chatId The chat to send the animation to.
525
543
  * @param animation The animation to send.
544
+ * @returns The sent animation.
526
545
  */
527
546
  sendAnimation(chatId: ID, animation: FileSource, params?: SendAnimationParams): Promise<MessageAnimation>;
528
547
  /**
@@ -531,6 +550,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
531
550
  * @method ms
532
551
  * @param chatId The chat to send the voice message to.
533
552
  * @param voice The voice to send.
553
+ * @returns The sent voice message.
534
554
  */
535
555
  sendVoice(chatId: ID, voice: FileSource, params?: SendVoiceParams): Promise<MessageVoice>;
536
556
  /**
@@ -539,6 +559,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
539
559
  * @method ms
540
560
  * @param chatId The chat to send the audio file to.
541
561
  * @param audio The audio to send.
562
+ * @returns The sent audio filr.
542
563
  */
543
564
  sendAudio(chatId: ID, audio: FileSource, params?: SendAudioParams): Promise<MessageAudio>;
544
565
  /**
@@ -547,6 +568,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
547
568
  * @method ms
548
569
  * @param chatId The chat to send the video note to.
549
570
  * @param videoNote The video note to send.
571
+ * @returns The sent video note.
550
572
  */
551
573
  sendVideoNote(chatId: ID, videoNote: FileSource, params?: SendVideoNoteParams): Promise<MessageVideoNote>;
552
574
  /**
@@ -556,6 +578,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
556
578
  * @param chatId The chat to send the location to.
557
579
  * @param latitude The location's latitude.
558
580
  * @param longitude The location's longitude.
581
+ * @returns The sent location.
559
582
  */
560
583
  sendLocation(chatId: ID, latitude: number, longitude: number, params?: SendLocationParams): Promise<MessageLocation>;
561
584
  /**
@@ -565,6 +588,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
565
588
  * @param chatId The chat to send the contact to.
566
589
  * @param firstName The contact's first name.
567
590
  * @param number The contact's phone number.
591
+ * @returns The sent contact.
568
592
  */
569
593
  sendContact(chatId: ID, firstName: string, number: string, params?: SendContactParams): Promise<MessageContact>;
570
594
  /**
@@ -572,6 +596,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
572
596
  *
573
597
  * @method ms
574
598
  * @param chatId The chat to send the dice to.
599
+ * @returns The sent dice.
575
600
  */
576
601
  sendDice(chatId: ID, params?: SendDiceParams): Promise<MessageDice>;
577
602
  /**
@@ -583,6 +608,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
583
608
  * @param longitude The longitude of the venue.
584
609
  * @param title The title of the venue.
585
610
  * @param address The written address of the venue.
611
+ * @returns The sent venue.
586
612
  */
587
613
  sendVenue(chatId: ID, latitude: number, longitude: number, title: string, address: string, params?: SendVenueParams): Promise<MessageVenue>;
588
614
  /**
@@ -615,6 +641,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
615
641
  *
616
642
  * @method fs
617
643
  * @param id Identifier of one or more of custom emojis.
644
+ * @returns The custom emoji documents.
618
645
  */
619
646
  getCustomEmojiDocuments(id: string | string[]): Promise<Document[]>;
620
647
  /**
@@ -735,6 +762,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
735
762
  *
736
763
  * @method ch
737
764
  * @param chatId The identifier of the chat.
765
+ * @returns The chat's administrators.
738
766
  */
739
767
  getChatAdministrators(chatId: ID): Promise<ChatMember[]>;
740
768
  /**
@@ -759,6 +787,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
759
787
  * @method st
760
788
  * @param chatId The identifier of the chat to retrieve the story from.
761
789
  * @param storyId The identifier of the story to retrieve.
790
+ * @returns The retrieved story.
762
791
  */
763
792
  getStory(chatId: ID, storyId: number): Promise<Story | null>;
764
793
  /**
@@ -845,6 +874,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
845
874
  * @method ac
846
875
  * @param id `"me"`, a bot ID, a supergroup ID, or a channel ID.
847
876
  * @param order The new order to use.
877
+ * @returns Whether the order was changed.
848
878
  */
849
879
  reorderUsernames(id: ID, order: string[]): Promise<boolean>;
850
880
  /**
@@ -858,6 +888,7 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
858
888
  * Get inactive chats. User-only.
859
889
  *
860
890
  * @method ch
891
+ * @retuns A list of inactive chats the current user is member of.
861
892
  */
862
893
  getInactiveChats(): Promise<InactiveChat[]>;
863
894
  /**
@@ -876,5 +907,49 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
876
907
  * @param boosts The number of boosts required to circumvent its restrictions.
877
908
  */
878
909
  setBoostsRequiredToCircumventRestrictions(chatId: ID, boosts: number): Promise<void>;
910
+ /**
911
+ * Create an invite link.
912
+ *
913
+ * @method ch
914
+ * @param chatId The identifier of the chat to create the invite link for.
915
+ * @returns The newly created invite link.
916
+ */
917
+ createInviteLink(chatId: ID, params?: CreateInviteLinkParams): Promise<InviteLink>;
918
+ /**
919
+ * Get the invite links created for a chat. User-only.
920
+ *
921
+ * @method ch
922
+ * @param chatId The identifier of the chat.
923
+ * @returns The invite links created for the chat. This might be a subset of the results if they were less than `limit`. The parameters `afterDate` and `afterInviteLink` can be used for pagination.
924
+ */
925
+ getCreatedInviteLinks(chatId: ID, params?: GetCreatedInviteLinksParams): Promise<InviteLink[]>;
926
+ /**
927
+ * Join a chat. User-only.
928
+ *
929
+ * @method ch
930
+ * @param chatId The identifier of the chat to join.
931
+ */
932
+ joinChat(chatId: ID): Promise<void>;
933
+ /**
934
+ * Leave a chat.
935
+ *
936
+ * @method ch
937
+ * @param chatId The identifier of the chat to leave.
938
+ */
939
+ leaveChat(chatId: ID): Promise<void>;
940
+ /**
941
+ * Block a user. User-only.
942
+ *
943
+ * @method mc
944
+ * @param userId The identifier of the user to block.
945
+ */
946
+ blockUser(userId: ID): Promise<void>;
947
+ /**
948
+ * Unblock a user. User-only.
949
+ *
950
+ * @method mc
951
+ * @param userId The identifier of the user to unblock.
952
+ */
953
+ unblockUser(userId: ID): Promise<void>;
879
954
  }
880
955
  export {};