linkfilter triggers

This commit is contained in:
Erik 2022-07-17 16:01:37 +03:00
parent 4c0905d84a
commit f412e1c3b3
Signed by untrusted user: Navy.gif
GPG Key ID: 811EC0CD80E7E5FB

View File

@ -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('`, `') } })
);
}
}