@mtkruto/node 0.1.141 → 0.1.143
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/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/5_client.d.ts +1 -0
- package/esm/5_client.js +1 -0
- package/esm/client/0_types.d.ts +2 -0
- package/esm/client/1_bot_info_manager.d.ts +30 -0
- package/esm/client/1_bot_info_manager.js +66 -0
- package/esm/client/1_network_statistics_manager.d.ts +19 -0
- package/esm/client/1_network_statistics_manager.js +48 -0
- package/esm/client/1_reaction_manager.d.ts +9 -0
- package/esm/client/1_reaction_manager.js +84 -0
- package/esm/client/2_message_manager.d.ts +22 -2
- package/esm/client/2_message_manager.js +282 -28
- package/esm/client/3_callback_query_manager.d.ts +16 -0
- package/esm/client/3_callback_query_manager.js +36 -0
- package/esm/client/3_chat_list_manager.d.ts +5 -9
- package/esm/client/3_chat_list_manager.js +190 -103
- package/esm/client/3_inline_query_manager.d.ts +16 -0
- package/esm/client/3_inline_query_manager.js +49 -0
- package/esm/client/4_client.d.ts +12 -12
- package/esm/client/4_client.js +162 -538
- package/esm/client/5_session_string.d.ts +3 -0
- package/esm/client/5_session_string.js +22 -0
- package/esm/connection/1_connection_web_socket.js +1 -1
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/5_client.d.ts +1 -0
- package/script/5_client.js +1 -0
- package/script/client/0_types.d.ts +2 -0
- package/script/client/1_bot_info_manager.d.ts +30 -0
- package/script/client/1_bot_info_manager.js +70 -0
- package/script/client/1_network_statistics_manager.d.ts +19 -0
- package/script/client/1_network_statistics_manager.js +52 -0
- package/script/client/1_reaction_manager.d.ts +9 -0
- package/script/client/1_reaction_manager.js +88 -0
- package/script/client/2_message_manager.d.ts +22 -2
- package/script/client/2_message_manager.js +281 -27
- package/script/client/3_callback_query_manager.d.ts +16 -0
- package/script/client/3_callback_query_manager.js +40 -0
- package/script/client/3_chat_list_manager.d.ts +5 -9
- package/script/client/3_chat_list_manager.js +187 -100
- package/script/client/3_inline_query_manager.d.ts +16 -0
- package/script/client/3_inline_query_manager.js +53 -0
- package/script/client/4_client.d.ts +12 -12
- package/script/client/4_client.js +158 -534
- package/script/client/5_session_string.d.ts +3 -0
- package/script/client/5_session_string.js +27 -0
- package/script/connection/1_connection_web_socket.js +1 -1
- package/esm/client/3_reaction_manager.d.ts +0 -16
- package/esm/client/3_reaction_manager.js +0 -61
- package/script/client/3_reaction_manager.d.ts +0 -16
- package/script/client/3_reaction_manager.js +0 -65
|
@@ -9,11 +9,11 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
9
9
|
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");
|
|
10
10
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
11
|
};
|
|
12
|
-
var _MessageManager_instances, _MessageManager_c,
|
|
12
|
+
var _MessageManager_instances, _MessageManager_c, _MessageManager_updatesToMessages, _MessageManager_constructReplyMarkup, _MessageManager_resolveSendAs, _MessageManager_constructReplyTo, _MessageManager_sendDocumentInner, _MessageManager_sendMedia, _MessageManager_resolveFileId, _MessageManager_sendReaction;
|
|
13
13
|
import { contentType, debug } from "../0_deps.js";
|
|
14
14
|
import { getRandomId, toUnixTimestamp, UNREACHABLE } from "../1_utilities.js";
|
|
15
|
-
import { as, peerToChatId, types } from "../2_tl.js";
|
|
16
|
-
import { assertMessageType, constructMessage as constructMessage_, FileID, FileType, messageEntityToTlObject, replyMarkupToTlObject } from "../3_types.js";
|
|
15
|
+
import { as, getChannelChatId, peerToChatId, types } from "../2_tl.js";
|
|
16
|
+
import { assertMessageType, constructMessage as constructMessage_, FileID, FileType, messageEntityToTlObject, reactionEqual, reactionToTlObject, replyMarkupToTlObject } from "../3_types.js";
|
|
17
17
|
import { STICKER_SET_NAME_TTL } from "../4_constants.js";
|
|
18
18
|
import { parseHtml } from "./0_html.js";
|
|
19
19
|
import { getFileContents, isHttpUrl } from "./0_utilities.js";
|
|
@@ -22,9 +22,14 @@ export class MessageManager {
|
|
|
22
22
|
constructor(c) {
|
|
23
23
|
_MessageManager_instances.add(this);
|
|
24
24
|
_MessageManager_c.set(this, void 0);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
Object.defineProperty(this, "usernameResolver", {
|
|
26
|
+
enumerable: true,
|
|
27
|
+
configurable: true,
|
|
28
|
+
writable: true,
|
|
29
|
+
value: async (v) => {
|
|
30
|
+
const inputPeer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(v).then((v) => v[as](types.InputPeerUser));
|
|
31
|
+
return new types.InputUser(inputPeer);
|
|
32
|
+
}
|
|
28
33
|
});
|
|
29
34
|
__classPrivateFieldSet(this, _MessageManager_c, c, "f");
|
|
30
35
|
}
|
|
@@ -78,6 +83,26 @@ export class MessageManager {
|
|
|
78
83
|
const messages = await this.getMessages(chatId, [messageId]);
|
|
79
84
|
return messages[0] ?? null;
|
|
80
85
|
}
|
|
86
|
+
parseText(text, params) {
|
|
87
|
+
const entities_ = params?.entities ?? [];
|
|
88
|
+
const parseMode = params?.parseMode ?? __classPrivateFieldGet(this, _MessageManager_c, "f").parseMode;
|
|
89
|
+
switch (parseMode) {
|
|
90
|
+
case null:
|
|
91
|
+
break;
|
|
92
|
+
case "HTML": {
|
|
93
|
+
const [newText, entitiesToPush] = parseHtml(text);
|
|
94
|
+
text = newText;
|
|
95
|
+
for (const entity of entitiesToPush) {
|
|
96
|
+
entities_.push(entity);
|
|
97
|
+
}
|
|
98
|
+
break;
|
|
99
|
+
}
|
|
100
|
+
default:
|
|
101
|
+
UNREACHABLE();
|
|
102
|
+
}
|
|
103
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => messageEntityToTlObject(v)) : undefined;
|
|
104
|
+
return [text, entities];
|
|
105
|
+
}
|
|
81
106
|
async getStickerSetName(inputStickerSet, hash = 0) {
|
|
82
107
|
const maybeStickerSetName = await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
|
|
83
108
|
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < STICKER_SET_NAME_TTL) {
|
|
@@ -152,7 +177,7 @@ export class MessageManager {
|
|
|
152
177
|
return messages;
|
|
153
178
|
}
|
|
154
179
|
async sendMessage(chatId, text, params) {
|
|
155
|
-
const [message, entities] =
|
|
180
|
+
const [message, entities] = this.parseText(text, params);
|
|
156
181
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
157
182
|
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
158
183
|
const randomId = getRandomId();
|
|
@@ -383,7 +408,7 @@ export class MessageManager {
|
|
|
383
408
|
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
384
409
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
385
410
|
const explanation = params?.explanation;
|
|
386
|
-
const parseResult = explanation !== undefined ?
|
|
411
|
+
const parseResult = explanation !== undefined ? this.parseText(explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
387
412
|
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
388
413
|
const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
389
414
|
const answers = options.map((v, i) => new types.PollAnswer({ option: new Uint8Array([i]), text: v }));
|
|
@@ -428,7 +453,7 @@ export class MessageManager {
|
|
|
428
453
|
return message_;
|
|
429
454
|
}
|
|
430
455
|
async editMessageText(chatId, messageId, text, params) {
|
|
431
|
-
const [message, entities] =
|
|
456
|
+
const [message, entities] = this.parseText(text, params);
|
|
432
457
|
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({
|
|
433
458
|
id: messageId,
|
|
434
459
|
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
@@ -475,27 +500,248 @@ export class MessageManager {
|
|
|
475
500
|
async unpinMessages(chatId) {
|
|
476
501
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.unpinAllMessages({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId) });
|
|
477
502
|
}
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
503
|
+
async setAvailableReactions(chatId, availableReactions) {
|
|
504
|
+
// TODO: sync with storage
|
|
505
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.setChatAvailableReactions({
|
|
506
|
+
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
507
|
+
available_reactions: availableReactions == "none" ? new types.ChatReactionsNone() : availableReactions == "all" ? new types.ChatReactionsAll() : Array.isArray(availableReactions) ? new types.ChatReactionsSome({ reactions: availableReactions.map((v) => v.type == "emoji" ? new types.ReactionEmoji({ emoticon: v.emoji }) : new types.ReactionCustomEmoji({ document_id: BigInt(v.id) })) }) : UNREACHABLE(),
|
|
508
|
+
});
|
|
509
|
+
}
|
|
510
|
+
async setReactions(chatId, messageId, reactions, params) {
|
|
511
|
+
await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_sendReaction).call(this, chatId, messageId, reactions, params);
|
|
512
|
+
}
|
|
513
|
+
async addReaction(chatId, messageId, reaction, params) {
|
|
514
|
+
const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
|
|
515
|
+
for (const r of chosenReactions) {
|
|
516
|
+
if (reactionEqual(r.reaction, reaction)) {
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
|
|
521
|
+
await this.setReactions(chatId, messageId, reactions, params);
|
|
522
|
+
}
|
|
523
|
+
async removeReaction(chatId, messageId, reaction) {
|
|
524
|
+
const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
|
|
525
|
+
for (const r of chosenReactions) {
|
|
526
|
+
if (reactionEqual(r.reaction, reaction)) {
|
|
527
|
+
const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction);
|
|
528
|
+
await this.setReactions(chatId, messageId, reactions);
|
|
529
|
+
break;
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
static canHandleUpdate(update) {
|
|
534
|
+
return update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditMessage || update instanceof types.UpdateEditChannelMessage || update instanceof types.UpdateDeleteMessages || update instanceof types.UpdateDeleteChannelMessages;
|
|
535
|
+
}
|
|
536
|
+
async handleUpdate(update) {
|
|
537
|
+
if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateEditMessage || update instanceof types.UpdateEditChannelMessage) {
|
|
538
|
+
if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
|
|
539
|
+
const chatId = peerToChatId(update.message.peer_id);
|
|
540
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.setMessage(chatId, update.message.id, update.message);
|
|
541
|
+
// promises.push(this.#chatListManager.reassignChatLastMessage(chatId));
|
|
490
542
|
}
|
|
491
|
-
break;
|
|
492
543
|
}
|
|
493
|
-
|
|
544
|
+
if (update instanceof types.UpdateNewMessage ||
|
|
545
|
+
update instanceof types.UpdateNewChannelMessage ||
|
|
546
|
+
update instanceof types.UpdateEditMessage ||
|
|
547
|
+
update instanceof types.UpdateEditChannelMessage) {
|
|
548
|
+
if (!(update.message instanceof types.MessageEmpty)) {
|
|
549
|
+
const isOutgoing = update.message.out;
|
|
550
|
+
let shouldIgnore = isOutgoing ? (await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getAccountType()) == "user" ? false : true : false;
|
|
551
|
+
if (__classPrivateFieldGet(this, _MessageManager_c, "f").ignoreOutgoing != null && isOutgoing) {
|
|
552
|
+
shouldIgnore = __classPrivateFieldGet(this, _MessageManager_c, "f").ignoreOutgoing;
|
|
553
|
+
}
|
|
554
|
+
if (!shouldIgnore) {
|
|
555
|
+
const message = await this.constructMessage(update.message);
|
|
556
|
+
if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage) {
|
|
557
|
+
return ({ message });
|
|
558
|
+
}
|
|
559
|
+
else {
|
|
560
|
+
return ({ editedMessage: message });
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
}
|
|
565
|
+
if (update instanceof types.UpdateDeleteMessages) {
|
|
566
|
+
const deletedMessages = new Array();
|
|
567
|
+
for (const messageId of update.messages) {
|
|
568
|
+
const chatId = await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getMessageChat(messageId);
|
|
569
|
+
if (chatId) {
|
|
570
|
+
deletedMessages.push({ chatId, messageId });
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
if (deletedMessages.length > 0) {
|
|
574
|
+
return { deletedMessages };
|
|
575
|
+
}
|
|
576
|
+
}
|
|
577
|
+
else if (update instanceof types.UpdateDeleteChannelMessages) {
|
|
578
|
+
const chatId = getChannelChatId(update.channel_id);
|
|
579
|
+
const deletedMessages = new Array();
|
|
580
|
+
for (const messageId of update.messages) {
|
|
581
|
+
const message = await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getMessage(chatId, messageId);
|
|
582
|
+
if (message != null) {
|
|
583
|
+
deletedMessages.push({ chatId, messageId });
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
return { deletedMessages };
|
|
587
|
+
}
|
|
588
|
+
return null;
|
|
589
|
+
}
|
|
590
|
+
async sendChatAction(chatId, action, params) {
|
|
591
|
+
let action_;
|
|
592
|
+
switch (action) {
|
|
593
|
+
case "type":
|
|
594
|
+
action_ = new types.SendMessageTypingAction();
|
|
595
|
+
break;
|
|
596
|
+
case "uploadPhoto":
|
|
597
|
+
action_ = new types.SendMessageUploadPhotoAction({ progress: 0 });
|
|
598
|
+
break;
|
|
599
|
+
case "recordVideo":
|
|
600
|
+
action_ = new types.SendMessageRecordVideoAction();
|
|
601
|
+
break;
|
|
602
|
+
case "uploadVideo":
|
|
603
|
+
action_ = new types.SendMessageRecordVideoAction();
|
|
604
|
+
break;
|
|
605
|
+
case "recordVoice":
|
|
606
|
+
action_ = new types.SendMessageRecordAudioAction();
|
|
607
|
+
break;
|
|
608
|
+
case "uploadAudio":
|
|
609
|
+
action_ = new types.SendMessageUploadAudioAction({ progress: 0 });
|
|
610
|
+
break;
|
|
611
|
+
case "uploadDocument":
|
|
612
|
+
action_ = new types.SendMessageUploadDocumentAction({ progress: 0 });
|
|
613
|
+
break;
|
|
614
|
+
case "chooseSticker":
|
|
615
|
+
action_ = new types.SendMessageChooseStickerAction();
|
|
616
|
+
break;
|
|
617
|
+
case "findLocation":
|
|
618
|
+
action_ = new types.SendMessageGeoLocationAction();
|
|
619
|
+
break;
|
|
620
|
+
case "recordVideoNote":
|
|
621
|
+
action_ = new types.SendMessageRecordRoundAction();
|
|
622
|
+
break;
|
|
623
|
+
case "uploadVideoNote":
|
|
624
|
+
action_ = new types.SendMessageUploadRoundAction({ progress: 0 });
|
|
625
|
+
break;
|
|
626
|
+
default:
|
|
627
|
+
throw new Error("Invalid chat action: " + action);
|
|
628
|
+
}
|
|
629
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.setTyping({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId });
|
|
630
|
+
}
|
|
631
|
+
async deleteChatPhoto(chatId) {
|
|
632
|
+
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
633
|
+
if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
|
|
634
|
+
UNREACHABLE();
|
|
635
|
+
}
|
|
636
|
+
if (peer instanceof types.InputPeerChannel) {
|
|
637
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: new types.InputChatPhotoEmpty() });
|
|
638
|
+
}
|
|
639
|
+
else if (peer instanceof types.InputPeerChat) {
|
|
640
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: new types.InputChatPhotoEmpty() });
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
async setChatPhoto(chatId, photo, params) {
|
|
644
|
+
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
645
|
+
if (!(peer instanceof types.InputPeerChannel) && !(peer instanceof types.InputPeerChat)) {
|
|
494
646
|
UNREACHABLE();
|
|
647
|
+
}
|
|
648
|
+
const [contents, fileName] = await getFileContents(photo);
|
|
649
|
+
const file = await __classPrivateFieldGet(this, _MessageManager_c, "f").fileManager.upload(contents, { fileName: params?.fileName ?? fileName, chunkSize: params?.chunkSize, signal: params?.signal });
|
|
650
|
+
const photo_ = new types.InputChatUploadedPhoto({ file });
|
|
651
|
+
if (peer instanceof types.InputPeerChannel) {
|
|
652
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editPhoto({ channel: new types.InputChannel(peer), photo: photo_ });
|
|
653
|
+
}
|
|
654
|
+
else if (peer instanceof types.InputPeerChat) {
|
|
655
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editChatPhoto({ chat_id: peer.chat_id, photo: photo_ });
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
async banChatMember(chatId, memberId, params) {
|
|
659
|
+
const chat = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
660
|
+
if (!(chat instanceof types.InputPeerChannel) && !(chat instanceof types.InputPeerChat)) {
|
|
661
|
+
throw new Error("Invalid chat ID");
|
|
662
|
+
}
|
|
663
|
+
const member = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
664
|
+
if (chat instanceof types.InputPeerChannel) {
|
|
665
|
+
if (params?.deleteMessages) {
|
|
666
|
+
try {
|
|
667
|
+
await this.deleteChatMemberMessages(chatId, memberId);
|
|
668
|
+
}
|
|
669
|
+
catch {
|
|
670
|
+
//
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
|
|
674
|
+
channel: new types.InputChannel(chat),
|
|
675
|
+
participant: member,
|
|
676
|
+
banned_rights: new types.ChatBannedRights({
|
|
677
|
+
until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
|
|
678
|
+
view_messages: true,
|
|
679
|
+
send_messages: true,
|
|
680
|
+
send_media: true,
|
|
681
|
+
send_stickers: true,
|
|
682
|
+
send_gifs: true,
|
|
683
|
+
send_games: true,
|
|
684
|
+
send_inline: true,
|
|
685
|
+
embed_links: true,
|
|
686
|
+
}),
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
else if (chat instanceof types.InputPeerChat) {
|
|
690
|
+
if (!(member instanceof types.InputPeerUser)) {
|
|
691
|
+
throw new Error("Invalid user ID");
|
|
692
|
+
}
|
|
693
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.deleteChatUser({
|
|
694
|
+
chat_id: chat.chat_id,
|
|
695
|
+
user_id: new types.InputUser(member),
|
|
696
|
+
revoke_history: params?.deleteMessages ? true : undefined,
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
async unbanChatMember(chatId, memberId) {
|
|
701
|
+
const chat = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
702
|
+
if (!(chat instanceof types.InputPeerChannel)) {
|
|
703
|
+
throw new Error("Invalid chat ID");
|
|
704
|
+
}
|
|
705
|
+
const member = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
706
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
|
|
707
|
+
channel: new types.InputChannel(chat),
|
|
708
|
+
participant: member,
|
|
709
|
+
banned_rights: new types.ChatBannedRights({ until_date: 0 }),
|
|
710
|
+
});
|
|
495
711
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
712
|
+
async setChatMemberRights(chatId, memberId, params) {
|
|
713
|
+
const chat = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
714
|
+
if (!(chat instanceof types.InputPeerChannel)) {
|
|
715
|
+
throw new Error("Invalid chat ID");
|
|
716
|
+
}
|
|
717
|
+
const member = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
718
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
|
|
719
|
+
channel: new types.InputChannel(chat),
|
|
720
|
+
participant: member,
|
|
721
|
+
banned_rights: new types.ChatBannedRights({
|
|
722
|
+
until_date: params?.untilDate ? toUnixTimestamp(params.untilDate) : 0,
|
|
723
|
+
send_messages: params?.rights?.canSendMessages ? true : undefined,
|
|
724
|
+
send_audios: params?.rights?.canSendAudio ? true : undefined,
|
|
725
|
+
send_docs: params?.rights?.canSendDocuments ? true : undefined,
|
|
726
|
+
send_photos: params?.rights?.canSendPhotos ? true : undefined,
|
|
727
|
+
send_videos: params?.rights?.canSendVideos ? true : undefined,
|
|
728
|
+
send_roundvideos: params?.rights?.canSendVideoNotes ? true : undefined,
|
|
729
|
+
send_voices: params?.rights?.canSendVoice ? true : undefined,
|
|
730
|
+
send_polls: params?.rights?.canSendPolls ? true : undefined,
|
|
731
|
+
send_stickers: params?.rights?.canSendStickers ? true : undefined,
|
|
732
|
+
send_gifs: params?.rights?.canSendAnimations ? true : undefined,
|
|
733
|
+
send_games: params?.rights?.canSendGames ? true : undefined,
|
|
734
|
+
send_inline: params?.rights?.canSendInlineBotResults ? true : undefined,
|
|
735
|
+
embed_links: params?.rights?.canAddWebPagePreviews ? true : undefined,
|
|
736
|
+
change_info: params?.rights?.canChangeInfo ? true : undefined,
|
|
737
|
+
invite_users: params?.rights?.canInviteUsers ? true : undefined,
|
|
738
|
+
pin_messages: params?.rights?.canPinMessages ? true : undefined,
|
|
739
|
+
manage_topics: params?.rights?.canManageTopics ? true : undefined,
|
|
740
|
+
}),
|
|
741
|
+
});
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
_MessageManager_c = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
|
|
499
745
|
const messages = new Array();
|
|
500
746
|
if (updates instanceof types.Updates) {
|
|
501
747
|
for (const update of updates.updates) {
|
|
@@ -520,7 +766,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
520
766
|
}, _MessageManager_constructReplyMarkup = async function _MessageManager_constructReplyMarkup(params) {
|
|
521
767
|
if (params?.replyMarkup) {
|
|
522
768
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
523
|
-
return replyMarkupToTlObject(params.replyMarkup,
|
|
769
|
+
return replyMarkupToTlObject(params.replyMarkup, this.usernameResolver.bind(this));
|
|
524
770
|
}
|
|
525
771
|
}, _MessageManager_resolveSendAs = async function _MessageManager_resolveSendAs(params) {
|
|
526
772
|
const sendAs = params?.sendAs;
|
|
@@ -580,7 +826,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
580
826
|
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
581
827
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
582
828
|
const caption_ = params?.caption;
|
|
583
|
-
const parseResult = caption_ !== undefined ?
|
|
829
|
+
const parseResult = caption_ !== undefined ? this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
584
830
|
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
585
831
|
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
586
832
|
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendMedia({
|
|
@@ -618,4 +864,12 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
618
864
|
};
|
|
619
865
|
}
|
|
620
866
|
return null;
|
|
867
|
+
}, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) {
|
|
868
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendReaction({
|
|
869
|
+
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
870
|
+
msg_id: messageId,
|
|
871
|
+
reaction: reactions.map((v) => reactionToTlObject(v)),
|
|
872
|
+
big: params?.big ? true : undefined,
|
|
873
|
+
add_to_recent: params?.addToRecents ? true : undefined,
|
|
874
|
+
});
|
|
621
875
|
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { enums, types } from "../2_tl.js";
|
|
2
|
+
import { Update } from "../3_types.js";
|
|
3
|
+
import { AnswerCallbackQueryParams } from "./0_params.js";
|
|
4
|
+
import { C as C_ } from "./0_types.js";
|
|
5
|
+
import { MessageManager } from "./2_message_manager.js";
|
|
6
|
+
type C = C_ & {
|
|
7
|
+
messageManager: MessageManager;
|
|
8
|
+
};
|
|
9
|
+
export declare class CallbackQueryManager {
|
|
10
|
+
#private;
|
|
11
|
+
constructor(c: C);
|
|
12
|
+
answerCallbackQuery(id: string, params?: AnswerCallbackQueryParams): Promise<void>;
|
|
13
|
+
static canHandleUpdate(update: enums.Update): update is types.UpdateBotCallbackQuery | types.UpdateInlineBotCallbackQuery;
|
|
14
|
+
handleUpdate(update: types.UpdateBotCallbackQuery | types.UpdateInlineBotCallbackQuery): Promise<Update>;
|
|
15
|
+
}
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _CallbackQueryManager_c;
|
|
13
|
+
import { types } from "../2_tl.js";
|
|
14
|
+
import { constructCallbackQuery } from "../3_types.js";
|
|
15
|
+
export class CallbackQueryManager {
|
|
16
|
+
constructor(c) {
|
|
17
|
+
_CallbackQueryManager_c.set(this, void 0);
|
|
18
|
+
__classPrivateFieldSet(this, _CallbackQueryManager_c, c, "f");
|
|
19
|
+
}
|
|
20
|
+
async answerCallbackQuery(id, params) {
|
|
21
|
+
await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").storage.assertBot("answerCallbackQuery");
|
|
22
|
+
await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").api.messages.setBotCallbackAnswer({
|
|
23
|
+
query_id: BigInt(id),
|
|
24
|
+
cache_time: params?.cacheTime ?? 0,
|
|
25
|
+
message: params?.text,
|
|
26
|
+
alert: params?.alert ? true : undefined,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
static canHandleUpdate(update) {
|
|
30
|
+
return update instanceof types.UpdateBotCallbackQuery || update instanceof types.UpdateInlineBotCallbackQuery;
|
|
31
|
+
}
|
|
32
|
+
async handleUpdate(update) {
|
|
33
|
+
return { callbackQuery: await constructCallbackQuery(update, __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").getEntity, __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").messageManager.getMessageWithReply.bind(__classPrivateFieldGet(this, _CallbackQueryManager_c, "f").messageManager)) };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
_CallbackQueryManager_c = new WeakMap();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { types } from "../2_tl.js";
|
|
2
|
-
import { Chat } from "../3_types.js";
|
|
1
|
+
import { enums, types } from "../2_tl.js";
|
|
2
|
+
import { Chat, ID } from "../3_types.js";
|
|
3
3
|
import { C as C_ } from "./0_types.js";
|
|
4
4
|
import { MessageManager } from "./2_message_manager.js";
|
|
5
5
|
type C = C_ & {
|
|
@@ -9,13 +9,9 @@ export declare class ChatListManager {
|
|
|
9
9
|
#private;
|
|
10
10
|
constructor(c: C);
|
|
11
11
|
reassignChatLastMessage(chatId: number, add?: boolean, sendUpdate?: boolean): Promise<() => Promise<void>>;
|
|
12
|
-
tryGetChatId(username: string): number | null;
|
|
13
|
-
getChatAnywhere(chatId: number): [Chat | undefined, number];
|
|
14
|
-
handelUpdateFolderPeers(update: types.UpdateFolderPeers): Promise<void>;
|
|
15
|
-
handleUpdatePinnedDialogs(update: types.UpdatePinnedDialogs): Promise<void>;
|
|
16
|
-
handleUpdateChannel(update: types.UpdateChannel): Promise<void>;
|
|
17
|
-
handleUpdateChat(update: types.UpdateChat): Promise<void>;
|
|
18
|
-
handleUpdateUser(update: types.UpdateUser | types.UpdateUserName): Promise<void>;
|
|
19
12
|
getChats(from?: "archived" | "main", after?: Chat, limit?: number): Promise<Chat[]>;
|
|
13
|
+
static canHandleUpdate(update: enums.Update): update is types.UpdateNewMessage | types.UpdateNewChannelMessage | types.UpdatePinnedDialogs | types.UpdateFolderPeers | types.UpdateChannel | types.UpdateChat | types.UpdateUser | types.UpdateUserName;
|
|
14
|
+
handleUpdate(update: types.UpdateNewMessage | types.UpdateNewChannelMessage | types.UpdatePinnedDialogs | types.UpdateFolderPeers | types.UpdateChannel | types.UpdateChat | types.UpdateUser | types.UpdateUserName): Promise<void>;
|
|
15
|
+
getChat(chatId: ID): Promise<Chat>;
|
|
20
16
|
}
|
|
21
17
|
export {};
|