diff --git a/src/commands/settings/SimilarMessagesCommand.js b/src/commands/settings/SimilarMessagesCommand.js index b6874b197..28f15f617 100644 --- a/src/commands/settings/SimilarMessagesCommand.js +++ b/src/commands/settings/SimilarMessagesCommand.js @@ -1,43 +1,23 @@ -const Command = require('../Command'); +const ConfigCommand = require('../ConfigCommand'); -class SimilarMessagesCommand extends Command { +class SimilarMessagesCommand extends ConfigCommand { static description = 'Configure message repeated message protection (deletes similar messages)'; - static usage = '|off|status'; + static usage = 'get|set|disable'; static comment = 'Count is the number of similar messages(1-60) a user is allowed to send per minute.'; - static names = ['similarmessages','similar','repeatedmessages','repeated']; + static names = ['similarmessages']; static userPerms = ['MANAGE_GUILD']; - async execute() { - if (this.args.length !== 1) { - await this.sendUsage(); - return; - } - - switch (this.args[0].toLowerCase()) { - case 'off': - this.guildConfig.similarMessages = -1; - await this.guildConfig.save(); - await this.reply('Disabled repeated message protection!'); - break; - case 'status': - await this.reply(`Repeated message protection is currently ${this.guildConfig.similarMessages === -1 ? 'disabled' : `set to ${this.guildConfig.similarMessages} similar messages per minute`}.`); - break; - default: { - const count = parseInt(this.args[0]); - if (count > 0 && count <= 60) { - this.guildConfig.similarMessages = count; - await this.guildConfig.save(); - await this.reply(`Enabled repeated message protection! Users can now only send ${count} similar messages per minute.`); - } else { - await this.sendUsage(); - } - } - } + static getSubCommands() { + return [ + require('./similarmessages/GetSimilarMessages'), + require('./similarmessages/SetSimilarMessages'), + require('./similarmessages/DisableSimilarMessages'), + ]; } } diff --git a/src/commands/settings/similarmessages/DisableSimilarMessages.js b/src/commands/settings/similarmessages/DisableSimilarMessages.js new file mode 100644 index 000000000..1afd5b9b0 --- /dev/null +++ b/src/commands/settings/similarmessages/DisableSimilarMessages.js @@ -0,0 +1,15 @@ +const SubCommand = require('../../SubCommand'); + +class DisableSimilarMessages extends SubCommand { + static names = ['disable', 'off']; + + static description = 'Disable repeated message protection.'; + + async execute() { + this.guildConfig.similarMessages = -1; + await this.guildConfig.save(); + await this.reply('Disabled repeated message protection!'); + } +} + +module.exports = DisableSimilarMessages; diff --git a/src/commands/settings/similarmessages/GetSimilarMessages.js b/src/commands/settings/similarmessages/GetSimilarMessages.js new file mode 100644 index 000000000..2ac23fa36 --- /dev/null +++ b/src/commands/settings/similarmessages/GetSimilarMessages.js @@ -0,0 +1,16 @@ +const GetConfigCommand = require('../../GetConfigCommand'); + +class GetSimilarMessages extends GetConfigCommand { + static names = ['get','show']; + + async execute() { + if (this.guildConfig.similarMessages === -1) { + await this.reply('Repeated message protection is currently disabled'); + } + else { + await this.reply(`Repeated message protection is set to ${this.guildConfig.similarMessages} similar messages per minute.`); + } + } +} + +module.exports = GetSimilarMessages; diff --git a/src/commands/settings/similarmessages/SetSimilarMessages.js b/src/commands/settings/similarmessages/SetSimilarMessages.js new file mode 100644 index 000000000..84fbcd3dd --- /dev/null +++ b/src/commands/settings/similarmessages/SetSimilarMessages.js @@ -0,0 +1,39 @@ +const SetConfigCommand = require('../../SetConfigCommand'); + +class SetSimilarMessages extends SetConfigCommand { + static usage = ''; + + static description = 'Amount of similar messages users are allowed to send per minute.'; + + async execute() { + const count = this.options.getInteger('count'); + if (!Number.isNaN(count) && count > 0 && count <= 60) { + this.guildConfig.similarMessages = count; + await this.guildConfig.save(); + await this.reply(`Enabled repeated message protection! Users can now only send ${count} similar messages per minute.`); + } else { + await this.sendUsage(); + } + } + + static getOptions() { + return [{ + name: 'count', + type: 'INTEGER', + description: 'Similar messages limit.', + required: true, + minValue: 1, + maxValue: 60, + }]; + } + + parseOptions(args) { + return [{ + type: 'INTEGER', + name: 'count', + value: parseInt(args.shift()) + }]; + } +} + +module.exports = SetSimilarMessages;