@mtkruto/node 0.1.190 → 0.1.191
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 +12 -0
- package/esm/0_errors.js +19 -0
- package/esm/client/0_client_abstract.js +3 -2
- package/esm/client/0_html.js +4 -3
- package/esm/client/0_markdown.js +6 -5
- package/esm/client/0_types.d.ts +0 -2
- package/esm/client/0_types.js +1 -2
- package/esm/client/0_utilities.js +2 -1
- package/esm/client/1_client_encrypted.js +1 -1
- package/esm/client/1_client_plain.js +3 -4
- package/esm/client/1_composer.js +3 -2
- package/esm/client/1_file_manager.js +4 -4
- package/esm/client/2_message_manager.js +41 -43
- package/esm/client/3_chat_list_manager.js +3 -2
- package/esm/client/3_story_manager.js +2 -1
- package/esm/client/4_client.d.ts +1 -1
- package/esm/client/4_client.js +13 -4
- package/esm/mod.d.ts +1 -0
- package/esm/mod.js +1 -0
- package/esm/types/0__file_id.js +2 -1
- package/esm/types/0_chat_photo.d.ts +1 -0
- package/esm/types/0_chat_photo.js +7 -4
- package/esm/types/5_callback_query.js +2 -1
- package/package.json +1 -1
- package/script/0_errors.d.ts +12 -0
- package/script/0_errors.js +27 -0
- package/script/client/0_client_abstract.js +3 -2
- package/script/client/0_html.js +4 -3
- package/script/client/0_markdown.js +6 -5
- package/script/client/0_types.d.ts +0 -2
- package/script/client/0_types.js +0 -4
- package/script/client/0_utilities.js +2 -1
- package/script/client/1_client_encrypted.js +2 -2
- package/script/client/1_client_plain.js +3 -4
- package/script/client/1_composer.js +3 -2
- package/script/client/1_file_manager.js +5 -5
- package/script/client/2_message_manager.js +41 -43
- package/script/client/3_chat_list_manager.js +3 -2
- package/script/client/3_story_manager.js +2 -1
- package/script/client/4_client.d.ts +1 -1
- package/script/client/4_client.js +13 -4
- package/script/mod.d.ts +1 -0
- package/script/mod.js +1 -0
- package/script/types/0__file_id.js +2 -1
- package/script/types/0_chat_photo.d.ts +1 -0
- package/script/types/0_chat_photo.js +7 -4
- package/script/types/5_callback_query.js +2 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { cleanObject } from "../1_utilities.js";
|
|
1
2
|
import { types } from "../2_tl.js";
|
|
2
3
|
import { FileType, PhotoSourceType, serializeFileId, toUniqueFileId } from "./0__file_id.js";
|
|
3
4
|
export function constructChatPhoto(photo, chatId, chatAccessHash) {
|
|
@@ -16,22 +17,24 @@ export function constructChatPhoto(photo, chatId, chatAccessHash) {
|
|
|
16
17
|
const bigFileId = serializeFileId(bigFileId_);
|
|
17
18
|
const bigFileUniqueId = toUniqueFileId(bigFileId_);
|
|
18
19
|
if (photo instanceof types.ChatPhoto) {
|
|
19
|
-
return {
|
|
20
|
+
return cleanObject({
|
|
20
21
|
smallFileId,
|
|
21
22
|
smallFileUniqueId,
|
|
22
23
|
bigFileId,
|
|
23
24
|
bigFileUniqueId,
|
|
24
25
|
hasVideo: photo.has_video || false,
|
|
25
|
-
|
|
26
|
+
strippedThumbnail: photo.stripped_thumb,
|
|
27
|
+
});
|
|
26
28
|
}
|
|
27
29
|
else {
|
|
28
|
-
return {
|
|
30
|
+
return cleanObject({
|
|
29
31
|
personal: photo.personal ? true : undefined,
|
|
30
32
|
smallFileId,
|
|
31
33
|
smallFileUniqueId,
|
|
32
34
|
bigFileId,
|
|
33
35
|
bigFileUniqueId,
|
|
34
36
|
hasVideo: photo.has_video || false,
|
|
35
|
-
|
|
37
|
+
strippedThumbnail: photo.stripped_thumb,
|
|
38
|
+
});
|
|
36
39
|
}
|
|
37
40
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
+
import { InputError } from "../0_errors.js";
|
|
1
2
|
import { base64DecodeUrlSafe, base64EncodeUrlSafe, cleanObject, UNREACHABLE } from "../1_utilities.js";
|
|
2
3
|
import { peerToChatId, serialize, TLReader, types } from "../2_tl.js";
|
|
3
4
|
import { constructUser } from "./1_user.js";
|
|
4
|
-
const ERR_INVALID_INLINE_MESSAGE_ID = new
|
|
5
|
+
const ERR_INVALID_INLINE_MESSAGE_ID = new InputError("Invalid inline message ID");
|
|
5
6
|
export function deserializeInlineMessageId(inlineMessageId) {
|
|
6
7
|
try {
|
|
7
8
|
const buffer = base64DecodeUrlSafe(inlineMessageId);
|
package/package.json
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare class MtkrutoError extends Error {
|
|
2
|
+
}
|
|
3
|
+
export declare class ConnectionError extends MtkrutoError {
|
|
4
|
+
}
|
|
5
|
+
export declare class AccessError extends MtkrutoError {
|
|
6
|
+
}
|
|
7
|
+
export declare class InputError extends MtkrutoError {
|
|
8
|
+
}
|
|
9
|
+
export declare class TransportError extends MtkrutoError {
|
|
10
|
+
readonly code: number;
|
|
11
|
+
constructor(code: number);
|
|
12
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransportError = exports.InputError = exports.AccessError = exports.ConnectionError = exports.MtkrutoError = void 0;
|
|
4
|
+
class MtkrutoError extends Error {
|
|
5
|
+
}
|
|
6
|
+
exports.MtkrutoError = MtkrutoError;
|
|
7
|
+
class ConnectionError extends MtkrutoError {
|
|
8
|
+
}
|
|
9
|
+
exports.ConnectionError = ConnectionError;
|
|
10
|
+
class AccessError extends MtkrutoError {
|
|
11
|
+
}
|
|
12
|
+
exports.AccessError = AccessError;
|
|
13
|
+
class InputError extends MtkrutoError {
|
|
14
|
+
}
|
|
15
|
+
exports.InputError = InputError;
|
|
16
|
+
class TransportError extends MtkrutoError {
|
|
17
|
+
constructor(code) {
|
|
18
|
+
super(`Transport error: ${code}`);
|
|
19
|
+
Object.defineProperty(this, "code", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
configurable: true,
|
|
22
|
+
writable: true,
|
|
23
|
+
value: code
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
exports.TransportError = TransportError;
|
|
@@ -14,6 +14,7 @@ var _ClientAbstract_dc;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ClientAbstract = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
17
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
17
18
|
const _3_transport_js_1 = require("../3_transport.js");
|
|
18
19
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
19
20
|
class ClientAbstract {
|
|
@@ -58,7 +59,7 @@ class ClientAbstract {
|
|
|
58
59
|
}
|
|
59
60
|
get dcId() {
|
|
60
61
|
if (!this.transport) {
|
|
61
|
-
throw new
|
|
62
|
+
throw new _0_errors_js_1.ConnectionError("Not connected.");
|
|
62
63
|
}
|
|
63
64
|
return this.transport.dcId;
|
|
64
65
|
}
|
|
@@ -85,7 +86,7 @@ class ClientAbstract {
|
|
|
85
86
|
}
|
|
86
87
|
async disconnect() {
|
|
87
88
|
if (!this.transport) {
|
|
88
|
-
throw new
|
|
89
|
+
throw new _0_errors_js_1.ConnectionError("Not connected.");
|
|
89
90
|
}
|
|
90
91
|
await this.transport.transport.deinitialize();
|
|
91
92
|
await this.transport.connection.close();
|
package/script/client/0_html.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.parseHtml = void 0;
|
|
4
4
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
5
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
5
6
|
function parseHtml(html) {
|
|
6
7
|
html = html.trim();
|
|
7
8
|
let text = "";
|
|
@@ -29,7 +30,7 @@ function parseHtml(html) {
|
|
|
29
30
|
case "a": {
|
|
30
31
|
const url = attribs.href;
|
|
31
32
|
if (!url) {
|
|
32
|
-
throw new
|
|
33
|
+
throw new _0_errors_js_1.InputError("Missing attribute: href");
|
|
33
34
|
}
|
|
34
35
|
stack.push({ type: "textLink", offset: text.length, length: 0, url });
|
|
35
36
|
break;
|
|
@@ -44,7 +45,7 @@ function parseHtml(html) {
|
|
|
44
45
|
break;
|
|
45
46
|
case "span":
|
|
46
47
|
if (attribs.class != "tg-spoiler") {
|
|
47
|
-
throw new
|
|
48
|
+
throw new _0_errors_js_1.InputError('The class attribute must be "tg-spoiler."');
|
|
48
49
|
}
|
|
49
50
|
// falls through
|
|
50
51
|
case "tg-spoiler":
|
|
@@ -52,7 +53,7 @@ function parseHtml(html) {
|
|
|
52
53
|
break;
|
|
53
54
|
case "tg-emoji":
|
|
54
55
|
if (!attribs["emoji-id"]) {
|
|
55
|
-
throw new
|
|
56
|
+
throw new _0_errors_js_1.InputError("Missing attribute: emoji-id");
|
|
56
57
|
}
|
|
57
58
|
stack.push({ type: "spoiler", offset: text.length, length: 0 });
|
|
58
59
|
break;
|
|
@@ -7,6 +7,7 @@ exports.parseMarkdown = exports.CODEPOINTS = void 0;
|
|
|
7
7
|
*/
|
|
8
8
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
9
9
|
const _3_types_js_1 = require("../3_types.js");
|
|
10
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
10
11
|
const enc = new TextEncoder();
|
|
11
12
|
const dec = new TextDecoder();
|
|
12
13
|
exports.CODEPOINTS = {
|
|
@@ -168,7 +169,7 @@ function parseMarkdown(text_) {
|
|
|
168
169
|
type = "spoiler";
|
|
169
170
|
}
|
|
170
171
|
else {
|
|
171
|
-
throw new
|
|
172
|
+
throw new _0_errors_js_1.InputError(`The character "${String.fromCharCode(c)}" is reserved and must be escaped with a preceding backslash.`);
|
|
172
173
|
}
|
|
173
174
|
break;
|
|
174
175
|
case exports.CODEPOINTS["["]:
|
|
@@ -253,7 +254,7 @@ function parseMarkdown(text_) {
|
|
|
253
254
|
}
|
|
254
255
|
url = Uint8Array.from(url_);
|
|
255
256
|
if (text[i] !== exports.CODEPOINTS[")"]) {
|
|
256
|
-
throw new Error(
|
|
257
|
+
throw new Error(`Can't find the end of the URL that starts at offset ${urlBeginPos}.`);
|
|
257
258
|
}
|
|
258
259
|
}
|
|
259
260
|
userId = getLinkUserId(dec.decode(url));
|
|
@@ -270,7 +271,7 @@ function parseMarkdown(text_) {
|
|
|
270
271
|
}
|
|
271
272
|
case "customEmoji": {
|
|
272
273
|
if (text[i + 1] !== exports.CODEPOINTS["("]) {
|
|
273
|
-
throw new
|
|
274
|
+
throw new _0_errors_js_1.InputError("Custom emoji entities must contain a tg://emoji URL.");
|
|
274
275
|
}
|
|
275
276
|
i += 2;
|
|
276
277
|
const url_ = [];
|
|
@@ -285,7 +286,7 @@ function parseMarkdown(text_) {
|
|
|
285
286
|
}
|
|
286
287
|
const url = Uint8Array.from(url_);
|
|
287
288
|
if (text[i] !== exports.CODEPOINTS[")"]) {
|
|
288
|
-
throw new
|
|
289
|
+
throw new _0_errors_js_1.InputError(`Can't find the end of the custom emoji URL that starts at offset ${urlBeginPos}.`);
|
|
289
290
|
}
|
|
290
291
|
customEmojiId = getLinkCustomEmojiId(dec.decode(url));
|
|
291
292
|
break;
|
|
@@ -317,7 +318,7 @@ function parseMarkdown(text_) {
|
|
|
317
318
|
}
|
|
318
319
|
if (nestedEntities.length !== 0) {
|
|
319
320
|
const last = nestedEntities[nestedEntities.length - 1];
|
|
320
|
-
throw new
|
|
321
|
+
throw new _0_errors_js_1.InputError(`Can't find the end of the ${last.type} entity that starts at offset ${last.entityByteOffset}.`);
|
|
321
322
|
}
|
|
322
323
|
entities = (0, _3_types_js_1.sortMessageEntities)(entities);
|
|
323
324
|
return [dec.decode(text.slice(0, resultSize)), entities];
|
package/script/client/0_types.js
CHANGED
|
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
exports.getChatListId = exports.getUsername = exports.isHttpUrl = exports.getFileContents = exports.isChannelPtsUpdate = exports.isPtsUpdate = exports.resolve = void 0;
|
|
27
27
|
const dntShim = __importStar(require("../_dnt.shims.js"));
|
|
28
28
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
29
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
29
30
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
30
31
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
31
32
|
const resolve = () => Promise.resolve();
|
|
@@ -111,7 +112,7 @@ function isDigit(string) {
|
|
|
111
112
|
const c = string.charCodeAt(0);
|
|
112
113
|
return "0".charCodeAt(0) <= c && c <= "9".charCodeAt(0);
|
|
113
114
|
}
|
|
114
|
-
const errInvalidUsername = (u) => new
|
|
115
|
+
const errInvalidUsername = (u) => new _0_errors_js_1.InputError(`Invalid username: ${u}`);
|
|
115
116
|
function validateUsername(string, ignoreAt = false) {
|
|
116
117
|
string = string.trim();
|
|
117
118
|
if (ignoreAt && string.startsWith("@")) {
|
|
@@ -14,12 +14,12 @@ var _ClientEncrypted_instances, _ClientEncrypted_authKey, _ClientEncrypted_authK
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ClientEncrypted = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
17
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
17
18
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
18
19
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
19
20
|
const _4_errors_js_1 = require("../4_errors.js");
|
|
20
21
|
const _0_client_abstract_js_1 = require("./0_client_abstract.js");
|
|
21
22
|
const _0_message_js_1 = require("./0_message.js");
|
|
22
|
-
const _0_types_js_1 = require("./0_types.js");
|
|
23
23
|
// global ClientEncrypted ID counter for logs
|
|
24
24
|
let id = 0;
|
|
25
25
|
/**
|
|
@@ -233,7 +233,7 @@ _ClientEncrypted_authKey = new WeakMap(), _ClientEncrypted_authKeyId = new WeakM
|
|
|
233
233
|
}
|
|
234
234
|
if (!this.connected) {
|
|
235
235
|
for (const [key, { reject }] of __classPrivateFieldGet(this, _ClientEncrypted_promises, "f").entries()) {
|
|
236
|
-
reject?.(new
|
|
236
|
+
reject?.(new _0_errors_js_1.ConnectionError("Connection was closed"));
|
|
237
237
|
__classPrivateFieldGet(this, _ClientEncrypted_promises, "f").delete(key);
|
|
238
238
|
}
|
|
239
239
|
}
|
|
@@ -14,6 +14,7 @@ var _ClientPlain_publicKeys, _ClientPlain_lastMsgId;
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ClientPlain = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
17
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
17
18
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
18
19
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
19
20
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
@@ -33,7 +34,7 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
|
|
|
33
34
|
}
|
|
34
35
|
async invoke(function_) {
|
|
35
36
|
if (!this.transport) {
|
|
36
|
-
throw new
|
|
37
|
+
throw new _0_errors_js_1.ConnectionError("Not connected.");
|
|
37
38
|
}
|
|
38
39
|
const msgId = __classPrivateFieldSet(this, _ClientPlain_lastMsgId, (0, _0_message_js_1.getMessageId)(__classPrivateFieldGet(this, _ClientPlain_lastMsgId, "f")), "f");
|
|
39
40
|
const payload = (0, _0_message_js_1.packUnencryptedMessage)(function_[_2_tl_js_1.serialize](), msgId);
|
|
@@ -44,9 +45,7 @@ class ClientPlain extends _0_client_abstract_js_1.ClientAbstract {
|
|
|
44
45
|
L.inBin(payload);
|
|
45
46
|
if (buffer.length == 4) {
|
|
46
47
|
const int = (0, _1_utilities_js_1.bigIntFromBuffer)(buffer, true, true);
|
|
47
|
-
|
|
48
|
-
throw new Error("-404");
|
|
49
|
-
}
|
|
48
|
+
throw new _0_errors_js_1.TransportError(Number(int));
|
|
50
49
|
}
|
|
51
50
|
const { message } = (0, _0_message_js_1.unpackUnencryptedMessage)(buffer);
|
|
52
51
|
const reader = new _2_tl_js_1.TLReader(message);
|
|
@@ -13,6 +13,7 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
13
13
|
var _Composer_handle, _Composer_prefixes;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.Composer = exports.skip = exports.concat = exports.flatten = void 0;
|
|
16
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
16
17
|
const _0_filters_js_1 = require("./0_filters.js");
|
|
17
18
|
function flatten(mw) {
|
|
18
19
|
return typeof mw === "function" ? mw : (ctx, next) => mw.middleware()(ctx, next);
|
|
@@ -40,7 +41,7 @@ exports.skip = skip;
|
|
|
40
41
|
class Composer {
|
|
41
42
|
set prefixes(value) {
|
|
42
43
|
if (__classPrivateFieldGet(this, _Composer_prefixes, "f") !== undefined) {
|
|
43
|
-
throw new
|
|
44
|
+
throw new _0_errors_js_1.InputError("Prefixes already set");
|
|
44
45
|
}
|
|
45
46
|
__classPrivateFieldSet(this, _Composer_prefixes, value, "f");
|
|
46
47
|
}
|
|
@@ -90,7 +91,7 @@ class Composer {
|
|
|
90
91
|
continue;
|
|
91
92
|
}
|
|
92
93
|
if (left.startsWith(right) || right.startsWith(left)) {
|
|
93
|
-
throw new
|
|
94
|
+
throw new _0_errors_js_1.InputError("Intersecting prefixes");
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
}
|
|
@@ -13,12 +13,12 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _FileManager_instances, _FileManager_c, _FileManager_Lupload, _FileManager_downloadInner;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.FileManager = void 0;
|
|
16
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
16
17
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
17
18
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
18
19
|
const _3_types_js_1 = require("../3_types.js");
|
|
19
20
|
const _4_constants_js_1 = require("../4_constants.js");
|
|
20
21
|
const _4_errors_js_1 = require("../4_errors.js");
|
|
21
|
-
const _0_types_js_1 = require("./0_types.js");
|
|
22
22
|
class FileManager {
|
|
23
23
|
constructor(c) {
|
|
24
24
|
_FileManager_instances.add(this);
|
|
@@ -32,7 +32,7 @@ class FileManager {
|
|
|
32
32
|
const isBig = contents.length > 1048576; // 10 MB
|
|
33
33
|
const chunkSize = params?.chunkSize ?? 512 * 1024;
|
|
34
34
|
if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
|
|
35
|
-
throw new
|
|
35
|
+
throw new _0_errors_js_1.InputError("chunkSize must be divisible by 1024.");
|
|
36
36
|
}
|
|
37
37
|
const signal = params?.signal;
|
|
38
38
|
__classPrivateFieldGet(this, _FileManager_Lupload, "f").debug("uploading " + (isBig ? "big " : "") + "file of size " + contents.length + " with chunk size of " + chunkSize);
|
|
@@ -70,7 +70,7 @@ class FileManager {
|
|
|
70
70
|
__classPrivateFieldGet(this, _FileManager_Lupload, "f").warning("got a flood wait of " + err.seconds + " seconds");
|
|
71
71
|
await new Promise((r) => setTimeout(r, err.seconds * 1000));
|
|
72
72
|
}
|
|
73
|
-
else if (err instanceof
|
|
73
|
+
else if (err instanceof _0_errors_js_1.ConnectionError) {
|
|
74
74
|
while (true) {
|
|
75
75
|
try {
|
|
76
76
|
await new Promise((r) => setTimeout(r, 3000));
|
|
@@ -173,7 +173,7 @@ class FileManager {
|
|
|
173
173
|
async getCustomEmojiStickers(id) {
|
|
174
174
|
id = Array.isArray(id) ? id : [id];
|
|
175
175
|
if (!id.length) {
|
|
176
|
-
|
|
176
|
+
return [];
|
|
177
177
|
}
|
|
178
178
|
const stickers = new Array();
|
|
179
179
|
let shouldFetch = false;
|
|
@@ -232,7 +232,7 @@ _FileManager_c = new WeakMap(), _FileManager_Lupload = new WeakMap(), _FileManag
|
|
|
232
232
|
}
|
|
233
233
|
const chunkSize = params?.chunkSize ?? 1024 * 1024;
|
|
234
234
|
if ((0, _1_utilities_js_1.mod)(chunkSize, 1024) != 0) {
|
|
235
|
-
throw new
|
|
235
|
+
throw new _0_errors_js_1.InputError("chunkSize must be divisible by 1024.");
|
|
236
236
|
}
|
|
237
237
|
const { api, connect, disconnect } = __classPrivateFieldGet(this, _FileManager_c, "f").apiFactory(dcId);
|
|
238
238
|
await connect();
|
|
@@ -14,6 +14,7 @@ var _MessageManager_instances, _MessageManager_c, _MessageManager_LresolveFileId
|
|
|
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");
|
|
17
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
17
18
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
18
19
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
19
20
|
const _3_types_js_1 = require("../3_types.js");
|
|
@@ -23,7 +24,7 @@ const _0_html_js_1 = require("./0_html.js");
|
|
|
23
24
|
const _0_markdown_js_1 = require("./0_markdown.js");
|
|
24
25
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
25
26
|
const FALLBACK_MIME_TYPE = "application/octet-stream";
|
|
26
|
-
const STICKER_MIME_TYPES = ["image/webp", "video/
|
|
27
|
+
const STICKER_MIME_TYPES = ["image/webp", "video/webm", "application/x-tgsticker"];
|
|
27
28
|
class MessageManager {
|
|
28
29
|
constructor(c) {
|
|
29
30
|
_MessageManager_instances.add(this);
|
|
@@ -576,12 +577,9 @@ class MessageManager {
|
|
|
576
577
|
}
|
|
577
578
|
}
|
|
578
579
|
async deleteChatMemberMessages(chatId, memberId) {
|
|
579
|
-
const channel = await __classPrivateFieldGet(this, _MessageManager_c, "f").
|
|
580
|
-
if (!(channel instanceof _2_tl_js_1.types.InputPeerChannel)) {
|
|
581
|
-
throw new Error("Invalid chat ID");
|
|
582
|
-
}
|
|
580
|
+
const channel = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputChannel(chatId);
|
|
583
581
|
const participant = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
584
|
-
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.deleteParticipantHistory({ channel
|
|
582
|
+
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.deleteParticipantHistory({ channel, participant });
|
|
585
583
|
}
|
|
586
584
|
async pinMessage(chatId, messageId, params) {
|
|
587
585
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.updatePinnedMessage({
|
|
@@ -741,7 +739,7 @@ class MessageManager {
|
|
|
741
739
|
action_ = new _2_tl_js_1.types.SendMessageUploadRoundAction({ progress: 0 });
|
|
742
740
|
break;
|
|
743
741
|
default:
|
|
744
|
-
throw new
|
|
742
|
+
throw new _0_errors_js_1.InputError(`Invalid chat action: ${action}`);
|
|
745
743
|
}
|
|
746
744
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.setTyping({ peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId), action: action_, top_msg_id: params?.messageThreadId });
|
|
747
745
|
}
|
|
@@ -775,7 +773,7 @@ class MessageManager {
|
|
|
775
773
|
async banChatMember(chatId, memberId, params) {
|
|
776
774
|
const chat = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
777
775
|
if (!(chat instanceof _2_tl_js_1.types.InputPeerChannel) && !(chat instanceof _2_tl_js_1.types.InputPeerChat)) {
|
|
778
|
-
throw new
|
|
776
|
+
throw new _0_errors_js_1.InputError("Expected a channel, supergroup, or group ID.");
|
|
779
777
|
}
|
|
780
778
|
const member = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
781
779
|
if (chat instanceof _2_tl_js_1.types.InputPeerChannel) {
|
|
@@ -805,7 +803,7 @@ class MessageManager {
|
|
|
805
803
|
}
|
|
806
804
|
else if (chat instanceof _2_tl_js_1.types.InputPeerChat) {
|
|
807
805
|
if (!(member instanceof _2_tl_js_1.types.InputPeerUser)) {
|
|
808
|
-
throw new
|
|
806
|
+
throw new _0_errors_js_1.InputError(`Invalid user ID: ${memberId}`);
|
|
809
807
|
}
|
|
810
808
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.deleteChatUser({
|
|
811
809
|
chat_id: chat.chat_id,
|
|
@@ -815,25 +813,19 @@ class MessageManager {
|
|
|
815
813
|
}
|
|
816
814
|
}
|
|
817
815
|
async unbanChatMember(chatId, memberId) {
|
|
818
|
-
const
|
|
819
|
-
if (!(chat instanceof _2_tl_js_1.types.InputPeerChannel)) {
|
|
820
|
-
throw new Error("Invalid chat ID");
|
|
821
|
-
}
|
|
816
|
+
const channel = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputChannel(chatId);
|
|
822
817
|
const member = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
823
818
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
|
|
824
|
-
channel
|
|
819
|
+
channel,
|
|
825
820
|
participant: member,
|
|
826
821
|
banned_rights: new _2_tl_js_1.types.ChatBannedRights({ until_date: 0 }),
|
|
827
822
|
});
|
|
828
823
|
}
|
|
829
824
|
async setChatMemberRights(chatId, memberId, params) {
|
|
830
|
-
const
|
|
831
|
-
if (!(chat instanceof _2_tl_js_1.types.InputPeerChannel)) {
|
|
832
|
-
throw new Error("Invalid chat ID");
|
|
833
|
-
}
|
|
825
|
+
const channel = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputChannel(chatId);
|
|
834
826
|
const member = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(memberId);
|
|
835
827
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.editBanned({
|
|
836
|
-
channel
|
|
828
|
+
channel,
|
|
837
829
|
participant: member,
|
|
838
830
|
banned_rights: (0, _3_types_js_2.chatMemberRightsToTlObject)(params?.rights, params?.untilDate),
|
|
839
831
|
});
|
|
@@ -912,7 +904,7 @@ class MessageManager {
|
|
|
912
904
|
}
|
|
913
905
|
async createInviteLink(chatId, params) {
|
|
914
906
|
if (params?.requireApproval && params?.limit) {
|
|
915
|
-
throw new
|
|
907
|
+
throw new _0_errors_js_1.InputError("requireApproval cannot be true while limit is specified.");
|
|
916
908
|
}
|
|
917
909
|
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.exportChatInvite({
|
|
918
910
|
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
@@ -939,7 +931,7 @@ class MessageManager {
|
|
|
939
931
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("joinChat");
|
|
940
932
|
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
941
933
|
if (peer instanceof _2_tl_js_1.types.InputPeerUser) {
|
|
942
|
-
throw new
|
|
934
|
+
throw new _0_errors_js_1.InputError("Cannot join private chats.");
|
|
943
935
|
}
|
|
944
936
|
else if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
|
|
945
937
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.joinChannel({ channel: new _2_tl_js_1.types.InputChannel(peer) });
|
|
@@ -954,7 +946,7 @@ class MessageManager {
|
|
|
954
946
|
async leaveChat(chatId) {
|
|
955
947
|
const peer = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId);
|
|
956
948
|
if (peer instanceof _2_tl_js_1.types.InputPeerUser) {
|
|
957
|
-
throw new
|
|
949
|
+
throw new _0_errors_js_1.InputError("Cannot leave private chats.");
|
|
958
950
|
}
|
|
959
951
|
else if (peer instanceof _2_tl_js_1.types.InputPeerChannel) {
|
|
960
952
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.channels.leaveChannel({ channel: new _2_tl_js_1.types.InputChannel(peer) });
|
|
@@ -970,7 +962,7 @@ class MessageManager {
|
|
|
970
962
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("blockUser");
|
|
971
963
|
const id = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(userId);
|
|
972
964
|
if (!(id instanceof _2_tl_js_1.types.User)) {
|
|
973
|
-
throw new
|
|
965
|
+
throw new _0_errors_js_1.InputError("Only users can be blocked or unblocked.");
|
|
974
966
|
}
|
|
975
967
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.contacts.block({ id });
|
|
976
968
|
}
|
|
@@ -978,7 +970,7 @@ class MessageManager {
|
|
|
978
970
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").storage.assertUser("unblockUser");
|
|
979
971
|
const id = await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(userId);
|
|
980
972
|
if (!(id instanceof _2_tl_js_1.types.User)) {
|
|
981
|
-
throw new
|
|
973
|
+
throw new _0_errors_js_1.InputError("Only users can be blocked or unblocked.");
|
|
982
974
|
}
|
|
983
975
|
await __classPrivateFieldGet(this, _MessageManager_c, "f").api.contacts.unblock({ id });
|
|
984
976
|
}
|
|
@@ -998,7 +990,7 @@ class MessageManager {
|
|
|
998
990
|
return await (0, _3_types_js_2.constructChatMember)(participant, __classPrivateFieldGet(this, _MessageManager_c, "f").getEntity);
|
|
999
991
|
}
|
|
1000
992
|
else {
|
|
1001
|
-
throw new
|
|
993
|
+
throw new _0_errors_js_1.InputError("Expected a channel, supergroup, or group ID. Got a user ID instead.");
|
|
1002
994
|
}
|
|
1003
995
|
}
|
|
1004
996
|
async setChatStickerSet(chatId, setName) {
|
|
@@ -1011,24 +1003,30 @@ class MessageManager {
|
|
|
1011
1003
|
}
|
|
1012
1004
|
async stopPoll(chatId, messageId, params) {
|
|
1013
1005
|
const message = await this.getMessage(chatId, messageId);
|
|
1014
|
-
if (
|
|
1015
|
-
|
|
1016
|
-
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
1017
|
-
id: messageId,
|
|
1018
|
-
media: new _2_tl_js_1.types.InputMediaPoll({
|
|
1019
|
-
poll: new _2_tl_js_1.types.Poll({
|
|
1020
|
-
id: BigInt(message.poll.id),
|
|
1021
|
-
closed: true,
|
|
1022
|
-
question: "",
|
|
1023
|
-
answers: [],
|
|
1024
|
-
}),
|
|
1025
|
-
}),
|
|
1026
|
-
reply_markup: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params),
|
|
1027
|
-
});
|
|
1028
|
-
const message_ = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1029
|
-
return (0, _3_types_js_2.assertMessageType)(message_, "poll").poll;
|
|
1006
|
+
if (!message) {
|
|
1007
|
+
throw new _0_errors_js_1.InputError("Message not found.");
|
|
1030
1008
|
}
|
|
1031
|
-
(
|
|
1009
|
+
if (!("poll" in message)) {
|
|
1010
|
+
throw new _0_errors_js_1.InputError("Message is not a poll.");
|
|
1011
|
+
}
|
|
1012
|
+
if (message.poll.isClosed) {
|
|
1013
|
+
throw new _0_errors_js_1.InputError("Poll is already stopped.");
|
|
1014
|
+
}
|
|
1015
|
+
const result = await __classPrivateFieldGet(this, _MessageManager_c, "f").api.messages.editMessage({
|
|
1016
|
+
peer: await __classPrivateFieldGet(this, _MessageManager_c, "f").getInputPeer(chatId),
|
|
1017
|
+
id: messageId,
|
|
1018
|
+
media: new _2_tl_js_1.types.InputMediaPoll({
|
|
1019
|
+
poll: new _2_tl_js_1.types.Poll({
|
|
1020
|
+
id: BigInt(message.poll.id),
|
|
1021
|
+
closed: true,
|
|
1022
|
+
question: "",
|
|
1023
|
+
answers: [],
|
|
1024
|
+
}),
|
|
1025
|
+
}),
|
|
1026
|
+
reply_markup: await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_constructReplyMarkup).call(this, params),
|
|
1027
|
+
});
|
|
1028
|
+
const message_ = await __classPrivateFieldGet(this, _MessageManager_instances, "m", _MessageManager_updatesToMessages).call(this, chatId, result).then((v) => v[0]);
|
|
1029
|
+
return (0, _3_types_js_2.assertMessageType)(message_, "poll").poll;
|
|
1032
1030
|
}
|
|
1033
1031
|
async editMessageLiveLocation(chatId, messageId, latitude, longitude, params) {
|
|
1034
1032
|
const message = await this.getMessage(chatId, messageId);
|
|
@@ -1124,7 +1122,7 @@ _MessageManager_c = new WeakMap(), _MessageManager_LresolveFileId = new WeakMap(
|
|
|
1124
1122
|
if (media == null) {
|
|
1125
1123
|
if (typeof document === "string" && (0, _0_utilities_js_1.isHttpUrl)(document)) {
|
|
1126
1124
|
if (!urlSupported) {
|
|
1127
|
-
throw new
|
|
1125
|
+
throw new _0_errors_js_1.InputError("URL not supported.");
|
|
1128
1126
|
}
|
|
1129
1127
|
media = new _2_tl_js_1.types.InputMediaDocumentExternal({ url: document, spoiler });
|
|
1130
1128
|
}
|
|
@@ -13,6 +13,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
|
|
|
13
13
|
var _ChatListManager_instances, _ChatListManager_c, _ChatListManager_LgetChats, _ChatListManager_sendChatUpdate, _ChatListManager_chats, _ChatListManager_archivedChats, _ChatListManager_chatsLoadedFromStorage, _ChatListManager_tryGetChatId, _ChatListManager_getChatAnywhere, _ChatListManager_getChatList, _ChatListManager_loadChatsFromStorage, _ChatListManager_getLoadedChats, _ChatListManager_pinnedChats, _ChatListManager_pinnedArchiveChats, _ChatListManager_storageHadPinnedChats, _ChatListManager_pinnedChatsLoaded, _ChatListManager_loadPinnedChats, _ChatListManager_fetchPinnedChats, _ChatListManager_getPinnedChats, _ChatListManager_updateOrAddChat, _ChatListManager_removeChat, _ChatListManager_handleUpdateFolderPeers, _ChatListManager_handleUpdatePinnedDialogs, _ChatListManager_handleUpdateChannel, _ChatListManager_handleUpdateChat, _ChatListManager_handleUpdateUser, _ChatListManager_fetchChats;
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.ChatListManager = void 0;
|
|
16
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
16
17
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
17
18
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
18
19
|
const _3_types_js_1 = require("../3_types.js");
|
|
@@ -101,7 +102,7 @@ class ChatListManager {
|
|
|
101
102
|
await __classPrivateFieldGet(this, _ChatListManager_instances, "m", _ChatListManager_loadChatsFromStorage).call(this);
|
|
102
103
|
}
|
|
103
104
|
if (after && !__classPrivateFieldGet(this, _ChatListManager_chats, "f").get(after.id)) {
|
|
104
|
-
throw new
|
|
105
|
+
throw new _0_errors_js_1.InputError("Invalid after");
|
|
105
106
|
}
|
|
106
107
|
if (limit <= 0 || limit > 100) {
|
|
107
108
|
limit = 100;
|
|
@@ -262,7 +263,7 @@ _ChatListManager_c = new WeakMap(), _ChatListManager_LgetChats = new WeakMap(),
|
|
|
262
263
|
case 1:
|
|
263
264
|
return __classPrivateFieldGet(this, _ChatListManager_archivedChats, "f");
|
|
264
265
|
default:
|
|
265
|
-
throw new Error(
|
|
266
|
+
throw new Error(`Invalid chat list: ${listId}`);
|
|
266
267
|
}
|
|
267
268
|
}, _ChatListManager_loadChatsFromStorage = async function _ChatListManager_loadChatsFromStorage() {
|
|
268
269
|
const chats = await __classPrivateFieldGet(this, _ChatListManager_c, "f").storage.getChats(0);
|
|
@@ -14,6 +14,7 @@ var _StoryManager_instances, _StoryManager_c, _StoryManager_updatesToStory, _Sto
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.StoryManager = void 0;
|
|
16
16
|
const _0_deps_js_1 = require("../0_deps.js");
|
|
17
|
+
const _0_errors_js_1 = require("../0_errors.js");
|
|
17
18
|
const _1_utilities_js_1 = require("../1_utilities.js");
|
|
18
19
|
const _2_tl_js_1 = require("../2_tl.js");
|
|
19
20
|
const _3_types_js_1 = require("../3_types.js");
|
|
@@ -38,7 +39,7 @@ class StoryManager {
|
|
|
38
39
|
}
|
|
39
40
|
if (media == null) {
|
|
40
41
|
if (typeof source === "string" && (0, _0_utilities_js_1.isHttpUrl)(source)) {
|
|
41
|
-
throw new
|
|
42
|
+
throw new _0_errors_js_1.InputError("URL not supported.");
|
|
42
43
|
}
|
|
43
44
|
else {
|
|
44
45
|
const [contents, fileName_] = await (0, _0_utilities_js_1.getFileContents)(source);
|
|
@@ -229,7 +229,7 @@ export declare class Client<C extends Context = Context> extends Composer<C> {
|
|
|
229
229
|
* Before establishing the connection, the session is saved.
|
|
230
230
|
*/
|
|
231
231
|
connect(): Promise<void>;
|
|
232
|
-
reconnect(dc
|
|
232
|
+
reconnect(dc?: DC): Promise<void>;
|
|
233
233
|
[handleMigrationError](err: Migrate): Promise<void>;
|
|
234
234
|
disconnect(): Promise<void>;
|
|
235
235
|
/**
|