Add override
This commit is contained in:
parent
511e3c319d
commit
d832313af9
|
@ -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
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
8
index.js
8
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.`,
|
||||
|
|
Loading…
Reference in a new issue