From 0c1f3fd2caa9a6e71dd76af30ef509f3e47b93e8 Mon Sep 17 00:00:00 2001 From: Daniel Odendahl Jr Date: Sun, 23 Jul 2017 00:22:07 +0000 Subject: [PATCH] NPM Command --- commands/search/bot-info.js | 2 +- commands/search/npm.js | 50 +++++++++++++++++++++++++++++++++++++ html/carbonfeat.html | 1 + html/discordbots.html | 1 + package.json | 2 +- 5 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 commands/search/npm.js diff --git a/commands/search/bot-info.js b/commands/search/bot-info.js index 5a4ed368..86e2aba4 100644 --- a/commands/search/bot-info.js +++ b/commands/search/bot-info.js @@ -41,7 +41,7 @@ module.exports = class BotSearchCommand extends Command { body.prefix, true); return msg.embed(embed); } catch (err) { - if (err.message === '404 Not Found') return msg.say('Bot Not Found.'); + if (err.status === 404) return msg.say('Bot Not Found.'); else throw err; } } diff --git a/commands/search/npm.js b/commands/search/npm.js new file mode 100644 index 00000000..0ec6948b --- /dev/null +++ b/commands/search/npm.js @@ -0,0 +1,50 @@ +const Command = require('../../structures/Command'); +const { MessageEmbed } = require('discord.js'); +const snekfetch = require('snekfetch'); + +module.exports = class NPMCommand extends Command { + constructor(client) { + super(client, { + name: 'npm', + group: 'search', + memberName: 'npm', + description: 'Searches NPM for info on an NPM package.', + clientPermissions: ['EMBED_LINKS'], + args: [ + { + key: 'query', + prompt: 'What package do you want to get information for?', + type: 'string' + } + ] + }); + } + + async run(msg, args) { + try { + const { query } = args; + const { body } = await snekfetch + .get(`https://registry.npmjs.com/${query}`); + const embed = new MessageEmbed() + .setColor(0xCB0000) + .setAuthor('NPM', 'https://i.imgur.com/BCODHXd.png') + .setTitle(body.name) + .setURL(`https://www.npmjs.com/package/${query}`) + .setDescription(body.description) + .addField('❯ Version', + body['dist-tags'].latest, true) + .addField('❯ License', + body.license, true) + .addField('❯ Author', + body.author.name, true) + .addField('❯ Keywords', + body.keywords.join(', ')) + .addField('❯ Maintainers', + body.maintainers.map((user) => user.name).join(', ')); + return msg.embed(embed); + } catch (err) { + if (err.status === 404) return msg.say('Not Found.'); + else throw err; + } + } +}; diff --git a/html/carbonfeat.html b/html/carbonfeat.html index e7c7b3c9..2334dd01 100644 --- a/html/carbonfeat.html +++ b/html/carbonfeat.html @@ -47,6 +47,7 @@
  • Konachan
  • Google Maps
  • Neopets
  • +
  • NPM
  • osu!
  • Recipe Puppy
  • Rule34
  • diff --git a/html/discordbots.html b/html/discordbots.html index 00d70c27..ed01629a 100644 --- a/html/discordbots.html +++ b/html/discordbots.html @@ -44,6 +44,7 @@
  • Konachan
  • Google Maps
  • Neopets
  • +
  • NPM
  • osu!
  • Recipe Puppy
  • Rule34
  • diff --git a/package.json b/package.json index cdd2b74d..4a5b803c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "27.3.2", + "version": "27.4.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": {