Merge branch 'dev' of gitlab.libraryofcode.org:engineering/communityrelations into dev

merge-requests/10/head
Matthew 2020-04-30 21:36:20 -04:00
commit b6832766c1
No known key found for this signature in database
GPG Key ID: 766BE43AE75F7559
1 changed files with 56 additions and 0 deletions

56
src/commands/npm.ts Normal file
View File

@ -0,0 +1,56 @@
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.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);
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);
}
}
}