@mtkruto/node 0.1.103 → 0.1.104
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/4_constants.d.ts +1 -1
- package/esm/4_constants.js +1 -1
- package/esm/client/4_client.d.ts +2 -0
- package/esm/client/4_client.js +62 -3
- package/package.json +1 -1
- package/script/4_constants.d.ts +1 -1
- package/script/4_constants.js +1 -1
- package/script/client/4_client.d.ts +2 -0
- package/script/client/4_client.js +62 -3
package/esm/4_constants.d.ts
CHANGED
|
@@ -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.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.1.104";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/esm/4_constants.js
CHANGED
|
@@ -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.
|
|
57
|
+
export const APP_VERSION = "MTKruto 0.1.104";
|
|
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];
|
package/esm/client/4_client.d.ts
CHANGED
|
@@ -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
|
*
|
package/esm/client/4_client.js
CHANGED
|
@@ -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);
|
package/package.json
CHANGED
package/script/4_constants.d.ts
CHANGED
|
@@ -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.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.1.104";
|
|
9
9
|
export declare const DEVICE_MODEL: string;
|
|
10
10
|
export declare const LANG_CODE: string;
|
|
11
11
|
export declare const LANG_PACK = "";
|
package/script/4_constants.js
CHANGED
|
@@ -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.
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.1.104";
|
|
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);
|