@mtkruto/node 0.0.832 → 0.0.835

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 (127) hide show
  1. package/esm/client/client.d.ts +7 -2
  2. package/esm/client/client.js +66 -13
  3. package/esm/client/client_abstract.d.ts +2 -2
  4. package/esm/client/client_abstract.js +3 -8
  5. package/esm/client/client_plain.js +8 -7
  6. package/esm/connection/connection.d.ts +2 -1
  7. package/esm/connection/connection_web_socket.d.ts +1 -0
  8. package/esm/connection/connection_web_socket.js +3 -0
  9. package/esm/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
  10. package/esm/deps/deno.land/std@0.69.0/fmt/colors.js +224 -0
  11. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
  12. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +71 -0
  13. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
  14. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +112 -0
  15. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
  16. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +2 -0
  17. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
  18. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +39 -0
  19. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
  20. package/esm/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +1 -0
  21. package/esm/deps.d.ts +2 -0
  22. package/esm/deps.js +2 -0
  23. package/esm/storage/storage.d.ts +1 -1
  24. package/esm/storage/storage_local_storage.d.ts +1 -1
  25. package/esm/storage/storage_memory.d.ts +1 -1
  26. package/esm/storage/storage_session_storage.d.ts +1 -1
  27. package/esm/transport/transport.d.ts +1 -1
  28. package/esm/types/0_chat_administrator_rights.d.ts +17 -0
  29. package/esm/types/0_chat_administrator_rights.js +38 -0
  30. package/esm/types/0_chat_photo.d.ts +24 -0
  31. package/esm/types/0_chat_photo.js +28 -0
  32. package/esm/types/0_force_reply.d.ts +8 -0
  33. package/esm/types/0_force_reply.js +17 -0
  34. package/esm/types/0_keyboard_button_poll_type.d.ts +3 -0
  35. package/esm/types/0_login_url.d.ts +6 -0
  36. package/esm/types/0_login_url.js +1 -0
  37. package/esm/types/0_message_entity.d.ts +1 -1
  38. package/esm/types/0_message_entity.js +2 -2
  39. package/esm/types/0_reply_keyboard_remove.d.ts +7 -0
  40. package/esm/types/0_reply_keyboard_remove.js +8 -0
  41. package/esm/types/0_web_app_info.d.ts +4 -0
  42. package/esm/types/0_web_app_info.js +3 -0
  43. package/esm/types/1_chat.d.ts +60 -0
  44. package/esm/types/1_chat.js +70 -0
  45. package/esm/types/1_inline_keyboard_button.d.ts +33 -0
  46. package/esm/types/1_inline_keyboard_button.js +63 -0
  47. package/esm/types/1_keyboard_button.d.ts +43 -0
  48. package/esm/types/1_keyboard_button.js +133 -0
  49. package/esm/types/1_user.d.ts +19 -0
  50. package/esm/types/1_user.js +25 -0
  51. package/esm/types/2_inline_keyboard_markup.d.ts +7 -0
  52. package/esm/types/2_inline_keyboard_markup.js +25 -0
  53. package/esm/types/2_reply_keyboard_markup.d.ts +12 -0
  54. package/esm/types/2_reply_keyboard_markup.js +37 -0
  55. package/esm/types/3_message.d.ts +22 -0
  56. package/esm/types/3_message.js +87 -0
  57. package/esm/utilities/0_control.d.ts +1 -0
  58. package/esm/utilities/0_control.js +3 -0
  59. package/esm/utilities/0_object.d.ts +1 -0
  60. package/esm/utilities/0_object.js +14 -0
  61. package/esm/utilities/0_types.js +1 -0
  62. package/package.json +8 -6
  63. package/script/client/client.d.ts +7 -2
  64. package/script/client/client.js +65 -12
  65. package/script/client/client_abstract.d.ts +2 -2
  66. package/script/client/client_abstract.js +3 -8
  67. package/script/client/client_plain.js +7 -6
  68. package/script/connection/connection.d.ts +2 -1
  69. package/script/connection/connection_web_socket.d.ts +1 -0
  70. package/script/connection/connection_web_socket.js +3 -0
  71. package/script/deps/deno.land/std@0.69.0/fmt/colors.d.ts +77 -0
  72. package/script/deps/deno.land/std@0.69.0/fmt/colors.js +298 -0
  73. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.d.ts +3 -0
  74. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/colors.js +98 -0
  75. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.d.ts +22 -0
  76. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/debug.js +141 -0
  77. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.d.ts +2 -0
  78. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/deps.js +32 -0
  79. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.d.ts +1 -0
  80. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/format.js +43 -0
  81. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.d.ts +1 -0
  82. package/script/deps/raw.githubusercontent.com/MTKruto/debug/master/mod.js +17 -0
  83. package/script/deps.d.ts +2 -0
  84. package/script/deps.js +4 -1
  85. package/script/storage/storage.d.ts +1 -1
  86. package/script/storage/storage_local_storage.d.ts +1 -1
  87. package/script/storage/storage_memory.d.ts +1 -1
  88. package/script/storage/storage_session_storage.d.ts +1 -1
  89. package/script/transport/transport.d.ts +1 -1
  90. package/script/types/0_chat_administrator_rights.d.ts +17 -0
  91. package/script/types/0_chat_administrator_rights.js +66 -0
  92. package/script/types/0_chat_photo.d.ts +24 -0
  93. package/script/types/0_chat_photo.js +55 -0
  94. package/script/types/0_force_reply.d.ts +8 -0
  95. package/script/types/0_force_reply.js +45 -0
  96. package/script/types/0_keyboard_button_poll_type.d.ts +3 -0
  97. package/script/types/0_login_url.d.ts +6 -0
  98. package/script/types/0_login_url.js +2 -0
  99. package/script/types/0_message_entity.d.ts +1 -1
  100. package/script/types/0_message_entity.js +2 -2
  101. package/script/types/0_reply_keyboard_remove.d.ts +7 -0
  102. package/script/types/0_reply_keyboard_remove.js +36 -0
  103. package/script/types/0_web_app_info.d.ts +4 -0
  104. package/script/types/0_web_app_info.js +7 -0
  105. package/script/types/1_chat.d.ts +60 -0
  106. package/script/types/1_chat.js +97 -0
  107. package/script/types/1_inline_keyboard_button.d.ts +33 -0
  108. package/script/types/1_inline_keyboard_button.js +91 -0
  109. package/script/types/1_keyboard_button.d.ts +43 -0
  110. package/script/types/1_keyboard_button.js +161 -0
  111. package/script/types/1_user.d.ts +19 -0
  112. package/script/types/1_user.js +52 -0
  113. package/script/types/2_inline_keyboard_markup.d.ts +7 -0
  114. package/script/types/2_inline_keyboard_markup.js +53 -0
  115. package/script/types/2_reply_keyboard_markup.d.ts +12 -0
  116. package/script/types/2_reply_keyboard_markup.js +65 -0
  117. package/script/types/3_message.d.ts +22 -0
  118. package/script/types/3_message.js +114 -0
  119. package/script/utilities/0_control.d.ts +1 -0
  120. package/script/utilities/0_control.js +7 -0
  121. package/script/utilities/0_object.d.ts +1 -0
  122. package/script/utilities/0_object.js +18 -0
  123. package/script/utilities/0_types.js +2 -0
  124. /package/esm/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
  125. /package/esm/{types.d.ts → utilities/0_types.d.ts} +0 -0
  126. /package/script/{types.js → types/0_keyboard_button_poll_type.js} +0 -0
  127. /package/script/{types.d.ts → utilities/0_types.d.ts} +0 -0
@@ -0,0 +1,87 @@
1
+ import { UNREACHABLE } from "../utilities/0_control.js";
2
+ import { cleanObject } from "../utilities/0_object.js";
3
+ import * as types from "../tl/2_types.js";
4
+ import { constructForceReply } from "./0_force_reply.js";
5
+ import { constructMessageEntity } from "./0_message_entity.js";
6
+ import { constructReplyKeyboardRemove } from "./0_reply_keyboard_remove.js";
7
+ import { constructChat } from "./1_chat.js";
8
+ import { constructUser } from "./1_user.js";
9
+ import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
10
+ import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
11
+ export function constructMessage(message_, users, chats) {
12
+ let chat_ = null;
13
+ if (message_.peerId instanceof types.PeerUser) {
14
+ for (const user of users) {
15
+ if (user instanceof types.User && user.id == message_.peerId.userId) {
16
+ chat_ = constructChat(user);
17
+ break;
18
+ }
19
+ }
20
+ }
21
+ else if (message_.peerId instanceof types.PeerChat) {
22
+ for (const chat of chats) {
23
+ if (chat instanceof types.Chat && chat.id == message_.peerId.chatId) {
24
+ chat_ = constructChat(chat);
25
+ break;
26
+ }
27
+ }
28
+ }
29
+ else if (message_.peerId instanceof types.PeerChannel) {
30
+ for (const chat of chats) {
31
+ if (chat instanceof types.Channel && chat.id == message_.peerId.channelId) {
32
+ chat_ = constructChat(chat);
33
+ break;
34
+ }
35
+ }
36
+ }
37
+ if (!chat_) {
38
+ UNREACHABLE();
39
+ }
40
+ const message = { id: message_.id, chat: chat_, views: message_.views };
41
+ if (message_.fromId instanceof types.PeerUser) {
42
+ for (const user of users) {
43
+ if (user instanceof types.User && user.id == message_.fromId.userId) {
44
+ message.from = constructUser(user);
45
+ break;
46
+ }
47
+ }
48
+ }
49
+ if (message_.message) {
50
+ if (message_.media == undefined) {
51
+ message.text = message_.message;
52
+ }
53
+ else {
54
+ message.caption = message_.message;
55
+ }
56
+ }
57
+ if (message_.entities != undefined) {
58
+ if (message_.media == undefined) {
59
+ message.entities = message_.entities.map(constructMessageEntity).filter((v) => v);
60
+ }
61
+ else {
62
+ message.captionEntities = message_.entities.map(constructMessageEntity).filter((v) => v);
63
+ }
64
+ }
65
+ message.date = new Date(message_.date * 1000);
66
+ if (message_.editDate != undefined) {
67
+ message.editDate = new Date(message_.editDate * 1000);
68
+ }
69
+ if (message_.replyMarkup) {
70
+ if (message_.replyMarkup instanceof types.ReplyKeyboardMarkup) {
71
+ message.replyMarkup = constructReplyKeyboardMarkup(message_.replyMarkup);
72
+ }
73
+ else if (message_.replyMarkup instanceof types.ReplyInlineMarkup) {
74
+ message.replyMarkup = constructInlineKeyboardMarkup(message_.replyMarkup);
75
+ }
76
+ else if (message_.replyMarkup instanceof types.ReplyKeyboardHide) {
77
+ message.replyMarkup = constructReplyKeyboardRemove(message_.replyMarkup);
78
+ }
79
+ else if (message_.replyMarkup instanceof types.ReplyKeyboardForceReply) {
80
+ message.replyMarkup = constructForceReply(message_.replyMarkup);
81
+ }
82
+ else {
83
+ UNREACHABLE();
84
+ }
85
+ }
86
+ return cleanObject(message);
87
+ }
@@ -0,0 +1 @@
1
+ export declare function UNREACHABLE(): never;
@@ -0,0 +1,3 @@
1
+ export function UNREACHABLE() {
2
+ throw new Error("Unreachable");
3
+ }
@@ -0,0 +1 @@
1
+ export declare function cleanObject<T extends Record<string, any>>(object: T): T;
@@ -0,0 +1,14 @@
1
+ // deno-lint-ignore no-explicit-any
2
+ export function cleanObject(object) {
3
+ for (const [k, v] of Object.entries(object)) {
4
+ switch (typeof v) {
5
+ case "undefined":
6
+ delete object[k];
7
+ break;
8
+ case "object":
9
+ // @ts-ignore: this works, no idea why it complains
10
+ object[k] = cleanObject(v);
11
+ }
12
+ }
13
+ return object;
14
+ }
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "module": "./esm/mod.js",
3
3
  "main": "./script/mod.js",
4
4
  "name": "@mtkruto/node",
5
- "version": "0.0.832",
5
+ "version": "0.0.835",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -10,6 +10,12 @@
10
10
  "type": "git",
11
11
  "url": "git+https://github.com/MTKruto/MTKruto.git"
12
12
  },
13
+ "devDependencies": {
14
+ "@types/node": "^18.11.9",
15
+ "picocolors": "^1.0.0",
16
+ "@types/ws": "^8.5.4",
17
+ "@types/object-inspect": "^1.8.1"
18
+ },
13
19
  "exports": {
14
20
  ".": {
15
21
  "import": "./esm/mod.js",
@@ -21,13 +27,9 @@
21
27
  },
22
28
  "dependencies": {
23
29
  "async-mutex": "0.4.0",
30
+ "object-inspect": "1.12.3",
24
31
  "@deno/shim-deno": "~0.16.1",
25
32
  "@deno/shim-crypto": "~0.3.1",
26
33
  "ws": "^8.13.0"
27
- },
28
- "devDependencies": {
29
- "@types/node": "^18.11.9",
30
- "picocolors": "^1.0.0",
31
- "@types/ws": "^8.5.4"
32
34
  }
33
35
  }
@@ -1,10 +1,14 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  import * as types from "../tl/2_types.js";
3
3
  import * as functions from "../tl/3_functions.js";
4
4
  import { ClientAbstract } from "./client_abstract.js";
5
5
  import { Storage } from "../storage/storage.js";
6
6
  import { DC, TransportProvider } from "../transport/transport_provider.js";
7
7
  import { MessageEntity } from "../types/0_message_entity.js";
8
+ import { ReplyKeyboardRemove } from "../types/0_reply_keyboard_remove.js";
9
+ import { ForceReply } from "../types/0_force_reply.js";
10
+ import { ReplyKeyboardMarkup } from "../types/2_reply_keyboard_markup.js";
11
+ import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
8
12
  export declare const restartAuth: unique symbol;
9
13
  export declare enum ParseMode {
10
14
  None = "none",
@@ -136,5 +140,6 @@ export declare class Client extends ClientAbstract {
136
140
  replyToMessageId?: number;
137
141
  messageThreadId?: number;
138
142
  sendAs?: number | string;
139
- }): Promise<types.TypeUpdates>;
143
+ replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
144
+ }): Promise<import("../types/3_message.js").Message>;
140
145
  }
@@ -27,6 +27,8 @@ exports.Client = exports.ParseMode = exports.restartAuth = void 0;
27
27
  const deps_js_1 = require("../deps.js");
28
28
  const constants_js_1 = require("../constants.js");
29
29
  const _0_bigint_js_1 = require("../utilities/0_bigint.js");
30
+ const _0_control_js_1 = require("../utilities/0_control.js");
31
+ const _0_hash_js_1 = require("../utilities/0_hash.js");
30
32
  const _0_html_js_1 = require("../utilities/0_html.js");
31
33
  const _1_message_js_1 = require("../utilities/1_message.js");
32
34
  const _1_password_js_1 = require("../utilities/1_password.js");
@@ -40,8 +42,13 @@ const _6_message_container_js_1 = require("../tl/6_message_container.js");
40
42
  const client_abstract_js_1 = require("./client_abstract.js");
41
43
  const client_plain_js_1 = require("./client_plain.js");
42
44
  const storage_memory_js_1 = require("../storage/storage_memory.js");
43
- const _0_hash_js_1 = require("../utilities/0_hash.js");
44
45
  const _0_message_entity_js_1 = require("../types/0_message_entity.js");
46
+ const _0_reply_keyboard_remove_js_1 = require("../types/0_reply_keyboard_remove.js");
47
+ const _0_force_reply_js_1 = require("../types/0_force_reply.js");
48
+ const _2_reply_keyboard_markup_js_1 = require("../types/2_reply_keyboard_markup.js");
49
+ const _2_inline_keyboard_markup_js_1 = require("../types/2_inline_keyboard_markup.js");
50
+ const _3_message_js_1 = require("../types/3_message.js");
51
+ const d = (0, deps_js_1.debug)("client");
45
52
  exports.restartAuth = Symbol();
46
53
  var ParseMode;
47
54
  (function (ParseMode) {
@@ -226,7 +233,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
226
233
  if (dc == null) {
227
234
  await this.storage.setDc(constants_js_1.DEFAULT_INITIAL_DC);
228
235
  }
229
- // logger().debug("Client connected");
236
+ d("enrypted client connected");
230
237
  this.receiveLoop();
231
238
  this.pingLoop();
232
239
  }
@@ -254,6 +261,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
254
261
  if (!this.apiHash) {
255
262
  throw new Error("apiHash not set");
256
263
  }
264
+ d("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
257
265
  await this.invoke(new functions.InitConnection({
258
266
  apiId: this.apiId,
259
267
  appVersion: this.appVersion,
@@ -267,6 +275,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
267
275
  systemLangCode: this.systemLangCode,
268
276
  systemVersion: this.systemVersion,
269
277
  }));
278
+ d("connection inited");
270
279
  const handlePassword = async (err) => {
271
280
  params = params;
272
281
  if (err instanceof types.RPCError && err.errorMessage == "SESSION_PASSWORD_NEEDED") {
@@ -277,6 +286,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
277
286
  const password = typeof params.password === "string" ? params.password : await params.password();
278
287
  const input = await (0, _1_password_js_1.checkPassword)(password, ap);
279
288
  await this.invoke(new functions.AuthCheckPassword({ password: input }));
289
+ d("authorized as user");
280
290
  break;
281
291
  }
282
292
  catch (err) {
@@ -299,6 +309,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
299
309
  };
300
310
  try {
301
311
  await this.invoke(new functions.UpdatesGetState());
312
+ d("already authorized");
302
313
  return;
303
314
  }
304
315
  catch (err) {
@@ -311,6 +322,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
311
322
  try {
312
323
  if (params instanceof types.AuthExportedAuthorization) {
313
324
  await this.invoke(new functions.AuthImportAuthorization({ id: params.id, bytes: params.bytes }));
325
+ d("authorization imported");
314
326
  }
315
327
  else if (typeof params == "object") {
316
328
  while (true) {
@@ -326,6 +338,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
326
338
  phoneNumber,
327
339
  settings: new types.CodeSettings(),
328
340
  }));
341
+ d("verification code sent");
329
342
  if (sentCode instanceof types.AuthSentCode) {
330
343
  while (true) {
331
344
  const phoneCode = typeof params.code === "string" ? params.code : await params.code();
@@ -336,6 +349,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
336
349
  }
337
350
  else {
338
351
  signedIn = true;
352
+ d("authorized as user");
339
353
  break;
340
354
  }
341
355
  }
@@ -369,6 +383,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
369
383
  }
370
384
  else {
371
385
  await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
386
+ d("authorized as bot");
372
387
  }
373
388
  }
374
389
  catch (err) {
@@ -380,6 +395,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
380
395
  newDc += "-test";
381
396
  }
382
397
  await this.reconnect(newDc);
398
+ d("migrated to DC%s", newDc);
383
399
  if (typeof params === "object" && phoneNumber != null) {
384
400
  params = Object.assign({}, params);
385
401
  params.phone = phoneNumber;
@@ -420,8 +436,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
420
436
  try {
421
437
  decrypted = await (0, _1_message_js_1.decryptMessage)(buffer, this.auth.key, this.auth.id, this.sessionId);
422
438
  }
423
- catch (_err) {
424
- // logger().error(`Failed to decrypt message: ${err}`);
439
+ catch (err) {
440
+ d("failed to decrypt message: %o", err);
425
441
  continue;
426
442
  }
427
443
  const messages = decrypted instanceof _6_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
@@ -430,7 +446,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
430
446
  if (body instanceof types.GZIPPacked) {
431
447
  body = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(body.packedData)).readObject();
432
448
  }
433
- // logger().debug(`Received ${body.constructor.name}`);
449
+ d("received %s", body.constructor.name);
434
450
  if (body instanceof types.Updates) {
435
451
  this.processUpdates(body);
436
452
  }
@@ -439,6 +455,12 @@ class Client extends client_abstract_js_1.ClientAbstract {
439
455
  if (result instanceof types.GZIPPacked) {
440
456
  result = new _3_tl_reader_js_1.TLReader((0, deps_js_1.gunzip)(result.packedData)).readObject();
441
457
  }
458
+ if (result instanceof types.RPCError) {
459
+ d("RPCResult: %d %s", result.errorCode, result.errorMessage);
460
+ }
461
+ else {
462
+ d("RPCResult: %s", result.constructor.name);
463
+ }
442
464
  const promise = this.promises.get(message.body.messageId);
443
465
  if (promise) {
444
466
  if (result instanceof types.RPCError) {
@@ -480,8 +502,8 @@ class Client extends client_abstract_js_1.ClientAbstract {
480
502
  try {
481
503
  await this.invoke(new functions.Ping({ pingId: (0, _0_bigint_js_1.getRandomBigInt)(8, true, false) }));
482
504
  }
483
- catch (_err) {
484
- // logger().error(`Failed to invoke ping: ${err}`);
505
+ catch (err) {
506
+ d("ping loop error: %o", err);
485
507
  }
486
508
  await new Promise((r) => setTimeout(r, 60 * 1000));
487
509
  }
@@ -497,7 +519,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
497
519
  }
498
520
  const message = new _5_message_js_1.Message((0, _1_message_js_1.getMessageId)(), seqNo, function_);
499
521
  await this.transport.send(await (0, _1_message_js_1.encryptMessage)(message, this.auth.key, this.auth.id, this.state.salt, this.sessionId));
500
- // logger().debug(`Invoked ${function_.constructor.name}`);
522
+ d("invoked %s", function_.constructor.name);
501
523
  if (noWait) {
502
524
  return;
503
525
  }
@@ -591,7 +613,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
591
613
  channelId = resolved.peer.channelId;
592
614
  }
593
615
  else {
594
- throw new Error("Unreachable");
616
+ (0, _0_control_js_1.UNREACHABLE)();
595
617
  }
596
618
  }
597
619
  if (userId) {
@@ -603,7 +625,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
603
625
  return new types.InputPeerChannel({ channelId, accessHash: accessHash ?? 0n });
604
626
  }
605
627
  else {
606
- throw new Error("Unreachable");
628
+ (0, _0_control_js_1.UNREACHABLE)();
607
629
  }
608
630
  }
609
631
  }
@@ -638,6 +660,27 @@ class Client extends client_abstract_js_1.ClientAbstract {
638
660
  }
639
661
  }
640
662
  }
663
+ let replyMarkup = undefined;
664
+ if (params?.replyMarkup) {
665
+ if ("inlineKeyboard" in params.replyMarkup) {
666
+ replyMarkup = await (0, _2_inline_keyboard_markup_js_1.inlineKeyboardMarkupToTlObject)(params.replyMarkup, async (v) => {
667
+ const inputPeer = await this.getInputPeer(v).then((v) => v[_1_tl_object_js_1.as](types.InputPeerUser));
668
+ return new types.InputUser({ userId: inputPeer.userId, accessHash: inputPeer.accessHash });
669
+ });
670
+ }
671
+ else if ("keyboard" in params.replyMarkup) {
672
+ replyMarkup = (0, _2_reply_keyboard_markup_js_1.replyKeyboardMarkupToTlObject)(params.replyMarkup);
673
+ }
674
+ else if ("removeKeyboard" in params.replyMarkup) {
675
+ replyMarkup = (0, _0_reply_keyboard_remove_js_1.replyKeyboardRemoveToTlObject)(params.replyMarkup);
676
+ }
677
+ else if ("forceReply" in params.replyMarkup) {
678
+ replyMarkup = (0, _0_force_reply_js_1.forceReplyToTlObject)(params.replyMarkup);
679
+ }
680
+ else {
681
+ throw new Error("The replyMarkup parameter has an unexpected type");
682
+ }
683
+ }
641
684
  const peer = await this.getInputPeer(chatId);
642
685
  const randomId = (0, _0_bigint_js_1.getRandomId)();
643
686
  const message = text;
@@ -648,7 +691,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
648
691
  const topMsgId = params?.messageThreadId;
649
692
  const sendAs = params?.sendAs ? await this.getInputPeer(params.sendAs) : undefined;
650
693
  const entities = entities_?.length > 0 ? entities_.map((v) => (0, _0_message_entity_js_1.messageEntityToTlObject)(v)) : undefined;
651
- return await this.invoke(new functions.MessagesSendMessage({
694
+ const updates = await this.invoke(new functions.MessagesSendMessage({
652
695
  peer,
653
696
  randomId,
654
697
  message,
@@ -659,7 +702,17 @@ class Client extends client_abstract_js_1.ClientAbstract {
659
702
  topMsgId,
660
703
  sendAs,
661
704
  entities,
662
- }));
705
+ replyMarkup,
706
+ })).then((v) => v[_1_tl_object_js_1.as](types.Updates));
707
+ for (const update of updates.updates) {
708
+ if (update instanceof types.UpdateNewMessage) {
709
+ return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), updates.users, updates.chats);
710
+ }
711
+ else if (update instanceof types.UpdateNewChannelMessage) {
712
+ return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), updates.users, updates.chats);
713
+ }
714
+ }
715
+ (0, _0_control_js_1.UNREACHABLE)();
663
716
  }
664
717
  }
665
718
  exports.Client = Client;
@@ -1,16 +1,16 @@
1
+ import { MaybePromise } from "../utilities/0_types.js";
1
2
  import { Connection } from "../connection/connection.js";
2
3
  import { Transport } from "../transport/transport.js";
3
4
  import { DC } from "../transport/transport_provider.js";
4
- import { MaybePromise } from "../types.js";
5
5
  export declare abstract class ClientAbstract {
6
6
  protected transportProvider: import("../transport/transport_provider.js").TransportProvider;
7
7
  protected connection: Connection;
8
8
  protected transport: Transport;
9
9
  private _dcId;
10
- protected connected: boolean;
11
10
  constructor(transportProvider?: import("../transport/transport_provider.js").TransportProvider);
12
11
  get dcId(): number;
13
12
  setDc(dc: DC): MaybePromise<void>;
13
+ get connected(): boolean;
14
14
  connect(): Promise<void>;
15
15
  reconnect(dc?: DC): Promise<void>;
16
16
  disconnect(): Promise<void>;
@@ -30,12 +30,6 @@ class ClientAbstract {
30
30
  writable: true,
31
31
  value: void 0
32
32
  });
33
- Object.defineProperty(this, "connected", {
34
- enumerable: true,
35
- configurable: true,
36
- writable: true,
37
- value: false
38
- });
39
33
  const { connection, transport, dcId } = transportProvider({ cdn: false });
40
34
  this.connection = connection;
41
35
  this.transport = transport;
@@ -51,11 +45,13 @@ class ClientAbstract {
51
45
  this.transport = transport;
52
46
  this._dcId = dcId;
53
47
  }
48
+ get connected() {
49
+ return this.connection.connected;
50
+ }
54
51
  async connect() {
55
52
  await (0, deps_js_1.initTgCrypto)();
56
53
  await this.connection.open();
57
54
  await this.transport.initialize();
58
- this.connected = true;
59
55
  }
60
56
  async reconnect(dc) {
61
57
  await this.disconnect();
@@ -67,7 +63,6 @@ class ClientAbstract {
67
63
  async disconnect() {
68
64
  await this.transport.deinitialize();
69
65
  await this.connection.close();
70
- this.connected = false;
71
66
  }
72
67
  }
73
68
  exports.ClientAbstract = ClientAbstract;
@@ -13,6 +13,7 @@ const _2_types_js_1 = require("../tl/2_types.js");
13
13
  const _3_functions_js_1 = require("../tl/3_functions.js");
14
14
  const _3_tl_reader_js_1 = require("../tl/3_tl_reader.js");
15
15
  const client_abstract_js_1 = require("./client_abstract.js");
16
+ const d = (0, deps_js_1.debug)("auth_key_creation");
16
17
  class ClientPlain extends client_abstract_js_1.ClientAbstract {
17
18
  async invoke(function_) {
18
19
  await this.transport.send((0, _1_message_js_1.packUnencryptedMessage)(function_[_1_tl_object_js_1.serialize]()));
@@ -29,14 +30,14 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
29
30
  }
30
31
  async createAuthKey() {
31
32
  const nonce = (0, _0_bigint_js_1.getRandomBigInt)(16, false, true);
32
- // logger().debug("Auth key creation started");
33
+ d("auth key creation started");
33
34
  const resPq = await this.invoke(new _3_functions_js_1.ReqPQMulti({ nonce }));
34
35
  (0, deps_js_1.assertInstanceOf)(resPq, _2_types_js_1.ResPQ);
35
36
  (0, deps_js_1.assertEquals)(resPq.nonce, nonce);
36
- // logger().debug("Got res_pq");
37
+ d("got res_pq");
37
38
  const pq_ = (0, _0_bigint_js_1.bigIntFromBuffer)(resPq.pq, false, false);
38
39
  const [p_, q_] = (0, deps_js_1.factorize)(pq_);
39
- // logger().debug("Factorized pq");
40
+ d("factorized pq");
40
41
  const p = (0, _0_buffer_js_1.bufferFromBigInt)(p_, 4, false, false);
41
42
  const q = (0, _0_buffer_js_1.bufferFromBigInt)(q_, 4, false, false);
42
43
  let publicKeyFingerprint;
@@ -74,7 +75,7 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
74
75
  encryptedData,
75
76
  }));
76
77
  (0, deps_js_1.assertInstanceOf)(dhParams, _2_types_js_1.ServerDHParamsOK);
77
- // logger().debug("Got server_DH_params_ok");
78
+ d("got server_DH_params_ok");
78
79
  const newNonce_ = (0, _0_buffer_js_1.bufferFromBigInt)(newNonce, 32, true, true);
79
80
  const serverNonce_ = (0, _0_buffer_js_1.bufferFromBigInt)(serverNonce, 16, true, true);
80
81
  const tmpAesKey = (0, _0_buffer_js_1.concat)(await (0, _0_hash_js_1.sha1)((0, _0_buffer_js_1.concat)(newNonce_, serverNonce_)), (await (0, _0_hash_js_1.sha1)((0, _0_buffer_js_1.concat)(serverNonce_, newNonce_))).slice(0, 0 + 12));
@@ -100,12 +101,12 @@ class ClientPlain extends client_abstract_js_1.ClientAbstract {
100
101
  encryptedData = (0, deps_js_1.ige256Encrypt)(dataWithHash, tmpAesKey, tmpAesIv);
101
102
  const dhGenOk = await this.invoke(new _3_functions_js_1.SetClientDHParams({ nonce, serverNonce, encryptedData }));
102
103
  (0, deps_js_1.assertInstanceOf)(dhGenOk, _2_types_js_1.DHGenOK);
103
- // logger().debug("Got dh_gen_ok");
104
+ d("got dh_gen_ok");
104
105
  const serverNonceSlice = serverNonce_.slice(0, 8);
105
106
  const salt = newNonce_.slice(0, 0 + 8).map((v, i) => v ^ serverNonceSlice[i]);
106
107
  const authKey_ = (0, _0_bigint_js_1.modExp)(gA, b, dhPrime);
107
108
  const authKey = (0, _0_buffer_js_1.bufferFromBigInt)(authKey_, 256, false, false);
108
- // logger().debug("Auth key created");
109
+ d("auth key created");
109
110
  return {
110
111
  authKey,
111
112
  salt: (0, _0_bigint_js_1.bigIntFromBuffer)(salt, true, false),
@@ -1,5 +1,6 @@
1
- import { MaybePromise } from "../types.js";
1
+ import { MaybePromise } from "../utilities/0_types.js";
2
2
  export declare abstract class Connection {
3
+ abstract get connected(): boolean;
3
4
  abstract open(): MaybePromise<void>;
4
5
  abstract read(p: Uint8Array): MaybePromise<void>;
5
6
  abstract write(p: Uint8Array): MaybePromise<void>;
@@ -6,6 +6,7 @@ export declare class ConnectionWebSocket implements Connection {
6
6
  private buffer;
7
7
  private nextResolve;
8
8
  constructor(url: string | URL);
9
+ get connected(): boolean;
9
10
  open(): Promise<void>;
10
11
  read(p: Uint8Array): Promise<void>;
11
12
  write(p: Uint8Array): Promise<void>;
@@ -72,6 +72,9 @@ class ConnectionWebSocket {
72
72
  };
73
73
  this.webSocket.onerror = console.error;
74
74
  }
75
+ get connected() {
76
+ return this.webSocket.readyState == dntShim.WebSocket.OPEN;
77
+ }
75
78
  async open() {
76
79
  while (this.webSocket.readyState != dntShim.WebSocket.OPEN) {
77
80
  if (this.webSocket.readyState == dntShim.WebSocket.CLOSED) {
@@ -0,0 +1,77 @@
1
+ /** RGB 8-bits per channel. Each in range `0->255` or `0x00->0xff` */
2
+ interface Rgb {
3
+ r: number;
4
+ g: number;
5
+ b: number;
6
+ }
7
+ export declare function setColorEnabled(value: boolean): void;
8
+ export declare function getColorEnabled(): boolean;
9
+ export declare function reset(str: string): string;
10
+ export declare function bold(str: string): string;
11
+ export declare function dim(str: string): string;
12
+ export declare function italic(str: string): string;
13
+ export declare function underline(str: string): string;
14
+ export declare function inverse(str: string): string;
15
+ export declare function hidden(str: string): string;
16
+ export declare function strikethrough(str: string): string;
17
+ export declare function black(str: string): string;
18
+ export declare function red(str: string): string;
19
+ export declare function green(str: string): string;
20
+ export declare function yellow(str: string): string;
21
+ export declare function blue(str: string): string;
22
+ export declare function magenta(str: string): string;
23
+ export declare function cyan(str: string): string;
24
+ export declare function white(str: string): string;
25
+ export declare function gray(str: string): string;
26
+ export declare function brightBlack(str: string): string;
27
+ export declare function brightRed(str: string): string;
28
+ export declare function brightGreen(str: string): string;
29
+ export declare function brightYellow(str: string): string;
30
+ export declare function brightBlue(str: string): string;
31
+ export declare function brightMagenta(str: string): string;
32
+ export declare function brightCyan(str: string): string;
33
+ export declare function brightWhite(str: string): string;
34
+ export declare function bgBlack(str: string): string;
35
+ export declare function bgRed(str: string): string;
36
+ export declare function bgGreen(str: string): string;
37
+ export declare function bgYellow(str: string): string;
38
+ export declare function bgBlue(str: string): string;
39
+ export declare function bgMagenta(str: string): string;
40
+ export declare function bgCyan(str: string): string;
41
+ export declare function bgWhite(str: string): string;
42
+ export declare function bgBrightBlack(str: string): string;
43
+ export declare function bgBrightRed(str: string): string;
44
+ export declare function bgBrightGreen(str: string): string;
45
+ export declare function bgBrightYellow(str: string): string;
46
+ export declare function bgBrightBlue(str: string): string;
47
+ export declare function bgBrightMagenta(str: string): string;
48
+ export declare function bgBrightCyan(str: string): string;
49
+ export declare function bgBrightWhite(str: string): string;
50
+ /** Set text color using paletted 8bit colors.
51
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit */
52
+ export declare function rgb8(str: string, color: number): string;
53
+ /** Set background color using paletted 8bit colors.
54
+ * https://en.wikipedia.org/wiki/ANSI_escape_code#8-bit */
55
+ export declare function bgRgb8(str: string, color: number): string;
56
+ /** Set text color using 24bit rgb.
57
+ * `color` can be a number in range `0x000000` to `0xffffff` or
58
+ * an `Rgb`.
59
+ *
60
+ * To produce the color magenta:
61
+ *
62
+ * rgba24("foo", 0xff00ff);
63
+ * rgba24("foo", {r: 255, g: 0, b: 255});
64
+ */
65
+ export declare function rgb24(str: string, color: number | Rgb): string;
66
+ /** Set background color using 24bit rgb.
67
+ * `color` can be a number in range `0x000000` to `0xffffff` or
68
+ * an `Rgb`.
69
+ *
70
+ * To produce the color magenta:
71
+ *
72
+ * bgRgba24("foo", 0xff00ff);
73
+ * bgRgba24("foo", {r: 255, g: 0, b: 255});
74
+ */
75
+ export declare function bgRgb24(str: string, color: number | Rgb): string;
76
+ export declare function stripColor(string: string): string;
77
+ export {};