fix(client): use 6-digit codes for test phone numbers
This commit is contained in:
parent
b28e85ca0a
commit
58f4356d58
1 changed files with 8 additions and 9 deletions
|
@ -12,7 +12,7 @@ import { TelegramClient } from '../../client'
|
||||||
* @param params Additional parameters
|
* @param params Additional parameters
|
||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export async function startTest (
|
export async function startTest(
|
||||||
this: TelegramClient,
|
this: TelegramClient,
|
||||||
params?: {
|
params?: {
|
||||||
/**
|
/**
|
||||||
|
@ -52,15 +52,14 @@ export async function startTest (
|
||||||
* If true, TOS will not be displayed and `tosCallback` will not be called.
|
* If true, TOS will not be displayed and `tosCallback` will not be called.
|
||||||
*/
|
*/
|
||||||
acceptTos?: boolean
|
acceptTos?: boolean
|
||||||
},
|
}
|
||||||
): Promise<User> {
|
): Promise<User> {
|
||||||
if (!params) params = {}
|
if (!params) params = {}
|
||||||
|
|
||||||
if (params.logout)
|
if (params.logout)
|
||||||
try {
|
try {
|
||||||
await this.logOut()
|
await this.logOut()
|
||||||
} catch (e) {
|
} catch (e) {}
|
||||||
}
|
|
||||||
|
|
||||||
const availableDcs = await this.call({
|
const availableDcs = await this.call({
|
||||||
_: 'help.getConfig',
|
_: 'help.getConfig',
|
||||||
|
@ -70,15 +69,15 @@ export async function startTest (
|
||||||
if (phone) {
|
if (phone) {
|
||||||
if (!phone.match(/^99966\d{5}/))
|
if (!phone.match(/^99966\d{5}/))
|
||||||
throw new MtCuteArgumentError(
|
throw new MtCuteArgumentError(
|
||||||
`${phone} is an invalid test phone number`,
|
`${phone} is an invalid test phone number`
|
||||||
)
|
)
|
||||||
const id = parseInt(phone[5])
|
const id = parseInt(phone[5])
|
||||||
if (!availableDcs.find(dc => dc.id === id))
|
if (!availableDcs.find((dc) => dc.id === id))
|
||||||
throw new MtCuteArgumentError(`${phone} has invalid DC ID (${id})`)
|
throw new MtCuteArgumentError(`${phone} has invalid DC ID (${id})`)
|
||||||
} else {
|
} else {
|
||||||
let dcId = this._primaryDc.id
|
let dcId = this._primaryDc.id
|
||||||
if (params.dcId) {
|
if (params.dcId) {
|
||||||
if (!availableDcs.find(dc => dc.id === params!.dcId))
|
if (!availableDcs.find((dc) => dc.id === params!.dcId))
|
||||||
throw new MtCuteArgumentError(`DC ID is invalid (${dcId})`)
|
throw new MtCuteArgumentError(`DC ID is invalid (${dcId})`)
|
||||||
dcId = params.dcId
|
dcId = params.dcId
|
||||||
}
|
}
|
||||||
|
@ -90,7 +89,7 @@ export async function startTest (
|
||||||
}
|
}
|
||||||
|
|
||||||
// such a smart solution, much wow
|
// such a smart solution, much wow
|
||||||
const code = phone[5] + phone[5] + phone[5] + phone[5] + phone[5]
|
const code = phone[5] + phone[5] + phone[5] + phone[5] + phone[5] + phone[5]
|
||||||
|
|
||||||
return this.start({
|
return this.start({
|
||||||
phone,
|
phone,
|
||||||
|
@ -98,6 +97,6 @@ export async function startTest (
|
||||||
firstName: params.firstName,
|
firstName: params.firstName,
|
||||||
lastName: params.lastName,
|
lastName: params.lastName,
|
||||||
acceptTos: params.acceptTos,
|
acceptTos: params.acceptTos,
|
||||||
codeSentCallback: () => {}
|
codeSentCallback: () => {},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue