Files
xiao/commands/search/npm.js
T
Daniel Odendahl Jr 0c1f3fd2ca NPM Command
2017-07-23 00:22:07 +00:00

51 lines
1.8 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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;
}
}
};