From 56d4c5e4e7288a0346879bd50f4a8b435f152f85 Mon Sep 17 00:00:00 2001 From: pseudoyu Date: Sat, 2 Nov 2024 19:38:16 +0700 Subject: [PATCH] refactor(route/telegram): use log instead of console to resolve eslint issue --- .../telegram/scripts/get-telegram-session.mjs | 13 ++++++++----- pnpm-lock.yaml | 4 ++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/routes/telegram/scripts/get-telegram-session.mjs b/lib/routes/telegram/scripts/get-telegram-session.mjs index a819073d66fe9d..4564411001d0b7 100644 --- a/lib/routes/telegram/scripts/get-telegram-session.mjs +++ b/lib/routes/telegram/scripts/get-telegram-session.mjs @@ -1,6 +1,9 @@ import { TelegramClient } from 'telegram'; import { StringSession } from 'telegram/sessions/index.js'; import readline from 'readline'; +import debug from 'debug'; + +const log = debug('telegram:session'); function userInput(question) { const rl = readline.createInterface({ @@ -16,7 +19,7 @@ function userInput(question) { } async function getSessionString() { - const apiId = parseInt(await userInput('Please enter your API ID: ')); + const apiId = Number.parseInt(await userInput('Please enter your API ID: ')); const apiHash = await userInput('Please enter your API Hash: '); const stringSession = new StringSession(''); const client = new TelegramClient(stringSession, apiId, apiHash, { @@ -26,16 +29,16 @@ async function getSessionString() { phoneNumber: async () => await userInput('Please enter your phone number: '), password: async () => await userInput('Please enter your password: '), phoneCode: async () => await userInput('Please enter the code you received: '), - onError: (err) => console.log(err), + onError: (err) => log('Error:', err), }); - console.log('You are now connected.'); + log('You are now connected.'); const sessionString = client.session.save(); + log('Your session string is:', sessionString); - console.log('Your session string is:', sessionString); await client.disconnect(); return sessionString; } // Run the function -getSessionString().catch(console.error); +getSessionString().catch((error) => log('Error:', error)); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d50a5caf6f9ab6..362fbe164f5424 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8819,7 +8819,7 @@ snapshots: extract-zip@2.0.1: dependencies: - debug: 4.3.4 + debug: 4.3.7 get-stream: 5.2.0 yauzl: 2.10.0 optionalDependencies: @@ -10536,7 +10536,7 @@ snapshots: proxy-agent@6.4.0: dependencies: agent-base: 7.1.1 - debug: 4.3.4 + debug: 4.3.7 http-proxy-agent: 7.0.2 https-proxy-agent: 7.0.5 lru-cache: 7.18.3