This commit is contained in:
Erik 2021-06-17 01:52:29 +03:00
parent 8cfacb9d9c
commit 7127b3b683
No known key found for this signature in database
GPG Key ID: 7E862371D3409F16

View File

@ -3,7 +3,7 @@ const validInfractions = ['WARN', 'MUTE', 'KICK', 'BAN', 'SOFTBAN'];
module.exports = class FilterSetting extends Setting {
async _action(message, args, setting) {
async _action(message, args, setting, { _wordWatcher } = {}) {
const { resolver } = this.client;
const submethod = args.shift().toLowerCase();
@ -15,7 +15,11 @@ module.exports = class FilterSetting extends Setting {
let result = null,
index = null;
if (resolved.method === 'add') {
result = await this._createAction(message, setting);
if (setting.actions.length >= 5 && _wordWatcher) return {
error: true,
msg: message.format('S_WORDWATCHER_ACTION_LIMIT')
};
result = await this._createAction(message, setting, { _wordWatcher });
index = 'S_FILTER_ACTION_ADD';
} else if (resolved.method === 'edit') {
result = await this._editAction(message, setting);
@ -47,23 +51,25 @@ module.exports = class FilterSetting extends Setting {
};
}
async _createAction(message, setting) {
async _createAction(message, setting, { _wordWatcher }) {
const actionObject = { action: null, duration: null, points: null, expiration: null, force: false, prune: false };
const actionObject = { type: null, duration: null, points: null, expiration: null, force: false, prune: false };
let response = await message.prompt(message.format('S_FILTER_ACTION_ADD_START', { valid: validInfractions.join('`, `') }));
const valid = [...validInfractions];
if (_wordWatcher) valid.push('DELETE'); //Used for wordwatcher quick actions to just delete the flagged message
let response = await message.prompt(message.format('S_FILTER_ACTION_ADD_START', { valid: valid.join('`, `'), wordwatcher: _wordWatcher ? message.format('S_WORDWATCHER_ACTION_ADD_START', { amount: setting.actions.length }) : '' }));
if (!response) return { error: true, msg: message.format('ERR_TIMEOUT') };
const { resolver } = this.client;
const [action] = response.content.split(' ');
const [action] = response.content.toLowerCase().split(' ');
if (['cancel', 'abort', 'exit'].includes(response.content.toLowerCase())) return {
error: true,
msg: message.format('ERR_CANCEL')
};
const infType = resolver.resolveInfraction(action);
if (!infType || !validInfractions.includes(infType)) return { error: true, msg: message.format('S_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') }) };
const infType = resolver.resolveInfraction(action);
if ((!infType || !validInfractions.includes(infType)) && !['del', 'delete'].includes(action)) return { error: true, msg: message.format('S_FILTER_INVALID_INFRACTION', { valid: validInfractions.join('`, `') }) };
actionObject.type = infType;
//Add a duration to the action