abstract away prefix + ev cmd
All checks were successful
Deploy bot / build-and-deploy (push) Successful in 14s

This commit is contained in:
2025-08-08 17:03:24 +02:00
parent a57aa17deb
commit 1009165751
14 changed files with 226 additions and 51 deletions

View File

@ -1,13 +1,19 @@
exports.name = "bonus";
exports.description =
":star: Sums and calculates bonus for player stat numbers.";
exports.usage = "<<bonus <number> <number> [inf optional extra numbers]";
exports.example = "<<bonus 100 100";
exports.usage =
"CLIENT_PREFIX:bonus <number> <number> [inf optional extra numbers]";
exports.example = "CLIENT_PREFIX:bonus 100 100";
exports.hidden = false;
exports.run = (client, message, args) => {
let is1nan = false;
if (!args[0])
return message.channel.send("Not enough arguments, consult <<help.");
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
args.forEach((arg) => {
if (isNaN(parseInt(arg))) {
is1nan = true;
@ -16,7 +22,10 @@ exports.run = (client, message, args) => {
});
if (is1nan)
return message.channel.send(
"You have provided invalid arguments to this command, please consult <<help."
"You have provided invalid arguments to this command, please consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let sum = 0;
args.forEach((arg) => {

View File

@ -1,16 +1,24 @@
exports.name = "cat";
exports.description = ":cat: Calculates boost for cat.";
exports.usage = "<<cat <boost> <levels>";
exports.example = "<<cat 80 120";
exports.usage = "CLIENT_PREFIX:cat <boost> <levels>";
exports.example = "CLIENT_PREFIX:cat 80 120";
exports.hidden = false;
exports.run = (client, message, args) => {
if (!args[0] || !args[1])
return message.channel.send("Not enough arguments, consult <<help.");
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let boost = parseInt(args[0]);
let levels = parseInt(args[1]);
if (isNaN(boost) || isNaN(levels))
return message.channel.send(
"Boost or levels is not a number. Consult <<help."
"Boost or levels is not a number. Consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let extraboost = Math.floor(levels / 3 - 3);
let players = Math.floor(levels / 29) + 1;

View File

@ -1,12 +1,17 @@
exports.name = "cb";
exports.description =
":crossed_swords: Calculate calamity blade damage taking in to account projectile speed.";
exports.usage = "<<cb <damage> <ups> [projectile speed]";
exports.example = "<<cb 10000 250 10000";
exports.usage = "CLIENT_PREFIX:cb <damage> <ups> [projectile speed]";
exports.example = "CLIENT_PREFIX:cb 10000 250 10000";
exports.hidden = false;
exports.run = (client, message, args) => {
if (!args[0] || !args[1])
return message.channel.send("Not enough arguments, consult <<help.");
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let cb = parseInt(args[0]);
let ups = parseInt(args[1]);
if (isNaN(cb) || isNaN(ups))

View File

@ -128,9 +128,10 @@ function weightedInterpolatePrice(pricesArr, inputNum, p = 2) {
exports.name = "estimate";
exports.description =
":money_with_wings: Give an estimated price of certain items in cv.";
exports.usage = "<<estimate [summary of item you want the price of]";
exports.usage =
"CLIENT_PREFIX:estimate [summary of item you want the price of]";
exports.example =
"<<estimate 1600 ab2\n<<estimate 1100 thp\n<<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\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.run = async (client, message, args) => {
if (!args[0]) {
@ -139,7 +140,7 @@ exports.run = async (client, message, args) => {
tbl += p.returnKeyWord + "\n";
});
return message.channel
.send(`Available items in pricing table:\n\`\`\`\n${tbl}\`\`\`\nFor usage, consult \`<<help estimate\`
.send(`Available items in pricing table:\n\`\`\`\n${tbl}\`\`\`\nFor usage, consult \`CLIENT_PREFIX:help estimate\`.replaceAll("CLIENT_PREFIX:", client.prefix)
`);
}
const combined = args.join(" ");
@ -156,7 +157,10 @@ exports.run = async (client, message, args) => {
});
if (!gameValue) {
return message.channel.send(
"You didn't include any numbers in your query. Try again or consult `<<help estimate`."
"You didn't include any numbers in your query. Try again or consult `CLIENT_PREFIX:help estimate`.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
}
priceTable.forEach((price, idx) => {
@ -200,6 +204,9 @@ exports.run = async (client, message, args) => {
}
} else
message.channel.send(
"Your query couldn't be matched with anything, please refine your query or reffer to `<<help estimate` or use `<<estimate` to see all available price tables for more information."
"Your query couldn't be matched with anything, please refine your query or reffer to `CLIENT_PREFIX:help estimate` or use `CLIENT_PREFIX:estimate` to see all available price tables for more information.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
};

113
commands/ev.js Normal file
View File

@ -0,0 +1,113 @@
const BASEDMG = 1e9; // absurdly high to avoid base damage bottleneck
function getHeroDamageScaling(statVal) {
return (
1.0 +
0.33 *
(Math.pow(4.0, 0.1 * 1.1) -
1.0 +
0.68 * (Math.pow(statVal + 1, 0.375 * 1.1) - 1.0))
);
}
function getAb2Scaling(statVal) {
return (
1.0 +
0.66 * (Math.pow(4.0, 0.0825) - 1.0) +
0.75 * (Math.pow(statVal + 1, 0.3375) - 1.0)
);
}
function getTotalDamage(hdmgStat, baseDamage) {
return Math.max(
Math.max(32.0, Math.max(1.0, baseDamage)) *
getHeroDamageScaling(hdmgStat) *
(1.2 * 0.8 * 0.155),
1.0
);
}
function getBeamDamage(hdmg, ab2) {
return (
getTotalDamage(hdmg, BASEDMG) * 0.6 * Math.pow(getAb2Scaling(ab2), 0.93)
);
}
/**
* Find optimal split of totalStats between hdmg and ab2
* using a binary/golden section search.
*/
function findOptimalDistribution(totalStats) {
let left = 0;
let right = totalStats;
const phi = (Math.sqrt(5) - 1) / 2; // golden ratio for faster convergence
let x1 = right - phi * (right - left);
let x2 = left + phi * (right - left);
while (Math.abs(right - left) > 1e-3) {
const f1 = getBeamDamage(x1, totalStats - x1);
const f2 = getBeamDamage(x2, totalStats - x2);
if (f1 < f2) {
left = x1;
x1 = x2;
x2 = left + phi * (right - left);
} else {
right = x2;
x2 = x1;
x1 = right - phi * (right - left);
}
}
const hdmg = (left + right) / 2;
const ab2 = totalStats - hdmg;
return {
hdmg: hdmg,
ab2: ab2,
};
}
exports.name = "ev";
exports.description =
":robot: Calculate how much hero damage/ab2 you should aim for.";
exports.usage =
"CLIENT_PREFIX:ev <hdmg> <ab2> OR CLIENT_PREFIX:ev <total stats>";
exports.example = "CLIENT_PREFIX:ev 6000 5000\nCLIENT_PREFIX:ev 10000";
exports.hidden = false;
exports.run = (client, message, args) => {
if (!args[0])
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let total = parseInt(args[0]);
if (isNaN(total))
return message.channel.send(
"One of the arguments is not a number. Consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
if (args[1]) {
if (isNaN(parseInt(args[1]))) {
return message.channel.send(
"One of the arguments is not a number. Consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
} else total += parseInt(args[1]);
}
const distribution = findOptimalDistribution(total);
message.channel.send(
`You should aim for **${
Math.round(distribution.hdmg) - 3
}** hero damage and **${
Math.round(distribution.ab2) + 3
}** ab2. *(approximately)*`
);
};

View File

@ -27,16 +27,24 @@ function get_damage_multiplier(stat_val) {
exports.name = "hb";
exports.description = ":muscle: Calculate hero boost's damage multiplier.";
exports.usage = "<<hb <points>";
exports.example = "<<hb 5000";
exports.usage = "CLIENT_PREFIX:hb <points>";
exports.example = "CLIENT_PREFIX:hb 5000";
exports.hidden = false;
exports.run = (client, message, args) => {
if (!args[0])
return message.channel.send("Not enough arguments, consult <<help.");
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let hbPoints = parseInt(args[0]);
if (isNaN(hbPoints))
return message.channel.send(
"Given argument is not a number. Consult <<help."
"Given argument is not a number. Consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
message.channel.send(

View File

@ -2,8 +2,8 @@ const { EmbedBuilder } = require("discord.js");
exports.name = "help";
exports.description =
":scroll: Shows this message and provides insight into other commands.";
exports.usage = "<<help [optional other command]";
exports.example = "<<help res";
exports.usage = "CLIENT_PREFIX:help [optional other command]";
exports.example = "CLIENT_PREFIX:help res";
exports.hidden = false;
exports.run = (client, message, args) => {
let embed = new EmbedBuilder();
@ -12,7 +12,10 @@ exports.run = (client, message, args) => {
const cmd = client.commands.get(args[0]);
if (!cmd)
return message.channel.send(
"Command not found, try `<<help` first."
"Command not found, try `CLIENT_PREFIX:help` first.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
if (cmd.hidden && message.author.id != client.ownerID) return;
embed.setTitle(`Help for \`${cmd.name}\` command`);
@ -20,11 +23,11 @@ exports.run = (client, message, args) => {
embed.addFields(
{
name: "Usage",
value: cmd.usage,
value: cmd.usage.replaceAll("CLIENT_PREFIX:", client.prefix),
},
{
name: "Example",
value: cmd.example,
value: cmd.example.replaceAll("CLIENT_PREFIX:", client.prefix),
}
);
} else {
@ -34,7 +37,10 @@ exports.run = (client, message, args) => {
if (cmd.hidden && message.author.id != client.ownerID) return;
embed.addFields({
name: cmd.name,
value: cmd.description,
value: cmd.description.replaceAll(
"CLIENT_PREFIX:",
client.prefix
),
});
});
}

View File

@ -1,12 +1,17 @@
exports.name = "ms";
exports.description =
":tada: Calculate moon staff damage taking in to account projectile speed.";
exports.usage = "<<ms <elemental damage> <ups> [projectile speed]";
exports.example = "<<ms 10000 250 10000";
exports.usage = "CLIENT_PREFIX:ms <elemental damage> <ups> [projectile speed]";
exports.example = "CLIENT_PREFIX:ms 10000 250 10000";
exports.hidden = false;
exports.run = (client, message, args) => {
if (!args[0] || !args[1])
return message.channel.send("Not enough arguments, consult <<help.");
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let moonstaff = parseInt(args[0]);
let ups = parseInt(args[1]);
if (isNaN(moonstaff) || isNaN(ups))

View File

@ -11,8 +11,8 @@ function format(seconds) {
exports.name = "ping";
exports.description = ":ping_pong: View service statistics.";
exports.usage = "<<ping";
exports.example = "<<ping";
exports.usage = "CLIENT_PREFIX:ping";
exports.example = "CLIENT_PREFIX:ping";
exports.hidden = true;
exports.run = async (client, message, args) => {
message.channel.send("Fetching data...").then((m) => {

View File

@ -1,7 +1,7 @@
exports.name = "refetch";
exports.description = ":ninja: Refetch user react data.";
exports.usage = "<<refetch";
exports.example = "<<refetch";
exports.usage = "CLIENT_PREFIX:refetch";
exports.example = "CLIENT_PREFIX:refetch";
exports.hidden = true;
exports.run = async (client, message, args) => {
if (message.author.id != client.ownerID) return;

View File

@ -2,8 +2,8 @@ exports.name = "res";
exports.description =
":shield: Calculates how much upgrades you need to max your resistances. For Ult pieces and better. (slightly inaccurate but this is hard to calculate)";
exports.usage =
"<<res <res> <res> <res> [res] | <hero stat> <levels> [second hero stat]";
exports.example = "<<res -3 1 -16 14 | 406 440";
"CLIENT_PREFIX:res <res> <res> <res> [res] | <hero stat> <levels> [second hero stat]";
exports.example = "CLIENT_PREFIX:res -3 1 -16 14 | 406 440";
exports.hidden = false;
exports.run = (client, message, args) => {
for (let i = 0; i < args.length; i++) {

View File

@ -28,16 +28,24 @@ function get_damage_multiplier(stat_val) {
exports.name = "tb";
exports.description = ":fire: Calculate tower boost's damage multiplier.";
exports.usage = "<<tb <points>";
exports.example = "<<tb 5000";
exports.usage = "CLIENT_PREFIX:tb <points>";
exports.example = "CLIENT_PREFIX:tb 5000";
exports.hidden = false;
exports.run = (client, message, args) => {
if (!args[0])
return message.channel.send("Not enough arguments, consult <<help.");
return message.channel.send(
"Not enough arguments, consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
let tbPoints = parseInt(args[0]);
if (isNaN(tbPoints))
return message.channel.send(
"Given argument is not a number. Consult <<help."
"Given argument is not a number. Consult CLIENT_PREFIX:help.".replaceAll(
"CLIENT_PREFIX:",
client.prefix
)
);
message.channel.send(

View File

@ -20,6 +20,7 @@ const client = new Client({
});
client.commands = new Collection();
client.ownerID = 263247134147608578;
client.prefix = prefix;
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
@ -73,8 +74,13 @@ client.on(Events.MessageCreate, async (message) => {
const cmd = client.commands.get(command);
if (!cmd) return;
try {
await cmd.run(client, message, args);
} catch (e) {
message.channel.send(
"Command " + cmd.name + " exited with an exception: " + e
);
}
});
// Log in to Discord with your client's token

20
old.js
View File

@ -28,7 +28,7 @@ client.on(Events.MessageCreate, (message) => {
return message.channel.send("not implemented.");
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
"Not enough arguments, consult CLIENT_PREFIX:help."
);
let ab1 = parseInt(args[0]);
let ab2 = parseInt(args[1]);
@ -42,7 +42,7 @@ client.on(Events.MessageCreate, (message) => {
return message.channel.send("not implemented.");
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
"Not enough arguments, consult CLIENT_PREFIX:help."
);
let ab1 = parseInt(args[0]);
let ab2 = parseInt(args[1]);
@ -57,7 +57,7 @@ client.on(Events.MessageCreate, (message) => {
if (command == "ms") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
"Not enough arguments, consult CLIENT_PREFIX:help."
);
let cb = parseInt(args[0]);
let ups = parseInt(args[1]);
@ -209,7 +209,7 @@ client.on(Events.MessageCreate, (message) => {
if (command == "cat") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
"Not enough arguments, consult CLIENT_PREFIX:help."
);
let boost = parseInt(args[0]);
let levels = parseInt(args[1]);
@ -225,7 +225,7 @@ client.on(Events.MessageCreate, (message) => {
if (command == "bident") {
if (!args[0] || !args[1])
return message.channel.send(
"Not enough arguments, consult <<help."
"Not enough arguments, consult CLIENT_PREFIX:help."
);
let damage = parseInt(args[0]);
let ups = parseInt(args[1]);
@ -250,7 +250,7 @@ client.on(Events.MessageCreate, (message) => {
if (command == "cdrag") {
if (!args[0] || !args[1] || !args[2])
return message.channel.send(
"Not enough arguments, consult <<help."
"Not enough arguments, consult CLIENT_PREFIX:help."
);
let damage = parseInt(args[0]);
let upgrades = parseInt(args[1]);
@ -270,19 +270,19 @@ client.on(Events.MessageCreate, (message) => {
embed.addFields(
{
name: "cat",
value: ":cat: Calculates boost for cat. (<<cat <boost> <levels>)",
value: ":cat: Calculates boost for cat. (CLIENT_PREFIX:cat <boost> <levels>)",
},
{
name: "cdrag",
value: ":dragon: Calculate damage for crystaline dragon taking into account upgrades and additional projectiles. (<<cdrag <base> <ups> <extra projectiles>)",
value: ":dragon: Calculate damage for crystaline dragon taking into account upgrades and additional projectiles. (CLIENT_PREFIX:cdrag <base> <ups> <extra projectiles>)",
},
{
name: "cb",
value: ":crossed_swords: Calculate calamity blade damage taking in to account speed. (<<cb <damage> <ups> [proj speed])",
value: ":crossed_swords: Calculate calamity blade damage taking in to account speed. (CLIENT_PREFIX:cb <damage> <ups> [proj speed])",
},
{
name: "bident",
value: ":trident: Calculate bident damage taking in to account speed and charge speed. (<<bident <damage> <ups> [proj speed] [charge speed])",
value: ":trident: Calculate bident damage taking in to account speed and charge speed. (CLIENT_PREFIX:bident <damage> <ups> [proj speed] [charge speed])",
},
{
name: "ms",