WIP: Transfer command
This commit is contained in:
@@ -26,7 +26,6 @@ module.exports = {
|
||||
`).get();
|
||||
|
||||
if (message.content === "fuck") {
|
||||
|
||||
let lastSpend = db.prepare(`
|
||||
SELECT id, amount, message_raw, created_at
|
||||
FROM grocery_spendings
|
||||
@@ -43,6 +42,36 @@ module.exports = {
|
||||
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 lines = message.content.split("\n");
|
||||
let additionalSpent = 0.0;
|
||||
|
||||
Reference in New Issue
Block a user