bot.callbackQuery(/^credit_confirm_(\d+)_(\d+)$/, async (ctx) => { const chatInstance = ctx.update.callback_query.chat_instance; const amount = parseInt(ctx.match[1], 10); const targetUserId = parseInt(ctx.match[2], 10); const userId = ctx.from.id; const firstName = ctx.from.first_name; if (userId !== targetUserId) { return ctx.answerCallbackQuery({ text: "Это не твой кредит! Создай свой запрос.", show_alert: true }); } if (!chatInstance) return ctx.answerCallbackQuery({ text: "Error: No chat instance." }); const db = getDb(); const user = getChatUser(db, chatInstance, userId, firstName); if (!user.credit) user.credit = 0; if (!user.credit_taken_today) user.credit_taken_today = 0; const info = getCreditInfo(user); if (info.taken + amount > 50) { saveDb(db); return ctx.answerCallbackQuery({ text: `Лимит превышен! Ты уже взял ${info.taken} см сегодня. Остаток: ${50 - info.taken} см.`, show_alert: true }); } user.size += amount; user.credit += amount; user.credit_taken_today = (user.credit_taken_today || 0) + amount; user.credit_last_reset = user.credit_last_reset || Date.now(); saveDb(db); try { await ctx.editMessageText( `🏦 *${user.name}* взял кредит!\n` + `💰 Сумма: *${amount} см*\n` + `📉 Долг: *${user.credit} см*\n` + `📏 Размер сейчас: *${user.size} см*\n` + `⚠️ _Вернуть придется с процентами!_`, { parse_mode: "Markdown" } ); } catch (e) { console.error(e); } await ctx.answerCallbackQuery({ text: `Кредит ${amount} см выдан!` }); });