mirror of
https://github.com/arthur-pbty/xiao.git
synced 2026-06-03 23:36:43 +02:00
Re-implement auto commands
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
const Command = require('../../structures/commands/AutoReply');
|
||||
|
||||
module.exports = class CanYouNotCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'can-you-not',
|
||||
aliases: ['can-u-not'],
|
||||
group: 'auto',
|
||||
memberName: 'can-you-not',
|
||||
description: 'Can YOU not?',
|
||||
patterns: [/^(can (you|u) not\??)$/i]
|
||||
});
|
||||
}
|
||||
|
||||
generateText() {
|
||||
return 'Can YOU not?';
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
const Command = require('../../structures/commands/AutoReply');
|
||||
|
||||
module.exports = class UnflipCommand extends Command {
|
||||
constructor(client, info) {
|
||||
super(client, {
|
||||
name: 'unflip',
|
||||
group: 'auto',
|
||||
memberName: 'unflip',
|
||||
description: 'Unflips a table.',
|
||||
patterns: [/\(╯°□°)╯︵ ┻━┻/i]
|
||||
});
|
||||
}
|
||||
|
||||
generateText() {
|
||||
return '┬─┬ノ( º _ ºノ)';
|
||||
}
|
||||
};
|
||||
@@ -1,17 +0,0 @@
|
||||
const Command = require('../../framework/Command');
|
||||
|
||||
module.exports = class CanYouNotCommand extends Command {
|
||||
constructor(client) {
|
||||
super(client, {
|
||||
name: 'can-you-not',
|
||||
aliases: ['can-u-not'],
|
||||
group: 'single',
|
||||
memberName: 'can-you-not',
|
||||
description: 'Can YOU not?'
|
||||
});
|
||||
}
|
||||
|
||||
run(msg) {
|
||||
return msg.say('Can YOU not?');
|
||||
}
|
||||
};
|
||||
+18
-1
@@ -52,8 +52,25 @@ module.exports = class CommandClient extends Client {
|
||||
if (this.blacklist.user.includes(msg.author.id)) return;
|
||||
if (msg.guild && this.blacklist.guild.includes(msg.guild.id)) return;
|
||||
if (msg.guild && !msg.channel.permissionsFor(this.user).has('SEND_MESSAGES')) return;
|
||||
if (!this.dispatcher.isCommand(msg)) return;
|
||||
|
||||
const patternCmd = this.dispatcher.isPatternCommand(msg);
|
||||
if (patternCmd) {
|
||||
try {
|
||||
const result = await patternCmd.run(msg);
|
||||
patternCmd.uses++;
|
||||
patternCmd.lastRun = new Date();
|
||||
this.emit('commandRun', patternCmd, result, msg);
|
||||
} catch (err) {
|
||||
this.emit('commandError', patternCmd, err, msg);
|
||||
await msg.reply(stripIndents`
|
||||
An error occurred while running this command: \`${err.message}\`.
|
||||
You shouldn't ever recieve an error like this.
|
||||
${this.invite ? `Please visit ${this.invite} for support.` : ''}
|
||||
`);
|
||||
}
|
||||
}
|
||||
|
||||
if (!this.dispatcher.isCommand(msg)) return;
|
||||
const parsed = await this.dispatcher.parseMessage(msg);
|
||||
if (typeof parsed === 'string') {
|
||||
const helpUsage = this.registry.commands.get('help').usage();
|
||||
|
||||
@@ -12,6 +12,7 @@ module.exports = class Command {
|
||||
this.details = options.details || null;
|
||||
this.flags = options.flags || [];
|
||||
this.args = options.args ? options.args.map(arg => new Argument(client, arg)) : [];
|
||||
this.patterns = options.patterns || [];
|
||||
this.clientPermissions = options.clientPermissions || [];
|
||||
this.userPermissions = options.userPermissions || [];
|
||||
this.ownerOnly = options.ownerOnly || false;
|
||||
|
||||
@@ -24,6 +24,13 @@ module.exports = class CommandDispatcher {
|
||||
return Boolean(command);
|
||||
}
|
||||
|
||||
isPatternCommand(msg) {
|
||||
const patternCommands = this.commands
|
||||
.filter(cmd => cmd.patterns.length && cmd.patterns.some(pattern => pattern.test(msg.content)));
|
||||
if (!patternCommands.size) return false;
|
||||
return patternCommands.first();
|
||||
}
|
||||
|
||||
async parseMessage(msg) {
|
||||
const matched = msg.content.match(this.commandPattern);
|
||||
const command = this.resolveCommand(matched[2].toLowerCase());
|
||||
|
||||
Reference in New Issue
Block a user