Files
xiao/commands/random-res/name.js
T
2021-04-25 09:49:04 -04:00

51 lines
1.3 KiB
JavaScript

const Command = require('../../structures/Command');
const request = require('node-superfetch');
const { list } = require('../../util/Util');
const genders = ['male', 'female', 'both'];
module.exports = class NameCommand extends Command {
constructor(client) {
super(client, {
name: 'name',
group: 'random-res',
memberName: 'name',
description: 'Responds with a random name, with the gender of your choice.',
credit: [
{
name: 'Random User Generator',
url: 'https://randomuser.me/',
reason: 'API',
reasonURL: 'https://randomuser.me/documentation'
}
],
args: [
{
key: 'gender',
prompt: `Which gender do you want to generate a name for? Either ${list(genders, 'or')}.`,
type: 'string',
default: 'both',
oneOf: genders,
parse: gender => gender.toLowerCase()
}
]
});
}
async run(msg, { gender }) {
try {
const { body } = await request
.get('https://randomuser.me/api/')
.query({
inc: 'name',
noinfo: '',
gender: gender === 'both' ? '' : gender,
nat: 'AU,US,CA,GB'
});
const data = body.results[0].name;
return msg.say(`${data.first} ${data.last}`);
} catch (err) {
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};