@mtkruto/node 0.1.143 → 0.1.144

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. package/esm/3_types.d.ts +1 -0
  2. package/esm/3_types.js +1 -0
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/0_message.js +9 -9
  6. package/esm/client/1_file_manager.js +1 -1
  7. package/esm/client/2_client_plain.js +4 -4
  8. package/esm/client/2_message_manager.d.ts +2 -1
  9. package/esm/client/2_message_manager.js +37 -21
  10. package/esm/client/4_client.d.ts +10 -1
  11. package/esm/client/4_client.js +23 -11
  12. package/esm/storage/0_storage.js +1 -1
  13. package/esm/tl/0_tl_raw_reader.js +3 -2
  14. package/esm/tl/0_tl_raw_writer.js +3 -3
  15. package/esm/transport/0_obfuscation.js +2 -2
  16. package/esm/transport/1_transport_abridged.js +1 -1
  17. package/esm/transport/1_transport_intermediate.js +1 -1
  18. package/esm/types/0__file_id.js +2 -2
  19. package/esm/types/0_chat_member_rights.d.ts +3 -0
  20. package/esm/types/0_chat_member_rights.js +45 -1
  21. package/esm/types/2_chat_member.d.ts +46 -0
  22. package/esm/types/2_chat_member.js +89 -0
  23. package/package.json +1 -1
  24. package/script/3_types.d.ts +1 -0
  25. package/script/3_types.js +1 -0
  26. package/script/4_constants.d.ts +1 -1
  27. package/script/4_constants.js +1 -1
  28. package/script/client/0_message.js +9 -9
  29. package/script/client/1_file_manager.js +1 -1
  30. package/script/client/2_client_plain.js +4 -4
  31. package/script/client/2_message_manager.d.ts +2 -1
  32. package/script/client/2_message_manager.js +36 -20
  33. package/script/client/4_client.d.ts +10 -1
  34. package/script/client/4_client.js +23 -11
  35. package/script/storage/0_storage.js +1 -1
  36. package/script/tl/0_tl_raw_reader.js +3 -2
  37. package/script/tl/0_tl_raw_writer.js +3 -3
  38. package/script/transport/0_obfuscation.js +2 -2
  39. package/script/transport/1_transport_abridged.js +1 -1
  40. package/script/transport/1_transport_intermediate.js +1 -1
  41. package/script/types/0__file_id.js +2 -2
  42. package/script/types/0_chat_member_rights.d.ts +3 -0
  43. package/script/types/0_chat_member_rights.js +48 -0
  44. package/script/types/2_chat_member.d.ts +46 -0
  45. package/script/types/2_chat_member.js +93 -0
package/esm/3_types.d.ts CHANGED
@@ -47,6 +47,7 @@ export * from "./types/1_sticker.js";
47
47
  export * from "./types/1_user.js";
48
48
  export * from "./types/1_video_note.js";
49
49
  export * from "./types/1_video.js";
50
+ export * from "./types/2_chat_member.js";
50
51
  export * from "./types/2_chosen_inline_result.js";
51
52
  export * from "./types/2_game.js";
52
53
  export * from "./types/2_inline_keyboard_button.js";
package/esm/3_types.js CHANGED
@@ -47,6 +47,7 @@ export * from "./types/1_sticker.js";
47
47
  export * from "./types/1_user.js";
48
48
  export * from "./types/1_video_note.js";
49
49
  export * from "./types/1_video.js";
50
+ export * from "./types/2_chat_member.js";
50
51
  export * from "./types/2_chosen_inline_result.js";
51
52
  export * from "./types/2_game.js";
52
53
  export * from "./types/2_inline_keyboard_button.js";
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
6
  export declare const LAYER = 169;
7
- export declare const APP_VERSION = "MTKruto 0.1.143";
7
+ export declare const APP_VERSION = "MTKruto 0.1.144";
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 = 169;
56
- export const APP_VERSION = "MTKruto 0.1.143";
56
+ export const APP_VERSION = "MTKruto 0.1.144";
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" ? "en" : navigator.language.split("-")[0];
@@ -39,11 +39,11 @@ export async function encryptMessage(message, authKey, authKeyId, salt, sessionI
39
39
  payloadWriter.write(encoded);
40
40
  payloadWriter.write(new Uint8Array(mod(-(payloadWriter.buffer.length + 12), 16) + 12));
41
41
  const payload = payloadWriter.buffer;
42
- const messageKey = (await sha256(concat(authKey.slice(88, 120), payload))).slice(8, 24);
43
- const a = await sha256(concat(messageKey, authKey.slice(0, 36)));
44
- const b = await sha256(concat(authKey.slice(40, 76), messageKey));
45
- const aesKey = concat(a.slice(0, 8), b.slice(8, 24), a.slice(24, 32));
46
- const aesIV = concat(b.slice(0, 8), a.slice(8, 24), b.slice(24, 32));
42
+ const messageKey = (await sha256(concat(authKey.subarray(88, 120), payload))).subarray(8, 24);
43
+ const a = await sha256(concat(messageKey, authKey.subarray(0, 36)));
44
+ const b = await sha256(concat(authKey.subarray(40, 76), messageKey));
45
+ const aesKey = concat(a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32));
46
+ const aesIV = concat(b.subarray(0, 8), a.subarray(8, 24), b.subarray(24, 32));
47
47
  const messageWriter = new TLWriter();
48
48
  messageWriter.writeInt64(authKeyId);
49
49
  messageWriter.write(messageKey);
@@ -55,10 +55,10 @@ export async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
55
55
  assertEquals(reader.readInt64(false), authKeyId);
56
56
  const messageKey_ = reader.readInt128();
57
57
  const messageKey = bufferFromBigInt(messageKey_, 16, true, true);
58
- const a = await sha256(concat(messageKey, authKey.slice(8, 44)));
59
- const b = await sha256(concat(authKey.slice(48, 84), messageKey));
60
- const aesKey = concat(a.slice(0, 8), b.slice(8, 24), a.slice(24, 32));
61
- const aesIv = concat(b.slice(0, 8), a.slice(8, 24), b.slice(24, 32));
58
+ const a = await sha256(concat(messageKey, authKey.subarray(8, 44)));
59
+ const b = await sha256(concat(authKey.subarray(48, 84), messageKey));
60
+ const aesKey = concat(a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32));
61
+ const aesIv = concat(b.subarray(0, 8), a.subarray(8, 24), b.subarray(24, 32));
62
62
  const plaintext = ige256Decrypt(reader.buffer, aesKey, aesIv);
63
63
  assertEquals(plaintext.buffer.byteLength % 4, 0);
64
64
  let plainReader = new TLReader(plaintext);
@@ -44,7 +44,7 @@ export class FileManager {
44
44
  try {
45
45
  const start = part * chunkSize;
46
46
  const end = start + chunkSize;
47
- const bytes = contents.slice(start, end);
47
+ const bytes = contents.subarray(start, end);
48
48
  if (bytes.length == 0) {
49
49
  continue main;
50
50
  }
@@ -106,8 +106,8 @@ export class ClientPlain extends ClientAbstract {
106
106
  d("got server_DH_params_ok");
107
107
  const newNonce_ = bufferFromBigInt(newNonce, 32, true, true);
108
108
  const serverNonce_ = bufferFromBigInt(serverNonce, 16, true, true);
109
- const tmpAesKey = concat(await sha1(concat(newNonce_, serverNonce_)), (await sha1(concat(serverNonce_, newNonce_))).slice(0, 0 + 12));
110
- const tmpAesIv = concat((await sha1(concat(serverNonce_, newNonce_))).slice(12, 12 + 8), await sha1(concat(newNonce_, newNonce_)), newNonce_.slice(0, 0 + 4));
109
+ const tmpAesKey = concat(await sha1(concat(newNonce_, serverNonce_)), (await sha1(concat(serverNonce_, newNonce_))).subarray(0, 0 + 12));
110
+ const tmpAesIv = concat((await sha1(concat(serverNonce_, newNonce_))).subarray(12, 12 + 8), await sha1(concat(newNonce_, newNonce_)), newNonce_.subarray(0, 0 + 4));
111
111
  const answerWithHash = ige256Decrypt(dhParams.encrypted_answer, tmpAesKey, tmpAesIv);
112
112
  const dhInnerData = new TLReader(answerWithHash.slice(20)).readObject();
113
113
  assertInstanceOf(dhInnerData, types.Server_DH_inner_data);
@@ -130,8 +130,8 @@ export class ClientPlain extends ClientAbstract {
130
130
  const dhGenOk = await this.invoke(new functions.set_client_DH_params({ nonce, server_nonce: serverNonce, encrypted_data: encryptedData }));
131
131
  assertInstanceOf(dhGenOk, types.Dh_gen_ok);
132
132
  d("got dh_gen_ok");
133
- const serverNonceSlice = serverNonce_.slice(0, 8);
134
- const salt = newNonce_.slice(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
133
+ const serverNonceSlice = serverNonce_.subarray(0, 8);
134
+ const salt = newNonce_.subarray(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
135
135
  const authKey_ = modExp(gA, b, dhPrime);
136
136
  const authKey = bufferFromBigInt(authKey_, 256, false, false);
137
137
  d("auth key created");
@@ -1,5 +1,5 @@
1
1
  import { enums, types } from "../2_tl.js";
2
- import { ChatAction, FileSource, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
2
+ import { ChatAction, ChatMember, FileSource, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
3
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
4
  import { AddReactionParams, SetReactionsParams } from "./0_params.js";
5
5
  import { C as C_ } from "./0_types.js";
@@ -56,5 +56,6 @@ export declare class MessageManager {
56
56
  banChatMember(chatId: ID, memberId: ID, params?: BanChatMemberParams): Promise<void>;
57
57
  unbanChatMember(chatId: ID, memberId: ID): Promise<void>;
58
58
  setChatMemberRights(chatId: ID, memberId: ID, params?: SetChatMemberRightsParams): Promise<void>;
59
+ getChatAdministrators(chatId: ID): Promise<ChatMember[]>;
59
60
  }
60
61
  export {};
@@ -13,7 +13,7 @@ var _MessageManager_instances, _MessageManager_c, _MessageManager_updatesToMessa
13
13
  import { contentType, debug } from "../0_deps.js";
14
14
  import { getRandomId, toUnixTimestamp, UNREACHABLE } from "../1_utilities.js";
15
15
  import { as, getChannelChatId, peerToChatId, types } from "../2_tl.js";
16
- import { assertMessageType, constructMessage as constructMessage_, FileID, FileType, messageEntityToTlObject, reactionEqual, reactionToTlObject, replyMarkupToTlObject } from "../3_types.js";
16
+ import { assertMessageType, chatMemberRightsToTlObject, constructChatMember, constructMessage as constructMessage_, FileID, FileType, messageEntityToTlObject, reactionEqual, reactionToTlObject, replyMarkupToTlObject } from "../3_types.js";
17
17
  import { STICKER_SET_NAME_TTL } from "../4_constants.js";
18
18
  import { parseHtml } from "./0_html.js";
19
19
  import { getFileContents, isHttpUrl } from "./0_utilities.js";
@@ -718,28 +718,44 @@ export class MessageManager {
718
718
  await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
719
719
  channel: new types.InputChannel(chat),
720
720
  participant: member,
721
- banned_rights: new types.ChatBannedRights({
722
- until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
723
- send_messages: params?.rights?.canSendMessages ? true : undefined,
724
- send_audios: params?.rights?.canSendAudio ? true : undefined,
725
- send_docs: params?.rights?.canSendDocuments ? true : undefined,
726
- send_photos: params?.rights?.canSendPhotos ? true : undefined,
727
- send_videos: params?.rights?.canSendVideos ? true : undefined,
728
- send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
729
- send_voices: params?.rights?.canSendVoice ? true : undefined,
730
- send_polls: params?.rights?.canSendPolls ? true : undefined,
731
- send_stickers: params?.rights?.canSendStickers ? true : undefined,
732
- send_gifs: params?.rights?.canSendAnimations ? true : undefined,
733
- send_games: params?.rights?.canSendGames ? true : undefined,
734
- send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
735
- embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
736
- change_info: params?.rights?.canChangeInfo ? true : undefined,
737
- invite_users: params?.rights?.canInviteUsers ? true : undefined,
738
- pin_messages: params?.rights?.canPinMessages ? true : undefined,
739
- manage_topics: params?.rights?.canManageTopics ? true : undefined,
740
- }),
721
+ banned_rights: chatMemberRightsToTlObject(params?.rights, params?.untilDate),
741
722
  });
742
723
  }
724
+ async getChatAdministrators(chatId) {
725
+ const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
726
+ if (peer instanceof types.InputPeerChannel) {
727
+ const channel = new types.InputChannel(peer);
728
+ const participants = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.getParticipants({
729
+ channel,
730
+ filter: new types.ChannelParticipantsAdmins(),
731
+ offset: 0,
732
+ limit: 100,
733
+ hash: 0n,
734
+ });
735
+ if (participants instanceof types.channels.ChannelParticipantsNotModified) {
736
+ UNREACHABLE();
737
+ }
738
+ const chatMembers = new Array();
739
+ for (const p of participants.participants) {
740
+ chatMembers.push(await constructChatMember(p, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity));
741
+ }
742
+ return chatMembers;
743
+ }
744
+ else if (peer instanceof types.InputPeerChat) {
745
+ const fullChat = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.getFullChat(peer); // TODO: full chat cache
746
+ if (!(fullChat.full_chat instanceof types.ChatFull) || !(fullChat.full_chat.participants instanceof types.ChatParticipants)) {
747
+ UNREACHABLE();
748
+ }
749
+ const chatMembers = new Array();
750
+ for (const p of fullChat.full_chat.participants.participants) {
751
+ chatMembers.push(await constructChatMember(p, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity));
752
+ }
753
+ return chatMembers;
754
+ }
755
+ else {
756
+ UNREACHABLE();
757
+ }
758
+ }
743
759
  }
744
760
  _MessageManager_c = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
745
761
  const messages = new Array();
@@ -2,7 +2,7 @@ import { MaybePromise } from "../1_utilities.js";
2
2
  import { functions, types } from "../2_tl.js";
3
3
  import { Storage } from "../3_storage.js";
4
4
  import { DC } from "../3_transport.js";
5
- import { BotCommand, Chat, ChatAction, ChatP, Document, FileSource, ID, InlineQueryResult, Message, MessageAnimation, MessageAudio, MessageContact, MessageDice, MessageDocument, MessageLocation, MessagePhoto, MessagePoll, MessageText, MessageVenue, MessageVideo, MessageVideoNote, MessageVoice, NetworkStatistics, ParseMode, Reaction, Update, UpdateIntersection, User } from "../3_types.js";
5
+ import { BotCommand, Chat, ChatAction, ChatMember, ChatP, Document, FileSource, ID, InlineQueryResult, Message, MessageAnimation, MessageAudio, MessageContact, MessageDice, MessageDocument, MessageLocation, MessagePhoto, MessagePoll, MessageText, MessageVenue, MessageVideo, MessageVideoNote, MessageVoice, NetworkStatistics, ParseMode, Reaction, Update, UpdateIntersection, User } from "../3_types.js";
6
6
  import { Migrate } from "../4_errors.js";
7
7
  import { ClientAbstract } from "./0_client_abstract.js";
8
8
  import { FilterQuery, WithFilter } from "./0_filters.js";
@@ -74,6 +74,8 @@ export interface Context {
74
74
  kickSender: () => Promise<void>;
75
75
  /** Set the rights of the received message. */
76
76
  setSenderRights: (params?: SetChatMemberRightsParams) => Promise<void>;
77
+ /** Get the administrators of the chat which the message was received from. */
78
+ getChatAdministrators: () => Promise<ChatMember[]>;
77
79
  /** Change the reactions made to the received message. */
78
80
  react: (reactions: Reaction[], params?: SetReactionsParams) => Promise<void>;
79
81
  /** Send a chat action to the chat which the message was received from. */
@@ -694,5 +696,12 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
694
696
  * @param memberId The identifier of a member.
695
697
  */
696
698
  setChatMemberRights(chatId: ID, memberId: ID, params?: SetChatMemberRightsParams): Promise<void>;
699
+ /**
700
+ * Get the administrators of a chat.
701
+ *
702
+ * @method
703
+ * @param chatId The identifier of the chat.
704
+ */
705
+ getChatAdministrators(chatId: ID): Promise<ChatMember[]>;
697
706
  }
698
707
  export {};
@@ -323,6 +323,10 @@ export class Client extends ClientAbstract {
323
323
  }
324
324
  return this.setChatMemberRights(chatId, senderId, params);
325
325
  },
326
+ getChatAdministrators: () => {
327
+ const { chatId } = mustGetMsg();
328
+ return this.getChatAdministrators(chatId);
329
+ },
326
330
  react: (reactions, params) => {
327
331
  const { chatId, messageId } = mustGetMsg();
328
332
  return this.setReactions(chatId, messageId, reactions, params);
@@ -738,16 +742,6 @@ export class Client extends ClientAbstract {
738
742
  if (!this.apiHash) {
739
743
  throw new Error("apiHash not set");
740
744
  }
741
- if (typeof params === "undefined") {
742
- const loginType = mustPromptOneOf("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
743
- if (loginType == "b") {
744
- params = mustPrompt("Bot token:");
745
- }
746
- else {
747
- params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt("Password:") };
748
- }
749
- }
750
- dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
751
745
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
752
746
  try {
753
747
  await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
@@ -761,6 +755,16 @@ export class Client extends ClientAbstract {
761
755
  throw err;
762
756
  }
763
757
  }
758
+ if (typeof params === "undefined") {
759
+ const loginType = mustPromptOneOf("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
760
+ if (loginType == "b") {
761
+ params = mustPrompt("Bot token:");
762
+ }
763
+ else {
764
+ params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt("Password:") };
765
+ }
766
+ }
767
+ dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
764
768
  if (typeof params === "string") {
765
769
  while (true) {
766
770
  try {
@@ -898,7 +902,6 @@ export class Client extends ClientAbstract {
898
902
  */
899
903
  async start(params) {
900
904
  await this.connect();
901
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
902
905
  await this.authorize(params);
903
906
  }
904
907
  /**
@@ -1843,6 +1846,15 @@ export class Client extends ClientAbstract {
1843
1846
  async setChatMemberRights(chatId, memberId, params) {
1844
1847
  await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatMemberRights(chatId, memberId, params);
1845
1848
  }
1849
+ /**
1850
+ * Get the administrators of a chat.
1851
+ *
1852
+ * @method
1853
+ * @param chatId The identifier of the chat.
1854
+ */
1855
+ async getChatAdministrators(chatId) {
1856
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").getChatAdministrators(chatId);
1857
+ }
1846
1858
  }
1847
1859
  _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
1848
1860
  await __classPrivateFieldGet(this, _Client_handle, "f").call(this, await __classPrivateFieldGet(this, _Client_constructContext, "f").call(this, update), resolve);
@@ -301,7 +301,7 @@ export class Storage {
301
301
  }
302
302
  _Storage_authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
303
303
  if (authKey != null) {
304
- __classPrivateFieldSet(this, _Storage_authKeyId, await sha1(authKey).then((hash) => bigIntFromBuffer(hash.slice(-8), true, false)), "f");
304
+ __classPrivateFieldSet(this, _Storage_authKeyId, await sha1(authKey).then((hash) => bigIntFromBuffer(hash.subarray(-8), true, false)), "f");
305
305
  }
306
306
  else {
307
307
  __classPrivateFieldSet(this, _Storage_authKeyId, null, "f");
@@ -18,7 +18,7 @@ export class TLRawReader {
18
18
  throw new TLError("No data remaining");
19
19
  }
20
20
  const buffer = this._buffer.slice(0, count);
21
- this._buffer = this._buffer.slice(count);
21
+ this._buffer = this._buffer.subarray(count);
22
22
  return buffer;
23
23
  }
24
24
  readInt24(signed = true) {
@@ -34,7 +34,8 @@ export class TLRawReader {
34
34
  return bigIntFromBuffer(buffer, true, signed);
35
35
  }
36
36
  readDouble() {
37
- return new DataView(this.read(8).buffer).getFloat64(0, true);
37
+ const buffer = this.read(8);
38
+ return new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength).getFloat64(0, true);
38
39
  }
39
40
  readInt128(signed = true) {
40
41
  const buffer = this.read(128 / 8);
@@ -28,9 +28,9 @@ export class TLRawWriter {
28
28
  return this;
29
29
  }
30
30
  writeDouble(double) {
31
- const buf = new Uint8Array(8);
32
- new DataView(buf.buffer).setFloat64(0, double, true);
33
- this.write(buf);
31
+ const buffer = new Uint8Array(8);
32
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength).setFloat64(0, double, true);
33
+ this.write(buffer);
34
34
  return this;
35
35
  }
36
36
  writeInt128(int, signed = true) {
@@ -7,7 +7,7 @@ export async function getObfuscationParameters(protocol, connection) {
7
7
  if (init[0] == 0xEF) {
8
8
  continue;
9
9
  }
10
- const dataView = new DataView(init.buffer);
10
+ const dataView = new DataView(init.buffer, init.byteOffset, init.byteLength);
11
11
  const firstInt = dataView.getInt32(0);
12
12
  if ([0x44414548, 0x54534F50, 0x20544547, 0x4954504F, 0x02010316, 0xDDDDDDDD, 0xEEEEEEEE].includes(firstInt)) {
13
13
  continue;
@@ -27,6 +27,6 @@ export async function getObfuscationParameters(protocol, connection) {
27
27
  const decryptKey = initRev.slice(8, 8 + 32);
28
28
  const decryptIv = initRev.slice(40, 40 + 16);
29
29
  const decryptionCTR = new CTR(decryptKey, decryptIv);
30
- await connection.write(concat(init.slice(0, 56), encryptedInit.slice(56, 56 + 8)));
30
+ await connection.write(concat(init.subarray(0, 56), encryptedInit.subarray(56, 56 + 8)));
31
31
  return { encryptionCTR, decryptionCTR };
32
32
  }
@@ -49,7 +49,7 @@ export class TransportAbridged extends Transport {
49
49
  const buffer = new Uint8Array(3);
50
50
  await __classPrivateFieldGet(this, _TransportAbridged_connection, "f").read(buffer);
51
51
  this.decrypt(buffer);
52
- const dataView = new DataView(buffer.buffer);
52
+ const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
53
53
  length = dataView.getUint16(0, true);
54
54
  }
55
55
  }
@@ -42,7 +42,7 @@ export class TransportIntermediate extends Transport {
42
42
  const buffer = new Uint8Array(4);
43
43
  await __classPrivateFieldGet(this, _TransportIntermediate_connection, "f").read(buffer);
44
44
  this.decrypt(buffer);
45
- const dataView = new DataView(buffer.buffer);
45
+ const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
46
46
  length = dataView.getUint32(0, true);
47
47
  }
48
48
  const buffer = new Uint8Array(length);
@@ -86,11 +86,11 @@ export class FileID {
86
86
  let buffer;
87
87
  if (major < 4) {
88
88
  minor = 0;
89
- buffer = decoded.slice(0, -1);
89
+ buffer = decoded.subarray(0, -1);
90
90
  }
91
91
  else {
92
92
  minor = decoded[decoded.length - 2];
93
- buffer = decoded.slice(0, -2);
93
+ buffer = decoded.subarray(0, -2);
94
94
  }
95
95
  const reader = new TLReader(buffer);
96
96
  let fileType = reader.readInt32();
@@ -1,3 +1,4 @@
1
+ import { types } from "../2_tl.js";
1
2
  /** The rights of a chat member. */
2
3
  export interface ChatMemberRights {
3
4
  /** Whether messages are allowed to be sent. */
@@ -35,3 +36,5 @@ export interface ChatMemberRights {
35
36
  /** Whether it is allowed to manage topics. */
36
37
  canManageTopics?: boolean;
37
38
  }
39
+ export declare function constructChatMemberRights(rights: types.ChatBannedRights): ChatMemberRights;
40
+ export declare function chatMemberRightsToTlObject(rights?: ChatMemberRights, untilDate?: Date): import("../tl/2_types.js").ChatBannedRights_;
@@ -1 +1,45 @@
1
- export {};
1
+ import { toUnixTimestamp } from "../1_utilities.js";
2
+ import { types } from "../2_tl.js";
3
+ export function constructChatMemberRights(rights) {
4
+ return {
5
+ canSendMessages: rights.send_messages ? true : false,
6
+ canSendAudio: rights.send_audios ? true : false,
7
+ canSendDocuments: rights.send_docs ? true : false,
8
+ canSendPhotos: rights.send_photos ? true : false,
9
+ canSendVideos: rights.send_messages ? true : false,
10
+ canSendVideoNotes: rights.send_roundvideos ? true : false,
11
+ canSendVoice: rights.send_voices ? true : false,
12
+ canSendPolls: rights.send_polls ? true : false,
13
+ canSendStickers: rights.send_stickers ? true : false,
14
+ canSendAnimations: rights.send_gifs ? true : undefined,
15
+ canSendGames: rights.send_games ? true : undefined,
16
+ canSendInlineBotResults: rights.send_inline ? true : undefined,
17
+ canAddWebPagePreviews: rights.embed_links ? true : undefined,
18
+ canChangeInfo: rights.change_info ? true : undefined,
19
+ canInviteUsers: rights.invite_users ? true : undefined,
20
+ canPinMessages: rights.pin_messages ? true : undefined,
21
+ canManageTopics: rights.manage_topics ? true : undefined,
22
+ };
23
+ }
24
+ export function chatMemberRightsToTlObject(rights, untilDate) {
25
+ return new types.ChatBannedRights({
26
+ until_date: untilDate ? toUnixTimestamp(untilDate) : 0,
27
+ send_messages: rights?.canSendMessages ? true : undefined,
28
+ send_audios: rights?.canSendAudio ? true : undefined,
29
+ send_docs: rights?.canSendDocuments ? true : undefined,
30
+ send_photos: rights?.canSendPhotos ? true : undefined,
31
+ send_videos: rights?.canSendVideos ? true : undefined,
32
+ send_roundvideos: rights?.canSendVideoNotes ? true : undefined,
33
+ send_voices: rights?.canSendVoice ? true : undefined,
34
+ send_polls: rights?.canSendPolls ? true : undefined,
35
+ send_stickers: rights?.canSendStickers ? true : undefined,
36
+ send_gifs: rights?.canSendAnimations ? true : undefined,
37
+ send_games: rights?.canSendGames ? true : undefined,
38
+ send_inline: rights?.canSendInlineBotResults ? true : undefined,
39
+ embed_links: rights?.canAddWebPagePreviews ? true : undefined,
40
+ change_info: rights?.canChangeInfo ? true : undefined,
41
+ invite_users: rights?.canInviteUsers ? true : undefined,
42
+ pin_messages: rights?.canPinMessages ? true : undefined,
43
+ manage_topics: rights?.canManageTopics ? true : undefined,
44
+ });
45
+ }
@@ -0,0 +1,46 @@
1
+ import { enums } from "../2_tl.js";
2
+ import { ChatAdministratorRights } from "./0_chat_administrator_rights.js";
3
+ import { ChatMemberRights } from "./0_chat_member_rights.js";
4
+ import { EntityGetter } from "./1__getters.js";
5
+ import { User } from "./1_user.js";
6
+ /** @unlisted */
7
+ export type ChatMemberStatus = "creator" | "administrator" | "member" | "restricted" | "left" | "banned";
8
+ /** @unlisted */
9
+ export interface ChatMemberBase {
10
+ status: ChatMemberStatus;
11
+ user: User;
12
+ }
13
+ /** @unlisted */
14
+ export interface ChatMemberCreator extends ChatMemberBase {
15
+ status: "creator";
16
+ isAnonymous: boolean;
17
+ title?: string;
18
+ }
19
+ /** @unlisted */
20
+ export interface ChatMemberAdministrator extends ChatMemberBase {
21
+ status: "administrator";
22
+ rights: ChatAdministratorRights;
23
+ title?: string;
24
+ }
25
+ /** @unlisted */
26
+ export interface ChatMemberMember extends ChatMemberBase {
27
+ status: "member";
28
+ }
29
+ /** @unlisted */
30
+ export interface ChatMemberRestricted extends ChatMemberBase {
31
+ status: "restricted";
32
+ isMember: boolean;
33
+ rights: ChatMemberRights;
34
+ untilDate?: Date;
35
+ }
36
+ /** @unlisted */
37
+ export interface ChatMemberLeft extends ChatMemberBase {
38
+ status: "left";
39
+ }
40
+ /** @unlisted */
41
+ export interface ChatMemberBanned extends ChatMemberBase {
42
+ status: "banned";
43
+ untilDate?: Date;
44
+ }
45
+ export type ChatMember = ChatMemberCreator | ChatMemberAdministrator | ChatMemberMember | ChatMemberRestricted | ChatMemberLeft | ChatMemberBanned;
46
+ export declare function constructChatMember(participant: enums.ChannelParticipant | enums.ChatParticipant, getEntity: EntityGetter): Promise<ChatMember>;
@@ -0,0 +1,89 @@
1
+ import { cleanObject, fromUnixTimestamp, UNREACHABLE } from "../1_utilities.js";
2
+ import { types } from "../2_tl.js";
3
+ import { constructChatAdministratorRights } from "./0_chat_administrator_rights.js";
4
+ import { constructChatMemberRights } from "./0_chat_member_rights.js";
5
+ import { constructUser } from "./1_user.js";
6
+ export async function constructChatMember(participant, getEntity) {
7
+ const user_ = "user_id" in participant ? await getEntity(new types.PeerUser(participant)) : "peer" in participant ? participant.peer instanceof types.PeerUser ? await getEntity(participant.peer) : UNREACHABLE() : UNREACHABLE(); // TODO: support other peer types
8
+ if (user_ == null)
9
+ UNREACHABLE();
10
+ const user = constructUser(user_);
11
+ if (participant instanceof types.ChannelParticipant || participant instanceof types.ChatParticipant) {
12
+ return {
13
+ status: "member",
14
+ user,
15
+ };
16
+ }
17
+ else if (participant instanceof types.ChannelParticipantCreator) {
18
+ return cleanObject({
19
+ status: "creator",
20
+ user,
21
+ isAnonymous: participant.admin_rights.anonymous ? true : false,
22
+ title: participant.rank,
23
+ });
24
+ }
25
+ else if (participant instanceof types.ChannelParticipantAdmin) {
26
+ return cleanObject({
27
+ status: "administrator",
28
+ user,
29
+ rights: constructChatAdministratorRights(participant.admin_rights),
30
+ title: participant.rank,
31
+ });
32
+ }
33
+ else if (participant instanceof types.ChannelParticipantBanned) {
34
+ const untilDate = participant.banned_rights.until_date ? fromUnixTimestamp(participant.banned_rights.until_date) : undefined;
35
+ if (!participant.banned_rights.view_messages) {
36
+ participant.peer;
37
+ return cleanObject({
38
+ status: "banned",
39
+ user,
40
+ untilDate,
41
+ });
42
+ }
43
+ const isMember = participant.left ? true : false;
44
+ const rights = constructChatMemberRights(participant.banned_rights);
45
+ return cleanObject({
46
+ status: "restricted",
47
+ user,
48
+ isMember,
49
+ rights,
50
+ untilDate,
51
+ });
52
+ }
53
+ else if (participant instanceof types.ChannelParticipantSelf) {
54
+ UNREACHABLE(); // TODO: implement
55
+ }
56
+ else if (participant instanceof types.ChannelParticipantLeft) {
57
+ return { status: "left", user };
58
+ }
59
+ else if (participant instanceof types.ChatParticipantAdmin) {
60
+ return cleanObject({
61
+ status: "administrator",
62
+ user,
63
+ rights: {
64
+ isAnonymous: false,
65
+ canManageChat: true,
66
+ canDeleteMessages: true,
67
+ canManageVideoChats: false,
68
+ canRestrictMembers: true,
69
+ canPromoteMembers: false,
70
+ canChangeInfo: true,
71
+ canInviteUsers: true,
72
+ canPostMessages: false,
73
+ canEditMessages: false,
74
+ canPinMessages: true,
75
+ canManageTopics: false,
76
+ },
77
+ });
78
+ }
79
+ else if (participant instanceof types.ChatParticipantCreator) {
80
+ return cleanObject({
81
+ status: "creator",
82
+ user,
83
+ isAnonymous: false,
84
+ });
85
+ }
86
+ else {
87
+ UNREACHABLE();
88
+ }
89
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtkruto/node",
3
- "version": "0.1.143",
3
+ "version": "0.1.144",
4
4
  "description": "MTKruto for Node.js",
5
5
  "author": "Roj <rojvv@icloud.com>",
6
6
  "repository": {
@@ -47,6 +47,7 @@ export * from "./types/1_sticker.js";
47
47
  export * from "./types/1_user.js";
48
48
  export * from "./types/1_video_note.js";
49
49
  export * from "./types/1_video.js";
50
+ export * from "./types/2_chat_member.js";
50
51
  export * from "./types/2_chosen_inline_result.js";
51
52
  export * from "./types/2_game.js";
52
53
  export * from "./types/2_inline_keyboard_button.js";
package/script/3_types.js CHANGED
@@ -63,6 +63,7 @@ __exportStar(require("./types/1_sticker.js"), exports);
63
63
  __exportStar(require("./types/1_user.js"), exports);
64
64
  __exportStar(require("./types/1_video_note.js"), exports);
65
65
  __exportStar(require("./types/1_video.js"), exports);
66
+ __exportStar(require("./types/2_chat_member.js"), exports);
66
67
  __exportStar(require("./types/2_chosen_inline_result.js"), exports);
67
68
  __exportStar(require("./types/2_game.js"), exports);
68
69
  __exportStar(require("./types/2_inline_keyboard_button.js"), exports);
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
4
4
  export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const INITIAL_DC: DC;
6
6
  export declare const LAYER = 169;
7
- export declare const APP_VERSION = "MTKruto 0.1.143";
7
+ export declare const APP_VERSION = "MTKruto 0.1.144";
8
8
  export declare const DEVICE_MODEL: string;
9
9
  export declare const LANG_CODE: string;
10
10
  export declare const LANG_PACK = "";
@@ -79,7 +79,7 @@ exports.PUBLIC_KEYS = Object.freeze([
79
79
  ]);
80
80
  exports.INITIAL_DC = "2";
81
81
  exports.LAYER = 169;
82
- exports.APP_VERSION = "MTKruto 0.1.143";
82
+ exports.APP_VERSION = "MTKruto 0.1.144";
83
83
  // @ts-ignore: lib
84
84
  exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
85
85
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -45,11 +45,11 @@ async function encryptMessage(message, authKey, authKeyId, salt, sessionId) {
45
45
  payloadWriter.write(encoded);
46
46
  payloadWriter.write(new Uint8Array((0, _1_utilities_js_1.mod)(-(payloadWriter.buffer.length + 12), 16) + 12));
47
47
  const payload = payloadWriter.buffer;
48
- const messageKey = (await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.slice(88, 120), payload))).slice(8, 24);
49
- const a = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(messageKey, authKey.slice(0, 36)));
50
- const b = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.slice(40, 76), messageKey));
51
- const aesKey = (0, _1_utilities_js_1.concat)(a.slice(0, 8), b.slice(8, 24), a.slice(24, 32));
52
- const aesIV = (0, _1_utilities_js_1.concat)(b.slice(0, 8), a.slice(8, 24), b.slice(24, 32));
48
+ const messageKey = (await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.subarray(88, 120), payload))).subarray(8, 24);
49
+ const a = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(messageKey, authKey.subarray(0, 36)));
50
+ const b = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.subarray(40, 76), messageKey));
51
+ const aesKey = (0, _1_utilities_js_1.concat)(a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32));
52
+ const aesIV = (0, _1_utilities_js_1.concat)(b.subarray(0, 8), a.subarray(8, 24), b.subarray(24, 32));
53
53
  const messageWriter = new _2_tl_js_1.TLWriter();
54
54
  messageWriter.writeInt64(authKeyId);
55
55
  messageWriter.write(messageKey);
@@ -62,10 +62,10 @@ async function decryptMessage(buffer, authKey, authKeyId, _sessionId) {
62
62
  (0, _0_deps_js_1.assertEquals)(reader.readInt64(false), authKeyId);
63
63
  const messageKey_ = reader.readInt128();
64
64
  const messageKey = (0, _1_utilities_js_1.bufferFromBigInt)(messageKey_, 16, true, true);
65
- const a = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(messageKey, authKey.slice(8, 44)));
66
- const b = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.slice(48, 84), messageKey));
67
- const aesKey = (0, _1_utilities_js_1.concat)(a.slice(0, 8), b.slice(8, 24), a.slice(24, 32));
68
- const aesIv = (0, _1_utilities_js_1.concat)(b.slice(0, 8), a.slice(8, 24), b.slice(24, 32));
65
+ const a = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(messageKey, authKey.subarray(8, 44)));
66
+ const b = await (0, _1_utilities_js_1.sha256)((0, _1_utilities_js_1.concat)(authKey.subarray(48, 84), messageKey));
67
+ const aesKey = (0, _1_utilities_js_1.concat)(a.subarray(0, 8), b.subarray(8, 24), a.subarray(24, 32));
68
+ const aesIv = (0, _1_utilities_js_1.concat)(b.subarray(0, 8), a.subarray(8, 24), b.subarray(24, 32));
69
69
  const plaintext = (0, _0_deps_js_1.ige256Decrypt)(reader.buffer, aesKey, aesIv);
70
70
  (0, _0_deps_js_1.assertEquals)(plaintext.buffer.byteLength % 4, 0);
71
71
  let plainReader = new _2_tl_js_1.TLReader(plaintext);
@@ -47,7 +47,7 @@ class FileManager {
47
47
  try {
48
48
  const start = part * chunkSize;
49
49
  const end = start + chunkSize;
50
- const bytes = contents.slice(start, end);
50
+ const bytes = contents.subarray(start, end);
51
51
  if (bytes.length == 0) {
52
52
  continue main;
53
53
  }
@@ -109,8 +109,8 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
109
109
  d("got server_DH_params_ok");
110
110
  const newNonce_ = (0, _1_utilities_js_1.bufferFromBigInt)(newNonce, 32, true, true);
111
111
  const serverNonce_ = (0, _1_utilities_js_1.bufferFromBigInt)(serverNonce, 16, true, true);
112
- const tmpAesKey = (0, _1_utilities_js_1.concat)(await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(newNonce_, serverNonce_)), (await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(serverNonce_, newNonce_))).slice(0, 0 + 12));
113
- const tmpAesIv = (0, _1_utilities_js_1.concat)((await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(serverNonce_, newNonce_))).slice(12, 12 + 8), await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(newNonce_, newNonce_)), newNonce_.slice(0, 0 + 4));
112
+ const tmpAesKey = (0, _1_utilities_js_1.concat)(await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(newNonce_, serverNonce_)), (await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(serverNonce_, newNonce_))).subarray(0, 0 + 12));
113
+ const tmpAesIv = (0, _1_utilities_js_1.concat)((await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(serverNonce_, newNonce_))).subarray(12, 12 + 8), await (0, _1_utilities_js_1.sha1)((0, _1_utilities_js_1.concat)(newNonce_, newNonce_)), newNonce_.subarray(0, 0 + 4));
114
114
  const answerWithHash = (0, _0_deps_js_1.ige256Decrypt)(dhParams.encrypted_answer, tmpAesKey, tmpAesIv);
115
115
  const dhInnerData = new _2_tl_js_1.TLReader(answerWithHash.slice(20)).readObject();
116
116
  (0, _0_deps_js_1.assertInstanceOf)(dhInnerData, _2_tl_js_1.types.Server_DH_inner_data);
@@ -133,8 +133,8 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
133
133
  const dhGenOk = await this.invoke(new _2_tl_js_1.functions.set_client_DH_params({ nonce, server_nonce: serverNonce, encrypted_data: encryptedData }));
134
134
  (0, _0_deps_js_1.assertInstanceOf)(dhGenOk, _2_tl_js_1.types.Dh_gen_ok);
135
135
  d("got dh_gen_ok");
136
- const serverNonceSlice = serverNonce_.slice(0, 8);
137
- const salt = newNonce_.slice(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
136
+ const serverNonceSlice = serverNonce_.subarray(0, 8);
137
+ const salt = newNonce_.subarray(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
138
138
  const authKey_ = (0, _1_utilities_js_1.modExp)(gA, b, dhPrime);
139
139
  const authKey = (0, _1_utilities_js_1.bufferFromBigInt)(authKey_, 256, false, false);
140
140
  d("auth key created");
@@ -1,5 +1,5 @@
1
1
  import { enums, types } from "../2_tl.js";
2
- import { ChatAction, FileSource, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
2
+ import { ChatAction, ChatMember, FileSource, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
3
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
4
  import { AddReactionParams, SetReactionsParams } from "./0_params.js";
5
5
  import { C as C_ } from "./0_types.js";
@@ -56,5 +56,6 @@ export declare class MessageManager {
56
56
  banChatMember(chatId: ID, memberId: ID, params?: BanChatMemberParams): Promise<void>;
57
57
  unbanChatMember(chatId: ID, memberId: ID): Promise<void>;
58
58
  setChatMemberRights(chatId: ID, memberId: ID, params?: SetChatMemberRightsParams): Promise<void>;
59
+ getChatAdministrators(chatId: ID): Promise<ChatMember[]>;
59
60
  }
60
61
  export {};
@@ -721,28 +721,44 @@ class MessageManager {
721
721
  await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
722
722
  channel: new _2_tl_js_1.types.InputChannel(chat),
723
723
  participant: member,
724
- banned_rights: new _2_tl_js_1.types.ChatBannedRights({
725
- until_date: params?.untilDate ? (0, _1_utilities_js_1.toUnixTimestamp)(params.untilDate) : 0,
726
- send_messages: params?.rights?.canSendMessages ? true : undefined,
727
- send_audios: params?.rights?.canSendAudio ? true : undefined,
728
- send_docs: params?.rights?.canSendDocuments ? true : undefined,
729
- send_photos: params?.rights?.canSendPhotos ? true : undefined,
730
- send_videos: params?.rights?.canSendVideos ? true : undefined,
731
- send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
732
- send_voices: params?.rights?.canSendVoice ? true : undefined,
733
- send_polls: params?.rights?.canSendPolls ? true : undefined,
734
- send_stickers: params?.rights?.canSendStickers ? true : undefined,
735
- send_gifs: params?.rights?.canSendAnimations ? true : undefined,
736
- send_games: params?.rights?.canSendGames ? true : undefined,
737
- send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
738
- embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
739
- change_info: params?.rights?.canChangeInfo ? true : undefined,
740
- invite_users: params?.rights?.canInviteUsers ? true : undefined,
741
- pin_messages: params?.rights?.canPinMessages ? true : undefined,
742
- manage_topics: params?.rights?.canManageTopics ? true : undefined,
743
- }),
724
+ banned_rights: (0, _3_types_js_1.chatMemberRightsToTlObject)(params?.rights, params?.untilDate),
744
725
  });
745
726
  }
727
+ async getChatAdministrators(chatId) {
728
+ const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
729
+ if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
730
+ const channel = new _2_tl_js_1.types.InputChannel(peer);
731
+ const participants = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.getParticipants({
732
+ channel,
733
+ filter: new _2_tl_js_1.types.ChannelParticipantsAdmins(),
734
+ offset: 0,
735
+ limit: 100,
736
+ hash: 0n,
737
+ });
738
+ if (participants instanceof _2_tl_js_1.types.channels.ChannelParticipantsNotModified) {
739
+ (0, _1_utilities_js_1.UNREACHABLE)();
740
+ }
741
+ const chatMembers = new Array();
742
+ for (const p of participants.participants) {
743
+ chatMembers.push(await (0, _3_types_js_1.constructChatMember)(p, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity));
744
+ }
745
+ return chatMembers;
746
+ }
747
+ else if (peer instanceof _2_tl_js_1.types.InputPeerChat) {
748
+ const fullChat = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.getFullChat(peer); // TODO: full chat cache
749
+ if (!(fullChat.full_chat instanceof _2_tl_js_1.types.ChatFull) || !(fullChat.full_chat.participants instanceof _2_tl_js_1.types.ChatParticipants)) {
750
+ (0, _1_utilities_js_1.UNREACHABLE)();
751
+ }
752
+ const chatMembers = new Array();
753
+ for (const p of fullChat.full_chat.participants.participants) {
754
+ chatMembers.push(await (0, _3_types_js_1.constructChatMember)(p, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity));
755
+ }
756
+ return chatMembers;
757
+ }
758
+ else {
759
+ (0, _1_utilities_js_1.UNREACHABLE)();
760
+ }
761
+ }
746
762
  }
747
763
  exports.MessageManager = MessageManager;
748
764
  _MessageManager_c = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
@@ -2,7 +2,7 @@ import { MaybePromise } from "../1_utilities.js";
2
2
  import { functions, types } from "../2_tl.js";
3
3
  import { Storage } from "../3_storage.js";
4
4
  import { DC } from "../3_transport.js";
5
- import { BotCommand, Chat, ChatAction, ChatP, Document, FileSource, ID, InlineQueryResult, Message, MessageAnimation, MessageAudio, MessageContact, MessageDice, MessageDocument, MessageLocation, MessagePhoto, MessagePoll, MessageText, MessageVenue, MessageVideo, MessageVideoNote, MessageVoice, NetworkStatistics, ParseMode, Reaction, Update, UpdateIntersection, User } from "../3_types.js";
5
+ import { BotCommand, Chat, ChatAction, ChatMember, ChatP, Document, FileSource, ID, InlineQueryResult, Message, MessageAnimation, MessageAudio, MessageContact, MessageDice, MessageDocument, MessageLocation, MessagePhoto, MessagePoll, MessageText, MessageVenue, MessageVideo, MessageVideoNote, MessageVoice, NetworkStatistics, ParseMode, Reaction, Update, UpdateIntersection, User } from "../3_types.js";
6
6
  import { Migrate } from "../4_errors.js";
7
7
  import { ClientAbstract } from "./0_client_abstract.js";
8
8
  import { FilterQuery, WithFilter } from "./0_filters.js";
@@ -74,6 +74,8 @@ export interface Context {
74
74
  kickSender: () => Promise<void>;
75
75
  /** Set the rights of the received message. */
76
76
  setSenderRights: (params?: SetChatMemberRightsParams) => Promise<void>;
77
+ /** Get the administrators of the chat which the message was received from. */
78
+ getChatAdministrators: () => Promise<ChatMember[]>;
77
79
  /** Change the reactions made to the received message. */
78
80
  react: (reactions: Reaction[], params?: SetReactionsParams) => Promise<void>;
79
81
  /** Send a chat action to the chat which the message was received from. */
@@ -694,5 +696,12 @@ export declare class Client<C extends Context = Context> extends ClientAbstract
694
696
  * @param memberId The identifier of a member.
695
697
  */
696
698
  setChatMemberRights(chatId: ID, memberId: ID, params?: SetChatMemberRightsParams): Promise<void>;
699
+ /**
700
+ * Get the administrators of a chat.
701
+ *
702
+ * @method
703
+ * @param chatId The identifier of the chat.
704
+ */
705
+ getChatAdministrators(chatId: ID): Promise<ChatMember[]>;
697
706
  }
698
707
  export {};
@@ -327,6 +327,10 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
327
327
  }
328
328
  return this.setChatMemberRights(chatId, senderId, params);
329
329
  },
330
+ getChatAdministrators: () => {
331
+ const { chatId } = mustGetMsg();
332
+ return this.getChatAdministrators(chatId);
333
+ },
330
334
  react: (reactions, params) => {
331
335
  const { chatId, messageId } = mustGetMsg();
332
336
  return this.setReactions(chatId, messageId, reactions, params);
@@ -742,16 +746,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
742
746
  if (!this.apiHash) {
743
747
  throw new Error("apiHash not set");
744
748
  }
745
- if (typeof params === "undefined") {
746
- const loginType = (0, _1_utilities_js_1.mustPromptOneOf)("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
747
- if (loginType == "b") {
748
- params = (0, _1_utilities_js_1.mustPrompt)("Bot token:");
749
- }
750
- else {
751
- params = { phone: () => (0, _1_utilities_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_utilities_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_utilities_js_1.mustPrompt)("Password:") };
752
- }
753
- }
754
- dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof _2_tl_js_1.types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
755
749
  await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
756
750
  try {
757
751
  await __classPrivateFieldGet(this, _Client_updateManager, "f").fetchState("authorize");
@@ -765,6 +759,16 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
765
759
  throw err;
766
760
  }
767
761
  }
762
+ if (typeof params === "undefined") {
763
+ const loginType = (0, _1_utilities_js_1.mustPromptOneOf)("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
764
+ if (loginType == "b") {
765
+ params = (0, _1_utilities_js_1.mustPrompt)("Bot token:");
766
+ }
767
+ else {
768
+ params = { phone: () => (0, _1_utilities_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_utilities_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_utilities_js_1.mustPrompt)("Password:") };
769
+ }
770
+ }
771
+ dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof _2_tl_js_1.types.auth.ExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
768
772
  if (typeof params === "string") {
769
773
  while (true) {
770
774
  try {
@@ -902,7 +906,6 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
902
906
  */
903
907
  async start(params) {
904
908
  await this.connect();
905
- await __classPrivateFieldGet(this, _Client_instances, "m", _Client_initConnection).call(this);
906
909
  await this.authorize(params);
907
910
  }
908
911
  /**
@@ -1847,6 +1850,15 @@ class Client extends _0_client_abstract_js_1.ClientAbstract {
1847
1850
  async setChatMemberRights(chatId, memberId, params) {
1848
1851
  await __classPrivateFieldGet(this, _Client_messageManager, "f").setChatMemberRights(chatId, memberId, params);
1849
1852
  }
1853
+ /**
1854
+ * Get the administrators of a chat.
1855
+ *
1856
+ * @method
1857
+ * @param chatId The identifier of the chat.
1858
+ */
1859
+ async getChatAdministrators(chatId) {
1860
+ return await __classPrivateFieldGet(this, _Client_messageManager, "f").getChatAdministrators(chatId);
1861
+ }
1850
1862
  }
1851
1863
  exports.Client = Client;
1852
1864
  _Client_handleCtxUpdate = async function _Client_handleCtxUpdate(update) {
@@ -305,7 +305,7 @@ class Storage {
305
305
  exports.Storage = Storage;
306
306
  _Storage_authKeyId = new WeakMap(), _Storage_instances = new WeakSet(), _Storage_resetAuthKeyId = async function _Storage_resetAuthKeyId(authKey) {
307
307
  if (authKey != null) {
308
- __classPrivateFieldSet(this, _Storage_authKeyId, await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.slice(-8), true, false)), "f");
308
+ __classPrivateFieldSet(this, _Storage_authKeyId, await (0, _1_utilities_js_1.sha1)(authKey).then((hash) => (0, _1_utilities_js_1.bigIntFromBuffer)(hash.subarray(-8), true, false)), "f");
309
309
  }
310
310
  else {
311
311
  __classPrivateFieldSet(this, _Storage_authKeyId, null, "f");
@@ -22,7 +22,7 @@ class TLRawReader {
22
22
  throw new TLError("No data remaining");
23
23
  }
24
24
  const buffer = this._buffer.slice(0, count);
25
- this._buffer = this._buffer.slice(count);
25
+ this._buffer = this._buffer.subarray(count);
26
26
  return buffer;
27
27
  }
28
28
  readInt24(signed = true) {
@@ -38,7 +38,8 @@ class TLRawReader {
38
38
  return (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, signed);
39
39
  }
40
40
  readDouble() {
41
- return new DataView(this.read(8).buffer).getFloat64(0, true);
41
+ const buffer = this.read(8);
42
+ return new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength).getFloat64(0, true);
42
43
  }
43
44
  readInt128(signed = true) {
44
45
  const buffer = this.read(128 / 8);
@@ -31,9 +31,9 @@ class TLRawWriter {
31
31
  return this;
32
32
  }
33
33
  writeDouble(double) {
34
- const buf = new Uint8Array(8);
35
- new DataView(buf.buffer).setFloat64(0, double, true);
36
- this.write(buf);
34
+ const buffer = new Uint8Array(8);
35
+ new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength).setFloat64(0, double, true);
36
+ this.write(buffer);
37
37
  return this;
38
38
  }
39
39
  writeInt128(int, signed = true) {
@@ -33,7 +33,7 @@ async function getObfuscationParameters(protocol, connection) {
33
33
  if (init[0] == 0xEF) {
34
34
  continue;
35
35
  }
36
- const dataView = new DataView(init.buffer);
36
+ const dataView = new DataView(init.buffer, init.byteOffset, init.byteLength);
37
37
  const firstInt = dataView.getInt32(0);
38
38
  if ([0x44414548, 0x54534F50, 0x20544547, 0x4954504F, 0x02010316, 0xDDDDDDDD, 0xEEEEEEEE].includes(firstInt)) {
39
39
  continue;
@@ -53,7 +53,7 @@ async function getObfuscationParameters(protocol, connection) {
53
53
  const decryptKey = initRev.slice(8, 8 + 32);
54
54
  const decryptIv = initRev.slice(40, 40 + 16);
55
55
  const decryptionCTR = new _1_utilities_js_1.CTR(decryptKey, decryptIv);
56
- await connection.write((0, _1_utilities_js_1.concat)(init.slice(0, 56), encryptedInit.slice(56, 56 + 8)));
56
+ await connection.write((0, _1_utilities_js_1.concat)(init.subarray(0, 56), encryptedInit.subarray(56, 56 + 8)));
57
57
  return { encryptionCTR, decryptionCTR };
58
58
  }
59
59
  exports.getObfuscationParameters = getObfuscationParameters;
@@ -52,7 +52,7 @@ class TransportAbridged extends _0_transport_js_1.Transport {
52
52
  const buffer = new Uint8Array(3);
53
53
  await __classPrivateFieldGet(this, _TransportAbridged_connection, "f").read(buffer);
54
54
  this.decrypt(buffer);
55
- const dataView = new DataView(buffer.buffer);
55
+ const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
56
56
  length = dataView.getUint16(0, true);
57
57
  }
58
58
  }
@@ -45,7 +45,7 @@ class TransportIntermediate extends _0_transport_js_1.Transport {
45
45
  const buffer = new Uint8Array(4);
46
46
  await __classPrivateFieldGet(this, _TransportIntermediate_connection, "f").read(buffer);
47
47
  this.decrypt(buffer);
48
- const dataView = new DataView(buffer.buffer);
48
+ const dataView = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
49
49
  length = dataView.getUint32(0, true);
50
50
  }
51
51
  const buffer = new Uint8Array(length);
@@ -89,11 +89,11 @@ class FileID {
89
89
  let buffer;
90
90
  if (major < 4) {
91
91
  minor = 0;
92
- buffer = decoded.slice(0, -1);
92
+ buffer = decoded.subarray(0, -1);
93
93
  }
94
94
  else {
95
95
  minor = decoded[decoded.length - 2];
96
- buffer = decoded.slice(0, -2);
96
+ buffer = decoded.subarray(0, -2);
97
97
  }
98
98
  const reader = new _2_tl_js_1.TLReader(buffer);
99
99
  let fileType = reader.readInt32();
@@ -1,3 +1,4 @@
1
+ import { types } from "../2_tl.js";
1
2
  /** The rights of a chat member. */
2
3
  export interface ChatMemberRights {
3
4
  /** Whether messages are allowed to be sent. */
@@ -35,3 +36,5 @@ export interface ChatMemberRights {
35
36
  /** Whether it is allowed to manage topics. */
36
37
  canManageTopics?: boolean;
37
38
  }
39
+ export declare function constructChatMemberRights(rights: types.ChatBannedRights): ChatMemberRights;
40
+ export declare function chatMemberRightsToTlObject(rights?: ChatMemberRights, untilDate?: Date): import("../tl/2_types.js").ChatBannedRights_;
@@ -1,2 +1,50 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.chatMemberRightsToTlObject = exports.constructChatMemberRights = void 0;
4
+ const _1_utilities_js_1 = require("../1_utilities.js");
5
+ const _2_tl_js_1 = require("../2_tl.js");
6
+ function constructChatMemberRights(rights) {
7
+ return {
8
+ canSendMessages: rights.send_messages ? true : false,
9
+ canSendAudio: rights.send_audios ? true : false,
10
+ canSendDocuments: rights.send_docs ? true : false,
11
+ canSendPhotos: rights.send_photos ? true : false,
12
+ canSendVideos: rights.send_messages ? true : false,
13
+ canSendVideoNotes: rights.send_roundvideos ? true : false,
14
+ canSendVoice: rights.send_voices ? true : false,
15
+ canSendPolls: rights.send_polls ? true : false,
16
+ canSendStickers: rights.send_stickers ? true : false,
17
+ canSendAnimations: rights.send_gifs ? true : undefined,
18
+ canSendGames: rights.send_games ? true : undefined,
19
+ canSendInlineBotResults: rights.send_inline ? true : undefined,
20
+ canAddWebPagePreviews: rights.embed_links ? true : undefined,
21
+ canChangeInfo: rights.change_info ? true : undefined,
22
+ canInviteUsers: rights.invite_users ? true : undefined,
23
+ canPinMessages: rights.pin_messages ? true : undefined,
24
+ canManageTopics: rights.manage_topics ? true : undefined,
25
+ };
26
+ }
27
+ exports.constructChatMemberRights = constructChatMemberRights;
28
+ function chatMemberRightsToTlObject(rights, untilDate) {
29
+ return new _2_tl_js_1.types.ChatBannedRights({
30
+ until_date: untilDate ? (0, _1_utilities_js_1.toUnixTimestamp)(untilDate) : 0,
31
+ send_messages: rights?.canSendMessages ? true : undefined,
32
+ send_audios: rights?.canSendAudio ? true : undefined,
33
+ send_docs: rights?.canSendDocuments ? true : undefined,
34
+ send_photos: rights?.canSendPhotos ? true : undefined,
35
+ send_videos: rights?.canSendVideos ? true : undefined,
36
+ send_roundvideos: rights?.canSendVideoNotes ? true : undefined,
37
+ send_voices: rights?.canSendVoice ? true : undefined,
38
+ send_polls: rights?.canSendPolls ? true : undefined,
39
+ send_stickers: rights?.canSendStickers ? true : undefined,
40
+ send_gifs: rights?.canSendAnimations ? true : undefined,
41
+ send_games: rights?.canSendGames ? true : undefined,
42
+ send_inline: rights?.canSendInlineBotResults ? true : undefined,
43
+ embed_links: rights?.canAddWebPagePreviews ? true : undefined,
44
+ change_info: rights?.canChangeInfo ? true : undefined,
45
+ invite_users: rights?.canInviteUsers ? true : undefined,
46
+ pin_messages: rights?.canPinMessages ? true : undefined,
47
+ manage_topics: rights?.canManageTopics ? true : undefined,
48
+ });
49
+ }
50
+ exports.chatMemberRightsToTlObject = chatMemberRightsToTlObject;
@@ -0,0 +1,46 @@
1
+ import { enums } from "../2_tl.js";
2
+ import { ChatAdministratorRights } from "./0_chat_administrator_rights.js";
3
+ import { ChatMemberRights } from "./0_chat_member_rights.js";
4
+ import { EntityGetter } from "./1__getters.js";
5
+ import { User } from "./1_user.js";
6
+ /** @unlisted */
7
+ export type ChatMemberStatus = "creator" | "administrator" | "member" | "restricted" | "left" | "banned";
8
+ /** @unlisted */
9
+ export interface ChatMemberBase {
10
+ status: ChatMemberStatus;
11
+ user: User;
12
+ }
13
+ /** @unlisted */
14
+ export interface ChatMemberCreator extends ChatMemberBase {
15
+ status: "creator";
16
+ isAnonymous: boolean;
17
+ title?: string;
18
+ }
19
+ /** @unlisted */
20
+ export interface ChatMemberAdministrator extends ChatMemberBase {
21
+ status: "administrator";
22
+ rights: ChatAdministratorRights;
23
+ title?: string;
24
+ }
25
+ /** @unlisted */
26
+ export interface ChatMemberMember extends ChatMemberBase {
27
+ status: "member";
28
+ }
29
+ /** @unlisted */
30
+ export interface ChatMemberRestricted extends ChatMemberBase {
31
+ status: "restricted";
32
+ isMember: boolean;
33
+ rights: ChatMemberRights;
34
+ untilDate?: Date;
35
+ }
36
+ /** @unlisted */
37
+ export interface ChatMemberLeft extends ChatMemberBase {
38
+ status: "left";
39
+ }
40
+ /** @unlisted */
41
+ export interface ChatMemberBanned extends ChatMemberBase {
42
+ status: "banned";
43
+ untilDate?: Date;
44
+ }
45
+ export type ChatMember = ChatMemberCreator | ChatMemberAdministrator | ChatMemberMember | ChatMemberRestricted | ChatMemberLeft | ChatMemberBanned;
46
+ export declare function constructChatMember(participant: enums.ChannelParticipant | enums.ChatParticipant, getEntity: EntityGetter): Promise<ChatMember>;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructChatMember = void 0;
4
+ const _1_utilities_js_1 = require("../1_utilities.js");
5
+ const _2_tl_js_1 = require("../2_tl.js");
6
+ const _0_chat_administrator_rights_js_1 = require("./0_chat_administrator_rights.js");
7
+ const _0_chat_member_rights_js_1 = require("./0_chat_member_rights.js");
8
+ const _1_user_js_1 = require("./1_user.js");
9
+ async function constructChatMember(participant, getEntity) {
10
+ const user_ = "user_id" in participant ? await getEntity(new _2_tl_js_1.types.PeerUser(participant)) : "peer" in participant ? participant.peer instanceof _2_tl_js_1.types.PeerUser ? await getEntity(participant.peer) : (0, _1_utilities_js_1.UNREACHABLE)() : (0, _1_utilities_js_1.UNREACHABLE)(); // TODO: support other peer types
11
+ if (user_ == null)
12
+ (0, _1_utilities_js_1.UNREACHABLE)();
13
+ const user = (0, _1_user_js_1.constructUser)(user_);
14
+ if (participant instanceof _2_tl_js_1.types.ChannelParticipant || participant instanceof _2_tl_js_1.types.ChatParticipant) {
15
+ return {
16
+ status: "member",
17
+ user,
18
+ };
19
+ }
20
+ else if (participant instanceof _2_tl_js_1.types.ChannelParticipantCreator) {
21
+ return (0, _1_utilities_js_1.cleanObject)({
22
+ status: "creator",
23
+ user,
24
+ isAnonymous: participant.admin_rights.anonymous ? true : false,
25
+ title: participant.rank,
26
+ });
27
+ }
28
+ else if (participant instanceof _2_tl_js_1.types.ChannelParticipantAdmin) {
29
+ return (0, _1_utilities_js_1.cleanObject)({
30
+ status: "administrator",
31
+ user,
32
+ rights: (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(participant.admin_rights),
33
+ title: participant.rank,
34
+ });
35
+ }
36
+ else if (participant instanceof _2_tl_js_1.types.ChannelParticipantBanned) {
37
+ const untilDate = participant.banned_rights.until_date ? (0, _1_utilities_js_1.fromUnixTimestamp)(participant.banned_rights.until_date) : undefined;
38
+ if (!participant.banned_rights.view_messages) {
39
+ participant.peer;
40
+ return (0, _1_utilities_js_1.cleanObject)({
41
+ status: "banned",
42
+ user,
43
+ untilDate,
44
+ });
45
+ }
46
+ const isMember = participant.left ? true : false;
47
+ const rights = (0, _0_chat_member_rights_js_1.constructChatMemberRights)(participant.banned_rights);
48
+ return (0, _1_utilities_js_1.cleanObject)({
49
+ status: "restricted",
50
+ user,
51
+ isMember,
52
+ rights,
53
+ untilDate,
54
+ });
55
+ }
56
+ else if (participant instanceof _2_tl_js_1.types.ChannelParticipantSelf) {
57
+ (0, _1_utilities_js_1.UNREACHABLE)(); // TODO: implement
58
+ }
59
+ else if (participant instanceof _2_tl_js_1.types.ChannelParticipantLeft) {
60
+ return { status: "left", user };
61
+ }
62
+ else if (participant instanceof _2_tl_js_1.types.ChatParticipantAdmin) {
63
+ return (0, _1_utilities_js_1.cleanObject)({
64
+ status: "administrator",
65
+ user,
66
+ rights: {
67
+ isAnonymous: false,
68
+ canManageChat: true,
69
+ canDeleteMessages: true,
70
+ canManageVideoChats: false,
71
+ canRestrictMembers: true,
72
+ canPromoteMembers: false,
73
+ canChangeInfo: true,
74
+ canInviteUsers: true,
75
+ canPostMessages: false,
76
+ canEditMessages: false,
77
+ canPinMessages: true,
78
+ canManageTopics: false,
79
+ },
80
+ });
81
+ }
82
+ else if (participant instanceof _2_tl_js_1.types.ChatParticipantCreator) {
83
+ return (0, _1_utilities_js_1.cleanObject)({
84
+ status: "creator",
85
+ user,
86
+ isAnonymous: false,
87
+ });
88
+ }
89
+ else {
90
+ (0, _1_utilities_js_1.UNREACHABLE)();
91
+ }
92
+ }
93
+ exports.constructChatMember = constructChatMember;