@mtkruto/node 0.1.500 → 0.1.600
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.
- package/esm/3_types.d.ts +6 -1
- package/esm/3_types.js +6 -1
- package/esm/client/0_params.d.ts +28 -6
- package/esm/client/1_file_manager.d.ts +5 -1
- package/esm/client/1_file_manager.js +50 -49
- package/esm/client/2_video_chat_manager.d.ts +43 -0
- package/esm/client/2_video_chat_manager.js +194 -0
- package/esm/client/3_callback_query_manager.js +1 -0
- package/esm/client/3_chat_list_manager.d.ts +3 -3
- package/esm/client/3_chat_list_manager.js +75 -98
- package/esm/client/3_inline_query_manager.js +1 -0
- package/esm/client/4_client.d.ts +67 -3
- package/esm/client/4_client.js +92 -3
- package/esm/storage/0_storage.d.ts +14 -0
- package/esm/storage/0_storage.js +39 -2
- package/esm/tl/3_utilities.d.ts +1 -1
- package/esm/tl/3_utilities.js +3 -3
- package/esm/types/0_birthday.d.ts +27 -0
- package/esm/types/0_birthday.js +26 -0
- package/esm/types/0_giveaway_parameters.d.ts +1 -1
- package/esm/types/0_live_stream_channel.d.ts +30 -0
- package/esm/types/0_live_stream_channel.js +26 -0
- package/esm/types/0_opening_hours.d.ts +25 -0
- package/esm/types/0_opening_hours.js +25 -0
- package/esm/types/0_video_chat.d.ts +60 -0
- package/esm/types/0_video_chat.js +53 -0
- package/esm/types/1_chat_p.d.ts +4 -0
- package/esm/types/1_chat_p.js +1 -0
- package/esm/types/2_business_connection.d.ts +6 -0
- package/esm/types/2_chat.d.ts +62 -0
- package/esm/types/2_chat.js +66 -0
- package/esm/types/2_inactive_chat.d.ts +1 -1
- package/esm/types/2_invite_link.d.ts +1 -1
- package/esm/types/2_message_reaction_count.d.ts +1 -1
- package/esm/types/2_message_reactions.d.ts +1 -1
- package/esm/types/3_chat_member_updated.d.ts +1 -1
- package/esm/types/4_message.d.ts +3 -3
- package/esm/types/5_chat_list_item.d.ts +35 -0
- package/esm/types/5_chat_list_item.js +86 -0
- package/esm/types/6_update.d.ts +14 -5
- package/esm/types/_file_id.d.ts +1 -0
- package/esm/utilities/0_bigint.d.ts +1 -0
- package/esm/utilities/0_bigint.js +7 -3
- package/package.json +1 -1
- package/script/3_types.d.ts +6 -1
- package/script/3_types.js +6 -1
- package/script/client/0_params.d.ts +28 -6
- package/script/client/1_file_manager.d.ts +5 -1
- package/script/client/1_file_manager.js +50 -49
- package/script/client/2_video_chat_manager.d.ts +43 -0
- package/script/client/2_video_chat_manager.js +198 -0
- package/script/client/3_callback_query_manager.js +1 -0
- package/script/client/3_chat_list_manager.d.ts +3 -3
- package/script/client/3_chat_list_manager.js +72 -95
- package/script/client/3_inline_query_manager.js +1 -0
- package/script/client/4_client.d.ts +67 -3
- package/script/client/4_client.js +92 -3
- package/script/storage/0_storage.d.ts +14 -0
- package/script/storage/0_storage.js +39 -2
- package/script/tl/3_utilities.d.ts +1 -1
- package/script/tl/3_utilities.js +3 -3
- package/script/types/0_birthday.d.ts +27 -0
- package/script/types/0_birthday.js +30 -0
- package/script/types/0_giveaway_parameters.d.ts +1 -1
- package/script/types/0_live_stream_channel.d.ts +30 -0
- package/script/types/0_live_stream_channel.js +30 -0
- package/script/types/0_opening_hours.d.ts +25 -0
- package/script/types/0_opening_hours.js +29 -0
- package/script/types/0_video_chat.d.ts +60 -0
- package/script/types/0_video_chat.js +57 -0
- package/script/types/1_chat_p.d.ts +4 -0
- package/script/types/1_chat_p.js +1 -0
- package/script/types/2_business_connection.d.ts +6 -0
- package/script/types/2_chat.d.ts +62 -0
- package/script/types/2_chat.js +70 -0
- package/script/types/2_inactive_chat.d.ts +1 -1
- package/script/types/2_invite_link.d.ts +1 -1
- package/script/types/2_message_reaction_count.d.ts +1 -1
- package/script/types/2_message_reactions.d.ts +1 -1
- package/script/types/3_chat_member_updated.d.ts +1 -1
- package/script/types/4_message.d.ts +3 -3
- package/script/types/5_chat_list_item.d.ts +35 -0
- package/script/types/5_chat_list_item.js +94 -0
- package/script/types/6_update.d.ts +14 -5
- package/script/types/_file_id.d.ts +1 -0
- package/script/utilities/0_bigint.d.ts +1 -0
- package/script/utilities/0_bigint.js +7 -3
- package/esm/types/5_chat.d.ts +0 -59
- package/esm/types/5_chat.js +0 -126
- package/script/types/5_chat.d.ts +0 -59
- package/script/types/5_chat.js +0 -134
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2024 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { enums, types } from "../2_tl.js";
|
|
21
|
+
import { EntityGetter } from "./_getters.js";
|
|
22
|
+
import { ChatP } from "./1_chat_p.js";
|
|
23
|
+
import { StickerSetNameGetter } from "./1_sticker.js";
|
|
24
|
+
import { Message, MessageGetter } from "./4_message.js";
|
|
25
|
+
export interface ChatListItem {
|
|
26
|
+
chat: ChatP;
|
|
27
|
+
order: string;
|
|
28
|
+
pinned: number;
|
|
29
|
+
lastMessage?: Omit<Message, "replyToMessage">;
|
|
30
|
+
}
|
|
31
|
+
export declare function getChatListItemOrder(lastMessage: Omit<Message, "replyToMessage"> | undefined, pinned: number): string;
|
|
32
|
+
export declare function constructChatListItem(chatId: number, pinned: number, lastMessageId: number, getEntity: EntityGetter, getMessage: MessageGetter): Promise<ChatListItem | null>;
|
|
33
|
+
export declare function constructChatListItem2(entity: types.User | types.Chat | types.ChatForbidden | types.Channel | types.ChannelForbidden, pinned: number, lastMessage: Omit<Message, "replyToMessage"> | undefined): ChatListItem;
|
|
34
|
+
export declare function constructChatListItem3(chatId: number, pinned: number, lastMessage: Omit<Message, "replyToMessage"> | undefined, getEntity: EntityGetter): Promise<ChatListItem | null>;
|
|
35
|
+
export declare function constructChatListItem4(dialog: enums.Dialog, dialogs: types.messages.Dialogs | types.messages.DialogsSlice, pinnedChats: number[], getEntity: EntityGetter, getMessage: MessageGetter, getStickerSetName: StickerSetNameGetter): Promise<ChatListItem>;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2024 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { unreachable } from "../0_deps.js";
|
|
21
|
+
import { chatIdToPeer, peerToChatId, types } from "../2_tl.js";
|
|
22
|
+
import { constructChatP } from "./1_chat_p.js";
|
|
23
|
+
import { constructMessage } from "./4_message.js";
|
|
24
|
+
export function getChatListItemOrder(lastMessage, pinned) {
|
|
25
|
+
const p = pinned == -1 ? "" : `P${100 - pinned}`;
|
|
26
|
+
if (!lastMessage) {
|
|
27
|
+
return p + "0";
|
|
28
|
+
}
|
|
29
|
+
return p + String((BigInt(Math.floor(lastMessage.date.getTime())) << 32n) + BigInt(lastMessage.id));
|
|
30
|
+
}
|
|
31
|
+
export async function constructChatListItem(chatId, pinned, lastMessageId, getEntity, getMessage) {
|
|
32
|
+
const entity = await getEntity(chatIdToPeer(chatId));
|
|
33
|
+
if (entity == null) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
const lastMessage_ = lastMessageId > 0 ? await getMessage(chatId, lastMessageId) : null;
|
|
37
|
+
const lastMessage = lastMessage_ == null ? undefined : lastMessage_;
|
|
38
|
+
return {
|
|
39
|
+
chat: constructChatP(entity),
|
|
40
|
+
order: getChatListItemOrder(lastMessage, pinned),
|
|
41
|
+
pinned,
|
|
42
|
+
lastMessage,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export function constructChatListItem2(entity, pinned, lastMessage) {
|
|
46
|
+
return {
|
|
47
|
+
chat: constructChatP(entity),
|
|
48
|
+
order: getChatListItemOrder(lastMessage, pinned),
|
|
49
|
+
pinned,
|
|
50
|
+
lastMessage,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export async function constructChatListItem3(chatId, pinned, lastMessage, getEntity) {
|
|
54
|
+
const entity = await getEntity(chatIdToPeer(chatId));
|
|
55
|
+
if (entity == null) {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
chat: constructChatP(entity),
|
|
60
|
+
order: getChatListItemOrder(lastMessage, pinned),
|
|
61
|
+
pinned,
|
|
62
|
+
lastMessage,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
export async function constructChatListItem4(dialog, dialogs, pinnedChats, getEntity, getMessage, getStickerSetName) {
|
|
66
|
+
const topMessage_ = dialogs.messages.find((v) => "id" in v && v.id == dialog.top_message);
|
|
67
|
+
if (!topMessage_) {
|
|
68
|
+
unreachable();
|
|
69
|
+
}
|
|
70
|
+
const pinned = pinnedChats.indexOf(peerToChatId(dialog.peer));
|
|
71
|
+
const lastMessage = await constructMessage(topMessage_, getEntity, getMessage, getStickerSetName, false);
|
|
72
|
+
const order = getChatListItemOrder(lastMessage, pinned);
|
|
73
|
+
const userId = "user_id" in dialog.peer ? dialog.peer.user_id : null;
|
|
74
|
+
const chatId = "chat_id" in dialog.peer ? dialog.peer.chat_id : null;
|
|
75
|
+
const channelId = "channel_id" in dialog.peer ? dialog.peer.channel_id : null;
|
|
76
|
+
const chat__ = chatId != null ? dialogs.chats.find((v) => v instanceof types.Chat && v.id == chatId) : channelId != null ? dialogs.chats.find((v) => v instanceof types.Channel && v.id == channelId) : userId != null ? dialogs.users.find((v) => v instanceof types.User && v.id == userId) : unreachable();
|
|
77
|
+
if (!chat__) {
|
|
78
|
+
unreachable();
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
chat: constructChatP(chat__),
|
|
82
|
+
order,
|
|
83
|
+
lastMessage,
|
|
84
|
+
pinned,
|
|
85
|
+
};
|
|
86
|
+
}
|
package/esm/types/6_update.d.ts
CHANGED
|
@@ -31,7 +31,8 @@ import { ChatMemberUpdated } from "./3_chat_member_updated.js";
|
|
|
31
31
|
import { Story } from "./3_story.js";
|
|
32
32
|
import { Message } from "./4_message.js";
|
|
33
33
|
import { CallbackQuery } from "./5_callback_query.js";
|
|
34
|
-
import {
|
|
34
|
+
import { ChatListItem } from "./5_chat_list_item.js";
|
|
35
|
+
import { VideoChat } from "./0_video_chat.js";
|
|
35
36
|
/**
|
|
36
37
|
* A client's connection state was changed.
|
|
37
38
|
*
|
|
@@ -165,14 +166,14 @@ export interface UpdateChosenInlineResult {
|
|
|
165
166
|
*/
|
|
166
167
|
export interface UpdateNewChat {
|
|
167
168
|
/** The newly added chat. */
|
|
168
|
-
newChat:
|
|
169
|
+
newChat: ChatListItem;
|
|
169
170
|
}
|
|
170
171
|
/**
|
|
171
172
|
* A chat in the chat list was edited. User-only.
|
|
172
173
|
* @unlisted
|
|
173
174
|
*/
|
|
174
175
|
export interface UpdateEditedChat {
|
|
175
|
-
editedChat:
|
|
176
|
+
editedChat: ChatListItem;
|
|
176
177
|
}
|
|
177
178
|
/**
|
|
178
179
|
* A chat was removed from the chat list. User-only.
|
|
@@ -242,6 +243,13 @@ export interface UpdateNewStory {
|
|
|
242
243
|
export interface UpdateBusinessConnection {
|
|
243
244
|
businessConnection: BusinessConnection;
|
|
244
245
|
}
|
|
246
|
+
/**
|
|
247
|
+
* A video chat was started, scheduled, or ended.
|
|
248
|
+
* @unlisted
|
|
249
|
+
*/
|
|
250
|
+
export interface UpdateVideoChat {
|
|
251
|
+
videoChat: VideoChat;
|
|
252
|
+
}
|
|
245
253
|
/** @unlisted */
|
|
246
254
|
export interface UpdateMap {
|
|
247
255
|
message: UpdateNewMessage;
|
|
@@ -263,8 +271,9 @@ export interface UpdateMap {
|
|
|
263
271
|
deletedStory: UpdateDeletedStory;
|
|
264
272
|
story: UpdateNewStory;
|
|
265
273
|
businessConnection: UpdateBusinessConnection;
|
|
274
|
+
videoChat: UpdateVideoChat;
|
|
266
275
|
}
|
|
267
276
|
/** @unlisted */
|
|
268
|
-
export type UpdateIntersection<T> = T & Partial<UpdateConnectionState & UpdateAuthorizationState & UpdateNewMessage & UpdateEditedMessage & UpdateDeletedMessages & UpdateCallbackQuery & UpdateInlineQuery & UpdateChosenInlineResult & UpdateNewChat & UpdateEditedChat & UpdateDeletedChat & UpdateMessageInteractions & UpdateMessageReactionCount & UpdateMessageReactions & UpdateChatMember & UpdateMyChatMember & UpdateDeletedStory & UpdateNewStory & UpdateBusinessConnection>;
|
|
277
|
+
export type UpdateIntersection<T> = T & Partial<UpdateConnectionState & UpdateAuthorizationState & UpdateNewMessage & UpdateEditedMessage & UpdateDeletedMessages & UpdateCallbackQuery & UpdateInlineQuery & UpdateChosenInlineResult & UpdateNewChat & UpdateEditedChat & UpdateDeletedChat & UpdateMessageInteractions & UpdateMessageReactionCount & UpdateMessageReactions & UpdateChatMember & UpdateMyChatMember & UpdateDeletedStory & UpdateNewStory & UpdateBusinessConnection & UpdateVideoChat>;
|
|
269
278
|
/** An incoming update. */
|
|
270
|
-
export type Update = UpdateConnectionState | UpdateAuthorizationState | UpdateNewMessage | UpdateEditedMessage | UpdateDeletedMessages | UpdateCallbackQuery | UpdateInlineQuery | UpdateChosenInlineResult | UpdateNewChat | UpdateEditedChat | UpdateDeletedChat | UpdateMessageInteractions | UpdateMessageReactionCount | UpdateMessageReactions | UpdateChatMember | UpdateMyChatMember | UpdateDeletedStory | UpdateNewStory | UpdateBusinessConnection;
|
|
279
|
+
export type Update = UpdateConnectionState | UpdateAuthorizationState | UpdateNewMessage | UpdateEditedMessage | UpdateDeletedMessages | UpdateCallbackQuery | UpdateInlineQuery | UpdateChosenInlineResult | UpdateNewChat | UpdateEditedChat | UpdateDeletedChat | UpdateMessageInteractions | UpdateMessageReactionCount | UpdateMessageReactions | UpdateChatMember | UpdateMyChatMember | UpdateDeletedStory | UpdateNewStory | UpdateBusinessConnection | UpdateVideoChat;
|
package/esm/types/_file_id.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export declare function mod(n: number, m: number): number;
|
|
|
4
4
|
export declare function bigIntFromBuffer(buffer: Uint8Array, little?: boolean, signed?: boolean): bigint;
|
|
5
5
|
export declare function getRandomBigInt(byteLength: number, little?: boolean, signed?: boolean): bigint;
|
|
6
6
|
/** Get a random ID. Useful when calling API functions directly. */
|
|
7
|
+
export declare function getRandomId(number: true): number;
|
|
7
8
|
export declare function getRandomId(): bigint;
|
|
8
9
|
export declare function gcd(a: bigint, b: bigint): bigint;
|
|
@@ -56,9 +56,13 @@ export function getRandomBigInt(byteLength, little, signed) {
|
|
|
56
56
|
dntShim.crypto.getRandomValues(randomBytes);
|
|
57
57
|
return bigIntFromBuffer(randomBytes, little, signed);
|
|
58
58
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
59
|
+
export function getRandomId(number) {
|
|
60
|
+
if (number) {
|
|
61
|
+
return Number(getRandomBigInt(4, true, true));
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
return getRandomBigInt(8, true, true);
|
|
65
|
+
}
|
|
62
66
|
}
|
|
63
67
|
export function gcd(a, b) {
|
|
64
68
|
if (a == 0n) {
|
package/package.json
CHANGED
package/script/3_types.d.ts
CHANGED
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
export * from "./types/_file_id.js";
|
|
21
21
|
export * from "./types/_getters.js";
|
|
22
22
|
export * from "./types/0_authorization_state.js";
|
|
23
|
+
export * from "./types/0_birthday.js";
|
|
23
24
|
export * from "./types/0_bot_command.js";
|
|
24
25
|
export * from "./types/0_callback_query_answer.js";
|
|
25
26
|
export * from "./types/0_callback_query_question.js";
|
|
@@ -35,6 +36,7 @@ export * from "./types/0_giveaway_parameters.js";
|
|
|
35
36
|
export * from "./types/0_id.js";
|
|
36
37
|
export * from "./types/0_keyboard_button_poll_type.js";
|
|
37
38
|
export * from "./types/0_link_preview.js";
|
|
39
|
+
export * from "./types/0_live_stream_channel.js";
|
|
38
40
|
export * from "./types/0_location.js";
|
|
39
41
|
export * from "./types/0_login_url.js";
|
|
40
42
|
export * from "./types/0_mask_position.js";
|
|
@@ -43,6 +45,7 @@ export * from "./types/0_message_reference.js";
|
|
|
43
45
|
export * from "./types/0_message_search_filter.js";
|
|
44
46
|
export * from "./types/0_mini_app_info.js";
|
|
45
47
|
export * from "./types/0_network_statistics_entry.js";
|
|
48
|
+
export * from "./types/0_opening_hours.js";
|
|
46
49
|
export * from "./types/0_parse_mode.js";
|
|
47
50
|
export * from "./types/0_poll_option.js";
|
|
48
51
|
export * from "./types/0_price_tag.js";
|
|
@@ -51,6 +54,7 @@ export * from "./types/0_restriction_reason.js";
|
|
|
51
54
|
export * from "./types/0_self_destruct_option.js";
|
|
52
55
|
export * from "./types/0_story_reference.js";
|
|
53
56
|
export * from "./types/0_thumbnail.js";
|
|
57
|
+
export * from "./types/0_video_chat.js";
|
|
54
58
|
export * from "./types/0_voice.js";
|
|
55
59
|
export * from "./types/1_animation.js";
|
|
56
60
|
export * from "./types/1_audio.js";
|
|
@@ -96,6 +100,7 @@ export * from "./types/3_story.js";
|
|
|
96
100
|
export * from "./types/4_inline_query_result.js";
|
|
97
101
|
export * from "./types/4_message.js";
|
|
98
102
|
export * from "./types/5_callback_query.js";
|
|
99
|
-
export * from "./types/
|
|
103
|
+
export * from "./types/5_chat_list_item.js";
|
|
104
|
+
export * from "./types/2_chat.js";
|
|
100
105
|
export * from "./types/5_inline_query_answer.js";
|
|
101
106
|
export * from "./types/6_update.js";
|
package/script/3_types.js
CHANGED
|
@@ -36,6 +36,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
36
36
|
__exportStar(require("./types/_file_id.js"), exports);
|
|
37
37
|
__exportStar(require("./types/_getters.js"), exports);
|
|
38
38
|
__exportStar(require("./types/0_authorization_state.js"), exports);
|
|
39
|
+
__exportStar(require("./types/0_birthday.js"), exports);
|
|
39
40
|
__exportStar(require("./types/0_bot_command.js"), exports);
|
|
40
41
|
__exportStar(require("./types/0_callback_query_answer.js"), exports);
|
|
41
42
|
__exportStar(require("./types/0_callback_query_question.js"), exports);
|
|
@@ -51,6 +52,7 @@ __exportStar(require("./types/0_giveaway_parameters.js"), exports);
|
|
|
51
52
|
__exportStar(require("./types/0_id.js"), exports);
|
|
52
53
|
__exportStar(require("./types/0_keyboard_button_poll_type.js"), exports);
|
|
53
54
|
__exportStar(require("./types/0_link_preview.js"), exports);
|
|
55
|
+
__exportStar(require("./types/0_live_stream_channel.js"), exports);
|
|
54
56
|
__exportStar(require("./types/0_location.js"), exports);
|
|
55
57
|
__exportStar(require("./types/0_login_url.js"), exports);
|
|
56
58
|
__exportStar(require("./types/0_mask_position.js"), exports);
|
|
@@ -59,6 +61,7 @@ __exportStar(require("./types/0_message_reference.js"), exports);
|
|
|
59
61
|
__exportStar(require("./types/0_message_search_filter.js"), exports);
|
|
60
62
|
__exportStar(require("./types/0_mini_app_info.js"), exports);
|
|
61
63
|
__exportStar(require("./types/0_network_statistics_entry.js"), exports);
|
|
64
|
+
__exportStar(require("./types/0_opening_hours.js"), exports);
|
|
62
65
|
__exportStar(require("./types/0_parse_mode.js"), exports);
|
|
63
66
|
__exportStar(require("./types/0_poll_option.js"), exports);
|
|
64
67
|
__exportStar(require("./types/0_price_tag.js"), exports);
|
|
@@ -67,6 +70,7 @@ __exportStar(require("./types/0_restriction_reason.js"), exports);
|
|
|
67
70
|
__exportStar(require("./types/0_self_destruct_option.js"), exports);
|
|
68
71
|
__exportStar(require("./types/0_story_reference.js"), exports);
|
|
69
72
|
__exportStar(require("./types/0_thumbnail.js"), exports);
|
|
73
|
+
__exportStar(require("./types/0_video_chat.js"), exports);
|
|
70
74
|
__exportStar(require("./types/0_voice.js"), exports);
|
|
71
75
|
__exportStar(require("./types/1_animation.js"), exports);
|
|
72
76
|
__exportStar(require("./types/1_audio.js"), exports);
|
|
@@ -112,6 +116,7 @@ __exportStar(require("./types/3_story.js"), exports);
|
|
|
112
116
|
__exportStar(require("./types/4_inline_query_result.js"), exports);
|
|
113
117
|
__exportStar(require("./types/4_message.js"), exports);
|
|
114
118
|
__exportStar(require("./types/5_callback_query.js"), exports);
|
|
115
|
-
__exportStar(require("./types/
|
|
119
|
+
__exportStar(require("./types/5_chat_list_item.js"), exports);
|
|
120
|
+
__exportStar(require("./types/2_chat.js"), exports);
|
|
116
121
|
__exportStar(require("./types/5_inline_query_answer.js"), exports);
|
|
117
122
|
__exportStar(require("./types/6_update.js"), exports);
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
19
|
*/
|
|
20
20
|
import { MaybePromise } from "../1_utilities.js";
|
|
21
|
-
import { BotCommandScope,
|
|
21
|
+
import { BotCommandScope, ChatListItem, ChatMemberRights, FileSource, ID, InlineQueryResultButton, LinkPreview, Message, MessageEntity, MessageSearchFilter, ParseMode, ReplyMarkup, ReplyQuote, SelfDestructOption, StoryInteractiveArea, StoryPrivacy } from "../3_types.js";
|
|
22
22
|
export interface AnswerCallbackQueryParams {
|
|
23
23
|
/** A text to be shown to the user. */
|
|
24
24
|
text?: string;
|
|
@@ -48,7 +48,7 @@ export interface _SendCommon extends _BusinessConnectionIdCommon {
|
|
|
48
48
|
replyQuote?: ReplyQuote;
|
|
49
49
|
/** The identifier of a thread to send the message to. */
|
|
50
50
|
messageThreadId?: number;
|
|
51
|
-
/** The identifier of
|
|
51
|
+
/** The identifier of a chat to send the message on behalf of. User-only. */
|
|
52
52
|
sendAs?: ID;
|
|
53
53
|
/** The reply markup of the message. Bot-only. */
|
|
54
54
|
replyMarkup?: ReplyMarkup;
|
|
@@ -276,7 +276,7 @@ export interface GetChatsParams {
|
|
|
276
276
|
/** The chat list to get the chats from. Defaults to main. */
|
|
277
277
|
from?: "main" | "archived";
|
|
278
278
|
/** The last chat to get chats after. */
|
|
279
|
-
after?:
|
|
279
|
+
after?: ChatListItem;
|
|
280
280
|
/** The maximum number of results to return. Must be in the range of 1-100. Defaults to 100. */
|
|
281
281
|
limit?: number;
|
|
282
282
|
}
|
|
@@ -287,7 +287,7 @@ export interface PinMessageParams {
|
|
|
287
287
|
disableNotification?: boolean;
|
|
288
288
|
}
|
|
289
289
|
export interface BanChatMemberParams {
|
|
290
|
-
/** A point
|
|
290
|
+
/** A point in time within the future in which the ban will be reverted. */
|
|
291
291
|
untilDate?: Date;
|
|
292
292
|
/** Whether to delete all of the user's messages. */
|
|
293
293
|
deleteMessages?: boolean;
|
|
@@ -295,7 +295,7 @@ export interface BanChatMemberParams {
|
|
|
295
295
|
export interface SetChatMemberRightsParams {
|
|
296
296
|
/** The member's new rights. All fields default to `true` if the chat's default member rights allow. This means that this method is the same as unbanChatMember if this parameter is not provided or all of its fields are `true`. */
|
|
297
297
|
rights?: ChatMemberRights;
|
|
298
|
-
/** A point
|
|
298
|
+
/** A point in time within the future in which the restriction will be reverted. */
|
|
299
299
|
untilDate?: Date;
|
|
300
300
|
}
|
|
301
301
|
export interface CreateStoryParams extends _CaptionCommon, _UploadCommon {
|
|
@@ -325,7 +325,7 @@ export interface SearchMessagesParams {
|
|
|
325
325
|
export interface CreateInviteLinkParams {
|
|
326
326
|
/** An optional title to be attached to the link that can only be seen by admins. */
|
|
327
327
|
title?: string;
|
|
328
|
-
/**
|
|
328
|
+
/** A point in time within the future in which the invite link will be invalidated. */
|
|
329
329
|
expireAt?: Date;
|
|
330
330
|
/** The times the invite link can be used. Cannot be specified while `requireApproval` is `true`. */
|
|
331
331
|
limit?: number;
|
|
@@ -359,3 +359,25 @@ export interface SendInlineQueryParams {
|
|
|
359
359
|
query?: string;
|
|
360
360
|
offset?: string;
|
|
361
361
|
}
|
|
362
|
+
export interface StartVideoChatParams {
|
|
363
|
+
/** The video chat's title. */
|
|
364
|
+
title?: string;
|
|
365
|
+
/** Whether this is going to be a live stream. */
|
|
366
|
+
liveStream?: boolean;
|
|
367
|
+
}
|
|
368
|
+
export interface ScheduleVideoChatParams extends StartVideoChatParams {
|
|
369
|
+
}
|
|
370
|
+
export interface JoinVideoChatParams {
|
|
371
|
+
/** The identifier of a chat to join the video chat on behalf of. */
|
|
372
|
+
joinAs?: ID;
|
|
373
|
+
/** Invite hash. */
|
|
374
|
+
inviteHash?: string;
|
|
375
|
+
/** Whether to enable audio. Enabled by default. */
|
|
376
|
+
audio?: boolean;
|
|
377
|
+
/** Whether to enable video. Enabled by default. */
|
|
378
|
+
video?: boolean;
|
|
379
|
+
}
|
|
380
|
+
export interface DownloadLiveStreamChunkParams {
|
|
381
|
+
/** Video quality. */
|
|
382
|
+
quality?: "low" | "medium" | "high";
|
|
383
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { types } from "../2_tl.js";
|
|
1
|
+
import { enums, types } from "../2_tl.js";
|
|
2
2
|
import { FileSource, Sticker } from "../3_types.js";
|
|
3
3
|
import { DownloadParams, UploadParams } from "./0_params.js";
|
|
4
4
|
import { C } from "./0_types.js";
|
|
@@ -6,6 +6,10 @@ export declare class FileManager {
|
|
|
6
6
|
#private;
|
|
7
7
|
constructor(c: C);
|
|
8
8
|
upload(file: FileSource, params?: UploadParams, checkName?: null | ((name: string) => string), allowStream?: boolean): Promise<import("../tl/2_types.js").InputFile_ | import("../tl/2_types.js").InputFileBig_>;
|
|
9
|
+
downloadInner(location: enums.InputFileLocation, dcId: number, params?: {
|
|
10
|
+
chunkSize?: number;
|
|
11
|
+
offset?: number;
|
|
12
|
+
}): AsyncGenerator<Uint8Array, void, unknown>;
|
|
9
13
|
static validateChunkSize(chunkSize: number, max: number): void;
|
|
10
14
|
download(fileId: string, params?: DownloadParams): AsyncGenerator<Uint8Array, void, unknown>;
|
|
11
15
|
getStickerSetName(inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
|
|
@@ -33,7 +33,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
33
33
|
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");
|
|
34
34
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
35
35
|
};
|
|
36
|
-
var _FileManager_instances, _a, _FileManager_c, _FileManager_Lupload, _FileManager_UPLOAD_MAX_CHUNK_SIZE, _FileManager_DOWNLOAD_MAX_CHUNK_SIZE, _FileManager_BIG_FILE_THRESHOLD, _FileManager_UPLOAD_REQUEST_PER_CONNECTION, _FileManager_uploadStream, _FileManager_uploadBuffer, _FileManager_handleUploadError, _FileManager_getFileContents,
|
|
36
|
+
var _FileManager_instances, _a, _FileManager_c, _FileManager_Lupload, _FileManager_UPLOAD_MAX_CHUNK_SIZE, _FileManager_DOWNLOAD_MAX_CHUNK_SIZE, _FileManager_BIG_FILE_THRESHOLD, _FileManager_UPLOAD_REQUEST_PER_CONNECTION, _FileManager_uploadStream, _FileManager_uploadBuffer, _FileManager_handleUploadError, _FileManager_getFileContents, _FileManager_CUSTOM_EMOJI_TTL;
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
38
|
exports.FileManager = void 0;
|
|
39
39
|
/**
|
|
@@ -110,6 +110,51 @@ class FileManager {
|
|
|
110
110
|
return new _2_tl_js_1.types.InputFileBig({ id: fileId, parts: result.parts, name });
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
|
+
async *downloadInner(location, dcId, params) {
|
|
114
|
+
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
115
|
+
if (id != null && __classPrivateFieldGet(this, _FileManager_c, "f").storage.supportsFiles) {
|
|
116
|
+
const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
|
|
117
|
+
const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
|
|
118
|
+
if (file != null && file[0] > 0) {
|
|
119
|
+
yield* __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset);
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const chunkSize = params?.chunkSize ?? __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE);
|
|
124
|
+
_a.validateChunkSize(chunkSize, __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE));
|
|
125
|
+
const connection = __classPrivateFieldGet(this, _FileManager_c, "f").getCdnConnection(dcId);
|
|
126
|
+
await connection.connect();
|
|
127
|
+
const limit = chunkSize;
|
|
128
|
+
let offset = params?.offset ? BigInt(params.offset) : 0n;
|
|
129
|
+
let part = 0;
|
|
130
|
+
try {
|
|
131
|
+
while (true) {
|
|
132
|
+
const file = await connection.api.upload.getFile({ location, offset, limit });
|
|
133
|
+
if (file instanceof _2_tl_js_1.types.upload.File) {
|
|
134
|
+
yield file.bytes;
|
|
135
|
+
if (id != null) {
|
|
136
|
+
await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
|
|
137
|
+
}
|
|
138
|
+
++part;
|
|
139
|
+
if (file.bytes.length < limit) {
|
|
140
|
+
if (id != null) {
|
|
141
|
+
await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
|
|
142
|
+
}
|
|
143
|
+
break;
|
|
144
|
+
}
|
|
145
|
+
else {
|
|
146
|
+
offset += BigInt(file.bytes.length);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
else {
|
|
150
|
+
(0, _0_deps_js_1.unreachable)();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
finally {
|
|
155
|
+
(0, _1_utilities_js_1.drop)(connection.disconnect());
|
|
156
|
+
}
|
|
157
|
+
}
|
|
113
158
|
static validateChunkSize(chunkSize, max) {
|
|
114
159
|
if (chunkSize <= 0) {
|
|
115
160
|
throw new _0_errors_js_1.InputError("chunkSize must be bigger than zero.");
|
|
@@ -135,7 +180,7 @@ class FileManager {
|
|
|
135
180
|
const big = fileId_.location.source.type == _3_types_js_1.PhotoSourceType.ChatPhotoBig;
|
|
136
181
|
const peer = await __classPrivateFieldGet(this, _FileManager_c, "f").getInputPeer(Number(fileId_.location.source.chatId)); // TODO: use access hash from source?
|
|
137
182
|
const location = new _2_tl_js_1.types.InputPeerPhotoFileLocation({ big: big ? true : undefined, peer, photo_id: fileId_.location.id });
|
|
138
|
-
yield*
|
|
183
|
+
yield* this.downloadInner(location, fileId_.dcId, params);
|
|
139
184
|
break;
|
|
140
185
|
}
|
|
141
186
|
case _3_types_js_1.FileType.Photo: {
|
|
@@ -145,7 +190,7 @@ class FileManager {
|
|
|
145
190
|
file_reference: fileId_.fileReference ?? new Uint8Array(),
|
|
146
191
|
thumb_size: "thumbnailType" in fileId_.location.source ? String.fromCharCode(fileId_.location.source.thumbnailType) : "",
|
|
147
192
|
});
|
|
148
|
-
yield*
|
|
193
|
+
yield* this.downloadInner(location, fileId_.dcId, params);
|
|
149
194
|
break;
|
|
150
195
|
}
|
|
151
196
|
case _3_types_js_1.FileType.Thumbnail: {
|
|
@@ -155,7 +200,7 @@ class FileManager {
|
|
|
155
200
|
file_reference: fileId_.fileReference ?? new Uint8Array(),
|
|
156
201
|
thumb_size: "thumbnailType" in fileId_.location.source ? String.fromCharCode(fileId_.location.source.thumbnailType) : (0, _0_deps_js_1.unreachable)(),
|
|
157
202
|
});
|
|
158
|
-
yield*
|
|
203
|
+
yield* this.downloadInner(location, fileId_.dcId, params);
|
|
159
204
|
break;
|
|
160
205
|
}
|
|
161
206
|
}
|
|
@@ -167,7 +212,7 @@ class FileManager {
|
|
|
167
212
|
file_reference: fileId_.fileReference ?? new Uint8Array(),
|
|
168
213
|
thumb_size: "",
|
|
169
214
|
});
|
|
170
|
-
yield*
|
|
215
|
+
yield* this.downloadInner(location, fileId_.dcId, params);
|
|
171
216
|
}
|
|
172
217
|
else {
|
|
173
218
|
(0, _0_deps_js_1.unreachable)();
|
|
@@ -400,50 +445,6 @@ _a = FileManager, _FileManager_c = new WeakMap(), _FileManager_Lupload = new Wea
|
|
|
400
445
|
}
|
|
401
446
|
}
|
|
402
447
|
return { size: params?.fileSize ? params.fileSize : size, name, contents };
|
|
403
|
-
}, _FileManager_downloadInner = async function* _FileManager_downloadInner(location, dcId, params) {
|
|
404
|
-
const id = "id" in location ? location.id : "photo_id" in location ? location.photo_id : null;
|
|
405
|
-
if (id != null && __classPrivateFieldGet(this, _FileManager_c, "f").storage.supportsFiles) {
|
|
406
|
-
const file = await __classPrivateFieldGet(this, _FileManager_c, "f").storage.getFile(id);
|
|
407
|
-
const partOffset = file == null ? 0 : params?.offset ? Math.ceil(10 / file[1]) - 1 : 0;
|
|
408
|
-
if (file != null && file[0] > 0) {
|
|
409
|
-
yield* __classPrivateFieldGet(this, _FileManager_c, "f").storage.iterFileParts(id, file[0], partOffset);
|
|
410
|
-
return;
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
const chunkSize = params?.chunkSize ?? __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE);
|
|
414
|
-
_a.validateChunkSize(chunkSize, __classPrivateFieldGet(_a, _a, "f", _FileManager_DOWNLOAD_MAX_CHUNK_SIZE));
|
|
415
|
-
const connection = __classPrivateFieldGet(this, _FileManager_c, "f").getCdnConnection(dcId);
|
|
416
|
-
await connection.connect();
|
|
417
|
-
const limit = chunkSize;
|
|
418
|
-
let offset = params?.offset ? BigInt(params.offset) : 0n;
|
|
419
|
-
let part = 0;
|
|
420
|
-
try {
|
|
421
|
-
while (true) {
|
|
422
|
-
const file = await connection.api.upload.getFile({ location, offset, limit });
|
|
423
|
-
if (file instanceof _2_tl_js_1.types.upload.File) {
|
|
424
|
-
yield file.bytes;
|
|
425
|
-
if (id != null) {
|
|
426
|
-
await __classPrivateFieldGet(this, _FileManager_c, "f").storage.saveFilePart(id, part, file.bytes);
|
|
427
|
-
}
|
|
428
|
-
++part;
|
|
429
|
-
if (file.bytes.length < limit) {
|
|
430
|
-
if (id != null) {
|
|
431
|
-
await __classPrivateFieldGet(this, _FileManager_c, "f").storage.setFilePartCount(id, part + 1, chunkSize);
|
|
432
|
-
}
|
|
433
|
-
break;
|
|
434
|
-
}
|
|
435
|
-
else {
|
|
436
|
-
offset += BigInt(file.bytes.length);
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
else {
|
|
440
|
-
(0, _0_deps_js_1.unreachable)();
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
finally {
|
|
445
|
-
(0, _1_utilities_js_1.drop)(connection.disconnect());
|
|
446
|
-
}
|
|
447
448
|
};
|
|
448
449
|
_FileManager_UPLOAD_MAX_CHUNK_SIZE = { value: 512 * _1_utilities_js_1.kilobyte };
|
|
449
450
|
_FileManager_DOWNLOAD_MAX_CHUNK_SIZE = { value: 1 * _1_utilities_js_1.megabyte };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2024 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { enums, types } from "../2_tl.js";
|
|
21
|
+
import { ID, Update, VideoChatActive, VideoChatScheduled } from "../3_types.js";
|
|
22
|
+
import { DownloadLiveStreamChunkParams, JoinVideoChatParams, StartVideoChatParams } from "./0_params.js";
|
|
23
|
+
import { C as C_ } from "./0_types.js";
|
|
24
|
+
import { FileManager } from "./1_file_manager.js";
|
|
25
|
+
interface C extends C_ {
|
|
26
|
+
fileManager: FileManager;
|
|
27
|
+
}
|
|
28
|
+
type VideoChatManagerUpdate = types.UpdateGroupCall;
|
|
29
|
+
export declare class VideoChatManager {
|
|
30
|
+
#private;
|
|
31
|
+
constructor(c: C);
|
|
32
|
+
startVideoChat(chatId: ID, params?: StartVideoChatParams): Promise<VideoChatActive>;
|
|
33
|
+
scheduleVideoChat(chatId: ID, startAt: Date, params?: StartVideoChatParams): Promise<VideoChatScheduled>;
|
|
34
|
+
joinVideoChat(id: string, params: string, params_?: JoinVideoChatParams): Promise<string>;
|
|
35
|
+
leaveVideoChat(id: string): Promise<void>;
|
|
36
|
+
joinLiveStream(id: string): Promise<void>;
|
|
37
|
+
getVideoChat(id: string): Promise<import("../3_types.js").VideoChat>;
|
|
38
|
+
static canHandleUpdate(update: enums.Update): update is VideoChatManagerUpdate;
|
|
39
|
+
handleUpdate(update: VideoChatManagerUpdate): Promise<Update>;
|
|
40
|
+
getLiveStreamChannels(id: string): Promise<import("../3_types.js").LiveStreamChannel[]>;
|
|
41
|
+
downloadLiveStreamChunk(id: string, channel: number, scale: number, timestamp: number, params?: DownloadLiveStreamChunkParams): AsyncGenerator<Uint8Array, void, unknown>;
|
|
42
|
+
}
|
|
43
|
+
export {};
|