chore: deprecated .run method

This commit is contained in:
alina sireneva
2024-07-26 06:46:18 +03:00
parent dd87587708
commit 39199f9a5e
10 changed files with 20 additions and 25 deletions

View File

@@ -39,9 +39,8 @@ dp.onNewMessage(filters.chat('private'), async (msg) => {
await msg.replyText('hiiii from mtcute! 🌸')
})
tg.run({ /* optional params */ }, async (self) => {
console.log(`✨ logged in as ${self.displayName}`)
})
const self = await tg.start({ /* optional params */ }
console.log(`✨ logged in as ${self.displayName}`)
```
mtcute is a modern, performant and *✨ cute ✨* [mtproto](https://mtcute.dev/guide/intro/mtproto-vs-bot-api.html) library and bot framework,

View File

@@ -19,7 +19,6 @@ const tg = new TelegramClient({
storage: 'my-account'
})
tg.run(async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
const self = await tg.start()
console.log(`✨ logged in as ${self.displayName}`)
```

View File

@@ -76,10 +76,10 @@ export class TelegramClient extends TelegramClientBase {
/**
* Tiny wrapper over Node `readline` package
* for simpler user input for `.run()` method.
* for simpler user input for `.start()` method.
*
* Associated `readline` interface is closed
* after `run()` returns, or with the client.
* after `start()` returns, or with the client.
*
* @param text Text of the question
*/

View File

@@ -39,11 +39,10 @@ const tg = new TelegramClient({
// ... same options as above
})
tg.run({
const self = await tg.start({
phone: '+1234567890',
code: () => prompt('Enter the code:'),
password: 'my-password',
}, async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
console.log(`✨ logged in as ${self.displayName}`)
```

View File

@@ -672,6 +672,7 @@ export interface TelegramClient extends ITelegramClient {
*
* @param params Parameters to be passed to {@link start}
* @param then Function to be called after {@link start} returns
* @deprecated This method provides no real value over {@link start}, please use it instead
*/
run(params: Parameters<typeof start>[1], then?: (user: User) => void | Promise<void>): void
/**

View File

@@ -12,6 +12,7 @@ import { start } from './start.js'
*
* @param params Parameters to be passed to {@link start}
* @param then Function to be called after {@link start} returns
* @deprecated This method provides no real value over {@link start}, please use it instead
*/
export function run(
client: ITelegramClient,

View File

@@ -19,7 +19,6 @@ const tg = new TelegramClient({
storage: 'my-account'
})
tg.run(async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
const self = await tg.start()
console.log(`✨ logged in as ${self.displayName}`)
```

View File

@@ -21,7 +21,6 @@ const tg = new TelegramClient({
storage: 'my-account'
})
tg.run(async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
const self = await tg.start()
console.log(`✨ logged in as ${self.displayName}`)
```

View File

@@ -90,10 +90,10 @@ export class TelegramClient extends TelegramClientBase {
/**
* Tiny wrapper over Node `readline` package
* for simpler user input for `.run()` method.
* for simpler user input for `.start()` method.
*
* Associated `readline` interface is closed
* after `run()` returns, or with the client.
* after `start()` returns, or with the client.
*
* @param text Text of the question
*/

View File

@@ -19,9 +19,8 @@ const tg = new TelegramClient({
storage: 'my-account'
})
tg.run(async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
const self = await tg.start()
console.log(`✨ logged in as ${self.displayName}`)
```
## Usage with workers
@@ -47,7 +46,6 @@ const worker = new Worker(new URL('./worker.ts', import.meta.url), { type: 'modu
const port = new TelegramWorkerPort({ worker })
const tg = new TelegramClient({ client: port })
tg.run({}, async (user) => {
console.log(`✨ logged in as ${user.displayName}`)
})
const self = await tg.start()
console.log(`✨ logged in as ${user.displayName}`)
```