mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-12 08:14:47 +02:00
Add features from Auto
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { js_beautify: beautify } = require('js-beautify');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class BeautifyCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'beautify',
|
||||
aliases: ['js-beautify'],
|
||||
group: 'code',
|
||||
memberName: 'lint',
|
||||
description: 'Beautifies code with js-beautify.',
|
||||
clientPermissions: ['READ_MESSAGE_HISTORY'],
|
||||
args: [
|
||||
{
|
||||
key: 'code',
|
||||
prompt: 'What code do you want to beautify?',
|
||||
type: 'code'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { code }) {
|
||||
return msg.reply(stripIndents`
|
||||
\`\`\`${code.lang || 'js'}
|
||||
${beautify(code.code)}
|
||||
\`\`\`
|
||||
`);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,38 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { Linter } = require('eslint');
|
||||
const linter = new Linter();
|
||||
const rules = linter.getRules();
|
||||
|
||||
module.exports = class LintRuleCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'lint-rule',
|
||||
aliases: ['eslint-rule'],
|
||||
group: 'code',
|
||||
memberName: 'lint-rule',
|
||||
description: 'Responds with information on an ESLint rule.',
|
||||
clientPermissions: ['EMBED_LINKS'],
|
||||
args: [
|
||||
{
|
||||
key: 'rule',
|
||||
prompt: 'Which rule would you like to get information on?',
|
||||
type: 'string',
|
||||
parse: rule => rule.toLowerCase().replace(/ /g, '-')
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
run(msg, { rule }) {
|
||||
if (!rules.has(rule)) return msg.say('Could not find any results.');
|
||||
const data = rules.get(rule).meta;
|
||||
const embed = new MessageEmbed()
|
||||
.setAuthor('ESLint', 'https://i.imgur.com/04GhEhU.png', 'https://eslint.org/')
|
||||
.setColor(0x3A33D1)
|
||||
.setTitle(`${rule} (${data.docs.category})`)
|
||||
.setURL(`https://eslint.org/docs/rules/${rule}`)
|
||||
.setDescription(data.docs.description);
|
||||
return msg.embed(embed);
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,50 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { Linter } = require('eslint');
|
||||
const linter = new Linter();
|
||||
const { stripIndents } = require('common-tags');
|
||||
const { trimArray } = require('../../util/Util');
|
||||
const { goodMessages, badMessages, defaultConfig } = require('../../assets/json/lint');
|
||||
|
||||
module.exports = class LintCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'lint',
|
||||
aliases: ['eslint'],
|
||||
group: 'code',
|
||||
memberName: 'lint',
|
||||
description: 'Lints code using ESLint.',
|
||||
clientPermissions: ['READ_MESSAGE_HISTORY'],
|
||||
args: [
|
||||
{
|
||||
key: 'code',
|
||||
prompt: 'What code do you want to lint?',
|
||||
type: 'code'
|
||||
}
|
||||
]
|
||||
});
|
||||
}
|
||||
|
||||
async run(msg, { code }) {
|
||||
if (!code.lang || ['js', 'javascript'].includes(code.lang)) {
|
||||
const errors = linter.verify(code.code, defaultConfig);
|
||||
if (!errors.length) return msg.reply(goodMessages[Math.floor(Math.random() * goodMessages.length)]);
|
||||
const errorMap = trimArray(errors.map(err => `\`[${err.line}:${err.column}] ${err.message}\``));
|
||||
return msg.reply(stripIndents`
|
||||
${badMessages[Math.floor(Math.random() * badMessages.length)]}
|
||||
${errorMap.join('\n')}
|
||||
`);
|
||||
}
|
||||
if (code.lang === 'json') {
|
||||
try {
|
||||
JSON.parse(code.code);
|
||||
return msg.reply(goodMessages[Math.floor(Math.random() * goodMessages.length)]);
|
||||
} catch (err) {
|
||||
return msg.reply(stripIndents`
|
||||
${badMessages[Math.floor(Math.random() * badMessages.length)]}
|
||||
\`${err.name}: ${err.message}\`
|
||||
`);
|
||||
}
|
||||
}
|
||||
return msg.reply('I don\'t know how to lint that language.');
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user