@mtkruto/node 0.0.977 → 0.0.978
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 +2 -1
- package/esm/client/3_client.js +15 -12
- package/esm/constants.d.ts +1 -1
- package/esm/constants.js +1 -1
- package/esm/utilities/1_misc.d.ts +1 -0
- package/esm/utilities/1_misc.js +7 -0
- package/package.json +1 -1
- package/script/client/3_client.d.ts +2 -1
- package/script/client/3_client.js +14 -11
- package/script/constants.d.ts +1 -1
- package/script/constants.js +1 -1
- package/script/utilities/1_misc.d.ts +1 -0
- package/script/utilities/1_misc.js +9 -1
package/esm/client/3_client.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare enum ParseMode {
|
|
|
23
23
|
export interface AuthorizeUserParams<S = string> {
|
|
24
24
|
phone: S | (() => MaybePromise<S>);
|
|
25
25
|
code: S | (() => MaybePromise<S>);
|
|
26
|
-
password: S | (() => MaybePromise<S>);
|
|
26
|
+
password: S | ((hint: string | null) => MaybePromise<S>);
|
|
27
27
|
}
|
|
28
28
|
export type UpdateHandler = null | ((client: Client, update: types.TypeUpdate) => MaybePromise<void>);
|
|
29
29
|
export interface ClientParams {
|
|
@@ -196,4 +196,5 @@ export declare class Client extends ClientAbstract {
|
|
|
196
196
|
[getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
|
|
197
197
|
forwardMessages(from: number | string, to: number | string, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
|
|
198
198
|
forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
|
|
199
|
+
getMe(): Promise<import("../types/1_user.js").User>;
|
|
199
200
|
}
|
package/esm/client/3_client.js
CHANGED
|
@@ -23,9 +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/1_misc.js";
|
|
26
|
+
import { drop, mustPrompt, mustPromptOneOf } from "../utilities/1_misc.js";
|
|
27
27
|
import { getChannelChatId, peerToChatId } from "./0_utilities.js";
|
|
28
|
-
import {
|
|
28
|
+
import { constructUser } from "../types/1_user.js";
|
|
29
29
|
const d = debug("Client");
|
|
30
30
|
const dGap = debug("Client/recoverUpdateGap");
|
|
31
31
|
const dGapC = debug("Client/recoverChannelUpdateGap");
|
|
@@ -318,16 +318,12 @@ export class Client extends ClientAbstract {
|
|
|
318
318
|
throw new Error("apiHash not set");
|
|
319
319
|
}
|
|
320
320
|
if (typeof params === "undefined") {
|
|
321
|
-
const
|
|
322
|
-
if (
|
|
323
|
-
params =
|
|
324
|
-
phone: phoneNumberOrBotToken,
|
|
325
|
-
code: () => String(mustPromptNumber("Enter the verification code:")),
|
|
326
|
-
password: () => mustPrompt("Enter the account password:"),
|
|
327
|
-
};
|
|
321
|
+
const loginType = mustPromptOneOf("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
|
|
322
|
+
if (loginType == "b") {
|
|
323
|
+
params = mustPrompt("Bot token:");
|
|
328
324
|
}
|
|
329
325
|
else {
|
|
330
|
-
params =
|
|
326
|
+
params = { phone: () => mustPrompt("Phone number:"), code: () => mustPrompt("Verification code:"), password: () => mustPrompt(`Password:`) };
|
|
331
327
|
}
|
|
332
328
|
}
|
|
333
329
|
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
@@ -352,7 +348,7 @@ export class Client extends ClientAbstract {
|
|
|
352
348
|
const ap = await this.invoke(new functions.AccountGetPassword());
|
|
353
349
|
if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
|
|
354
350
|
try {
|
|
355
|
-
const password = typeof params.password === "string" ? params.password : await params.password();
|
|
351
|
+
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
356
352
|
const input = await checkPassword(password, ap);
|
|
357
353
|
await this.invoke(new functions.AuthCheckPassword({ password: input }));
|
|
358
354
|
await this.storage.setAccountType("user");
|
|
@@ -406,7 +402,7 @@ export class Client extends ClientAbstract {
|
|
|
406
402
|
apiId: this.apiId,
|
|
407
403
|
apiHash: this.apiHash,
|
|
408
404
|
phoneNumber,
|
|
409
|
-
settings: new types.CodeSettings(
|
|
405
|
+
settings: new types.CodeSettings(),
|
|
410
406
|
}));
|
|
411
407
|
dAuth("verification code sent");
|
|
412
408
|
if (sentCode instanceof types.AuthSentCode) {
|
|
@@ -1334,4 +1330,11 @@ export class Client extends ClientAbstract {
|
|
|
1334
1330
|
async forwardMessage(from, to, messageId, params) {
|
|
1335
1331
|
return await this.forwardMessages(from, to, [messageId], params).then((v) => v[0]);
|
|
1336
1332
|
}
|
|
1333
|
+
async getMe() {
|
|
1334
|
+
const users = await this.invoke(new functions.UsersGetUsers({ id: [new types.InputUserSelf()] }));
|
|
1335
|
+
if (users.length < 1) {
|
|
1336
|
+
UNREACHABLE();
|
|
1337
|
+
}
|
|
1338
|
+
return constructUser(users[0][as](types.User));
|
|
1339
|
+
}
|
|
1337
1340
|
}
|
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.978";
|
|
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.978";
|
|
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];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function drop<T>(promise: Promise<T>): void;
|
|
2
2
|
export declare function mustPrompt(message: string): string;
|
|
3
3
|
export declare function mustPromptNumber(message: string): number;
|
|
4
|
+
export declare function mustPromptOneOf<T extends readonly string[]>(message: string, choices: T): T[number];
|
package/esm/utilities/1_misc.js
CHANGED
|
@@ -19,3 +19,10 @@ export function mustPromptNumber(message) {
|
|
|
19
19
|
}
|
|
20
20
|
return result;
|
|
21
21
|
}
|
|
22
|
+
export function mustPromptOneOf(message, choices) {
|
|
23
|
+
let result = prompt(message);
|
|
24
|
+
while (result == null || !choices.includes(result)) {
|
|
25
|
+
result = prompt(message);
|
|
26
|
+
}
|
|
27
|
+
return result;
|
|
28
|
+
}
|
package/package.json
CHANGED
|
@@ -23,7 +23,7 @@ export declare enum ParseMode {
|
|
|
23
23
|
export interface AuthorizeUserParams<S = string> {
|
|
24
24
|
phone: S | (() => MaybePromise<S>);
|
|
25
25
|
code: S | (() => MaybePromise<S>);
|
|
26
|
-
password: S | (() => MaybePromise<S>);
|
|
26
|
+
password: S | ((hint: string | null) => MaybePromise<S>);
|
|
27
27
|
}
|
|
28
28
|
export type UpdateHandler = null | ((client: Client, update: types.TypeUpdate) => MaybePromise<void>);
|
|
29
29
|
export interface ClientParams {
|
|
@@ -196,4 +196,5 @@ export declare class Client extends ClientAbstract {
|
|
|
196
196
|
[getStickerSetName](inputStickerSet: types.InputStickerSetID, hash?: number): Promise<string>;
|
|
197
197
|
forwardMessages(from: number | string, to: number | string, messageIds: number[], params?: ForwardMessagesParams): Promise<Message[]>;
|
|
198
198
|
forwardMessage(from: number | string, to: number | string, messageId: number, params?: ForwardMessagesParams): Promise<Message>;
|
|
199
|
+
getMe(): Promise<import("../types/1_user.js").User>;
|
|
199
200
|
}
|
|
@@ -51,7 +51,7 @@ 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
52
|
const _1_misc_js_1 = require("../utilities/1_misc.js");
|
|
53
53
|
const _0_utilities_js_1 = require("./0_utilities.js");
|
|
54
|
-
const
|
|
54
|
+
const _1_user_js_1 = require("../types/1_user.js");
|
|
55
55
|
const d = (0, deps_js_1.debug)("Client");
|
|
56
56
|
const dGap = (0, deps_js_1.debug)("Client/recoverUpdateGap");
|
|
57
57
|
const dGapC = (0, deps_js_1.debug)("Client/recoverChannelUpdateGap");
|
|
@@ -344,16 +344,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
344
344
|
throw new Error("apiHash not set");
|
|
345
345
|
}
|
|
346
346
|
if (typeof params === "undefined") {
|
|
347
|
-
const
|
|
348
|
-
if (
|
|
349
|
-
params =
|
|
350
|
-
phone: phoneNumberOrBotToken,
|
|
351
|
-
code: () => String((0, _1_misc_js_2.mustPromptNumber)("Enter the verification code:")),
|
|
352
|
-
password: () => (0, _1_misc_js_2.mustPrompt)("Enter the account password:"),
|
|
353
|
-
};
|
|
347
|
+
const loginType = (0, _1_misc_js_1.mustPromptOneOf)("Do you want to login as bot [b] or user [u]?", ["b", "u"]);
|
|
348
|
+
if (loginType == "b") {
|
|
349
|
+
params = (0, _1_misc_js_1.mustPrompt)("Bot token:");
|
|
354
350
|
}
|
|
355
351
|
else {
|
|
356
|
-
params =
|
|
352
|
+
params = { phone: () => (0, _1_misc_js_1.mustPrompt)("Phone number:"), code: () => (0, _1_misc_js_1.mustPrompt)("Verification code:"), password: () => (0, _1_misc_js_1.mustPrompt)(`Password:`) };
|
|
357
353
|
}
|
|
358
354
|
}
|
|
359
355
|
dAuth("authorizing with %s", typeof params === "string" ? "bot token" : params instanceof types.AuthExportedAuthorization ? "exported authorization" : "AuthorizeUserParams");
|
|
@@ -378,7 +374,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
378
374
|
const ap = await this.invoke(new functions.AccountGetPassword());
|
|
379
375
|
if (ap.currentAlgo instanceof types.PasswordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
|
|
380
376
|
try {
|
|
381
|
-
const password = typeof params.password === "string" ? params.password : await params.password();
|
|
377
|
+
const password = typeof params.password === "string" ? params.password : await params.password(ap.hint ?? null);
|
|
382
378
|
const input = await (0, _0_password_js_1.checkPassword)(password, ap);
|
|
383
379
|
await this.invoke(new functions.AuthCheckPassword({ password: input }));
|
|
384
380
|
await this.storage.setAccountType("user");
|
|
@@ -432,7 +428,7 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
432
428
|
apiId: this.apiId,
|
|
433
429
|
apiHash: this.apiHash,
|
|
434
430
|
phoneNumber,
|
|
435
|
-
settings: new types.CodeSettings(
|
|
431
|
+
settings: new types.CodeSettings(),
|
|
436
432
|
}));
|
|
437
433
|
dAuth("verification code sent");
|
|
438
434
|
if (sentCode instanceof types.AuthSentCode) {
|
|
@@ -1360,5 +1356,12 @@ class Client extends _1_client_abstract_js_1.ClientAbstract {
|
|
|
1360
1356
|
async forwardMessage(from, to, messageId, params) {
|
|
1361
1357
|
return await this.forwardMessages(from, to, [messageId], params).then((v) => v[0]);
|
|
1362
1358
|
}
|
|
1359
|
+
async getMe() {
|
|
1360
|
+
const users = await this.invoke(new functions.UsersGetUsers({ id: [new types.InputUserSelf()] }));
|
|
1361
|
+
if (users.length < 1) {
|
|
1362
|
+
(0, _0_control_js_1.UNREACHABLE)();
|
|
1363
|
+
}
|
|
1364
|
+
return (0, _1_user_js_1.constructUser)(users[0][_1_tl_object_js_1.as](types.User));
|
|
1365
|
+
}
|
|
1363
1366
|
}
|
|
1364
1367
|
exports.Client = Client;
|
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.978";
|
|
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.978";
|
|
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];
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export declare function drop<T>(promise: Promise<T>): void;
|
|
2
2
|
export declare function mustPrompt(message: string): string;
|
|
3
3
|
export declare function mustPromptNumber(message: string): number;
|
|
4
|
+
export declare function mustPromptOneOf<T extends readonly string[]>(message: string, choices: T): T[number];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.mustPromptNumber = exports.mustPrompt = exports.drop = void 0;
|
|
3
|
+
exports.mustPromptOneOf = exports.mustPromptNumber = exports.mustPrompt = exports.drop = void 0;
|
|
4
4
|
const _0_control_js_1 = require("./0_control.js");
|
|
5
5
|
function drop(promise) {
|
|
6
6
|
promise.then().catch();
|
|
@@ -25,3 +25,11 @@ function mustPromptNumber(message) {
|
|
|
25
25
|
return result;
|
|
26
26
|
}
|
|
27
27
|
exports.mustPromptNumber = mustPromptNumber;
|
|
28
|
+
function mustPromptOneOf(message, choices) {
|
|
29
|
+
let result = prompt(message);
|
|
30
|
+
while (result == null || !choices.includes(result)) {
|
|
31
|
+
result = prompt(message);
|
|
32
|
+
}
|
|
33
|
+
return result;
|
|
34
|
+
}
|
|
35
|
+
exports.mustPromptOneOf = mustPromptOneOf;
|