@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
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { base64DecodeUrlSafe, base64EncodeUrlSafe, rleDecode, rleEncode } from "../1_utilities.js";
|
|
2
|
+
import { TLReader, TLWriter } from "../2_tl.js";
|
|
3
|
+
export async function exportSessionString(client) {
|
|
4
|
+
const [dc, authKey] = await Promise.all([client.storage.getDc(), client.storage.getAuthKey()]);
|
|
5
|
+
if (dc == null || authKey == null) {
|
|
6
|
+
throw new Error("Client not authorized");
|
|
7
|
+
}
|
|
8
|
+
const writer = new TLWriter();
|
|
9
|
+
writer.writeString(dc);
|
|
10
|
+
writer.writeBytes(authKey);
|
|
11
|
+
const data = rleEncode(writer.buffer);
|
|
12
|
+
return base64EncodeUrlSafe(data);
|
|
13
|
+
}
|
|
14
|
+
export async function importSessionString(client, string) {
|
|
15
|
+
const data = rleDecode(base64DecodeUrlSafe(string));
|
|
16
|
+
const reader = new TLReader(data);
|
|
17
|
+
const dc = reader.readString();
|
|
18
|
+
const authKey = reader.readBytes();
|
|
19
|
+
await client.storage.initialize();
|
|
20
|
+
await client.storage.setDc(dc);
|
|
21
|
+
await client.storage.setAuthKey(authKey);
|
|
22
|
+
}
|
|
@@ -50,7 +50,7 @@ export class ConnectionWebSocket extends ConnectionUnframed {
|
|
|
50
50
|
try {
|
|
51
51
|
while (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState != dntShim.WebSocket.OPEN) {
|
|
52
52
|
if (__classPrivateFieldGet(this, _ConnectionWebSocket_webSocket, "f").readyState == dntShim.WebSocket.CLOSED) {
|
|
53
|
-
if (__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f")
|
|
53
|
+
if (__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f") && "message" in __classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f")) {
|
|
54
54
|
throw new Error(__classPrivateFieldGet(this, _ConnectionWebSocket_connectionError, "f").message);
|
|
55
55
|
}
|
|
56
56
|
else {
|
package/package.json
CHANGED
package/script/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/script/4_constants.js
CHANGED
|
@@ -79,7 +79,7 @@ exports.PUBLIC_KEYS = Object.freeze([
|
|
|
79
79
|
]);
|
|
80
80
|
exports.INITIAL_DC = "2";
|
|
81
81
|
exports.LAYER = 169;
|
|
82
|
-
exports.APP_VERSION = "MTKruto 0.1.
|
|
82
|
+
exports.APP_VERSION = "MTKruto 0.1.142";
|
|
83
83
|
// @ts-ignore: lib
|
|
84
84
|
exports.DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
|
|
85
85
|
exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
|
package/script/5_client.d.ts
CHANGED
package/script/5_client.js
CHANGED
|
@@ -18,3 +18,4 @@ __exportStar(require("./client/0_params.js"), exports);
|
|
|
18
18
|
__exportStar(require("./client/2_client_plain.js"), exports);
|
|
19
19
|
__exportStar(require("./client/4_client.js"), exports);
|
|
20
20
|
__exportStar(require("./client/5_composer.js"), exports);
|
|
21
|
+
__exportStar(require("./client/5_session_string.js"), exports);
|
|
@@ -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,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _ReactionManager_c;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.ReactionManager = void 0;
|
|
16
|
+
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
17
|
+
const _2_tl_js_1 = require("../2_tl.js");
|
|
18
|
+
const _3_types_js_1 = require("../3_types.js");
|
|
19
|
+
class ReactionManager {
|
|
20
|
+
constructor(c) {
|
|
21
|
+
_ReactionManager_c.set(this, void 0);
|
|
22
|
+
__classPrivateFieldSet(this, _ReactionManager_c, c, "f");
|
|
23
|
+
}
|
|
24
|
+
static canHandleUpdate(update) {
|
|
25
|
+
return update instanceof _2_tl_js_1.types.UpdateBotMessageReactions || update instanceof _2_tl_js_1.types.UpdateBotMessageReaction || update instanceof _2_tl_js_1.types.UpdateMessageReactions || update instanceof _2_tl_js_1.types.UpdateChannelMessageViews || update instanceof _2_tl_js_1.types.UpdateChannelMessageForwards;
|
|
26
|
+
}
|
|
27
|
+
async handleUpdate(update) {
|
|
28
|
+
if (update instanceof _2_tl_js_1.types.UpdateBotMessageReactions) {
|
|
29
|
+
const messageReactionCount = await (0, _3_types_js_1.constructMessageReactionCount)(update, __classPrivateFieldGet(this, _ReactionManager_c, "f").getEntity);
|
|
30
|
+
if (messageReactionCount) {
|
|
31
|
+
return { messageReactionCount };
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
else if (update instanceof _2_tl_js_1.types.UpdateBotMessageReaction) {
|
|
38
|
+
const messageReactions = await (0, _3_types_js_1.constructMessageReactions)(update, __classPrivateFieldGet(this, _ReactionManager_c, "f").getEntity);
|
|
39
|
+
if (messageReactions) {
|
|
40
|
+
return { messageReactions };
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
else if (update instanceof _2_tl_js_1.types.UpdateMessageReactions) {
|
|
47
|
+
const chatId = (0, _2_tl_js_1.peerToChatId)(update.peer);
|
|
48
|
+
const message = await __classPrivateFieldGet(this, _ReactionManager_c, "f").storage.getMessage(chatId, update.msg_id);
|
|
49
|
+
if (message instanceof _2_tl_js_1.types.Message) {
|
|
50
|
+
message.reactions = update.reactions;
|
|
51
|
+
await __classPrivateFieldGet(this, _ReactionManager_c, "f").storage.setMessage(chatId, update.msg_id, message);
|
|
52
|
+
const views = message.views ?? 0;
|
|
53
|
+
const forwards = message.forwards ?? 0;
|
|
54
|
+
const recentReactions = update.reactions.recent_reactions ?? [];
|
|
55
|
+
const reactions = update.reactions.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions));
|
|
56
|
+
return ({ messageInteractions: { chatId, messageId: update.msg_id, reactions, views, forwards } });
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
else if (update instanceof _2_tl_js_1.types.UpdateChannelMessageViews || update instanceof _2_tl_js_1.types.UpdateChannelMessageForwards) {
|
|
63
|
+
const chatId = (0, _2_tl_js_1.peerToChatId)(new _2_tl_js_1.types.PeerChannel(update));
|
|
64
|
+
const message = await __classPrivateFieldGet(this, _ReactionManager_c, "f").storage.getMessage(chatId, update.id);
|
|
65
|
+
if (message instanceof _2_tl_js_1.types.Message) {
|
|
66
|
+
if ("views" in update) {
|
|
67
|
+
message.views = update.views;
|
|
68
|
+
}
|
|
69
|
+
if ("forwards" in update) {
|
|
70
|
+
message.forwards = update.forwards;
|
|
71
|
+
}
|
|
72
|
+
const views = message.views ?? 0;
|
|
73
|
+
const forwards = message.forwards ?? 0;
|
|
74
|
+
const recentReactions = message.reactions?.recent_reactions ?? [];
|
|
75
|
+
const reactions = message.reactions?.results.map((v) => (0, _3_types_js_1.constructMessageReaction)(v, recentReactions)) ?? [];
|
|
76
|
+
return { messageInteractions: { chatId, messageId: update.id, reactions, views, forwards } };
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
exports.ReactionManager = ReactionManager;
|
|
88
|
+
_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 {};
|
|
@@ -10,7 +10,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
10
10
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
11
|
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
12
|
};
|
|
13
|
-
var _MessageManager_instances, _MessageManager_c,
|
|
13
|
+
var _MessageManager_instances, _MessageManager_c, _MessageManager_updatesToMessages, _MessageManager_constructReplyMarkup, _MessageManager_resolveSendAs, _MessageManager_constructReplyTo, _MessageManager_sendDocumentInner, _MessageManager_sendMedia, _MessageManager_resolveFileId, _MessageManager_sendReaction;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.MessageManager = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
@@ -25,9 +25,14 @@ class MessageManager {
|
|
|
25
25
|
constructor(c) {
|
|
26
26
|
_MessageManager_instances.add(this);
|
|
27
27
|
_MessageManager_c.set(this, void 0);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
Object.defineProperty(this, "usernameResolver", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: async (v) => {
|
|
33
|
+
const inputPeer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(v).then((v) => v[_2_tl_js_1.as](_2_tl_js_1.types.InputPeerUser));
|
|
34
|
+
return new _2_tl_js_1.types.InputUser(inputPeer);
|
|
35
|
+
}
|
|
31
36
|
});
|
|
32
37
|
__classPrivateFieldSet(this, _MessageManager_c, c, "f");
|
|
33
38
|
}
|
|
@@ -81,6 +86,26 @@ class MessageManager {
|
|
|
81
86
|
const messages = await this.getMessages(chatId, [messageId]);
|
|
82
87
|
return messages[0] ?? null;
|
|
83
88
|
}
|
|
89
|
+
parseText(text, params) {
|
|
90
|
+
const entities_ = params?.entities ?? [];
|
|
91
|
+
const parseMode = params?.parseMode ?? __classPrivateFieldGet(this, _MessageManager_c, "f").parseMode;
|
|
92
|
+
switch (parseMode) {
|
|
93
|
+
case null:
|
|
94
|
+
break;
|
|
95
|
+
case "HTML": {
|
|
96
|
+
const [newText, entitiesToPush] = (0, _0_html_js_1.parseHtml)(text);
|
|
97
|
+
text = newText;
|
|
98
|
+
for (const entity of entitiesToPush) {
|
|
99
|
+
entities_.push(entity);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
default:
|
|
104
|
+
(0, _1_utilities_js_1.UNREACHABLE)();
|
|
105
|
+
}
|
|
106
|
+
const entities = entities_?.length > 0 ? entities_.map((v) => (0, _3_types_js_1.messageEntityToTlObject)(v)) : undefined;
|
|
107
|
+
return [text, entities];
|
|
108
|
+
}
|
|
84
109
|
async getStickerSetName(inputStickerSet, hash = 0) {
|
|
85
110
|
const maybeStickerSetName = await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getStickerSetName(inputStickerSet.id, inputStickerSet.access_hash);
|
|
86
111
|
if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < _4_constants_js_1.STICKER_SET_NAME_TTL) {
|
|
@@ -155,7 +180,7 @@ class MessageManager {
|
|
|
155
180
|
return messages;
|
|
156
181
|
}
|
|
157
182
|
async sendMessage(chatId, text, params) {
|
|
158
|
-
const [message, entities] =
|
|
183
|
+
const [message, entities] = this.parseText(text, params);
|
|
159
184
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
160
185
|
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
161
186
|
const randomId = (0, _1_utilities_js_1.getRandomId)();
|
|
@@ -386,7 +411,7 @@ class MessageManager {
|
|
|
386
411
|
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
387
412
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
388
413
|
const explanation = params?.explanation;
|
|
389
|
-
const parseResult = explanation !== undefined ?
|
|
414
|
+
const parseResult = explanation !== undefined ? this.parseText(explanation, { parseMode: params?.explanationParseMode, entities: params?.explanationEntities }) : undefined;
|
|
390
415
|
const solution = parseResult === undefined ? undefined : parseResult[0];
|
|
391
416
|
const solutionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
392
417
|
const answers = options.map((v, i) => new _2_tl_js_1.types.PollAnswer({ option: new Uint8Array([i]), text: v }));
|
|
@@ -431,7 +456,7 @@ class MessageManager {
|
|
|
431
456
|
return message_;
|
|
432
457
|
}
|
|
433
458
|
async editMessageText(chatId, messageId, text, params) {
|
|
434
|
-
const [message, entities] =
|
|
459
|
+
const [message, entities] = this.parseText(text, params);
|
|
435
460
|
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({
|
|
436
461
|
id: messageId,
|
|
437
462
|
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
@@ -478,28 +503,96 @@ class MessageManager {
|
|
|
478
503
|
async unpinMessages(chatId) {
|
|
479
504
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.unpinAllMessages({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId) });
|
|
480
505
|
}
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
506
|
+
async setAvailableReactions(chatId, availableReactions) {
|
|
507
|
+
// TODO: sync with storage
|
|
508
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.setChatAvailableReactions({
|
|
509
|
+
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
510
|
+
available_reactions: availableReactions == "none" ? new _2_tl_js_1.types.ChatReactionsNone() : availableReactions == "all" ? new _2_tl_js_1.types.ChatReactionsAll() : Array.isArray(availableReactions) ? new _2_tl_js_1.types.ChatReactionsSome({ reactions: availableReactions.map((v) => v.type == "emoji" ? new _2_tl_js_1.types.ReactionEmoji({ emoticon: v.emoji }) : new _2_tl_js_1.types.ReactionCustomEmoji({ document_id: BigInt(v.id) })) }) : (0, _1_utilities_js_1.UNREACHABLE)(),
|
|
511
|
+
});
|
|
512
|
+
}
|
|
513
|
+
async setReactions(chatId, messageId, reactions, params) {
|
|
514
|
+
await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_sendReaction).call(this, chatId, messageId, reactions, params);
|
|
515
|
+
}
|
|
516
|
+
async addReaction(chatId, messageId, reaction, params) {
|
|
517
|
+
const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
|
|
518
|
+
for (const r of chosenReactions) {
|
|
519
|
+
if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
|
|
520
|
+
return;
|
|
494
521
|
}
|
|
495
|
-
break;
|
|
496
522
|
}
|
|
497
|
-
|
|
498
|
-
|
|
523
|
+
const reactions = [reaction, ...chosenReactions.map((v) => v.reaction)];
|
|
524
|
+
await this.setReactions(chatId, messageId, reactions, params);
|
|
525
|
+
}
|
|
526
|
+
async removeReaction(chatId, messageId, reaction) {
|
|
527
|
+
const chosenReactions = await this.getMessage(chatId, messageId).then((v) => v?.reactions ?? []).then((v) => v.filter((v) => v.chosen));
|
|
528
|
+
for (const r of chosenReactions) {
|
|
529
|
+
if ((0, _3_types_js_1.reactionEqual)(r.reaction, reaction)) {
|
|
530
|
+
const reactions = chosenReactions.filter((v) => v != r).map((v) => v.reaction);
|
|
531
|
+
await this.setReactions(chatId, messageId, reactions);
|
|
532
|
+
break;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
static canHandleUpdate(update) {
|
|
537
|
+
return update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage || update instanceof _2_tl_js_1.types.UpdateDeleteMessages || update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages;
|
|
499
538
|
}
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
539
|
+
async handleUpdate(update) {
|
|
540
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateEditMessage || update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
541
|
+
if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
|
|
542
|
+
const chatId = (0, _2_tl_js_1.peerToChatId)(update.message.peer_id);
|
|
543
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.setMessage(chatId, update.message.id, update.message);
|
|
544
|
+
// promises.push(this.#chatListManager.reassignChatLastMessage(chatId));
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage ||
|
|
548
|
+
update instanceof _2_tl_js_1.types.UpdateNewChannelMessage ||
|
|
549
|
+
update instanceof _2_tl_js_1.types.UpdateEditMessage ||
|
|
550
|
+
update instanceof _2_tl_js_1.types.UpdateEditChannelMessage) {
|
|
551
|
+
if (!(update.message instanceof _2_tl_js_1.types.MessageEmpty)) {
|
|
552
|
+
const isOutgoing = update.message.out;
|
|
553
|
+
let shouldIgnore = isOutgoing ? (await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getAccountType()) == "user" ? false : true : false;
|
|
554
|
+
if (__classPrivateFieldGet(this, _MessageManager_c, "f").ignoreOutgoing != null && isOutgoing) {
|
|
555
|
+
shouldIgnore = __classPrivateFieldGet(this, _MessageManager_c, "f").ignoreOutgoing;
|
|
556
|
+
}
|
|
557
|
+
if (!shouldIgnore) {
|
|
558
|
+
const message = await this.constructMessage(update.message);
|
|
559
|
+
if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
|
|
560
|
+
return ({ message });
|
|
561
|
+
}
|
|
562
|
+
else {
|
|
563
|
+
return ({ editedMessage: message });
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (update instanceof _2_tl_js_1.types.UpdateDeleteMessages) {
|
|
569
|
+
const deletedMessages = new Array();
|
|
570
|
+
for (const messageId of update.messages) {
|
|
571
|
+
const chatId = await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getMessageChat(messageId);
|
|
572
|
+
if (chatId) {
|
|
573
|
+
deletedMessages.push({ chatId, messageId });
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (deletedMessages.length > 0) {
|
|
577
|
+
return { deletedMessages };
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
else if (update instanceof _2_tl_js_1.types.UpdateDeleteChannelMessages) {
|
|
581
|
+
const chatId = (0, _2_tl_js_1.getChannelChatId)(update.channel_id);
|
|
582
|
+
const deletedMessages = new Array();
|
|
583
|
+
for (const messageId of update.messages) {
|
|
584
|
+
const message = await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.getMessage(chatId, messageId);
|
|
585
|
+
if (message != null) {
|
|
586
|
+
deletedMessages.push({ chatId, messageId });
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
return { deletedMessages };
|
|
590
|
+
}
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
exports.MessageManager = MessageManager;
|
|
595
|
+
_MessageManager_c = new WeakMap(), _MessageManager_instances = new WeakSet(), _MessageManager_updatesToMessages = async function _MessageManager_updatesToMessages(chatId, updates) {
|
|
503
596
|
const messages = new Array();
|
|
504
597
|
if (updates instanceof _2_tl_js_1.types.Updates) {
|
|
505
598
|
for (const update of updates.updates) {
|
|
@@ -524,7 +617,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
524
617
|
}, _MessageManager_constructReplyMarkup = async function _MessageManager_constructReplyMarkup(params) {
|
|
525
618
|
if (params?.replyMarkup) {
|
|
526
619
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertBot("replyMarkup");
|
|
527
|
-
return (0, _3_types_js_1.replyMarkupToTlObject)(params.replyMarkup,
|
|
620
|
+
return (0, _3_types_js_1.replyMarkupToTlObject)(params.replyMarkup, this.usernameResolver.bind(this));
|
|
528
621
|
}
|
|
529
622
|
}, _MessageManager_resolveSendAs = async function _MessageManager_resolveSendAs(params) {
|
|
530
623
|
const sendAs = params?.sendAs;
|
|
@@ -584,7 +677,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
584
677
|
const sendAs = params?.sendAs ? await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(params.sendAs) : undefined; // TODO: check default sendAs
|
|
585
678
|
const replyMarkup = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params);
|
|
586
679
|
const caption_ = params?.caption;
|
|
587
|
-
const parseResult = caption_ !== undefined ?
|
|
680
|
+
const parseResult = caption_ !== undefined ? this.parseText(caption_, { parseMode: params?.parseMode, entities: params?.captionEntities }) : undefined;
|
|
588
681
|
const caption = parseResult === undefined ? undefined : parseResult[0];
|
|
589
682
|
const captionEntities = parseResult === undefined ? undefined : parseResult[1];
|
|
590
683
|
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendMedia({
|
|
@@ -622,4 +715,12 @@ _MessageManager_c = new WeakMap(), _MessageManager_usernameResolver = new WeakMa
|
|
|
622
715
|
};
|
|
623
716
|
}
|
|
624
717
|
return null;
|
|
718
|
+
}, _MessageManager_sendReaction = async function _MessageManager_sendReaction(chatId, messageId, reactions, params) {
|
|
719
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.sendReaction({
|
|
720
|
+
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
721
|
+
msg_id: messageId,
|
|
722
|
+
reaction: reactions.map((v) => (0, _3_types_js_1.reactionToTlObject)(v)),
|
|
723
|
+
big: params?.big ? true : undefined,
|
|
724
|
+
add_to_recent: params?.addToRecents ? true : undefined,
|
|
725
|
+
});
|
|
625
726
|
};
|
|
@@ -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,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
3
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
4
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
5
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
6
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
7
|
+
};
|
|
8
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
10
|
+
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
11
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
12
|
+
};
|
|
13
|
+
var _CallbackQueryManager_c;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.CallbackQueryManager = void 0;
|
|
16
|
+
const _2_tl_js_1 = require("../2_tl.js");
|
|
17
|
+
const _3_types_js_1 = require("../3_types.js");
|
|
18
|
+
class CallbackQueryManager {
|
|
19
|
+
constructor(c) {
|
|
20
|
+
_CallbackQueryManager_c.set(this, void 0);
|
|
21
|
+
__classPrivateFieldSet(this, _CallbackQueryManager_c, c, "f");
|
|
22
|
+
}
|
|
23
|
+
async answerCallbackQuery(id, params) {
|
|
24
|
+
await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").storage.assertBot("answerCallbackQuery");
|
|
25
|
+
await __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").api.messages.setBotCallbackAnswer({
|
|
26
|
+
query_id: BigInt(id),
|
|
27
|
+
cache_time: params?.cacheTime ?? 0,
|
|
28
|
+
message: params?.text,
|
|
29
|
+
alert: params?.alert ? true : undefined,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
static canHandleUpdate(update) {
|
|
33
|
+
return update instanceof _2_tl_js_1.types.UpdateBotCallbackQuery || update instanceof _2_tl_js_1.types.UpdateInlineBotCallbackQuery;
|
|
34
|
+
}
|
|
35
|
+
async handleUpdate(update) {
|
|
36
|
+
return { callbackQuery: await (0, _3_types_js_1.constructCallbackQuery)(update, __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").getEntity, __classPrivateFieldGet(this, _CallbackQueryManager_c, "f").messageManager.getMessageWithReply.bind(this)) };
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
exports.CallbackQueryManager = CallbackQueryManager;
|
|
40
|
+
_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 {};
|