now supports adding time directly in threshold

This commit is contained in:
Erik 2020-09-01 23:04:13 +03:00
parent caf576a657
commit 5c386cf925

View File

@ -1,7 +1,8 @@
const { Setting } = require('../../../../interfaces/');
const CONSTANTS = {
INFRACTIONS: ['WARN', 'MUTE', 'KICK', 'SOFTBAN', 'BAN', 'VCMUTE', 'VCKICK', 'VCBAN']
INFRACTIONS: ['WARN', 'MUTE', 'KICK', 'SOFTBAN', 'BAN', 'VCMUTE', 'VCKICK', 'VCBAN'],
TIMED: ['MUTE', 'BAN', 'VCMUTE', 'VCBAN']
};
class AutoModerationSetting extends Setting {
@ -16,13 +17,7 @@ class AutoModerationSetting extends Setting {
autoModeration: {
enabled: true,
thresholds: {
'10': {
type: 'MUTE',
length: 60
},
'20': {
type: 'KICK'
}
},
usePrevious: false // use previous threshold if no new threshold is exceeded
}
@ -50,12 +45,12 @@ class AutoModerationSetting extends Setting {
index = 'S_AUTOMOD_TOGGLE';
langParams = { toggle: message.format('ON_OFF_TOGGLE', { toggle: false }, true) };
} else if (method.toLowerCase() === 'threshold') {
const action = params.shift()?.toLowerCase();
if (!action) return { error: true, msg: message.format('S_AUTOMOD_NOARG') };
const points = parseInt(params.shift());
if (isNaN(points) || points < 0 || points > 100) return { error: true, msg: message.format('S_AUTOMOD_INVALID_POINTS', {}) };
const action = params.shift()?.toLowerCase();
if (!action) return { error: true, msg: message.format('S_AUTOMOD_NOARG') };
if (['delete', 'remove'].includes(action)) {
const old = setting.thresholds[points];
@ -67,17 +62,25 @@ class AutoModerationSetting extends Setting {
return { error: true, msg: message.format('S_AUTOMOD_REMOVE_NOPOINTS', { points }) };
}
} else {
const infraction = resolver.resolveInfraction(action);
if (!CONSTANTS.INFRACTIONS.includes(infraction)) return { error: true, msg: message.format('S_AUTOMOD_INVALID_TYPE', { infraction }) };
const old = setting.thresholds[points];
const timed = CONSTANTS.TIMED.includes(infraction);
const _time = params.join(' ');
const time = resolver.resolveTime(_time);
if (old) {
index = 'S_AUTOMOD_OVERWRITE_POINTS';
langParams = { type: infraction, points, oldType: old.type };
index = timed && time ? 'S_AUTOMOD_OVERWRITE_POINTS_TIMED' : 'S_AUTOMOD_OVERWRITE_POINTS';
langParams = { type: infraction, points, oldType: old.type, time: resolver.timeAgo(time, true, true, true) };
} else {
index = 'S_AUTOMOD_ADD_POINTS';
langParams = { type: infraction, points };
index = timed && time ? 'S_AUTOMOD_ADD_POINTS_TIMED' : 'S_AUTOMOD_ADD_POINTS';
langParams = { type: infraction, points, time: resolver.timeAgo(time, true, true, true) };
}
setting.thresholds[points] = { type: infraction };
if (timed && time) setting.thresholds[points].length = time;
}
} else if (method.toLowerCase() === 'length') {
@ -102,6 +105,16 @@ class AutoModerationSetting extends Setting {
index = 'S_AUTOMOD_LENGTH_SUCCESS';
}
} else if (['useprev', 'useprevious', 'previous'].includes(method.toLowerCase())) {
const bool = resolver.resolveBoolean(params[0]);
if (bool) setting.usePrevious = bool;
else if (bool === false) setting.usePrevious = bool;
else return { error: true, msg: message.format('ERR_BOOLEAN_RESOLVE', { resolveable: params[0] }) };
index = 'S_AUTOMOD_USEPREV_TOGGLE';
langParams = { toggle: message.format('ON_OFF_TOGGLE', { toggle: bool }, true) };
}
await message.guild._updateSettings({ [this.index]: setting });