sroosh 1.0.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.
Files changed (250) hide show
  1. package/CryptoFile-BROWSER.d.ts +2 -0
  2. package/CryptoFile-BROWSER.js +23 -0
  3. package/CryptoFile.d.ts +2 -0
  4. package/CryptoFile.js +23 -0
  5. package/Helpers.d.ts +151 -0
  6. package/Helpers.js +480 -0
  7. package/Password.d.ts +15 -0
  8. package/Password.js +271 -0
  9. package/README.md +105 -0
  10. package/Utils.d.ts +228 -0
  11. package/Utils.js +1248 -0
  12. package/Version.d.ts +1 -0
  13. package/Version.js +4 -0
  14. package/client/2fa.d.ts +48 -0
  15. package/client/2fa.js +109 -0
  16. package/client/TelegramClient.d.ts +1042 -0
  17. package/client/TelegramClient.js +1244 -0
  18. package/client/account.d.ts +0 -0
  19. package/client/account.js +1 -0
  20. package/client/auth.d.ts +93 -0
  21. package/client/auth.js +363 -0
  22. package/client/bots.d.ts +6 -0
  23. package/client/bots.js +24 -0
  24. package/client/buttons.d.ts +4 -0
  25. package/client/buttons.js +87 -0
  26. package/client/chats.d.ts +46 -0
  27. package/client/chats.js +350 -0
  28. package/client/dialogs.d.ts +52 -0
  29. package/client/dialogs.js +174 -0
  30. package/client/downloads.d.ts +157 -0
  31. package/client/downloads.js +598 -0
  32. package/client/fs-BROWSER.d.ts +10 -0
  33. package/client/fs-BROWSER.js +13 -0
  34. package/client/fs.d.ts +1 -0
  35. package/client/fs.js +13 -0
  36. package/client/index.d.ts +15 -0
  37. package/client/index.js +50 -0
  38. package/client/messageParse.d.ts +17 -0
  39. package/client/messageParse.js +191 -0
  40. package/client/messages.d.ts +259 -0
  41. package/client/messages.js +804 -0
  42. package/client/os-BROWSER.d.ts +5 -0
  43. package/client/os-BROWSER.js +10 -0
  44. package/client/os.d.ts +2 -0
  45. package/client/os.js +23 -0
  46. package/client/path-BROWSER.d.ts +7 -0
  47. package/client/path-BROWSER.js +8 -0
  48. package/client/path.d.ts +2 -0
  49. package/client/path.js +7 -0
  50. package/client/telegramBaseClient.d.ts +239 -0
  51. package/client/telegramBaseClient.js +369 -0
  52. package/client/updates.d.ts +31 -0
  53. package/client/updates.js +254 -0
  54. package/client/uploads.d.ts +137 -0
  55. package/client/uploads.js +514 -0
  56. package/client/users.d.ts +29 -0
  57. package/client/users.js +491 -0
  58. package/crypto/AuthKey.d.ts +20 -0
  59. package/crypto/AuthKey.js +76 -0
  60. package/crypto/CTR.d.ts +6 -0
  61. package/crypto/CTR.js +35 -0
  62. package/crypto/Factorizator.d.ts +19 -0
  63. package/crypto/Factorizator.js +74 -0
  64. package/crypto/IGE.d.ts +18 -0
  65. package/crypto/IGE.js +34 -0
  66. package/crypto/RSA.d.ts +15 -0
  67. package/crypto/RSA.js +150 -0
  68. package/crypto/converters.d.ts +19 -0
  69. package/crypto/converters.js +52 -0
  70. package/crypto/crypto.d.ts +27 -0
  71. package/crypto/crypto.js +117 -0
  72. package/crypto/words.d.ts +6 -0
  73. package/crypto/words.js +48 -0
  74. package/entityCache.d.ts +7 -0
  75. package/entityCache.js +79 -0
  76. package/errors/Common.d.ts +72 -0
  77. package/errors/Common.js +122 -0
  78. package/errors/RPCBaseErrors.d.ts +84 -0
  79. package/errors/RPCBaseErrors.js +134 -0
  80. package/errors/RPCErrorList.d.ts +37 -0
  81. package/errors/RPCErrorList.js +117 -0
  82. package/errors/index.d.ts +11 -0
  83. package/errors/index.js +29 -0
  84. package/events/Album.d.ts +36 -0
  85. package/events/Album.js +104 -0
  86. package/events/CallbackQuery.d.ts +74 -0
  87. package/events/CallbackQuery.js +193 -0
  88. package/events/DeletedMessage.d.ts +45 -0
  89. package/events/DeletedMessage.js +63 -0
  90. package/events/EditedMessage.d.ts +30 -0
  91. package/events/EditedMessage.js +41 -0
  92. package/events/NewMessage.d.ts +89 -0
  93. package/events/NewMessage.js +182 -0
  94. package/events/Raw.d.ts +29 -0
  95. package/events/Raw.js +43 -0
  96. package/events/common.d.ts +66 -0
  97. package/events/common.js +141 -0
  98. package/events/index.d.ts +2 -0
  99. package/events/index.js +8 -0
  100. package/extensions/AsyncQueue.d.ts +10 -0
  101. package/extensions/AsyncQueue.js +32 -0
  102. package/extensions/BinaryReader.d.ts +100 -0
  103. package/extensions/BinaryReader.js +242 -0
  104. package/extensions/BinaryWriter.d.ts +7 -0
  105. package/extensions/BinaryWriter.js +15 -0
  106. package/extensions/Deferred.d.ts +8 -0
  107. package/extensions/Deferred.js +16 -0
  108. package/extensions/Logger.d.ts +58 -0
  109. package/extensions/Logger.js +127 -0
  110. package/extensions/MessagePacker.d.ts +22 -0
  111. package/extensions/MessagePacker.js +154 -0
  112. package/extensions/PendingState.d.ts +12 -0
  113. package/extensions/PendingState.js +29 -0
  114. package/extensions/PromisedNetSockets-BROWSER.d.ts +8 -0
  115. package/extensions/PromisedNetSockets-BROWSER.js +12 -0
  116. package/extensions/PromisedNetSockets.d.ts +25 -0
  117. package/extensions/PromisedNetSockets.js +178 -0
  118. package/extensions/PromisedWebSockets.d.ts +19 -0
  119. package/extensions/PromisedWebSockets.js +134 -0
  120. package/extensions/html.d.ts +5 -0
  121. package/extensions/html.js +213 -0
  122. package/extensions/index.d.ts +7 -0
  123. package/extensions/index.js +17 -0
  124. package/extensions/markdown.d.ts +5 -0
  125. package/extensions/markdown.js +76 -0
  126. package/extensions/markdownv2.d.ts +5 -0
  127. package/extensions/markdownv2.js +51 -0
  128. package/extensions/net-BROWSER.d.ts +8 -0
  129. package/extensions/net-BROWSER.js +11 -0
  130. package/extensions/net.d.ts +1 -0
  131. package/extensions/net.js +13 -0
  132. package/extensions/socks-BROWSER.d.ts +3 -0
  133. package/extensions/socks-BROWSER.js +6 -0
  134. package/extensions/socks.d.ts +1 -0
  135. package/extensions/socks.js +13 -0
  136. package/index.d.ts +14 -0
  137. package/index.js +48 -0
  138. package/inspect-BROWSER.d.ts +3 -0
  139. package/inspect-BROWSER.js +6 -0
  140. package/inspect.d.ts +1 -0
  141. package/inspect.js +5 -0
  142. package/network/Authenticator.d.ts +12 -0
  143. package/network/Authenticator.js +193 -0
  144. package/network/MTProtoPlainSender.d.ts +19 -0
  145. package/network/MTProtoPlainSender.js +74 -0
  146. package/network/MTProtoSender.d.ts +291 -0
  147. package/network/MTProtoSender.js +854 -0
  148. package/network/MTProtoState.d.ts +103 -0
  149. package/network/MTProtoState.js +267 -0
  150. package/network/RequestState.d.ts +19 -0
  151. package/network/RequestState.js +35 -0
  152. package/network/connection/Connection.d.ts +71 -0
  153. package/network/connection/Connection.js +157 -0
  154. package/network/connection/ConnectionWebSocket.d.ts +19 -0
  155. package/network/connection/ConnectionWebSocket.js +77 -0
  156. package/network/connection/CustomIntermediatePacketCodec.d.ts +8 -0
  157. package/network/connection/CustomIntermediatePacketCodec.js +25 -0
  158. package/network/connection/CustomPromisedWebSockets.d.ts +22 -0
  159. package/network/connection/CustomPromisedWebSockets.js +170 -0
  160. package/network/connection/ObfuscatedIO.d.ts +12 -0
  161. package/network/connection/ObfuscatedIO.js +64 -0
  162. package/network/connection/TCPAbridged.d.ts +20 -0
  163. package/network/connection/TCPAbridged.js +58 -0
  164. package/network/connection/TCPFull.d.ts +17 -0
  165. package/network/connection/TCPFull.js +61 -0
  166. package/network/connection/TCPMTProxy.d.ts +50 -0
  167. package/network/connection/TCPMTProxy.js +121 -0
  168. package/network/connection/TCPObfuscated.d.ts +18 -0
  169. package/network/connection/TCPObfuscated.js +79 -0
  170. package/network/connection/index.d.ts +5 -0
  171. package/network/connection/index.js +13 -0
  172. package/network/index.d.ts +11 -0
  173. package/network/index.js +24 -0
  174. package/package.json +73 -0
  175. package/platform.d.ts +3 -0
  176. package/platform.js +6 -0
  177. package/requestIter.d.ts +24 -0
  178. package/requestIter.js +107 -0
  179. package/sessions/Abstract.d.ts +103 -0
  180. package/sessions/Abstract.js +6 -0
  181. package/sessions/CacheApiSession.d.ts +18 -0
  182. package/sessions/CacheApiSession.js +99 -0
  183. package/sessions/Memory.d.ts +38 -0
  184. package/sessions/Memory.js +272 -0
  185. package/sessions/StoreSession.d.ts +14 -0
  186. package/sessions/StoreSession.js +77 -0
  187. package/sessions/StringSession.d.ts +33 -0
  188. package/sessions/StringSession.js +116 -0
  189. package/sessions/index.d.ts +4 -0
  190. package/sessions/index.js +13 -0
  191. package/sessions/localStorage-BROWSER.d.ts +3 -0
  192. package/sessions/localStorage-BROWSER.js +9 -0
  193. package/sessions/localStorage.d.ts +1 -0
  194. package/sessions/localStorage.js +4 -0
  195. package/tl/AllTLObjects.d.ts +3 -0
  196. package/tl/AllTLObjects.js +17 -0
  197. package/tl/MTProtoRequest.d.ts +19 -0
  198. package/tl/MTProtoRequest.js +38 -0
  199. package/tl/api.d.ts +2 -0
  200. package/tl/api.js +507 -0
  201. package/tl/apiTl.d.ts +2 -0
  202. package/tl/apiTl.js +1638 -0
  203. package/tl/core/GZIPPacked.d.ts +16 -0
  204. package/tl/core/GZIPPacked.js +51 -0
  205. package/tl/core/MessageContainer.d.ts +12 -0
  206. package/tl/core/MessageContainer.js +42 -0
  207. package/tl/core/RPCResult.d.ts +15 -0
  208. package/tl/core/RPCResult.js +32 -0
  209. package/tl/core/TLMessage.d.ts +10 -0
  210. package/tl/core/TLMessage.js +14 -0
  211. package/tl/core/index.d.ts +6 -0
  212. package/tl/core/index.js +16 -0
  213. package/tl/custom/button.d.ts +25 -0
  214. package/tl/custom/button.js +78 -0
  215. package/tl/custom/chatGetter.d.ts +30 -0
  216. package/tl/custom/chatGetter.js +114 -0
  217. package/tl/custom/dialog.d.ts +31 -0
  218. package/tl/custom/dialog.js +40 -0
  219. package/tl/custom/draft.d.ts +22 -0
  220. package/tl/custom/draft.js +48 -0
  221. package/tl/custom/file.d.ts +22 -0
  222. package/tl/custom/file.js +68 -0
  223. package/tl/custom/forward.d.ts +16 -0
  224. package/tl/custom/forward.js +47 -0
  225. package/tl/custom/index.d.ts +1 -0
  226. package/tl/custom/index.js +5 -0
  227. package/tl/custom/inlineResult.d.ts +33 -0
  228. package/tl/custom/inlineResult.js +87 -0
  229. package/tl/custom/inlineResults.d.ts +21 -0
  230. package/tl/custom/inlineResults.js +26 -0
  231. package/tl/custom/message.d.ts +428 -0
  232. package/tl/custom/message.js +702 -0
  233. package/tl/custom/messageButton.d.ts +55 -0
  234. package/tl/custom/messageButton.js +152 -0
  235. package/tl/custom/senderGetter.d.ts +29 -0
  236. package/tl/custom/senderGetter.js +55 -0
  237. package/tl/generateModule.d.ts +1 -0
  238. package/tl/generateModule.js +17 -0
  239. package/tl/generationHelpers.d.ts +12 -0
  240. package/tl/generationHelpers.js +289 -0
  241. package/tl/index.d.ts +3 -0
  242. package/tl/index.js +10 -0
  243. package/tl/patched/index.d.ts +2 -0
  244. package/tl/patched/index.js +77 -0
  245. package/tl/schemaTl.d.ts +2 -0
  246. package/tl/schemaTl.js +64 -0
  247. package/tl/types-generator/generate.d.ts +1 -0
  248. package/tl/types-generator/generate.js +84 -0
  249. package/tl/types-generator/template.d.ts +6 -0
  250. package/tl/types-generator/template.js +257 -0
@@ -0,0 +1,55 @@
1
+ /// <reference types="node" />
2
+ import type { TelegramClient } from "../../client/TelegramClient";
3
+ import type { ButtonLike, EntityLike, MessageIDLike } from "../../define";
4
+ import { Api } from "../api";
5
+ import { inspect } from "../../inspect";
6
+ export declare class MessageButton {
7
+ private readonly _client;
8
+ private readonly _chat;
9
+ readonly button: ButtonLike;
10
+ private readonly _bot?;
11
+ private readonly _msgId;
12
+ [inspect.custom](): {
13
+ [key: string]: any;
14
+ };
15
+ constructor(client: TelegramClient, original: ButtonLike, chat: EntityLike, bot: EntityLike | undefined, msgId: MessageIDLike);
16
+ get client(): TelegramClient;
17
+ get text(): string;
18
+ get data(): Buffer | undefined;
19
+ get inlineQuery(): string | undefined;
20
+ get url(): string | undefined;
21
+ /**
22
+ * Emulates the behaviour of clicking this button.
23
+
24
+ If it's a normal `KeyboardButton` with text, a message will be
25
+ sent, and the sent `Message <Message>` returned.
26
+
27
+ If it's an inline `KeyboardButtonCallback` with text and data,
28
+ it will be "clicked" and the `BotCallbackAnswer` returned.
29
+
30
+ If it's an inline `KeyboardButtonSwitchInline` button, the
31
+ `StartBot` will be invoked and the resulting updates
32
+ returned.
33
+
34
+ If it's a `KeyboardButtonUrl`, the URL of the button will
35
+ be returned.
36
+
37
+ If it's a `KeyboardButtonRequestPhone`, you must indicate that you
38
+ want to ``sharePhone=True`` in order to share it. Sharing it is not a
39
+ default because it is a privacy concern and could happen accidentally.
40
+
41
+ You may also use ``sharePhone=phone`` to share a specific number, in
42
+ which case either `str` or `InputMediaContact` should be used.
43
+
44
+ If it's a `KeyboardButtonRequestGeoLocation`, you must pass a
45
+ tuple in ``shareGeo=[longitude, latitude]``. Note that Telegram seems
46
+ to have some heuristics to determine impossible locations, so changing
47
+ this value a lot quickly may not work as expected. You may also pass a
48
+ `InputGeoPoint` if you find the order confusing.
49
+ */
50
+ click({ sharePhone, shareGeo, password, }: {
51
+ sharePhone?: boolean | string | Api.InputMediaContact;
52
+ shareGeo?: [number, number] | Api.InputMediaGeoPoint;
53
+ password?: string;
54
+ }): Promise<string | Api.Message | Api.messages.BotCallbackAnswer | Api.TypeUpdates | null | undefined>;
55
+ }
@@ -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
+ constructor(client, original, chat, bot, msgId) {
11
+ this.button = original;
12
+ this._bot = bot;
13
+ this._chat = chat;
14
+ this._msgId = msgId;
15
+ this._client = client;
16
+ }
17
+ [inspect_1.inspect.custom]() {
18
+ return (0, Helpers_1.betterConsoleLog)(this);
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,29 @@
1
+ /// <reference types="node" />
2
+ import type { Entity } from "../../define";
3
+ import type { SrooshClient } from "../..";
4
+ import { Api } from "../api";
5
+ import { ChatGetter } from "./chatGetter";
6
+ import bigInt from "big-integer";
7
+ import { inspect } from "../../inspect";
8
+ interface SenderGetterConstructorInterface {
9
+ senderId?: bigInt.BigInteger;
10
+ sender?: Entity;
11
+ inputSender?: Api.TypeInputPeer;
12
+ }
13
+ export declare class SenderGetter extends ChatGetter {
14
+ _senderId?: bigInt.BigInteger;
15
+ _sender?: Entity;
16
+ _inputSender?: Api.TypeInputPeer;
17
+ _client?: SrooshClient;
18
+ [inspect.custom](): {
19
+ [key: string]: any;
20
+ };
21
+ static initSenderClass(c: any, { senderId, sender, inputSender }: SenderGetterConstructorInterface): void;
22
+ get sender(): Entity | undefined;
23
+ getSender(): Promise<Entity | undefined>;
24
+ get inputSender(): Api.TypeInputPeer | undefined;
25
+ getInputSender(): Promise<Api.TypeInputPeer | undefined>;
26
+ get senderId(): bigInt.BigInteger | undefined;
27
+ _refetchSender(): Promise<void>;
28
+ }
29
+ 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,12 @@
1
+ /// <reference types="node" />
2
+ import type { DateLike } from "../define";
3
+ declare const snakeToCamelCase: (name: string) => string;
4
+ declare const variableSnakeToCamelCase: (str: string) => string;
5
+ declare const CORE_TYPES: Set<number>;
6
+ declare const fromLine: (line: string, isFunction: boolean) => any;
7
+ declare function buildArgConfig(name: string, argType: string): any;
8
+ declare const parseTl: (content: string, layer: string, methods?: any[], ignoreIds?: Set<number>) => Generator<any, void, unknown>;
9
+ declare const findAll: (regex: RegExp, str: string, matches?: any) => any;
10
+ export declare function serializeBytes(data: Buffer | string | any): Buffer;
11
+ export declare function serializeDate(dt: DateLike | Date): Buffer;
12
+ 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.buildArgConfig = exports.parseTl = exports.findAll = exports.serializeDate = exports.serializeBytes = void 0;
4
+ const Helpers_1 = require("../Helpers");
5
+ const snakeToCamelCase = (name) => {
6
+ const result = name.replace(/(?:^|_)([a-z])/g, (_, g) => g.toUpperCase());
7
+ return result.replace(/_/g, "");
8
+ };
9
+ exports.snakeToCamelCase = snakeToCamelCase;
10
+ const variableSnakeToCamelCase = (str) => str.replace(/([-_][a-z])/g, (group) => group.toUpperCase().replace("-", "").replace("_", ""));
11
+ exports.variableSnakeToCamelCase = variableSnakeToCamelCase;
12
+ const CORE_TYPES = new Set([
13
+ 0xbc799737,
14
+ 0x997275b5,
15
+ 0x3fedd339,
16
+ 0xc4b9f9bb,
17
+ 0x56730bcc, // null#56730bcc = Null;
18
+ ]);
19
+ exports.CORE_TYPES = CORE_TYPES;
20
+ const AUTH_KEY_TYPES = new Set([
21
+ 0x05162463,
22
+ 0x83c95aec,
23
+ 0xa9f55f95,
24
+ 0x3c6a84d4,
25
+ 0x56fddf88,
26
+ 0xd0e8075c,
27
+ 0xb5890dba,
28
+ 0x6643b654,
29
+ 0xd712e4be,
30
+ 0xf5045f1f,
31
+ 0x3072cfa1, // gzip_packed
32
+ ]);
33
+ const fromLine = (line, isFunction) => {
34
+ const match = line.match(/([\w.]+)(?:#([0-9a-fA-F]+))?(?:\s{?\w+:[\w\d<>#.?!]+}?)*\s=\s([\w\d<>#.?]+);$/);
35
+ if (!match) {
36
+ // Probably "vector#1cb5c415 {t:Type} # [ t ] = Vector t;"
37
+ throw new Error(`Cannot parse TLObject ${line}`);
38
+ }
39
+ const argsMatch = findAll(/({)?(\w+):([\w\d<>#.?!]+)}?/, line);
40
+ const currentConfig = {
41
+ name: match[1],
42
+ constructorId: parseInt(match[2], 16),
43
+ argsConfig: {},
44
+ subclassOfId: (0, Helpers_1.crc32)(match[3]),
45
+ result: match[3],
46
+ isFunction: isFunction,
47
+ namespace: undefined,
48
+ };
49
+ if (!currentConfig.constructorId) {
50
+ const hexId = "";
51
+ let args;
52
+ if (Object.values(currentConfig.argsConfig).length) {
53
+ args = ` ${Object.keys(currentConfig.argsConfig)
54
+ .map((arg) => arg.toString())
55
+ .join(" ")}`;
56
+ }
57
+ else {
58
+ args = "";
59
+ }
60
+ const representation = `${currentConfig.name}${hexId}${args} = ${currentConfig.result}`
61
+ .replace(/(:|\?)bytes /g, "$1string ")
62
+ .replace(/</g, " ")
63
+ .replace(/>|{|}/g, "")
64
+ .replace(/ \w+:flags(\d+)?\.\d+\?true/g, "");
65
+ if (currentConfig.name === "inputMediaInvoice") {
66
+ // eslint-disable-next-line no-empty
67
+ if (currentConfig.name === "inputMediaInvoice") {
68
+ }
69
+ }
70
+ currentConfig.constructorId = (0, Helpers_1.crc32)(Buffer.from(representation, "utf8"));
71
+ }
72
+ for (const [brace, name, argType] of argsMatch) {
73
+ if (brace === undefined) {
74
+ // @ts-ignore
75
+ currentConfig.argsConfig[variableSnakeToCamelCase(name)] =
76
+ buildArgConfig(name, argType);
77
+ }
78
+ }
79
+ if (currentConfig.name.includes(".")) {
80
+ [currentConfig.namespace, currentConfig.name] =
81
+ currentConfig.name.split(/\.(.+)/);
82
+ }
83
+ currentConfig.name = snakeToCamelCase(currentConfig.name);
84
+ /*
85
+ for (const arg in currentConfig.argsConfig){
86
+ if (currentConfig.argsConfig.hasOwnProperty(arg)){
87
+ if (currentConfig.argsConfig[arg].flagIndicator){
88
+ delete currentConfig.argsConfig[arg]
89
+ }
90
+ }
91
+ }*/
92
+ return currentConfig;
93
+ };
94
+ exports.fromLine = fromLine;
95
+ function buildArgConfig(name, argType) {
96
+ name = name === "self" ? "is_self" : name;
97
+ // Default values
98
+ const currentConfig = {
99
+ isVector: false,
100
+ isFlag: false,
101
+ skipConstructorId: false,
102
+ flagName: null,
103
+ flagIndex: -1,
104
+ flagIndicator: true,
105
+ type: null,
106
+ useVectorId: null,
107
+ };
108
+ // Special case: some types can be inferred, which makes it
109
+ // less annoying to type. Currently the only type that can
110
+ // be inferred is if the name is 'random_id', to which a
111
+ // random ID will be assigned if left as None (the default)
112
+ const canBeInferred = name === "random_id";
113
+ // The type can be an indicator that other arguments will be flags
114
+ if (argType !== "#") {
115
+ currentConfig.flagIndicator = false;
116
+ // Strip the exclamation mark always to have only the name
117
+ currentConfig.type = argType.replace(/^!+/, "");
118
+ // The type may be a flag (flags.IDX?REAL_TYPE)
119
+ // Note that 'flags' is NOT the flags name; this
120
+ // is determined by a previous argument
121
+ // However, we assume that the argument will always be starts with 'flags'
122
+ // @ts-ignore
123
+ const flagMatch = currentConfig.type.match(/(flags(?:\d+)?).(\d+)\?([\w<>.]+)/);
124
+ if (flagMatch) {
125
+ currentConfig.isFlag = true;
126
+ // As of layer 140, flagName can be "flags" or "flags2"
127
+ currentConfig.flagName = flagMatch[1];
128
+ currentConfig.flagIndex = Number(flagMatch[2]);
129
+ // Update the type to match the exact type, not the "flagged" one
130
+ currentConfig.type = flagMatch[3];
131
+ }
132
+ // Then check if the type is a Vector<REAL_TYPE>
133
+ // @ts-ignore
134
+ const vectorMatch = currentConfig.type.match(/[Vv]ector<([\w\d.]+)>/);
135
+ if (vectorMatch) {
136
+ currentConfig.isVector = true;
137
+ // If the type's first letter is not uppercase, then
138
+ // it is a constructor and we use (read/write) its ID.
139
+ // @ts-ignore
140
+ currentConfig.useVectorId = currentConfig.type.charAt(0) === "V";
141
+ // Update the type to match the one inside the vector
142
+ [, currentConfig.type] = vectorMatch;
143
+ }
144
+ // See use_vector_id. An example of such case is ipPort in
145
+ // help.configSpecial
146
+ // @ts-ignore
147
+ if (/^[a-z]$/.test(currentConfig.type.split(".").pop().charAt(0))) {
148
+ currentConfig.skipConstructorId = true;
149
+ }
150
+ // The name may contain "date" in it, if this is the case and
151
+ // the type is "int", we can safely assume that this should be
152
+ // treated as a "date" object. Note that this is not a valid
153
+ // Telegram object, but it's easier to work with
154
+ // if (
155
+ // this.type === 'int' &&
156
+ // (/(\b|_)([dr]ate|until|since)(\b|_)/.test(name) ||
157
+ // ['expires', 'expires_at', 'was_online'].includes(name))
158
+ // ) {
159
+ // this.type = 'date';
160
+ // }
161
+ }
162
+ // workaround
163
+ if (currentConfig.type == "future_salt") {
164
+ currentConfig.type = "FutureSalt";
165
+ }
166
+ return currentConfig;
167
+ }
168
+ exports.buildArgConfig = buildArgConfig;
169
+ const parseTl = function* (content, layer, methods = [], ignoreIds = CORE_TYPES) {
170
+ const methodInfo = (methods || []).reduce((o, m) => (Object.assign(Object.assign({}, o), { [m.name]: m })), {});
171
+ const objAll = [];
172
+ const objByName = {};
173
+ const objByType = {};
174
+ const file = content;
175
+ let isFunction = false;
176
+ for (let line of file.split("\n")) {
177
+ const commentIndex = line.indexOf("//");
178
+ if (commentIndex !== -1) {
179
+ line = line.slice(0, commentIndex);
180
+ }
181
+ line = line.trim();
182
+ if (!line) {
183
+ continue;
184
+ }
185
+ const match = line.match(/---(\w+)---/);
186
+ if (match) {
187
+ const [, followingTypes] = match;
188
+ isFunction = followingTypes === "functions";
189
+ continue;
190
+ }
191
+ try {
192
+ const result = fromLine(line, isFunction);
193
+ if (ignoreIds.has(result.constructorId)) {
194
+ continue;
195
+ }
196
+ objAll.push(result);
197
+ if (!result.isFunction) {
198
+ if (!objByType[result.result]) {
199
+ objByType[result.result] = [];
200
+ }
201
+ objByName[result.name] = result;
202
+ objByType[result.result].push(result);
203
+ }
204
+ }
205
+ catch (e) {
206
+ if (!e.toString().includes("vector#1cb5c415")) {
207
+ throw e;
208
+ }
209
+ }
210
+ }
211
+ // Once all objects have been parsed, replace the
212
+ // string type from the arguments with references
213
+ for (const obj of objAll) {
214
+ if (AUTH_KEY_TYPES.has(obj.constructorId)) {
215
+ for (const arg in obj.argsConfig) {
216
+ if (obj.argsConfig[arg].type === "string") {
217
+ obj.argsConfig[arg].type = "bytes";
218
+ }
219
+ }
220
+ }
221
+ }
222
+ for (const obj of objAll) {
223
+ yield obj;
224
+ }
225
+ };
226
+ exports.parseTl = parseTl;
227
+ const findAll = (regex, str, matches = []) => {
228
+ if (!regex.flags.includes("g")) {
229
+ regex = new RegExp(regex.source, "g");
230
+ }
231
+ const res = regex.exec(str);
232
+ if (res) {
233
+ matches.push(res.slice(1));
234
+ findAll(regex, str, matches);
235
+ }
236
+ return matches;
237
+ };
238
+ exports.findAll = findAll;
239
+ function serializeBytes(data) {
240
+ if (!(data instanceof Buffer)) {
241
+ if (typeof data == "string") {
242
+ data = Buffer.from(data);
243
+ }
244
+ else {
245
+ throw Error(`Bytes or str expected, not ${data.constructor.name}`);
246
+ }
247
+ }
248
+ const r = [];
249
+ let padding;
250
+ if (data.length < 254) {
251
+ padding = (data.length + 1) % 4;
252
+ if (padding !== 0) {
253
+ padding = 4 - padding;
254
+ }
255
+ r.push(Buffer.from([data.length]));
256
+ r.push(data);
257
+ }
258
+ else {
259
+ padding = data.length % 4;
260
+ if (padding !== 0) {
261
+ padding = 4 - padding;
262
+ }
263
+ r.push(Buffer.from([
264
+ 254,
265
+ data.length % 256,
266
+ (data.length >> 8) % 256,
267
+ (data.length >> 16) % 256,
268
+ ]));
269
+ r.push(data);
270
+ }
271
+ r.push(Buffer.alloc(padding).fill(0));
272
+ return Buffer.concat(r);
273
+ }
274
+ exports.serializeBytes = serializeBytes;
275
+ function serializeDate(dt) {
276
+ if (!dt) {
277
+ return Buffer.alloc(4).fill(0);
278
+ }
279
+ if (dt instanceof Date) {
280
+ dt = Math.floor((Date.now() - dt.getTime()) / 1000);
281
+ }
282
+ if (typeof dt == "number") {
283
+ const t = Buffer.alloc(4);
284
+ t.writeInt32LE(dt, 0);
285
+ return t;
286
+ }
287
+ throw Error(`Cannot interpret "${dt}" as a date`);
288
+ }
289
+ exports.serializeDate = serializeDate;
package/tl/index.d.ts ADDED
@@ -0,0 +1,3 @@
1
+ import { Api } from "./api";
2
+ export { Api };
3
+ export { serializeBytes, serializeDate } from "./generationHelpers";
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; } });
@@ -0,0 +1,2 @@
1
+ declare function patchAll(): void;
2
+ export { patchAll };