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 1/3] 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); + } + } +} From fa9eaf060be5a6a47ffc5a4aac70fb2bc70093b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Thu, 30 Apr 2020 02:34:15 -0400 Subject: [PATCH 2/3] Added timestamp and footer to the embed --- src/commands/mdn.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/commands/mdn.ts b/src/commands/mdn.ts index cd5e084..5ef7e3c 100644 --- a/src/commands/mdn.ts +++ b/src/commands/mdn.ts @@ -36,6 +36,8 @@ export default class Npm extends Command { const embed = new RichEmbed(); embed.setColor(0xCC3534); + embed.setTimestamp(); + embed.setFooter(this.client.user.username, this.client.user.avatarURL); 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); From 1a98387fe6501739fd0b92d6b5875963964d7a1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?DedShot=E2=84=A2=239195?= Date: Thu, 30 Apr 2020 02:35:04 -0400 Subject: [PATCH 3/3] changed file name from mdn to npm --- src/commands/{mdn.ts => npm.ts} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/commands/{mdn.ts => npm.ts} (100%) diff --git a/src/commands/mdn.ts b/src/commands/npm.ts similarity index 100% rename from src/commands/mdn.ts rename to src/commands/npm.ts