@mtkruto/node 0.1.103 → 0.1.105

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.
package/esm/3_types.d.ts CHANGED
@@ -21,6 +21,7 @@ export * from "./types/0_message_entity.js";
21
21
  export * from "./types/0_parse_mode.js";
22
22
  export * from "./types/0_poll_option.js";
23
23
  export * from "./types/0_reply_keyboard_remove.js";
24
+ export * from "./types/0_restriction_reason.js";
24
25
  export * from "./types/0_thumbnail.js";
25
26
  export * from "./types/0_venue.js";
26
27
  export * from "./types/0_voice.js";
package/esm/3_types.js CHANGED
@@ -21,6 +21,7 @@ export * from "./types/0_message_entity.js";
21
21
  export * from "./types/0_parse_mode.js";
22
22
  export * from "./types/0_poll_option.js";
23
23
  export * from "./types/0_reply_keyboard_remove.js";
24
+ export * from "./types/0_restriction_reason.js";
24
25
  export * from "./types/0_thumbnail.js";
25
26
  export * from "./types/0_venue.js";
26
27
  export * from "./types/0_voice.js";
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.1.103";
8
+ export declare const APP_VERSION = "MTKruto 0.1.105";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -54,7 +54,7 @@ export const PUBLIC_KEYS = Object.freeze([
54
54
  export const VECTOR_CONSTRUCTOR = 0x1CB5C415;
55
55
  export const INITIAL_DC = "2-test";
56
56
  export const LAYER = 161;
57
- export const APP_VERSION = "MTKruto 0.1.103";
57
+ export const APP_VERSION = "MTKruto 0.1.105";
58
58
  // @ts-ignore: lib
59
59
  export const 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;
60
60
  export const LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -70,6 +70,8 @@ export declare class Client extends ClientAbstract {
70
70
  private initConnection;
71
71
  private lastPropagatedAuthorizationState;
72
72
  private propagateAuthorizationState;
73
+ private selfId;
74
+ private getSelfId;
73
75
  /**
74
76
  * Calls [initConnection](1) and authorizes the client with one of the following:
75
77
  *
@@ -198,6 +198,12 @@ export class Client extends ClientAbstract {
198
198
  writable: true,
199
199
  value: null
200
200
  });
201
+ Object.defineProperty(this, "selfId", {
202
+ enumerable: true,
203
+ configurable: true,
204
+ writable: true,
205
+ value: null
206
+ });
201
207
  Object.defineProperty(this, "pingLoopStarted", {
202
208
  enumerable: true,
203
209
  configurable: true,
@@ -380,6 +386,12 @@ export class Client extends ClientAbstract {
380
386
  this.lastPropagatedAuthorizationState = authorized;
381
387
  }
382
388
  }
389
+ async getSelfId() {
390
+ if (this.selfId == null) {
391
+ this.selfId = await this.getMe().then((v) => v.id);
392
+ }
393
+ return this.selfId;
394
+ }
383
395
  /**
384
396
  * Calls [initConnection](1) and authorizes the client with one of the following:
385
397
  *
@@ -429,7 +441,8 @@ export class Client extends ClientAbstract {
429
441
  if (typeof params === "string") {
430
442
  while (true) {
431
443
  try {
432
- await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
444
+ const auth = await this.invoke(new functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
445
+ this.selfId = Number(auth[as](types.AuthAuthorization).user.id);
433
446
  await this.storage.setAccountType("bot");
434
447
  break;
435
448
  }
@@ -494,11 +507,12 @@ export class Client extends ClientAbstract {
494
507
  while (true) {
495
508
  const code = typeof params.code === "string" ? params.code : await params.code();
496
509
  try {
497
- await this.invoke(new functions.AuthSignIn({
510
+ const auth = await this.invoke(new functions.AuthSignIn({
498
511
  phoneNumber: phone,
499
512
  phoneCode: code,
500
513
  phoneCodeHash: sentCode.phoneCodeHash,
501
514
  }));
515
+ this.selfId = Number(auth[as](types.AuthAuthorization).user.id);
502
516
  await this.storage.setAccountType("user");
503
517
  dAuth("authorized as user");
504
518
  await this.propagateAuthorizationState(true);
@@ -526,7 +540,8 @@ export class Client extends ClientAbstract {
526
540
  try {
527
541
  const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
528
542
  const input = await checkPassword(password, ap);
529
- await this.invoke(new functions.AuthCheckPassword({ password: input }));
543
+ const auth = await this.invoke(new functions.AuthCheckPassword({ password: input }));
544
+ this.selfId = Number(auth[as](types.AuthAuthorization).user.id);
530
545
  await this.storage.setAccountType("user");
531
546
  dAuth("authorized as user");
532
547
  await this.propagateAuthorizationState(true);
@@ -1480,6 +1495,50 @@ export class Client extends ClientAbstract {
1480
1495
  }
1481
1496
  // TODO: log errors
1482
1497
  async handleUpdate(update) {
1498
+ if (update instanceof types.UpdateShortMessage) {
1499
+ update = new types.UpdateNewMessage({
1500
+ message: new types.Message({
1501
+ out: update.out,
1502
+ mentioned: update.mentioned,
1503
+ mediaUnread: update.mediaUnread,
1504
+ silent: update.silent,
1505
+ id: update.id,
1506
+ fromId: update.out ? new types.PeerUser({ userId: await this.getSelfId().then(BigInt) }) : new types.PeerUser({ userId: update.userId }),
1507
+ peerId: new types.PeerChat({ chatId: update.userId }),
1508
+ message: update.message,
1509
+ date: update.date,
1510
+ fwdFrom: update.fwdFrom,
1511
+ viaBotId: update.viaBotId,
1512
+ replyTo: update.replyTo,
1513
+ entities: update.entities,
1514
+ ttlPeriod: update.ttlPeriod,
1515
+ }),
1516
+ pts: update.pts,
1517
+ ptsCount: update.ptsCount,
1518
+ });
1519
+ }
1520
+ else if (update instanceof types.UpdateShortChatMessage) {
1521
+ update = new types.UpdateNewMessage({
1522
+ message: new types.Message({
1523
+ out: update.out,
1524
+ mentioned: update.mentioned,
1525
+ mediaUnread: update.mediaUnread,
1526
+ silent: update.silent,
1527
+ id: update.id,
1528
+ fromId: new types.PeerUser({ userId: update.fromId }),
1529
+ peerId: new types.PeerChat({ chatId: update.chatId }),
1530
+ fwdFrom: update.fwdFrom,
1531
+ viaBotId: update.viaBotId,
1532
+ replyTo: update.replyTo,
1533
+ date: update.date,
1534
+ message: update.message,
1535
+ entities: update.entities,
1536
+ ttlPeriod: update.ttlPeriod,
1537
+ }),
1538
+ pts: update.pts,
1539
+ ptsCount: update.ptsCount,
1540
+ });
1541
+ }
1483
1542
  if (update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewMessage || update instanceof types.UpdateNewChannelMessage || update instanceof types.UpdateNewChannelMessage) {
1484
1543
  if (update.message instanceof types.Message || update.message instanceof types.MessageService) {
1485
1544
  await this.storage.setMessage(peerToChatId(update.message.peerId), update.message.id, update.message);
@@ -0,0 +1,7 @@
1
+ import { types } from "../2_tl.js";
2
+ export interface RestrictionReason {
3
+ platform: string;
4
+ reason: string;
5
+ text: string;
6
+ }
7
+ export declare function constructRestrictionReason(rr: types.TypeRestrictionReason): RestrictionReason;
@@ -0,0 +1,3 @@
1
+ export function constructRestrictionReason(rr) {
2
+ return { platform: rr.platform, reason: rr.reason, text: rr.text };
3
+ }
@@ -1,6 +1,7 @@
1
1
  import { types } from "../2_tl.js";
2
2
  import { ChatPhoto } from "./0_chat_photo.js";
3
3
  import { Color } from "./0_color.js";
4
+ import { RestrictionReason } from "./0_restriction_reason.js";
4
5
  export type ChatType = "private" | "group" | "supergroup" | "channel";
5
6
  export declare namespace Chat {
6
7
  interface Base {
@@ -37,7 +38,7 @@ export declare namespace Chat {
37
38
  /** True, if the access to the user must be restricted for the reason specified in `restriction_reason` */
38
39
  isRestricted?: boolean;
39
40
  /** Contains the reason why access to the user must be restricted. */
40
- restrictionReason?: types.RestrictionReason[];
41
+ restrictionReason?: RestrictionReason[];
41
42
  }
42
43
  interface Group extends Base {
43
44
  type: "group";
@@ -66,7 +67,7 @@ export declare namespace Chat {
66
67
  /** True, if the access to the user must be restricted for the reason specified in `restriction_reason` */
67
68
  isRestricted: boolean;
68
69
  /** Contains the reason why access to the user must be restricted. */
69
- restrictionReason?: types.RestrictionReason[];
70
+ restrictionReason?: RestrictionReason[];
70
71
  }
71
72
  interface Channel extends ChannelBase {
72
73
  type: "channel";
@@ -3,6 +3,7 @@ import { types } from "../2_tl.js";
3
3
  import { ZERO_CHANNEL_ID } from "../4_constants.js";
4
4
  import { constructChatPhoto } from "./0_chat_photo.js";
5
5
  import { getColor } from "./0_color.js";
6
+ import { constructRestrictionReason } from "./0_restriction_reason.js";
6
7
  export function constructChat(chat) {
7
8
  if (chat instanceof types.User) {
8
9
  const id = Number(chat.id);
@@ -74,7 +75,7 @@ export function constructChat(chat) {
74
75
  chat_.username = chat.username;
75
76
  chat_.also = chat.usernames?.map((v) => v.username);
76
77
  if (chat_.isRestricted) {
77
- chat_.restrictionReason = chat.restrictionReason;
78
+ chat_.restrictionReason = (chat.restrictionReason ?? []).map(constructRestrictionReason);
78
79
  }
79
80
  if (chat.photo instanceof types.ChatPhoto) {
80
81
  chat_.photo = constructChatPhoto(chat.photo, chat_.id, chat.accessHash ?? 0n);
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.1.103",
5
+ "version": "0.1.105",
6
6
  "description": "MTKruto for Node.js",
7
7
  "author": "Roj <rojvv@icloud.com>",
8
8
  "license": "LGPL-3.0-or-later",
@@ -21,6 +21,7 @@ export * from "./types/0_message_entity.js";
21
21
  export * from "./types/0_parse_mode.js";
22
22
  export * from "./types/0_poll_option.js";
23
23
  export * from "./types/0_reply_keyboard_remove.js";
24
+ export * from "./types/0_restriction_reason.js";
24
25
  export * from "./types/0_thumbnail.js";
25
26
  export * from "./types/0_venue.js";
26
27
  export * from "./types/0_voice.js";
package/script/3_types.js CHANGED
@@ -37,6 +37,7 @@ __exportStar(require("./types/0_message_entity.js"), exports);
37
37
  __exportStar(require("./types/0_parse_mode.js"), exports);
38
38
  __exportStar(require("./types/0_poll_option.js"), exports);
39
39
  __exportStar(require("./types/0_reply_keyboard_remove.js"), exports);
40
+ __exportStar(require("./types/0_restriction_reason.js"), exports);
40
41
  __exportStar(require("./types/0_thumbnail.js"), exports);
41
42
  __exportStar(require("./types/0_venue.js"), exports);
42
43
  __exportStar(require("./types/0_voice.js"), exports);
@@ -5,7 +5,7 @@ export declare const PUBLIC_KEYS: PublicKeys;
5
5
  export declare const VECTOR_CONSTRUCTOR = 481674261;
6
6
  export declare const INITIAL_DC: DC;
7
7
  export declare const LAYER = 161;
8
- export declare const APP_VERSION = "MTKruto 0.1.103";
8
+ export declare const APP_VERSION = "MTKruto 0.1.105";
9
9
  export declare const DEVICE_MODEL: string;
10
10
  export declare const LANG_CODE: string;
11
11
  export declare const LANG_PACK = "";
@@ -80,7 +80,7 @@ exports.PUBLIC_KEYS = Object.freeze([
80
80
  exports.VECTOR_CONSTRUCTOR = 0x1CB5C415;
81
81
  exports.INITIAL_DC = "2-test";
82
82
  exports.LAYER = 161;
83
- exports.APP_VERSION = "MTKruto 0.1.103";
83
+ exports.APP_VERSION = "MTKruto 0.1.105";
84
84
  // @ts-ignore: lib
85
85
  exports.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;
86
86
  exports.LANG_CODE = typeof navigator === "undefined" ? "en" : navigator.language.split("-")[0];
@@ -70,6 +70,8 @@ export declare class Client extends ClientAbstract {
70
70
  private initConnection;
71
71
  private lastPropagatedAuthorizationState;
72
72
  private propagateAuthorizationState;
73
+ private selfId;
74
+ private getSelfId;
73
75
  /**
74
76
  * Calls [initConnection](1) and authorizes the client with one of the following:
75
77
  *
@@ -202,6 +202,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
202
202
  writable: true,
203
203
  value: null
204
204
  });
205
+ Object.defineProperty(this, "selfId", {
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true,
209
+ value: null
210
+ });
205
211
  Object.defineProperty(this, "pingLoopStarted", {
206
212
  enumerable: true,
207
213
  configurable: true,
@@ -384,6 +390,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
384
390
  this.lastPropagatedAuthorizationState = authorized;
385
391
  }
386
392
  }
393
+ async getSelfId() {
394
+ if (this.selfId == null) {
395
+ this.selfId = await this.getMe().then((v) => v.id);
396
+ }
397
+ return this.selfId;
398
+ }
387
399
  /**
388
400
  * Calls [initConnection](1) and authorizes the client with one of the following:
389
401
  *
@@ -433,7 +445,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
433
445
  if (typeof params === "string") {
434
446
  while (true) {
435
447
  try {
436
- await this.invoke(new _2_tl_js_1.functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
448
+ const auth = await this.invoke(new _2_tl_js_1.functions.AuthImportBotAuthorization({ apiId: this.apiId, apiHash: this.apiHash, botAuthToken: params, flags: 0 }));
449
+ this.selfId = Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.AuthAuthorization).user.id);
437
450
  await this.storage.setAccountType("bot");
438
451
  break;
439
452
  }
@@ -498,11 +511,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
498
511
  while (true) {
499
512
  const code = typeof params.code === "string" ? params.code : await params.code();
500
513
  try {
501
- await this.invoke(new _2_tl_js_1.functions.AuthSignIn({
514
+ const auth = await this.invoke(new _2_tl_js_1.functions.AuthSignIn({
502
515
  phoneNumber: phone,
503
516
  phoneCode: code,
504
517
  phoneCodeHash: sentCode.phoneCodeHash,
505
518
  }));
519
+ this.selfId = Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.AuthAuthorization).user.id);
506
520
  await this.storage.setAccountType("user");
507
521
  dAuth("authorized as user");
508
522
  await this.propagateAuthorizationState(true);
@@ -530,7 +544,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
530
544
  try {
531
545
  const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
532
546
  const input = await (0, _0_password_js_1.checkPassword)(password, ap);
533
- await this.invoke(new _2_tl_js_1.functions.AuthCheckPassword({ password: input }));
547
+ const auth = await this.invoke(new _2_tl_js_1.functions.AuthCheckPassword({ password: input }));
548
+ this.selfId = Number(auth[_2_tl_js_1.as](_2_tl_js_1.types.AuthAuthorization).user.id);
534
549
  await this.storage.setAccountType("user");
535
550
  dAuth("authorized as user");
536
551
  await this.propagateAuthorizationState(true);
@@ -1484,6 +1499,50 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
1484
1499
  }
1485
1500
  // TODO: log errors
1486
1501
  async handleUpdate(update) {
1502
+ if (update instanceof _2_tl_js_1.types.UpdateShortMessage) {
1503
+ update = new _2_tl_js_1.types.UpdateNewMessage({
1504
+ message: new _2_tl_js_1.types.Message({
1505
+ out: update.out,
1506
+ mentioned: update.mentioned,
1507
+ mediaUnread: update.mediaUnread,
1508
+ silent: update.silent,
1509
+ id: update.id,
1510
+ fromId: update.out ? new _2_tl_js_1.types.PeerUser({ userId: await this.getSelfId().then(BigInt) }) : new _2_tl_js_1.types.PeerUser({ userId: update.userId }),
1511
+ peerId: new _2_tl_js_1.types.PeerChat({ chatId: update.userId }),
1512
+ message: update.message,
1513
+ date: update.date,
1514
+ fwdFrom: update.fwdFrom,
1515
+ viaBotId: update.viaBotId,
1516
+ replyTo: update.replyTo,
1517
+ entities: update.entities,
1518
+ ttlPeriod: update.ttlPeriod,
1519
+ }),
1520
+ pts: update.pts,
1521
+ ptsCount: update.ptsCount,
1522
+ });
1523
+ }
1524
+ else if (update instanceof _2_tl_js_1.types.UpdateShortChatMessage) {
1525
+ update = new _2_tl_js_1.types.UpdateNewMessage({
1526
+ message: new _2_tl_js_1.types.Message({
1527
+ out: update.out,
1528
+ mentioned: update.mentioned,
1529
+ mediaUnread: update.mediaUnread,
1530
+ silent: update.silent,
1531
+ id: update.id,
1532
+ fromId: new _2_tl_js_1.types.PeerUser({ userId: update.fromId }),
1533
+ peerId: new _2_tl_js_1.types.PeerChat({ chatId: update.chatId }),
1534
+ fwdFrom: update.fwdFrom,
1535
+ viaBotId: update.viaBotId,
1536
+ replyTo: update.replyTo,
1537
+ date: update.date,
1538
+ message: update.message,
1539
+ entities: update.entities,
1540
+ ttlPeriod: update.ttlPeriod,
1541
+ }),
1542
+ pts: update.pts,
1543
+ ptsCount: update.ptsCount,
1544
+ });
1545
+ }
1487
1546
  if (update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage || update instanceof _2_tl_js_1.types.UpdateNewChannelMessage) {
1488
1547
  if (update.message instanceof _2_tl_js_1.types.Message || update.message instanceof _2_tl_js_1.types.MessageService) {
1489
1548
  await this.storage.setMessage((0, _2_tl_js_1.peerToChatId)(update.message.peerId), update.message.id, update.message);
@@ -0,0 +1,7 @@
1
+ import { types } from "../2_tl.js";
2
+ export interface RestrictionReason {
3
+ platform: string;
4
+ reason: string;
5
+ text: string;
6
+ }
7
+ export declare function constructRestrictionReason(rr: types.TypeRestrictionReason): RestrictionReason;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.constructRestrictionReason = void 0;
4
+ function constructRestrictionReason(rr) {
5
+ return { platform: rr.platform, reason: rr.reason, text: rr.text };
6
+ }
7
+ exports.constructRestrictionReason = constructRestrictionReason;
@@ -1,6 +1,7 @@
1
1
  import { types } from "../2_tl.js";
2
2
  import { ChatPhoto } from "./0_chat_photo.js";
3
3
  import { Color } from "./0_color.js";
4
+ import { RestrictionReason } from "./0_restriction_reason.js";
4
5
  export type ChatType = "private" | "group" | "supergroup" | "channel";
5
6
  export declare namespace Chat {
6
7
  interface Base {
@@ -37,7 +38,7 @@ export declare namespace Chat {
37
38
  /** True, if the access to the user must be restricted for the reason specified in `restriction_reason` */
38
39
  isRestricted?: boolean;
39
40
  /** Contains the reason why access to the user must be restricted. */
40
- restrictionReason?: types.RestrictionReason[];
41
+ restrictionReason?: RestrictionReason[];
41
42
  }
42
43
  interface Group extends Base {
43
44
  type: "group";
@@ -66,7 +67,7 @@ export declare namespace Chat {
66
67
  /** True, if the access to the user must be restricted for the reason specified in `restriction_reason` */
67
68
  isRestricted: boolean;
68
69
  /** Contains the reason why access to the user must be restricted. */
69
- restrictionReason?: types.RestrictionReason[];
70
+ restrictionReason?: RestrictionReason[];
70
71
  }
71
72
  interface Channel extends ChannelBase {
72
73
  type: "channel";
@@ -6,6 +6,7 @@ const _2_tl_js_1 = require("../2_tl.js");
6
6
  const _4_constants_js_1 = require("../4_constants.js");
7
7
  const _0_chat_photo_js_1 = require("./0_chat_photo.js");
8
8
  const _0_color_js_1 = require("./0_color.js");
9
+ const _0_restriction_reason_js_1 = require("./0_restriction_reason.js");
9
10
  function constructChat(chat) {
10
11
  if (chat instanceof _2_tl_js_1.types.User) {
11
12
  const id = Number(chat.id);
@@ -77,7 +78,7 @@ function constructChat(chat) {
77
78
  chat_.username = chat.username;
78
79
  chat_.also = chat.usernames?.map((v) => v.username);
79
80
  if (chat_.isRestricted) {
80
- chat_.restrictionReason = chat.restrictionReason;
81
+ chat_.restrictionReason = (chat.restrictionReason ?? []).map(_0_restriction_reason_js_1.constructRestrictionReason);
81
82
  }
82
83
  if (chat.photo instanceof _2_tl_js_1.types.ChatPhoto) {
83
84
  chat_.photo = (0, _0_chat_photo_js_1.constructChatPhoto)(chat.photo, chat_.id, chat.accessHash ?? 0n);