@mtkruto/node 0.0.989 → 0.0.990

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 (49) hide show
  1. package/esm/client/3_client.js +12 -12
  2. package/esm/constants.d.ts +1 -1
  3. package/esm/constants.js +1 -1
  4. package/esm/tl/2_types.d.ts +2055 -1617
  5. package/esm/tl/2_types.js +3447 -3447
  6. package/esm/tl/3_functions.d.ts +154 -154
  7. package/esm/tl/3_functions.js +988 -988
  8. package/esm/types/0_poll_option.d.ts +8 -0
  9. package/esm/types/0_poll_option.js +6 -0
  10. package/esm/types/1_chat.js +3 -4
  11. package/esm/types/1_keyboard_button.js +4 -5
  12. package/esm/types/1_photo.js +0 -2
  13. package/esm/types/1_poll.d.ts +32 -0
  14. package/esm/types/1_poll.js +23 -0
  15. package/esm/types/1_sticker.js +1 -1
  16. package/esm/types/1_user.js +1 -2
  17. package/esm/types/2_game.js +2 -2
  18. package/esm/types/2_inline_keyboard_markup.js +1 -2
  19. package/esm/types/2_reply_keyboard_markup.js +1 -2
  20. package/esm/types/3_message.d.ts +2 -0
  21. package/esm/types/3_message.js +4 -0
  22. package/esm/utilities/0_queue.d.ts +2 -0
  23. package/esm/utilities/0_queue.js +14 -2
  24. package/esm/utilities/1_misc.js +1 -1
  25. package/package.json +1 -1
  26. package/script/client/3_client.js +12 -12
  27. package/script/constants.d.ts +1 -1
  28. package/script/constants.js +1 -1
  29. package/script/tl/2_types.d.ts +2055 -1617
  30. package/script/tl/2_types.js +3894 -3894
  31. package/script/tl/3_functions.d.ts +154 -154
  32. package/script/tl/3_functions.js +988 -988
  33. package/script/types/0_poll_option.d.ts +8 -0
  34. package/script/types/0_poll_option.js +10 -0
  35. package/script/types/1_chat.js +3 -4
  36. package/script/types/1_keyboard_button.js +4 -5
  37. package/script/types/1_photo.js +0 -2
  38. package/script/types/1_poll.d.ts +32 -0
  39. package/script/types/1_poll.js +27 -0
  40. package/script/types/1_sticker.js +1 -1
  41. package/script/types/1_user.js +1 -2
  42. package/script/types/2_game.js +2 -2
  43. package/script/types/2_inline_keyboard_markup.js +1 -2
  44. package/script/types/2_reply_keyboard_markup.js +1 -2
  45. package/script/types/3_message.d.ts +2 -0
  46. package/script/types/3_message.js +4 -0
  47. package/script/utilities/0_queue.d.ts +2 -0
  48. package/script/utilities/0_queue.js +14 -2
  49. package/script/utilities/1_misc.js +1 -1
@@ -0,0 +1,8 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface PollOption {
3
+ /** Option text, 1-100 characters */
4
+ text: string;
5
+ /** Number of users that voted for this option */
6
+ voterCount: number;
7
+ }
8
+ export declare function constructPollOption(option: types.PollAnswer, results: Array<types.TypePollAnswerVoters>): PollOption;
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructPollOption = void 0;
4
+ function constructPollOption(option, results) {
5
+ return {
6
+ text: option.text,
7
+ voterCount: results.find((v) => v.option.every((v, i) => option.option[i] == v))?.voters ?? 0,
8
+ };
9
+ }
10
+ exports.constructPollOption = constructPollOption;
@@ -27,7 +27,6 @@ exports.constructChat = exports.ChatType = void 0;
27
27
  const constants_js_1 = require("../constants.js");
28
28
  const _0_control_js_1 = require("../utilities/0_control.js");
29
29
  const _0_object_js_1 = require("../utilities/0_object.js");
30
- const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
31
30
  const types = __importStar(require("../tl/2_types.js"));
32
31
  const _0_id_color_js_1 = require("./!0_id_color.js");
33
32
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
@@ -55,7 +54,7 @@ function constructChat(chat) {
55
54
  };
56
55
  if (chat_.isBot) {
57
56
  chat_.isRestricted = chat.restricted || false;
58
- chat_.restrictionReason = chat.restrictionReason?.map((v) => v[_1_tl_object_js_1.as](types.RestrictionReason));
57
+ chat_.restrictionReason = chat.restrictionReason;
59
58
  }
60
59
  if (chat.photo instanceof types.UserProfilePhoto) {
61
60
  chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo, chat_.id, chat.accessHash ?? 0n);
@@ -107,9 +106,9 @@ function constructChat(chat) {
107
106
  };
108
107
  }
109
108
  chat_.username = chat.username;
110
- chat_.also = chat.usernames?.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username);
109
+ chat_.also = chat.usernames?.map((v) => v.username);
111
110
  if (chat_.isRestricted) {
112
- chat_.restrictionReason = chat.restrictionReason?.map((v) => v[_1_tl_object_js_1.as](types.RestrictionReason));
111
+ chat_.restrictionReason = chat.restrictionReason;
113
112
  }
114
113
  if (chat.photo instanceof types.ChatPhoto) {
115
114
  chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo, chat_.id, chat.accessHash ?? 0n);
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.keyboardButtonToTlObject = exports.constructKeyboardButton = void 0;
27
27
  const _0_control_js_1 = require("../utilities/0_control.js");
28
- const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
29
28
  const types = __importStar(require("../tl/2_types.js"));
30
29
  const _0_chat_administrator_rights_js_1 = require("./0_chat_administrator_rights.js");
31
30
  function constructKeyboardButton(button_) {
@@ -56,10 +55,10 @@ function constructKeyboardButton(button_) {
56
55
  },
57
56
  };
58
57
  if (button_.peerType.botAdminRights) {
59
- button.requestChat.botAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.botAdminRights[_1_tl_object_js_1.as](types.ChatAdminRights));
58
+ button.requestChat.botAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.botAdminRights);
60
59
  }
61
60
  if (button_.peerType.userAdminRights) {
62
- button.requestChat.userAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.userAdminRights[_1_tl_object_js_1.as](types.ChatAdminRights));
61
+ button.requestChat.userAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.userAdminRights);
63
62
  }
64
63
  return button;
65
64
  }
@@ -74,10 +73,10 @@ function constructKeyboardButton(button_) {
74
73
  },
75
74
  };
76
75
  if (button_.peerType.botAdminRights) {
77
- button.requestChat.botAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.botAdminRights[_1_tl_object_js_1.as](types.ChatAdminRights));
76
+ button.requestChat.botAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.botAdminRights);
78
77
  }
79
78
  if (button_.peerType.userAdminRights) {
80
- button.requestChat.userAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.userAdminRights[_1_tl_object_js_1.as](types.ChatAdminRights));
79
+ button.requestChat.userAdministratorRights = (0, _0_chat_administrator_rights_js_1.constructChatAdministratorRights)(button_.peerType.userAdminRights);
81
80
  }
82
81
  return button;
83
82
  }
@@ -24,7 +24,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.constructPhoto = void 0;
27
- const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
28
27
  const types = __importStar(require("../tl/2_types.js"));
29
28
  const _0_file_id_js_1 = require("./!0_file_id.js");
30
29
  const _0_thumbnail_js_1 = require("./0_thumbnail.js");
@@ -39,7 +38,6 @@ function constructPhoto(photo) {
39
38
  }
40
39
  })
41
40
  .filter((v) => v instanceof types.PhotoSize)
42
- .map((v) => v[_1_tl_object_js_1.as](types.PhotoSize))
43
41
  .sort((a, b) => a.size - b.size);
44
42
  const largest = sizes.slice(-1)[0];
45
43
  const { dcId, id: mediaId, accessHash, fileReference } = photo;
@@ -0,0 +1,32 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { MessageEntity } from "./0_message_entity.js";
3
+ import { PollOption } from "./0_poll_option.js";
4
+ export interface Poll {
5
+ /** Unique poll identifier */
6
+ id: string;
7
+ /** Poll question, 1-300 characters */
8
+ question: string;
9
+ /** List of poll options */
10
+ options: PollOption[];
11
+ /** Total number of users that voted in the poll */
12
+ totalVoterCount: number;
13
+ /** True, if the poll is closed */
14
+ isClosed: boolean;
15
+ /** True, if the poll is anonymous */
16
+ isAnonymous: boolean;
17
+ /** Poll type, currently can be “regular” or “quiz” */
18
+ type: "regular" | "quiz";
19
+ /** True, if the poll allows multiple answers */
20
+ allowMultipleAnswers?: boolean;
21
+ /** Optional. 0-based identifier of the correct answer option. Available only for polls in the quiz mode, which are closed, or was sent (not forwarded) by the bot or to the private chat with the bot. */
22
+ correctOptionId?: number;
23
+ /** Optional. Text that is shown when a user chooses an incorrect answer or taps on the lamp icon in a quiz-style poll, 0-200 characters */
24
+ explanation?: string;
25
+ /** Optional. Special entities like usernames, URLs, bot commands, etc. that appear in the explanation */
26
+ explanationEntities?: MessageEntity[];
27
+ /** Optional. Amount of time in seconds the poll will be active after creation */
28
+ openPeriod?: number;
29
+ /** Optional. Point in time (Unix timestamp) when the poll will be automatically closed */
30
+ closeDate?: Date;
31
+ }
32
+ export declare function constructPoll(media_: types.MessageMediaPoll): Poll;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructPoll = void 0;
4
+ const _0_object_js_1 = require("../utilities/0_object.js");
5
+ const _0_message_entity_js_1 = require("./0_message_entity.js");
6
+ const _0_poll_option_js_1 = require("./0_poll_option.js");
7
+ function constructPoll(media_) {
8
+ const poll = media_.poll;
9
+ const correctOption = media_.results.results?.find((v) => v.correct)?.option;
10
+ const correctOptionId = correctOption !== undefined ? poll.answers.findIndex((v) => v.option.every((v, i) => correctOption[i] == v)) : undefined;
11
+ return (0, _0_object_js_1.cleanObject)({
12
+ id: String(poll.id),
13
+ question: poll.question,
14
+ options: poll.answers.map((v) => (0, _0_poll_option_js_1.constructPollOption)(v, media_.results.results ?? [])),
15
+ totalVoterCount: media_.results.totalVoters ?? 0,
16
+ isClosed: poll.closed || false,
17
+ isAnonymous: !poll.publicVoters,
18
+ type: poll.quiz ? "quiz" : "regular",
19
+ allowMultipleAnswers: poll.quiz ? undefined : poll.multipleChoice || false,
20
+ correctOptionId,
21
+ explanation: media_.results.solution,
22
+ explanationEntities: media_.results.solutionEntities?.map(_0_message_entity_js_1.constructMessageEntity).filter((v) => v != null),
23
+ openPeriod: poll.closePeriod,
24
+ closeDate: poll.closeDate ? new Date(poll.closeDate * 1000) : undefined,
25
+ });
26
+ }
27
+ exports.constructPoll = constructPoll;
@@ -46,7 +46,7 @@ async function constructSticker(document, fileId, fileUniqueId, getStickerSetNam
46
46
  emoji: stickerAttribute.alt || undefined,
47
47
  setName,
48
48
  premiumAnimation: undefined,
49
- maskPosition: stickerAttribute.maskCoords ? (0, _0_mask_position_js_1.constructMaskPosition)(stickerAttribute.maskCoords[_1_tl_object_js_1.as](types.MaskCoords)) : undefined,
49
+ maskPosition: stickerAttribute.maskCoords ? (0, _0_mask_position_js_1.constructMaskPosition)(stickerAttribute.maskCoords) : undefined,
50
50
  customEmojiId: undefined,
51
51
  needsRepainting: undefined,
52
52
  fileSize: Number(document.size),
@@ -25,7 +25,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.constructUser = void 0;
27
27
  const _0_object_js_1 = require("../utilities/0_object.js");
28
- const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
29
28
  const types = __importStar(require("../tl/2_types.js"));
30
29
  const _0_id_color_js_1 = require("./!0_id_color.js");
31
30
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
@@ -38,7 +37,7 @@ function constructUser(user_) {
38
37
  firstName: user_.firstName || "",
39
38
  lastName: user_.lastName,
40
39
  username: user_.username,
41
- also: user_.usernames?.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username),
40
+ also: user_.usernames?.map((v) => v.username),
42
41
  languageCode: user_.langCode,
43
42
  isScam: user_.scam || false,
44
43
  isFake: user_.fake || false,
@@ -31,11 +31,11 @@ const _0_file_id_js_1 = require("./!0_file_id.js");
31
31
  const _1_animation_js_1 = require("./1_animation.js");
32
32
  const _1_photo_js_1 = require("./1_photo.js");
33
33
  function constructGame(media_) {
34
- const game_ = media_.game[_1_tl_object_js_1.as](types.Game);
34
+ const game_ = media_.game;
35
35
  const document_ = game_.document ? game_.document[_1_tl_object_js_1.as](types.Document) : undefined;
36
36
  return (0, _0_object_js_1.cleanObject)({
37
37
  title: game_.title,
38
- description: game_.description,
38
+ description: media_.game.description,
39
39
  photo: (0, _1_photo_js_1.constructPhoto)(game_.photo[_1_tl_object_js_1.as](types.Photo)),
40
40
  animation: document_
41
41
  ? (0, _1_animation_js_1.constructAnimation)(document_, document_.attributes.find((v) => v instanceof types.DocumentAttributeVideo), document_.attributes.find((v) => v instanceof types.DocumentAttributeFilename), new _0_file_id_js_1.FileID(null, null, _0_file_id_js_1.FileType.Animation, document_.dcId, {
@@ -24,12 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.inlineKeyboardMarkupToTlObject = exports.constructInlineKeyboardMarkup = void 0;
27
- const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
28
27
  const types = __importStar(require("../tl/2_types.js"));
29
28
  const _1_inline_keyboard_button_js_1 = require("./1_inline_keyboard_button.js");
30
29
  function constructInlineKeyboardMarkup(keyboard_) {
31
30
  const rows = new Array();
32
- for (const row_ of keyboard_.rows.map((v) => v[_1_tl_object_js_1.as](types.KeyboardButtonRow))) {
31
+ for (const row_ of keyboard_.rows) {
33
32
  const row = new Array();
34
33
  for (const button_ of row_.buttons) {
35
34
  row.push((0, _1_inline_keyboard_button_js_1.constructInlineKeyboardButton)(button_));
@@ -24,12 +24,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.replyKeyboardMarkupToTlObject = exports.constructReplyKeyboardMarkup = void 0;
27
- const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
28
27
  const types = __importStar(require("../tl/2_types.js"));
29
28
  const _1_keyboard_button_js_1 = require("./1_keyboard_button.js");
30
29
  function constructReplyKeyboardMarkup(keyboard_) {
31
30
  const rows = new Array();
32
- for (const row_ of keyboard_.rows.map((v) => v[_1_tl_object_js_1.as](types.KeyboardButtonRow))) {
31
+ for (const row_ of keyboard_.rows) {
33
32
  const row = new Array();
34
33
  for (const button_ of row_.buttons) {
35
34
  row.push((0, _1_keyboard_button_js_1.constructKeyboardButton)(button_));
@@ -18,6 +18,7 @@ import { Voice } from "./0_voice.js";
18
18
  import { Dice } from "./0_dice.js";
19
19
  import { Contact } from "./0_contact.js";
20
20
  import { Game } from "./2_game.js";
21
+ import { Poll } from "./1_poll.js";
21
22
  import { Venue } from "./0_venue.js";
22
23
  import { Location } from "./0_location.js";
23
24
  /** This object represents a message. */
@@ -100,6 +101,7 @@ export interface Message {
100
101
  contact?: Contact;
101
102
  /** Message is a game, information about the game. */
102
103
  game?: Game;
104
+ poll?: Poll;
103
105
  /** Message is a venue, information about the venue. For backward compatibility, when this field is set, the location field will also be set */
104
106
  venue?: Venue;
105
107
  /** Message is a shared location, information about the location */
@@ -48,6 +48,7 @@ const _0_dice_js_1 = require("./0_dice.js");
48
48
  const _0_file_id_js_1 = require("./!0_file_id.js");
49
49
  const _0_contact_js_1 = require("./0_contact.js");
50
50
  const _2_game_js_1 = require("./2_game.js");
51
+ const _1_poll_js_1 = require("./1_poll.js");
51
52
  const _0_venue_js_1 = require("./0_venue.js");
52
53
  const _0_location_js_1 = require("./0_location.js");
53
54
  const constants_js_1 = require("../constants.js");
@@ -402,6 +403,9 @@ async function constructMessage(message_, getEntity, getMessage, getStickerSetNa
402
403
  else if (message_.media instanceof types.MessageMediaGame) {
403
404
  message.game = (0, _2_game_js_1.constructGame)(message_.media);
404
405
  }
406
+ else if (message_.media instanceof types.MessageMediaPoll) {
407
+ message.poll = (0, _1_poll_js_1.constructPoll)(message_.media);
408
+ }
405
409
  else if (message_.media instanceof types.MessageMediaVenue) {
406
410
  message.venue = (0, _0_venue_js_1.constructVenue)(message_.media);
407
411
  }
@@ -1,5 +1,7 @@
1
1
  export declare class Queue {
2
+ private d;
2
3
  private functions;
4
+ constructor(name: string);
3
5
  add(fn: () => Promise<void>): void;
4
6
  private busy;
5
7
  private check;
@@ -1,8 +1,15 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Queue = void 0;
4
+ const deps_js_1 = require("../deps.js");
4
5
  class Queue {
5
- constructor() {
6
+ constructor(name) {
7
+ Object.defineProperty(this, "d", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: void 0
12
+ });
6
13
  Object.defineProperty(this, "functions", {
7
14
  enumerable: true,
8
15
  configurable: true,
@@ -15,6 +22,7 @@ class Queue {
15
22
  writable: true,
16
23
  value: false
17
24
  });
25
+ this.d = (0, deps_js_1.debug)(`q/${name}`);
18
26
  }
19
27
  add(fn) {
20
28
  this.functions.push(fn);
@@ -29,7 +37,11 @@ class Queue {
29
37
  }
30
38
  const fn = this.functions.shift();
31
39
  if (fn !== undefined) {
32
- fn().finally(() => {
40
+ fn()
41
+ .catch((err) => {
42
+ this.d("%o", err);
43
+ })
44
+ .finally(() => {
33
45
  this.busy = false;
34
46
  this.check();
35
47
  });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.mustPromptOneOf = exports.mustPromptNumber = exports.mustPrompt = exports.drop = void 0;
4
4
  const _0_control_js_1 = require("./0_control.js");
5
5
  function drop(promise) {
6
- promise.then().catch();
6
+ promise.catch(() => { });
7
7
  }
8
8
  exports.drop = drop;
9
9
  function mustPrompt(message) {