diff --git a/structure/client/components/settings/moderation/WordFilter.js b/structure/client/components/settings/moderation/WordFilter.js index eece9f7..c01ba0c 100644 --- a/structure/client/components/settings/moderation/WordFilter.js +++ b/structure/client/components/settings/moderation/WordFilter.js @@ -21,7 +21,8 @@ module.exports = class WordFilter extends FilterSetting { 'wordfilter bypass add role "rolename with several words"', 'wordfilter ignore set #channel channel-name', 'wordfilter silent on', - 'wordfilter actions ' // time reg: (\d{1,3}\s?[a-z]{1,7} ?){1,2} | points reg: \d{1,3}\s?(points?|pts?|p) -- parse points first + 'wordfilter actions ', // time reg: (\d{1,3}\s?[a-z]{1,7} ?){1,2} | points reg: \d{1,3}\s?(points?|pts?|p) -- parse points first + 'wordfilter presets add profane' ], default: { wordFilter: { @@ -42,7 +43,8 @@ module.exports = class WordFilter extends FilterSetting { // } ], ignore: [], - bypass: [] + bypass: [], + presets: [] } } }); @@ -75,8 +77,13 @@ module.exports = class WordFilter extends FilterSetting { } else if (['explicit', 'fuzzy', 'tokenized', 'token', 'whitelist'].includes(method)) { + if (args.length < 2) return { + error: true, + msg: message.format('MISSING_ARGS') + }; if (method === 'token') method = 'tokenized'; - const resolved = await resolver.resolveMethod(args, null, setting[method], { + const resolved = await resolver.resolveMethod(args, { + existing: setting[method], allowedMethods: ['add', 'remove', 'set', 'reset'] }); if (!resolved) return { @@ -88,8 +95,13 @@ module.exports = class WordFilter extends FilterSetting { langParams = { changed: resolved.changed.join('`, `') || '' }; } else if (['ignore', 'channelignore', 'ignorechannel'].includes(method)) { - - const resolved = await resolver.resolveMethod(args, null, setting.ignore, { + + if (args.length < 2) return { + error: true, + msg: message.format('MISSING_ARGS') + }; + const resolved = await resolver.resolveMethod(args, { + existing: setting.ignore, resolver: resolver.resolveChannels.bind(resolver), guild, allowedMethods: ['add', 'remove', 'set', 'reset'] @@ -104,7 +116,12 @@ module.exports = class WordFilter extends FilterSetting { } else if (['bypass', 'roleignore', 'ignorerole'].includes(method)) { - const resolved = await resolver.resolveMethod(args, null, setting.bypass, { + if (args.length < 2) return { + error: true, + msg: message.format('MISSING_ARGS') + }; + const resolved = await resolver.resolveMethod(args, { + existing: setting.bypass, resolver: resolver.resolveRoles.bind(resolver), guild, allowedMethods: ['add', 'remove', 'set', 'reset'] @@ -144,7 +161,7 @@ module.exports = class WordFilter extends FilterSetting { */ const submethod = args.shift().toLowerCase(); - const resolved = await resolver.resolveMethod([submethod], null, null, { + const resolved = await resolver.resolveMethod([submethod], { allowedMethods: ['add', 'remove', 'edit', 'list', 'reset'] }); if (!resolved) return { error: true, msg: message.format('ERR_INVALID_METHOD', { method: submethod }) }; @@ -181,6 +198,44 @@ module.exports = class WordFilter extends FilterSetting { trigger: result.trigger instanceof Array ? '||' + result.trigger.join(', ') + '||' : '`' + result.trigger + '`' }; + } else if (['preset', 'presets'].includes(method)) { + + if (args.length < 2) return { + error: true, + msg: message.format('S_WORDFILTER_PRESETMISSING_ARGS') + }; + const valid = { + profane: ['profane', 'profanity', 'swears', 'swear', 'swearing'], + slurs: ['slur', 'slurs'], + obscene: ['obscenity', 'obscene', 'nsfw'] + }; + const resolved = await resolver.resolveMethod(args, { + valid: Object.values(valid).reduce((acc, val) => { + acc.push(...val); + return acc; + }, []), allowedMethods: ['add', 'remove', 'set', 'reset'] + }); + const { method: submethod, changed } = resolved; + let { presets } = setting; + const _resolved = []; + + for (const item of changed) { + if (valid.profane.includes(item) && !_resolved.includes('profanity')) _resolved.push('profanity'); + else if (valid.slurs.includes(item) && !_resolved.includes('slurs')) _resolved.push('slurs'); + else if (valid.obscene.includes(item) && !_resolved.includes('obscene')) _resolved.push('obscene'); + } + + if (submethod === 'set') presets = _resolved; + else if (submethod === 'reset') presets = []; + else if (submethod === 'add') presets = [ + ...presets, + ..._resolved.filter((item) => !presets.includes(item))]; + else if (submethod === 'remove') presets = presets.filter((item) => !_resolved.includes(item)); + + index = 'S_FILTER_PRESETS'; + langParams.presets = presets.join('`, `') || 'N/A'; + setting.presets = presets; + } await message.guild._updateSettings({ [this.index]: setting }); @@ -254,8 +309,8 @@ module.exports = class WordFilter extends FilterSetting { inline: true }, { - name: '\u200b', - value: '\u200b', + name: '》 Preset filters', + value: setting.presets.join(', ') || 'N/A', inline: true }, {