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,54 @@
|
|
|
1
|
+
import type { TelegramClient } from "../../client/TelegramClient";
|
|
2
|
+
import type { ButtonLike, EntityLike, MessageIDLike } from "../../define";
|
|
3
|
+
import { Api } from "../api";
|
|
4
|
+
import { inspect } from "../../inspect";
|
|
5
|
+
export declare class MessageButton {
|
|
6
|
+
private readonly _client;
|
|
7
|
+
private readonly _chat;
|
|
8
|
+
readonly button: ButtonLike;
|
|
9
|
+
private readonly _bot?;
|
|
10
|
+
private readonly _msgId;
|
|
11
|
+
[inspect.custom](): {
|
|
12
|
+
[key: string]: any;
|
|
13
|
+
};
|
|
14
|
+
constructor(client: TelegramClient, original: ButtonLike, chat: EntityLike, bot: EntityLike | undefined, msgId: MessageIDLike);
|
|
15
|
+
get client(): TelegramClient;
|
|
16
|
+
get text(): string;
|
|
17
|
+
get data(): Api.bytes | undefined;
|
|
18
|
+
get inlineQuery(): string | undefined;
|
|
19
|
+
get url(): string | undefined;
|
|
20
|
+
/**
|
|
21
|
+
* Emulates the behaviour of clicking this button.
|
|
22
|
+
|
|
23
|
+
If it's a normal `KeyboardButton` with text, a message will be
|
|
24
|
+
sent, and the sent `Message <Message>` returned.
|
|
25
|
+
|
|
26
|
+
If it's an inline `KeyboardButtonCallback` with text and data,
|
|
27
|
+
it will be "clicked" and the `BotCallbackAnswer` returned.
|
|
28
|
+
|
|
29
|
+
If it's an inline `KeyboardButtonSwitchInline` button, the
|
|
30
|
+
`StartBot` will be invoked and the resulting updates
|
|
31
|
+
returned.
|
|
32
|
+
|
|
33
|
+
If it's a `KeyboardButtonUrl`, the URL of the button will
|
|
34
|
+
be returned.
|
|
35
|
+
|
|
36
|
+
If it's a `KeyboardButtonRequestPhone`, you must indicate that you
|
|
37
|
+
want to ``sharePhone=True`` in order to share it. Sharing it is not a
|
|
38
|
+
default because it is a privacy concern and could happen accidentally.
|
|
39
|
+
|
|
40
|
+
You may also use ``sharePhone=phone`` to share a specific number, in
|
|
41
|
+
which case either `str` or `InputMediaContact` should be used.
|
|
42
|
+
|
|
43
|
+
If it's a `KeyboardButtonRequestGeoLocation`, you must pass a
|
|
44
|
+
tuple in ``shareGeo=[longitude, latitude]``. Note that Telegram seems
|
|
45
|
+
to have some heuristics to determine impossible locations, so changing
|
|
46
|
+
this value a lot quickly may not work as expected. You may also pass a
|
|
47
|
+
`InputGeoPoint` if you find the order confusing.
|
|
48
|
+
*/
|
|
49
|
+
click({ sharePhone, shareGeo, password, }: {
|
|
50
|
+
sharePhone?: boolean | string | Api.InputMediaContact;
|
|
51
|
+
shareGeo?: [number, number] | Api.InputMediaGeoPoint;
|
|
52
|
+
password?: string;
|
|
53
|
+
}): Promise<string | Api.Message | Api.messages.BotCallbackAnswer | Api.TypeUpdates | null | undefined>;
|
|
54
|
+
}
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageButton = void 0;
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const button_1 = require("./button");
|
|
6
|
+
const Helpers_1 = require("../../Helpers");
|
|
7
|
+
const Password_1 = require("../../Password");
|
|
8
|
+
const inspect_1 = require("../../inspect");
|
|
9
|
+
class MessageButton {
|
|
10
|
+
[inspect_1.inspect.custom]() {
|
|
11
|
+
return (0, Helpers_1.betterConsoleLog)(this);
|
|
12
|
+
}
|
|
13
|
+
constructor(client, original, chat, bot, msgId) {
|
|
14
|
+
this.button = original;
|
|
15
|
+
this._bot = bot;
|
|
16
|
+
this._chat = chat;
|
|
17
|
+
this._msgId = msgId;
|
|
18
|
+
this._client = client;
|
|
19
|
+
}
|
|
20
|
+
get client() {
|
|
21
|
+
return this._client;
|
|
22
|
+
}
|
|
23
|
+
get text() {
|
|
24
|
+
return !(this.button instanceof button_1.Button) ? this.button.text : "";
|
|
25
|
+
}
|
|
26
|
+
get data() {
|
|
27
|
+
if (this.button instanceof api_1.Api.KeyboardButtonCallback) {
|
|
28
|
+
return this.button.data;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
get inlineQuery() {
|
|
32
|
+
if (this.button instanceof api_1.Api.KeyboardButtonSwitchInline) {
|
|
33
|
+
return this.button.query;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
get url() {
|
|
37
|
+
if (this.button instanceof api_1.Api.KeyboardButtonUrl) {
|
|
38
|
+
return this.button.url;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Emulates the behaviour of clicking this button.
|
|
43
|
+
|
|
44
|
+
If it's a normal `KeyboardButton` with text, a message will be
|
|
45
|
+
sent, and the sent `Message <Message>` returned.
|
|
46
|
+
|
|
47
|
+
If it's an inline `KeyboardButtonCallback` with text and data,
|
|
48
|
+
it will be "clicked" and the `BotCallbackAnswer` returned.
|
|
49
|
+
|
|
50
|
+
If it's an inline `KeyboardButtonSwitchInline` button, the
|
|
51
|
+
`StartBot` will be invoked and the resulting updates
|
|
52
|
+
returned.
|
|
53
|
+
|
|
54
|
+
If it's a `KeyboardButtonUrl`, the URL of the button will
|
|
55
|
+
be returned.
|
|
56
|
+
|
|
57
|
+
If it's a `KeyboardButtonRequestPhone`, you must indicate that you
|
|
58
|
+
want to ``sharePhone=True`` in order to share it. Sharing it is not a
|
|
59
|
+
default because it is a privacy concern and could happen accidentally.
|
|
60
|
+
|
|
61
|
+
You may also use ``sharePhone=phone`` to share a specific number, in
|
|
62
|
+
which case either `str` or `InputMediaContact` should be used.
|
|
63
|
+
|
|
64
|
+
If it's a `KeyboardButtonRequestGeoLocation`, you must pass a
|
|
65
|
+
tuple in ``shareGeo=[longitude, latitude]``. Note that Telegram seems
|
|
66
|
+
to have some heuristics to determine impossible locations, so changing
|
|
67
|
+
this value a lot quickly may not work as expected. You may also pass a
|
|
68
|
+
`InputGeoPoint` if you find the order confusing.
|
|
69
|
+
*/
|
|
70
|
+
async click({ sharePhone = false, shareGeo = [0, 0], password, }) {
|
|
71
|
+
if (this.button instanceof api_1.Api.KeyboardButton) {
|
|
72
|
+
return this._client.sendMessage(this._chat, {
|
|
73
|
+
message: this.button.text,
|
|
74
|
+
parseMode: undefined,
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
else if (this.button instanceof api_1.Api.KeyboardButtonCallback) {
|
|
78
|
+
let encryptedPassword;
|
|
79
|
+
if (password != undefined) {
|
|
80
|
+
const pwd = await this.client.invoke(new api_1.Api.account.GetPassword());
|
|
81
|
+
encryptedPassword = await (0, Password_1.computeCheck)(pwd, password);
|
|
82
|
+
}
|
|
83
|
+
const request = new api_1.Api.messages.GetBotCallbackAnswer({
|
|
84
|
+
peer: this._chat,
|
|
85
|
+
msgId: this._msgId,
|
|
86
|
+
data: this.button.data,
|
|
87
|
+
password: encryptedPassword,
|
|
88
|
+
});
|
|
89
|
+
try {
|
|
90
|
+
return await this._client.invoke(request);
|
|
91
|
+
}
|
|
92
|
+
catch (e) {
|
|
93
|
+
if (e.errorMessage == "BOT_RESPONSE_TIMEOUT") {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
throw e;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
else if (this.button instanceof api_1.Api.KeyboardButtonSwitchInline) {
|
|
100
|
+
return this._client.invoke(new api_1.Api.messages.StartBot({
|
|
101
|
+
bot: this._bot,
|
|
102
|
+
peer: this._chat,
|
|
103
|
+
startParam: this.button.query,
|
|
104
|
+
}));
|
|
105
|
+
}
|
|
106
|
+
else if (this.button instanceof api_1.Api.KeyboardButtonUrl) {
|
|
107
|
+
return this.button.url;
|
|
108
|
+
}
|
|
109
|
+
else if (this.button instanceof api_1.Api.KeyboardButtonGame) {
|
|
110
|
+
const request = new api_1.Api.messages.GetBotCallbackAnswer({
|
|
111
|
+
peer: this._chat,
|
|
112
|
+
msgId: this._msgId,
|
|
113
|
+
game: true,
|
|
114
|
+
});
|
|
115
|
+
try {
|
|
116
|
+
return await this._client.invoke(request);
|
|
117
|
+
}
|
|
118
|
+
catch (e) {
|
|
119
|
+
if (e.errorMessage == "BOT_RESPONSE_TIMEOUT") {
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
else if (this.button instanceof api_1.Api.KeyboardButtonRequestPhone) {
|
|
126
|
+
if (!sharePhone) {
|
|
127
|
+
throw new Error("cannot click on phone buttons unless sharePhone=true");
|
|
128
|
+
}
|
|
129
|
+
if (sharePhone == true || typeof sharePhone == "string") {
|
|
130
|
+
const me = await this._client.getMe();
|
|
131
|
+
sharePhone = new api_1.Api.InputMediaContact({
|
|
132
|
+
phoneNumber: (sharePhone == true ? me.phone : sharePhone) || "",
|
|
133
|
+
firstName: me.firstName || "",
|
|
134
|
+
lastName: me.lastName || "",
|
|
135
|
+
vcard: "",
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
throw new Error("Not supported for now");
|
|
139
|
+
// TODO
|
|
140
|
+
//return this._client.sendFile(this._chat, phoneMedia);
|
|
141
|
+
}
|
|
142
|
+
else if (this.button instanceof api_1.Api.InputWebFileGeoPointLocation) {
|
|
143
|
+
if (!shareGeo) {
|
|
144
|
+
throw new Error("cannot click on geo buttons unless shareGeo=[longitude, latitude]");
|
|
145
|
+
}
|
|
146
|
+
throw new Error("Not supported for now");
|
|
147
|
+
// TODO
|
|
148
|
+
//return this._client.sendFile(this._chat, geoMedia);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
exports.MessageButton = MessageButton;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Entity } from "../../define";
|
|
2
|
+
import type { TelegramClient } from "../..";
|
|
3
|
+
import { Api } from "../api";
|
|
4
|
+
import { ChatGetter } from "./chatGetter";
|
|
5
|
+
import bigInt from "big-integer";
|
|
6
|
+
import { inspect } from "../../inspect";
|
|
7
|
+
interface SenderGetterConstructorInterface {
|
|
8
|
+
senderId?: bigInt.BigInteger;
|
|
9
|
+
sender?: Entity;
|
|
10
|
+
inputSender?: Api.TypeInputPeer;
|
|
11
|
+
}
|
|
12
|
+
export declare class SenderGetter extends ChatGetter {
|
|
13
|
+
_senderId?: bigInt.BigInteger;
|
|
14
|
+
_sender?: Entity;
|
|
15
|
+
_inputSender?: Api.TypeInputPeer;
|
|
16
|
+
_client?: TelegramClient;
|
|
17
|
+
[inspect.custom](): {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
};
|
|
20
|
+
static initSenderClass(c: any, { senderId, sender, inputSender }: SenderGetterConstructorInterface): void;
|
|
21
|
+
get sender(): Entity | undefined;
|
|
22
|
+
getSender(): Promise<Entity | undefined>;
|
|
23
|
+
get inputSender(): Api.TypeInputPeer | undefined;
|
|
24
|
+
getInputSender(): Promise<Api.TypeInputPeer | undefined>;
|
|
25
|
+
get senderId(): bigInt.BigInteger | undefined;
|
|
26
|
+
_refetchSender(): Promise<void>;
|
|
27
|
+
}
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SenderGetter = void 0;
|
|
4
|
+
const api_1 = require("../api");
|
|
5
|
+
const Helpers_1 = require("../../Helpers");
|
|
6
|
+
const chatGetter_1 = require("./chatGetter");
|
|
7
|
+
const inspect_1 = require("../../inspect");
|
|
8
|
+
class SenderGetter extends chatGetter_1.ChatGetter {
|
|
9
|
+
[inspect_1.inspect.custom]() {
|
|
10
|
+
return (0, Helpers_1.betterConsoleLog)(this);
|
|
11
|
+
}
|
|
12
|
+
static initSenderClass(c, { senderId, sender, inputSender }) {
|
|
13
|
+
c._senderId = senderId;
|
|
14
|
+
c._sender = sender;
|
|
15
|
+
c._inputSender = inputSender;
|
|
16
|
+
c._client = undefined;
|
|
17
|
+
}
|
|
18
|
+
get sender() {
|
|
19
|
+
return this._sender;
|
|
20
|
+
}
|
|
21
|
+
async getSender() {
|
|
22
|
+
if (this._client &&
|
|
23
|
+
(!this._sender ||
|
|
24
|
+
(this._sender instanceof api_1.Api.Channel && this._sender.min)) &&
|
|
25
|
+
(await this.getInputSender())) {
|
|
26
|
+
try {
|
|
27
|
+
this._sender = await this._client.getEntity(this._inputSender);
|
|
28
|
+
}
|
|
29
|
+
catch (e) {
|
|
30
|
+
await this._refetchSender();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return this._sender;
|
|
34
|
+
}
|
|
35
|
+
get inputSender() {
|
|
36
|
+
if (!this._inputSender && this._senderId && this._client) {
|
|
37
|
+
try {
|
|
38
|
+
this._inputSender = this._client._entityCache.get(this._senderId);
|
|
39
|
+
}
|
|
40
|
+
catch (e) { }
|
|
41
|
+
}
|
|
42
|
+
return this._inputSender;
|
|
43
|
+
}
|
|
44
|
+
async getInputSender() {
|
|
45
|
+
if (!this.inputSender && this._senderId && this._client) {
|
|
46
|
+
await this._refetchSender();
|
|
47
|
+
}
|
|
48
|
+
return this._inputSender;
|
|
49
|
+
}
|
|
50
|
+
get senderId() {
|
|
51
|
+
return this._senderId;
|
|
52
|
+
}
|
|
53
|
+
async _refetchSender() { }
|
|
54
|
+
}
|
|
55
|
+
exports.SenderGetter = SenderGetter;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const fs = require("fs");
|
|
3
|
+
const path = require("path");
|
|
4
|
+
require("./types-generator/generate");
|
|
5
|
+
function main() {
|
|
6
|
+
const apiTl = fs.readFileSync(path.resolve(__dirname, `./static/api.tl`), "utf-8");
|
|
7
|
+
fs.writeFileSync(path.resolve(__dirname, "./apiTl.js"), `module.exports = \`${stripTl(apiTl)}\`;`);
|
|
8
|
+
const schemaTl = fs.readFileSync(path.resolve(__dirname, `./static/schema.tl`), "utf-8");
|
|
9
|
+
fs.writeFileSync(path.resolve(__dirname, "./schemaTl.js"), `module.exports = \`${stripTl(schemaTl)}\`;`);
|
|
10
|
+
}
|
|
11
|
+
function stripTl(tl) {
|
|
12
|
+
return tl
|
|
13
|
+
.replace(/\/\*[\s\S]*?\*\/|\/\/.*/g, "")
|
|
14
|
+
.replace(/\n\s*\n/g, "\n")
|
|
15
|
+
.replace(/`/g, "\\`");
|
|
16
|
+
}
|
|
17
|
+
main();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { DateLike } from "../define";
|
|
2
|
+
declare const snakeToCamelCase: (name: string) => string;
|
|
3
|
+
declare const variableSnakeToCamelCase: (str: string) => string;
|
|
4
|
+
declare const CORE_TYPES: Set<number>;
|
|
5
|
+
declare const fromLine: (line: string, isFunction: boolean) => any;
|
|
6
|
+
declare function buildArgConfig(name: string, argType: string): any;
|
|
7
|
+
declare const parseTl: (content: string, layer: string, methods?: any[], ignoreIds?: Set<number>) => Generator<any, void, unknown>;
|
|
8
|
+
declare const findAll: (regex: RegExp, str: string, matches?: any) => any;
|
|
9
|
+
export declare function serializeBytes(data: Buffer | string | any): Buffer<ArrayBuffer>;
|
|
10
|
+
export declare function serializeDate(dt: DateLike | Date): Buffer<ArrayBuffer>;
|
|
11
|
+
export { findAll, parseTl, buildArgConfig, fromLine, CORE_TYPES, snakeToCamelCase, variableSnakeToCamelCase, };
|
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.variableSnakeToCamelCase = exports.snakeToCamelCase = exports.CORE_TYPES = exports.fromLine = exports.parseTl = exports.findAll = void 0;
|
|
4
|
+
exports.serializeBytes = serializeBytes;
|
|
5
|
+
exports.serializeDate = serializeDate;
|
|
6
|
+
exports.buildArgConfig = buildArgConfig;
|
|
7
|
+
const Helpers_1 = require("../Helpers");
|
|
8
|
+
const snakeToCamelCase = (name) => {
|
|
9
|
+
const result = name.replace(/(?:^|_)([a-z])/g, (_, g) => g.toUpperCase());
|
|
10
|
+
return result.replace(/_/g, "");
|
|
11
|
+
};
|
|
12
|
+
exports.snakeToCamelCase = snakeToCamelCase;
|
|
13
|
+
const variableSnakeToCamelCase = (str) => str.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace("-", "").replace("_", ""));
|
|
14
|
+
exports.variableSnakeToCamelCase = variableSnakeToCamelCase;
|
|
15
|
+
const CORE_TYPES = new Set([
|
|
16
|
+
0xbc799737, // boolFalse#bc799737 = Bool;
|
|
17
|
+
0x997275b5, // boolTrue#997275b5 = Bool;
|
|
18
|
+
0x3fedd339, // true#3fedd339 = True;
|
|
19
|
+
0xc4b9f9bb, // error#c4b9f9bb code:int text:string = Error;
|
|
20
|
+
0x56730bcc, // null#56730bcc = Null;
|
|
21
|
+
]);
|
|
22
|
+
exports.CORE_TYPES = CORE_TYPES;
|
|
23
|
+
const AUTH_KEY_TYPES = new Set([
|
|
24
|
+
0x05162463, // resPQ,
|
|
25
|
+
0x83c95aec, // p_q_inner_data
|
|
26
|
+
0xa9f55f95, // p_q_inner_data_dc
|
|
27
|
+
0x3c6a84d4, // p_q_inner_data_temp
|
|
28
|
+
0x56fddf88, // p_q_inner_data_temp_dc
|
|
29
|
+
0xd0e8075c, // server_DH_params_ok
|
|
30
|
+
0xb5890dba, // server_DH_inner_data
|
|
31
|
+
0x6643b654, // client_DH_inner_data
|
|
32
|
+
0xd712e4be, // req_DH_params
|
|
33
|
+
0xf5045f1f, // set_client_DH_params
|
|
34
|
+
0x3072cfa1, // gzip_packed
|
|
35
|
+
]);
|
|
36
|
+
const fromLine = (line, isFunction) => {
|
|
37
|
+
const match = line.match(/([\w.]+)(?:#([0-9a-fA-F]+))?(?:\s{?\w+:[\w\d<>#.?!]+}?)*\s=\s([\w\d<>#.?]+);$/);
|
|
38
|
+
if (!match) {
|
|
39
|
+
// Probably "vector#1cb5c415 {t:Type} # [ t ] = Vector t;"
|
|
40
|
+
throw new Error(`Cannot parse TLObject ${line}`);
|
|
41
|
+
}
|
|
42
|
+
const argsMatch = findAll(/({)?(\w+):([\w\d<>#.?!]+)}?/, line);
|
|
43
|
+
const currentConfig = {
|
|
44
|
+
name: match[1],
|
|
45
|
+
constructorId: parseInt(match[2], 16),
|
|
46
|
+
argsConfig: {},
|
|
47
|
+
subclassOfId: (0, Helpers_1.crc32)(match[3]),
|
|
48
|
+
result: match[3],
|
|
49
|
+
isFunction: isFunction,
|
|
50
|
+
namespace: undefined,
|
|
51
|
+
};
|
|
52
|
+
if (!currentConfig.constructorId) {
|
|
53
|
+
const hexId = "";
|
|
54
|
+
let args;
|
|
55
|
+
if (Object.values(currentConfig.argsConfig).length) {
|
|
56
|
+
args = ` ${Object.keys(currentConfig.argsConfig)
|
|
57
|
+
.map((arg) => arg.toString())
|
|
58
|
+
.join(" ")}`;
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
args = "";
|
|
62
|
+
}
|
|
63
|
+
const representation = `${currentConfig.name}${hexId}${args} = ${currentConfig.result}`
|
|
64
|
+
.replace(/(:|\?)bytes /g, "$1string ")
|
|
65
|
+
.replace(/</g, " ")
|
|
66
|
+
.replace(/>|{|}/g, "")
|
|
67
|
+
.replace(/ \w+:flags(\d+)?\.\d+\?true/g, "");
|
|
68
|
+
if (currentConfig.name === "inputMediaInvoice") {
|
|
69
|
+
// eslint-disable-next-line no-empty
|
|
70
|
+
if (currentConfig.name === "inputMediaInvoice") {
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
currentConfig.constructorId = (0, Helpers_1.crc32)(Buffer.from(representation, "utf8"));
|
|
74
|
+
}
|
|
75
|
+
for (const [brace, name, argType] of argsMatch) {
|
|
76
|
+
if (brace === undefined) {
|
|
77
|
+
// @ts-ignore
|
|
78
|
+
currentConfig.argsConfig[variableSnakeToCamelCase(name)] =
|
|
79
|
+
buildArgConfig(name, argType);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (currentConfig.name.includes(".")) {
|
|
83
|
+
[currentConfig.namespace, currentConfig.name] =
|
|
84
|
+
currentConfig.name.split(/\.(.+)/);
|
|
85
|
+
}
|
|
86
|
+
currentConfig.name = snakeToCamelCase(currentConfig.name);
|
|
87
|
+
/*
|
|
88
|
+
for (const arg in currentConfig.argsConfig){
|
|
89
|
+
if (currentConfig.argsConfig.hasOwnProperty(arg)){
|
|
90
|
+
if (currentConfig.argsConfig[arg].flagIndicator){
|
|
91
|
+
delete currentConfig.argsConfig[arg]
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}*/
|
|
95
|
+
return currentConfig;
|
|
96
|
+
};
|
|
97
|
+
exports.fromLine = fromLine;
|
|
98
|
+
function buildArgConfig(name, argType) {
|
|
99
|
+
name = name === "self" ? "is_self" : name;
|
|
100
|
+
// Default values
|
|
101
|
+
const currentConfig = {
|
|
102
|
+
isVector: false,
|
|
103
|
+
isFlag: false,
|
|
104
|
+
skipConstructorId: false,
|
|
105
|
+
flagName: null,
|
|
106
|
+
flagIndex: -1,
|
|
107
|
+
flagIndicator: true,
|
|
108
|
+
type: null,
|
|
109
|
+
useVectorId: null,
|
|
110
|
+
};
|
|
111
|
+
// Special case: some types can be inferred, which makes it
|
|
112
|
+
// less annoying to type. Currently the only type that can
|
|
113
|
+
// be inferred is if the name is 'random_id', to which a
|
|
114
|
+
// random ID will be assigned if left as None (the default)
|
|
115
|
+
const canBeInferred = name === "random_id";
|
|
116
|
+
// The type can be an indicator that other arguments will be flags
|
|
117
|
+
if (argType !== "#") {
|
|
118
|
+
currentConfig.flagIndicator = false;
|
|
119
|
+
// Strip the exclamation mark always to have only the name
|
|
120
|
+
currentConfig.type = argType.replace(/^!+/, "");
|
|
121
|
+
// The type may be a flag (flags.IDX?REAL_TYPE)
|
|
122
|
+
// Note that 'flags' is NOT the flags name; this
|
|
123
|
+
// is determined by a previous argument
|
|
124
|
+
// However, we assume that the argument will always be starts with 'flags'
|
|
125
|
+
// @ts-ignore
|
|
126
|
+
const flagMatch = currentConfig.type.match(/(flags(?:\d+)?).(\d+)\?([\w<>.]+)/);
|
|
127
|
+
if (flagMatch) {
|
|
128
|
+
currentConfig.isFlag = true;
|
|
129
|
+
// As of layer 140, flagName can be "flags" or "flags2"
|
|
130
|
+
currentConfig.flagName = flagMatch[1];
|
|
131
|
+
currentConfig.flagIndex = Number(flagMatch[2]);
|
|
132
|
+
// Update the type to match the exact type, not the "flagged" one
|
|
133
|
+
currentConfig.type = flagMatch[3];
|
|
134
|
+
}
|
|
135
|
+
// Then check if the type is a Vector<REAL_TYPE>
|
|
136
|
+
// @ts-ignore
|
|
137
|
+
const vectorMatch = currentConfig.type.match(/[Vv]ector<([\w\d.]+)>/);
|
|
138
|
+
if (vectorMatch) {
|
|
139
|
+
currentConfig.isVector = true;
|
|
140
|
+
// If the type's first letter is not uppercase, then
|
|
141
|
+
// it is a constructor and we use (read/write) its ID.
|
|
142
|
+
// @ts-ignore
|
|
143
|
+
currentConfig.useVectorId = currentConfig.type.charAt(0) === "V";
|
|
144
|
+
// Update the type to match the one inside the vector
|
|
145
|
+
[, currentConfig.type] = vectorMatch;
|
|
146
|
+
}
|
|
147
|
+
// See use_vector_id. An example of such case is ipPort in
|
|
148
|
+
// help.configSpecial
|
|
149
|
+
// @ts-ignore
|
|
150
|
+
if (/^[a-z]$/.test(currentConfig.type.split(".").pop().charAt(0))) {
|
|
151
|
+
currentConfig.skipConstructorId = true;
|
|
152
|
+
}
|
|
153
|
+
// The name may contain "date" in it, if this is the case and
|
|
154
|
+
// the type is "int", we can safely assume that this should be
|
|
155
|
+
// treated as a "date" object. Note that this is not a valid
|
|
156
|
+
// Telegram object, but it's easier to work with
|
|
157
|
+
// if (
|
|
158
|
+
// this.type === 'int' &&
|
|
159
|
+
// (/(\b|_)([dr]ate|until|since)(\b|_)/.test(name) ||
|
|
160
|
+
// ['expires', 'expires_at', 'was_online'].includes(name))
|
|
161
|
+
// ) {
|
|
162
|
+
// this.type = 'date';
|
|
163
|
+
// }
|
|
164
|
+
}
|
|
165
|
+
// workaround
|
|
166
|
+
if (currentConfig.type == "future_salt") {
|
|
167
|
+
currentConfig.type = "FutureSalt";
|
|
168
|
+
}
|
|
169
|
+
return currentConfig;
|
|
170
|
+
}
|
|
171
|
+
const parseTl = function* (content, layer, methods = [], ignoreIds = CORE_TYPES) {
|
|
172
|
+
const methodInfo = (methods || []).reduce((o, m) => (Object.assign(Object.assign({}, o), { [m.name]: m })), {});
|
|
173
|
+
const objAll = [];
|
|
174
|
+
const objByName = {};
|
|
175
|
+
const objByType = {};
|
|
176
|
+
const file = content;
|
|
177
|
+
let isFunction = false;
|
|
178
|
+
for (let line of file.split("\n")) {
|
|
179
|
+
const commentIndex = line.indexOf("//");
|
|
180
|
+
if (commentIndex !== -1) {
|
|
181
|
+
line = line.slice(0, commentIndex);
|
|
182
|
+
}
|
|
183
|
+
line = line.trim();
|
|
184
|
+
if (!line) {
|
|
185
|
+
continue;
|
|
186
|
+
}
|
|
187
|
+
const match = line.match(/---(\w+)---/);
|
|
188
|
+
if (match) {
|
|
189
|
+
const [, followingTypes] = match;
|
|
190
|
+
isFunction = followingTypes === "functions";
|
|
191
|
+
continue;
|
|
192
|
+
}
|
|
193
|
+
try {
|
|
194
|
+
const result = fromLine(line, isFunction);
|
|
195
|
+
if (ignoreIds.has(result.constructorId)) {
|
|
196
|
+
continue;
|
|
197
|
+
}
|
|
198
|
+
objAll.push(result);
|
|
199
|
+
if (!result.isFunction) {
|
|
200
|
+
if (!objByType[result.result]) {
|
|
201
|
+
objByType[result.result] = [];
|
|
202
|
+
}
|
|
203
|
+
objByName[result.name] = result;
|
|
204
|
+
objByType[result.result].push(result);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
catch (e) {
|
|
208
|
+
if (!e.toString().includes("vector#1cb5c415")) {
|
|
209
|
+
throw e;
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
// Once all objects have been parsed, replace the
|
|
214
|
+
// string type from the arguments with references
|
|
215
|
+
for (const obj of objAll) {
|
|
216
|
+
if (AUTH_KEY_TYPES.has(obj.constructorId)) {
|
|
217
|
+
for (const arg in obj.argsConfig) {
|
|
218
|
+
if (obj.argsConfig[arg].type === "string") {
|
|
219
|
+
obj.argsConfig[arg].type = "bytes";
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
for (const obj of objAll) {
|
|
225
|
+
yield obj;
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
exports.parseTl = parseTl;
|
|
229
|
+
const findAll = (regex, str, matches = []) => {
|
|
230
|
+
if (!regex.flags.includes("g")) {
|
|
231
|
+
regex = new RegExp(regex.source, "g");
|
|
232
|
+
}
|
|
233
|
+
const res = regex.exec(str);
|
|
234
|
+
if (res) {
|
|
235
|
+
matches.push(res.slice(1));
|
|
236
|
+
findAll(regex, str, matches);
|
|
237
|
+
}
|
|
238
|
+
return matches;
|
|
239
|
+
};
|
|
240
|
+
exports.findAll = findAll;
|
|
241
|
+
function serializeBytes(data) {
|
|
242
|
+
if (!(data instanceof Buffer)) {
|
|
243
|
+
if (typeof data == "string") {
|
|
244
|
+
data = Buffer.from(data);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
throw Error(`Bytes or str expected, not ${data.constructor.name}`);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
const r = [];
|
|
251
|
+
let padding;
|
|
252
|
+
if (data.length < 254) {
|
|
253
|
+
padding = (data.length + 1) % 4;
|
|
254
|
+
if (padding !== 0) {
|
|
255
|
+
padding = 4 - padding;
|
|
256
|
+
}
|
|
257
|
+
r.push(Buffer.from([data.length]));
|
|
258
|
+
r.push(data);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
padding = data.length % 4;
|
|
262
|
+
if (padding !== 0) {
|
|
263
|
+
padding = 4 - padding;
|
|
264
|
+
}
|
|
265
|
+
r.push(Buffer.from([
|
|
266
|
+
254,
|
|
267
|
+
data.length % 256,
|
|
268
|
+
(data.length >> 8) % 256,
|
|
269
|
+
(data.length >> 16) % 256,
|
|
270
|
+
]));
|
|
271
|
+
r.push(data);
|
|
272
|
+
}
|
|
273
|
+
r.push(Buffer.alloc(padding).fill(0));
|
|
274
|
+
return Buffer.concat(r);
|
|
275
|
+
}
|
|
276
|
+
function serializeDate(dt) {
|
|
277
|
+
if (!dt) {
|
|
278
|
+
return Buffer.alloc(4).fill(0);
|
|
279
|
+
}
|
|
280
|
+
if (dt instanceof Date) {
|
|
281
|
+
dt = Math.floor((Date.now() - dt.getTime()) / 1000);
|
|
282
|
+
}
|
|
283
|
+
if (typeof dt == "number") {
|
|
284
|
+
const t = Buffer.alloc(4);
|
|
285
|
+
t.writeInt32LE(dt, 0);
|
|
286
|
+
return t;
|
|
287
|
+
}
|
|
288
|
+
throw Error(`Cannot interpret "${dt}" as a date`);
|
|
289
|
+
}
|
package/tl/index.d.ts
ADDED
package/tl/index.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.serializeDate = exports.serializeBytes = exports.Api = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
Object.defineProperty(exports, "Api", { enumerable: true, get: function () { return api_1.Api; } });
|
|
6
|
+
const patched_1 = require("./patched");
|
|
7
|
+
(0, patched_1.patchAll)();
|
|
8
|
+
var generationHelpers_1 = require("./generationHelpers");
|
|
9
|
+
Object.defineProperty(exports, "serializeBytes", { enumerable: true, get: function () { return generationHelpers_1.serializeBytes; } });
|
|
10
|
+
Object.defineProperty(exports, "serializeDate", { enumerable: true, get: function () { return generationHelpers_1.serializeDate; } });
|