@mtkruto/node 0.77.2 → 0.78.1
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/0_errors.d.ts +1 -0
- package/esm/0_errors.d.ts.map +1 -1
- package/esm/0_errors.js +5 -0
- package/esm/3_errors.d.ts +6 -0
- package/esm/3_errors.d.ts.map +1 -1
- package/esm/3_errors.js +6 -0
- package/esm/3_types.d.ts +3 -0
- package/esm/3_types.d.ts.map +1 -1
- package/esm/3_types.js +3 -0
- package/esm/4_constants.d.ts +1 -0
- package/esm/4_constants.d.ts.map +1 -1
- package/esm/4_constants.js +2 -0
- package/esm/5_client.d.ts +6 -1
- package/esm/5_client.d.ts.map +1 -1
- package/esm/5_client.js +6 -1
- package/esm/_dnt.polyfills.d.ts +13 -13
- package/esm/_dnt.polyfills.d.ts.map +1 -1
- package/esm/_dnt.polyfills.js +11 -11
- package/esm/client/0_worker_request.d.ts +26 -0
- package/esm/client/0_worker_request.d.ts.map +1 -0
- package/esm/client/0_worker_request.js +20 -0
- package/esm/client/0_worker_response.d.ts +39 -0
- package/esm/client/0_worker_response.d.ts.map +1 -0
- package/esm/client/0_worker_response.js +20 -0
- package/esm/client/1_client_generic.d.ts +1602 -0
- package/esm/client/1_client_generic.d.ts.map +1 -0
- package/esm/client/1_client_generic.js +24 -0
- package/esm/client/2_account_manager.d.ts +6 -1
- package/esm/client/2_account_manager.d.ts.map +1 -1
- package/esm/client/2_account_manager.js +84 -0
- package/esm/client/2_context.d.ts +114 -0
- package/esm/client/2_context.d.ts.map +1 -0
- package/esm/client/2_context.js +453 -0
- package/esm/client/2_file_manager.d.ts.map +1 -1
- package/esm/client/2_file_manager.js +13 -6
- package/esm/client/2_sign_in.d.ts +25 -0
- package/esm/client/2_sign_in.d.ts.map +1 -0
- package/esm/client/2_sign_in.js +114 -0
- package/esm/client/{0_filters.d.ts → 3_filters.d.ts} +6 -3
- package/esm/client/3_filters.d.ts.map +1 -0
- package/esm/client/3_filters_test.d.ts.map +1 -0
- package/esm/client/{1_composer.d.ts → 4_composer.d.ts} +12 -11
- package/esm/client/4_composer.d.ts.map +1 -0
- package/esm/client/{1_composer.js → 4_composer.js} +17 -7
- package/esm/client/4_composer_test.d.ts.map +1 -0
- package/esm/client/5_client.d.ts +43 -179
- package/esm/client/5_client.d.ts.map +1 -1
- package/esm/client/5_client.js +141 -595
- package/esm/client/5_client_dispatcher.d.ts +1660 -0
- package/esm/client/5_client_dispatcher.d.ts.map +1 -0
- package/esm/client/5_client_dispatcher.js +2141 -0
- package/esm/client/6_client_worker.d.ts +27 -0
- package/esm/client/6_client_worker.d.ts.map +1 -0
- package/esm/client/6_client_worker.js +51 -0
- package/esm/types/0_bot_token_check_result.d.ts +29 -0
- package/esm/types/0_bot_token_check_result.d.ts.map +1 -0
- package/esm/types/0_bot_token_check_result.js +20 -0
- package/esm/types/0_code_check_result.d.ts +37 -0
- package/esm/types/0_code_check_result.d.ts.map +1 -0
- package/esm/types/0_code_check_result.js +20 -0
- package/esm/types/0_password_check_result.d.ts +33 -0
- package/esm/types/0_password_check_result.d.ts.map +1 -0
- package/esm/types/0_password_check_result.js +20 -0
- package/esm/types/1_chat_p.d.ts.map +1 -1
- package/esm/types/1_chat_p.js +2 -2
- package/esm/types/2_chat.d.ts +3 -3
- package/esm/types/2_chat.d.ts.map +1 -1
- package/package.json +1 -1
- package/script/0_errors.d.ts +1 -0
- package/script/0_errors.d.ts.map +1 -1
- package/script/0_errors.js +5 -0
- package/script/3_errors.d.ts +6 -0
- package/script/3_errors.d.ts.map +1 -1
- package/script/3_errors.js +11 -3
- package/script/3_types.d.ts +3 -0
- package/script/3_types.d.ts.map +1 -1
- package/script/3_types.js +3 -0
- package/script/4_constants.d.ts +1 -0
- package/script/4_constants.d.ts.map +1 -1
- package/script/4_constants.js +3 -1
- package/script/5_client.d.ts +6 -1
- package/script/5_client.d.ts.map +1 -1
- package/script/5_client.js +6 -1
- package/script/_dnt.polyfills.d.ts +13 -13
- package/script/_dnt.polyfills.d.ts.map +1 -1
- package/script/_dnt.polyfills.js +11 -11
- package/script/client/0_worker_request.d.ts +26 -0
- package/script/client/0_worker_request.d.ts.map +1 -0
- package/script/client/0_worker_request.js +21 -0
- package/script/client/0_worker_response.d.ts +39 -0
- package/script/client/0_worker_response.d.ts.map +1 -0
- package/script/client/0_worker_response.js +21 -0
- package/script/client/1_client_generic.d.ts +1602 -0
- package/script/client/1_client_generic.d.ts.map +1 -0
- package/script/client/1_client_generic.js +28 -0
- package/script/client/2_account_manager.d.ts +6 -1
- package/script/client/2_account_manager.d.ts.map +1 -1
- package/script/client/2_account_manager.js +84 -0
- package/script/client/2_context.d.ts +114 -0
- package/script/client/2_context.d.ts.map +1 -0
- package/script/client/2_context.js +457 -0
- package/script/client/2_file_manager.d.ts.map +1 -1
- package/script/client/2_file_manager.js +11 -4
- package/script/client/2_sign_in.d.ts +25 -0
- package/script/client/2_sign_in.d.ts.map +1 -0
- package/script/client/2_sign_in.js +118 -0
- package/script/client/{0_filters.d.ts → 3_filters.d.ts} +6 -3
- package/script/client/3_filters.d.ts.map +1 -0
- package/script/client/3_filters_test.d.ts.map +1 -0
- package/script/client/{1_composer.d.ts → 4_composer.d.ts} +12 -11
- package/script/client/4_composer.d.ts.map +1 -0
- package/script/client/{1_composer.js → 4_composer.js} +17 -7
- package/script/client/4_composer_test.d.ts.map +1 -0
- package/script/client/5_client.d.ts +43 -179
- package/script/client/5_client.d.ts.map +1 -1
- package/script/client/5_client.js +140 -594
- package/script/client/5_client_dispatcher.d.ts +1660 -0
- package/script/client/5_client_dispatcher.d.ts.map +1 -0
- package/script/client/5_client_dispatcher.js +2178 -0
- package/script/client/6_client_worker.d.ts +27 -0
- package/script/client/6_client_worker.d.ts.map +1 -0
- package/script/client/6_client_worker.js +55 -0
- package/script/types/0_bot_token_check_result.d.ts +29 -0
- package/script/types/0_bot_token_check_result.d.ts.map +1 -0
- package/script/types/0_bot_token_check_result.js +21 -0
- package/script/types/0_code_check_result.d.ts +37 -0
- package/script/types/0_code_check_result.d.ts.map +1 -0
- package/script/types/0_code_check_result.js +21 -0
- package/script/types/0_password_check_result.d.ts +33 -0
- package/script/types/0_password_check_result.d.ts.map +1 -0
- package/script/types/0_password_check_result.js +21 -0
- package/script/types/1_chat_p.d.ts.map +1 -1
- package/script/types/1_chat_p.js +2 -2
- package/script/types/2_chat.d.ts +3 -3
- package/script/types/2_chat.d.ts.map +1 -1
- package/esm/client/0_filters.d.ts.map +0 -1
- package/esm/client/0_filters_test.d.ts.map +0 -1
- package/esm/client/1_composer.d.ts.map +0 -1
- package/script/client/0_filters.d.ts.map +0 -1
- package/script/client/0_filters_test.d.ts.map +0 -1
- package/script/client/1_composer.d.ts.map +0 -1
- /package/esm/client/{0_filters.js → 3_filters.js} +0 -0
- /package/script/client/{0_filters.js → 3_filters.js} +0 -0
|
@@ -0,0 +1,457 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.Context = void 0;
|
|
23
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
24
|
+
const _2_tl_js_1 = require("../2_tl.js");
|
|
25
|
+
class Context {
|
|
26
|
+
#client;
|
|
27
|
+
#me;
|
|
28
|
+
#update;
|
|
29
|
+
constructor(client, me, update) {
|
|
30
|
+
this.#client = client;
|
|
31
|
+
this.#me = me;
|
|
32
|
+
this.#update = update;
|
|
33
|
+
}
|
|
34
|
+
get update() {
|
|
35
|
+
return this.#update;
|
|
36
|
+
}
|
|
37
|
+
get me() {
|
|
38
|
+
return this.#me;
|
|
39
|
+
}
|
|
40
|
+
get client() {
|
|
41
|
+
return this.#client;
|
|
42
|
+
}
|
|
43
|
+
get msg() {
|
|
44
|
+
return "message" in this.update ? this.update.message : "editedMessage" in this.update ? this.update.editedMessage : "scheduledMessage" in this.update ? this.update.scheduledMessage : "callbackQuery" in this.update ? this.update.callbackQuery.message : undefined;
|
|
45
|
+
}
|
|
46
|
+
#mustGetMsg() {
|
|
47
|
+
if (this.msg !== undefined) {
|
|
48
|
+
return { chatId: this.msg.chat.id, messageId: this.msg.id, businessConnectionId: this.msg.businessConnectionId, senderId: this.msg.from?.id, userId: this.msg.from?.id };
|
|
49
|
+
}
|
|
50
|
+
const reactions = "messageInteractions" in this.update ? this.update.messageInteractions : undefined;
|
|
51
|
+
if (reactions !== undefined) {
|
|
52
|
+
return { chatId: reactions.chatId, messageId: reactions.messageId };
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
(0, _0_deps_js_1.unreachable)();
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
#mustGetChatId() {
|
|
59
|
+
if (this.chat) {
|
|
60
|
+
return this.chat.id;
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
(0, _0_deps_js_1.unreachable)();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
#mustGetUserId() {
|
|
67
|
+
if (this.msg?.from) {
|
|
68
|
+
return this.msg.from.id;
|
|
69
|
+
}
|
|
70
|
+
else if ("callbackQuery" in this.update) {
|
|
71
|
+
return this.update.callbackQuery.from.id;
|
|
72
|
+
}
|
|
73
|
+
else if ("chosenInlineResult" in this.update) {
|
|
74
|
+
return this.update.chosenInlineResult.from.id;
|
|
75
|
+
}
|
|
76
|
+
else {
|
|
77
|
+
(0, _0_deps_js_1.unreachable)();
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
#mustGetInlineMsgId() {
|
|
81
|
+
if ("chosenInlineResult" in this.update) {
|
|
82
|
+
if (this.update.chosenInlineResult.inlineMessageId) {
|
|
83
|
+
return this.update.chosenInlineResult.inlineMessageId;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
else if ("callbackQuery" in this.update) {
|
|
87
|
+
if (this.update.callbackQuery.inlineMessageId) {
|
|
88
|
+
return this.update.callbackQuery.inlineMessageId;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
(0, _0_deps_js_1.unreachable)();
|
|
92
|
+
}
|
|
93
|
+
#getReplyTo = (quote, chatId, messageId) => {
|
|
94
|
+
if ("story" in this.update) {
|
|
95
|
+
return { chatId: this.update.story.chat.id, storyId: this.update.story.id };
|
|
96
|
+
}
|
|
97
|
+
const isPrivate = chatId > 0;
|
|
98
|
+
const shouldQuote = quote === undefined ? !isPrivate : quote;
|
|
99
|
+
return shouldQuote ? { messageId } : undefined;
|
|
100
|
+
};
|
|
101
|
+
get chat() {
|
|
102
|
+
return this.msg?.chat ?? ("messageReactions" in this.update ? this.update.messageReactions.chat : "messageReactionCount" in this.update ? this.update.messageReactionCount.chat : "chatMember" in this.update ? this.update.chatMember.chat : "myChatMember" in this.update ? this.update.myChatMember.chat : "joinRequest" in this.update ? this.update.joinRequest.chat : "story" in this.update ? this.update.story.chat : undefined);
|
|
103
|
+
}
|
|
104
|
+
get from() {
|
|
105
|
+
const from = "callbackQuery" in this.update ? this.update.callbackQuery.from : "inlineQuery" in this.update ? this.update.inlineQuery.from : "chatMember" in this.update ? this.update.chatMember.from : "myChatMember" in this.update ? this.update.myChatMember.from : "messageReactions" in this.update ? this.update.messageReactions.user : "preCheckoutQuery" in this.update ? this.update.preCheckoutQuery.from : "joinRequest" in this.update ? this.update.joinRequest.from : "businessConnection" in this.update ? this.update.businessConnection.user : "pollAnswer" in this.update ? this.update.pollAnswer.from : this.msg?.from;
|
|
106
|
+
return from;
|
|
107
|
+
}
|
|
108
|
+
toJSON() {
|
|
109
|
+
if ("update" in this.update) {
|
|
110
|
+
return { update: (0, _2_tl_js_1.toJSON)(this.update.update) };
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
return this.update;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
async reply(text, params) {
|
|
117
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
118
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
119
|
+
return await this.client.sendMessage(chatId, text, { ...params, replyTo, businessConnectionId });
|
|
120
|
+
}
|
|
121
|
+
async replyPoll(question, options, params) {
|
|
122
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
123
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
124
|
+
return await this.client.sendPoll(chatId, question, options, { ...params, replyTo, businessConnectionId });
|
|
125
|
+
}
|
|
126
|
+
async replyPhoto(photo, params) {
|
|
127
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
128
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
129
|
+
return await this.client.sendPhoto(chatId, photo, { ...params, replyTo, businessConnectionId });
|
|
130
|
+
}
|
|
131
|
+
async replyMediaGroup(media, params) {
|
|
132
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
133
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
134
|
+
return await this.client.sendMediaGroup(chatId, media, { ...params, replyTo, businessConnectionId });
|
|
135
|
+
}
|
|
136
|
+
async replyInvoice(title, description, payload, currency, prices, params) {
|
|
137
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
138
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
139
|
+
return await this.client.sendInvoice(chatId, title, description, payload, currency, prices, { ...params, replyTo, businessConnectionId });
|
|
140
|
+
}
|
|
141
|
+
async replyDocument(document, params) {
|
|
142
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
143
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
144
|
+
return await this.client.sendDocument(chatId, document, { ...params, replyTo, businessConnectionId });
|
|
145
|
+
}
|
|
146
|
+
async replySticker(sticker, params) {
|
|
147
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
148
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
149
|
+
return await this.client.sendSticker(chatId, sticker, { ...params, replyTo, businessConnectionId });
|
|
150
|
+
}
|
|
151
|
+
async replyLocation(latitude, longitude, params) {
|
|
152
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
153
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
154
|
+
return await this.client.sendLocation(chatId, latitude, longitude, { ...params, replyTo, businessConnectionId });
|
|
155
|
+
}
|
|
156
|
+
async replyDice(params) {
|
|
157
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
158
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
159
|
+
return await this.client.sendDice(chatId, { ...params, replyTo, businessConnectionId });
|
|
160
|
+
}
|
|
161
|
+
async replyVenue(latitude, longitude, title, address, params) {
|
|
162
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
163
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
164
|
+
return await this.client.sendVenue(chatId, latitude, longitude, title, address, { ...params, replyTo, businessConnectionId });
|
|
165
|
+
}
|
|
166
|
+
async replyContact(firstName, number, params) {
|
|
167
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
168
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
169
|
+
return await this.client.sendContact(chatId, firstName, number, { ...params, replyTo, businessConnectionId });
|
|
170
|
+
}
|
|
171
|
+
async replyVideo(video, params) {
|
|
172
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
173
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
174
|
+
return await this.client.sendVideo(chatId, video, { ...params, replyTo, businessConnectionId });
|
|
175
|
+
}
|
|
176
|
+
async replyAnimation(animation, params) {
|
|
177
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
178
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
179
|
+
return await this.client.sendAnimation(chatId, animation, { ...params, replyTo, businessConnectionId });
|
|
180
|
+
}
|
|
181
|
+
async replyVoice(voice, params) {
|
|
182
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
183
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
184
|
+
return await this.client.sendVoice(chatId, voice, { ...params, replyTo, businessConnectionId });
|
|
185
|
+
}
|
|
186
|
+
async replyAudio(audio, params) {
|
|
187
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
188
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
189
|
+
return await this.client.sendAudio(chatId, audio, { ...params, replyTo, businessConnectionId });
|
|
190
|
+
}
|
|
191
|
+
async replyVideoNote(videoNote, params) {
|
|
192
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
193
|
+
const replyTo = this.#getReplyTo(params?.quote, chatId, messageId);
|
|
194
|
+
return await this.client.sendVideoNote(chatId, videoNote, { ...params, replyTo, businessConnectionId });
|
|
195
|
+
}
|
|
196
|
+
async delete() {
|
|
197
|
+
const { chatId, messageId } = this.#mustGetMsg();
|
|
198
|
+
return await this.client.deleteMessage(chatId, messageId);
|
|
199
|
+
}
|
|
200
|
+
async forward(to, params) {
|
|
201
|
+
const { chatId, messageId } = this.#mustGetMsg();
|
|
202
|
+
return await this.client.forwardMessage(chatId, to, messageId, params);
|
|
203
|
+
}
|
|
204
|
+
async pin(params) {
|
|
205
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
206
|
+
return await this.client.pinMessage(chatId, messageId, { ...params, businessConnectionId });
|
|
207
|
+
}
|
|
208
|
+
async unpin() {
|
|
209
|
+
const { chatId, messageId, businessConnectionId } = this.#mustGetMsg();
|
|
210
|
+
return await this.client.unpinMessage(chatId, messageId, { businessConnectionId });
|
|
211
|
+
}
|
|
212
|
+
async banSender(params) {
|
|
213
|
+
const { chatId, senderId } = this.#mustGetMsg();
|
|
214
|
+
if (!senderId) {
|
|
215
|
+
(0, _0_deps_js_1.unreachable)();
|
|
216
|
+
}
|
|
217
|
+
return await this.client.banChatMember(chatId, senderId, params);
|
|
218
|
+
}
|
|
219
|
+
async kickSender() {
|
|
220
|
+
const { chatId, senderId } = this.#mustGetMsg();
|
|
221
|
+
if (!senderId) {
|
|
222
|
+
(0, _0_deps_js_1.unreachable)();
|
|
223
|
+
}
|
|
224
|
+
return await this.client.kickChatMember(chatId, senderId);
|
|
225
|
+
}
|
|
226
|
+
async setSenderRights(params) {
|
|
227
|
+
const { chatId, senderId } = this.#mustGetMsg();
|
|
228
|
+
if (!senderId) {
|
|
229
|
+
(0, _0_deps_js_1.unreachable)();
|
|
230
|
+
}
|
|
231
|
+
return await this.client.setChatMemberRights(chatId, senderId, params);
|
|
232
|
+
}
|
|
233
|
+
async getChatAdministrators() {
|
|
234
|
+
const chatId = this.#mustGetChatId();
|
|
235
|
+
return await this.client.getChatAdministrators(chatId);
|
|
236
|
+
}
|
|
237
|
+
async react(reactions, params) {
|
|
238
|
+
const { chatId, messageId } = this.#mustGetMsg();
|
|
239
|
+
return await this.client.setReactions(chatId, messageId, reactions, params);
|
|
240
|
+
}
|
|
241
|
+
async sendChatAction(action, params) {
|
|
242
|
+
const chatId = this.#mustGetChatId();
|
|
243
|
+
return await this.client.sendChatAction(chatId, action, params);
|
|
244
|
+
}
|
|
245
|
+
async editInlineMessageText(text, params) {
|
|
246
|
+
const inlineMessageId = this.#mustGetInlineMsgId();
|
|
247
|
+
return await this.client.editInlineMessageText(inlineMessageId, text, params);
|
|
248
|
+
}
|
|
249
|
+
async editInlineMessageCaption(params) {
|
|
250
|
+
const inlineMessageId = this.#mustGetInlineMsgId();
|
|
251
|
+
return await this.client.editInlineMessageCaption(inlineMessageId, params);
|
|
252
|
+
}
|
|
253
|
+
async editInlineMessageMedia(media, params) {
|
|
254
|
+
const inlineMessageId = this.#mustGetInlineMsgId();
|
|
255
|
+
return await this.client.editInlineMessageMedia(inlineMessageId, media, params);
|
|
256
|
+
}
|
|
257
|
+
async editInlineMessageLiveLocation(latitude, longitude, params) {
|
|
258
|
+
const inlineMessageId = this.#mustGetInlineMsgId();
|
|
259
|
+
return await this.client.editInlineMessageLiveLocation(inlineMessageId, latitude, longitude, params);
|
|
260
|
+
}
|
|
261
|
+
async editInlineMessageReplyMarkup(params) {
|
|
262
|
+
const inlineMessageId = this.#mustGetInlineMsgId();
|
|
263
|
+
return await this.client.editInlineMessageReplyMarkup(inlineMessageId, params);
|
|
264
|
+
}
|
|
265
|
+
async editMessageText(messageId, text, params) {
|
|
266
|
+
const chatId = this.#mustGetChatId();
|
|
267
|
+
return await this.client.editMessageText(chatId, messageId, text, params);
|
|
268
|
+
}
|
|
269
|
+
async editMessageCaption(messageId, params) {
|
|
270
|
+
const chatId = this.#mustGetChatId();
|
|
271
|
+
return await this.client.editMessageCaption(chatId, messageId, params);
|
|
272
|
+
}
|
|
273
|
+
async editMessageMedia(messageId, media, params) {
|
|
274
|
+
const chatId = this.#mustGetChatId();
|
|
275
|
+
return await this.client.editMessageMedia(chatId, messageId, media, params);
|
|
276
|
+
}
|
|
277
|
+
async editMessageLiveLocation(messageId, latitude, longitude, params) {
|
|
278
|
+
const chatId = this.#mustGetChatId();
|
|
279
|
+
return await this.client.editMessageLiveLocation(chatId, messageId, latitude, longitude, params);
|
|
280
|
+
}
|
|
281
|
+
async editMessageReplyMarkup(messageId, params) {
|
|
282
|
+
const chatId = this.#mustGetChatId();
|
|
283
|
+
return await this.client.editMessageReplyMarkup(chatId, messageId, params);
|
|
284
|
+
}
|
|
285
|
+
async answerCallbackQuery(params) {
|
|
286
|
+
if (!("callbackQuery" in this.update)) {
|
|
287
|
+
(0, _0_deps_js_1.unreachable)();
|
|
288
|
+
}
|
|
289
|
+
return await this.client.answerCallbackQuery(this.update.callbackQuery.id, params);
|
|
290
|
+
}
|
|
291
|
+
async answerInlineQuery(results, params) {
|
|
292
|
+
if (!("inlineQuery" in this.update)) {
|
|
293
|
+
(0, _0_deps_js_1.unreachable)();
|
|
294
|
+
}
|
|
295
|
+
return await this.client.answerInlineQuery(this.update.inlineQuery.id, results, params);
|
|
296
|
+
}
|
|
297
|
+
async getMessage(messageId) {
|
|
298
|
+
const chatId = this.#mustGetChatId();
|
|
299
|
+
return await this.client.getMessage(chatId, messageId);
|
|
300
|
+
}
|
|
301
|
+
async getMessages(messageIds) {
|
|
302
|
+
const chatId = this.#mustGetChatId();
|
|
303
|
+
return await this.client.getMessages(chatId, messageIds);
|
|
304
|
+
}
|
|
305
|
+
async forwardMessage(to, messageId, params) {
|
|
306
|
+
const chatId = this.#mustGetChatId();
|
|
307
|
+
return await this.client.forwardMessage(chatId, to, messageId, params);
|
|
308
|
+
}
|
|
309
|
+
async forwardMessages(to, messageIds, params) {
|
|
310
|
+
const chatId = this.#mustGetChatId();
|
|
311
|
+
return await this.client.forwardMessages(chatId, to, messageIds, params);
|
|
312
|
+
}
|
|
313
|
+
async deleteMessage(messageId, params) {
|
|
314
|
+
const chatId = this.#mustGetChatId();
|
|
315
|
+
return await this.client.deleteMessage(chatId, messageId, params);
|
|
316
|
+
}
|
|
317
|
+
async deleteMessages(messageIds, params) {
|
|
318
|
+
const chatId = this.#mustGetChatId();
|
|
319
|
+
return await this.client.deleteMessages(chatId, messageIds, params);
|
|
320
|
+
}
|
|
321
|
+
async pinMessage(messageId, params) {
|
|
322
|
+
const chatId = this.#mustGetChatId();
|
|
323
|
+
return await this.client.pinMessage(chatId, messageId, params);
|
|
324
|
+
}
|
|
325
|
+
async unpinMessage(messageId) {
|
|
326
|
+
const chatId = this.#mustGetChatId();
|
|
327
|
+
return await this.client.unpinMessage(chatId, messageId);
|
|
328
|
+
}
|
|
329
|
+
async unpinMessages() {
|
|
330
|
+
const chatId = this.#mustGetChatId();
|
|
331
|
+
return await this.client.unpinMessages(chatId);
|
|
332
|
+
}
|
|
333
|
+
async setAvailableReactions(availableReactions) {
|
|
334
|
+
const chatId = this.#mustGetChatId();
|
|
335
|
+
return await this.client.setAvailableReactions(chatId, availableReactions);
|
|
336
|
+
}
|
|
337
|
+
async addReaction(messageId, reaction, params) {
|
|
338
|
+
const chatId = this.#mustGetChatId();
|
|
339
|
+
return await this.client.addReaction(chatId, messageId, reaction, params);
|
|
340
|
+
}
|
|
341
|
+
async removeReaction(messageId, reaction) {
|
|
342
|
+
const chatId = this.#mustGetChatId();
|
|
343
|
+
return await this.client.removeReaction(chatId, messageId, reaction);
|
|
344
|
+
}
|
|
345
|
+
async setReactions(messageId, reactions, params) {
|
|
346
|
+
const chatId = this.#mustGetChatId();
|
|
347
|
+
return await this.client.setReactions(chatId, messageId, reactions, params);
|
|
348
|
+
}
|
|
349
|
+
async read() {
|
|
350
|
+
const { chatId, messageId } = this.#mustGetMsg();
|
|
351
|
+
return await this.client.readMessages(chatId, messageId);
|
|
352
|
+
}
|
|
353
|
+
async setChatPhoto(photo, params) {
|
|
354
|
+
const chatId = this.#mustGetChatId();
|
|
355
|
+
return await this.client.setChatPhoto(chatId, photo, params);
|
|
356
|
+
}
|
|
357
|
+
async deletChatPhoto() {
|
|
358
|
+
const chatId = this.#mustGetChatId();
|
|
359
|
+
return await this.client.deleteChatPhoto(chatId);
|
|
360
|
+
}
|
|
361
|
+
async banChatMember(memberId, params) {
|
|
362
|
+
const chatId = this.#mustGetChatId();
|
|
363
|
+
return await this.client.banChatMember(chatId, memberId, params);
|
|
364
|
+
}
|
|
365
|
+
async unbanChatMember(memberId) {
|
|
366
|
+
const chatId = this.#mustGetChatId();
|
|
367
|
+
return await this.client.unbanChatMember(chatId, memberId);
|
|
368
|
+
}
|
|
369
|
+
async kickChatMember(memberId) {
|
|
370
|
+
const chatId = this.#mustGetChatId();
|
|
371
|
+
return await this.client.kickChatMember(chatId, memberId);
|
|
372
|
+
}
|
|
373
|
+
async setChatMemberRights(memberId, params) {
|
|
374
|
+
const chatId = this.#mustGetChatId();
|
|
375
|
+
return await this.client.setChatMemberRights(chatId, memberId, params);
|
|
376
|
+
}
|
|
377
|
+
async promoteChatMember(userId, params) {
|
|
378
|
+
const chatId = this.#mustGetChatId();
|
|
379
|
+
return await this.client.promoteChatMember(chatId, userId, params);
|
|
380
|
+
}
|
|
381
|
+
async deleteChatMemberMessages(userId) {
|
|
382
|
+
const chatId = this.#mustGetChatId();
|
|
383
|
+
return await this.client.deleteChatMemberMessages(chatId, userId);
|
|
384
|
+
}
|
|
385
|
+
async searchMessages(params) {
|
|
386
|
+
const chatId = this.#mustGetChatId();
|
|
387
|
+
params ??= {};
|
|
388
|
+
params.chatId = chatId;
|
|
389
|
+
return await this.client.searchMessages(params);
|
|
390
|
+
}
|
|
391
|
+
async setBoostsRequiredToCircumventRestrictions(boosts) {
|
|
392
|
+
const chatId = this.#mustGetChatId();
|
|
393
|
+
return await this.client.setBoostsRequiredToCircumventRestrictions(chatId, boosts);
|
|
394
|
+
}
|
|
395
|
+
async createInviteLink(params) {
|
|
396
|
+
const chatId = this.#mustGetChatId();
|
|
397
|
+
return await this.client.createInviteLink(chatId, params);
|
|
398
|
+
}
|
|
399
|
+
async getCreatedInviteLinks(params) {
|
|
400
|
+
const chatId = this.#mustGetChatId();
|
|
401
|
+
return await this.client.getCreatedInviteLinks(chatId, params);
|
|
402
|
+
}
|
|
403
|
+
async leaveChat() {
|
|
404
|
+
const chatId = this.#mustGetChatId();
|
|
405
|
+
return await this.client.leaveChat(chatId);
|
|
406
|
+
}
|
|
407
|
+
async blockUser() {
|
|
408
|
+
return await this.client.blockUser(this.#mustGetUserId());
|
|
409
|
+
}
|
|
410
|
+
async unblockUser() {
|
|
411
|
+
return await this.client.unblockUser(this.#mustGetUserId());
|
|
412
|
+
}
|
|
413
|
+
async getChatMember(userId) {
|
|
414
|
+
const chatId = this.#mustGetChatId();
|
|
415
|
+
return await this.client.getChatMember(chatId, userId);
|
|
416
|
+
}
|
|
417
|
+
async getChatMembers(params) {
|
|
418
|
+
const chatId = this.#mustGetChatId();
|
|
419
|
+
return await this.client.getChatMembers(chatId, params);
|
|
420
|
+
}
|
|
421
|
+
async setChatStickerSet(setName) {
|
|
422
|
+
const chatId = this.#mustGetChatId();
|
|
423
|
+
return await this.client.setChatStickerSet(chatId, setName);
|
|
424
|
+
}
|
|
425
|
+
async deleteChatStickerSet() {
|
|
426
|
+
const chatId = this.#mustGetChatId();
|
|
427
|
+
return await this.client.deleteChatStickerSet(chatId);
|
|
428
|
+
}
|
|
429
|
+
async getBusinessConnection() {
|
|
430
|
+
const { businessConnectionId } = this.#mustGetMsg();
|
|
431
|
+
if (!businessConnectionId) {
|
|
432
|
+
(0, _0_deps_js_1.unreachable)();
|
|
433
|
+
}
|
|
434
|
+
return await this.client.getBusinessConnection(businessConnectionId);
|
|
435
|
+
}
|
|
436
|
+
async answerPreCheckoutQuery(ok, params) {
|
|
437
|
+
if (!("preCheckoutQuery" in this.update)) {
|
|
438
|
+
(0, _0_deps_js_1.unreachable)();
|
|
439
|
+
}
|
|
440
|
+
return await this.client.answerPreCheckoutQuery(this.update.preCheckoutQuery.id, ok, params);
|
|
441
|
+
}
|
|
442
|
+
async approveJoinRequest() {
|
|
443
|
+
const { chatId, userId } = this.#mustGetMsg();
|
|
444
|
+
if (!userId) {
|
|
445
|
+
(0, _0_deps_js_1.unreachable)();
|
|
446
|
+
}
|
|
447
|
+
return await this.client.approveJoinRequest(chatId, userId);
|
|
448
|
+
}
|
|
449
|
+
async declineJoinRequest() {
|
|
450
|
+
const { chatId, userId } = this.#mustGetMsg();
|
|
451
|
+
if (!userId) {
|
|
452
|
+
(0, _0_deps_js_1.unreachable)();
|
|
453
|
+
}
|
|
454
|
+
return await this.client.declineJoinRequest(chatId, userId);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
exports.Context = Context;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"2_file_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"2_file_manager.d.ts","sourceRoot":"","sources":["../../src/client/2_file_manager.ts"],"names":[],"mappings":"AAyBA,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAGjC,OAAO,EAAoD,KAAK,UAAU,EAA8C,KAAK,OAAO,EAAkB,MAAM,eAAe,CAAC;AAG5K,OAAO,KAAK,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAEnE,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,cAAc,CAAC;AAEtC,qBAAa,WAAW;;gBAMV,CAAC,EAAE,CAAC;IAQhB,aAAa;IASP,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,MAAM,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,EAAE,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC,EAAE,WAAW,UAAO,GAAG,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC;IAwP1I,aAAa,CAAC,QAAQ,EAAE,GAAG,CAAC,iBAAiB,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,cAAc,GAAG,SAAS;IA4EtG,MAAM,CAAC,iBAAiB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM;IAevD,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,MAAM;IAY7B,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,cAAc;IAgEjD,iBAAiB,CAAC,eAAe,EAAE,GAAG,CAAC,iBAAiB,EAAE,IAAI,SAAI;IAqBlE,sBAAsB,CAAC,EAAE,EAAE,MAAM,GAAG,MAAM,EAAE;CA6CnD"}
|
|
@@ -59,6 +59,7 @@ const _0_deps_js_1 = require("../0_deps.js");
|
|
|
59
59
|
const _0_errors_js_1 = require("../0_errors.js");
|
|
60
60
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
61
61
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
62
|
+
const _3_errors_js_1 = require("../3_errors.js");
|
|
62
63
|
const _3_transport_js_1 = require("../3_transport.js");
|
|
63
64
|
const _3_types_js_1 = require("../3_types.js");
|
|
64
65
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
@@ -68,7 +69,6 @@ class FileManager {
|
|
|
68
69
|
#c;
|
|
69
70
|
#Lupload;
|
|
70
71
|
static #UPLOAD_MAX_CHUNK_SIZE = 512 * _1_utilities_js_1.kilobyte;
|
|
71
|
-
static #DOWNLOAD_MAX_CHUNK_SIZE = 1 * _1_utilities_js_1.megabyte;
|
|
72
72
|
static #BIG_FILE_THRESHOLD = 10 * _1_utilities_js_1.megabyte;
|
|
73
73
|
constructor(c) {
|
|
74
74
|
this.#c = c;
|
|
@@ -231,7 +231,14 @@ class FileManager {
|
|
|
231
231
|
}
|
|
232
232
|
}
|
|
233
233
|
async #handleError(err, retryIn, logPrefix) {
|
|
234
|
-
if (
|
|
234
|
+
if (err instanceof _3_errors_js_1.TimeTooBig || err instanceof _3_errors_js_1.TimeTooSmall) {
|
|
235
|
+
throw err;
|
|
236
|
+
}
|
|
237
|
+
else if (err instanceof _4_errors_js_1.FloodWait) {
|
|
238
|
+
this.#Lupload.warning(`${logPrefix} retrying in ${err.seconds} seconds:`, err);
|
|
239
|
+
await (0, _0_deps_js_1.delay)(err.seconds * _0_deps_js_1.SECOND);
|
|
240
|
+
}
|
|
241
|
+
else if (retryIn > 0) {
|
|
235
242
|
this.#Lupload.warning(`${logPrefix} retrying in ${retryIn} seconds:`, err);
|
|
236
243
|
await (0, _0_deps_js_1.delay)(retryIn * _0_deps_js_1.SECOND);
|
|
237
244
|
}
|
|
@@ -335,8 +342,8 @@ class FileManager {
|
|
|
335
342
|
return;
|
|
336
343
|
}
|
|
337
344
|
}
|
|
338
|
-
const chunkSize = params?.chunkSize ??
|
|
339
|
-
_a.validateChunkSize(chunkSize,
|
|
345
|
+
const chunkSize = params?.chunkSize ?? _4_constants_js_1.DOWNLOAD_MAX_CHUNK_SIZE;
|
|
346
|
+
_a.validateChunkSize(chunkSize, _4_constants_js_1.DOWNLOAD_MAX_CHUNK_SIZE);
|
|
340
347
|
if (params?.offset !== undefined) {
|
|
341
348
|
_a.validateOffset(params.offset);
|
|
342
349
|
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
3
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
4
|
+
*
|
|
5
|
+
* This file is part of MTKruto.
|
|
6
|
+
*
|
|
7
|
+
* This program is free software: you can redistribute it and/or modify
|
|
8
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
10
|
+
* (at your option) any later version.
|
|
11
|
+
*
|
|
12
|
+
* This program is distributed in the hope that it will be useful,
|
|
13
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
* GNU Lesser General Public License for more details.
|
|
16
|
+
*
|
|
17
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
19
|
+
*/
|
|
20
|
+
import { type Logger } from "../1_utilities.js";
|
|
21
|
+
import type { SignInParams } from "./0_params.js";
|
|
22
|
+
import type { ClientGeneric } from "./1_client_generic.js";
|
|
23
|
+
export declare const restartAuth: unique symbol;
|
|
24
|
+
export declare function signIn(client: ClientGeneric, logger: Logger, params: SignInParams | undefined): Promise<void>;
|
|
25
|
+
//# sourceMappingURL=2_sign_in.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"2_sign_in.d.ts","sourceRoot":"","sources":["../../src/client/2_sign_in.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAGH,OAAO,EAAE,KAAK,MAAM,EAA+B,MAAM,mBAAmB,CAAC;AAI7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAE3D,eAAO,MAAM,WAAW,eAAwB,CAAC;AAEjD,wBAAsB,MAAM,CAAC,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,SAAS,iBAkFnG"}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* MTKruto - Cross-runtime JavaScript library for building Telegram clients
|
|
4
|
+
* Copyright (C) 2023-2026 Roj <https://roj.im/>
|
|
5
|
+
*
|
|
6
|
+
* This file is part of MTKruto.
|
|
7
|
+
*
|
|
8
|
+
* This program is free software: you can redistribute it and/or modify
|
|
9
|
+
* it under the terms of the GNU Lesser General Public License as published by
|
|
10
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
11
|
+
* (at your option) any later version.
|
|
12
|
+
*
|
|
13
|
+
* This program is distributed in the hope that it will be useful,
|
|
14
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
15
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
16
|
+
* GNU Lesser General Public License for more details.
|
|
17
|
+
*
|
|
18
|
+
* You should have received a copy of the GNU Lesser General Public License
|
|
19
|
+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.restartAuth = void 0;
|
|
23
|
+
exports.signIn = signIn;
|
|
24
|
+
const _0_deps_js_1 = require("../0_deps.js");
|
|
25
|
+
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
26
|
+
const _2_tl_js_1 = require("../2_tl.js");
|
|
27
|
+
const _3_errors_js_1 = require("../3_errors.js");
|
|
28
|
+
const _4_errors_js_1 = require("../4_errors.js");
|
|
29
|
+
exports.restartAuth = Symbol("restartAuth");
|
|
30
|
+
async function signIn(client, logger, params) {
|
|
31
|
+
try {
|
|
32
|
+
await client.getMe();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
catch (err) {
|
|
36
|
+
if ((!(err instanceof _4_errors_js_1.InputError))) {
|
|
37
|
+
throw err;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
if (typeof params === "undefined") {
|
|
41
|
+
const loginType = (0, _1_utilities_js_1.mustPromptOneOf)("Do you want to sign in as a bot [b] or as a user [u]?", ["b", "u"]);
|
|
42
|
+
if (loginType === "b") {
|
|
43
|
+
params = { botToken: (0, _1_utilities_js_1.mustPrompt)("Bot token:") };
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
params = { phone: () => (0, _1_utilities_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_utilities_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_utilities_js_1.mustPrompt)("Password:") };
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
logger.debug("signing in with", typeof params === "string" ? "bot token" : _2_tl_js_1.Api.is("auth.exportedAuthorization", params) ? "exported authorization" : "AuthorizeUserParams");
|
|
50
|
+
if (params && "botToken" in params) {
|
|
51
|
+
const result = await client.checkBotToken(params.botToken);
|
|
52
|
+
if (result.type === "signed_in") {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
(0, _0_deps_js_1.unreachable)();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
auth: while (true) {
|
|
60
|
+
try {
|
|
61
|
+
let phone;
|
|
62
|
+
while (true) {
|
|
63
|
+
try {
|
|
64
|
+
phone = typeof params.phone === "string" ? params.phone : await params.phone();
|
|
65
|
+
await client.sendCode(phone);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
catch (err) {
|
|
69
|
+
if (err instanceof _3_errors_js_1.PhoneNumberInvalid) {
|
|
70
|
+
continue;
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
throw err;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
logger.debug("verification code sent");
|
|
78
|
+
code: while (true) {
|
|
79
|
+
const code = typeof params.code === "string" ? params.code : await params.code();
|
|
80
|
+
const codeCheckResult = await client.checkCode(code);
|
|
81
|
+
if (codeCheckResult.type === "signed_in") {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
else if (codeCheckResult.type === "invalid_code") {
|
|
85
|
+
continue code;
|
|
86
|
+
}
|
|
87
|
+
else if (codeCheckResult.type === "password_required") {
|
|
88
|
+
break code;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
(0, _0_deps_js_1.unreachable)();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const passwordHint = await client.getPasswordHint();
|
|
95
|
+
password: while (true) {
|
|
96
|
+
const password = typeof params.password === "string" ? params.password : await params.password(passwordHint);
|
|
97
|
+
const passwordCheckResult = await client.checkPassword(password);
|
|
98
|
+
if (passwordCheckResult.type === "signed_in") {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
else if (passwordCheckResult.type === "invalid_password") {
|
|
102
|
+
continue password;
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
(0, _0_deps_js_1.unreachable)();
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
if (err === exports.restartAuth) {
|
|
111
|
+
continue auth;
|
|
112
|
+
}
|
|
113
|
+
else {
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
}
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
*/
|
|
20
20
|
import type { Api } from "../2_tl.js";
|
|
21
21
|
import type { CallbackQuery, ChosenInlineResult, MessageTypes, UpdateIntersection, UpdateMap } from "../3_types.js";
|
|
22
|
+
import type { Context } from "./2_context.js";
|
|
22
23
|
type AnyLevel1 = keyof UpdateMap;
|
|
23
24
|
type GetLevel1Type<L1 extends AnyLevel1> = UpdateMap[L1];
|
|
24
25
|
interface Level2Map {
|
|
@@ -55,9 +56,11 @@ interface Shortcuts<T extends UpdateIntersection> {
|
|
|
55
56
|
from: T["callbackQuery"] extends object ? T["callbackQuery"]["from"] : T["inlineQuery"] extends object ? T["inlineQuery"]["from"] : T["chosenInlineResult"] extends object ? T["chosenInlineResult"]["from"] : T["message"] extends object ? T["message"]["from"] : T["editedMessage"] extends object ? T["editedMessage"]["from"] : T["scheduledMessage"] extends object ? T["scheduledMessage"]["from"] : T["preCheckoutQuery"] extends object ? T["preCheckoutQuery"]["from"] : T["joinRequest"] extends object ? T["joinRequest"]["from"] : T["pollAnswer"] extends object ? T["pollAnswer"]["from"] : undefined;
|
|
56
57
|
}
|
|
57
58
|
type GetShortcuts<T> = T extends UpdateIntersection ? T["update"] extends object ? Record<string, never> : Shortcuts<T> : Record<string, never>;
|
|
58
|
-
type Filter<Q extends AnyLevelX> =
|
|
59
|
+
type Filter<Q extends AnyLevelX> = {
|
|
60
|
+
update: FilterCore<Q>;
|
|
61
|
+
} & GetShortcuts<FilterCore<Q>>;
|
|
59
62
|
export type FilterQuery = AnyLevelX;
|
|
60
|
-
export type WithFilter<T, Q extends FilterQuery> = T & Filter<Q>;
|
|
63
|
+
export type WithFilter<T extends Context, Q extends FilterQuery> = T & Filter<Q>;
|
|
61
64
|
export declare function match<Q extends FilterQuery, T extends object>(filter: Q, value: T): boolean;
|
|
62
65
|
export {};
|
|
63
|
-
//# sourceMappingURL=
|
|
66
|
+
//# sourceMappingURL=3_filters.d.ts.map
|