From 851c29eaee73cd40fd69bb6883b0a84a76a78c22 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Mon, 21 Aug 2017 21:02:04 +0000 Subject: [PATCH] GitHub Command --- commands/search/github.js | 60 +++++++++++++++++++++++++++++++++++++++ package.json | 4 +-- 2 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 commands/search/github.js diff --git a/commands/search/github.js b/commands/search/github.js new file mode 100644 index 00000000..9c6d8c2f --- /dev/null +++ b/commands/search/github.js @@ -0,0 +1,60 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); +const moment = require('moment'); +const { GITHUB_LOGIN } = process.env; + +module.exports = class GitHubCommand extends Command { + constructor(client) { + super(client, { + name: 'github', + group: 'search', + memberName: 'github', + description: 'Searches GitHub for info on a GitHub repository.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'author', + prompt: 'Who is the author of the repository?', + type: 'string' + }, + { + key: 'repository', + prompt: 'What is the name of the repository you would like to get information for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + const { author, repository } = args; + try { + const { body } = await snekfetch + .get(`https://${GITHUB_LOGIN}@api.github.com/repos/${author}/${repository}`); + const embed = new MessageEmbed() + .setColor(0xCB0000) + .setAuthor('GitHub', 'https://i.imgur.com/BCODHXd.png') + .setTitle(body.full_name) + .setURL(body.html_url) + .setDescription(body.description || 'No Description.') + .setThumbnail(body.owner.avatar_url || null) + .addField('❯ Stars', + body.stargazers_count, true) + .addField('❯ Forks', + body.forks, true) + .addField('❯ Issues', + body.open_issues, true) + .addField('❯ Language', + body.language || 'N/A', true) + .addField('❯ Created', + moment(body.created_at).format('MMMM Do YYYY'), true) + .addField('❯ Modified', + moment(body.updated_at).format('MMMM Do YYYY'), true); + return msg.embed(embed); + } catch (err) { + if (err.status === 404) return msg.say('Not Found.'); + throw err; + } + } +}; diff --git a/package.json b/package.json index da5e62b3..7feb62ec 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "30.7.3", + "version": "30.8.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { @@ -46,7 +46,7 @@ "zalgolize": "^1.2.4" }, "devDependencies": { - "eslint": "^4.4.1", + "eslint": "^4.5.0", "eslint-config-aqua": "^1.4.1" }, "eslintConfig": {