more more more
All checks were successful
Deploy bot / build-and-deploy (push) Successful in 13s

This commit is contained in:
2025-08-08 13:03:39 +02:00
parent 5cff410320
commit 04e8ecc471

View File

@ -32,9 +32,24 @@ const priceTable = [
returnKeyWord: "tb/ab1 piece", returnKeyWord: "tb/ab1 piece",
prices: ["980;5", "1050;15", "1100;40", "1150;70", "1200;500"], prices: ["980;5", "1050;15", "1100;40", "1150;70", "1200;500"],
}, },
{
regex: /\b(?:app builder|apprentice builder|app piece|apprentice piece)\b/i,
returnKeyWord: "apprentice builder piece",
prices: [
"2000;25",
"2050;35",
"2100;50",
"2150;80",
"2200;150",
"2250;220",
"2300;500",
"2350;1000",
"2400;50000",
],
},
{ {
regex: /\b(?:app builder staff|apprentice build staff|app staff|apprentice staff)\b/i, regex: /\b(?:app builder staff|apprentice build staff|app staff|apprentice staff)\b/i,
returnKeyWord: "apprentice staff", returnKeyWord: "apprentice builder staff",
prices: [ prices: [
"2200;5", "2200;5",
"2250;15", "2250;15",
@ -86,12 +101,36 @@ function findClosestPrice(subtable, gameValue) {
return { val: closest.val, diff: smallestDiff }; return { val: closest.val, diff: smallestDiff };
} }
function weightedInterpolatePrice(pricesArr, inputNum, p = 2) {
let lower = null;
let upper = null;
for (let i = 0; i < pricesArr.length; i++) {
if (pricesArr[i].number === inputNum) return pricesArr[i].val;
if (pricesArr[i].number < inputNum) lower = pricesArr[i];
if (pricesArr[i].number > inputNum) {
upper = pricesArr[i];
break;
}
}
if (!lower) return upper.val;
if (!upper) return lower.val;
const fraction = (inputNum - lower.number) / (upper.number - lower.number);
const weight =
Math.pow(fraction, p) /
(Math.pow(fraction, p) + Math.pow(1 - fraction, p));
return lower.val + weight * (upper.val - lower.val);
}
exports.name = "estimate"; exports.name = "estimate";
exports.description = exports.description =
":money_with_wings: Give an estimated price of certain items in cv. [WIP]"; ":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 = "<<estimate [summary of item you want the price of]";
exports.example = exports.example =
"<<estimate 1600 ab2 (ab2 dps)\n<<estimate 1100 thp\n<<estimate 2400 app builder staff\n(please use slang(thp,tdmg,etc), do not put the slang first instead always number first\n do not include armor type, conflicting or superflous data to avoid confusion)"; "<<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)";
exports.hidden = false; exports.hidden = false;
exports.run = async (client, message, args) => { exports.run = async (client, message, args) => {
if (!args[0]) { if (!args[0]) {
@ -104,14 +143,10 @@ exports.run = async (client, message, args) => {
`); `);
} }
const combined = args.join(" "); const combined = args.join(" ");
console.log(combined);
// regex's are split for readability
const builderRegex = /\b(?:app|apprentice|tdmg|tdamage|aura|trange)\b/i;
const otherRegex = /\b(?:frost rifle|mm|mischief maker|)\b/i;
let entryFound = false; let entryFound = false;
let estimatedPrice = 0; let estimatedPrice = 0;
let priceDiffFromTable = 0; let subtable, closestInTable;
let gameValue = 0; let gameValue = 0;
let returnKeyWord = ""; let returnKeyWord = "";
args.forEach((arg) => { args.forEach((arg) => {
@ -125,27 +160,37 @@ exports.run = async (client, message, args) => {
); );
} }
priceTable.forEach((price, idx) => { priceTable.forEach((price, idx) => {
if (price.regex.test(combined)) { if (price.regex.test(combined) && !entryFound) {
entryFound = true; entryFound = true;
returnKeyWord = price.returnKeyWord; returnKeyWord = price.returnKeyWord;
let closestInTable = findClosestPrice( subtable = constructPriceSubTable(idx);
constructPriceSubTable(idx), closestInTable = findClosestPrice(subtable, gameValue);
gameValue estimatedPrice = Math.round(
weightedInterpolatePrice(subtable, gameValue)
); );
estimatedPrice = closestInTable.val;
priceDiffFromTable = closestInTable.diff;
} }
}); });
if (entryFound) { if (entryFound) {
if (combined.includes("showtable")) {
let res = "";
subtable.forEach((entry) => {
res += String(entry.number).padEnd(14, " ") + entry.val + "\n";
});
message.channel.send(
`Displaying data price table for \`${returnKeyWord}\`.\n\`\`\`\nGame Value\tPrice\n${res}\`\`\``
);
} else
message.channel.send( message.channel.send(
`Hmm... I estimate your **${gameValue} ${returnKeyWord}** to be worth approximately ${ `Hmm... I estimate your **${gameValue} ${returnKeyWord}** to be worth approximately ${
estimatedPrice > 499 estimatedPrice > 499
? `**__${estimatedPrice}__** (atleast 1 cheater, worth auctioning)` ? `**__${estimatedPrice}__** (atleast 1 cheater, worth auctioning)`
: `**${estimatedPrice}**` : `**${estimatedPrice}**`
} cv.\n*Take this info with a grain of salt though. Estimation is provided through looking at past trades/price checks/sheets in DDRNG. GLHF.*\n*Calc diff: ${priceDiffFromTable}*.` } cv.\n*Estimation is provided through looking at past trades/price checks/sheets in DDRNG.*\n*Closest price in table: **${
closestInTable.val
}** cv, diff: **${closestInTable.diff}***.`
); );
} else } else
message.channel.send( message.channel.send(
"Your summary didn't match any entry in price table (WIP, im workig on it), please refine your query and/or reffer to `<<help estimate` for more information." "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."
); );
}; };