Fortune Cookie and Name APIs

This commit is contained in:
Daniel Odendahl Jr
2017-08-17 22:19:40 +00:00
parent 80d86b3411
commit a395b07632
2 changed files with 22 additions and 17 deletions
+11 -3
View File
@@ -1,5 +1,6 @@
const Command = require('../../structures/Command');
const fortunes = require('../../assets/json/fortune');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
module.exports = class FortuneCommand extends Command {
constructor(client) {
@@ -12,7 +13,14 @@ module.exports = class FortuneCommand extends Command {
});
}
run(msg) {
return msg.say(fortunes[Math.floor(Math.random() * fortunes.length)]);
async run(msg) {
const { body } = await snekfetch
.get('http://fortunecookieapi.herokuapp.com/v1/cookie')
.query({ limit: 1 });
return msg.say(stripIndents`
${body[0].fortune.message}
Lotto: ${body[0].lotto.numbers.join(', ')}
Lesson: ${body[0].lesson.chinese} (${body[0].lesson.pronunciation}): ${body[0].lesson.english}
`);
}
};
+11 -14
View File
@@ -1,7 +1,7 @@
const Command = require('../../structures/Command');
const { last, male, female } = require('../../assets/json/name');
const snekfetch = require('snekfetch');
module.exports = class RandomNameCommand extends Command {
module.exports = class NameCommand extends Command {
constructor(client) {
super(client, {
name: 'name',
@@ -24,18 +24,15 @@ module.exports = class RandomNameCommand extends Command {
});
}
run(msg, args) { // eslint-disable-line consistent-return
async run(msg, args) {
const { gender } = args;
const lastName = last[Math.floor(Math.random() * last.length)];
if (gender === 'male') {
return msg.say(`${male[Math.floor(Math.random() * male.length)]} ${lastName}`);
} else if (gender === 'female') {
return msg.say(`${female[Math.floor(Math.random() * female.length)]} ${lastName}`);
} else if (gender === 'both') {
const genders = ['male', 'female'];
const rGender = genders[Math.floor(Math.random() * genders.length)];
if (rGender === 'male') return msg.say(`${male[Math.floor(Math.random() * male.length)]} ${lastName}`);
else if (rGender === 'female') return msg.say(`${female[Math.floor(Math.random() * female.length)]} ${lastName}`);
}
const { body } = await snekfetch
.get('http://namey.muffinlabs.com/name.json')
.query({
with_surname: true,
type: gender,
frequency: 'all'
});
return msg.say(body[0]);
}
};