From 67c2e38b56dd7db722bcf3240ccf130d07b7475f Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sat, 23 Sep 2017 23:05:52 +0000 Subject: [PATCH] Random Person Command --- commands/random-res/history.js | 2 +- commands/random-res/new-york-times.js | 2 +- commands/random-res/random-person.js | 69 +++++++++++++++++++++++++++ commands/random/shorten-url.js | 2 +- package.json | 2 +- structures/PostgreSQL.js | 2 +- 6 files changed, 74 insertions(+), 5 deletions(-) create mode 100644 commands/random-res/random-person.js diff --git a/commands/random-res/history.js b/commands/random-res/history.js index cf67828c..f619434e 100644 --- a/commands/random-res/history.js +++ b/commands/random-res/history.js @@ -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.'); diff --git a/commands/random-res/new-york-times.js b/commands/random-res/new-york-times.js index 0b28c7f7..3ea90fef 100644 --- a/commands/random-res/new-york-times.js +++ b/commands/random-res/new-york-times.js @@ -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' diff --git a/commands/random-res/random-person.js b/commands/random-res/random-person.js new file mode 100644 index 00000000..58eafce3 --- /dev/null +++ b/commands/random-res/random-person.js @@ -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!`); + } + } +}; diff --git a/commands/random/shorten-url.js b/commands/random/shorten-url.js index c079b85f..d46b5442 100644 --- a/commands/random/shorten-url.js +++ b/commands/random/shorten-url.js @@ -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}>`); diff --git a/package.json b/package.json index 569344be..a499ec17 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "42.6.1", + "version": "42.7.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/PostgreSQL.js b/structures/PostgreSQL.js index 57a1574d..7998a837 100644 --- a/structures/PostgreSQL.js +++ b/structures/PostgreSQL.js @@ -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); }); }