@mtkruto/node 0.0.923 → 0.0.931

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 (67) hide show
  1. package/esm/client/3_client.d.ts +2 -0
  2. package/esm/client/3_client.js +17 -4
  3. package/esm/constants.d.ts +2 -1
  4. package/esm/constants.js +2 -1
  5. package/esm/storage/0_storage.d.ts +3 -0
  6. package/esm/storage/0_storage.js +19 -0
  7. package/esm/types/0_audio.d.ts +13 -0
  8. package/esm/types/0_audio.js +14 -0
  9. package/esm/types/0_contact.d.ts +9 -0
  10. package/esm/types/0_contact.js +9 -0
  11. package/esm/types/0_dice.d.ts +6 -0
  12. package/esm/types/0_dice.js +3 -0
  13. package/esm/types/0_mask_position.d.ts +8 -0
  14. package/esm/types/0_mask_position.js +8 -0
  15. package/esm/types/0_thumbnail.d.ts +1 -1
  16. package/esm/types/0_thumbnail.js +15 -1
  17. package/esm/types/0_voice.d.ts +9 -0
  18. package/esm/types/0_voice.js +9 -0
  19. package/esm/types/1_animation.d.ts +13 -0
  20. package/esm/types/1_animation.js +14 -0
  21. package/esm/types/1_document.d.ts +11 -0
  22. package/esm/types/1_document.js +12 -0
  23. package/esm/types/1_inline_keyboard_button.d.ts +4 -1
  24. package/esm/types/1_inline_keyboard_button.js +3 -0
  25. package/esm/types/1_photo.js +1 -13
  26. package/esm/types/1_sticker.d.ts +23 -0
  27. package/esm/types/1_sticker.js +28 -0
  28. package/esm/types/1_video.d.ts +14 -0
  29. package/esm/types/1_video.js +15 -0
  30. package/esm/types/1_video_note.d.ts +12 -0
  31. package/esm/types/1_video_note.js +12 -0
  32. package/esm/types/3_message.d.ts +19 -1
  33. package/esm/types/3_message.js +65 -2
  34. package/package.json +1 -1
  35. package/script/client/3_client.d.ts +2 -0
  36. package/script/client/3_client.js +17 -4
  37. package/script/constants.d.ts +2 -1
  38. package/script/constants.js +3 -2
  39. package/script/storage/0_storage.d.ts +3 -0
  40. package/script/storage/0_storage.js +19 -0
  41. package/script/types/0_audio.d.ts +13 -0
  42. package/script/types/0_audio.js +41 -0
  43. package/script/types/0_contact.d.ts +9 -0
  44. package/script/types/0_contact.js +13 -0
  45. package/script/types/0_dice.d.ts +6 -0
  46. package/script/types/0_dice.js +7 -0
  47. package/script/types/0_mask_position.d.ts +8 -0
  48. package/script/types/0_mask_position.js +12 -0
  49. package/script/types/0_thumbnail.d.ts +1 -1
  50. package/script/types/0_thumbnail.js +38 -1
  51. package/script/types/0_voice.d.ts +9 -0
  52. package/script/types/0_voice.js +13 -0
  53. package/script/types/1_animation.d.ts +13 -0
  54. package/script/types/1_animation.js +41 -0
  55. package/script/types/1_document.d.ts +11 -0
  56. package/script/types/1_document.js +39 -0
  57. package/script/types/1_inline_keyboard_button.d.ts +4 -1
  58. package/script/types/1_inline_keyboard_button.js +3 -0
  59. package/script/types/1_photo.js +1 -13
  60. package/script/types/1_sticker.d.ts +23 -0
  61. package/script/types/1_sticker.js +55 -0
  62. package/script/types/1_video.d.ts +14 -0
  63. package/script/types/1_video.js +42 -0
  64. package/script/types/1_video_note.d.ts +12 -0
  65. package/script/types/1_video_note.js +39 -0
  66. package/script/types/3_message.d.ts +19 -1
  67. package/script/types/3_message.js +65 -2
@@ -12,6 +12,7 @@ import { InlineKeyboardMarkup } from "../types/2_inline_keyboard_markup.js";
12
12
  import { Message } from "../types/3_message.js";
13
13
  import { ClientAbstract } from "./1_client_abstract.js";
14
14
  export declare const getEntity: unique symbol;
15
+ export declare const getStickerSetName: unique symbol;
15
16
  export declare const restartAuth: unique symbol;
16
17
  export declare enum ParseMode {
17
18
  None = "none",
@@ -164,4 +165,5 @@ export declare class Client extends ClientAbstract {
164
165
  getMessage(chatId: number | string, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
165
166
  private downloadInner;
166
167
  download(fileId_: string): Promise<AsyncGenerator<Uint8Array, void, unknown>>;
168
+ [getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
167
169
  }
@@ -1,5 +1,5 @@
1
1
  import { debug, gunzip, Mutex } from "../deps.js";
2
- import { ackThreshold, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
2
+ import { ackThreshold, CHANNEL_DIFFERENCE_LIMIT_BOT, CHANNEL_DIFFERENCE_LIMIT_USER, DEFAULT_APP_VERSION, DEFAULT_DEVICE_MODEL, DEFAULT_LANG_CODE, DEFAULT_LANG_PACK, DEFAULT_SYSTEM_LANG_CODE, DEFAULT_SYSTEM_VERSION, LAYER, MAX_CHANNEL_ID, MAX_CHAT_ID, STICKER_SET_NAME_TTL, USERNAME_TTL, ZERO_CHANNEL_ID } from "../constants.js";
3
3
  import { bigIntFromBuffer, getRandomBigInt, getRandomId } from "../utilities/0_bigint.js";
4
4
  import { UNREACHABLE } from "../utilities/0_control.js";
5
5
  import { sha1 } from "../utilities/0_hash.js";
@@ -30,6 +30,7 @@ const dAuth = debug("Client/authorize");
30
30
  const dRecv = debug("Client/receiveLoop");
31
31
  const UPDATE_GAP = Symbol();
32
32
  export const getEntity = Symbol();
33
+ export const getStickerSetName = Symbol();
33
34
  export const restartAuth = Symbol();
34
35
  export var ParseMode;
35
36
  (function (ParseMode) {
@@ -1082,10 +1083,10 @@ export class Client extends ClientAbstract {
1082
1083
  if (result instanceof types.Updates) {
1083
1084
  for (const update of result.updates) {
1084
1085
  if (update instanceof types.UpdateNewMessage) {
1085
- return constructMessage(update.message[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this));
1086
+ return constructMessage(update.message[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
1086
1087
  }
1087
1088
  else if (update instanceof types.UpdateNewChannelMessage) {
1088
- return constructMessage(update.message[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this));
1089
+ return constructMessage(update.message[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this), this[getStickerSetName].bind(this));
1089
1090
  }
1090
1091
  }
1091
1092
  }
@@ -1113,7 +1114,7 @@ export class Client extends ClientAbstract {
1113
1114
  }
1114
1115
  const messages = new Array();
1115
1116
  for (const message_ of messages_.messages) {
1116
- messages.push(await constructMessage(message_[as](types.Message), this[getEntity].bind(this), null));
1117
+ messages.push(await constructMessage(message_[as](types.Message), this[getEntity].bind(this), null, this[getStickerSetName].bind(this)));
1117
1118
  }
1118
1119
  return messages;
1119
1120
  }
@@ -1185,4 +1186,16 @@ export class Client extends ClientAbstract {
1185
1186
  UNREACHABLE();
1186
1187
  }
1187
1188
  }
1189
+ async [getStickerSetName](inputStickerSet, hash = 0) {
1190
+ const maybeStickerSetName = await this.storage.getStickerSetName(inputStickerSet.id, inputStickerSet.accessHash);
1191
+ if (maybeStickerSetName != null && Date.now() - maybeStickerSetName[1].getTime() < STICKER_SET_NAME_TTL) {
1192
+ return maybeStickerSetName[0];
1193
+ }
1194
+ else {
1195
+ const stickerSet = await this.invoke(new functions.MessagesGetStickerSet({ stickerset: inputStickerSet, hash }));
1196
+ const name = stickerSet[as](types.MessagesStickerSet).set[as](types.StickerSet).shortName;
1197
+ await this.storage.updateStickerSetName(inputStickerSet.id, inputStickerSet.accessHash, name);
1198
+ return name;
1199
+ }
1200
+ }
1188
1201
  }
@@ -4,13 +4,14 @@ export declare const publicKeys: Map<bigint, [bigint, bigint]>;
4
4
  export declare const VECTOR_CONSTRUCTOR = 481674261;
5
5
  export declare const DEFAULT_INITIAL_DC: DC;
6
6
  export declare const LAYER = 158;
7
- export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.923";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.931";
8
8
  export declare const DEFAULT_DEVICE_MODEL: string;
9
9
  export declare const DEFAULT_LANG_CODE: string;
10
10
  export declare const DEFAULT_LANG_PACK = "";
11
11
  export declare const DEFAULT_SYSTEM_LANG_CODE: string;
12
12
  export declare const DEFAULT_SYSTEM_VERSION: string;
13
13
  export declare const USERNAME_TTL = 86400;
14
+ export declare const STICKER_SET_NAME_TTL = 172800;
14
15
  export declare const MAX_CHAT_ID = 999999999999;
15
16
  export declare const MAX_CHANNEL_ID = 997852516352;
16
17
  export declare const ZERO_CHANNEL_ID = -1000000000000;
package/esm/constants.js CHANGED
@@ -62,7 +62,7 @@ export const publicKeys = new Map([
62
62
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
63
63
  export const DEFAULT_INITIAL_DC = "2-test";
64
64
  export const LAYER = 158;
65
- export const DEFAULT_APP_VERSION = "MTKruto 0.0.923";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.931";
66
66
  // @ts-ignore: lib
67
67
  export const DEFAULT_DEVICE_MODEL = typeof dntShim.Deno === "undefined" ? typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : process.platform + "-" + process.arch : navigator.userAgent.split(" ")[0] : dntShim.Deno.build.os + "-" + dntShim.Deno.build.arch;
68
68
  export const DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -71,6 +71,7 @@ export const DEFAULT_SYSTEM_LANG_CODE = typeof navigator === "undefined" ? "en"
71
71
  // @ts-ignore: lib
72
72
  export const DEFAULT_SYSTEM_VERSION = typeof navigator === "undefined" ? typeof process === "undefined" ? "Unknown" : "Node.js/" + process.versions.node : navigator.userAgent;
73
73
  export const USERNAME_TTL = 86400;
74
+ export const STICKER_SET_NAME_TTL = 172800;
74
75
  export const MAX_CHAT_ID = 999999999999;
75
76
  export const MAX_CHANNEL_ID = 997852516352;
76
77
  export const ZERO_CHANNEL_ID = -1000000000000;
@@ -38,4 +38,7 @@ export declare abstract class Storage {
38
38
  private readonly accountType__;
39
39
  setAccountType(type: "user" | "bot"): Promise<void>;
40
40
  getAccountType(): Promise<"bot" | "user">;
41
+ private readonly stickerSetName__;
42
+ updateStickerSetName(id: bigint, accessHash: bigint, name: string): Promise<void>;
43
+ getStickerSetName(id: bigint, accessHash: bigint): Promise<[string, Date] | null>;
41
44
  }
@@ -56,6 +56,12 @@ export class Storage {
56
56
  writable: true,
57
57
  value: "accountType__"
58
58
  });
59
+ Object.defineProperty(this, "stickerSetName__", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: "stickerSetName__"
64
+ });
59
65
  }
60
66
  setDc(dc) {
61
67
  return this.set("dc", dc);
@@ -199,4 +205,17 @@ export class Storage {
199
205
  UNREACHABLE();
200
206
  }
201
207
  }
208
+ async updateStickerSetName(id, accessHash, name) {
209
+ await this.set(`${this.stickerSetName__}${id}${accessHash}`, JSON.stringify([name, new Date()]));
210
+ }
211
+ async getStickerSetName(id, accessHash) {
212
+ const stickerSetName_ = await this.get(`${this.stickerSetName__}${id}${accessHash}`);
213
+ if (stickerSetName_ != null) {
214
+ const [name, updatedAt] = JSON.parse(stickerSetName_);
215
+ return [name, new Date(updatedAt)];
216
+ }
217
+ else {
218
+ return null;
219
+ }
220
+ }
202
221
  }
@@ -0,0 +1,13 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface Audio {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ duration: number;
7
+ performer?: string;
8
+ title?: string;
9
+ mimeType: string;
10
+ fileSize: number;
11
+ thumbnails: Thumbnail[];
12
+ }
13
+ export declare function constructAudio(document: types.Document, audioAttribute: types.DocumentAttributeAudio | undefined, fileId: string, fileUniqueId: string): Audio;
@@ -0,0 +1,14 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { constructThumbnail } from "./0_thumbnail.js";
3
+ export function constructAudio(document, audioAttribute, fileId, fileUniqueId) {
4
+ return {
5
+ fileId,
6
+ fileUniqueId,
7
+ duration: audioAttribute?.duration ?? 0,
8
+ performer: audioAttribute?.performer,
9
+ title: audioAttribute?.title,
10
+ mimeType: document.mimeType,
11
+ fileSize: Number(document.size),
12
+ thumbnails: document.thumbs ? document.thumbs.map((v) => v instanceof types.PhotoSize ? constructThumbnail(v, document) : null).filter((v) => v) : [],
13
+ };
14
+ }
@@ -0,0 +1,9 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface Contact {
3
+ phoneNumber: string;
4
+ firstName: string;
5
+ lastName?: string;
6
+ userId?: number;
7
+ vcard?: string;
8
+ }
9
+ export declare function constructContact(contact: types.MessageMediaContact): Contact;
@@ -0,0 +1,9 @@
1
+ export function constructContact(contact) {
2
+ return {
3
+ phoneNumber: contact.phoneNumber,
4
+ firstName: contact.firstName,
5
+ lastName: contact.lastName || undefined,
6
+ userId: Number(contact.userId) || undefined,
7
+ vcard: contact.vcard || undefined,
8
+ };
9
+ }
@@ -0,0 +1,6 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface Dice {
3
+ emoji: string;
4
+ value: number;
5
+ }
6
+ export declare function constructDice(dice_: types.MessageMediaDice): Dice;
@@ -0,0 +1,3 @@
1
+ export function constructDice(dice_) {
2
+ return { emoji: dice_.emoticon, value: dice_.value };
3
+ }
@@ -0,0 +1,8 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface MaskPosition {
3
+ point: "forehead" | "eyes" | "mouth" | "chin";
4
+ xShift: number;
5
+ yShift: number;
6
+ scale: number;
7
+ }
8
+ export declare function constructMaskPosition({ n, x, y, zoom }: types.MaskCoords): MaskPosition;
@@ -0,0 +1,8 @@
1
+ export function constructMaskPosition({ n, x, y, zoom }) {
2
+ return {
3
+ point: n == 0 ? "forehead" : n == 1 ? "eyes" : n == 2 ? "mouth" : "chin",
4
+ xShift: x,
5
+ yShift: y,
6
+ scale: zoom,
7
+ };
8
+ }
@@ -6,4 +6,4 @@ export interface Thumbnail {
6
6
  height: number;
7
7
  fileSize: number;
8
8
  }
9
- export declare function constructThumbnail(size: types.PhotoSize, fileId: string, fileUniqueId: string): Thumbnail;
9
+ export declare function constructThumbnail(size: types.PhotoSize, file: types.Document | types.Photo): Thumbnail;
@@ -1,4 +1,18 @@
1
- export function constructThumbnail(size, fileId, fileUniqueId) {
1
+ import * as types from "../tl/2_types.js";
2
+ import { FileID, FileType, FileUniqueID, FileUniqueType, ThumbnailSource } from "./!0_file_id.js";
3
+ export function constructThumbnail(size, file) {
4
+ const fileType = file instanceof types.Photo ? FileType.Photo : FileType.Document;
5
+ const fileId = new FileID(null, null, fileType, file.dcId, {
6
+ mediaId: file.id,
7
+ accessHash: file.accessHash,
8
+ fileReference: file.fileReference,
9
+ thumbnailFileType: fileType,
10
+ thumbnailSource: ThumbnailSource.Thumbnail,
11
+ thumbnailSize: size.type,
12
+ volumeId: 0n,
13
+ localId: 0,
14
+ }).encode();
15
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: file.id }).encode();
2
16
  return {
3
17
  fileId,
4
18
  fileUniqueId,
@@ -0,0 +1,9 @@
1
+ import * as types from "../tl/2_types.js";
2
+ export interface Voice {
3
+ fileId: string;
4
+ fileUniqueId: string;
5
+ duration: number;
6
+ mimeType: string;
7
+ fileSize: number;
8
+ }
9
+ export declare function constructVoice(document: types.Document, audioAttributes: types.DocumentAttributeAudio, fileId: string, fileUniqueId: string): Voice;
@@ -0,0 +1,9 @@
1
+ export function constructVoice(document, audioAttributes, fileId, fileUniqueId) {
2
+ return {
3
+ fileId,
4
+ fileUniqueId,
5
+ duration: audioAttributes.duration,
6
+ mimeType: document.mimeType,
7
+ fileSize: Number(document.size),
8
+ };
9
+ }
@@ -0,0 +1,13 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface Animation {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ width: number;
7
+ height: number;
8
+ duration: number;
9
+ thumbnails: Thumbnail[];
10
+ mimeType: string;
11
+ fileSize: number;
12
+ }
13
+ export declare function constructAnimation(document: types.Document, videoAttribute: types.DocumentAttributeVideo | undefined, fileId: string, fileUniqueId: string): Animation;
@@ -0,0 +1,14 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { constructThumbnail } from "./0_thumbnail.js";
3
+ export function constructAnimation(document, videoAttribute, fileId, fileUniqueId) {
4
+ return {
5
+ fileId,
6
+ fileUniqueId,
7
+ width: videoAttribute?.w ?? 0,
8
+ height: videoAttribute?.h ?? 0,
9
+ duration: videoAttribute?.duration ?? 0,
10
+ thumbnails: document.thumbs ? document.thumbs.map((v) => v instanceof types.PhotoSize ? constructThumbnail(v, document) : null).filter((v) => v) : [],
11
+ mimeType: document.mimeType,
12
+ fileSize: Number(document.size),
13
+ };
14
+ }
@@ -0,0 +1,11 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface Document {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ thumbnails: Thumbnail[];
7
+ fileName: string;
8
+ mimeType: string;
9
+ fileSize: number;
10
+ }
11
+ export declare function constructDocument(document: types.Document, fileNameAttribute: types.DocumentAttributeFilename, fileId: string, fileUniqueId: string): Document;
@@ -0,0 +1,12 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { constructThumbnail } from "./0_thumbnail.js";
3
+ export function constructDocument(document, fileNameAttribute, fileId, fileUniqueId) {
4
+ return {
5
+ fileId,
6
+ fileUniqueId,
7
+ thumbnails: document.thumbs ? document.thumbs.map((v) => v instanceof types.PhotoSize ? constructThumbnail(v, document) : null).filter((v) => v) : [],
8
+ fileName: fileNameAttribute.fileName,
9
+ mimeType: document.mimeType,
10
+ fileSize: Number(document.size),
11
+ };
12
+ }
@@ -24,10 +24,13 @@ export declare namespace InlineKeyboardButton {
24
24
  interface SwitchInlineCurrent extends Base {
25
25
  switchInlineQueryCurrentChat: string;
26
26
  }
27
+ interface Game extends Base {
28
+ callbackGame: {};
29
+ }
27
30
  interface Pay extends Base {
28
31
  pay: boolean;
29
32
  }
30
33
  }
31
- export type InlineKeyboardButton = InlineKeyboardButton.URL | InlineKeyboardButton.Callback | InlineKeyboardButton.WebApp | InlineKeyboardButton.Login | InlineKeyboardButton.SwitchInline | InlineKeyboardButton.SwitchInlineCurrent | InlineKeyboardButton.Pay;
34
+ export type InlineKeyboardButton = InlineKeyboardButton.URL | InlineKeyboardButton.Callback | InlineKeyboardButton.WebApp | InlineKeyboardButton.Login | InlineKeyboardButton.SwitchInline | InlineKeyboardButton.SwitchInlineCurrent | InlineKeyboardButton.Game | InlineKeyboardButton.Pay;
32
35
  export declare function constructInlineKeyboardButton(button_: types.TypeKeyboardButton): InlineKeyboardButton;
33
36
  export declare function inlineKeyboardButtonToTlObject(button: InlineKeyboardButton, usernameResolver: (username: string) => MaybePromise<types.InputUser>): Promise<types.KeyboardButtonURL | types.KeyboardButtonCallback | types.KeyboardButtonSwitchInline | types.KeyboardButtonBuy | types.InputKeyboardButtonURLAuth | types.KeyboardButtonWebView>;
@@ -25,6 +25,9 @@ export function constructInlineKeyboardButton(button_) {
25
25
  else if (button_ instanceof types.KeyboardButtonBuy) {
26
26
  return { text: button_.text, pay: true };
27
27
  }
28
+ else if (button_ instanceof types.KeyboardButtonGame) {
29
+ return { text: button_.text, callbackGame: {} };
30
+ }
28
31
  else {
29
32
  UNREACHABLE();
30
33
  }
@@ -32,18 +32,6 @@ export function constructPhoto(photo) {
32
32
  width: largest.w,
33
33
  height: largest.h,
34
34
  fileSize: largest.size,
35
- thumbnails: sizes.slice(0, -1).map((v) => {
36
- const fileId = new FileID(null, null, FileType.Photo, dcId, {
37
- mediaId,
38
- accessHash,
39
- fileReference,
40
- thumbnailSource: ThumbnailSource.Thumbnail,
41
- thumbnailFileType: FileType.Photo,
42
- thumbnailSize: v.type,
43
- volumeId: 0n,
44
- localId: 0,
45
- }).encode();
46
- return constructThumbnail(v, fileId, fileUniqueId);
47
- }),
35
+ thumbnails: sizes.slice(0, -1).map((v) => constructThumbnail(v, photo)),
48
36
  };
49
37
  }
@@ -0,0 +1,23 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { MaybePromise } from "../utilities/0_types.js";
3
+ import { Thumbnail } from "./0_thumbnail.js";
4
+ import { MaskPosition } from "./0_mask_position.js";
5
+ export interface Sticker {
6
+ fileId: string;
7
+ fileUniqueId: string;
8
+ type: "regular" | "mask" | "custom_emoji";
9
+ width: number;
10
+ height: number;
11
+ isAnimated: boolean;
12
+ isVideo: boolean;
13
+ thumbnails: Thumbnail[];
14
+ emoji?: string;
15
+ setName?: string;
16
+ premiumAnimation?: File;
17
+ maskPosition?: MaskPosition;
18
+ customEmojiId?: string;
19
+ needsRepainting?: boolean;
20
+ fileSize?: number;
21
+ }
22
+ export type StickerSetNameGetter = (inputStickerSet: types.InputStickerSetID) => MaybePromise<string>;
23
+ export declare function constructSticker(document: types.Document, fileId: string, fileUniqueId: string, getStickerSetName: StickerSetNameGetter): Promise<Sticker>;
@@ -0,0 +1,28 @@
1
+ import { as } from "../tl/1_tl_object.js";
2
+ import * as types from "../tl/2_types.js";
3
+ import { constructThumbnail } from "./0_thumbnail.js";
4
+ import { constructMaskPosition } from "./0_mask_position.js";
5
+ export async function constructSticker(document, fileId, fileUniqueId, getStickerSetName) {
6
+ const stickerAttribute = document.attributes.find((v) => v instanceof types.DocumentAttributeSticker);
7
+ const imageSizeAttribute = document.attributes.find((v) => v instanceof types.DocumentAttributeImageSize);
8
+ const videoAttribute = document.attributes.find((v) => v instanceof types.DocumentAttributeVideo);
9
+ const setName = await getStickerSetName(stickerAttribute.stickerset[as](types.InputStickerSetID));
10
+ return {
11
+ fileId,
12
+ fileUniqueId,
13
+ // TODO: custom_emoji type?
14
+ type: stickerAttribute.mask ? "mask" : "regular",
15
+ width: imageSizeAttribute ? imageSizeAttribute.w : videoAttribute ? videoAttribute.w : 512,
16
+ height: imageSizeAttribute ? imageSizeAttribute.h : videoAttribute ? videoAttribute.h : 512,
17
+ isAnimated: document.mimeType == "application/x-tgsticker",
18
+ isVideo: document.mimeType == "video/webm",
19
+ thumbnails: document.thumbs ? document.thumbs.map((v) => v instanceof types.PhotoSize ? constructThumbnail(v, document) : null).filter((v) => v) : [],
20
+ emoji: stickerAttribute.alt || undefined,
21
+ setName,
22
+ premiumAnimation: undefined,
23
+ maskPosition: stickerAttribute.maskCoords ? constructMaskPosition(stickerAttribute.maskCoords[as](types.MaskCoords)) : undefined,
24
+ customEmojiId: undefined,
25
+ needsRepainting: undefined,
26
+ fileSize: Number(document.size),
27
+ };
28
+ }
@@ -0,0 +1,14 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface Video {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ width: number;
7
+ height: number;
8
+ duration: number;
9
+ thumbnails: Thumbnail[];
10
+ fileName?: string;
11
+ mimeType: string;
12
+ fileSize: number;
13
+ }
14
+ export declare function constructVideo(document: types.Document, videoAttribute: types.DocumentAttributeVideo, fileName: string | undefined, fileId: string, fileUniqueId: string): Video;
@@ -0,0 +1,15 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { constructThumbnail } from "./0_thumbnail.js";
3
+ export function constructVideo(document, videoAttribute, fileName, fileId, fileUniqueId) {
4
+ return {
5
+ fileId,
6
+ fileUniqueId,
7
+ width: videoAttribute.w,
8
+ height: videoAttribute.h,
9
+ duration: videoAttribute.duration,
10
+ thumbnails: document.thumbs ? document.thumbs.map((v) => v instanceof types.PhotoSize ? constructThumbnail(v, document) : null).filter((v) => v) : [],
11
+ fileName,
12
+ mimeType: document.mimeType,
13
+ fileSize: Number(document.size),
14
+ };
15
+ }
@@ -0,0 +1,12 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { Thumbnail } from "./0_thumbnail.js";
3
+ export interface VideoNote {
4
+ fileId: string;
5
+ fileUniqueId: string;
6
+ length: number;
7
+ duration: number;
8
+ thumbnails: Thumbnail[];
9
+ fileName?: string;
10
+ fileSize: number;
11
+ }
12
+ export declare function constructVideoNote(document: types.Document, videoAttribute: types.DocumentAttributeVideo, fileId: string, fileUniqueId: string): VideoNote;
@@ -0,0 +1,12 @@
1
+ import * as types from "../tl/2_types.js";
2
+ import { constructThumbnail } from "./0_thumbnail.js";
3
+ export function constructVideoNote(document, videoAttribute, fileId, fileUniqueId) {
4
+ return {
5
+ fileId,
6
+ fileUniqueId,
7
+ length: videoAttribute.w,
8
+ duration: videoAttribute.duration,
9
+ thumbnails: document.thumbs ? document.thumbs.map((v) => v instanceof types.PhotoSize ? constructThumbnail(v, document) : null).filter((v) => v) : [],
10
+ fileSize: Number(document.size),
11
+ };
12
+ }
@@ -7,7 +7,16 @@ import { Chat } from "./1_chat.js";
7
7
  import { User } from "./1_user.js";
8
8
  import { InlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
9
9
  import { ReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
10
+ import { Sticker, StickerSetNameGetter } from "./1_sticker.js";
10
11
  import { Photo } from "./1_photo.js";
12
+ import { Document } from "./1_document.js";
13
+ import { Video } from "./1_video.js";
14
+ import { VideoNote } from "./1_video_note.js";
15
+ import { Animation } from "./1_animation.js";
16
+ import { Audio } from "./0_audio.js";
17
+ import { Voice } from "./0_voice.js";
18
+ import { Dice } from "./0_dice.js";
19
+ import { Contact } from "./0_contact.js";
11
20
  export interface Message {
12
21
  id: number;
13
22
  threadId?: number;
@@ -37,6 +46,15 @@ export interface Message {
37
46
  views?: number;
38
47
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
39
48
  photo?: Photo;
49
+ document?: Document;
50
+ video?: Video;
51
+ sticker?: Sticker;
52
+ animation?: Animation;
53
+ voice?: Voice;
54
+ audio?: Audio;
55
+ dice?: Dice;
56
+ videoNote?: VideoNote;
57
+ contact?: Contact;
40
58
  }
41
59
  export declare function constructMessage(message_: types.Message, getEntity: {
42
60
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -44,4 +62,4 @@ export declare function constructMessage(message_: types.Message, getEntity: {
44
62
  (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
45
63
  }, getMessage: {
46
64
  (chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
47
- } | null): Promise<Message>;
65
+ } | null, getStickerSetName: StickerSetNameGetter): Promise<Message>;
@@ -9,9 +9,19 @@ import { constructChat } from "./1_chat.js";
9
9
  import { constructUser } from "./1_user.js";
10
10
  import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
11
11
  import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
12
+ import { constructSticker } from "./1_sticker.js";
12
13
  import { constructPhoto } from "./1_photo.js";
14
+ import { constructDocument } from "./1_document.js";
15
+ import { constructVideo } from "./1_video.js";
16
+ import { constructVideoNote } from "./1_video_note.js";
17
+ import { constructAnimation } from "./1_animation.js";
18
+ import { constructAudio } from "./0_audio.js";
19
+ import { constructVoice } from "./0_voice.js";
20
+ import { constructDice } from "./0_dice.js";
21
+ import { FileID, FileType, FileUniqueID, FileUniqueType } from "./!0_file_id.js";
22
+ import { constructContact } from "./0_contact.js";
13
23
  const d = debug("types/Message");
14
- export async function constructMessage(message_, getEntity, getMessage) {
24
+ export async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
15
25
  let chat_ = null;
16
26
  if (message_.peerId instanceof types.PeerUser) {
17
27
  const entity = await getEntity(message_.peerId);
@@ -111,7 +121,6 @@ export async function constructMessage(message_, getEntity, getMessage) {
111
121
  UNREACHABLE();
112
122
  }
113
123
  }
114
- // message_.
115
124
  if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
116
125
  if (message_.replyTo.forumTopic) {
117
126
  message.isTopicMessage = true;
@@ -180,6 +189,60 @@ export async function constructMessage(message_, getEntity, getMessage) {
180
189
  message.photo = constructPhoto(message_.media.photo);
181
190
  }
182
191
  }
192
+ else if (message_.media instanceof types.MessageMediaDice) {
193
+ message.dice = constructDice(message_.media);
194
+ }
195
+ else if (message_.media instanceof types.MessageMediaDocument) {
196
+ const { document } = message_.media;
197
+ if (document instanceof types.Document) {
198
+ const getFileId = (type) => new FileID(null, null, type, document.dcId, {
199
+ mediaId: document.id,
200
+ accessHash: document.accessHash,
201
+ fileReference: document.fileReference,
202
+ }).encode();
203
+ const fileUniqueId = new FileUniqueID(FileUniqueType.Document, { mediaId: document.id }).encode();
204
+ const animated = document.attributes.find((v) => v instanceof types.DocumentAttributeAnimated);
205
+ const audio = document.attributes.find((v) => v instanceof types.DocumentAttributeAudio);
206
+ const fileName = document.attributes.find((v) => v instanceof types.DocumentAttributeFilename);
207
+ const sticker = document.attributes.find((v) => v instanceof types.DocumentAttributeSticker);
208
+ const video = document.attributes.find((v) => v instanceof types.DocumentAttributeVideo);
209
+ if (animated) {
210
+ message.animation = constructAnimation(document, video, getFileId(FileType.Animation), fileUniqueId);
211
+ }
212
+ else if (video) {
213
+ if (video.roundMessage) {
214
+ message.videoNote = constructVideoNote(document, video, getFileId(FileType.VideoNote), fileUniqueId);
215
+ }
216
+ else {
217
+ message.video = constructVideo(document, video, fileName?.fileName, getFileId(FileType.Video), fileUniqueId);
218
+ }
219
+ }
220
+ else if (audio) {
221
+ if (audio.voice) {
222
+ message.voice = constructVoice(document, audio, getFileId(FileType.Voice), fileUniqueId);
223
+ }
224
+ else {
225
+ message.audio = constructAudio(document, audio, getFileId(FileType.Audio), fileUniqueId);
226
+ }
227
+ }
228
+ else if (sticker) {
229
+ message.sticker = await constructSticker(document, getFileId(FileType.Sticker), fileUniqueId, getStickerSetName);
230
+ }
231
+ else if (fileName) {
232
+ message.document = constructDocument(document, fileName, getFileId(FileType.Document), fileUniqueId);
233
+ }
234
+ else {
235
+ UNREACHABLE();
236
+ }
237
+ }
238
+ }
239
+ else if (message_.media instanceof types.MessageMediaContact) {
240
+ message.contact = constructContact(message_.media);
241
+ }
242
+ else {
243
+ // not implemented
244
+ UNREACHABLE();
245
+ }
183
246
  }
184
247
  return cleanObject(message);
185
248
  }
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.923",
5
+ "version": "0.0.931",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",