mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-11 03:14:35 +02:00
Try out eslint v9
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const moment = require('moment');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { shorten, formatNumber } = require('../../util/Util');
|
||||
const logos = require('../../assets/json/logos');
|
||||
const { GITHUB_ACCESS_TOKEN } = process.env;
|
||||
|
||||
module.exports = class GithubCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'github',
|
||||
aliases: ['repo', 'gh', 'github-repo', 'gh-repo'],
|
||||
group: 'search',
|
||||
memberName: 'github',
|
||||
description: 'Responds with information on a GitHub repository.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
credit: [
|
||||
{
|
||||
name: 'GitHub',
|
||||
url: 'https://github.com/',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://developer.github.com/v3/'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'author',
|
||||
type: 'string',
|
||||
parse: author => encodeURIComponent(author)
|
||||
},
|
||||
{
|
||||
key: 'repository',
|
||||
type: 'string',
|
||||
parse: repository => encodeURIComponent(repository)
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { author, repository }) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get(`https://api.github.com/repos/${author}/${repository}`)
|
||||
.set({ Authorization: `token ${GITHUB_ACCESS_TOKEN}` });
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xFFFFFF)
|
||||
.setAuthor('GitHub', logos.github, 'https://github.com/')
|
||||
.setTitle(body.full_name)
|
||||
.setURL(body.html_url)
|
||||
.setDescription(body.description ? shorten(body.description) : 'No description.')
|
||||
.setThumbnail(body.owner.avatar_url)
|
||||
.addField('❯ Stars', formatNumber(body.stargazers_count), true)
|
||||
.addField('❯ Forks', formatNumber(body.forks), true)
|
||||
.addField('❯ Issues', formatNumber(body.open_issues), true)
|
||||
.addField('❯ Language', body.language || '???', true)
|
||||
.addField('❯ Creation Date', moment.utc(body.created_at).format('MM/DD/YYYY h:mm A'), true)
|
||||
.addField('❯ Modification Date', moment.utc(body.updated_at).format('MM/DD/YYYY h:mm A'), true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
const Command = require('../../framework/Command');
|
||||
const moment = require('moment');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { trimArray } = require('../../util/Util');
|
||||
const logos = require('../../assets/json/logos');
|
||||
|
||||
module.exports = class NPMCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'npm',
|
||||
group: 'search',
|
||||
memberName: 'npm',
|
||||
description: 'Responds with information on an NPM package.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
credit: [
|
||||
{
|
||||
name: 'npm',
|
||||
url: 'https://www.npmjs.com/',
|
||||
reason: 'API'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'pkg',
|
||||
label: 'package',
|
||||
type: 'string',
|
||||
parse: pkg => encodeURIComponent(pkg.replaceAll(' ', '-'))
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { pkg }) {
|
||||
try {
|
||||
const { body } = await request.get(`https://registry.npmjs.com/${pkg}`);
|
||||
if (body.time.unpublished) return msg.say('This package no longer exists.');
|
||||
const version = body.versions[body['dist-tags'].latest];
|
||||
const maintainers = trimArray(body.maintainers.map(user => user.name));
|
||||
const dependencies = version.dependencies ? trimArray(Object.keys(version.dependencies)) : null;
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xCB0000)
|
||||
.setAuthor('NPM', logos.npm, 'https://www.npmjs.com/')
|
||||
.setTitle(body.name)
|
||||
.setURL(`https://www.npmjs.com/package/${pkg}`)
|
||||
.setDescription(body.description || 'No description.')
|
||||
.addField('❯ Version', body['dist-tags'].latest, true)
|
||||
.addField('❯ License', body.license || 'None', true)
|
||||
.addField('❯ Author', body.author ? body.author.name : '???', true)
|
||||
.addField('❯ Creation Date', moment.utc(body.time.created).format('MM/DD/YYYY h:mm A'), true)
|
||||
.addField('❯ Modification Date', moment.utc(body.time.modified).format('MM/DD/YYYY h:mm A'), true)
|
||||
.addField('❯ Main File', version.main || 'index.js', true)
|
||||
.addField('❯ Dependencies', dependencies && dependencies.length ? dependencies.join(', ') : 'None')
|
||||
.addField('❯ Maintainers', maintainers.join(', '));
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
if (err.status === 404) return msg.say('Could not find any results.');
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user