From b1d278ba2dd127cfc670c1f89f5d894f83c6604e Mon Sep 17 00:00:00 2001 From: loicbersier Date: Fri, 28 Sep 2018 17:57:00 +0200 Subject: [PATCH] Replaced snekfetch by node-fetch --- commands/fun/randocat.js | 27 +++++++++++++---------- commands/fun/randodog.js | 25 +++++++++++---------- commands/fun/reddit.js | 47 +++++++++++++++++++++------------------- package.json | 2 +- 4 files changed, 55 insertions(+), 46 deletions(-) diff --git a/commands/fun/randocat.js b/commands/fun/randocat.js index 41f8ce93..81ae8803 100644 --- a/commands/fun/randocat.js +++ b/commands/fun/randocat.js @@ -1,24 +1,27 @@ const { Command } = require('discord.js-commando'); const Discord = require('discord.js'); -const snekfetch = require('snekfetch'); -module.exports = class RandoCatCommand extends Command { +const fetch = require('node-fetch') +module.exports = class RandoDogCommand extends Command { constructor(client) { super(client, { - name: 'randocat', + name: 'randodog', group: 'fun', - memberName: 'randocat', - description: `Show a random cat`, + memberName: 'randodog', + description: `Show a random dog`, }); } - async run(message, { city }) { - const { body } = await snekfetch.get(`http://aws.random.cat/meow`); - const dogEmbed = new Discord.RichEmbed() + async run(message) { + + fetch("http://aws.random.cat/meow").then((response) => { + return response.json(); +}).then((response) => { + const catEmbed = new Discord.RichEmbed() .setColor("#ff9900") .setTitle('Meow') - .setImage(body.file) + .setImage(response.file) - message.say(dogEmbed); - } -}; \ No newline at end of file + message.say(catEmbed); + }); +}}; \ No newline at end of file diff --git a/commands/fun/randodog.js b/commands/fun/randodog.js index ea570fbd..408bb408 100644 --- a/commands/fun/randodog.js +++ b/commands/fun/randodog.js @@ -1,24 +1,27 @@ const { Command } = require('discord.js-commando'); const Discord = require('discord.js'); -const snekfetch = require('snekfetch'); -module.exports = class RandoDogCommand extends Command { +const fetch = require('node-fetch') +module.exports = class RandoCatCommand extends Command { constructor(client) { super(client, { - name: 'randodog', + name: 'randocat', group: 'fun', - memberName: 'randodog', - description: `Show a random doggy`, + memberName: 'randocat', + description: `Show a random cat`, }); } - async run(message, { city }) { - const { body } = await snekfetch.get(`https://random.dog/woof.json`); + async run(message) { + + fetch("https://random.dog/woof.json").then((response) => { + return response.json(); +}).then((response) => { const dogEmbed = new Discord.RichEmbed() .setColor("#ff9900") - .setTitle('Woof') - .setImage(body.url) + .setTitle('Meow') + .setImage(response.file) message.say(dogEmbed); - } -}; \ No newline at end of file + }); +}}; \ No newline at end of file diff --git a/commands/fun/reddit.js b/commands/fun/reddit.js index c8189c94..f40810e7 100644 --- a/commands/fun/reddit.js +++ b/commands/fun/reddit.js @@ -1,6 +1,6 @@ const { Command } = require('discord.js-commando'); const Discord = require('discord.js'); -const snekfetch = require('snekfetch'); +const fetch = require('node-fetch'); module.exports = class redditCommand extends Command { constructor(client) { super(client, { @@ -19,26 +19,29 @@ module.exports = class redditCommand extends Command { } async run(message, { sub }) { - const { body } = await snekfetch.get('https://www.reddit.com/r/' + sub + '.json?limit=100'); let /* the bodies hit the floor */ i = Math.floor((Math.random() * 10) + 1); let a = 0 - if (!body.data.children[1]) - return message.say('Not a valid subreddit') - while (body.data.children[i].data.post_hint !== 'image') { - i = Math.floor((Math.random() * 100) + 1); - a++ - if (a == 5) - return message.say("Could not find any images") - } - if (body.data.children[i].data.over_18 == true) - return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback \")") - const redditEmbed = new Discord.RichEmbed() - .setColor("#ff9900") - .setTitle(body.data.children[i].data.title) - .setImage(body.data.children[i].data.url) - .setURL('https://reddit.com' + body.data.children[i].data.permalink) - .setFooter(`⬆ ${body.data.children[i].data.ups} 💬 ${body.data.children[i].data.num_comments}`) - - message.say(redditEmbed); - } - } \ No newline at end of file + fetch('https://www.reddit.com/r/' + sub + '.json?limit=100').then((response) => { + return response.json(); + }).then((response) => { + if (!response.data) + return message.say('Not a valid subreddit') + while (response.data.children[i].data.post_hint !== 'image') { + i = Math.floor((Math.random() * 100) + 1); + a++ + if (a == 5) + return message.say("Could not find any images") + } + if (response.data.children[i].data.over_18 == true) + return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback \")") + const redditEmbed = new Discord.RichEmbed() + .setColor("#ff9900") + .setTitle(response.data.children[i].data.title) + .setImage(response.data.children[i].data.url) + .setURL('https://reddit.com' + response.data.children[i].data.permalink) + .setFooter(`⬆ ${response.data.children[i].data.ups} 💬 ${response.data.children[i].data.num_comments}`) + + message.say(redditEmbed); + } + +)}} \ No newline at end of file diff --git a/package.json b/package.json index fe8ffbb1..5e845b1e 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,6 @@ "dependencies": { "discord.js": "^11.4.2", "discord.js-commando": "^0.10.0", - "snekfetch": "^4.0.4" + "node-fetch": "^2.2.0" } }