Replaced snekfetch by node-fetch
This commit is contained in:
parent
c652c2b671
commit
b1d278ba2d
4 changed files with 55 additions and 46 deletions
|
@ -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);
|
||||
}
|
||||
};
|
||||
message.say(catEmbed);
|
||||
});
|
||||
}};
|
|
@ -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);
|
||||
}
|
||||
};
|
||||
});
|
||||
}};
|
|
@ -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 <your 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}`)
|
||||
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 <your 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);
|
||||
}
|
||||
}
|
||||
message.say(redditEmbed);
|
||||
}
|
||||
|
||||
)}}
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue