@mtkruto/node 0.1.140 → 0.1.142
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 +1 -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 +13 -1
- package/esm/client/2_message_manager.js +130 -29
- 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 +48 -0
- package/esm/client/4_client.d.ts +10 -10
- package/esm/client/4_client.js +128 -315
- 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 +1 -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 +13 -1
- package/script/client/2_message_manager.js +129 -28
- 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 +52 -0
- package/script/client/4_client.d.ts +10 -10
- package/script/client/4_client.js +126 -313
- 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
package/esm/4_constants.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export type PublicKeys = readonly [bigint, [bigint, bigint]][];
|
|
|
4
4
|
export declare const PUBLIC_KEYS: PublicKeys;
|
|
5
5
|
export declare const INITIAL_DC: DC;
|
|
6
6
|
export declare const LAYER = 169;
|
|
7
|
-
export declare const APP_VERSION = "MTKruto 0.1.
|
|
7
|
+
export declare const APP_VERSION = "MTKruto 0.1.142";
|
|
8
8
|
export declare const DEVICE_MODEL: string;
|
|
9
9
|
export declare const LANG_CODE: string;
|
|
10
10
|
export declare const LANG_PACK = "";
|
package/esm/4_constants.js
CHANGED
|
@@ -53,7 +53,7 @@ export const PUBLIC_KEYS = Object.freeze([
|
|
|
53
53
|
]);
|
|
54
54
|
export const INITIAL_DC = "2";
|
|
55
55
|
export const LAYER = 169;
|
|
56
|
-
export const APP_VERSION = "MTKruto 0.1.
|
|
56
|
+
export const APP_VERSION = "MTKruto 0.1.142";
|
|
57
57
|
// @ts-ignore: lib
|
|
58
58
|
export const DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
59
59
|
export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/esm/5_client.d.ts
CHANGED
package/esm/5_client.js
CHANGED
package/esm/client/0_types.d.ts
CHANGED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { enums, types } from "../2_tl.js";
|
|
2
|
+
import { Update } from "../3_types.js";
|
|
3
|
+
import { C } from "./0_types.js";
|
|
4
|
+
export declare class ReactionManager {
|
|
5
|
+
#private;
|
|
6
|
+
constructor(c: C);
|
|
7
|
+
static canHandleUpdate(update: enums.Update): update is types.UpdateBotMessageReactions | types.UpdateBotMessageReaction | types.UpdateMessageReactions | types.UpdateChannelMessageViews | types.UpdateChannelMessageForwards;
|
|
8
|
+
handleUpdate(update: types.UpdateBotMessageReactions | types.UpdateBotMessageReaction | types.UpdateMessageReactions | types.UpdateChannelMessageViews | types.UpdateChannelMessageForwards): Promise<Update | null>;
|
|
9
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
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 _ReactionManager_c;
|
|
13
|
+
import { UNREACHABLE } from "../1_utilities.js";
|
|
14
|
+
import { peerToChatId, types } from "../2_tl.js";
|
|
15
|
+
import { constructMessageReaction, constructMessageReactionCount, constructMessageReactions } from "../3_types.js";
|
|
16
|
+
export class ReactionManager {
|
|
17
|
+
constructor(c) {
|
|
18
|
+
_ReactionManager_c.set(this, void 0);
|
|
19
|
+
__classPrivateFieldSet(this, _ReactionManager_c, c, "f");
|
|
20
|
+
}
|
|
21
|
+
static canHandleUpdate(update) {
|
|
22
|
+
return update instanceof types.UpdateBotMessageReactions || update instanceof types.UpdateBotMessageReaction || update instanceof types.UpdateMessageReactions || update instanceof types.UpdateChannelMessageViews || update instanceof types.UpdateChannelMessageForwards;
|
|
23
|
+
}
|
|
24
|
+
async handleUpdate(update) {
|
|
25
|
+
if (update instanceof types.UpdateBotMessageReactions) {
|
|
26
|
+
const messageReactionCount = await constructMessageReactionCount(update, __classPrivateFieldGet(this, _ReactionManager_c, "f").getEntity);
|
|
27
|
+
if (messageReactionCount) {
|
|
28
|
+
return { messageReactionCount };
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
else if (update instanceof types.UpdateBotMessageReaction) {
|
|
35
|
+
const messageReactions = await constructMessageReactions(update, __classPrivateFieldGet(this, _ReactionManager_c, "f").getEntity);
|
|
36
|
+
if (messageReactions) {
|
|
37
|
+
return { messageReactions };
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else if (update instanceof types.UpdateMessageReactions) {
|
|
44
|
+
const chatId = peerToChatId(update.peer);
|
|
45
|
+
const message = await __classPrivateFieldGet(this, _ReactionManager_c, "f").storage.getMessage(chatId, update.msg_id);
|
|
46
|
+
if (message instanceof types.Message) {
|
|
47
|
+
message.reactions = update.reactions;
|
|
48
|
+
await __classPrivateFieldGet(this, _ReactionManager_c, "f").storage.setMessage(chatId, update.msg_id, message);
|
|
49
|
+
const views = message.views ?? 0;
|
|
50
|
+
const forwards = message.forwards ?? 0;
|
|
51
|
+
const recentReactions = update.reactions.recent_reactions ?? [];
|
|
52
|
+
const reactions = update.reactions.results.map((v) => constructMessageReaction(v, recentReactions));
|
|
53
|
+
return ({ messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } });
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (update instanceof types.UpdateChannelMessageViews || update instanceof types.UpdateChannelMessageForwards) {
|
|
60
|
+
const chatId = peerToChatId(new types.PeerChannel(update));
|
|
61
|
+
const message = await __classPrivateFieldGet(this, _ReactionManager_c, "f").storage.getMessage(chatId, update.id);
|
|
62
|
+
if (message instanceof types.Message) {
|
|
63
|
+
if ("views" in update) {
|
|
64
|
+
message.views = update.views;
|
|
65
|
+
}
|
|
66
|
+
if ("forwards" in update) {
|
|
67
|
+
message.forwards = update.forwards;
|
|
68
|
+
}
|
|
69
|
+
const views = message.views ?? 0;
|
|
70
|
+
const forwards = message.forwards ?? 0;
|
|
71
|
+
const recentReactions = message.reactions?.recent_reactions ?? [];
|
|
72
|
+
const reactions = message.reactions?.results.map((v) => constructMessageReaction(v, recentReactions)) ?? [];
|
|
73
|
+
return { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } };
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
UNREACHABLE();
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
_ReactionManager_c = new WeakMap();
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { enums, types } from "../2_tl.js";
|
|
2
|
-
import { FileSource, ID, Message } from "../3_types.js";
|
|
2
|
+
import { FileSource, ID, Message, MessageEntity, ParseMode, Reaction, Update, UsernameResolver } from "../3_types.js";
|
|
3
3
|
import { DeleteMessagesParams, EditMessageParams, EditMessageReplyMarkupParams, ForwardMessagesParams, GetHistoryParams, PinMessageParams, SendAnimationParams, SendAudioParams, SendContactParams, SendDiceParams, SendDocumentParams, SendLocationParams, SendMessageParams, SendPhotoParams, SendPollParams, SendVenueParams, SendVideoNoteParams, SendVideoParams, SendVoiceParams } from "./0_params.js";
|
|
4
|
+
import { AddReactionParams, SetReactionsParams } from "./0_params.js";
|
|
4
5
|
import { C as C_ } from "./0_types.js";
|
|
5
6
|
import { FileManager } from "./1_file_manager.js";
|
|
6
7
|
interface C extends C_ {
|
|
@@ -12,10 +13,15 @@ export declare class MessageManager {
|
|
|
12
13
|
getMessages(chatId: ID, messageIds: number[]): Promise<Message[]>;
|
|
13
14
|
getMessageWithReply(chatId: ID, messageId: number): Promise<Message>;
|
|
14
15
|
getMessage(chatId: ID, messageId: number): Promise<Message>;
|
|
16
|
+
parseText(text: string, params?: {
|
|
17
|
+
parseMode?: ParseMode;
|
|
18
|
+
entities?: MessageEntity[];
|
|
19
|
+
}): readonly [string, (import("../tl/2_types.js").MessageEntityMention_ | import("../tl/2_types.js").MessageEntityHashtag_ | import("../tl/2_types.js").MessageEntityBotCommand_ | import("../tl/2_types.js").MessageEntityUrl_ | import("../tl/2_types.js").MessageEntityEmail_ | import("../tl/2_types.js").MessageEntityBold_ | import("../tl/2_types.js").MessageEntityItalic_ | import("../tl/2_types.js").MessageEntityCode_ | import("../tl/2_types.js").MessageEntityPre_ | import("../tl/2_types.js").MessageEntityTextUrl_ | import("../tl/2_types.js").MessageEntityMentionName_ | import("../tl/2_types.js").MessageEntityPhone_ | import("../tl/2_types.js").MessageEntityCashtag_ | import("../tl/2_types.js").MessageEntityUnderline_ | import("../tl/2_types.js").MessageEntityStrike_ | import("../tl/2_types.js").MessageEntityBankCard_ | import("../tl/2_types.js").MessageEntitySpoiler_ | import("../tl/2_types.js").MessageEntityCustomEmoji_ | import("../tl/2_types.js").MessageEntityBlockquote_)[] | undefined];
|
|
15
20
|
getStickerSetName(inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
|
|
16
21
|
constructMessage(message_: enums.Message, r?: boolean): Promise<Message>;
|
|
17
22
|
forwardMessages(from: ID, to: ID, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
|
|
18
23
|
getHistory(chatId: ID, params?: GetHistoryParams): Promise<Message[]>;
|
|
24
|
+
usernameResolver: UsernameResolver;
|
|
19
25
|
sendMessage(chatId: ID, text: string, params?: SendMessageParams): Promise<import("../3_types.js").MessageText>;
|
|
20
26
|
sendVenue(chatId: ID, latitude: number, longitude: number, title: string, address: string, params?: SendVenueParams): Promise<import("../3_types.js").MessageVenue>;
|
|
21
27
|
sendContact(chatId: ID, firstName: string, number: string, params?: SendContactParams): Promise<import("../3_types.js").MessageContact>;
|
|
@@ -36,5 +42,11 @@ export declare class MessageManager {
|
|
|
36
42
|
pinMessage(chatId: ID, messageId: number, params?: PinMessageParams): Promise<void>;
|
|
37
43
|
unpinMessage(chatId: ID, messageId: number): Promise<void>;
|
|
38
44
|
unpinMessages(chatId: ID): Promise<void>;
|
|
45
|
+
setAvailableReactions(chatId: ID, availableReactions: "none" | "all" | Reaction[]): Promise<void>;
|
|
46
|
+
setReactions(chatId: number, messageId: number, reactions: Reaction[], params?: SetReactionsParams): Promise<void>;
|
|
47
|
+
addReaction(chatId: number, messageId: number, reaction: Reaction, params?: AddReactionParams): Promise<void>;
|
|
48
|
+
removeReaction(chatId: number, messageId: number, reaction: Reaction): Promise<void>;
|
|
49
|
+
static canHandleUpdate(update: enums.Update): update is types.UpdateNewMessage | types.UpdateNewChannelMessage | types.UpdateEditMessage | types.UpdateEditChannelMessage | types.UpdateDeleteMessages | types.UpdateDeleteChannelMessages;
|
|
50
|
+
handleUpdate(update: types.UpdateNewMessage | types.UpdateNewChannelMessage | types.UpdateEditMessage | types.UpdateEditChannelMessage | types.UpdateDeleteMessages | types.UpdateDeleteChannelMessages): Promise<Update | null>;
|
|
39
51
|
}
|
|
40
52
|
export {};
|
|
@@ -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,95 @@ 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;
|
|
490
518
|
}
|
|
491
|
-
break;
|
|
492
519
|
}
|
|
493
|
-
|
|
494
|
-
|
|
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));
|
|
542
|
+
}
|
|
543
|
+
}
|
|
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;
|
|
495
589
|
}
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
}, _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
|
|
590
|
+
}
|
|
591
|
+
_MessageManager_c = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
|
|
499
592
|
const messages = new Array();
|
|
500
593
|
if (updates instanceof types.Updates) {
|
|
501
594
|
for (const update of updates.updates) {
|
|
@@ -520,7 +613,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
520
613
|
}, _MessageManager_constructReplyMarkup = async function _MessageManager_constructReplyMarkup(params) {
|
|
521
614
|
if (params?.replyMarkup) {
|
|
522
615
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
523
|
-
return replyMarkupToTlObject(params.replyMarkup,
|
|
616
|
+
return replyMarkupToTlObject(params.replyMarkup, this.usernameResolver.bind(this));
|
|
524
617
|
}
|
|
525
618
|
}, _MessageManager_resolveSendAs = async function _MessageManager_resolveSendAs(params) {
|
|
526
619
|
const sendAs = params?.sendAs;
|
|
@@ -580,7 +673,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
580
673
|
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
581
674
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
582
675
|
const caption_ = params?.caption;
|
|
583
|
-
const parseResult = caption_ !== undefined ?
|
|
676
|
+
const parseResult = caption_ !== undefined ? this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
584
677
|
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
585
678
|
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
586
679
|
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendMedia({
|
|
@@ -618,4 +711,12 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
618
711
|
};
|
|
619
712
|
}
|
|
620
713
|
return null;
|
|
714
|
+
}, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) {
|
|
715
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendReaction({
|
|
716
|
+
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
717
|
+
msg_id: messageId,
|
|
718
|
+
reaction: reactions.map((v) => reactionToTlObject(v)),
|
|
719
|
+
big: params?.big ? true : undefined,
|
|
720
|
+
add_to_recent: params?.addToRecents ? true : undefined,
|
|
721
|
+
});
|
|
621
722
|
};
|
|
@@ -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(this)) };
|
|
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 {};
|