From 7e7356af1c858450591402618c69525e188d9a44 Mon Sep 17 00:00:00 2001 From: oxpoe Date: Fri, 9 Oct 2026 10:39:46 +0700 Subject: [PATCH] feat(telegram): perintah /offline /aktif /pendapatan (+ tombol) --- services/telegramBot.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/services/telegramBot.js b/services/telegramBot.js index 57f7fd3..7cdd472 100644 --- a/services/telegramBot.js +++ b/services/telegramBot.js @@ -298,6 +298,7 @@ function initTelegram() { [{ text: 'šŸŽ« Voucher', callback_data: 'menu_vouch' }, { text: 'šŸ’° Tagihan', callback_data: 'menu_bill' }], [{ text: 'āš™ļø MikroTik Status', callback_data: 'menu_mt' }], [{ text: 'šŸ–„ļø Sistem', callback_data: 'menu_sys' }, { text: 'šŸ’° Tunggakan', callback_data: 'menu_arrears' }], + [{ text: 'šŸ’° Pendapatan', callback_data: 'menu_pendapatan' }], [{ text: 'šŸŽ« Tiket', callback_data: 'menu_tiket' }, { text: 'šŸ“” OLT', callback_data: 'menu_olt' }, { text: 'šŸ“¶ Trafik', callback_data: 'menu_trafik' }], [{ text: 'šŸ”„ Refresh', callback_data: 'menu_main' }] ] @@ -425,6 +426,10 @@ function initTelegram() { catch (e) { bot.sendMessage(chatId, 'Gagal: ' + e.message); } } + else if (data === 'menu_pendapatan') { + try { bot.sendMessage(chatId, tgPendapatanText(), { parse_mode: 'Markdown', reply_markup: { inline_keyboard: [[{ text: 'ā¬…ļø Kembali', callback_data: 'menu_main' }]] } }); } + catch (e) { bot.sendMessage(chatId, 'Gagal: ' + e.message); } + } else if (data === 'mt_resource') { try { const res = await mikrotikSvc.getSystemResource(); @@ -789,6 +794,34 @@ function initTelegram() { catch (e) { bot.sendMessage(msg.chat.id, 'Gagal: ' + e.message); } }); + bot.onText(/\/(offline|pppoeoffline|pppoe-offline)/i, async (msg) => { + if (!isAdmin(msg)) return; + try { const snap = await loadPppoeSnapshot(); bot.sendMessage(msg.chat.id, buildOfflineTelegramText(snap)); } + catch (e) { bot.sendMessage(msg.chat.id, 'Gagal: ' + e.message); } + }); + bot.onText(/\/(aktif|pppoeonline|pppoe-online)/i, async (msg) => { + if (!isAdmin(msg)) return; + try { + const snap = await loadPppoeSnapshot(); + const active = snap.active || []; + let t = `🟢 *PPPoE ONLINE*\n\nTotal Aktif: *${active.length}*\n`; + active.slice(0, 20).forEach((s, i) => { t += `${i + 1}. ${(s && (s.name || s.user)) || '-'}\n`; }); + if (active.length > 20) t += `\n_...dan ${active.length - 20} lainnya._`; + bot.sendMessage(msg.chat.id, t, { parse_mode: 'Markdown', reply_markup: backBtn }); + } catch (e) { bot.sendMessage(msg.chat.id, 'Gagal: ' + e.message); } + }); + function tgPendapatanText() { + const today = Number(billingSvc.getTodayRevenue() || 0); + const stats = billingSvc.getDashboardStats() || {}; + const month = Number(stats.thisMonth || 0); + return `šŸ’° *PENDAPATAN*\n\nšŸ“… Hari ini: *Rp ${today.toLocaleString('id-ID')}*\nšŸ—“ļø Bulan ini: *Rp ${month.toLocaleString('id-ID')}*\nā³ Belum dibayar: *${stats.unpaidCount || 0} tagihan*\n`; + } + bot.onText(/\/(pendapatan|kas|revenue)/i, async (msg) => { + if (!isAdmin(msg)) return; + try { bot.sendMessage(msg.chat.id, tgPendapatanText(), { parse_mode: 'Markdown', reply_markup: backBtn }); } + catch (e) { bot.sendMessage(msg.chat.id, 'Gagal: ' + e.message); } + }); + bot.onText(/\/ringkasan/i, async (msg) => { if (!isAdmin(msg)) return; const chatId = msg.chat.id;