WIP: Transfer command

This commit is contained in:
2026-03-28 14:13:18 +01:00
parent d3349231f3
commit 728b99b1f9

View File

@@ -26,7 +26,6 @@ module.exports = {
`).get(); `).get();
if (message.content === "fuck") { if (message.content === "fuck") {
let lastSpend = db.prepare(` let lastSpend = db.prepare(`
SELECT id, amount, message_raw, created_at SELECT id, amount, message_raw, created_at
FROM grocery_spendings FROM grocery_spendings
@@ -43,6 +42,36 @@ module.exports = {
return; return;
} }
const transferRegex = /^transfer\s+(\d+(?:[.,]\d+)?)$/i;
const transferMatch = message.content.match(transferRegex);
if (transferMatch) {
if (authorId !== "222457277708369928" && authorId !== "372115788498468864") {
await message.reply("Only Minz and Miffy can use the transfer command.");
return;
}
let amount = parseFloat(transferMatch[1].replace(',', '.'));
const targetId = authorId === "222457277708369928" ? "372115788498468864" : "222457277708369928";
const insertSpending = db.prepare(`
INSERT INTO grocery_spendings (discord_id, message_id, message_raw, amount, budget_id)
VALUES (?, ?, ?, ?, ?)
`);
const runTransfer = db.transaction(() => {
insertSpending.run(authorId, message.id, message.content, amount, currentBudget.id);
insertSpending.run(targetId, message.id, message.content, -amount, currentBudget.id);
});
runTransfer();
const targetName = authorId === "222457277708369928" ? "Miffy" : "Minz";
await message.reply(`Transferred ${amount.toFixed(2)} ${currency} to ${targetName}.`);
return;
}
let matches = []; let matches = [];
let lines = message.content.split("\n"); let lines = message.content.split("\n");
let additionalSpent = 0.0; let additionalSpent = 0.0;