@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
package/esm/storage/0_storage.js
CHANGED
|
@@ -30,6 +30,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
30
30
|
};
|
|
31
31
|
var _Storage_instances, _Storage_authKeyId, _Storage_resetAuthKeyId, _Storage_accountId, _Storage_accountType, _Storage_getUpdateId;
|
|
32
32
|
import { AssertionError, unreachable } from "../0_deps.js";
|
|
33
|
+
import { InputError } from "../0_errors.js";
|
|
33
34
|
import { base64DecodeUrlSafe, base64EncodeUrlSafe, bigIntFromBuffer, rleDecode, rleEncode, sha1, ZERO_CHANNEL_ID } from "../1_utilities.js";
|
|
34
35
|
import { peerToChatId, serialize, TLObject, TLReader, TLWriter, types } from "../2_tl.js";
|
|
35
36
|
// key parts
|
|
@@ -77,6 +78,12 @@ export const K = {
|
|
|
77
78
|
inlineQueryAnswer: (userId, chatId, query, offset) => [...K.cache.inlineQueryAnswers(), userId, chatId, query, offset],
|
|
78
79
|
callbackQueryAnswers: () => [K.cache.P("callbackQueryAnswers")],
|
|
79
80
|
callbackQueryAnswer: (chatId, messageId, question) => [...K.cache.callbackQueryAnswers(), chatId, messageId, question],
|
|
81
|
+
fullChats: () => [K.cache.P("fullChats")],
|
|
82
|
+
fullChat: (chatId) => [...K.cache.fullChats(), chatId],
|
|
83
|
+
groupCalls: () => [K.cache.P("groupCalls")],
|
|
84
|
+
groupCall: (id) => [...K.cache.groupCalls(), id],
|
|
85
|
+
groupCallAccessHashes: () => [K.cache.P("groupCallAccessHashes")],
|
|
86
|
+
groupCallAccessHash: (id) => [...K.cache.groupCallAccessHashes(), id],
|
|
80
87
|
},
|
|
81
88
|
messages: {
|
|
82
89
|
P: (string) => `messages.${string}`,
|
|
@@ -431,6 +438,24 @@ export class Storage {
|
|
|
431
438
|
return null;
|
|
432
439
|
}
|
|
433
440
|
}
|
|
441
|
+
async setFullChat(chatId, fullChat) {
|
|
442
|
+
await this.setTlObject(K.cache.fullChat(chatId), fullChat);
|
|
443
|
+
}
|
|
444
|
+
async getFullChat(chatId) {
|
|
445
|
+
return await this.getTlObject(K.cache.fullChat(chatId));
|
|
446
|
+
}
|
|
447
|
+
async setGroupCall(id, groupCall) {
|
|
448
|
+
await this.setTlObject(K.cache.groupCall(id), groupCall);
|
|
449
|
+
}
|
|
450
|
+
async getGroupCall(id) {
|
|
451
|
+
return await this.getTlObject(K.cache.groupCall(id));
|
|
452
|
+
}
|
|
453
|
+
async setGroupCallAccessHash(id, accessHash) {
|
|
454
|
+
await this.set(K.cache.groupCallAccessHash(id), accessHash);
|
|
455
|
+
}
|
|
456
|
+
async getGroupCallAccessHash(id) {
|
|
457
|
+
return await this.get(K.cache.groupCallAccessHash(id));
|
|
458
|
+
}
|
|
434
459
|
async setUpdate(boxId, update) {
|
|
435
460
|
await this.setTlObject(K.updates.update(boxId, __classPrivateFieldGet(this, _Storage_instances, "m", _Storage_getUpdateId).call(this, update)), update);
|
|
436
461
|
}
|
|
@@ -449,12 +474,12 @@ export class Storage {
|
|
|
449
474
|
}
|
|
450
475
|
async assertUser(source) {
|
|
451
476
|
if (await this.getAccountType() != "user") {
|
|
452
|
-
throw new
|
|
477
|
+
throw new InputError(`${source}: not user a client`);
|
|
453
478
|
}
|
|
454
479
|
}
|
|
455
480
|
async assertBot(source) {
|
|
456
481
|
if (await this.getAccountType() != "bot") {
|
|
457
|
-
throw new
|
|
482
|
+
throw new InputError(`${source}: not a bot client`);
|
|
458
483
|
}
|
|
459
484
|
}
|
|
460
485
|
async deleteFiles() {
|
|
@@ -488,6 +513,16 @@ export class Storage {
|
|
|
488
513
|
await this.set(key, null);
|
|
489
514
|
}
|
|
490
515
|
}
|
|
516
|
+
async deleteFullChats() {
|
|
517
|
+
for await (const [key] of await this.getMany({ prefix: K.cache.fullChats() })) {
|
|
518
|
+
await this.set(key, null);
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
async deleteGroupCalls() {
|
|
522
|
+
for await (const [key] of await this.getMany({ prefix: K.cache.groupCalls() })) {
|
|
523
|
+
await this.set(key, null);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
491
526
|
async deleteStickerSetNames() {
|
|
492
527
|
for await (const [key] of await this.getMany({ prefix: K.cache.stickerSetNames() })) {
|
|
493
528
|
await this.set(key, null);
|
|
@@ -514,6 +549,8 @@ export class Storage {
|
|
|
514
549
|
this.deleteBusinessConnections(),
|
|
515
550
|
this.deleteInlineQueryAnswers(),
|
|
516
551
|
this.deleteCallbackQueryAnswers(),
|
|
552
|
+
this.deleteFullChats(),
|
|
553
|
+
this.deleteGroupCalls(),
|
|
517
554
|
this.deleteStickerSetNames(),
|
|
518
555
|
this.deletePeers(),
|
|
519
556
|
this.deleteUsernames(),
|
package/esm/tl/3_utilities.d.ts
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
import { enums, types } from "./2_types.js";
|
|
21
21
|
export declare function getChannelChatId(channelId: bigint): number;
|
|
22
22
|
export type AnyEntity = types.User | types.Channel | types.ChannelForbidden | types.Chat | types.ChatForbidden;
|
|
23
|
-
export declare function peerToChatId(peer: enums.Peer | enums.InputPeer | AnyEntity | {
|
|
23
|
+
export declare function peerToChatId(peer: enums.Peer | enums.InputPeer | AnyEntity | types.ChannelFull | types.UserFull | types.ChatFull | {
|
|
24
24
|
channel_id: bigint;
|
|
25
25
|
} | {
|
|
26
26
|
user_id: bigint;
|
package/esm/tl/3_utilities.js
CHANGED
|
@@ -24,13 +24,13 @@ export function getChannelChatId(channelId) {
|
|
|
24
24
|
return ZERO_CHANNEL_ID + -Number(channelId);
|
|
25
25
|
}
|
|
26
26
|
export function peerToChatId(peer) {
|
|
27
|
-
if (peer instanceof types.PeerUser || peer instanceof types.InputPeerUser || peer instanceof types.User || "user_id" in peer) {
|
|
27
|
+
if (peer instanceof types.PeerUser || peer instanceof types.InputPeerUser || peer instanceof types.User || peer instanceof types.UserFull || "user_id" in peer) {
|
|
28
28
|
return Number("id" in peer ? peer.id : peer.user_id);
|
|
29
29
|
}
|
|
30
|
-
else if (peer instanceof types.PeerChat || peer instanceof types.InputPeerChat || peer instanceof types.Chat || peer instanceof types.ChatForbidden || "chat_id" in peer) {
|
|
30
|
+
else if (peer instanceof types.PeerChat || peer instanceof types.InputPeerChat || peer instanceof types.Chat || peer instanceof types.ChatForbidden || peer instanceof types.ChatFull || "chat_id" in peer) {
|
|
31
31
|
return -Number("id" in peer ? peer.id : peer.chat_id);
|
|
32
32
|
}
|
|
33
|
-
else if (peer instanceof types.PeerChannel || peer instanceof types.InputPeerChannel || peer instanceof types.Channel || peer instanceof types.ChannelForbidden || "channel_id" in peer) {
|
|
33
|
+
else if (peer instanceof types.PeerChannel || peer instanceof types.InputPeerChannel || peer instanceof types.Channel || peer instanceof types.ChannelForbidden || peer instanceof types.ChannelFull || "channel_id" in peer) {
|
|
34
34
|
return getChannelChatId("id" in peer ? peer.id : peer.channel_id);
|
|
35
35
|
}
|
|
36
36
|
else {
|
|
@@ -0,0 +1,27 @@
|
|
|
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 { types } from "../2_tl.js";
|
|
21
|
+
/** A user's birthday. */
|
|
22
|
+
export interface Birthday {
|
|
23
|
+
day: number;
|
|
24
|
+
month: number;
|
|
25
|
+
year?: number;
|
|
26
|
+
}
|
|
27
|
+
export declare function constructBirthday(birthday: types.Birthday): Birthday;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export function constructBirthday(birthday) {
|
|
21
|
+
return {
|
|
22
|
+
day: birthday.day,
|
|
23
|
+
month: birthday.month,
|
|
24
|
+
year: birthday.year,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -24,7 +24,7 @@ export interface GiveawayParameters {
|
|
|
24
24
|
boostedChatId: number;
|
|
25
25
|
/** The identifiers of additional chats that the user must subscribe to in order to be eligible for the prizes. */
|
|
26
26
|
additionalChatIds: number[];
|
|
27
|
-
/**
|
|
27
|
+
/** A point in time within the future in which the winners will be selected. */
|
|
28
28
|
winnerSelectionDate: Date;
|
|
29
29
|
/** Whether only new members of the chats will be eligible for the prizes. */
|
|
30
30
|
onlyNewMembers: boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
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 { types } from "../2_tl.js";
|
|
21
|
+
/** A live stream channel. */
|
|
22
|
+
export interface LiveStreamChannel {
|
|
23
|
+
/** The live stream channel's unique identifier. */
|
|
24
|
+
id: number;
|
|
25
|
+
/** The scale of the live stream channel's chunks. Duration of each chunk is equal to 1000 / 2 ^ scale. ` */
|
|
26
|
+
scale: number;
|
|
27
|
+
/** The live stream channel's last timestamp. */
|
|
28
|
+
timestamp: number;
|
|
29
|
+
}
|
|
30
|
+
export declare function constructLiveStreamChannel(channel: types.GroupCallStreamChannel): LiveStreamChannel;
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
export function constructLiveStreamChannel(channel) {
|
|
21
|
+
return {
|
|
22
|
+
id: channel.channel,
|
|
23
|
+
scale: channel.scale,
|
|
24
|
+
timestamp: Number(channel.last_timestamp_ms),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { types } from "../2_tl.js";
|
|
21
|
+
export interface OpeningHours {
|
|
22
|
+
timezone: string;
|
|
23
|
+
intervals: [number, number][];
|
|
24
|
+
}
|
|
25
|
+
export declare function constructOpeningHours(hours: types.BusinessWorkHours): OpeningHours;
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
export function constructOpeningHours(hours) {
|
|
21
|
+
return {
|
|
22
|
+
timezone: hours.timezone_id,
|
|
23
|
+
intervals: hours.weekly_open.map((v) => [v.start_minute, v.end_minute]),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
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 } from "../2_tl.js";
|
|
21
|
+
/** @unlisted */
|
|
22
|
+
export interface _VideoChatCommon {
|
|
23
|
+
/** The video chat's unique identifier. */
|
|
24
|
+
id: string;
|
|
25
|
+
}
|
|
26
|
+
/** @unlisted */
|
|
27
|
+
export interface _VideoChatNotEndedCommon {
|
|
28
|
+
/** The video chat's title. */
|
|
29
|
+
title: string;
|
|
30
|
+
/** Whether it is a live stream. */
|
|
31
|
+
liveStream: boolean;
|
|
32
|
+
/** The number of current participants. */
|
|
33
|
+
participantCount: number;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* An ongoing video chat.
|
|
37
|
+
* @unlisted
|
|
38
|
+
*/
|
|
39
|
+
export interface VideoChatActive extends _VideoChatCommon, _VideoChatNotEndedCommon {
|
|
40
|
+
/** Whether the video chat is being recorded. */
|
|
41
|
+
recording: boolean;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* A scheduled video chat.
|
|
45
|
+
* @unlisted
|
|
46
|
+
*/
|
|
47
|
+
export interface VideoChatScheduled extends _VideoChatCommon, _VideoChatNotEndedCommon {
|
|
48
|
+
/** The point in time in which the video chat will be started. */
|
|
49
|
+
scheduledFor: Date;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* An ended video chat.
|
|
53
|
+
* @unlisted
|
|
54
|
+
*/
|
|
55
|
+
export interface VideoChatEnded extends _VideoChatCommon {
|
|
56
|
+
/** The duration of the video chat in seconds. */
|
|
57
|
+
duration: number;
|
|
58
|
+
}
|
|
59
|
+
export type VideoChat = VideoChatActive | VideoChatScheduled | VideoChatEnded;
|
|
60
|
+
export declare function constructVideoChat(call: enums.GroupCall): VideoChat;
|
|
@@ -0,0 +1,53 @@
|
|
|
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 { fromUnixTimestamp } from "../1_utilities.js";
|
|
21
|
+
import { types } from "../2_tl.js";
|
|
22
|
+
export function constructVideoChat(call) {
|
|
23
|
+
const id = String(call.id);
|
|
24
|
+
if (call instanceof types.GroupCallDiscarded) {
|
|
25
|
+
return {
|
|
26
|
+
id,
|
|
27
|
+
duration: call.duration,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
const title = call.title ?? "";
|
|
32
|
+
const liveStream = call.rtmp_stream ? true : false;
|
|
33
|
+
const participantCount = call.participants_count;
|
|
34
|
+
if (call.schedule_date) {
|
|
35
|
+
return {
|
|
36
|
+
id,
|
|
37
|
+
title,
|
|
38
|
+
scheduledFor: fromUnixTimestamp(call.schedule_date),
|
|
39
|
+
liveStream,
|
|
40
|
+
participantCount,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
return {
|
|
45
|
+
id,
|
|
46
|
+
title,
|
|
47
|
+
liveStream,
|
|
48
|
+
recording: call.record_video_active ? true : false,
|
|
49
|
+
participantCount,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
package/esm/types/1_chat_p.d.ts
CHANGED
|
@@ -41,6 +41,8 @@ export interface ChatPPrivate extends _ChatPBase {
|
|
|
41
41
|
lastName?: string;
|
|
42
42
|
/** The user's main username. */
|
|
43
43
|
username?: string;
|
|
44
|
+
/** The user's additional usernames. */
|
|
45
|
+
also?: string[];
|
|
44
46
|
/** Whether the user has been identified as scam. */
|
|
45
47
|
isScam: boolean;
|
|
46
48
|
/** Whether the user has been identified as an impersonator. */
|
|
@@ -68,6 +70,8 @@ export interface ChatPChannelBase extends _ChatPBase {
|
|
|
68
70
|
title: string;
|
|
69
71
|
/** The main username of the chat or channel. */
|
|
70
72
|
username?: string;
|
|
73
|
+
/** The chat or channel's additional usernames. */
|
|
74
|
+
also?: string[];
|
|
71
75
|
/** Whether the chat or channel has been identified as scam. */
|
|
72
76
|
isScam: boolean;
|
|
73
77
|
/** Whether the chat or channel has been identified as an impersonator. */
|
package/esm/types/1_chat_p.js
CHANGED
|
@@ -96,6 +96,7 @@ export function constructChatP(chat) {
|
|
|
96
96
|
};
|
|
97
97
|
}
|
|
98
98
|
chat_.username = chat.username ?? chat.usernames?.[0].username;
|
|
99
|
+
chat_.also = chat.usernames?.map((v) => v.username).filter((v) => v != chat_.username);
|
|
99
100
|
if (chat_.isRestricted) {
|
|
100
101
|
chat_.restrictionReason = (chat.restriction_reason ?? []).map(constructRestrictionReason);
|
|
101
102
|
}
|
|
@@ -20,11 +20,17 @@
|
|
|
20
20
|
import { types } from "../2_tl.js";
|
|
21
21
|
import { EntityGetter } from "./_getters.js";
|
|
22
22
|
import { User } from "./1_user.js";
|
|
23
|
+
/** A business connection. */
|
|
23
24
|
export interface BusinessConnection {
|
|
25
|
+
/** The business connection's unique identifier. */
|
|
24
26
|
id: string;
|
|
27
|
+
/** The business account that the connection is made with. */
|
|
25
28
|
user: User;
|
|
29
|
+
/** The point in time in which the connection was recently updated. */
|
|
26
30
|
date: Date;
|
|
31
|
+
/** Whether the bot can reply to older chats. */
|
|
27
32
|
canReply: boolean;
|
|
33
|
+
/** Whether the connection is active. */
|
|
28
34
|
isEnabled: boolean;
|
|
29
35
|
}
|
|
30
36
|
export declare function constructBusinessConnection(connection: types.BotBusinessConnection, getEntity: EntityGetter): Promise<BusinessConnection>;
|
|
@@ -0,0 +1,62 @@
|
|
|
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 { types } from "../2_tl.js";
|
|
21
|
+
import { EntityGetter } from "./_getters.js";
|
|
22
|
+
import { OpeningHours } from "./0_opening_hours.js";
|
|
23
|
+
import { ChatPChannel, ChatPGroup, ChatPPrivate, ChatPSupergroup } from "./1_chat_p.js";
|
|
24
|
+
import { Photo } from "./1_photo.js";
|
|
25
|
+
import { Location } from "./0_location.js";
|
|
26
|
+
import { Birthday } from "./0_birthday.js";
|
|
27
|
+
/** @unlisted */
|
|
28
|
+
export interface ChatBase {
|
|
29
|
+
/** The chat's photo. */
|
|
30
|
+
photo?: Photo;
|
|
31
|
+
}
|
|
32
|
+
/** @unlisted */
|
|
33
|
+
export interface ChatChannel extends ChatBase, ChatPChannel {
|
|
34
|
+
/** The channel's video chat ID. */
|
|
35
|
+
videoChatId?: string;
|
|
36
|
+
}
|
|
37
|
+
/** @unlisted */
|
|
38
|
+
export interface ChatSupergroup extends ChatBase, ChatPSupergroup {
|
|
39
|
+
/** The chat's video chat ID. */
|
|
40
|
+
videoChatId?: string;
|
|
41
|
+
}
|
|
42
|
+
/** @unlisted */
|
|
43
|
+
export interface ChatGroup extends ChatBase, ChatPGroup {
|
|
44
|
+
/** The chat's video chat ID. */
|
|
45
|
+
videoChatId?: string;
|
|
46
|
+
}
|
|
47
|
+
/** @unlisted */
|
|
48
|
+
export interface ChatPrivate extends ChatBase, ChatPPrivate {
|
|
49
|
+
/** The user's birthday. */
|
|
50
|
+
birthday?: Birthday;
|
|
51
|
+
/** The written address of the business. */
|
|
52
|
+
address?: string;
|
|
53
|
+
/** The exact location of the business. */
|
|
54
|
+
location?: Location;
|
|
55
|
+
/** The opening hours of the business. */
|
|
56
|
+
openingHours?: OpeningHours;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A chat with more fields.
|
|
60
|
+
*/
|
|
61
|
+
export type Chat = ChatChannel | ChatSupergroup | ChatGroup | ChatPrivate;
|
|
62
|
+
export declare function constructChat(fullChat: types.UserFull | types.ChatFull | types.ChannelFull, getEntity: EntityGetter): Promise<Chat>;
|
|
@@ -0,0 +1,66 @@
|
|
|
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 { types } from "../2_tl.js";
|
|
22
|
+
import { constructOpeningHours } from "./0_opening_hours.js";
|
|
23
|
+
import { constructChatP } from "./1_chat_p.js";
|
|
24
|
+
import { constructPhoto } from "./1_photo.js";
|
|
25
|
+
import { constructLocation } from "./0_location.js";
|
|
26
|
+
import { constructBirthday } from "./0_birthday.js";
|
|
27
|
+
import { cleanObject } from "../1_utilities.js";
|
|
28
|
+
export async function constructChat(fullChat, getEntity) {
|
|
29
|
+
if (fullChat instanceof types.UserFull) {
|
|
30
|
+
const user = await getEntity(new types.PeerUser({ user_id: fullChat.id }));
|
|
31
|
+
if (user == null)
|
|
32
|
+
unreachable();
|
|
33
|
+
const chatP = constructChatP(user);
|
|
34
|
+
return cleanObject({
|
|
35
|
+
...chatP,
|
|
36
|
+
birthday: fullChat.birthday ? constructBirthday(fullChat.birthday) : undefined,
|
|
37
|
+
photo: fullChat.profile_photo && fullChat.profile_photo instanceof types.Photo ? constructPhoto(fullChat.profile_photo) : undefined,
|
|
38
|
+
address: fullChat.business_location?.address,
|
|
39
|
+
location: fullChat.business_location?.geo_point && fullChat.business_location.geo_point instanceof types.GeoPoint ? constructLocation(fullChat.business_location.geo_point) : undefined,
|
|
40
|
+
openingHours: fullChat.business_work_hours ? constructOpeningHours(fullChat.business_work_hours) : undefined,
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
else if (fullChat instanceof types.ChatFull) {
|
|
44
|
+
const chat = await getEntity(new types.PeerChat({ chat_id: fullChat.id }));
|
|
45
|
+
if (chat == null)
|
|
46
|
+
unreachable();
|
|
47
|
+
const chatP = constructChatP(chat);
|
|
48
|
+
return cleanObject({
|
|
49
|
+
...chatP,
|
|
50
|
+
photo: fullChat.chat_photo && fullChat.chat_photo instanceof types.Photo ? constructPhoto(fullChat.chat_photo) : undefined,
|
|
51
|
+
videoChatId: fullChat.call ? String(fullChat.call.id) : undefined,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
else if (fullChat instanceof types.ChannelFull) {
|
|
55
|
+
const chat = await getEntity(new types.PeerChannel({ channel_id: fullChat.id }));
|
|
56
|
+
if (chat == null)
|
|
57
|
+
unreachable();
|
|
58
|
+
const chatP = constructChatP(chat);
|
|
59
|
+
return cleanObject({
|
|
60
|
+
...chatP,
|
|
61
|
+
photo: fullChat.chat_photo && fullChat.chat_photo instanceof types.Photo ? constructPhoto(fullChat.chat_photo) : undefined,
|
|
62
|
+
videoChatId: fullChat.call ? String(fullChat.call.id) : undefined,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
unreachable();
|
|
66
|
+
}
|
|
@@ -21,7 +21,7 @@ import { enums } from "../2_tl.js";
|
|
|
21
21
|
import { ChatP } from "./1_chat_p.js";
|
|
22
22
|
/** An inactive chat. */
|
|
23
23
|
export interface InactiveChat {
|
|
24
|
-
/** The
|
|
24
|
+
/** The time which the chat was last active. */
|
|
25
25
|
lastActivity: Date;
|
|
26
26
|
/** The chat that has been marked as inactive. */
|
|
27
27
|
chat: ChatP;
|
|
@@ -32,7 +32,7 @@ export interface InviteLink {
|
|
|
32
32
|
revoked: boolean;
|
|
33
33
|
/** An optional title. */
|
|
34
34
|
title?: string;
|
|
35
|
-
/**
|
|
35
|
+
/** A point in time within the future in which the ban will be reverted. */
|
|
36
36
|
expiresAt?: Date;
|
|
37
37
|
/** The times the invite link can be used. */
|
|
38
38
|
limit?: number;
|
|
@@ -27,7 +27,7 @@ export interface MessageReactionCount {
|
|
|
27
27
|
chat: ChatP;
|
|
28
28
|
/** The message's identifier. */
|
|
29
29
|
messageId: number;
|
|
30
|
-
/**
|
|
30
|
+
/** The point in time in which the change was made. */
|
|
31
31
|
date: Date;
|
|
32
32
|
/** The reactions made to the post. */
|
|
33
33
|
reactions: ReactionCount[];
|
|
@@ -32,7 +32,7 @@ export interface MessageReactions {
|
|
|
32
32
|
user?: User;
|
|
33
33
|
/** The chat that changed its reactions to the message. Unset if done on behalf of a user. */
|
|
34
34
|
actorChat?: ChatP;
|
|
35
|
-
/** The point
|
|
35
|
+
/** The point in time in which the change was made. */
|
|
36
36
|
date: Date;
|
|
37
37
|
/** The previous reactions. */
|
|
38
38
|
oldReactions: Reaction[];
|
|
@@ -29,7 +29,7 @@ export interface ChatMemberUpdated {
|
|
|
29
29
|
chat: ChatP;
|
|
30
30
|
/** The one who made the change. */
|
|
31
31
|
from: User;
|
|
32
|
-
/** The point
|
|
32
|
+
/** The point in time in which the chat member's status was changed. */
|
|
33
33
|
date: Date;
|
|
34
34
|
/** The old status of the chat member. */
|
|
35
35
|
oldChatMember: ChatMember;
|
package/esm/types/4_message.d.ts
CHANGED
|
@@ -57,7 +57,7 @@ export interface _MessageBase {
|
|
|
57
57
|
from?: User;
|
|
58
58
|
/** The chat which the message was sent on behalf of. */
|
|
59
59
|
senderChat?: ChatP;
|
|
60
|
-
/** The point
|
|
60
|
+
/** The point in time in which the message was sent. */
|
|
61
61
|
date: Date;
|
|
62
62
|
/** The chat where the message was sent to. */
|
|
63
63
|
chat: ChatP;
|
|
@@ -73,7 +73,7 @@ export interface _MessageBase {
|
|
|
73
73
|
forwardSignature?: string;
|
|
74
74
|
/** The name of the original sender of the message. */
|
|
75
75
|
forwardSenderName?: string;
|
|
76
|
-
/** The point
|
|
76
|
+
/** The point in time in which the original message was sent. */
|
|
77
77
|
forwardDate?: Date;
|
|
78
78
|
/** Whether the message was sent in a topic thread. */
|
|
79
79
|
isTopicMessage: boolean;
|
|
@@ -89,7 +89,7 @@ export interface _MessageBase {
|
|
|
89
89
|
replyQuote?: ReplyQuote;
|
|
90
90
|
/** The inline bot that was used to send this message. */
|
|
91
91
|
viaBot?: User;
|
|
92
|
-
/** The point
|
|
92
|
+
/** The point in time in which the message's last edit was made. */
|
|
93
93
|
editDate?: Date;
|
|
94
94
|
/** Whether the contents of the message is protected. */
|
|
95
95
|
hasProtectedContent?: boolean;
|