From 04e8ecc4717cfdf04aed8cdcf78891166271654e Mon Sep 17 00:00:00 2001 From: koneko <67551503+koneko@users.noreply.github.com> Date: Fri, 8 Aug 2025 13:03:39 +0200 Subject: [PATCH] more more more --- commands/estimate.js | 89 +++++++++++++++++++++++++++++++++----------- 1 file changed, 67 insertions(+), 22 deletions(-) diff --git a/commands/estimate.js b/commands/estimate.js index 6a9ce1d..964693c 100644 --- a/commands/estimate.js +++ b/commands/estimate.js @@ -32,9 +32,24 @@ const priceTable = [ returnKeyWord: "tb/ab1 piece", 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, - returnKeyWord: "apprentice staff", + returnKeyWord: "apprentice builder staff", prices: [ "2200;5", "2250;15", @@ -86,12 +101,36 @@ function findClosestPrice(subtable, gameValue) { 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.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 = "< { if (!args[0]) { @@ -104,14 +143,10 @@ exports.run = async (client, message, args) => { `); } 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 estimatedPrice = 0; - let priceDiffFromTable = 0; + let subtable, closestInTable; let gameValue = 0; let returnKeyWord = ""; args.forEach((arg) => { @@ -125,27 +160,37 @@ exports.run = async (client, message, args) => { ); } priceTable.forEach((price, idx) => { - if (price.regex.test(combined)) { + if (price.regex.test(combined) && !entryFound) { entryFound = true; returnKeyWord = price.returnKeyWord; - let closestInTable = findClosestPrice( - constructPriceSubTable(idx), - gameValue + subtable = constructPriceSubTable(idx); + closestInTable = findClosestPrice(subtable, gameValue); + estimatedPrice = Math.round( + weightedInterpolatePrice(subtable, gameValue) ); - estimatedPrice = closestInTable.val; - priceDiffFromTable = closestInTable.diff; } }); if (entryFound) { - message.channel.send( - `Hmm... I estimate your **${gameValue} ${returnKeyWord}** to be worth approximately ${ - estimatedPrice > 499 - ? `**__${estimatedPrice}__** (atleast 1 cheater, worth auctioning)` - : `**${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}*.` - ); + 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( + `Hmm... I estimate your **${gameValue} ${returnKeyWord}** to be worth approximately ${ + estimatedPrice > 499 + ? `**__${estimatedPrice}__** (atleast 1 cheater, worth auctioning)` + : `**${estimatedPrice}**` + } 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 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 `<