@mtkruto/node 0.1.142 → 0.1.144

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/esm/3_types.d.ts +1 -0
  2. package/esm/3_types.js +1 -0
  3. package/esm/4_constants.d.ts +1 -1
  4. package/esm/4_constants.js +1 -1
  5. package/esm/client/0_message.js +9 -9
  6. package/esm/client/0_types.d.ts +1 -0
  7. package/esm/client/1_bot_info_manager.d.ts +30 -0
  8. package/esm/client/1_bot_info_manager.js +66 -0
  9. package/esm/client/1_file_manager.js +1 -1
  10. package/esm/client/1_network_statistics_manager.d.ts +19 -0
  11. package/esm/client/1_network_statistics_manager.js +48 -0
  12. package/esm/client/2_client_plain.js +4 -4
  13. package/esm/client/2_message_manager.d.ts +11 -2
  14. package/esm/client/2_message_manager.js +170 -1
  15. package/esm/client/3_callback_query_manager.js +1 -1
  16. package/esm/client/3_inline_query_manager.js +2 -1
  17. package/esm/client/4_client.d.ts +21 -12
  18. package/esm/client/4_client.js +134 -311
  19. package/esm/storage/0_storage.js +1 -1
  20. package/esm/tl/0_tl_raw_reader.js +3 -2
  21. package/esm/tl/0_tl_raw_writer.js +3 -3
  22. package/esm/transport/0_obfuscation.js +2 -2
  23. package/esm/transport/1_transport_abridged.js +1 -1
  24. package/esm/transport/1_transport_intermediate.js +1 -1
  25. package/esm/types/0__file_id.js +2 -2
  26. package/esm/types/0_chat_member_rights.d.ts +3 -0
  27. package/esm/types/0_chat_member_rights.js +45 -1
  28. package/esm/types/2_chat_member.d.ts +46 -0
  29. package/esm/types/2_chat_member.js +89 -0
  30. package/package.json +1 -1
  31. package/script/3_types.d.ts +1 -0
  32. package/script/3_types.js +1 -0
  33. package/script/4_constants.d.ts +1 -1
  34. package/script/4_constants.js +1 -1
  35. package/script/client/0_message.js +9 -9
  36. package/script/client/0_types.d.ts +1 -0
  37. package/script/client/1_bot_info_manager.d.ts +30 -0
  38. package/script/client/1_bot_info_manager.js +70 -0
  39. package/script/client/1_file_manager.js +1 -1
  40. package/script/client/1_network_statistics_manager.d.ts +19 -0
  41. package/script/client/1_network_statistics_manager.js +52 -0
  42. package/script/client/2_client_plain.js +4 -4
  43. package/script/client/2_message_manager.d.ts +11 -2
  44. package/script/client/2_message_manager.js +169 -0
  45. package/script/client/3_callback_query_manager.js +1 -1
  46. package/script/client/3_inline_query_manager.js +2 -1
  47. package/script/client/4_client.d.ts +21 -12
  48. package/script/client/4_client.js +131 -308
  49. package/script/storage/0_storage.js +1 -1
  50. package/script/tl/0_tl_raw_reader.js +3 -2
  51. package/script/tl/0_tl_raw_writer.js +3 -3
  52. package/script/transport/0_obfuscation.js +2 -2
  53. package/script/transport/1_transport_abridged.js +1 -1
  54. package/script/transport/1_transport_intermediate.js +1 -1
  55. package/script/types/0__file_id.js +2 -2
  56. package/script/types/0_chat_member_rights.d.ts +3 -0
  57. package/script/types/0_chat_member_rights.js +48 -0
  58. package/script/types/2_chat_member.d.ts +46 -0
  59. package/script/types/2_chat_member.js +93 -0
@@ -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.142",
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.142";
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.142";
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);
@@ -34,6 +34,7 @@ export interface C {
34
34
  parseMode: ParseMode;
35
35
  apiFactory: ApiFactory;
36
36
  ignoreOutgoing: boolean | null;
37
+ cdn: boolean;
37
38
  }
38
39
  export declare class ConnectionError extends Error {
39
40
  }
@@ -0,0 +1,30 @@
1
+ import { BotCommand } from "../3_types.js";
2
+ import { GetMyCommandsParams, SetMyCommandsParams } from "./0_params.js";
3
+ import { C } from "./0_types.js";
4
+ export declare class BotInfoManager {
5
+ #private;
6
+ constructor(c: C);
7
+ setMyDescription(params?: {
8
+ description?: string;
9
+ languageCode?: string;
10
+ }): Promise<void>;
11
+ setMyName(params?: {
12
+ name?: string;
13
+ languageCode?: string;
14
+ }): Promise<void>;
15
+ setMyShortDescription(params?: {
16
+ shortDescription?: string;
17
+ languageCode?: string;
18
+ }): Promise<void>;
19
+ getMyDescription(params?: {
20
+ languageCode?: string;
21
+ }): Promise<string>;
22
+ getMyName(params?: {
23
+ languageCode?: string;
24
+ }): Promise<string>;
25
+ getMyShortDescription(params?: {
26
+ languageCode?: string;
27
+ }): Promise<string>;
28
+ getMyCommands(params?: GetMyCommandsParams): Promise<BotCommand[]>;
29
+ setMyCommands(commands: BotCommand[], params?: SetMyCommandsParams): Promise<void>;
30
+ }
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _BotInfoManager_instances, _BotInfoManager_c, _BotInfoManager_setMyInfo, _BotInfoManager_getMyInfo;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.BotInfoManager = void 0;
16
+ const _2_tl_js_1 = require("../2_tl.js");
17
+ const _3_types_js_1 = require("../3_types.js");
18
+ class BotInfoManager {
19
+ constructor(c) {
20
+ _BotInfoManager_instances.add(this);
21
+ _BotInfoManager_c.set(this, void 0);
22
+ __classPrivateFieldSet(this, _BotInfoManager_c, c, "f");
23
+ }
24
+ async setMyDescription(params) {
25
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyDescription");
26
+ await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_setMyInfo).call(this, { description: params?.description, lang_code: params?.languageCode ?? "" });
27
+ }
28
+ async setMyName(params) {
29
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyName");
30
+ await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_setMyInfo).call(this, { name: params?.name, lang_code: params?.languageCode ?? "" });
31
+ }
32
+ async setMyShortDescription(params) {
33
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyShortDescription");
34
+ await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_setMyInfo).call(this, { about: params?.shortDescription, lang_code: params?.languageCode ?? "" });
35
+ }
36
+ async getMyDescription(params) {
37
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyDescription");
38
+ return await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
39
+ }
40
+ async getMyName(params) {
41
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyName");
42
+ return await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_getMyInfo).call(this, params?.languageCode).then((v) => v.description);
43
+ }
44
+ async getMyShortDescription(params) {
45
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyShortDescription");
46
+ return await __classPrivateFieldGet(this, _BotInfoManager_instances, "m", _BotInfoManager_getMyInfo).call(this, params?.languageCode).then((v) => v.about);
47
+ }
48
+ async getMyCommands(params) {
49
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("getMyCommands");
50
+ const commands_ = await __classPrivateFieldGet(this, _BotInfoManager_c, "f").api.bots.getBotCommands({
51
+ lang_code: params?.languageCode ?? "",
52
+ scope: await (0, _3_types_js_1.botCommandScopeToTlObject)(params?.scope ?? { type: "default" }, __classPrivateFieldGet(this, _BotInfoManager_c, "f").getInputPeer),
53
+ });
54
+ return commands_.map((v) => ({ command: v.command, description: v.description }));
55
+ }
56
+ async setMyCommands(commands, params) {
57
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").storage.assertBot("setMyCommands");
58
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").api.bots.setBotCommands({
59
+ commands: commands.map((v) => new _2_tl_js_1.types.BotCommand(v)),
60
+ lang_code: params?.languageCode ?? "",
61
+ scope: await (0, _3_types_js_1.botCommandScopeToTlObject)(params?.scope ?? { type: "default" }, __classPrivateFieldGet(this, _BotInfoManager_c, "f").getInputPeer),
62
+ });
63
+ }
64
+ }
65
+ exports.BotInfoManager = BotInfoManager;
66
+ _BotInfoManager_c = new WeakMap(), _BotInfoManager_instances = new WeakSet(), _BotInfoManager_setMyInfo = async function _BotInfoManager_setMyInfo(info) {
67
+ await __classPrivateFieldGet(this, _BotInfoManager_c, "f").api.bots.setBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), ...info });
68
+ }, _BotInfoManager_getMyInfo = function _BotInfoManager_getMyInfo(languageCode) {
69
+ return __classPrivateFieldGet(this, _BotInfoManager_c, "f").api.bots.getBotInfo({ bot: new _2_tl_js_1.types.InputUserSelf(), lang_code: languageCode ?? "" });
70
+ };
@@ -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
  }
@@ -0,0 +1,19 @@
1
+ import { C } from "./0_types.js";
2
+ export declare class NetworkStatisticsManager {
3
+ #private;
4
+ constructor(c: C);
5
+ getNetworkStatistics(): Promise<{
6
+ messages: {
7
+ sent: number;
8
+ received: number;
9
+ };
10
+ cdn: {
11
+ sent: number;
12
+ received: number;
13
+ };
14
+ }>;
15
+ getTransportReadWriteCallback(): {
16
+ read: (count: number) => Promise<void>;
17
+ write: (count: number) => Promise<void>;
18
+ };
19
+ }
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
3
+ if (kind === "m") throw new TypeError("Private method is not writable");
4
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
5
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
6
+ return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
7
+ };
8
+ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
9
+ if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
10
+ if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
11
+ return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
12
+ };
13
+ var _NetworkStatisticsManager_c;
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.NetworkStatisticsManager = void 0;
16
+ class NetworkStatisticsManager {
17
+ constructor(c) {
18
+ _NetworkStatisticsManager_c.set(this, void 0);
19
+ __classPrivateFieldSet(this, _NetworkStatisticsManager_c, c, "f");
20
+ }
21
+ async getNetworkStatistics() {
22
+ const [messagesRead, messagesWrite, cdnRead, cdnWrite] = await Promise.all([
23
+ __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_messages_read"]),
24
+ __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_messages_write"]),
25
+ __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_cdn_read"]),
26
+ __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.get(["netstat_cdn_write"]),
27
+ ]);
28
+ const messages = {
29
+ sent: Number(messagesWrite || 0),
30
+ received: Number(messagesRead || 0),
31
+ };
32
+ const cdn = {
33
+ sent: Number(cdnWrite || 0),
34
+ received: Number(cdnRead || 0),
35
+ };
36
+ return { messages, cdn };
37
+ }
38
+ getTransportReadWriteCallback() {
39
+ return {
40
+ read: async (count) => {
41
+ const key = __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").cdn ? "netstat_cdn_read" : "netstat_messages_read";
42
+ await __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.incr([key], count);
43
+ },
44
+ write: async (count) => {
45
+ const key = __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").cdn ? "netstat_cdn_write" : "netstat_messages_write";
46
+ await __classPrivateFieldGet(this, _NetworkStatisticsManager_c, "f").storage.incr([key], count);
47
+ },
48
+ };
49
+ }
50
+ }
51
+ exports.NetworkStatisticsManager = NetworkStatisticsManager;
52
+ _NetworkStatisticsManager_c = new WeakMap();
@@ -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,6 +1,6 @@
1
1
  import { enums, types } from "../2_tl.js";
2
- import { FileSource, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
3
- import { DeleteMessagesParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetHistoryParams, PinMessageParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams } from "./0_params.js";
2
+ import { ChatAction, ChatMember, FileSource, 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
4
  import { AddReactionParams, SetReactionsParams } from "./0_params.js";
5
5
  import { C as C_ } from "./0_types.js";
6
6
  import { FileManager } from "./1_file_manager.js";
@@ -48,5 +48,14 @@ export declare class MessageManager {
48
48
  removeReaction(chatId: number, messageId: number, reaction: Reaction): Promise<void>;
49
49
  static canHandleUpdate(update: enums.Update): update is types.UpdateNewMessage | types.UpdateNewChannelMessage | types.UpdateEditMessage | types.UpdateEditChannelMessage | types.UpdateDeleteMessages | types.UpdateDeleteChannelMessages;
50
50
  handleUpdate(update: types.UpdateNewMessage | types.UpdateNewChannelMessage | types.UpdateEditMessage | types.UpdateEditChannelMessage | types.UpdateDeleteMessages | types.UpdateDeleteChannelMessages): Promise<Update | null>;
51
+ sendChatAction(chatId: ID, action: ChatAction, params?: {
52
+ messageThreadId?: number;
53
+ }): Promise<void>;
54
+ deleteChatPhoto(chatId: number): Promise<void>;
55
+ setChatPhoto(chatId: number, photo: FileSource, params?: SetChatPhotoParams): Promise<void>;
56
+ banChatMember(chatId: ID, memberId: ID, params?: BanChatMemberParams): Promise<void>;
57
+ unbanChatMember(chatId: ID, memberId: ID): Promise<void>;
58
+ setChatMemberRights(chatId: ID, memberId: ID, params?: SetChatMemberRightsParams): Promise<void>;
59
+ getChatAdministrators(chatId: ID): Promise<ChatMember[]>;
51
60
  }
52
61
  export {};