@mtkruto/node 0.0.903 → 0.0.905

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.
@@ -4,7 +4,7 @@ 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.903";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.905";
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 = "";
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.903";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.905";
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];
@@ -21,6 +21,7 @@ export function analyzeOptionalParam(ntype) {
21
21
  return { flagField, bitIndex };
22
22
  }
23
23
  function serializeSingleParam(writer, value, type, ntype) {
24
+ const valueRepr = value == null ? null : value.constructor.name;
24
25
  if (isTLObjectConstructor(type)) {
25
26
  if ((type.name == "TypeX" && value instanceof TLObject) ||
26
27
  value instanceof type) {
@@ -28,7 +29,7 @@ function serializeSingleParam(writer, value, type, ntype) {
28
29
  return;
29
30
  }
30
31
  else {
31
- throw new TypeError(`Expected ${type.name} but received ${value == null ? null : value.constructor.name}`);
32
+ throw new TypeError(`Expected ${type.name} but received ${valueRepr}`);
32
33
  }
33
34
  }
34
35
  if (type == Uint8Array) {
@@ -36,7 +37,7 @@ function serializeSingleParam(writer, value, type, ntype) {
36
37
  writer.writeBytes(value);
37
38
  }
38
39
  else {
39
- throw new TypeError("Expected Uint8Array");
40
+ throw new TypeError(`Expected Uint8Array but received ${valueRepr}`);
40
41
  }
41
42
  }
42
43
  switch (type) {
@@ -53,7 +54,7 @@ function serializeSingleParam(writer, value, type, ntype) {
53
54
  }
54
55
  }
55
56
  else {
56
- throw new TypeError("Expected bigint");
57
+ throw new TypeError(`Expected bigint but received ${valueRepr}`);
57
58
  }
58
59
  break;
59
60
  case "boolean":
@@ -66,7 +67,7 @@ function serializeSingleParam(writer, value, type, ntype) {
66
67
  }
67
68
  }
68
69
  else {
69
- throw new TypeError("Expected boolean");
70
+ throw new TypeError(`Expected boolean but received ${valueRepr}`);
70
71
  }
71
72
  break;
72
73
  case "number":
@@ -74,7 +75,7 @@ function serializeSingleParam(writer, value, type, ntype) {
74
75
  writer.writeInt32(value);
75
76
  }
76
77
  else {
77
- throw new TypeError("Expected number");
78
+ throw new TypeError(`Expected number but received ${valueRepr}`);
78
79
  }
79
80
  break;
80
81
  case "string":
@@ -85,12 +86,12 @@ function serializeSingleParam(writer, value, type, ntype) {
85
86
  writer.writeBytes(value);
86
87
  }
87
88
  else {
88
- throw new TypeError("Expected string or Uint8Array");
89
+ throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
89
90
  }
90
91
  break;
91
92
  case "true":
92
93
  if (value !== true) {
93
- throw new TypeError("Expected true");
94
+ throw new TypeError(`Expected true but received ${valueRepr}`);
94
95
  }
95
96
  }
96
97
  }
@@ -146,7 +147,7 @@ export class TLObject {
146
147
  return this;
147
148
  }
148
149
  else {
149
- throw new TypeError(`Expected ${constructor.name}, got ${this.constructor.name}`);
150
+ throw new TypeError(`Expected ${constructor.name} but received ${this.constructor.name}`);
150
151
  }
151
152
  }
152
153
  }
@@ -10,6 +10,7 @@ export declare namespace Chat {
10
10
  interface Base {
11
11
  type: ChatType;
12
12
  id: number;
13
+ idColor: string;
13
14
  photo?: ChatPhoto;
14
15
  }
15
16
  interface Private extends Base {
@@ -4,6 +4,7 @@ import { cleanObject } from "../utilities/0_object.js";
4
4
  import { as } from "../tl/1_tl_object.js";
5
5
  import * as types from "../tl/2_types.js";
6
6
  import { constructChatPhoto } from "./0_chat_photo.js";
7
+ import { getIdColor } from "./utilities/0_id_color.js";
7
8
  export var ChatType;
8
9
  (function (ChatType) {
9
10
  ChatType["Private"] = "private";
@@ -13,10 +14,12 @@ export var ChatType;
13
14
  })(ChatType || (ChatType = {}));
14
15
  export function constructChat(chat) {
15
16
  if (chat instanceof types.User) {
17
+ const id = Number(chat.id);
16
18
  const chat_ = {
17
19
  type: ChatType.Private,
18
20
  isBot: chat.bot || false,
19
- id: Number(chat.id),
21
+ id,
22
+ idColor: getIdColor(id),
20
23
  firstName: chat.firstName || "",
21
24
  lastName: chat.lastName,
22
25
  isScam: chat.scam || false,
@@ -34,9 +37,11 @@ export function constructChat(chat) {
34
37
  return cleanObject(chat_);
35
38
  }
36
39
  else if (chat instanceof types.Chat) {
40
+ const id = Number(-chat.id);
37
41
  const chat_ = {
38
42
  type: ChatType.Group,
39
- id: Number(-chat.id),
43
+ id,
44
+ idColor: getIdColor(id),
40
45
  title: chat.title,
41
46
  isCreator: chat.creator || false,
42
47
  };
@@ -48,11 +53,13 @@ export function constructChat(chat) {
48
53
  else if (chat instanceof types.Channel) {
49
54
  let chat_;
50
55
  const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
56
+ const id = ZERO_CHANNEL_ID + -Number(chat.id);
51
57
  if (chat.megagroup) {
52
- chat_ = { id: ZERO_CHANNEL_ID + -Number(chat.id), type: ChatType.Supergroup, title, isScam, isFake, isVerified, isRestricted };
58
+ chat_ = { id, idColor: getIdColor(id), type: ChatType.Supergroup, title, isScam, isFake, isVerified, isRestricted };
53
59
  }
54
60
  else {
55
- chat_ = { id: ZERO_CHANNEL_ID + -Number(chat.id), type: ChatType.Channel, title, isScam, isFake, isVerified, isRestricted };
61
+ const id = ZERO_CHANNEL_ID + -Number(chat.id);
62
+ chat_ = { id, idColor: getIdColor(id), type: ChatType.Channel, title, isScam, isFake, isVerified, isRestricted };
56
63
  }
57
64
  chat_.username = chat.username;
58
65
  chat_.also = chat.usernames?.map((v) => v[as](types.Username)).map((v) => v.username);
@@ -2,6 +2,7 @@ import * as types from "../tl/2_types.js";
2
2
  import { ChatPhoto } from "./0_chat_photo.js";
3
3
  export interface User {
4
4
  id: number;
5
+ idColor: string;
5
6
  isBot: boolean;
6
7
  firstName: string;
7
8
  lastName?: string;
@@ -2,9 +2,12 @@ import { cleanObject } from "../utilities/0_object.js";
2
2
  import { as } from "../tl/1_tl_object.js";
3
3
  import * as types from "../tl/2_types.js";
4
4
  import { constructChatPhoto } from "./0_chat_photo.js";
5
+ import { getIdColor } from "./utilities/0_id_color.js";
5
6
  export function constructUser(user_) {
7
+ const id = Number(user_.id);
6
8
  const user = {
7
- id: Number(user_.id),
9
+ id,
10
+ idColor: getIdColor(id),
8
11
  isBot: user_.bot || false,
9
12
  firstName: user_.firstName || "",
10
13
  lastName: user_.lastName,
@@ -9,17 +9,32 @@ import { InlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
9
9
  import { ReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
10
10
  export interface Message {
11
11
  id: number;
12
+ threadId?: number;
12
13
  from?: User;
14
+ senderChat?: Chat;
15
+ date?: Date;
13
16
  chat: Chat;
17
+ forwardFrom?: User;
18
+ forwardFromChat?: Chat;
19
+ forwardId?: number;
20
+ forwardSignature?: string;
21
+ forwardSenderName?: string;
22
+ forwardDate?: Date;
23
+ isTopicMessage: boolean;
24
+ isAutomaticForward?: boolean;
25
+ replyToMessage?: Omit<Message, "replyToMessage">;
26
+ viaBot?: User;
27
+ editDate?: Date;
28
+ hasProtectedContent: boolean;
29
+ mediaGroupId?: string;
30
+ authorSignature?: string;
14
31
  text?: string;
15
- caption?: string;
16
32
  entities?: MessageEntity[];
33
+ caption?: string;
17
34
  captionEntities?: MessageEntity[];
18
- date?: Date;
19
- editDate?: Date;
35
+ hasMediaSpoiler?: boolean;
20
36
  views?: number;
21
37
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
22
- replyToMessage?: Omit<Message, "replyToMessage">;
23
38
  }
24
39
  export declare function constructMessage(message_: types.Message, getEntity: {
25
40
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -42,7 +42,19 @@ export async function constructMessage(message_, getEntity, getMessage) {
42
42
  else {
43
43
  UNREACHABLE();
44
44
  }
45
- const message = { id: message_.id, chat: chat_, views: message_.views };
45
+ const message = {
46
+ id: message_.id,
47
+ chat: chat_,
48
+ views: message_.views,
49
+ isTopicMessage: false,
50
+ hasProtectedContent: message_.noforwards || false,
51
+ };
52
+ if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
53
+ message.hasMediaSpoiler = message_.media.spoiler || false;
54
+ }
55
+ if (message_.groupedId != undefined) {
56
+ message.mediaGroupId = String(message_.groupedId);
57
+ }
46
58
  if (message_.fromId instanceof types.PeerUser) {
47
59
  const entity = await getEntity(message_.fromId);
48
60
  if (entity) {
@@ -89,14 +101,68 @@ export async function constructMessage(message_, getEntity, getMessage) {
89
101
  UNREACHABLE();
90
102
  }
91
103
  }
104
+ // message_.
92
105
  if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
106
+ if (message_.replyTo.forumTopic) {
107
+ message.isTopicMessage = true;
108
+ }
93
109
  const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
94
110
  if (replyToMessage) {
95
111
  message.replyToMessage = replyToMessage;
112
+ message.threadId = message_.replyTo.replyToTopId;
96
113
  }
97
114
  else {
98
115
  d("couldn't get replied message");
99
116
  }
100
117
  }
118
+ if (message_.viaBotId != undefined) {
119
+ const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
120
+ if (viaBot) {
121
+ message.viaBot = constructUser(viaBot);
122
+ }
123
+ else {
124
+ UNREACHABLE();
125
+ }
126
+ }
127
+ if (message_.postAuthor != undefined) {
128
+ message.authorSignature = message_.postAuthor;
129
+ }
130
+ if (message_.fwdFrom instanceof types.MessageFwdHeader) {
131
+ message.isAutomaticForward = message_.fwdFrom.savedFromPeer != undefined && message_.fwdFrom.savedFromMsgId != undefined;
132
+ message.forwardSenderName = message_.fwdFrom.fromName;
133
+ message.forwardId = message_.fwdFrom.channelPost;
134
+ message.forwardSignature = message_.fwdFrom.postAuthor;
135
+ message.forwardDate = new Date(message_.date * 1000);
136
+ if (message_.fwdFrom.fromId instanceof types.PeerUser) {
137
+ const entity = await getEntity(message_.fwdFrom.fromId);
138
+ if (entity) {
139
+ message.forwardFrom = constructUser(entity);
140
+ }
141
+ else {
142
+ UNREACHABLE();
143
+ }
144
+ }
145
+ else if (message_.fwdFrom.fromId instanceof types.PeerChat) {
146
+ const entity = await getEntity(message_.fwdFrom.fromId);
147
+ if (entity) {
148
+ message.forwardFromChat = constructChat(entity);
149
+ }
150
+ else {
151
+ UNREACHABLE();
152
+ }
153
+ }
154
+ else if (message_.fwdFrom.fromId instanceof types.PeerChannel) {
155
+ const entity = await getEntity(message_.fwdFrom.fromId);
156
+ if (entity) {
157
+ message.forwardFromChat = constructChat(entity);
158
+ }
159
+ else {
160
+ UNREACHABLE();
161
+ }
162
+ }
163
+ else {
164
+ UNREACHABLE();
165
+ }
166
+ }
101
167
  return cleanObject(message);
102
168
  }
@@ -0,0 +1 @@
1
+ export declare function getIdColor(id: number): string;
@@ -0,0 +1,16 @@
1
+ const colors = [
2
+ "#ff5a2b",
3
+ "#ffa92b",
4
+ "#b364f1",
5
+ "#30dc53",
6
+ "#30dcc2",
7
+ "#309cdc",
8
+ "#e52eb1", // pink
9
+ ];
10
+ export function getIdColor(id) {
11
+ id = Number(String(id).replaceAll("-100", "-"));
12
+ if (id < 0) {
13
+ id = -id;
14
+ }
15
+ return colors[id % 7];
16
+ }
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.903",
5
+ "version": "0.0.905",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -4,7 +4,7 @@ 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.903";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.905";
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 = "";
@@ -88,7 +88,7 @@ exports.publicKeys = new Map([
88
88
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
89
89
  exports.DEFAULT_INITIAL_DC = "2-test";
90
90
  exports.LAYER = 158;
91
- exports.DEFAULT_APP_VERSION = "MTKruto 0.0.903";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.905";
92
92
  // @ts-ignore: lib
93
93
  exports.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;
94
94
  exports.DEFAULT_LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -26,6 +26,7 @@ function analyzeOptionalParam(ntype) {
26
26
  }
27
27
  exports.analyzeOptionalParam = analyzeOptionalParam;
28
28
  function serializeSingleParam(writer, value, type, ntype) {
29
+ const valueRepr = value == null ? null : value.constructor.name;
29
30
  if (isTLObjectConstructor(type)) {
30
31
  if ((type.name == "TypeX" && value instanceof TLObject) ||
31
32
  value instanceof type) {
@@ -33,7 +34,7 @@ function serializeSingleParam(writer, value, type, ntype) {
33
34
  return;
34
35
  }
35
36
  else {
36
- throw new TypeError(`Expected ${type.name} but received ${value == null ? null : value.constructor.name}`);
37
+ throw new TypeError(`Expected ${type.name} but received ${valueRepr}`);
37
38
  }
38
39
  }
39
40
  if (type == Uint8Array) {
@@ -41,7 +42,7 @@ function serializeSingleParam(writer, value, type, ntype) {
41
42
  writer.writeBytes(value);
42
43
  }
43
44
  else {
44
- throw new TypeError("Expected Uint8Array");
45
+ throw new TypeError(`Expected Uint8Array but received ${valueRepr}`);
45
46
  }
46
47
  }
47
48
  switch (type) {
@@ -58,7 +59,7 @@ function serializeSingleParam(writer, value, type, ntype) {
58
59
  }
59
60
  }
60
61
  else {
61
- throw new TypeError("Expected bigint");
62
+ throw new TypeError(`Expected bigint but received ${valueRepr}`);
62
63
  }
63
64
  break;
64
65
  case "boolean":
@@ -71,7 +72,7 @@ function serializeSingleParam(writer, value, type, ntype) {
71
72
  }
72
73
  }
73
74
  else {
74
- throw new TypeError("Expected boolean");
75
+ throw new TypeError(`Expected boolean but received ${valueRepr}`);
75
76
  }
76
77
  break;
77
78
  case "number":
@@ -79,7 +80,7 @@ function serializeSingleParam(writer, value, type, ntype) {
79
80
  writer.writeInt32(value);
80
81
  }
81
82
  else {
82
- throw new TypeError("Expected number");
83
+ throw new TypeError(`Expected number but received ${valueRepr}`);
83
84
  }
84
85
  break;
85
86
  case "string":
@@ -90,12 +91,12 @@ function serializeSingleParam(writer, value, type, ntype) {
90
91
  writer.writeBytes(value);
91
92
  }
92
93
  else {
93
- throw new TypeError("Expected string or Uint8Array");
94
+ throw new TypeError(`Expected string or Uint8Array but received ${valueRepr}`);
94
95
  }
95
96
  break;
96
97
  case "true":
97
98
  if (value !== true) {
98
- throw new TypeError("Expected true");
99
+ throw new TypeError(`Expected true but received ${valueRepr}`);
99
100
  }
100
101
  }
101
102
  }
@@ -151,7 +152,7 @@ class TLObject {
151
152
  return this;
152
153
  }
153
154
  else {
154
- throw new TypeError(`Expected ${constructor.name}, got ${this.constructor.name}`);
155
+ throw new TypeError(`Expected ${constructor.name} but received ${this.constructor.name}`);
155
156
  }
156
157
  }
157
158
  }
@@ -10,6 +10,7 @@ export declare namespace Chat {
10
10
  interface Base {
11
11
  type: ChatType;
12
12
  id: number;
13
+ idColor: string;
13
14
  photo?: ChatPhoto;
14
15
  }
15
16
  interface Private extends Base {
@@ -30,6 +30,7 @@ const _0_object_js_1 = require("../utilities/0_object.js");
30
30
  const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
31
31
  const types = __importStar(require("../tl/2_types.js"));
32
32
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
33
+ const _0_id_color_js_1 = require("./utilities/0_id_color.js");
33
34
  var ChatType;
34
35
  (function (ChatType) {
35
36
  ChatType["Private"] = "private";
@@ -39,10 +40,12 @@ var ChatType;
39
40
  })(ChatType = exports.ChatType || (exports.ChatType = {}));
40
41
  function constructChat(chat) {
41
42
  if (chat instanceof types.User) {
43
+ const id = Number(chat.id);
42
44
  const chat_ = {
43
45
  type: ChatType.Private,
44
46
  isBot: chat.bot || false,
45
- id: Number(chat.id),
47
+ id,
48
+ idColor: (0, _0_id_color_js_1.getIdColor)(id),
46
49
  firstName: chat.firstName || "",
47
50
  lastName: chat.lastName,
48
51
  isScam: chat.scam || false,
@@ -60,9 +63,11 @@ function constructChat(chat) {
60
63
  return (0, _0_object_js_1.cleanObject)(chat_);
61
64
  }
62
65
  else if (chat instanceof types.Chat) {
66
+ const id = Number(-chat.id);
63
67
  const chat_ = {
64
68
  type: ChatType.Group,
65
- id: Number(-chat.id),
69
+ id,
70
+ idColor: (0, _0_id_color_js_1.getIdColor)(id),
66
71
  title: chat.title,
67
72
  isCreator: chat.creator || false,
68
73
  };
@@ -74,11 +79,13 @@ function constructChat(chat) {
74
79
  else if (chat instanceof types.Channel) {
75
80
  let chat_;
76
81
  const { title, scam: isScam = false, fake: isFake = false, verified: isVerified = false, restricted: isRestricted = false, } = chat;
82
+ const id = constants_js_1.ZERO_CHANNEL_ID + -Number(chat.id);
77
83
  if (chat.megagroup) {
78
- chat_ = { id: constants_js_1.ZERO_CHANNEL_ID + -Number(chat.id), type: ChatType.Supergroup, title, isScam, isFake, isVerified, isRestricted };
84
+ chat_ = { id, idColor: (0, _0_id_color_js_1.getIdColor)(id), type: ChatType.Supergroup, title, isScam, isFake, isVerified, isRestricted };
79
85
  }
80
86
  else {
81
- chat_ = { id: constants_js_1.ZERO_CHANNEL_ID + -Number(chat.id), type: ChatType.Channel, title, isScam, isFake, isVerified, isRestricted };
87
+ const id = constants_js_1.ZERO_CHANNEL_ID + -Number(chat.id);
88
+ chat_ = { id, idColor: (0, _0_id_color_js_1.getIdColor)(id), type: ChatType.Channel, title, isScam, isFake, isVerified, isRestricted };
82
89
  }
83
90
  chat_.username = chat.username;
84
91
  chat_.also = chat.usernames?.map((v) => v[_1_tl_object_js_1.as](types.Username)).map((v) => v.username);
@@ -2,6 +2,7 @@ import * as types from "../tl/2_types.js";
2
2
  import { ChatPhoto } from "./0_chat_photo.js";
3
3
  export interface User {
4
4
  id: number;
5
+ idColor: string;
5
6
  isBot: boolean;
6
7
  firstName: string;
7
8
  lastName?: string;
@@ -28,9 +28,12 @@ const _0_object_js_1 = require("../utilities/0_object.js");
28
28
  const _1_tl_object_js_1 = require("../tl/1_tl_object.js");
29
29
  const types = __importStar(require("../tl/2_types.js"));
30
30
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
31
+ const _0_id_color_js_1 = require("./utilities/0_id_color.js");
31
32
  function constructUser(user_) {
33
+ const id = Number(user_.id);
32
34
  const user = {
33
- id: Number(user_.id),
35
+ id,
36
+ idColor: (0, _0_id_color_js_1.getIdColor)(id),
34
37
  isBot: user_.bot || false,
35
38
  firstName: user_.firstName || "",
36
39
  lastName: user_.lastName,
@@ -9,17 +9,32 @@ import { InlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
9
9
  import { ReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
10
10
  export interface Message {
11
11
  id: number;
12
+ threadId?: number;
12
13
  from?: User;
14
+ senderChat?: Chat;
15
+ date?: Date;
13
16
  chat: Chat;
17
+ forwardFrom?: User;
18
+ forwardFromChat?: Chat;
19
+ forwardId?: number;
20
+ forwardSignature?: string;
21
+ forwardSenderName?: string;
22
+ forwardDate?: Date;
23
+ isTopicMessage: boolean;
24
+ isAutomaticForward?: boolean;
25
+ replyToMessage?: Omit<Message, "replyToMessage">;
26
+ viaBot?: User;
27
+ editDate?: Date;
28
+ hasProtectedContent: boolean;
29
+ mediaGroupId?: string;
30
+ authorSignature?: string;
14
31
  text?: string;
15
- caption?: string;
16
32
  entities?: MessageEntity[];
33
+ caption?: string;
17
34
  captionEntities?: MessageEntity[];
18
- date?: Date;
19
- editDate?: Date;
35
+ hasMediaSpoiler?: boolean;
20
36
  views?: number;
21
37
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
22
- replyToMessage?: Omit<Message, "replyToMessage">;
23
38
  }
24
39
  export declare function constructMessage(message_: types.Message, getEntity: {
25
40
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -68,7 +68,19 @@ async function constructMessage(message_, getEntity, getMessage) {
68
68
  else {
69
69
  (0, _0_control_js_1.UNREACHABLE)();
70
70
  }
71
- const message = { id: message_.id, chat: chat_, views: message_.views };
71
+ const message = {
72
+ id: message_.id,
73
+ chat: chat_,
74
+ views: message_.views,
75
+ isTopicMessage: false,
76
+ hasProtectedContent: message_.noforwards || false,
77
+ };
78
+ if (message_.media instanceof types.MessageMediaPhoto || message_.media instanceof types.MessageMediaDocument) {
79
+ message.hasMediaSpoiler = message_.media.spoiler || false;
80
+ }
81
+ if (message_.groupedId != undefined) {
82
+ message.mediaGroupId = String(message_.groupedId);
83
+ }
72
84
  if (message_.fromId instanceof types.PeerUser) {
73
85
  const entity = await getEntity(message_.fromId);
74
86
  if (entity) {
@@ -115,15 +127,69 @@ async function constructMessage(message_, getEntity, getMessage) {
115
127
  (0, _0_control_js_1.UNREACHABLE)();
116
128
  }
117
129
  }
130
+ // message_.
118
131
  if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
132
+ if (message_.replyTo.forumTopic) {
133
+ message.isTopicMessage = true;
134
+ }
119
135
  const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
120
136
  if (replyToMessage) {
121
137
  message.replyToMessage = replyToMessage;
138
+ message.threadId = message_.replyTo.replyToTopId;
122
139
  }
123
140
  else {
124
141
  d("couldn't get replied message");
125
142
  }
126
143
  }
144
+ if (message_.viaBotId != undefined) {
145
+ const viaBot = await getEntity(new types.PeerUser({ userId: message_.viaBotId }));
146
+ if (viaBot) {
147
+ message.viaBot = (0, _1_user_js_1.constructUser)(viaBot);
148
+ }
149
+ else {
150
+ (0, _0_control_js_1.UNREACHABLE)();
151
+ }
152
+ }
153
+ if (message_.postAuthor != undefined) {
154
+ message.authorSignature = message_.postAuthor;
155
+ }
156
+ if (message_.fwdFrom instanceof types.MessageFwdHeader) {
157
+ message.isAutomaticForward = message_.fwdFrom.savedFromPeer != undefined && message_.fwdFrom.savedFromMsgId != undefined;
158
+ message.forwardSenderName = message_.fwdFrom.fromName;
159
+ message.forwardId = message_.fwdFrom.channelPost;
160
+ message.forwardSignature = message_.fwdFrom.postAuthor;
161
+ message.forwardDate = new Date(message_.date * 1000);
162
+ if (message_.fwdFrom.fromId instanceof types.PeerUser) {
163
+ const entity = await getEntity(message_.fwdFrom.fromId);
164
+ if (entity) {
165
+ message.forwardFrom = (0, _1_user_js_1.constructUser)(entity);
166
+ }
167
+ else {
168
+ (0, _0_control_js_1.UNREACHABLE)();
169
+ }
170
+ }
171
+ else if (message_.fwdFrom.fromId instanceof types.PeerChat) {
172
+ const entity = await getEntity(message_.fwdFrom.fromId);
173
+ if (entity) {
174
+ message.forwardFromChat = (0, _1_chat_js_1.constructChat)(entity);
175
+ }
176
+ else {
177
+ (0, _0_control_js_1.UNREACHABLE)();
178
+ }
179
+ }
180
+ else if (message_.fwdFrom.fromId instanceof types.PeerChannel) {
181
+ const entity = await getEntity(message_.fwdFrom.fromId);
182
+ if (entity) {
183
+ message.forwardFromChat = (0, _1_chat_js_1.constructChat)(entity);
184
+ }
185
+ else {
186
+ (0, _0_control_js_1.UNREACHABLE)();
187
+ }
188
+ }
189
+ else {
190
+ (0, _0_control_js_1.UNREACHABLE)();
191
+ }
192
+ }
127
193
  return (0, _0_object_js_1.cleanObject)(message);
128
194
  }
129
195
  exports.constructMessage = constructMessage;
@@ -0,0 +1 @@
1
+ export declare function getIdColor(id: number): string;
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getIdColor = void 0;
4
+ const colors = [
5
+ "#ff5a2b",
6
+ "#ffa92b",
7
+ "#b364f1",
8
+ "#30dc53",
9
+ "#30dcc2",
10
+ "#309cdc",
11
+ "#e52eb1", // pink
12
+ ];
13
+ function getIdColor(id) {
14
+ id = Number(String(id).replaceAll("-100", "-"));
15
+ if (id < 0) {
16
+ id = -id;
17
+ }
18
+ return colors[id % 7];
19
+ }
20
+ exports.getIdColor = getIdColor;