snekfetch 4.0.0

This commit is contained in:
Daniel Odendahl Jr
2018-02-26 22:10:01 +00:00
parent a4767134e5
commit 9aaf21913b
22 changed files with 45 additions and 40 deletions
+5 -3
View File
@@ -41,22 +41,24 @@ module.exports = class NeopetItemCommand extends Command {
}
async fetchItem(query) {
const { text } = await snekfetch
const { raw } = await snekfetch
.get('https://items.jellyneo.net/search/')
.query({
name: query,
name_type: 3
});
const text = raw.toString();
const id = text.match(/\/item\/([0-9]+)/);
if (!id) return null;
const price = text.match(/([0-9,]+) (NP|NC)/);
const url = `https://items.jellyneo.net/item/${id[1]}/`;
const details = await snekfetch.get(url);
const rawDetails = details.raw.toString();
return {
id: id[1],
url,
name: details.text.match(/<h1>(.+)<\/h1>/)[1],
details: details.text.match(/<em>(.+)<\/em>/)[1],
name: rawDetails.match(/<h1>(.+)<\/h1>/)[1],
details: rawDetails.match(/<em>(.+)<\/em>/)[1],
image: `https://items.jellyneo.net/assets/imgs/items/${id[1]}.gif`,
price: price ? Number.parseInt(price[1].replace(/,/g, ''), 10) : null,
currency: price ? price[2] : null