improved logging

This commit is contained in:
Dmitry Anderson 2024-10-28 19:00:03 +01:00
parent 0084abc4b8
commit af1c0253bf
2 changed files with 14 additions and 5 deletions

View File

@ -44,7 +44,6 @@ const captchaPassed = async (ctx: Ctx, db: Kysely<Database>, 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<Database>, 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
}

View File

@ -35,16 +35,25 @@ export const init = (bot: Bot<Ctx>, db: Kysely<Database>, 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<Ctx>, db: Kysely<Database>, 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)