From f412e1c3b3235b1c5bb564744bc23017ebca84bd Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sun, 17 Jul 2022 16:01:37 +0300 Subject: [PATCH] linkfilter triggers --- .../settings/moderation/LinkFilter.js | 52 +++++++++++++++++-- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/src/structure/components/settings/moderation/LinkFilter.js b/src/structure/components/settings/moderation/LinkFilter.js index d47a207..f5d0785 100644 --- a/src/structure/components/settings/moderation/LinkFilter.js +++ b/src/structure/components/settings/moderation/LinkFilter.js @@ -153,10 +153,56 @@ class LinkFilterSetting extends FilterSetting { } - async _createTrigger(interaction, action, actionObject) { + async _createTrigger(interaction, action, actionObject, actions) { - // TODO: FINISH THIS!! - actionObject.trigger = 'generic'; + const response = await interaction.promptMessage( + interaction.format('SETTING_LINKFILTER_ACTION_ADD_TRIGGERS'), + { time: 60 * 1000, editReply: true } + ); + if (!response) { + if (actions.find((ac) => ac.trigger === 'generic')) return { + error: true, + message: interaction.format('SETTING_FILTER_ACTIONS_EXISTING', { trigger: 'generic' }) + }; + actions.push(actionObject); + actionObject.trigger = 'generic'; + return actionObject; + } + await response.delete(); + if (['cancel', 'abort', 'exit'].includes(action.toLowerCase())) return { + error: true, + message: interaction.format('ERR_CANCEL') + }; + + const params = Util.parseQuotes(response.content).map(([param]) => param); + let first = params[0].toLowerCase(); + + if (['generic', 'gen', 'bl', 'blacklist', 'gl', 'greylist', 'wl', 'whitelist'].includes(first)) { + if (first === 'gen') first = 'generic'; + else if (first === 'bl') first = 'blacklist'; + else if (first === 'gl') first = 'greylist'; + else if (first === 'wl') first = 'whitelist'; + const existing = actions.find((ac) => ac.trigger === first); + if (existing) return { + error: true, + message: interaction.format('SETTING_FILTER_ACTIONS_EXISTING', { trigger: first }) + }; + actionObject.trigger = first; + } else { + const words = params.map((word) => word.toLowerCase()); + const removed = []; + for (const word of [...words]) { + const existing = actions.find((ac) => ac.trigger.includes(word)); + if (!existing) continue; + words.splice(words.indexOf(word), 1); + removed.push(word); + } + actionObject.trigger = words; + if (removed.length) interaction.channel.send( + interaction.format('SETTING_LINKFILTER_WORD_IN_ACTION', + { params: { words: removed.join('`, `') } }) + ); + } }