mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-10 02:45:22 +02:00
Move code commands to code group
This commit is contained in:
@@ -0,0 +1,29 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const Docs = require('discord.js-docs');
|
||||
|
||||
module.exports = class DocstCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'docs',
|
||||
aliases: ['discord-js-docs', 'discord-js', 'djs', 'djs-docs'],
|
||||
group: 'code',
|
||||
memberName: 'docs',
|
||||
description: 'Searches the discord.js docs for your query.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What do you want to search the docs for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
const doc = await Docs.fetch('stable');
|
||||
const embed = doc.resolveEmbed(query);
|
||||
if (!embed) return msg.say('Could not find any results.');
|
||||
return msg.embed(embed);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,66 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const moment = require('moment');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { shorten, formatNumber } = require('../../util/Util');
|
||||
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: 'code',
|
||||
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',
|
||||
prompt: 'Who is the author of the repository?',
|
||||
type: 'string',
|
||||
parse: author => encodeURIComponent(author)
|
||||
},
|
||||
{
|
||||
key: 'repository',
|
||||
prompt: 'What is the name of the 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', 'https://i.imgur.com/e4HunUm.png', '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.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,53 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
|
||||
module.exports = class MDNCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'mdn',
|
||||
group: 'code',
|
||||
memberName: 'mdn',
|
||||
description: 'Searches MDN for your query.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
credit: [
|
||||
{
|
||||
name: 'MDN Web Docs',
|
||||
url: 'https://developer.mozilla.org/en-US/',
|
||||
reason: 'API'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What article would you like to search for?',
|
||||
type: 'string',
|
||||
parse: query => query.replaceAll('#', '.prototype.')
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('https://developer.mozilla.org/api/v1/search')
|
||||
.query({
|
||||
q: query,
|
||||
locale: 'en-US',
|
||||
highlight: false
|
||||
});
|
||||
if (!body.documents.length) return msg.say('Could not find any results.');
|
||||
const data = body.documents[0];
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0x066FAD)
|
||||
.setAuthor('MDN', 'https://i.imgur.com/DFGXabG.png', 'https://developer.mozilla.org/')
|
||||
.setURL(`https://developer.mozilla.org${data.mdn_url}`)
|
||||
.setTitle(data.title)
|
||||
.setDescription(data.summary);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,61 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const moment = require('moment');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { trimArray } = require('../../util/Util');
|
||||
|
||||
module.exports = class NPMCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'npm',
|
||||
group: 'code',
|
||||
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',
|
||||
prompt: 'What package would you like to get information on?',
|
||||
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', 'https://i.imgur.com/ErKf5Y0.png', '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.');
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,68 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const moment = require('moment');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const request = require('node-superfetch');
|
||||
const { decode: decodeHTML } = require('html-entities');
|
||||
const { formatNumber, embedURL } = require('../../util/Util');
|
||||
const { STACKOVERFLOW_KEY } = process.env;
|
||||
|
||||
module.exports = class StackOverflowCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'stack-overflow',
|
||||
group: 'code',
|
||||
memberName: 'stack-overflow',
|
||||
description: 'Searches Stack Overflow for your query.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
credit: [
|
||||
{
|
||||
name: 'Stack Exchange',
|
||||
url: 'https://stackexchange.com/',
|
||||
reason: 'API',
|
||||
reasonURL: 'https://api.stackexchange.com/docs'
|
||||
}
|
||||
],
|
||||
args: [
|
||||
{
|
||||
key: 'query',
|
||||
prompt: 'What question would you like to search for?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { query }) {
|
||||
try {
|
||||
const { body } = await request
|
||||
.get('http://api.stackexchange.com/2.2/search/advanced')
|
||||
.query({
|
||||
page: 1,
|
||||
pagesize: 1,
|
||||
order: 'asc',
|
||||
sort: 'relevance',
|
||||
answers: 1,
|
||||
q: query,
|
||||
site: 'stackoverflow',
|
||||
key: STACKOVERFLOW_KEY
|
||||
});
|
||||
if (!body.items.length) return msg.say('Could not find any results.');
|
||||
const data = body.items[0];
|
||||
const embed = new MessageEmbed()
|
||||
.setColor(0xF48023)
|
||||
.setAuthor('Stack Overflow', 'https://i.imgur.com/P2jAgE3.png', 'https://stackoverflow.com/')
|
||||
.setURL(data.link)
|
||||
.setTitle(decodeHTML(data.title))
|
||||
.addField('❯ ID', data.question_id, true)
|
||||
.addField('❯ Asker', embedURL(data.owner.display_name, data.owner.link), true)
|
||||
.addField('❯ Views', formatNumber(data.view_count), true)
|
||||
.addField('❯ Score', formatNumber(data.score), true)
|
||||
.addField('❯ Creation Date', moment.utc(data.creation_date * 1000).format('MM/DD/YYYY h:mm A'), true)
|
||||
.addField('❯ Last Activity',
|
||||
moment.utc(data.last_activity_date * 1000).format('MM/DD/YYYY h:mm A'), true);
|
||||
return msg.embed(embed);
|
||||
} catch (err) {
|
||||
return msg.reply(`Oh no, an error occurred: \`${err.message}\`. Try again later!`);
|
||||
}
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user