feat(automod): add affects_self option for rules

This commit is contained in:
Dragory 2021-10-17 08:15:30 +03:00
parent 1f4f27c26a
commit 151a5df4af
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
3 changed files with 6 additions and 5 deletions

View file

@ -81,6 +81,10 @@ const configPreprocessor: ConfigPreprocessorFn<AutomodPluginType> = (options) =>
rule["affects_bots"] = false;
}
if (rule["affects_self"] == null) {
rule["affects_self"] = false;
}
// Loop through the rule's triggers
if (rule["triggers"]) {
for (const triggerObj of rule["triggers"]) {

View file

@ -23,11 +23,6 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
const channel = channelOrThread?.isThread() ? channelOrThread.parent : channelOrThread;
const categoryId = channel?.parentId;
// Don't apply Automod on Zeppelin itself
if (userId && userId === pluginData.client.user?.id) {
return;
}
const config = await pluginData.config.getMatchingConfig({
channelId,
categoryId,
@ -39,6 +34,7 @@ export async function runAutomod(pluginData: GuildPluginData<AutomodPluginType>,
for (const [ruleName, rule] of Object.entries(config.rules)) {
if (rule.enabled === false) continue;
if (!rule.affects_bots && (!user || user.bot) && !context.counterTrigger && !context.antiraid) continue;
if (!rule.affects_self && userId && userId === pluginData.client.user?.id) continue;
if (rule.cooldown && checkAndUpdateCooldown(pluginData, rule, context)) {
continue;

View file

@ -23,6 +23,7 @@ export const Rule = t.type({
name: t.string,
presets: tNullable(t.array(t.string)),
affects_bots: t.boolean,
affects_self: t.boolean,
triggers: t.array(t.partial(AvailableTriggers.props)),
actions: t.partial(AvailableActions.props),
cooldown: tNullable(t.string),