fixes to npm command

merge-requests/12/head
Matthew 2020-04-30 21:57:02 -04:00 committed by Bsian
parent 1eb05eff33
commit c20557a2ad
No known key found for this signature in database
GPG Key ID: 097FB9A291026091
1 changed files with 15 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import { Message } from 'eris';
import axios from 'axios'; import axios from 'axios';
import { Client, Command, RichEmbed } from '../class'; import { Client, Command, RichEmbed } from '../class';
export default class Npm extends Command { export default class NPM extends Command {
constructor(client: Client) { constructor(client: Client) {
super(client); super(client);
this.name = 'npm'; 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 }); 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 { data } = res;
const bugs: string = data.bugs.url || ''; const bugs: string = data.bugs?.url || '';
const description: string = data.description || 'None'; 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 homepage: string = data.homepage || '';
const license: string = data.license || 'None'; let license: string = 'None';
const dependencies: string = Object.keys(data.versions[version].dependencies).join(', ') || '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 name: string = data.name || 'None';
const repository: string = bugs.replace('/issues', '') || ''; const repository: string = bugs.replace('/issues', '') || '';
const creation: string = data.time.created ? new Date(data.time.created).toLocaleString('en') : 'None'; 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.setTimestamp();
embed.setFooter(this.client.user.username, this.client.user.avatarURL); embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setAuthor('NPM', 'https://i.imgur.com/ErKf5Y0.png', 'https://www.npmjs.com/'); 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('Name', name, true);
embed.addField('Latest version', version, true); embed.addField('Latest version', version, true);
embed.addField('License', license, true); embed.addField('License', license, true);