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 @@