add some checks, more work on price estimating
All checks were successful
Deploy bot / build-and-deploy (push) Successful in 13s
All checks were successful
Deploy bot / build-and-deploy (push) Successful in 13s
This commit is contained in:
@ -1,10 +1,91 @@
|
||||
const priceTable = [
|
||||
{
|
||||
regex: /\b(?:thp|summoner|summ)\b/i,
|
||||
returnKeyWord: "summoner piece",
|
||||
prices: ["1000;10", "1100;15", "1200;30", "1250;100", "1300;1000"],
|
||||
},
|
||||
];
|
||||
|
||||
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 };
|
||||
}
|
||||
|
||||
exports.name = "estimate";
|
||||
exports.description =
|
||||
":money_with_wings: Give an estimated price of certain items in cv.";
|
||||
exports.usage = "<<estimate [explanation of what you want to price]";
|
||||
":money_with_wings: Give an estimated price of certain items in cv. [WIP]";
|
||||
exports.usage = "<<estimate [summary of item you want the price of]";
|
||||
exports.example =
|
||||
"<<estimate 1600 monk dps\n<<estimate 1100 thp\n<<estimate 2400 app builder staff\n(do not include armor type or any superflous data)";
|
||||
exports.hidden = true;
|
||||
"<<estimate 1600 monk 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)";
|
||||
exports.hidden = false;
|
||||
exports.run = async (client, message, args) => {
|
||||
message.channel.send(":sob: im still wokring on this one...");
|
||||
const combined = args.join(" ");
|
||||
console.log(combined);
|
||||
// regex's are split for readability
|
||||
const builderRegex =
|
||||
/\b(?:app|apprentice|thp|summoner|summ|tdmg|tdamage|aura|trange)\b/i;
|
||||
const dpsRegex = /\b(?:dps|hhp|hdmg)\b/i;
|
||||
const otherRegex = /\b(?:frost rifle|mm|mischief maker|)\b/i;
|
||||
|
||||
let entryFound = false;
|
||||
let estimatedPrice = 0;
|
||||
let gameValue = 0;
|
||||
args.forEach((arg) => {
|
||||
if (!isNaN(parseInt(arg))) {
|
||||
gameValue = parseInt(arg);
|
||||
}
|
||||
});
|
||||
console.log(gameValue);
|
||||
let returnKeyWord = "";
|
||||
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 = true;
|
||||
returnKeyWord = price.returnKeyWord;
|
||||
estimatedPrice = findClosestPrice(
|
||||
constructPriceSubTable(idx),
|
||||
gameValue
|
||||
).val;
|
||||
}
|
||||
});
|
||||
if (entryFound) {
|
||||
message.channel.send(
|
||||
`Hmm... I estimate your ${gameValue} ${returnKeyWord} to be worth approximately ${
|
||||
estimatedPrice > 500
|
||||
? `**${estimatedPrice}** (probably auction)`
|
||||
: 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.*`
|
||||
);
|
||||
} 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 `<<help estimate` for more information."
|
||||
);
|
||||
};
|
||||
|
@ -4,17 +4,22 @@ exports.usage = "<<refetch";
|
||||
exports.example = "<<refetch";
|
||||
exports.hidden = true;
|
||||
exports.run = async (client, message, args) => {
|
||||
const url = "https://drive.overflow.fun/public/react.json";
|
||||
client.usersToReactTo = [];
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
if (message.author.id != client.ownerID) return;
|
||||
try {
|
||||
const url = "https://drive.overflow.fun/public/react.json";
|
||||
client.usersToReactTo = [];
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
|
||||
client.usersToReactTo = data.map((entry) => {
|
||||
const [userId, emoji] = entry.split(":");
|
||||
return { userId, emoji };
|
||||
});
|
||||
client.usersToReactTo = data.map((entry) => {
|
||||
const [userId, emoji] = entry.split(":");
|
||||
return { userId, emoji };
|
||||
});
|
||||
|
||||
message.channel.send(
|
||||
"Refetched react data. " + JSON.stringify(client.usersToReactTo)
|
||||
);
|
||||
message.channel.send(
|
||||
"Refetched react data. " + JSON.stringify(client.usersToReactTo)
|
||||
);
|
||||
} catch (e) {
|
||||
message.channel.send("copyparty instance unreachable/offline...");
|
||||
}
|
||||
};
|
||||
|
16
index.js
16
index.js
@ -35,13 +35,17 @@ fs.readdir("./commands/", (err, files) => {
|
||||
const url = "https://drive.overflow.fun/public/react.json";
|
||||
client.usersToReactTo = [];
|
||||
client.once(Events.ClientReady, async (readyClient) => {
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
try {
|
||||
const res = await fetch(url);
|
||||
const data = await res.json();
|
||||
|
||||
client.usersToReactTo = data.map((entry) => {
|
||||
const [userId, emoji] = entry.split(":");
|
||||
return { userId, emoji };
|
||||
});
|
||||
client.usersToReactTo = data.map((entry) => {
|
||||
const [userId, emoji] = entry.split(":");
|
||||
return { userId, emoji };
|
||||
});
|
||||
} catch (e) {
|
||||
console.warn("copyparty is offline, wont work.");
|
||||
}
|
||||
console.log(`Ready! Logged in as ${readyClient.user.tag}`);
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user