chore(telegram): replace debug with winston
This commit is contained in:
@@ -1,14 +1,12 @@
|
||||
import { TelegramClient } from 'telegram';
|
||||
import { StringSession } from 'telegram/sessions/index.js';
|
||||
import readline from 'readline';
|
||||
import debug from 'debug';
|
||||
|
||||
const log = debug('telegram:session');
|
||||
import winston from 'winston';
|
||||
|
||||
function userInput(question) {
|
||||
const rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout
|
||||
output: process.stdout,
|
||||
});
|
||||
return new Promise((resolve) => {
|
||||
rl.question(question, (answer) => {
|
||||
@@ -18,6 +16,15 @@ function userInput(question) {
|
||||
});
|
||||
}
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: 'info',
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.printf(({ level, message, timestamp }) => `${timestamp} ${level}: ${message}`)
|
||||
),
|
||||
transports: [new winston.transports.Console()],
|
||||
});
|
||||
|
||||
async function getSessionString() {
|
||||
const apiId = Number.parseInt(await userInput('Please enter your API ID: '));
|
||||
const apiHash = await userInput('Please enter your API Hash: ');
|
||||
@@ -29,16 +36,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) => log('Error:', err),
|
||||
onError: (err) => logger.error(err),
|
||||
});
|
||||
|
||||
log('You are now connected.');
|
||||
logger.info('You are now connected.');
|
||||
const sessionString = client.session.save();
|
||||
log('Your session string is:', sessionString);
|
||||
logger.info(`Your session string is: ${sessionString}`);
|
||||
|
||||
await client.disconnect();
|
||||
return sessionString;
|
||||
}
|
||||
|
||||
// Run the function
|
||||
getSessionString().catch((error) => log('Error:', error));
|
||||
getSessionString().catch((error) => logger.error(error));
|
||||
|
||||
Reference in New Issue
Block a user