Added npm command
parent
ed866067b4
commit
392fadc093
|
@ -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 <module name>';
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue