206 lines
6.6 KiB
JavaScript
206 lines
6.6 KiB
JavaScript
const priceTable = [
|
|
{
|
|
regex: /\b(?:thp|summoner|summ)\b/i,
|
|
returnKeyWord: "summoner piece",
|
|
prices: [
|
|
"1000;10",
|
|
"1050;12",
|
|
"1100;15",
|
|
"1150;25",
|
|
"1200;30",
|
|
"1250;100",
|
|
"1300;500",
|
|
],
|
|
},
|
|
{
|
|
regex: /\b(?:dps|ab2)\b/i,
|
|
returnKeyWord: "dps/ab2 piece",
|
|
prices: [
|
|
"1400;20",
|
|
"1450;35",
|
|
"1500;50",
|
|
"1550;75",
|
|
"1600;150",
|
|
"1650;500",
|
|
"1700;1000",
|
|
"1750;2000",
|
|
"1800;50000",
|
|
],
|
|
},
|
|
{
|
|
regex: /\b(?:tb|ab1)\b/i,
|
|
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 builder staff",
|
|
prices: [
|
|
"2200;5",
|
|
"2250;15",
|
|
"2300;25",
|
|
"2350;35",
|
|
"2400;45",
|
|
"2450;70",
|
|
"2500;100",
|
|
"2550;175",
|
|
"2600;250",
|
|
"2700;400",
|
|
"2800;500",
|
|
"2900;2000",
|
|
],
|
|
},
|
|
{
|
|
regex: /\b(?:aura|trange)\b/i,
|
|
returnKeyWord: "aura/trange piece",
|
|
prices: ["980;5", "1050;15", "1100;40", "1150;70", "1200;500"],
|
|
},
|
|
];
|
|
|
|
function constructPriceSubTable(idx) {
|
|
const orig = priceTable[idx];
|
|
const priceSubTable = [];
|
|
orig.prices.forEach((price) => {
|
|
const splitPrice = price.split(";");
|
|
const obj = {
|
|
number: parseInt(splitPrice[0]),
|
|
val: parseInt(splitPrice[1]),
|
|
};
|
|
priceSubTable.push(obj);
|
|
});
|
|
return priceSubTable;
|
|
}
|
|
|
|
function findClosestPrice(subtable, gameValue) {
|
|
let closest = subtable[0];
|
|
let smallestDiff = Math.abs(subtable[0].number - gameValue);
|
|
|
|
for (let i = 1; i < subtable.length; i++) {
|
|
const diff = Math.abs(subtable[i].number - gameValue);
|
|
if (diff < smallestDiff) {
|
|
smallestDiff = diff;
|
|
closest = subtable[i];
|
|
}
|
|
}
|
|
|
|
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.";
|
|
exports.usage = "<<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)";
|
|
exports.hidden = false;
|
|
exports.run = async (client, message, args) => {
|
|
if (!args[0]) {
|
|
let tbl = "";
|
|
priceTable.forEach((p) => {
|
|
tbl += p.returnKeyWord + "\n";
|
|
});
|
|
return message.channel
|
|
.send(`Available items in pricing table:\n\`\`\`\n${tbl}\`\`\`\nFor usage, consult \`<<help estimate\`
|
|
`);
|
|
}
|
|
const combined = args.join(" ");
|
|
|
|
let entryFound = false;
|
|
let estimatedPrice = 0;
|
|
let subtable, closestInTable;
|
|
let gameValue = 0;
|
|
let returnKeyWord = "";
|
|
args.forEach((arg) => {
|
|
if (!isNaN(parseInt(arg)) && !gameValue) {
|
|
gameValue = parseInt(arg);
|
|
}
|
|
});
|
|
if (!gameValue) {
|
|
return message.channel.send(
|
|
"You didn't include any numbers in your query. Try again or consult `<<help estimate`."
|
|
);
|
|
}
|
|
priceTable.forEach((price, idx) => {
|
|
if (price.regex.test(combined) && !entryFound) {
|
|
entryFound = true;
|
|
returnKeyWord = price.returnKeyWord;
|
|
subtable = constructPriceSubTable(idx);
|
|
closestInTable = findClosestPrice(subtable, gameValue);
|
|
estimatedPrice = Math.round(
|
|
weightedInterpolatePrice(subtable, gameValue)
|
|
);
|
|
if (idx == 0 && closestInTable.diff > 100) {
|
|
estimatedPrice = 0;
|
|
}
|
|
if (estimatedPrice > 100000) {
|
|
estimatedPrice = 100000;
|
|
}
|
|
}
|
|
});
|
|
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 {
|
|
let stringprice;
|
|
if (estimatedPrice > 499) {
|
|
stringprice = `**__${estimatedPrice}__** (atleast 1 cheater, worth auctioning)`;
|
|
} else if (estimatedPrice == 0) {
|
|
stringprice = "**0** (<:TavKeep:1179145911180480563>)";
|
|
} else {
|
|
stringprice = `**${estimatedPrice}**`;
|
|
}
|
|
message.channel.send(
|
|
`Hmm... I estimate your **${gameValue} ${returnKeyWord}** to be worth approximately ${stringprice} 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 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."
|
|
);
|
|
};
|