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 { Command } = require('discord.js-commando');
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const fetch = require('node-fetch')
|
||||||
module.exports = class RandoCatCommand extends Command {
|
module.exports = class RandoDogCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'randocat',
|
name: 'randodog',
|
||||||
group: 'fun',
|
group: 'fun',
|
||||||
memberName: 'randocat',
|
memberName: 'randodog',
|
||||||
description: `Show a random cat`,
|
description: `Show a random dog`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(message, { city }) {
|
async run(message) {
|
||||||
const { body } = await snekfetch.get(`http://aws.random.cat/meow`);
|
|
||||||
const dogEmbed = new Discord.RichEmbed()
|
fetch("http://aws.random.cat/meow").then((response) => {
|
||||||
|
return response.json();
|
||||||
|
}).then((response) => {
|
||||||
|
const catEmbed = new Discord.RichEmbed()
|
||||||
.setColor("#ff9900")
|
.setColor("#ff9900")
|
||||||
.setTitle('Meow')
|
.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 { Command } = require('discord.js-commando');
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const fetch = require('node-fetch')
|
||||||
module.exports = class RandoDogCommand extends Command {
|
module.exports = class RandoCatCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
name: 'randodog',
|
name: 'randocat',
|
||||||
group: 'fun',
|
group: 'fun',
|
||||||
memberName: 'randodog',
|
memberName: 'randocat',
|
||||||
description: `Show a random doggy`,
|
description: `Show a random cat`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(message, { city }) {
|
async run(message) {
|
||||||
const { body } = await snekfetch.get(`https://random.dog/woof.json`);
|
|
||||||
|
fetch("https://random.dog/woof.json").then((response) => {
|
||||||
|
return response.json();
|
||||||
|
}).then((response) => {
|
||||||
const dogEmbed = new Discord.RichEmbed()
|
const dogEmbed = new Discord.RichEmbed()
|
||||||
.setColor("#ff9900")
|
.setColor("#ff9900")
|
||||||
.setTitle('Woof')
|
.setTitle('Meow')
|
||||||
.setImage(body.url)
|
.setImage(response.file)
|
||||||
|
|
||||||
|
|
||||||
message.say(dogEmbed);
|
message.say(dogEmbed);
|
||||||
}
|
});
|
||||||
};
|
}};
|
|
@ -1,6 +1,6 @@
|
||||||
const { Command } = require('discord.js-commando');
|
const { Command } = require('discord.js-commando');
|
||||||
const Discord = require('discord.js');
|
const Discord = require('discord.js');
|
||||||
const snekfetch = require('snekfetch');
|
const fetch = require('node-fetch');
|
||||||
module.exports = class redditCommand extends Command {
|
module.exports = class redditCommand extends Command {
|
||||||
constructor(client) {
|
constructor(client) {
|
||||||
super(client, {
|
super(client, {
|
||||||
|
@ -19,26 +19,29 @@ module.exports = class redditCommand extends Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
async run(message, { sub }) {
|
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 /* the bodies hit the floor */ i = Math.floor((Math.random() * 10) + 1);
|
||||||
let a = 0
|
let a = 0
|
||||||
if (!body.data.children[1])
|
fetch('https://www.reddit.com/r/' + sub + '.json?limit=100').then((response) => {
|
||||||
return message.say('Not a valid subreddit')
|
return response.json();
|
||||||
while (body.data.children[i].data.post_hint !== 'image') {
|
}).then((response) => {
|
||||||
i = Math.floor((Math.random() * 100) + 1);
|
if (!response.data)
|
||||||
a++
|
return message.say('Not a valid subreddit')
|
||||||
if (a == 5)
|
while (response.data.children[i].data.post_hint !== 'image') {
|
||||||
return message.say("Could not find any images")
|
i = Math.floor((Math.random() * 100) + 1);
|
||||||
}
|
a++
|
||||||
if (body.data.children[i].data.over_18 == true)
|
if (a == 5)
|
||||||
return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback <your feedback>\")")
|
return message.say("Could not find any images")
|
||||||
const redditEmbed = new Discord.RichEmbed()
|
}
|
||||||
.setColor("#ff9900")
|
if (response.data.children[i].data.over_18 == true)
|
||||||
.setTitle(body.data.children[i].data.title)
|
return message.say("No nsfw ( if you want a nsfw version of this commands use the feedback commands \"haha feedback <your feedback>\")")
|
||||||
.setImage(body.data.children[i].data.url)
|
const redditEmbed = new Discord.RichEmbed()
|
||||||
.setURL('https://reddit.com' + body.data.children[i].data.permalink)
|
.setColor("#ff9900")
|
||||||
.setFooter(`⬆ ${body.data.children[i].data.ups} 💬 ${body.data.children[i].data.num_comments}`)
|
.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": {
|
"dependencies": {
|
||||||
"discord.js": "^11.4.2",
|
"discord.js": "^11.4.2",
|
||||||
"discord.js-commando": "^0.10.0",
|
"discord.js-commando": "^0.10.0",
|
||||||
"snekfetch": "^4.0.4"
|
"node-fetch": "^2.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue