Skip to content

Commit

Permalink
Merge pull request #464 from aternosorg/similarmessages
Browse files Browse the repository at this point in the history
/similarmessages
  • Loading branch information
JulianVennen authored Jan 5, 2022
2 parents cd1865f + 9bd3f09 commit 200c43b
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 30 deletions.
40 changes: 10 additions & 30 deletions src/commands/settings/SimilarMessagesCommand.js
Original file line number Diff line number Diff line change
@@ -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 = '<count>|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'),
];
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/commands/settings/similarmessages/DisableSimilarMessages.js
Original file line number Diff line number Diff line change
@@ -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;
16 changes: 16 additions & 0 deletions src/commands/settings/similarmessages/GetSimilarMessages.js
Original file line number Diff line number Diff line change
@@ -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;
39 changes: 39 additions & 0 deletions src/commands/settings/similarmessages/SetSimilarMessages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const SetConfigCommand = require('../../SetConfigCommand');

class SetSimilarMessages extends SetConfigCommand {
static usage = '<limit>';

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;

0 comments on commit 200c43b

Please sign in to comment.