mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 22:32:52 +02:00
snekfetch 4.0.0
This commit is contained in:
@@ -55,7 +55,7 @@ module.exports = class GitHubCommand extends Command {
|
||||
new Date(body.updated_at).toDateString(), true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,13 +21,13 @@ module.exports = class GoogleAutofillCommand extends Command {
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
const { raw } = await snekfetch
|
||||
.get('https://suggestqueries.google.com/complete/search')
|
||||
.query({
|
||||
client: 'firefox',
|
||||
q: query
|
||||
});
|
||||
const data = JSON.parse(text)[1];
|
||||
const data = JSON.parse(raw.toString())[1];
|
||||
if (!data.length) return msg.say('Could not find any results.');
|
||||
return msg.say(data.join('\n'));
|
||||
} catch (err) {
|
||||
|
||||
@@ -33,7 +33,7 @@ module.exports = class GravatarCommand extends Command {
|
||||
});
|
||||
return msg.say({ files: [{ attachment: body, name: `${hash}.jpg` }] });
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ module.exports = class HTTPCatCommand extends Command {
|
||||
|
||||
async run(msg, { code }) {
|
||||
try {
|
||||
const { body, text } = await snekfetch.get(`https://http.cat/${code}.jpg`);
|
||||
if (text.startsWith('<!DOCTYPE html>')) return msg.say('Could not find any results.');
|
||||
const { body, raw } = await snekfetch.get(`https://http.cat/${code}.jpg`);
|
||||
if (raw.toString().startsWith('<!DOCTYPE html>')) return msg.say('Could not find any results.');
|
||||
return msg.say({ files: [{ attachment: body, name: `${code}.jpg` }] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -30,7 +30,7 @@ module.exports = class ITunesCommand extends Command {
|
||||
|
||||
async run(msg, { country, query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
const { raw } = await snekfetch
|
||||
.get('https://itunes.apple.com/search')
|
||||
.query({
|
||||
term: query,
|
||||
@@ -40,7 +40,7 @@ module.exports = class ITunesCommand extends Command {
|
||||
explicit: msg.channel.nsfw ? 'yes' : 'no',
|
||||
country
|
||||
});
|
||||
const body = JSON.parse(text);
|
||||
const body = JSON.parse(raw.toString());
|
||||
if (!body.results.length) return msg.say('Could not find any results.');
|
||||
const data = body.results[0];
|
||||
const embed = new MessageEmbed()
|
||||
@@ -59,7 +59,7 @@ module.exports = class ITunesCommand extends Command {
|
||||
data.primaryGenreName, true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 400) {
|
||||
if (err.statusCode === 400) {
|
||||
return msg.reply('Invalid country code. Refer to <https://en.wikipedia.org/wiki/List_of_ISO_639-2_codes>.');
|
||||
}
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -28,10 +28,10 @@ module.exports = class MyAnimeListAnimeCommand extends Command {
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
const { raw } = await snekfetch
|
||||
.get(`https://${MAL_USERNAME}:${MAL_PASSWORD}@myanimelist.net/api/anime/search.xml`)
|
||||
.query({ q: query });
|
||||
const body = await xml(text);
|
||||
const body = await xml(raw.toString());
|
||||
const data = body.anime.entry[0];
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
|
||||
@@ -28,10 +28,10 @@ module.exports = class MyAnimeListMangaCommand extends Command {
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
const { raw } = await snekfetch
|
||||
.get(`https://${MAL_USERNAME}:${MAL_PASSWORD}@myanimelist.net/api/manga/search.xml`)
|
||||
.query({ q: query });
|
||||
const body = await xml(text);
|
||||
const body = await xml(raw.toString());
|
||||
const data = body.manga.entry[0];
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x2D54A2)
|
||||
|
||||
@@ -40,14 +40,14 @@ module.exports = class NeopetCommand extends Command {
|
||||
|
||||
async run(msg, { pet, mood }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
const { raw } = await snekfetch
|
||||
.get('http://www.sunnyneo.com/petimagefinder.php')
|
||||
.query({
|
||||
name: pet,
|
||||
size: 5,
|
||||
mood: moods[mood]
|
||||
});
|
||||
const link = text.match(/http:\/\/pets\.neopets\.com\/cp\/.+\.png/);
|
||||
const link = raw.toString().match(/http:\/\/pets\.neopets\.com\/cp\/.+\.png/);
|
||||
if (!link) return msg.say('Could not find any results.');
|
||||
return msg.say(link[0]);
|
||||
} catch (err) {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -55,7 +55,7 @@ module.exports = class NPMCommand extends Command {
|
||||
maintainers.join(', '));
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ module.exports = class PokedexCommand extends Command {
|
||||
.setThumbnail(`https://www.serebii.net/sunmoon/pokemon/${id}.png`);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,8 +34,8 @@ module.exports = class RottenTomatoesCommand extends Command {
|
||||
if (!search.body.movies.length) return msg.say('Could not find any results.');
|
||||
const find = search.body.movies.find(m => m.name.toLowerCase() === query.toLowerCase()) || search.body.movies[0];
|
||||
const urlID = find.url.replace('/m/', '');
|
||||
const { text } = await snekfetch.get(`https://www.rottentomatoes.com/api/private/v1.0/movies/${urlID}`);
|
||||
const body = JSON.parse(text);
|
||||
const { raw } = await snekfetch.get(`https://www.rottentomatoes.com/api/private/v1.0/movies/${urlID}`);
|
||||
const body = JSON.parse(raw.toString());
|
||||
const criticS = body.ratingSummary.allCritics;
|
||||
const audienceS = body.ratingSummary.audience;
|
||||
const embed = new MessageEmbed()
|
||||
|
||||
@@ -22,7 +22,7 @@ module.exports = class SafebooruCommand extends Command {
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { text } = await snekfetch
|
||||
const { raw } = await snekfetch
|
||||
.get('https://safebooru.org/index.php')
|
||||
.query({
|
||||
page: 'dapi',
|
||||
@@ -32,6 +32,7 @@ module.exports = class SafebooruCommand extends Command {
|
||||
tags: query,
|
||||
limit: 200
|
||||
});
|
||||
const text = raw.toString();
|
||||
if (!text) return msg.say('Could not find any results.');
|
||||
const body = JSON.parse(text);
|
||||
const data = body[Math.floor(Math.random() * body.length)];
|
||||
|
||||
@@ -41,7 +41,7 @@ module.exports = class TumblrCommand extends Command {
|
||||
data.ask ? 'Yes' : 'No', true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,8 +54,8 @@ module.exports = class TwitterCommand extends Command {
|
||||
body.status ? body.status.text : 'None');
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 401) await this.fetchToken();
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
if (err.statusCode === 401) await this.fetchToken();
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user