diff --git a/commands/economy/work.js b/commands/economy/work.js index b2c66c9..ae4bb67 100644 --- a/commands/economy/work.js +++ b/commands/economy/work.js @@ -7,13 +7,9 @@ module.exports = { .setName("work") .setDescription("Gives you a random amount of money."), async execute(interaction) { - const interactionUserId = interaction.user.id; - - const query = await db.query("SELECT userId, lastWorkTime FROM economy WHERE userId = ?", [interactionUserId]); - + const query = await db.query("SELECT userId, lastWorkTime FROM economy WHERE userId = ?", [interaction.user.id]); const userId = query[0]?.userId || null; const lastWorkTime = query[0]?.lastWorkTime || null; //lastWorkTime is stored as UTC - // const now = new Date(); const thirtyMinutesAgoUTC = new Date(new Date().getTime() + new Date().getTimezoneOffset() * 60000 - 30 * 60000); const amount = Math.floor(Math.random() * 100); @@ -36,14 +32,15 @@ module.exports = { } else { //if it's a user's first time using this command (so it's userId is not in the database yet...) - await db.query("INSERT INTO economy (userId, balance, lastWorkTime) VALUES (?, ?, ?)", + await db.query("INSERT INTO economy (userName, userId, balance, firstTransactionId, lastWorkTime) VALUES (?, ?, ?, ?, ?)", [ - interactionUserId, + interaction.user.username, + interaction.user.id, amount, new Date().toISOString().slice(0, 19).replace('T', ' '), + new Date().toISOString().slice(0, 19).replace('T', ' '), ] ); - var replyContent = `You've worked and succesfully earned $**${amount}** dollars.`; } diff --git a/index.js b/index.js index d997a9b..ea235dd 100755 --- a/index.js +++ b/index.js @@ -92,17 +92,17 @@ function setActivity() { client.on("ready", () => { setActivity(); -}) +}); //re-announces the bot's activity in every 20 minutes (in case of an internet outage or something) setInterval(setActivity, 20 * 60 * 1000); //closes connection to the database when closing the application -client.on("SIGINT", () => { +process.on("SIGINT", () => { console.log("Closing MariaDB database pool connection(s)..."); db.end(); - client.exit(0); -}) + process.exit(0); +}); //logs in with given token client.login(token); \ No newline at end of file