mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-09 01:04:16 +02:00
Fortune Cookie and Name APIs
This commit is contained in:
@@ -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
@@ -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]);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user