@mtkruto/node 0.0.941 → 0.0.950

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.941";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.950";
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.941";
65
+ export const DEFAULT_APP_VERSION = "MTKruto 0.0.950";
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,11 @@ function serializeSingleParam(writer, value, type, ntype) {
71
71
  }
72
72
  break;
73
73
  case "number":
74
+ //
75
+ if (value == null) {
76
+ value = 0;
77
+ }
78
+ //
74
79
  if (typeof value === "number") {
75
80
  writer.writeInt32(value);
76
81
  }
@@ -33,6 +33,6 @@ export function replyKeyboardMarkupToTlObject(replyMarkup) {
33
33
  selective: replyMarkup.selective || undefined,
34
34
  persistent: replyMarkup.isPersistent || undefined,
35
35
  rows: rows_,
36
- placeholder: replyMarkup.inputFieldPlaceholder
36
+ placeholder: replyMarkup.inputFieldPlaceholder,
37
37
  });
38
38
  }
@@ -90,6 +90,42 @@ export interface Message {
90
90
  game?: Game;
91
91
  venue?: Venue;
92
92
  location?: Location;
93
+ newChatMembers?: User[];
94
+ leftChatMember?: User;
95
+ newChatTitle?: string;
96
+ newChatPhoto?: Photo;
97
+ deletedChatPhoto?: true;
98
+ groupCreated?: true;
99
+ supergroupCreated?: true;
100
+ channelCreated?: true;
101
+ chatMigratedTo?: number;
102
+ chatMigratedFrom?: number;
103
+ pinnedMessage?: Message;
104
+ userShared?: {
105
+ requestId: number;
106
+ userId: number;
107
+ };
108
+ writeAccessAllowed?: {
109
+ webAppName?: string;
110
+ };
111
+ forumTopicCreated?: {
112
+ name: string;
113
+ iconColor: string;
114
+ iconCutsomEmojiId?: string;
115
+ };
116
+ forumTopicEdited?: {
117
+ name?: string;
118
+ iconCutsomEmojiId?: string;
119
+ };
120
+ forumTopicClosed?: Record<never, never>;
121
+ forumTopicReopened?: Record<never, never>;
122
+ videoChatScheduled?: {
123
+ startDate: Date;
124
+ };
125
+ videoChatStarted?: Record<never, never>;
126
+ videoChatEnded?: {
127
+ duration: number;
128
+ };
93
129
  }
94
130
  interface EntityGetter {
95
131
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -1,11 +1,12 @@
1
1
  import { debug } from "../deps.js";
2
2
  import { UNREACHABLE } from "../utilities/0_control.js";
3
3
  import { cleanObject } from "../utilities/0_object.js";
4
+ import { as } from "../tl/1_tl_object.js";
4
5
  import * as types from "../tl/2_types.js";
5
6
  import { constructForceReply } from "./0_force_reply.js";
6
7
  import { constructMessageEntity } from "./0_message_entity.js";
7
8
  import { constructReplyKeyboardRemove } from "./0_reply_keyboard_remove.js";
8
- import { constructChat } from "./1_chat.js";
9
+ import { ChatType, constructChat } from "./1_chat.js";
9
10
  import { constructUser } from "./1_user.js";
10
11
  import { constructInlineKeyboardMarkup } from "./2_inline_keyboard_markup.js";
11
12
  import { constructReplyKeyboardMarkup } from "./2_reply_keyboard_markup.js";
@@ -23,6 +24,7 @@ import { constructContact } from "./0_contact.js";
23
24
  import { constructGame } from "./2_game.js";
24
25
  import { constructVenue } from "./0_venue.js";
25
26
  import { constructLocation } from "./0_location.js";
27
+ import { ZERO_CHANNEL_ID } from "../constants.js";
26
28
  const d = debug("types/Message");
27
29
  async function getSender(message_, getEntity) {
28
30
  if (message_.fromId instanceof types.PeerUser) {
@@ -58,9 +60,7 @@ async function getReply(message_, chat, getMessage) {
58
60
  d("couldn't get replied message");
59
61
  }
60
62
  }
61
- else {
62
- return {};
63
- }
63
+ return { replyToMessage: undefined, threadId: undefined, isTopicMessage: undefined };
64
64
  }
65
65
  async function constructServiceMessage(message_, chat, getEntity, getMessage) {
66
66
  const message = {
@@ -69,9 +69,115 @@ async function constructServiceMessage(message_, chat, getEntity, getMessage) {
69
69
  date: new Date(message_.date * 1000),
70
70
  isTopicMessage: false,
71
71
  };
72
- Object.assign(message, await getReply(message_, chat, getMessage));
73
72
  Object.assign(message, await getSender(message_, getEntity));
74
- return message;
73
+ if (message_.action instanceof types.MessageActionChatAddUser) {
74
+ message.newChatMembers = [];
75
+ for (const user_ of message_.action.users) {
76
+ const entity = await getEntity(new types.PeerUser({ userId: user_ }));
77
+ if (entity) {
78
+ const user = constructUser(entity);
79
+ message.newChatMembers.push(user);
80
+ }
81
+ else {
82
+ UNREACHABLE();
83
+ }
84
+ }
85
+ }
86
+ else if (message_.action instanceof types.MessageActionChatDeleteUser) {
87
+ const entity = await getEntity(new types.PeerUser({ userId: message_.action.userId }));
88
+ if (entity) {
89
+ const user = constructUser(entity);
90
+ message.leftChatMember = user;
91
+ }
92
+ else {
93
+ UNREACHABLE();
94
+ }
95
+ }
96
+ else if (message_.action instanceof types.MessageActionChatEditTitle) {
97
+ message.newChatTitle = message_.action.title;
98
+ }
99
+ else if (message_.action instanceof types.MessageActionChatEditPhoto) {
100
+ message.newChatPhoto = constructPhoto(message_.action.photo[as](types.Photo));
101
+ }
102
+ else if (message_.action instanceof types.MessageActionChatDeletePhoto) {
103
+ message.deletedChatPhoto = true;
104
+ }
105
+ else if (message_.action instanceof types.MessageActionChatCreate) {
106
+ message.groupCreated = true;
107
+ message.newChatMembers = [];
108
+ for (const user_ of message_.action.users) {
109
+ const entity = await getEntity(new types.PeerUser({ userId: user_ }));
110
+ if (entity) {
111
+ const user = constructUser(entity);
112
+ message.newChatMembers.push(user);
113
+ }
114
+ else {
115
+ UNREACHABLE();
116
+ }
117
+ }
118
+ }
119
+ else if (message_.action instanceof types.MessageActionChannelCreate) {
120
+ if (message.chat.type == ChatType.Channel) {
121
+ message.channelCreated = true;
122
+ }
123
+ else if (message.chat.type == ChatType.Supergroup) {
124
+ message.supergroupCreated = true;
125
+ }
126
+ else {
127
+ UNREACHABLE();
128
+ }
129
+ }
130
+ else if (message_.action instanceof types.MessageActionChatMigrateTo) {
131
+ message.chatMigratedTo = ZERO_CHANNEL_ID + Number(-message_.action.channelId);
132
+ }
133
+ else if (message_.action instanceof types.MessageActionChannelMigrateFrom) {
134
+ message.chatMigratedFrom = Number(-message_.action.chatId);
135
+ }
136
+ else if (message_.action instanceof types.MessageActionPinMessage) {
137
+ const { replyToMessage } = await getReply(message_, chat, getMessage);
138
+ message.pinnedMessage = replyToMessage;
139
+ }
140
+ else if (message_.action instanceof types.MessageActionRequestedPeer) {
141
+ const user = message_.action.peer[as](types.PeerUser);
142
+ message.userShared = { requestId: message_.action.buttonId, userId: Number(user.userId) };
143
+ }
144
+ else if (message_.action instanceof types.MessageActionBotAllowed) {
145
+ const webAppName = message_.action.app ? message_.action.app[as](types.BotApp).title : undefined;
146
+ message.writeAccessAllowed = { webAppName };
147
+ }
148
+ else if (message_.action instanceof types.MessageActionTopicCreate) {
149
+ message.forumTopicCreated = {
150
+ name: message_.action.title,
151
+ iconColor: "#" + message_.action.iconColor.toString(16).padStart(6, "0"),
152
+ iconCutsomEmojiId: message_.action.iconEmojiId ? String(message_.action.iconEmojiId) : undefined,
153
+ };
154
+ }
155
+ else if (message_.action instanceof types.MessageActionTopicEdit) {
156
+ if (message_.action.closed) {
157
+ message.forumTopicClosed = {};
158
+ }
159
+ else if (message_.action.title || message_.action.iconEmojiId) {
160
+ message.forumTopicEdited = {
161
+ name: message_.action.title,
162
+ iconCutsomEmojiId: message_.action.iconEmojiId ? String(message_.action.iconEmojiId) : undefined,
163
+ };
164
+ }
165
+ else {
166
+ message.forumTopicReopened = {};
167
+ }
168
+ }
169
+ else if (message_.action instanceof types.MessageActionGroupCallScheduled) {
170
+ message.videoChatScheduled = { startDate: new Date(message_.action.scheduleDate * 1000) };
171
+ }
172
+ else if (message_.action instanceof types.MessageActionGroupCall) {
173
+ if (message_.action.duration) {
174
+ message.videoChatEnded = { duration: message_.action.duration };
175
+ }
176
+ else {
177
+ message.videoChatStarted = {};
178
+ }
179
+ }
180
+ return cleanObject(message);
75
181
  }
76
182
  export async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
77
183
  if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {
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.941",
5
+ "version": "0.0.950",
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.941";
7
+ export declare const DEFAULT_APP_VERSION = "MTKruto 0.0.950";
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.941";
91
+ exports.DEFAULT_APP_VERSION = "MTKruto 0.0.950";
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];
@@ -76,6 +76,11 @@ function serializeSingleParam(writer, value, type, ntype) {
76
76
  }
77
77
  break;
78
78
  case "number":
79
+ //
80
+ if (value == null) {
81
+ value = 0;
82
+ }
83
+ //
79
84
  if (typeof value === "number") {
80
85
  writer.writeInt32(value);
81
86
  }
@@ -60,7 +60,7 @@ function replyKeyboardMarkupToTlObject(replyMarkup) {
60
60
  selective: replyMarkup.selective || undefined,
61
61
  persistent: replyMarkup.isPersistent || undefined,
62
62
  rows: rows_,
63
- placeholder: replyMarkup.inputFieldPlaceholder
63
+ placeholder: replyMarkup.inputFieldPlaceholder,
64
64
  });
65
65
  }
66
66
  exports.replyKeyboardMarkupToTlObject = replyKeyboardMarkupToTlObject;
@@ -90,6 +90,42 @@ export interface Message {
90
90
  game?: Game;
91
91
  venue?: Venue;
92
92
  location?: Location;
93
+ newChatMembers?: User[];
94
+ leftChatMember?: User;
95
+ newChatTitle?: string;
96
+ newChatPhoto?: Photo;
97
+ deletedChatPhoto?: true;
98
+ groupCreated?: true;
99
+ supergroupCreated?: true;
100
+ channelCreated?: true;
101
+ chatMigratedTo?: number;
102
+ chatMigratedFrom?: number;
103
+ pinnedMessage?: Message;
104
+ userShared?: {
105
+ requestId: number;
106
+ userId: number;
107
+ };
108
+ writeAccessAllowed?: {
109
+ webAppName?: string;
110
+ };
111
+ forumTopicCreated?: {
112
+ name: string;
113
+ iconColor: string;
114
+ iconCutsomEmojiId?: string;
115
+ };
116
+ forumTopicEdited?: {
117
+ name?: string;
118
+ iconCutsomEmojiId?: string;
119
+ };
120
+ forumTopicClosed?: Record<never, never>;
121
+ forumTopicReopened?: Record<never, never>;
122
+ videoChatScheduled?: {
123
+ startDate: Date;
124
+ };
125
+ videoChatStarted?: Record<never, never>;
126
+ videoChatEnded?: {
127
+ duration: number;
128
+ };
93
129
  }
94
130
  interface EntityGetter {
95
131
  (peer: types.PeerUser): MaybePromise<types.User | null>;
@@ -27,6 +27,7 @@ exports.constructMessage = void 0;
27
27
  const deps_js_1 = require("../deps.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");
30
31
  const types = __importStar(require("../tl/2_types.js"));
31
32
  const _0_force_reply_js_1 = require("./0_force_reply.js");
32
33
  const _0_message_entity_js_1 = require("./0_message_entity.js");
@@ -49,6 +50,7 @@ const _0_contact_js_1 = require("./0_contact.js");
49
50
  const _2_game_js_1 = require("./2_game.js");
50
51
  const _0_venue_js_1 = require("./0_venue.js");
51
52
  const _0_location_js_1 = require("./0_location.js");
53
+ const constants_js_1 = require("../constants.js");
52
54
  const d = (0, deps_js_1.debug)("types/Message");
53
55
  async function getSender(message_, getEntity) {
54
56
  if (message_.fromId instanceof types.PeerUser) {
@@ -84,9 +86,7 @@ async function getReply(message_, chat, getMessage) {
84
86
  d("couldn't get replied message");
85
87
  }
86
88
  }
87
- else {
88
- return {};
89
- }
89
+ return { replyToMessage: undefined, threadId: undefined, isTopicMessage: undefined };
90
90
  }
91
91
  async function constructServiceMessage(message_, chat, getEntity, getMessage) {
92
92
  const message = {
@@ -95,9 +95,115 @@ async function constructServiceMessage(message_, chat, getEntity, getMessage) {
95
95
  date: new Date(message_.date * 1000),
96
96
  isTopicMessage: false,
97
97
  };
98
- Object.assign(message, await getReply(message_, chat, getMessage));
99
98
  Object.assign(message, await getSender(message_, getEntity));
100
- return message;
99
+ if (message_.action instanceof types.MessageActionChatAddUser) {
100
+ message.newChatMembers = [];
101
+ for (const user_ of message_.action.users) {
102
+ const entity = await getEntity(new types.PeerUser({ userId: user_ }));
103
+ if (entity) {
104
+ const user = (0, _1_user_js_1.constructUser)(entity);
105
+ message.newChatMembers.push(user);
106
+ }
107
+ else {
108
+ (0, _0_control_js_1.UNREACHABLE)();
109
+ }
110
+ }
111
+ }
112
+ else if (message_.action instanceof types.MessageActionChatDeleteUser) {
113
+ const entity = await getEntity(new types.PeerUser({ userId: message_.action.userId }));
114
+ if (entity) {
115
+ const user = (0, _1_user_js_1.constructUser)(entity);
116
+ message.leftChatMember = user;
117
+ }
118
+ else {
119
+ (0, _0_control_js_1.UNREACHABLE)();
120
+ }
121
+ }
122
+ else if (message_.action instanceof types.MessageActionChatEditTitle) {
123
+ message.newChatTitle = message_.action.title;
124
+ }
125
+ else if (message_.action instanceof types.MessageActionChatEditPhoto) {
126
+ message.newChatPhoto = (0, _1_photo_js_1.constructPhoto)(message_.action.photo[_1_tl_object_js_1.as](types.Photo));
127
+ }
128
+ else if (message_.action instanceof types.MessageActionChatDeletePhoto) {
129
+ message.deletedChatPhoto = true;
130
+ }
131
+ else if (message_.action instanceof types.MessageActionChatCreate) {
132
+ message.groupCreated = true;
133
+ message.newChatMembers = [];
134
+ for (const user_ of message_.action.users) {
135
+ const entity = await getEntity(new types.PeerUser({ userId: user_ }));
136
+ if (entity) {
137
+ const user = (0, _1_user_js_1.constructUser)(entity);
138
+ message.newChatMembers.push(user);
139
+ }
140
+ else {
141
+ (0, _0_control_js_1.UNREACHABLE)();
142
+ }
143
+ }
144
+ }
145
+ else if (message_.action instanceof types.MessageActionChannelCreate) {
146
+ if (message.chat.type == _1_chat_js_1.ChatType.Channel) {
147
+ message.channelCreated = true;
148
+ }
149
+ else if (message.chat.type == _1_chat_js_1.ChatType.Supergroup) {
150
+ message.supergroupCreated = true;
151
+ }
152
+ else {
153
+ (0, _0_control_js_1.UNREACHABLE)();
154
+ }
155
+ }
156
+ else if (message_.action instanceof types.MessageActionChatMigrateTo) {
157
+ message.chatMigratedTo = constants_js_1.ZERO_CHANNEL_ID + Number(-message_.action.channelId);
158
+ }
159
+ else if (message_.action instanceof types.MessageActionChannelMigrateFrom) {
160
+ message.chatMigratedFrom = Number(-message_.action.chatId);
161
+ }
162
+ else if (message_.action instanceof types.MessageActionPinMessage) {
163
+ const { replyToMessage } = await getReply(message_, chat, getMessage);
164
+ message.pinnedMessage = replyToMessage;
165
+ }
166
+ else if (message_.action instanceof types.MessageActionRequestedPeer) {
167
+ const user = message_.action.peer[_1_tl_object_js_1.as](types.PeerUser);
168
+ message.userShared = { requestId: message_.action.buttonId, userId: Number(user.userId) };
169
+ }
170
+ else if (message_.action instanceof types.MessageActionBotAllowed) {
171
+ const webAppName = message_.action.app ? message_.action.app[_1_tl_object_js_1.as](types.BotApp).title : undefined;
172
+ message.writeAccessAllowed = { webAppName };
173
+ }
174
+ else if (message_.action instanceof types.MessageActionTopicCreate) {
175
+ message.forumTopicCreated = {
176
+ name: message_.action.title,
177
+ iconColor: "#" + message_.action.iconColor.toString(16).padStart(6, "0"),
178
+ iconCutsomEmojiId: message_.action.iconEmojiId ? String(message_.action.iconEmojiId) : undefined,
179
+ };
180
+ }
181
+ else if (message_.action instanceof types.MessageActionTopicEdit) {
182
+ if (message_.action.closed) {
183
+ message.forumTopicClosed = {};
184
+ }
185
+ else if (message_.action.title || message_.action.iconEmojiId) {
186
+ message.forumTopicEdited = {
187
+ name: message_.action.title,
188
+ iconCutsomEmojiId: message_.action.iconEmojiId ? String(message_.action.iconEmojiId) : undefined,
189
+ };
190
+ }
191
+ else {
192
+ message.forumTopicReopened = {};
193
+ }
194
+ }
195
+ else if (message_.action instanceof types.MessageActionGroupCallScheduled) {
196
+ message.videoChatScheduled = { startDate: new Date(message_.action.scheduleDate * 1000) };
197
+ }
198
+ else if (message_.action instanceof types.MessageActionGroupCall) {
199
+ if (message_.action.duration) {
200
+ message.videoChatEnded = { duration: message_.action.duration };
201
+ }
202
+ else {
203
+ message.videoChatStarted = {};
204
+ }
205
+ }
206
+ return (0, _0_object_js_1.cleanObject)(message);
101
207
  }
102
208
  async function constructMessage(message_, getEntity, getMessage, getStickerSetName) {
103
209
  if (!(message_ instanceof types.Message) && !(message_ instanceof types.MessageService)) {