@mtkruto/node 0.0.902 → 0.0.904

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.
@@ -159,7 +159,7 @@ export declare class Client extends ClientAbstract {
159
159
  messageThreadId?: number;
160
160
  sendAs?: number | string;
161
161
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
162
- }): Promise<Message>;
163
- getMessages(chatId: number | string, messageIds: number[]): Promise<Message[]>;
164
- getMessage(chatId: number | string, messageId: number): Promise<Message | null>;
162
+ }): Promise<Omit<Message, "replyToMessage">>;
163
+ getMessages(chatId: number | string, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
164
+ getMessage(chatId: number | string, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
165
165
  }
@@ -1072,10 +1072,10 @@ export class Client extends ClientAbstract {
1072
1072
  if (result instanceof types.Updates) {
1073
1073
  for (const update of result.updates) {
1074
1074
  if (update instanceof types.UpdateNewMessage) {
1075
- return constructMessage(update.message[as](types.Message), this[getEntity].bind(this));
1075
+ return constructMessage(update.message[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this));
1076
1076
  }
1077
1077
  else if (update instanceof types.UpdateNewChannelMessage) {
1078
- return constructMessage(update.message[as](types.Message), this[getEntity].bind(this));
1078
+ return constructMessage(update.message[as](types.Message), this[getEntity].bind(this), this.getMessage.bind(this));
1079
1079
  }
1080
1080
  }
1081
1081
  }
@@ -1094,7 +1094,7 @@ export class Client extends ClientAbstract {
1094
1094
  messages_ = await this.invoke(new functions.ChannelsGetMessages({
1095
1095
  channel: new types.InputChannel({ channelId: peer.channelId, accessHash: peer.accessHash }),
1096
1096
  id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1097
- })).then((v) => v[as](types.MessagesMessages));
1097
+ })).then((v) => v[as](types.MessagesChannelMessages));
1098
1098
  }
1099
1099
  else {
1100
1100
  messages_ = await this.invoke(new functions.MessagesGetMessages({
@@ -1103,7 +1103,7 @@ export class Client extends ClientAbstract {
1103
1103
  }
1104
1104
  const messages = new Array();
1105
1105
  for (const message_ of messages_.messages) {
1106
- messages.push(await constructMessage(message_[as](types.Message), this[getEntity].bind(this)));
1106
+ messages.push(await constructMessage(message_[as](types.Message), this[getEntity].bind(this), null));
1107
1107
  }
1108
1108
  return messages;
1109
1109
  }
@@ -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.902";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.904";
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.902";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.904";
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
  }
@@ -1,3 +1,4 @@
1
+ import { MaybePromise } from "../utilities/0_types.js";
1
2
  import * as types from "../tl/2_types.js";
2
3
  import { ForceReply } from "./0_force_reply.js";
3
4
  import { MessageEntity } from "./0_message_entity.js";
@@ -18,9 +19,12 @@ export interface Message {
18
19
  editDate?: Date;
19
20
  views?: number;
20
21
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
22
+ replyToMessage?: Omit<Message, "replyToMessage">;
21
23
  }
22
24
  export declare function constructMessage(message_: types.Message, getEntity: {
23
- (peer: types.PeerUser): Promise<types.User | null>;
24
- (peer: types.PeerChat): Promise<types.Chat | null>;
25
- (peer: types.PeerChannel): Promise<types.Channel | null>;
26
- }): Promise<Message>;
25
+ (peer: types.PeerUser): MaybePromise<types.User | null>;
26
+ (peer: types.PeerChat): MaybePromise<types.Chat | null>;
27
+ (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
28
+ }, getMessage: {
29
+ (chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
30
+ } | null): Promise<Message>;
@@ -1,3 +1,4 @@
1
+ import { debug } from "../deps.js";
1
2
  import { UNREACHABLE } from "../utilities/0_control.js";
2
3
  import { cleanObject } from "../utilities/0_object.js";
3
4
  import * as types from "../tl/2_types.js";
@@ -8,7 +9,8 @@ import { constructChat } from "./1_chat.js";
8
9
  import { constructUser } from "./1_user.js";
9
10
  import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
10
11
  import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
11
- export async function constructMessage(message_, getEntity) {
12
+ const d = debug("types/Message");
13
+ export async function constructMessage(message_, getEntity, getMessage) {
12
14
  let chat_ = null;
13
15
  if (message_.peerId instanceof types.PeerUser) {
14
16
  const entity = await getEntity(message_.peerId);
@@ -87,5 +89,14 @@ export async function constructMessage(message_, getEntity) {
87
89
  UNREACHABLE();
88
90
  }
89
91
  }
92
+ if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
93
+ const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
94
+ if (replyToMessage) {
95
+ message.replyToMessage = replyToMessage;
96
+ }
97
+ else {
98
+ d("couldn't get replied message");
99
+ }
100
+ }
90
101
  return cleanObject(message);
91
102
  }
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.902",
5
+ "version": "0.0.904",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -159,7 +159,7 @@ export declare class Client extends ClientAbstract {
159
159
  messageThreadId?: number;
160
160
  sendAs?: number | string;
161
161
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
162
- }): Promise<Message>;
163
- getMessages(chatId: number | string, messageIds: number[]): Promise<Message[]>;
164
- getMessage(chatId: number | string, messageId: number): Promise<Message | null>;
162
+ }): Promise<Omit<Message, "replyToMessage">>;
163
+ getMessages(chatId: number | string, messageIds: number[]): Promise<Omit<Message, "replyToMessage">[]>;
164
+ getMessage(chatId: number | string, messageId: number): Promise<Omit<Message, "replyToMessage"> | null>;
165
165
  }
@@ -1098,10 +1098,10 @@ class Client extends client_abstract_js_1.ClientAbstract {
1098
1098
  if (result instanceof types.Updates) {
1099
1099
  for (const update of result.updates) {
1100
1100
  if (update instanceof types.UpdateNewMessage) {
1101
- return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this));
1101
+ return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this), this.getMessage.bind(this));
1102
1102
  }
1103
1103
  else if (update instanceof types.UpdateNewChannelMessage) {
1104
- return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this));
1104
+ return (0, _3_message_js_1.constructMessage)(update.message[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this), this.getMessage.bind(this));
1105
1105
  }
1106
1106
  }
1107
1107
  }
@@ -1120,7 +1120,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
1120
1120
  messages_ = await this.invoke(new functions.ChannelsGetMessages({
1121
1121
  channel: new types.InputChannel({ channelId: peer.channelId, accessHash: peer.accessHash }),
1122
1122
  id: messageIds.map((v) => new types.InputMessageID({ id: v })),
1123
- })).then((v) => v[_1_tl_object_js_1.as](types.MessagesMessages));
1123
+ })).then((v) => v[_1_tl_object_js_1.as](types.MessagesChannelMessages));
1124
1124
  }
1125
1125
  else {
1126
1126
  messages_ = await this.invoke(new functions.MessagesGetMessages({
@@ -1129,7 +1129,7 @@ class Client extends client_abstract_js_1.ClientAbstract {
1129
1129
  }
1130
1130
  const messages = new Array();
1131
1131
  for (const message_ of messages_.messages) {
1132
- messages.push(await (0, _3_message_js_1.constructMessage)(message_[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this)));
1132
+ messages.push(await (0, _3_message_js_1.constructMessage)(message_[_1_tl_object_js_1.as](types.Message), this[exports.getEntity].bind(this), null));
1133
1133
  }
1134
1134
  return messages;
1135
1135
  }
@@ -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.902";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.904";
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.902";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.904";
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
  }
@@ -1,3 +1,4 @@
1
+ import { MaybePromise } from "../utilities/0_types.js";
1
2
  import * as types from "../tl/2_types.js";
2
3
  import { ForceReply } from "./0_force_reply.js";
3
4
  import { MessageEntity } from "./0_message_entity.js";
@@ -18,9 +19,12 @@ export interface Message {
18
19
  editDate?: Date;
19
20
  views?: number;
20
21
  replyMarkup?: InlineKeyboardMarkup | ReplyKeyboardMarkup | ReplyKeyboardRemove | ForceReply;
22
+ replyToMessage?: Omit<Message, "replyToMessage">;
21
23
  }
22
24
  export declare function constructMessage(message_: types.Message, getEntity: {
23
- (peer: types.PeerUser): Promise<types.User | null>;
24
- (peer: types.PeerChat): Promise<types.Chat | null>;
25
- (peer: types.PeerChannel): Promise<types.Channel | null>;
26
- }): Promise<Message>;
25
+ (peer: types.PeerUser): MaybePromise<types.User | null>;
26
+ (peer: types.PeerChat): MaybePromise<types.Chat | null>;
27
+ (peer: types.PeerChannel): MaybePromise<types.Channel | null>;
28
+ }, getMessage: {
29
+ (chatId: number, messageId: number): MaybePromise<Omit<Message, "replyToMessage"> | null>;
30
+ } | null): Promise<Message>;
@@ -24,6 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.constructMessage = void 0;
27
+ const deps_js_1 = require("../deps.js");
27
28
  const _0_control_js_1 = require("../utilities/0_control.js");
28
29
  const _0_object_js_1 = require("../utilities/0_object.js");
29
30
  const types = __importStar(require("../tl/2_types.js"));
@@ -34,7 +35,8 @@ const _1_chat_js_1 = require("./1_chat.js");
34
35
  const _1_user_js_1 = require("./1_user.js");
35
36
  const _2_inline_keyboard_markup_js_1 = require("./2_inline_keyboard_markup.js");
36
37
  const _2_reply_keyboard_markup_js_1 = require("./2_reply_keyboard_markup.js");
37
- async function constructMessage(message_, getEntity) {
38
+ const d = (0, deps_js_1.debug)("types/Message");
39
+ async function constructMessage(message_, getEntity, getMessage) {
38
40
  let chat_ = null;
39
41
  if (message_.peerId instanceof types.PeerUser) {
40
42
  const entity = await getEntity(message_.peerId);
@@ -113,6 +115,15 @@ async function constructMessage(message_, getEntity) {
113
115
  (0, _0_control_js_1.UNREACHABLE)();
114
116
  }
115
117
  }
118
+ if (getMessage && message_.replyTo instanceof types.MessageReplyHeader) {
119
+ const replyToMessage = await getMessage(message.chat.id, message_.replyTo.replyToMsgId);
120
+ if (replyToMessage) {
121
+ message.replyToMessage = replyToMessage;
122
+ }
123
+ else {
124
+ d("couldn't get replied message");
125
+ }
126
+ }
116
127
  return (0, _0_object_js_1.cleanObject)(message);
117
128
  }
118
129
  exports.constructMessage = constructMessage;