From af1c0253bf83b5b9bb251c0f0e7bb1a4376ac4ca Mon Sep 17 00:00:00 2001 From: Dmitry Anderson <4nd3r5z0n@gmail.com> Date: Mon, 28 Oct 2024 19:00:03 +0100 Subject: [PATCH] improved logging --- bot/normal_mode/captcha.ts | 3 +-- bot/normal_mode/init.ts | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/bot/normal_mode/captcha.ts b/bot/normal_mode/captcha.ts index 864eb28..bc122b9 100644 --- a/bot/normal_mode/captcha.ts +++ b/bot/normal_mode/captcha.ts @@ -44,7 +44,6 @@ const captchaPassed = async (ctx: Ctx, db: Kysely, cfg: BotConfig) => ctx.chatId, ctx.session.captcha_data.message_id ) } - ctx.session.captcha_data = undefined const linkValidUntil = new Date() linkValidUntil.setHours(linkValidUntil.getHours() + 12) @@ -65,9 +64,9 @@ const captchaPassed = async (ctx: Ctx, db: Kysely, cfg: BotConfig) => }).execute() }) + ctx.session.captcha_data = undefined await ctx.reply(ctx.t("captcha-passed", { invite_link: link.invite_link })) - ctx.session.captcha_data = undefined } diff --git a/bot/normal_mode/init.ts b/bot/normal_mode/init.ts index 3147c74..5946295 100644 --- a/bot/normal_mode/init.ts +++ b/bot/normal_mode/init.ts @@ -35,16 +35,25 @@ export const init = (bot: Bot, db: Kysely, cfg: CompiledConfig) = const { botCfg } = cfg bot.on('message', async (ctx, next) => { - if (ctx.from?.is_bot) return - console.log(`Chat ID: ${ctx.msg.chat.id} From: ${ctx.from.id} Message: ${ctx.msg.text}`) + if (!ctx.from || ctx.from.is_bot) return + + console.log('=======================================') + console.log(`New message: CID: ${ctx.msg.chat.id} `+ + `From: ${ctx.from.first_name} ${ctx.from.last_name} `+ + `UID: ${ctx.from.id} Locale: ${ctx.from.language_code}`) + console.log(ctx.msg.text) + console.log() ctx.i18n.useLocale(ctx.from.language_code || DEFAULT_LOCALE) await next() }) bot.on('message:text', async (ctx, next) => { if (ctx.chat.id === botCfg.chat_id) { - await checkUser(ctx, db, botCfg, true) + console.log("Message was sent into the mic chat") + const userInfo = await checkUser(ctx, db, botCfg, true) + console.log("User Info: ", userInfo) } else if (ctx.message.chat.type == "private" && ctx.session.captcha_data) { + console.log("Handling message as captcha solution") await checkCaptchaSolution(ctx, db, botCfg) } else { await next() @@ -53,6 +62,7 @@ export const init = (bot: Bot, db: Kysely, cfg: CompiledConfig) = bot.command('start', async ctx => { const userInfo = await checkUserOnStart(ctx, db) + console.log("User clicked start. User Info: ", userInfo) if (userInfo.isBlocked || userInfo.isTimeout) return // TODO: if (userInfo.isNewUser) { /* Some hello message? */ } await initUserCaptcha(ctx, db, userInfo, botCfg)