From 4e492dfe2a3175fa9051b59032cf69ad89d5756e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Thu, 30 Apr 2020 02:18:15 -0400 Subject: [PATCH] Added npm command --- src/commands/mdn.ts | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/commands/mdn.ts diff --git a/src/commands/mdn.ts b/src/commands/mdn.ts new file mode 100644 index 0000000..cd5e084 --- /dev/null +++ b/src/commands/mdn.ts @@ -0,0 +1,54 @@ +import { Message } from 'eris'; +import axios from 'axios'; +import { Client, Command, RichEmbed } from '../class'; + +export default class Npm extends Command { + constructor(client: Client) { + super(client); + this.name = 'npm'; + this.description = 'Get information about npm modules.'; + this.usage = 'npm '; + this.permissions = 0; + this.guildOnly = false; + this.enabled = true; + } + + public async run(message: Message, args: string[]) { + try { + if (!args[0]) return this.error(message.channel, 'You need to specify a module name.'); + + const res = await axios.get(`https://registry.npmjs.com/${args[0]}`, { validateStatus: (_) => true }); + + if (res.status == 404) this.error(message.channel, 'Could not find the library, try something else.'); + + const { data } = res; + + const bugs: string = data.bugs.url || ''; + const description: string = data.description || 'None'; + const version: string = data['dist-tags'].latest || 'Unknown'; + const homepage: string = data.homepage || ''; + const license: string = data.license || 'None'; + const dependencies: string = Object.keys(data.versions[version].dependencies).join(', ') || 'None'; + const name: string = data.name || 'None'; + const repository: string = bugs.replace('/issues', '') || ''; + const creation: string = data.time.created ? new Date(data.time.created).toLocaleString('en') : 'None'; + const modification: string = data.time.modified ? new Date(data.time.modified).toLocaleString('en') : 'None'; + + const embed = new RichEmbed(); + embed.setColor(0xCC3534); + embed.setAuthor('NPM', 'https://i.imgur.com/ErKf5Y0.png', 'https://www.npmjs.com/'); + embed.setDescription(`[NPM](https://www.npmjs.com/package/${args[0]}) | [Homepage](${homepage}) | [Repository](${repository}) | [Bugs](${bugs})`); + embed.addField('Name', name, true); + embed.addField('Latest version', version, true); + embed.addField('License', license, true); + embed.addField('Description', description, false); + embed.addField('Dependencies', dependencies, false); + embed.addField('Creation Date', creation, true); + embed.addField('Modification Date', modification, true); + + return message.channel.createMessage({ embed }); + } catch (err) { + return this.client.util.handleError(err, message, this); + } + } +}