Fix receipts bugs: budget queries, undo/transfer desync, timer spam

This commit is contained in:
2026-08-09 23:19:02 +02:00
parent f9dd88b9b8
commit cd5b076d65
5 changed files with 59 additions and 63 deletions

View File

@@ -1,4 +1,5 @@
const { Events, channelLink, discordSort } = require('discord.js');
const { HOUSEHOLD_IDS } = require('../core/constants.js');
module.exports = {
name: Events.MessageCreate,
@@ -8,8 +9,8 @@ module.exports = {
const receiptsChannelId = process.env.NODE_ENV === 'development' ? '1468186493251227658' : '1462060674766344370';
if(message.channel.id === receiptsChannelId) {
const CURRENCY_MAP = {
"222457277708369928": "EUR", // Minz
"372115788498468864": "SEK", // Miffy
[HOUSEHOLD_IDS.MINZ]: "EUR",
[HOUSEHOLD_IDS.MIFFY]: "SEK",
};
let reply = "";
@@ -25,12 +26,17 @@ module.exports = {
LIMIT 1
`).get();
if (!currentBudget) {
await message.reply("No active budget period found for this week yet - try again in a moment.");
return;
}
if (message.content === "fuck") {
let lastSpend = db.prepare(`
SELECT id, amount, message_raw, created_at
FROM grocery_spendings
WHERE discord_id = ? AND budget_id = ?
ORDER BY created_at DESC, id DESC
SELECT id, amount, message_raw, created_at
FROM grocery_spendings
WHERE discord_id = ? AND budget_id = ? AND is_transfer = 0
ORDER BY created_at DESC, id DESC
LIMIT 1
`).get(authorId, currentBudget.id);
if (lastSpend) {
@@ -45,7 +51,7 @@ module.exports = {
const transferRegex = /^transfer\s+(\d+(?:[.,]\d+)?)$/i;
const transferMatch = message.content.match(transferRegex);
if (transferMatch) {
if (authorId !== "222457277708369928" && authorId !== "372115788498468864") {
if (authorId !== HOUSEHOLD_IDS.MINZ && authorId !== HOUSEHOLD_IDS.MIFFY) {
await message.reply("Only Minz and Miffy can use the transfer command.");
return;
}
@@ -53,11 +59,11 @@ module.exports = {
let amount = parseFloat(transferMatch[1].replace(',', '.'));
const targetId = authorId === "222457277708369928" ? "372115788498468864" : "222457277708369928";
const targetId = authorId === HOUSEHOLD_IDS.MINZ ? HOUSEHOLD_IDS.MIFFY : HOUSEHOLD_IDS.MINZ;
const insertSpending = db.prepare(`
INSERT INTO grocery_spendings (discord_id, message_id, message_raw, amount, budget_id)
VALUES (?, ?, ?, ?, ?)
INSERT INTO grocery_spendings (discord_id, message_id, message_raw, amount, budget_id, is_transfer)
VALUES (?, ?, ?, ?, ?, 1)
`);
const runTransfer = db.transaction(() => {
@@ -67,18 +73,17 @@ module.exports = {
runTransfer();
const targetName = authorId === "222457277708369928" ? "Miffy" : "Minz";
const targetName = authorId === HOUSEHOLD_IDS.MINZ ? "Miffy" : "Minz";
await message.reply(`Transferred ${amount.toFixed(2)}€ to ${targetName}.`);
return;
}
let matches = [];
let lines = message.content.split("\n");
let additionalSpent = 0.0;
lines.forEach(line => {0
lines.forEach(line => {
if (line.startsWith('-')) {
console.log(`Matching on line ${line}`);
const regex = /-(?=[0-9])([0-9]*[.,]?[0-9]*)/m;
const regex = /-\s*([0-9]+(?:[.,][0-9]+)?)/;
let match = regex.exec(line)
console.log(match);
if (match) {