@mtkruto/node 0.0.974 → 0.0.976
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/client/3_client.d.ts +5 -1
- package/esm/client/3_client.js +22 -1
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/utilities/1_misc.d.ts +3 -0
- package/esm/utilities/1_misc.js +21 -0
- package/package.json +1 -1
- package/script/client/3_client.d.ts +5 -1
- package/script/client/3_client.js +26 -5
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/utilities/1_misc.d.ts +3 -0
- package/script/utilities/1_misc.js +27 -0
- package/esm/utilities/0_misc.d.ts +0 -1
- package/esm/utilities/0_misc.js +0 -3
- package/script/utilities/0_misc.d.ts +0 -1
- package/script/utilities/0_misc.js +0 -7
package/esm/client/3_client.d.ts
CHANGED
|
@@ -131,7 +131,11 @@ export declare class Client extends ClientAbstract {
|
|
|
131
131
|
* [1]: https://core.telegram.org/method/initConnection
|
|
132
132
|
* [2]: https://core.telegram.org/method/updates.getState
|
|
133
133
|
*/
|
|
134
|
-
authorize(params
|
|
134
|
+
authorize(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Same as calling `.connect()` followed by `.authorize(params)`.
|
|
137
|
+
*/
|
|
138
|
+
start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
135
139
|
private receiveLoop;
|
|
136
140
|
private pingLoop;
|
|
137
141
|
private lastMsgId;
|
package/esm/client/3_client.js
CHANGED
|
@@ -23,8 +23,9 @@ import { parseHtml } from "./0_html.js";
|
|
|
23
23
|
import { checkPassword } from "./0_password.js";
|
|
24
24
|
import { ClientAbstract } from "./1_client_abstract.js";
|
|
25
25
|
import { ClientPlain } from "./2_client_plain.js";
|
|
26
|
-
import { drop } from "../utilities/
|
|
26
|
+
import { drop } from "../utilities/1_misc.js";
|
|
27
27
|
import { getChannelChatId, peerToChatId } from "./0_utilities.js";
|
|
28
|
+
import { mustPrompt, mustPromptNumber } from "../utilities/1_misc.js";
|
|
28
29
|
const d = debug("Client");
|
|
29
30
|
const dGap = debug("Client/recoverUpdateGap");
|
|
30
31
|
const dGapC = debug("Client/recoverChannelUpdateGap");
|
|
@@ -303,6 +304,19 @@ export class Client extends ClientAbstract {
|
|
|
303
304
|
if (!this.apiHash) {
|
|
304
305
|
throw new Error("apiHash not set");
|
|
305
306
|
}
|
|
307
|
+
if (typeof params === "undefined") {
|
|
308
|
+
const phoneNumberOrBotToken = mustPrompt("Enter a phone number or a bot token:");
|
|
309
|
+
if (phoneNumberOrBotToken.startsWith("+")) {
|
|
310
|
+
params = {
|
|
311
|
+
phone: phoneNumberOrBotToken,
|
|
312
|
+
code: () => String(mustPromptNumber("Enter the verification code:")),
|
|
313
|
+
password: () => mustPrompt("Enter the account password:"),
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
else {
|
|
317
|
+
params = phoneNumberOrBotToken;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
306
320
|
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
307
321
|
await this.invoke(new functions.InitConnection({
|
|
308
322
|
apiId: this.apiId,
|
|
@@ -459,6 +473,13 @@ export class Client extends ClientAbstract {
|
|
|
459
473
|
}
|
|
460
474
|
}
|
|
461
475
|
}
|
|
476
|
+
/**
|
|
477
|
+
* Same as calling `.connect()` followed by `.authorize(params)`.
|
|
478
|
+
*/
|
|
479
|
+
async start(params) {
|
|
480
|
+
await this.connect();
|
|
481
|
+
await this.authorize(params);
|
|
482
|
+
}
|
|
462
483
|
async receiveLoop() {
|
|
463
484
|
if (!this.auth) {
|
|
464
485
|
throw new Error("Not connected");
|
package/esm/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 = 160;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.0.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.976";
|
|
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/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 = 160;
|
|
57
|
-
export const APP_VERSION = "MTKruto 0.0.
|
|
57
|
+
export const APP_VERSION = "MTKruto 0.0.976";
|
|
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];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { UNREACHABLE } from "./0_control.js";
|
|
2
|
+
export function drop(promise) {
|
|
3
|
+
promise.then().catch();
|
|
4
|
+
}
|
|
5
|
+
export function mustPrompt(message) {
|
|
6
|
+
const result = prompt(message);
|
|
7
|
+
if (result == null) {
|
|
8
|
+
throw UNREACHABLE();
|
|
9
|
+
}
|
|
10
|
+
else {
|
|
11
|
+
return result;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function mustPromptNumber(message) {
|
|
15
|
+
let result = Number(BigInt(mustPrompt(message)));
|
|
16
|
+
while (isNaN(result)) {
|
|
17
|
+
console.log("Expected a number.");
|
|
18
|
+
result = Number(BigInt(mustPrompt(message)));
|
|
19
|
+
}
|
|
20
|
+
return result;
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -131,7 +131,11 @@ export declare class Client extends ClientAbstract {
|
|
|
131
131
|
* [1]: https://core.telegram.org/method/initConnection
|
|
132
132
|
* [2]: https://core.telegram.org/method/updates.getState
|
|
133
133
|
*/
|
|
134
|
-
authorize(params
|
|
134
|
+
authorize(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
135
|
+
/**
|
|
136
|
+
* Same as calling `.connect()` followed by `.authorize(params)`.
|
|
137
|
+
*/
|
|
138
|
+
start(params?: string | types.AuthExportedAuthorization | AuthorizeUserParams): Promise<void>;
|
|
135
139
|
private receiveLoop;
|
|
136
140
|
private pingLoop;
|
|
137
141
|
private lastMsgId;
|
|
@@ -49,8 +49,9 @@ const _0_html_js_1 = require("./0_html.js");
|
|
|
49
49
|
const _0_password_js_1 = require("./0_password.js");
|
|
50
50
|
const _1_client_abstract_js_1 = require("./1_client_abstract.js");
|
|
51
51
|
const _2_client_plain_js_1 = require("./2_client_plain.js");
|
|
52
|
-
const
|
|
52
|
+
const _1_misc_js_1 = require("../utilities/1_misc.js");
|
|
53
53
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
54
|
+
const _1_misc_js_2 = require("../utilities/1_misc.js");
|
|
54
55
|
const d = (0, deps_js_1.debug)("Client");
|
|
55
56
|
const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
|
|
56
57
|
const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
@@ -283,8 +284,8 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
283
284
|
await this.storage.setDc(this.transportProvider.initialDc);
|
|
284
285
|
}
|
|
285
286
|
d("encrypted client connected");
|
|
286
|
-
(0,
|
|
287
|
-
(0,
|
|
287
|
+
(0, _1_misc_js_1.drop)(this.receiveLoop());
|
|
288
|
+
(0, _1_misc_js_1.drop)(this.pingLoop());
|
|
288
289
|
}
|
|
289
290
|
async fetchState(source) {
|
|
290
291
|
const state = await this.invoke(new functions.UpdatesGetState());
|
|
@@ -329,6 +330,19 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
329
330
|
if (!this.apiHash) {
|
|
330
331
|
throw new Error("apiHash not set");
|
|
331
332
|
}
|
|
333
|
+
if (typeof params === "undefined") {
|
|
334
|
+
const phoneNumberOrBotToken = (0, _1_misc_js_2.mustPrompt)("Enter a phone number or a bot token:");
|
|
335
|
+
if (phoneNumberOrBotToken.startsWith("+")) {
|
|
336
|
+
params = {
|
|
337
|
+
phone: phoneNumberOrBotToken,
|
|
338
|
+
code: () => String((0, _1_misc_js_2.mustPromptNumber)("Enter the verification code:")),
|
|
339
|
+
password: () => (0, _1_misc_js_2.mustPrompt)("Enter the account password:"),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
else {
|
|
343
|
+
params = phoneNumberOrBotToken;
|
|
344
|
+
}
|
|
345
|
+
}
|
|
332
346
|
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
333
347
|
await this.invoke(new functions.InitConnection({
|
|
334
348
|
apiId: this.apiId,
|
|
@@ -485,6 +499,13 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
485
499
|
}
|
|
486
500
|
}
|
|
487
501
|
}
|
|
502
|
+
/**
|
|
503
|
+
* Same as calling `.connect()` followed by `.authorize(params)`.
|
|
504
|
+
*/
|
|
505
|
+
async start(params) {
|
|
506
|
+
await this.connect();
|
|
507
|
+
await this.authorize(params);
|
|
508
|
+
}
|
|
488
509
|
async receiveLoop() {
|
|
489
510
|
if (!this.auth) {
|
|
490
511
|
throw new Error("Not connected");
|
|
@@ -502,7 +523,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
502
523
|
}
|
|
503
524
|
catch (err) {
|
|
504
525
|
dRecv("failed to decrypt message: %o", err);
|
|
505
|
-
(0,
|
|
526
|
+
(0, _1_misc_js_1.drop)(this.recoverUpdateGap("decryption"));
|
|
506
527
|
continue;
|
|
507
528
|
}
|
|
508
529
|
const messages = decrypted instanceof _7_message_container_js_1.MessageContainer ? decrypted.messages : [decrypted];
|
|
@@ -513,7 +534,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
513
534
|
}
|
|
514
535
|
dRecv("received %s", body.constructor.name);
|
|
515
536
|
if (body instanceof types.Updates || body instanceof types.TypeUpdate) {
|
|
516
|
-
(0,
|
|
537
|
+
(0, _1_misc_js_1.drop)(this.processUpdates(body));
|
|
517
538
|
}
|
|
518
539
|
else if (message.body instanceof _5_rpc_result_js_1.RPCResult) {
|
|
519
540
|
let result = message.body.result;
|
package/script/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 = 160;
|
|
8
|
-
export declare const APP_VERSION = "MTKruto 0.0.
|
|
8
|
+
export declare const APP_VERSION = "MTKruto 0.0.976";
|
|
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/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 = 160;
|
|
83
|
-
exports.APP_VERSION = "MTKruto 0.0.
|
|
83
|
+
exports.APP_VERSION = "MTKruto 0.0.976";
|
|
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];
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.mustPromptNumber = exports.mustPrompt = exports.drop = void 0;
|
|
4
|
+
const _0_control_js_1 = require("./0_control.js");
|
|
5
|
+
function drop(promise) {
|
|
6
|
+
promise.then().catch();
|
|
7
|
+
}
|
|
8
|
+
exports.drop = drop;
|
|
9
|
+
function mustPrompt(message) {
|
|
10
|
+
const result = prompt(message);
|
|
11
|
+
if (result == null) {
|
|
12
|
+
throw (0, _0_control_js_1.UNREACHABLE)();
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.mustPrompt = mustPrompt;
|
|
19
|
+
function mustPromptNumber(message) {
|
|
20
|
+
let result = Number(BigInt(mustPrompt(message)));
|
|
21
|
+
while (isNaN(result)) {
|
|
22
|
+
console.log("Expected a number.");
|
|
23
|
+
result = Number(BigInt(mustPrompt(message)));
|
|
24
|
+
}
|
|
25
|
+
return result;
|
|
26
|
+
}
|
|
27
|
+
exports.mustPromptNumber = mustPromptNumber;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function drop<T>(promise: Promise<T>): void;
|
package/esm/utilities/0_misc.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export declare function drop<T>(promise: Promise<T>): void;
|