mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-18 13:56:25 +02:00
Framework Rewrite
This commit is contained in:
@@ -1,21 +0,0 @@
|
||||
const Command = require('../../structures/commands/AutoReply');
|
||||
|
||||
module.exports = class NoUCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'no-u',
|
||||
aliases: ['no-you'],
|
||||
group: 'auto',
|
||||
memberName: 'no-u',
|
||||
description: 'no u',
|
||||
patterns: [/^n+o+ u+$/i]
|
||||
});
|
||||
}
|
||||
|
||||
generateText(fromPattern) {
|
||||
if (!fromPattern) return 'no u';
|
||||
const chance = Boolean(Math.floor(Math.random() * 2));
|
||||
if (chance) return null;
|
||||
return 'no u';
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
const Command = require('../../structures/commands/AutoReply');
|
||||
|
||||
module.exports = class UnflipCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'unflip',
|
||||
group: 'auto',
|
||||
memberName: 'unflip',
|
||||
description: 'Unflips a flipped table.',
|
||||
patterns: [/\(╯°□°)╯︵ ┻━┻/i]
|
||||
});
|
||||
}
|
||||
|
||||
generateText() {
|
||||
return '┬─┬ ノ( ゜-゜ノ)';
|
||||
}
|
||||
};
|
||||
@@ -1,7 +1,7 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const moment = require('moment');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { util: { permissions } } = require('discord.js-commando');
|
||||
const permissions = require('../../assets/json/permission-names');
|
||||
|
||||
module.exports = class RoleCommand extends Command {
|
||||
constructor(client) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed } = require('discord.js');
|
||||
const { util: { permissions } } = require('discord.js-commando');
|
||||
const permissions = require('../../assets/json/permission-names');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class HelpCommand extends Command {
|
||||
@@ -31,7 +31,7 @@ module.exports = class HelpCommand extends Command {
|
||||
const embed = new MessageEmbed()
|
||||
.setTitle(`Command List (Page ${i + 1})`)
|
||||
.setDescription(stripIndents`
|
||||
To run a command, use ${msg.anyUsage('<command>')}.
|
||||
To run a command, use ${this.usage()}.
|
||||
${nsfw ? '' : 'Use in an NSFW channel to see NSFW commands.'}
|
||||
`)
|
||||
.setColor(0x00AE86);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { MessageEmbed, version: djsVersion } = require('discord.js');
|
||||
const { version: commandoVersion } = require('discord.js-commando');
|
||||
const moment = require('moment');
|
||||
require('moment-duration-format');
|
||||
const { formatNumber, embedURL } = require('../../util/Util');
|
||||
@@ -39,7 +38,7 @@ module.exports = class InfoCommand extends Command {
|
||||
.addField('❯ Version', `v${version}`, true)
|
||||
.addField('❯ Node.js', process.version, true)
|
||||
.addField('❯ Discord.js', `v${djsVersion}`, true)
|
||||
.addField('❯ Commando', `v${commandoVersion}`, true)
|
||||
.addField('❯ Framework', 'Custom', true)
|
||||
.addField('❯ Dependencies', Object.keys(deps).sort().join(', '));
|
||||
return msg.embed(embed);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
const Command = require('../../structures/Command');
|
||||
const { stripIndents } = require('common-tags');
|
||||
|
||||
module.exports = class PrefixCommand extends Command {
|
||||
constructor(client) {
|
||||
@@ -14,9 +13,6 @@ module.exports = class PrefixCommand extends Command {
|
||||
|
||||
run(msg) {
|
||||
const prefix = msg.guild ? msg.guild.commandPrefix : this.client.commandPrefix;
|
||||
return msg.reply(stripIndents`
|
||||
${prefix ? `The command prefix is \`${prefix}\`.` : 'There is no command prefix.'}
|
||||
To run a command, use ${msg.anyUsage('<command>')}.
|
||||
`);
|
||||
return msg.reply(prefix ? `The command prefix is \`${prefix}\`.` : 'There is no command prefix.');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -18,7 +18,7 @@ module.exports = class UnknownCommandCommand extends Command {
|
||||
run(msg) {
|
||||
if (!msg.guild) return null;
|
||||
const commands = this.makeCommandArray(this.client.isOwner(msg.author), msg.channel.nsfw);
|
||||
const command = msg.content.match(this.client.dispatcher._commandPatterns[this.client.commandPrefix]);
|
||||
const command = msg.content.match(this.client.dispatcher.commandPattern);
|
||||
const str = command ? command[2] : msg.content.split(' ')[0];
|
||||
const results = didYouMean(str, commands, { returnType: ReturnTypeEnums.ALL_SORTED_MATCHES });
|
||||
return msg.reply(stripIndents`
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
// Credit: https://github.com/discordjs/Commando/blob/master/src/commands/util/eval.js
|
||||
const util = require('util');
|
||||
const discord = require('discord.js');
|
||||
const tags = require('common-tags');
|
||||
const { escapeRegex } = require('../../util/Util');
|
||||
const Command = require('../../structures/Command');
|
||||
|
||||
const nl = '!!NL!!';
|
||||
const nlPattern = new RegExp(nl, 'g');
|
||||
|
||||
module.exports = class EvalCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'eval',
|
||||
group: 'util',
|
||||
memberName: 'eval',
|
||||
description: 'Executes JavaScript code.',
|
||||
details: 'Only the bot owner(s) may use this command.',
|
||||
ownerOnly: true,
|
||||
args: [
|
||||
{
|
||||
key: 'script',
|
||||
prompt: 'What code would you like to evaluate?',
|
||||
type: 'string'
|
||||
}
|
||||
]
|
||||
});
|
||||
|
||||
this.lastResult = null;
|
||||
Object.defineProperty(this, '_sensitivePattern', { value: null, configurable: true });
|
||||
}
|
||||
|
||||
run(msg, args) {
|
||||
// Make a bunch of helpers
|
||||
/* eslint-disable no-unused-vars */
|
||||
const message = msg;
|
||||
const client = msg.client;
|
||||
const lastResult = this.lastResult;
|
||||
const doReply = val => {
|
||||
if (val instanceof Error) {
|
||||
msg.reply(`Callback error: \`${val}\``);
|
||||
} else {
|
||||
const result = this.makeResultMessages(val, process.hrtime(this.hrStart));
|
||||
if (Array.isArray(result)) {
|
||||
for(const item of result) msg.reply(item);
|
||||
} else {
|
||||
msg.reply(result);
|
||||
}
|
||||
}
|
||||
};
|
||||
/* eslint-enable no-unused-vars */
|
||||
|
||||
// Remove any surrounding code blocks before evaluation
|
||||
if (args.script.startsWith('```') && args.script.endsWith('```')) {
|
||||
args.script = args.script.replace(/(^.*?\s)|(\n.*$)/g, '');
|
||||
}
|
||||
|
||||
// Run the code and measure its execution time
|
||||
let hrDiff;
|
||||
try {
|
||||
const hrStart = process.hrtime();
|
||||
this.lastResult = eval(args.script);
|
||||
hrDiff = process.hrtime(hrStart);
|
||||
} catch (err) {
|
||||
return msg.reply(`Error while evaluating: \`${err}\``);
|
||||
}
|
||||
|
||||
// Prepare for callback time and respond
|
||||
this.hrStart = process.hrtime();
|
||||
const result = this.makeResultMessages(this.lastResult, hrDiff, args.script);
|
||||
if (Array.isArray(result)) {
|
||||
return result.map(item => msg.reply(item));
|
||||
} else {
|
||||
return msg.reply(result);
|
||||
}
|
||||
}
|
||||
|
||||
makeResultMessages(result, hrDiff, input = null) {
|
||||
const inspected = util.inspect(result, { depth: 0 })
|
||||
.replace(nlPattern, '\n')
|
||||
.replace(this.sensitivePattern, '--snip--');
|
||||
const split = inspected.split('\n');
|
||||
const last = inspected.length - 1;
|
||||
const prependPart = inspected[0] !== '{' && inspected[0] !== '[' && inspected[0] !== "'" ? split[0] : inspected[0];
|
||||
const appendPart = inspected[last] !== '}' && inspected[last] !== ']' && inspected[last] !== "'" ?
|
||||
split[split.length - 1] :
|
||||
inspected[last];
|
||||
const prepend = `\`\`\`javascript\n${prependPart}\n`;
|
||||
const append = `\n${appendPart}\n\`\`\``;
|
||||
if (input) {
|
||||
return discord.splitMessage(tags.stripIndents`
|
||||
*Executed in ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
||||
\`\`\`javascript
|
||||
${inspected}
|
||||
\`\`\`
|
||||
`, { maxLength: 1900, prepend, append });
|
||||
} else {
|
||||
return discord.splitMessage(tags.stripIndents`
|
||||
*Callback executed after ${hrDiff[0] > 0 ? `${hrDiff[0]}s ` : ''}${hrDiff[1] / 1000000}ms.*
|
||||
\`\`\`javascript
|
||||
${inspected}
|
||||
\`\`\`
|
||||
`, { maxLength: 1900, prepend, append });
|
||||
}
|
||||
}
|
||||
|
||||
get sensitivePattern() {
|
||||
if (!this._sensitivePattern) {
|
||||
const client = this.client;
|
||||
let pattern = '';
|
||||
if (client.token) pattern += escapeRegex(client.token);
|
||||
Object.defineProperty(this, '_sensitivePattern', { value: new RegExp(pattern, 'gi'), configurable: false });
|
||||
}
|
||||
return this._sensitivePattern;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user