diff --git a/api/routes/estimate.js b/api/routes/estimate.js index 0c71187..a303ae6 100644 --- a/api/routes/estimate.js +++ b/api/routes/estimate.js @@ -138,20 +138,24 @@ export const get = async (req, res) => { const combined = req.query.q; if (!combined || combined.replace(" ", "").length == 0) - return res.status(400).json({ error: "Missing query." }); + return res.status(400).json({ error: "missing-query" }); let entryFound = false; let estimatedPrice = 0; let subtable, closestInTable; - let gameValue = 0; + let gameValue = -1; let returnKeyWord = ""; combined.split(" ").forEach((arg) => { - if (!isNaN(parseInt(arg)) && !gameValue) { + if (!isNaN(parseInt(arg)) && gameValue == -1) { gameValue = parseInt(arg); } }); + if (gameValue == -1) { + return res.status(400).json({ error: "gameValue-not-found" }); + } + priceTable.forEach((price, idx) => { if (price.regex.test(combined) && !entryFound) { entryFound = true; @@ -183,8 +187,5 @@ export const get = async (req, res) => { closestInTable, }); } - } else - return res - .status(400) - .json({ error: "Query could not be matched with anything." }); + } else return res.status(400).json({ error: "entry-not-found" }); }; diff --git a/bot/commands/bonus.js b/bot/commands/bonus.js index a3f789f..32c4296 100644 --- a/bot/commands/bonus.js +++ b/bot/commands/bonus.js @@ -5,6 +5,7 @@ exports.usage = "CLIENT_PREFIX:bonus [inf optional extra numbers]"; exports.example = "CLIENT_PREFIX:bonus 100 100"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { let is1nan = false; if (!args[0]) diff --git a/bot/commands/cat.js b/bot/commands/cat.js index a9547ae..02469fa 100644 --- a/bot/commands/cat.js +++ b/bot/commands/cat.js @@ -3,6 +3,7 @@ exports.description = ":cat: Calculates boost for cat."; exports.usage = "CLIENT_PREFIX:cat "; exports.example = "CLIENT_PREFIX:cat 80 120"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { if (!args[0] || !args[1]) return message.channel.send( diff --git a/bot/commands/cb.js b/bot/commands/cb.js index e53d672..db31ab2 100644 --- a/bot/commands/cb.js +++ b/bot/commands/cb.js @@ -5,6 +5,7 @@ exports.description = exports.usage = "CLIENT_PREFIX:cb [projectile speed]"; exports.example = "CLIENT_PREFIX:cb 10000 250 10000"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { if (!args[0] || !args[1]) return message.channel.send( diff --git a/bot/commands/est.js b/bot/commands/est.js index 382e112..6d2282a 100644 --- a/bot/commands/est.js +++ b/bot/commands/est.js @@ -1,8 +1,8 @@ +const est = require("./estimate"); exports.name = "est"; -exports.description = ":money_with_wings: Alias for estimate."; -exports.usage = "alias"; -exports.example = "alias"; -exports.hidden = true; -exports.run = async (client, message, args) => { - require("./estimate").run(client, message, args); -}; +exports.description = est.description; +exports.usage = est.usage; +exports.example = est.usage; +exports.hidden = false; +exports.isAlias = true; +exports.run = est.run; diff --git a/bot/commands/estimate.js b/bot/commands/estimate.js index 5fbaeb8..191f0f4 100644 --- a/bot/commands/estimate.js +++ b/bot/commands/estimate.js @@ -5,8 +5,9 @@ exports.description = exports.usage = "CLIENT_PREFIX:estimate [summary of item you want the price of]"; exports.example = - "CLIENT_PREFIX:estimate 1600 ab2\nCLIENT_PREFIX:estimate 1100 thp\nCLIENT_PREFIX:estimate 2400 app builder staff\n(you can also include `showtable` anywhere to show raw price data)\n(always put number first, do not put conflicting data to avoid confusion)"; + "CLIENT_PREFIX:estimate 1600 ab2\nCLIENT_PREFIX:estimate 1100 thp\nCLIENT_PREFIX:estimate 2400 app builder staff\nCLIENT_PREFIX:estimate 2200 app builder piece\nCLIENT_PREFIX:estimate 2200 app armor\n(you can also include `showtable` anywhere to show raw price data)\n(always put number first, do not put conflicting data to avoid confusion)"; exports.hidden = false; +exports.isAlias = false; exports.run = async (client, message, args) => { if (!args[0]) { return fetch(client.sharedEndpoint + "estimate" + "?getPriceTable=true") @@ -22,6 +23,11 @@ exports.run = async (client, message, args) => { } const combined = args.join(" "); let showtable = combined.includes("showtable"); + if (combined.startsWith("help")) { + require("./help").run(client, message, ["estimate"]); + return; + } + fetch( client.sharedEndpoint + "estimate" + @@ -31,7 +37,17 @@ exports.run = async (client, message, args) => { .then((d) => d.json()) .then((data) => { if (data.error) { - return message.channel.send(data.error); + if (data.error == "entry-not-found") + return message.channel.send( + "Your query couldn't be matched with anything, please refine your query or reffer to `CLIENT_PREFIX:help estimate`. You can also use `CLIENT_PREFIX:estimate` to see all available price tables for more information.".replaceAll( + "CLIENT_PREFIX:", + client.prefix + ) + ); + if (data.error == "") + return message.channel.send( + "API query is somehow empty, but did not error for `entry-not-found`, please contact shiro." + ); } else { if (showtable) { const { returnKeyWord, subtable } = data; diff --git a/bot/commands/ev.js b/bot/commands/ev.js index b36477d..30344ec 100644 --- a/bot/commands/ev.js +++ b/bot/commands/ev.js @@ -74,6 +74,7 @@ exports.usage = "CLIENT_PREFIX:ev OR CLIENT_PREFIX:ev "; exports.example = "CLIENT_PREFIX:ev 6000 5000\nCLIENT_PREFIX:ev 10000"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { if (!args[0]) return message.channel.send( diff --git a/bot/commands/hb.js b/bot/commands/hb.js index b3f0e12..1ed0a0c 100644 --- a/bot/commands/hb.js +++ b/bot/commands/hb.js @@ -30,6 +30,7 @@ exports.description = ":muscle: Calculate hero boost's damage multiplier."; exports.usage = "CLIENT_PREFIX:hb "; exports.example = "CLIENT_PREFIX:hb 5000"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { if (!args[0]) return message.channel.send( diff --git a/bot/commands/help.js b/bot/commands/help.js index 26ecc2f..1b98a00 100644 --- a/bot/commands/help.js +++ b/bot/commands/help.js @@ -17,7 +17,11 @@ exports.run = (client, message, args) => { client.prefix ) ); - if (cmd.hidden && message.author.id != client.ownerID) return; + if ( + (cmd.hidden && message.author.id != client.ownerID) || + cmd.description == "alias" + ) + return; embed.setTitle(`Help for \`${cmd.name}\` command`); embed.setDescription(cmd.description); embed.addFields( @@ -34,7 +38,11 @@ exports.run = (client, message, args) => { [...client.commands.values()] .sort((a, b) => (a.name > b.name ? 1 : -1)) .forEach((cmd) => { - if (cmd.hidden && message.author.id != client.ownerID) return; + if ( + (cmd.hidden && message.author.id != client.ownerID) || + cmd.isAlias + ) + return; embed.addFields({ name: cmd.name, value: cmd.description.replaceAll( diff --git a/bot/commands/ms.js b/bot/commands/ms.js index 0433865..8913cef 100644 --- a/bot/commands/ms.js +++ b/bot/commands/ms.js @@ -5,6 +5,7 @@ exports.description = exports.usage = "CLIENT_PREFIX:ms [projectile speed]"; exports.example = "CLIENT_PREFIX:ms 10000 250 10000"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { if (!args[0] || !args[1]) return message.channel.send( diff --git a/bot/commands/ping.js b/bot/commands/ping.js index 8962f3f..1848183 100644 --- a/bot/commands/ping.js +++ b/bot/commands/ping.js @@ -14,6 +14,7 @@ exports.description = ":ping_pong: View service statistics."; exports.usage = "CLIENT_PREFIX:ping"; exports.example = "CLIENT_PREFIX:ping"; exports.hidden = true; +exports.isAlias = false; exports.run = async (client, message, args) => { message.channel.send("Fetching data...").then((m) => { m.edit( diff --git a/bot/commands/refetch.js b/bot/commands/refetch.js index 4660282..865a222 100644 --- a/bot/commands/refetch.js +++ b/bot/commands/refetch.js @@ -3,6 +3,7 @@ exports.description = ":ninja: Refetch user react data."; exports.usage = "CLIENT_PREFIX:refetch"; exports.example = "CLIENT_PREFIX:refetch"; exports.hidden = true; +exports.isAlias = false; exports.run = async (client, message, args) => { if (message.author.id != client.ownerID) return; try { diff --git a/bot/commands/res.js b/bot/commands/res.js index 76114fc..eb45fd6 100644 --- a/bot/commands/res.js +++ b/bot/commands/res.js @@ -6,6 +6,7 @@ exports.usage = "CLIENT_PREFIX:res [res] | [second hero stat]"; exports.example = "CLIENT_PREFIX:res -3 1 -16 14 | 406 440"; exports.hidden = false; +exports.isAlias = false; exports.run = async (client, message, args) => { for (let i = 0; i < args.length; i++) { if (args[i] == "|") continue; diff --git a/bot/commands/tb.js b/bot/commands/tb.js index 0d4883d..aa4d7bc 100644 --- a/bot/commands/tb.js +++ b/bot/commands/tb.js @@ -31,6 +31,7 @@ exports.description = ":fire: Calculate tower boost's damage multiplier."; exports.usage = "CLIENT_PREFIX:tb "; exports.example = "CLIENT_PREFIX:tb 5000"; exports.hidden = false; +exports.isAlias = false; exports.run = (client, message, args) => { if (!args[0]) return message.channel.send(