mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-26 22:32:52 +02:00
snekfetch -> superagent
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
|
||||
module.exports = class AdviceSlipCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -14,8 +14,8 @@ module.exports = class AdviceSlipCommand extends Command {
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { raw } = await snekfetch.get('http://api.adviceslip.com/advice');
|
||||
return msg.say(JSON.parse(raw.toString()).slip.advice);
|
||||
const { text } = await request.get('http://api.adviceslip.com/advice');
|
||||
return msg.say(JSON.parse(text).slip.advice);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
const { THE_CAT_API_KEY } = process.env;
|
||||
|
||||
module.exports = class CatCommand extends Command {
|
||||
@@ -16,7 +16,7 @@ module.exports = class CatCommand extends Command {
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { body, headers } = await snekfetch
|
||||
const { body, headers } = await request
|
||||
.get('http://thecatapi.com/api/images/get')
|
||||
.query({ api_key: THE_CAT_API_KEY });
|
||||
const format = headers['content-type'].replace(/image\//i, '');
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
|
||||
module.exports = class ChuckNorrisCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -22,7 +22,7 @@ module.exports = class ChuckNorrisCommand extends Command {
|
||||
|
||||
async run(msg, { name }) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
const { body } = await request
|
||||
.get('http://api.icndb.com/jokes/random')
|
||||
.query({
|
||||
escape: 'javascript',
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
|
||||
module.exports = class DogCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -15,7 +15,7 @@ module.exports = class DogCommand extends Command {
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { body } = await snekfetch.get('https://dog.ceo/api/breeds/image/random');
|
||||
const { body } = await request.get('https://dog.ceo/api/breeds/image/random');
|
||||
return msg.say({ files: [body.message] });
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
|
||||
module.exports = class FactCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -15,7 +15,7 @@ module.exports = class FactCommand extends Command {
|
||||
async run(msg) {
|
||||
try {
|
||||
const article = await this.randomWikipediaArticle();
|
||||
const { body } = await snekfetch
|
||||
const { body } = await request
|
||||
.get('https://en.wikipedia.org/w/api.php')
|
||||
.query({
|
||||
action: 'query',
|
||||
@@ -40,7 +40,7 @@ module.exports = class FactCommand extends Command {
|
||||
}
|
||||
|
||||
async randomWikipediaArticle() {
|
||||
const { body } = await snekfetch
|
||||
const { body } = await request
|
||||
.get('https://en.wikipedia.org/w/api.php')
|
||||
.query({
|
||||
action: 'query',
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
const { shorten } = require('../../util/Util');
|
||||
const { NYTIMES_KEY } = process.env;
|
||||
|
||||
@@ -26,7 +26,7 @@ module.exports = class NewYorkTimesCommand extends Command {
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const fetch = snekfetch
|
||||
const fetch = request
|
||||
.get('https://api.nytimes.com/svc/search/v2/articlesearch.json')
|
||||
.query({
|
||||
'api-key': NYTIMES_KEY,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
|
||||
module.exports = class NumberFactCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -20,10 +20,10 @@ module.exports = class NumberFactCommand extends Command {
|
||||
|
||||
async run(msg, { number }) {
|
||||
try {
|
||||
const { raw } = await snekfetch.get(`http://numbersapi.com/${number}`);
|
||||
return msg.say(raw.toString());
|
||||
const { text } = await request.get(`http://numbersapi.com/${number}`);
|
||||
return msg.say(text);
|
||||
} catch (err) {
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class RedditCommand extends Command {
|
||||
@@ -23,7 +23,7 @@ module.exports = class RedditCommand extends Command {
|
||||
|
||||
async run(msg, { subreddit }) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
const { body } = await request
|
||||
.get(`https://www.reddit.com/r/${subreddit}/new.json`)
|
||||
.query({ sort: 'new' });
|
||||
const allowed = msg.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
|
||||
@@ -37,8 +37,8 @@ module.exports = class RedditCommand extends Command {
|
||||
⬇ ${post.downs}
|
||||
`);
|
||||
} catch (err) {
|
||||
if (err.statusCode === 403) return msg.say('This subreddit is private.');
|
||||
if (err.statusCode === 404) return msg.say('Could not find any results.');
|
||||
if (err.status === 403) return msg.say('This subreddit is private.');
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const snekfetch = require('snekfetch');
|
||||
const request = require('superagent');
|
||||
|
||||
module.exports = class ShowerThoughtCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -14,7 +14,7 @@ module.exports = class ShowerThoughtCommand extends Command {
|
||||
|
||||
async run(msg) {
|
||||
try {
|
||||
const { body } = await snekfetch
|
||||
const { body } = await request
|
||||
.get('https://www.reddit.com/r/Showerthoughts.json')
|
||||
.query({ limit: 1000 });
|
||||
const allowed = msg.channel.nsfw ? body.data.children : body.data.children.filter(post => !post.data.over_18);
|
||||
|
||||
Reference in New Issue
Block a user