fixes to npm command
parent
b6832766c1
commit
5ffc3a5eb7
|
@ -2,7 +2,7 @@ import { Message } from 'eris';
|
|||
import axios from 'axios';
|
||||
import { Client, Command, RichEmbed } from '../class';
|
||||
|
||||
export default class Npm extends Command {
|
||||
export default class NPM extends Command {
|
||||
constructor(client: Client) {
|
||||
super(client);
|
||||
this.name = 'npm';
|
||||
|
@ -19,16 +19,24 @@ export default class Npm extends Command {
|
|||
|
||||
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.');
|
||||
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 bugs: string = data.bugs?.url || '';
|
||||
const description: string = data.description || 'None';
|
||||
const version: string = data['dist-tags'].latest || 'Unknown';
|
||||
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';
|
||||
let license: string = 'None';
|
||||
if (typeof data.license === 'object') {
|
||||
license = data.license.type;
|
||||
} else if (typeof data.license === 'string') {
|
||||
license = data.license;
|
||||
}
|
||||
let dependencies: string = 'None';
|
||||
if (version !== 'Unknown' && data.versions[version].dependencies) {
|
||||
dependencies = Object.keys(data.versions[version].dependencies).join(', ');
|
||||
}
|
||||
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';
|
||||
|
@ -39,7 +47,7 @@ export default class Npm extends Command {
|
|||
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.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);
|
||||
|
|
Loading…
Reference in New Issue