teleproto 1.214.0
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/CryptoFile.d.ts +2 -0
- package/CryptoFile.js +37 -0
- package/Helpers.d.ts +150 -0
- package/Helpers.js +477 -0
- package/LICENSE +23 -0
- package/Password.d.ts +14 -0
- package/Password.js +270 -0
- package/README.md +98 -0
- package/Utils.d.ts +227 -0
- package/Utils.js +1247 -0
- package/Version.d.ts +1 -0
- package/Version.js +4 -0
- package/client/2fa.d.ts +48 -0
- package/client/2fa.js +108 -0
- package/client/TelegramClient.d.ts +1043 -0
- package/client/TelegramClient.js +1181 -0
- package/client/account.d.ts +0 -0
- package/client/account.js +1 -0
- package/client/auth.d.ts +92 -0
- package/client/auth.js +388 -0
- package/client/bots.d.ts +6 -0
- package/client/bots.js +23 -0
- package/client/buttons.d.ts +4 -0
- package/client/buttons.js +86 -0
- package/client/chats.d.ts +45 -0
- package/client/chats.js +350 -0
- package/client/dialogs.d.ts +52 -0
- package/client/dialogs.js +174 -0
- package/client/downloads.d.ts +156 -0
- package/client/downloads.js +614 -0
- package/client/fs.d.ts +1 -0
- package/client/fs.js +17 -0
- package/client/index.d.ts +15 -0
- package/client/index.js +64 -0
- package/client/messageParse.d.ts +17 -0
- package/client/messageParse.js +191 -0
- package/client/messages.d.ts +263 -0
- package/client/messages.js +813 -0
- package/client/os.d.ts +2 -0
- package/client/os.js +37 -0
- package/client/path.d.ts +2 -0
- package/client/path.js +7 -0
- package/client/telegramBaseClient.d.ts +237 -0
- package/client/telegramBaseClient.js +368 -0
- package/client/updates.d.ts +33 -0
- package/client/updates.js +260 -0
- package/client/uploads.d.ts +136 -0
- package/client/uploads.js +514 -0
- package/client/users.d.ts +29 -0
- package/client/users.js +490 -0
- package/crypto/AuthKey.d.ts +19 -0
- package/crypto/AuthKey.js +76 -0
- package/crypto/CTR.d.ts +5 -0
- package/crypto/CTR.js +16 -0
- package/crypto/Factorizator.d.ts +19 -0
- package/crypto/Factorizator.js +74 -0
- package/crypto/IGE.d.ts +11 -0
- package/crypto/IGE.js +115 -0
- package/crypto/RSA.d.ts +14 -0
- package/crypto/RSA.js +70 -0
- package/crypto/converters.d.ts +19 -0
- package/crypto/converters.js +52 -0
- package/crypto/crypto.d.ts +19 -0
- package/crypto/crypto.js +58 -0
- package/crypto/words.d.ts +6 -0
- package/crypto/words.js +47 -0
- package/define.d.ts +77 -0
- package/entityCache.d.ts +7 -0
- package/entityCache.js +79 -0
- package/errors/Common.d.ts +71 -0
- package/errors/Common.js +122 -0
- package/errors/RPCBaseErrors.d.ts +84 -0
- package/errors/RPCBaseErrors.js +134 -0
- package/errors/RPCErrorList.d.ts +37 -0
- package/errors/RPCErrorList.js +117 -0
- package/errors/index.d.ts +11 -0
- package/errors/index.js +32 -0
- package/events/Album.d.ts +36 -0
- package/events/Album.js +104 -0
- package/events/CallbackQuery.d.ts +73 -0
- package/events/CallbackQuery.js +193 -0
- package/events/DeletedMessage.d.ts +45 -0
- package/events/DeletedMessage.js +63 -0
- package/events/EditedMessage.d.ts +30 -0
- package/events/EditedMessage.js +41 -0
- package/events/NewMessage.d.ts +89 -0
- package/events/NewMessage.js +182 -0
- package/events/Raw.d.ts +29 -0
- package/events/Raw.js +43 -0
- package/events/common.d.ts +66 -0
- package/events/common.js +141 -0
- package/events/index.d.ts +2 -0
- package/events/index.js +8 -0
- package/extensions/AsyncQueue.d.ts +10 -0
- package/extensions/AsyncQueue.js +32 -0
- package/extensions/BinaryReader.d.ts +99 -0
- package/extensions/BinaryReader.js +242 -0
- package/extensions/BinaryWriter.d.ts +6 -0
- package/extensions/BinaryWriter.js +15 -0
- package/extensions/Deferred.d.ts +8 -0
- package/extensions/Deferred.js +16 -0
- package/extensions/Logger.d.ts +54 -0
- package/extensions/Logger.js +128 -0
- package/extensions/MessagePacker.d.ts +21 -0
- package/extensions/MessagePacker.js +154 -0
- package/extensions/PendingState.d.ts +12 -0
- package/extensions/PendingState.js +29 -0
- package/extensions/PromisedNetSockets.d.ts +24 -0
- package/extensions/PromisedNetSockets.js +192 -0
- package/extensions/PromisedWebSockets.d.ts +18 -0
- package/extensions/PromisedWebSockets.js +124 -0
- package/extensions/html.d.ts +5 -0
- package/extensions/html.js +228 -0
- package/extensions/index.d.ts +7 -0
- package/extensions/index.js +17 -0
- package/extensions/markdown.d.ts +5 -0
- package/extensions/markdown.js +76 -0
- package/extensions/markdownv2.d.ts +5 -0
- package/extensions/markdownv2.js +51 -0
- package/extensions/net.d.ts +1 -0
- package/extensions/net.js +17 -0
- package/extensions/socks.d.ts +1 -0
- package/extensions/socks.js +17 -0
- package/index.d.ts +14 -0
- package/index.js +62 -0
- package/inspect.d.ts +1 -0
- package/inspect.js +5 -0
- package/network/Authenticator.d.ts +12 -0
- package/network/Authenticator.js +192 -0
- package/network/MTProtoPlainSender.d.ts +19 -0
- package/network/MTProtoPlainSender.js +74 -0
- package/network/MTProtoSender.d.ts +290 -0
- package/network/MTProtoSender.js +873 -0
- package/network/MTProtoState.d.ts +102 -0
- package/network/MTProtoState.js +267 -0
- package/network/RequestState.d.ts +18 -0
- package/network/RequestState.js +35 -0
- package/network/connection/Connection.d.ts +69 -0
- package/network/connection/Connection.js +162 -0
- package/network/connection/TCPAbridged.d.ts +19 -0
- package/network/connection/TCPAbridged.js +58 -0
- package/network/connection/TCPFull.d.ts +16 -0
- package/network/connection/TCPFull.js +61 -0
- package/network/connection/TCPMTProxy.d.ts +49 -0
- package/network/connection/TCPMTProxy.js +121 -0
- package/network/connection/TCPObfuscated.d.ts +18 -0
- package/network/connection/TCPObfuscated.js +78 -0
- package/network/connection/index.d.ts +4 -0
- package/network/connection/index.js +11 -0
- package/network/index.d.ts +11 -0
- package/network/index.js +23 -0
- package/package.json +50 -0
- package/requestIter.d.ts +24 -0
- package/requestIter.js +109 -0
- package/sessions/Abstract.d.ts +103 -0
- package/sessions/Abstract.js +6 -0
- package/sessions/Memory.d.ts +38 -0
- package/sessions/Memory.js +272 -0
- package/sessions/StoreSession.d.ts +14 -0
- package/sessions/StoreSession.js +77 -0
- package/sessions/StringSession.d.ts +32 -0
- package/sessions/StringSession.js +116 -0
- package/sessions/index.d.ts +4 -0
- package/sessions/index.js +11 -0
- package/sessions/localStorage.d.ts +1 -0
- package/sessions/localStorage.js +4 -0
- package/tl/AllTLObjects.d.ts +3 -0
- package/tl/AllTLObjects.js +17 -0
- package/tl/MTProtoRequest.d.ts +18 -0
- package/tl/MTProtoRequest.js +38 -0
- package/tl/api.d.ts +32488 -0
- package/tl/api.js +507 -0
- package/tl/apiTl.d.ts +2 -0
- package/tl/apiTl.js +2209 -0
- package/tl/core/GZIPPacked.d.ts +15 -0
- package/tl/core/GZIPPacked.js +51 -0
- package/tl/core/MessageContainer.d.ts +12 -0
- package/tl/core/MessageContainer.js +42 -0
- package/tl/core/RPCResult.d.ts +14 -0
- package/tl/core/RPCResult.js +32 -0
- package/tl/core/TLMessage.d.ts +10 -0
- package/tl/core/TLMessage.js +14 -0
- package/tl/core/index.d.ts +6 -0
- package/tl/core/index.js +16 -0
- package/tl/custom/button.d.ts +24 -0
- package/tl/custom/button.js +78 -0
- package/tl/custom/chatGetter.d.ts +29 -0
- package/tl/custom/chatGetter.js +116 -0
- package/tl/custom/dialog.d.ts +30 -0
- package/tl/custom/dialog.js +40 -0
- package/tl/custom/draft.d.ts +21 -0
- package/tl/custom/draft.js +48 -0
- package/tl/custom/file.d.ts +21 -0
- package/tl/custom/file.js +68 -0
- package/tl/custom/forward.d.ts +15 -0
- package/tl/custom/forward.js +47 -0
- package/tl/custom/index.d.ts +1 -0
- package/tl/custom/index.js +5 -0
- package/tl/custom/inlineResult.d.ts +32 -0
- package/tl/custom/inlineResult.js +87 -0
- package/tl/custom/inlineResults.d.ts +20 -0
- package/tl/custom/inlineResults.js +26 -0
- package/tl/custom/message.d.ts +427 -0
- package/tl/custom/message.js +716 -0
- package/tl/custom/messageButton.d.ts +54 -0
- package/tl/custom/messageButton.js +152 -0
- package/tl/custom/senderGetter.d.ts +28 -0
- package/tl/custom/senderGetter.js +55 -0
- package/tl/generateModule.d.ts +1 -0
- package/tl/generateModule.js +17 -0
- package/tl/generationHelpers.d.ts +11 -0
- package/tl/generationHelpers.js +289 -0
- package/tl/index.d.ts +3 -0
- package/tl/index.js +10 -0
- package/tl/patched/index.d.ts +2 -0
- package/tl/patched/index.js +76 -0
- package/tl/schemaTl.d.ts +2 -0
- package/tl/schemaTl.js +64 -0
- package/tl/types-generator/generate.d.ts +1 -0
- package/tl/types-generator/generate.js +84 -0
- package/tl/types-generator/template.d.ts +6 -0
- package/tl/types-generator/template.js +257 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ProxyInterface } from "../network/connection/TCPMTProxy";
|
|
2
|
+
export declare class PromisedNetSockets {
|
|
3
|
+
private client?;
|
|
4
|
+
private closed;
|
|
5
|
+
private stream;
|
|
6
|
+
private canRead?;
|
|
7
|
+
private resolveRead;
|
|
8
|
+
private proxy?;
|
|
9
|
+
constructor(proxy?: ProxyInterface);
|
|
10
|
+
readExactly(number: number): Promise<Buffer<ArrayBuffer>>;
|
|
11
|
+
read(number: number): Promise<Buffer<ArrayBuffer>>;
|
|
12
|
+
readAll(): Promise<Buffer<ArrayBufferLike>>;
|
|
13
|
+
/**
|
|
14
|
+
* Creates a new connection
|
|
15
|
+
* @param port
|
|
16
|
+
* @param ip
|
|
17
|
+
* @returns {Promise<void>}
|
|
18
|
+
*/
|
|
19
|
+
connect(port: number, ip: string): Promise<unknown>;
|
|
20
|
+
write(data: Buffer): void;
|
|
21
|
+
close(): Promise<void>;
|
|
22
|
+
receive(): Promise<void>;
|
|
23
|
+
toString(): string;
|
|
24
|
+
}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.PromisedNetSockets = void 0;
|
|
37
|
+
const net = __importStar(require("./net"));
|
|
38
|
+
const socks_1 = require("./socks");
|
|
39
|
+
const async_mutex_1 = require("async-mutex");
|
|
40
|
+
const mutex = new async_mutex_1.Mutex();
|
|
41
|
+
const closeError = new Error("NetSocket was closed");
|
|
42
|
+
class PromisedNetSockets {
|
|
43
|
+
constructor(proxy) {
|
|
44
|
+
this.client = undefined;
|
|
45
|
+
this.closed = true;
|
|
46
|
+
this.stream = Buffer.alloc(0);
|
|
47
|
+
if (proxy) {
|
|
48
|
+
// we only want to use this when it's not an MTProto proxy.
|
|
49
|
+
if (!("MTProxy" in proxy)) {
|
|
50
|
+
if (!proxy.ip || !proxy.port || !proxy.socksType) {
|
|
51
|
+
throw new Error(`Invalid sockets params: ip=${proxy.ip}, port=${proxy.port}, socksType=${proxy.socksType}`);
|
|
52
|
+
}
|
|
53
|
+
this.proxy = proxy;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async readExactly(number) {
|
|
58
|
+
let readData = Buffer.alloc(0);
|
|
59
|
+
while (true) {
|
|
60
|
+
const thisTime = await this.read(number);
|
|
61
|
+
readData = Buffer.concat([readData, thisTime]);
|
|
62
|
+
number = number - thisTime.length;
|
|
63
|
+
if (!number || number === -437) {
|
|
64
|
+
return readData;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
async read(number) {
|
|
69
|
+
if (this.closed) {
|
|
70
|
+
throw closeError;
|
|
71
|
+
}
|
|
72
|
+
await this.canRead;
|
|
73
|
+
if (this.closed) {
|
|
74
|
+
throw closeError;
|
|
75
|
+
}
|
|
76
|
+
const toReturn = this.stream.slice(0, number);
|
|
77
|
+
this.stream = this.stream.slice(number);
|
|
78
|
+
if (this.stream.length === 0) {
|
|
79
|
+
this.canRead = new Promise((resolve) => {
|
|
80
|
+
this.resolveRead = resolve;
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return toReturn;
|
|
84
|
+
}
|
|
85
|
+
async readAll() {
|
|
86
|
+
if (this.closed || !(await this.canRead)) {
|
|
87
|
+
throw closeError;
|
|
88
|
+
}
|
|
89
|
+
const toReturn = this.stream;
|
|
90
|
+
this.stream = Buffer.alloc(0);
|
|
91
|
+
this.canRead = new Promise((resolve) => {
|
|
92
|
+
this.resolveRead = resolve;
|
|
93
|
+
});
|
|
94
|
+
return toReturn;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new connection
|
|
98
|
+
* @param port
|
|
99
|
+
* @param ip
|
|
100
|
+
* @returns {Promise<void>}
|
|
101
|
+
*/
|
|
102
|
+
async connect(port, ip) {
|
|
103
|
+
this.stream = Buffer.alloc(0);
|
|
104
|
+
let connected = false;
|
|
105
|
+
if (this.proxy) {
|
|
106
|
+
const info = await socks_1.SocksClient.createConnection({
|
|
107
|
+
proxy: {
|
|
108
|
+
host: this.proxy.ip,
|
|
109
|
+
port: this.proxy.port,
|
|
110
|
+
type: this.proxy.socksType,
|
|
111
|
+
userId: this.proxy.username,
|
|
112
|
+
password: this.proxy.password,
|
|
113
|
+
},
|
|
114
|
+
command: "connect",
|
|
115
|
+
timeout: (this.proxy.timeout || 5) * 1000,
|
|
116
|
+
destination: {
|
|
117
|
+
host: ip,
|
|
118
|
+
port: port,
|
|
119
|
+
},
|
|
120
|
+
});
|
|
121
|
+
this.client = info.socket;
|
|
122
|
+
connected = true;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
this.client = new net.Socket();
|
|
126
|
+
}
|
|
127
|
+
this.canRead = new Promise((resolve) => {
|
|
128
|
+
this.resolveRead = resolve;
|
|
129
|
+
});
|
|
130
|
+
this.closed = false;
|
|
131
|
+
return new Promise((resolve, reject) => {
|
|
132
|
+
if (this.client) {
|
|
133
|
+
if (connected) {
|
|
134
|
+
this.receive();
|
|
135
|
+
resolve(this);
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
this.client.connect(port, ip, () => {
|
|
139
|
+
this.receive();
|
|
140
|
+
resolve(this);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
this.client.on("error", reject);
|
|
144
|
+
this.client.on("close", () => {
|
|
145
|
+
if (this.client && this.client.destroyed) {
|
|
146
|
+
if (this.resolveRead) {
|
|
147
|
+
this.resolveRead(false);
|
|
148
|
+
}
|
|
149
|
+
this.closed = true;
|
|
150
|
+
}
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
write(data) {
|
|
156
|
+
if (this.closed) {
|
|
157
|
+
throw closeError;
|
|
158
|
+
}
|
|
159
|
+
if (this.client) {
|
|
160
|
+
this.client.write(data);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
async close() {
|
|
164
|
+
if (this.client) {
|
|
165
|
+
await this.client.destroy();
|
|
166
|
+
this.client.unref();
|
|
167
|
+
}
|
|
168
|
+
this.closed = true;
|
|
169
|
+
}
|
|
170
|
+
async receive() {
|
|
171
|
+
if (this.client) {
|
|
172
|
+
this.client.on("data", async (message) => {
|
|
173
|
+
const release = await mutex.acquire();
|
|
174
|
+
try {
|
|
175
|
+
let data;
|
|
176
|
+
//CONTEST BROWSER
|
|
177
|
+
this.stream = Buffer.concat([this.stream, message]);
|
|
178
|
+
if (this.resolveRead) {
|
|
179
|
+
this.resolveRead(true);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
finally {
|
|
183
|
+
release();
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
toString() {
|
|
189
|
+
return "PromisedNetSocket";
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
exports.PromisedNetSockets = PromisedNetSockets;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export declare class PromisedWebSockets {
|
|
2
|
+
private closed;
|
|
3
|
+
private stream;
|
|
4
|
+
private canRead?;
|
|
5
|
+
private resolveRead;
|
|
6
|
+
private client;
|
|
7
|
+
private website?;
|
|
8
|
+
constructor();
|
|
9
|
+
readExactly(number: number): Promise<Buffer<ArrayBuffer>>;
|
|
10
|
+
read(number: number): Promise<Buffer<ArrayBuffer>>;
|
|
11
|
+
readAll(): Promise<Buffer<ArrayBufferLike>>;
|
|
12
|
+
getWebSocketLink(ip: string, port: number, testServers: boolean): string;
|
|
13
|
+
connect(port: number, ip: string, testServers?: boolean): Promise<unknown>;
|
|
14
|
+
write(data: Buffer): void;
|
|
15
|
+
close(): Promise<void>;
|
|
16
|
+
receive(): Promise<void>;
|
|
17
|
+
toString(): string;
|
|
18
|
+
}
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PromisedWebSockets = void 0;
|
|
4
|
+
const websocket_1 = require("websocket");
|
|
5
|
+
const async_mutex_1 = require("async-mutex");
|
|
6
|
+
const mutex = new async_mutex_1.Mutex();
|
|
7
|
+
const closeError = new Error("WebSocket was closed");
|
|
8
|
+
class PromisedWebSockets {
|
|
9
|
+
constructor() {
|
|
10
|
+
this.client = undefined;
|
|
11
|
+
this.stream = Buffer.alloc(0);
|
|
12
|
+
this.closed = true;
|
|
13
|
+
}
|
|
14
|
+
async readExactly(number) {
|
|
15
|
+
let readData = Buffer.alloc(0);
|
|
16
|
+
while (true) {
|
|
17
|
+
const thisTime = await this.read(number);
|
|
18
|
+
readData = Buffer.concat([readData, thisTime]);
|
|
19
|
+
number = number - thisTime.length;
|
|
20
|
+
if (!number) {
|
|
21
|
+
return readData;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
async read(number) {
|
|
26
|
+
if (this.closed) {
|
|
27
|
+
throw closeError;
|
|
28
|
+
}
|
|
29
|
+
await this.canRead;
|
|
30
|
+
if (this.closed) {
|
|
31
|
+
throw closeError;
|
|
32
|
+
}
|
|
33
|
+
const toReturn = this.stream.slice(0, number);
|
|
34
|
+
this.stream = this.stream.slice(number);
|
|
35
|
+
if (this.stream.length === 0) {
|
|
36
|
+
this.canRead = new Promise((resolve) => {
|
|
37
|
+
this.resolveRead = resolve;
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
return toReturn;
|
|
41
|
+
}
|
|
42
|
+
async readAll() {
|
|
43
|
+
if (this.closed || !(await this.canRead)) {
|
|
44
|
+
throw closeError;
|
|
45
|
+
}
|
|
46
|
+
const toReturn = this.stream;
|
|
47
|
+
this.stream = Buffer.alloc(0);
|
|
48
|
+
this.canRead = new Promise((resolve) => {
|
|
49
|
+
this.resolveRead = resolve;
|
|
50
|
+
});
|
|
51
|
+
return toReturn;
|
|
52
|
+
}
|
|
53
|
+
getWebSocketLink(ip, port, testServers) {
|
|
54
|
+
if (port === 443) {
|
|
55
|
+
return `wss://${ip}:${port}/apiws${testServers ? "_test" : ""}`;
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
return `ws://${ip}:${port}/apiws${testServers ? "_test" : ""}`;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
async connect(port, ip, testServers = false) {
|
|
62
|
+
this.stream = Buffer.alloc(0);
|
|
63
|
+
this.canRead = new Promise((resolve) => {
|
|
64
|
+
this.resolveRead = resolve;
|
|
65
|
+
});
|
|
66
|
+
this.closed = false;
|
|
67
|
+
this.website = this.getWebSocketLink(ip, port, testServers);
|
|
68
|
+
this.client = new websocket_1.w3cwebsocket(this.website, "binary");
|
|
69
|
+
return new Promise((resolve, reject) => {
|
|
70
|
+
if (this.client) {
|
|
71
|
+
this.client.onopen = () => {
|
|
72
|
+
this.receive();
|
|
73
|
+
resolve(this);
|
|
74
|
+
};
|
|
75
|
+
this.client.onerror = (error) => {
|
|
76
|
+
reject(error);
|
|
77
|
+
};
|
|
78
|
+
this.client.onclose = () => {
|
|
79
|
+
if (this.resolveRead) {
|
|
80
|
+
this.resolveRead(false);
|
|
81
|
+
}
|
|
82
|
+
this.closed = true;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
write(data) {
|
|
88
|
+
if (this.closed) {
|
|
89
|
+
throw closeError;
|
|
90
|
+
}
|
|
91
|
+
if (this.client) {
|
|
92
|
+
this.client.send(data);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
async close() {
|
|
96
|
+
if (this.client) {
|
|
97
|
+
await this.client.close();
|
|
98
|
+
}
|
|
99
|
+
this.closed = true;
|
|
100
|
+
}
|
|
101
|
+
async receive() {
|
|
102
|
+
if (this.client) {
|
|
103
|
+
this.client.onmessage = async (message) => {
|
|
104
|
+
const release = await mutex.acquire();
|
|
105
|
+
try {
|
|
106
|
+
let data;
|
|
107
|
+
//CONTEST BROWSER
|
|
108
|
+
data = Buffer.from(await new Response(message.data).arrayBuffer());
|
|
109
|
+
this.stream = Buffer.concat([this.stream, data]);
|
|
110
|
+
if (this.resolveRead) {
|
|
111
|
+
this.resolveRead(true);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
finally {
|
|
115
|
+
release();
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
toString() {
|
|
121
|
+
return "PromisedWebSocket";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
exports.PromisedWebSockets = PromisedWebSockets;
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HTMLParser = void 0;
|
|
4
|
+
const tl_1 = require("../tl");
|
|
5
|
+
const index_1 = require("../index");
|
|
6
|
+
class HTMLParser {
|
|
7
|
+
static parse(html) {
|
|
8
|
+
if (!html) {
|
|
9
|
+
return [html, []];
|
|
10
|
+
}
|
|
11
|
+
const text = [];
|
|
12
|
+
const entities = [];
|
|
13
|
+
const openTags = [];
|
|
14
|
+
const buildingEntities = new Map();
|
|
15
|
+
let pos = 0;
|
|
16
|
+
let textPos = 0;
|
|
17
|
+
while (pos < html.length) {
|
|
18
|
+
const tagStart = html.indexOf('<', pos);
|
|
19
|
+
if (tagStart === -1) {
|
|
20
|
+
const textContent = html.substring(pos);
|
|
21
|
+
text.push(textContent);
|
|
22
|
+
for (const [_, entity] of buildingEntities) {
|
|
23
|
+
entity.length += textContent.length;
|
|
24
|
+
}
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
if (tagStart > pos) {
|
|
28
|
+
const textContent = html.substring(pos, tagStart);
|
|
29
|
+
text.push(textContent);
|
|
30
|
+
for (const [_, entity] of buildingEntities) {
|
|
31
|
+
entity.length += textContent.length;
|
|
32
|
+
}
|
|
33
|
+
textPos += textContent.length;
|
|
34
|
+
}
|
|
35
|
+
const tagEnd = html.indexOf('>', tagStart);
|
|
36
|
+
if (tagEnd === -1) {
|
|
37
|
+
text.push(html.substring(tagStart));
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
const tagContent = html.substring(tagStart + 1, tagEnd);
|
|
41
|
+
if (tagContent.startsWith('/')) {
|
|
42
|
+
const tagName = tagContent.substring(1).trim().toLowerCase();
|
|
43
|
+
const entity = buildingEntities.get(tagName);
|
|
44
|
+
if (entity) {
|
|
45
|
+
buildingEntities.delete(tagName);
|
|
46
|
+
entities.push(entity);
|
|
47
|
+
}
|
|
48
|
+
const index = openTags.findIndex(t => t.name === tagName);
|
|
49
|
+
if (index !== -1) {
|
|
50
|
+
openTags.splice(index, 1);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
let tagName = tagContent;
|
|
55
|
+
let attributes = {};
|
|
56
|
+
const spaceIndex = tagContent.indexOf(' ');
|
|
57
|
+
if (spaceIndex !== -1) {
|
|
58
|
+
tagName = tagContent.substring(0, spaceIndex).toLowerCase();
|
|
59
|
+
const attrStr = tagContent.substring(spaceIndex + 1);
|
|
60
|
+
const attrRegex = /([^\s=]+)(?:=(?:"([^"]*)"|'([^']*)'|([^\s>]*)))?/g;
|
|
61
|
+
let match;
|
|
62
|
+
while ((match = attrRegex.exec(attrStr)) !== null) {
|
|
63
|
+
const name = match[1];
|
|
64
|
+
const value = match[2] || match[3] || match[4] || '';
|
|
65
|
+
attributes[name] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else {
|
|
69
|
+
tagName = tagContent.toLowerCase();
|
|
70
|
+
}
|
|
71
|
+
if (tagName.endsWith('/')) {
|
|
72
|
+
tagName = tagName.slice(0, -1);
|
|
73
|
+
pos = tagEnd + 1;
|
|
74
|
+
continue;
|
|
75
|
+
}
|
|
76
|
+
let tagMeta = undefined;
|
|
77
|
+
openTags.unshift({ name: tagName, meta: tagMeta });
|
|
78
|
+
let EntityType;
|
|
79
|
+
const args = {};
|
|
80
|
+
if (tagName === "strong" || tagName === "b") {
|
|
81
|
+
EntityType = tl_1.Api.MessageEntityBold;
|
|
82
|
+
}
|
|
83
|
+
else if (tagName === "spoiler") {
|
|
84
|
+
EntityType = tl_1.Api.MessageEntitySpoiler;
|
|
85
|
+
}
|
|
86
|
+
else if (tagName === "em" || tagName === "i") {
|
|
87
|
+
EntityType = tl_1.Api.MessageEntityItalic;
|
|
88
|
+
}
|
|
89
|
+
else if (tagName === "u") {
|
|
90
|
+
EntityType = tl_1.Api.MessageEntityUnderline;
|
|
91
|
+
}
|
|
92
|
+
else if (tagName === "del" || tagName === "s") {
|
|
93
|
+
EntityType = tl_1.Api.MessageEntityStrike;
|
|
94
|
+
}
|
|
95
|
+
else if (tagName === "blockquote") {
|
|
96
|
+
EntityType = tl_1.Api.MessageEntityBlockquote;
|
|
97
|
+
if (attributes.expandable !== undefined) {
|
|
98
|
+
args.collapsed = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
else if (tagName === "code") {
|
|
102
|
+
const pre = buildingEntities.get("pre");
|
|
103
|
+
if (pre && pre instanceof tl_1.Api.MessageEntityPre) {
|
|
104
|
+
if (attributes.class && attributes.class.startsWith('language-')) {
|
|
105
|
+
pre.language = attributes.class.slice("language-".length);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
EntityType = tl_1.Api.MessageEntityCode;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
else if (tagName === "pre") {
|
|
113
|
+
EntityType = tl_1.Api.MessageEntityPre;
|
|
114
|
+
args["language"] = "";
|
|
115
|
+
}
|
|
116
|
+
else if (tagName === "a") {
|
|
117
|
+
let url = attributes.href;
|
|
118
|
+
if (url) {
|
|
119
|
+
if (url.startsWith("mailto:")) {
|
|
120
|
+
url = url.slice("mailto:".length);
|
|
121
|
+
EntityType = tl_1.Api.MessageEntityEmail;
|
|
122
|
+
tagMeta = url;
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
EntityType = tl_1.Api.MessageEntityTextUrl;
|
|
126
|
+
args["url"] = url;
|
|
127
|
+
}
|
|
128
|
+
openTags[0].meta = tagMeta;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
else if (tagName === "tg-emoji") {
|
|
132
|
+
EntityType = tl_1.Api.MessageEntityCustomEmoji;
|
|
133
|
+
args["documentId"] = attributes["emoji-id"];
|
|
134
|
+
}
|
|
135
|
+
if (EntityType && !buildingEntities.has(tagName)) {
|
|
136
|
+
buildingEntities.set(tagName, new EntityType(Object.assign({ offset: textPos, length: 0 }, args)));
|
|
137
|
+
}
|
|
138
|
+
if (tagName === "a" && tagMeta) {
|
|
139
|
+
text.push(tagMeta);
|
|
140
|
+
for (const [_, entity] of buildingEntities) {
|
|
141
|
+
entity.length += tagMeta.length;
|
|
142
|
+
}
|
|
143
|
+
textPos += tagMeta.length;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
pos = tagEnd + 1;
|
|
147
|
+
}
|
|
148
|
+
const finalText = text.join('');
|
|
149
|
+
return [index_1.helpers.stripText(finalText, entities), entities];
|
|
150
|
+
}
|
|
151
|
+
static unparse(text, entities, _offset = 0, _length) {
|
|
152
|
+
if (!text || !entities || !entities.length) {
|
|
153
|
+
return text;
|
|
154
|
+
}
|
|
155
|
+
if (_length == undefined) {
|
|
156
|
+
_length = text.length;
|
|
157
|
+
}
|
|
158
|
+
const html = [];
|
|
159
|
+
let lastOffset = 0;
|
|
160
|
+
for (let i = 0; i < entities.length; i++) {
|
|
161
|
+
const entity = entities[i];
|
|
162
|
+
if (entity.offset >= _offset + _length) {
|
|
163
|
+
break;
|
|
164
|
+
}
|
|
165
|
+
let relativeOffset = entity.offset - _offset;
|
|
166
|
+
if (relativeOffset > lastOffset) {
|
|
167
|
+
html.push(text.slice(lastOffset, relativeOffset));
|
|
168
|
+
}
|
|
169
|
+
else if (relativeOffset < lastOffset) {
|
|
170
|
+
continue;
|
|
171
|
+
}
|
|
172
|
+
let skipEntity = false;
|
|
173
|
+
let length = entity.length;
|
|
174
|
+
let entityText = this.unparse(text.slice(relativeOffset, relativeOffset + length), entities.slice(i + 1, entities.length), entity.offset, length);
|
|
175
|
+
if (entity instanceof tl_1.Api.MessageEntityBold) {
|
|
176
|
+
html.push(`<strong>${entityText}</strong>`);
|
|
177
|
+
}
|
|
178
|
+
else if (entity instanceof tl_1.Api.MessageEntitySpoiler) {
|
|
179
|
+
html.push(`<spoiler>${entityText}</spoiler>`);
|
|
180
|
+
}
|
|
181
|
+
else if (entity instanceof tl_1.Api.MessageEntityItalic) {
|
|
182
|
+
html.push(`<em>${entityText}</em>`);
|
|
183
|
+
}
|
|
184
|
+
else if (entity instanceof tl_1.Api.MessageEntityCode) {
|
|
185
|
+
html.push(`<code>${entityText}</code>`);
|
|
186
|
+
}
|
|
187
|
+
else if (entity instanceof tl_1.Api.MessageEntityUnderline) {
|
|
188
|
+
html.push(`<u>${entityText}</u>`);
|
|
189
|
+
}
|
|
190
|
+
else if (entity instanceof tl_1.Api.MessageEntityStrike) {
|
|
191
|
+
html.push(`<del>${entityText}</del>`);
|
|
192
|
+
}
|
|
193
|
+
else if (entity instanceof tl_1.Api.MessageEntityBlockquote) {
|
|
194
|
+
html.push(`<blockquote>${entityText}</blockquote>`);
|
|
195
|
+
}
|
|
196
|
+
else if (entity instanceof tl_1.Api.MessageEntityPre) {
|
|
197
|
+
if (entity.language) {
|
|
198
|
+
html.push(`<pre><code class="language-${entity.language}">${entityText}</code></pre>`);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
html.push(`<pre>${entityText}</pre>`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
else if (entity instanceof tl_1.Api.MessageEntityEmail) {
|
|
205
|
+
html.push(`<a href="mailto:${entityText}">${entityText}</a>`);
|
|
206
|
+
}
|
|
207
|
+
else if (entity instanceof tl_1.Api.MessageEntityUrl) {
|
|
208
|
+
html.push(`<a href="${entityText}">${entityText}</a>`);
|
|
209
|
+
}
|
|
210
|
+
else if (entity instanceof tl_1.Api.MessageEntityTextUrl) {
|
|
211
|
+
html.push(`<a href="${entity.url}">${entityText}</a>`);
|
|
212
|
+
}
|
|
213
|
+
else if (entity instanceof tl_1.Api.MessageEntityMentionName) {
|
|
214
|
+
html.push(`<a href="tg://user?id=${entity.userId}">${entityText}</a>`);
|
|
215
|
+
}
|
|
216
|
+
else if (entity instanceof tl_1.Api.MessageEntityCustomEmoji) {
|
|
217
|
+
html.push(`<tg-emoji emoji-id="${entity.documentId}">${entityText}</tg-emoji>`);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
skipEntity = true;
|
|
221
|
+
}
|
|
222
|
+
lastOffset = relativeOffset + (skipEntity ? 0 : length);
|
|
223
|
+
}
|
|
224
|
+
html.push(text.slice(lastOffset, text.length));
|
|
225
|
+
return html.join("");
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
exports.HTMLParser = HTMLParser;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Logger } from "./Logger";
|
|
2
|
+
export { BinaryWriter } from "./BinaryWriter";
|
|
3
|
+
export { BinaryReader } from "./BinaryReader";
|
|
4
|
+
export { PromisedWebSockets } from "./PromisedWebSockets";
|
|
5
|
+
export { PromisedNetSockets } from "./PromisedNetSockets";
|
|
6
|
+
export { MessagePacker } from "./MessagePacker";
|
|
7
|
+
export { AsyncQueue } from "./AsyncQueue";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AsyncQueue = exports.MessagePacker = exports.PromisedNetSockets = exports.PromisedWebSockets = exports.BinaryReader = exports.BinaryWriter = exports.Logger = void 0;
|
|
4
|
+
var Logger_1 = require("./Logger");
|
|
5
|
+
Object.defineProperty(exports, "Logger", { enumerable: true, get: function () { return Logger_1.Logger; } });
|
|
6
|
+
var BinaryWriter_1 = require("./BinaryWriter");
|
|
7
|
+
Object.defineProperty(exports, "BinaryWriter", { enumerable: true, get: function () { return BinaryWriter_1.BinaryWriter; } });
|
|
8
|
+
var BinaryReader_1 = require("./BinaryReader");
|
|
9
|
+
Object.defineProperty(exports, "BinaryReader", { enumerable: true, get: function () { return BinaryReader_1.BinaryReader; } });
|
|
10
|
+
var PromisedWebSockets_1 = require("./PromisedWebSockets");
|
|
11
|
+
Object.defineProperty(exports, "PromisedWebSockets", { enumerable: true, get: function () { return PromisedWebSockets_1.PromisedWebSockets; } });
|
|
12
|
+
var PromisedNetSockets_1 = require("./PromisedNetSockets");
|
|
13
|
+
Object.defineProperty(exports, "PromisedNetSockets", { enumerable: true, get: function () { return PromisedNetSockets_1.PromisedNetSockets; } });
|
|
14
|
+
var MessagePacker_1 = require("./MessagePacker");
|
|
15
|
+
Object.defineProperty(exports, "MessagePacker", { enumerable: true, get: function () { return MessagePacker_1.MessagePacker; } });
|
|
16
|
+
var AsyncQueue_1 = require("./AsyncQueue");
|
|
17
|
+
Object.defineProperty(exports, "AsyncQueue", { enumerable: true, get: function () { return AsyncQueue_1.AsyncQueue; } });
|