From 9aec92b274bae64ea078fc04540398713e7f7928 Mon Sep 17 00:00:00 2001 From: Christopher Thai Date: Sun, 3 Nov 2024 12:59:21 -0800 Subject: [PATCH] Fixed math command + other minor errors --- src/commands/commandList/battle/crate.js | 2 +- src/commands/commandList/utils/mathWorker.js | 3 ++- src/commands/commandList/zoo/lootbox.js | 2 +- src/commands/commandList/zoo/upgrade.js | 2 +- utils/registerAppCommands.js | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/commands/commandList/battle/crate.js b/src/commands/commandList/battle/crate.js index e3eff083a..c7853c608 100644 --- a/src/commands/commandList/battle/crate.js +++ b/src/commands/commandList/battle/crate.js @@ -56,7 +56,7 @@ module.exports = new CommandInterface({ } else if (p.args.length > 0 && p.args[0].toLowerCase() == 'all') { let sql = `SELECT boxcount FROM crate INNER JOIN user ON crate.uid = user.uid WHERE id = ${p.msg.author.id};`; let result = await p.query(sql); - if (!result || result[0].boxcount <= 0) { + if (!result[0] || result[0].boxcount <= 0) { p.errorMsg(", you don't have any more weapon crates!"); return; } diff --git a/src/commands/commandList/utils/mathWorker.js b/src/commands/commandList/utils/mathWorker.js index b796ae3b6..e5bfaef66 100644 --- a/src/commands/commandList/utils/mathWorker.js +++ b/src/commands/commandList/utils/mathWorker.js @@ -37,6 +37,7 @@ function compute(expression) { return limitedEvaluate(expression); } -if (process.send) { +// Not a child process if registering app commands, it will fail +if (!process.env.REGITER_COMMANDS) { workerpool.worker({ compute: compute }); } diff --git a/src/commands/commandList/zoo/lootbox.js b/src/commands/commandList/zoo/lootbox.js index f933c51b9..96a114e14 100644 --- a/src/commands/commandList/zoo/lootbox.js +++ b/src/commands/commandList/zoo/lootbox.js @@ -63,7 +63,7 @@ module.exports = new CommandInterface({ ) { let sql = `SELECT boxcount FROM lootbox WHERE id = ${this.msg.author.id};`; let result = await this.query(sql); - if (!result || result[0].boxcount <= 0) { + if (!result[0] || result[0].boxcount <= 0) { this.errorMsg(", you don't have any more lootboxes!"); return; } diff --git a/src/commands/commandList/zoo/upgrade.js b/src/commands/commandList/zoo/upgrade.js index 9c3252bd2..8599a0e30 100644 --- a/src/commands/commandList/zoo/upgrade.js +++ b/src/commands/commandList/zoo/upgrade.js @@ -70,7 +70,7 @@ module.exports = new CommandInterface({ all = true; // owo upg duration lvl - } else if ((args[1] && 'lvl' == args[1].toLowerCase()) || 'level' == args[1].toLowerCase()) { + } else if (['lvl', 'level'].includes(args[1]?.toLowerCase())) { if (args[0]) { trait = traits[args[0].toLowerCase()]; } diff --git a/utils/registerAppCommands.js b/utils/registerAppCommands.js index 3de269fbf..429a67f36 100644 --- a/utils/registerAppCommands.js +++ b/utils/registerAppCommands.js @@ -7,6 +7,7 @@ // Run this file to update all application commands require('dotenv').config(); +process.env['REGITER_COMMANDS'] = true; const axios = require('axios'); const requireDir = require('require-dir'); const dir = requireDir('../src/commands/commandList', { recurse: true }); @@ -14,7 +15,7 @@ const CommandInterface = require('../src/commands/CommandInterface.js'); const url = `https://discord.com/api/v8/applications/${process.env.CLIENT_ID}/commands`; const headers = { - 'Authorization': `Bot ${process.env.CLIENT_SECRET}`, + 'Authorization': `Bot ${process.env.BOT_TOKEN}`, }; const newCommands = {};