Random Person Command

This commit is contained in:
Daniel Odendahl Jr
2017-09-23 23:05:52 +00:00
parent f44f383397
commit 67c2e38b56
6 changed files with 74 additions and 5 deletions
+1 -1
View File
@@ -36,7 +36,7 @@ module.exports = class HistoryCommand extends Command {
.setTimestamp()
.setDescription(`${event.year}: ${event.text}`)
.addField(' See More',
event.links.map(link => `${link.title}: ${link.link.replace(/\)/g, '%29')}`).join('\n'));
event.links.map(link => `[${link.title}](${link.link.replace(/\)/g, '%29')})`).join(', '));
return msg.embed(embed);
} catch (err) {
if (err.status === 404 || err.status === 500) return msg.say('Could not find any results.');
+1 -1
View File
@@ -26,7 +26,7 @@ module.exports = class NewYorkTimesCommand extends Command {
async run(msg, { query }) {
try {
const fetch = snekfetch
.get(`https://api.nytimes.com/svc/search/v2/articlesearch.json`)
.get('https://api.nytimes.com/svc/search/v2/articlesearch.json')
.query({
'api-key': NYTIMES_KEY,
sort: 'newest'
+69
View File
@@ -0,0 +1,69 @@
const Command = require('../../structures/Command');
const { MessageEmbed } = require('discord.js');
const snekfetch = require('snekfetch');
const { stripIndents } = require('common-tags');
const { list } = require('../../structures/Util');
const genders = ['male', 'female', 'both'];
module.exports = class RandomPersonCommand extends Command {
constructor(client) {
super(client, {
name: 'random-person',
group: 'random-res',
memberName: 'random-person',
description: 'Responds with a randomly generated person.',
clientPermissions: ['EMBED_LINKS'],
args: [
{
key: 'gender',
prompt: `What gender do you want to generate a name for? Either ${list(genders, 'or')}.`,
type: 'string',
default: 'both'
}
]
});
}
async run(msg, { gender }) {
try {
const { body } = await snekfetch
.get('https://randomuser.me/api/')
.query({
gender,
noinfo: ''
});
const data = body.results[0];
const embed = new MessageEmbed()
.setColor(0x9797FF)
.setThumbnail(data.picture.large)
.addField(' First Name',
data.name.first.toUpperCase(), true)
.addField(' Last Name',
data.name.last.toUpperCase(), true)
.addField(' Title',
data.name.title.toUpperCase(), true)
.addField(' Gender',
data.gender.toUpperCase(), true)
.addField(' Username',
data.login.username, true)
.addField(' Password',
data.login.password, true)
.addField(' Email',
data.email, true)
.addField(' Phone',
data.phone, true)
.addField(' Cell',
data.cell, true)
.addField(' Birthday',
new Date(data.dob).toDateString(), true)
.addField(' Address',
stripIndents`
${data.location.street.toUpperCase()}
${data.location.city.toUpperCase()}, ${data.location.state.toUpperCase()} ${data.location.postcode}
`);
return msg.embed(embed);
} catch (err) {
return msg.say(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
}
}
};
+1 -1
View File
@@ -23,7 +23,7 @@ module.exports = class ShortenURLCommand extends Command {
async run(msg, { url }) {
try {
const { body } = await snekfetch
.post(`https://www.googleapis.com/urlshortener/v1/url`)
.post('https://www.googleapis.com/urlshortener/v1/url')
.query({ key: GOOGLE_KEY })
.send({ longUrl: url });
return msg.say(`<${body.id}>`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "42.6.1",
"version": "42.7.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {
+1 -1
View File
@@ -17,7 +17,7 @@ class Database {
)
.catch(err => {
console.error(`[DATABASE] Unable to connect: ${err}`);
console.error(`[DATABASE] Reconnecting in 5 seconds...`);
console.error('[DATABASE] Reconnecting in 5 seconds...');
setTimeout(() => Database.start(), 5000);
});
}