From d832313af997f7df4e88d3a38455a28dd4a894be Mon Sep 17 00:00:00 2001 From: ChrisChrome Date: Sun, 30 Jul 2023 22:37:27 -0600 Subject: [PATCH] Add override --- commands.json | 6 ++++++ index.js | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/commands.json b/commands.json index 1fba2da..6ff08c0 100644 --- a/commands.json +++ b/commands.json @@ -15,6 +15,12 @@ "description": "The amount to modify (can be negative)", "type": 10, "required": true + }, + { + "name": "override", + "description": "Override their coins with the amount given instead of adding to it", + "type": 5, + "required": false } ] }, diff --git a/index.js b/index.js index 28f392c..4155e2f 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ client.on("ready", async () => { // Functions -checkAndModifyPoints = async (user, amount) => { +checkAndModifyPoints = async (user, amount, override) => { // Check if the user exists, if not, add them to the database await db.get(`SELECT * FROM points WHERE id = '${user.id}'`, async (err, row) => { @@ -61,6 +61,10 @@ checkAndModifyPoints = async (user, amount) => { return amount; } if (row) { + if (override) { + await db.run(`UPDATE points SET points = ${amount} WHERE id = '${user.id}'`); + return amount; + } await db.run(`UPDATE points SET points = ${row.points + amount} WHERE id = '${user.id}'`); return row.points + amount; } @@ -143,7 +147,7 @@ client.on("interactionCreate", async interaction => { content: "You must specify an amount.", ephemeral: true }); - let outputStatus = await checkAndModifyPoints(interaction.options.getMember("user").user, interaction.options.getNumber("amount")); + let outputStatus = await checkAndModifyPoints(interaction.options.getMember("user").user, interaction.options.getNumber("amount"), interaction.options.getBoolean("override") || false); if (outputStatus !== false) { interaction.reply({ content: `Gave ${interaction.options.getMember("user").user.username} ${interaction.options.getNumber("amount")} coins.`,