From 7ca4b47ba9c6b906ff72c7c5a5e0594b67085eb9 Mon Sep 17 00:00:00 2001 From: Minz Date: Mon, 26 Jan 2026 10:03:45 +0100 Subject: [PATCH] Add debug messages to receipt logic --- timers/receiptTimer.js | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/timers/receiptTimer.js b/timers/receiptTimer.js index 0116297..dec5b12 100644 --- a/timers/receiptTimer.js +++ b/timers/receiptTimer.js @@ -30,15 +30,14 @@ module.exports = { // S M T W T F S let db = await client.localDB; const channel = await client.channels.fetch(timer.data.channelId); - await channel.send(`Format date last monday ${lastMonday} Format date next monday ${nextMonday}`); - + const config = await (await db.prepare(`SELECT weekly_budget, last_date_msg_receipts FROM bot_config`).get()); const existingBudget = db.prepare(`SELECT id FROM weekly_budgets WHERE start_date = ?`).get(startDate); - - await channel.send(`\`\`\`SELECT id FROM weekly_budgets WHERE start_date = ${startDate}\`\`\` - ${JSON.stringify(existingBudget)}`); - + if (!existingBudget) { + await channel.send(`Format date last monday ${lastMonday} as startDate Format date next monday ${nextMonday} as endDate`); + await channel.send(`\`\`\`SELECT id FROM weekly_budgets WHERE start_date = ${startDate}\`\`\` + ${JSON.stringify(existingBudget)}`); console.log(`No budget found for week starting ${startDate}.`); const response = await fetch(`https://api.frankfurter.dev/v1/latest?amount=1&from=EUR&to=SEK`); @@ -76,16 +75,16 @@ module.exports = { LIMIT 1; `).get(); - await channel.send(`\`\`\`SELECT - date(last_date_msg_receipts) AS last_date, - datetime('now', 'localtime') AS current_time_full, - (date(last_date_msg_receipts) = date('now', 'localtime')) AS was_sent_today - FROM bot_config - LIMIT 1;\`\`\` - - ${JSON.stringify(debug)}`); - + if (!notification.was_sent_today) { + await channel.send(`\`\`\`SELECT + date(last_date_msg_receipts) AS last_date, + datetime('now', 'localtime') AS current_time_full, + (date(last_date_msg_receipts) = date('now', 'localtime')) AS was_sent_today + FROM bot_config + LIMIT 1;\`\`\` + + ${JSON.stringify(debug)}`); const currentDate = new Date().toLocaleDateString('en-GB', { weekday: 'long', day: '2-digit',