Skip to content

Commit 0294184

Browse files
committed
fix: automod not trigger flexibility and update docs examples.
1 parent bbc06c8 commit 0294184

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

backend/src/plugins/Automod/docs.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,14 @@ export const automodPluginDocs: ZeppelinPluginDocs = {
135135
triggers:
136136
- and:
137137
triggers:
138-
- match_links: {}
138+
- match_links:
139+
only_real_links: true
140+
include_words: ['http'] # catch any real link
139141
- not:
140142
trigger:
141143
match_invites:
142144
allow_group_dm_invites: false
145+
exclude_invite_codes: [] # matches any invite code
143146
actions:
144147
clean: true
145148
warn:

backend/src/plugins/Automod/triggers/not.ts

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { z } from "zod";
22
import { AutomodTriggerBlueprint, AutomodTriggerMatchResult, automodTrigger } from "../helpers.js";
33

44
interface NotTriggerMatchResultExtra {
5-
triggerName: string;
5+
triggerNames: string[];
66
}
77

88
interface CreateNotTriggerOpts {
@@ -21,8 +21,8 @@ export function createNotTrigger({ getAvailableTriggers }: CreateNotTriggerOpts)
2121
return z
2222
.strictObject(schemaShape)
2323
.partial()
24-
.refine((val) => Object.values(val).filter((v) => v !== undefined).length === 1, {
25-
message: "Not trigger must specify exactly one trigger",
24+
.refine((val) => Object.values(val).some((v) => v !== undefined), {
25+
message: "Not trigger must specify at least one trigger",
2626
});
2727
});
2828

@@ -33,38 +33,52 @@ export function createNotTrigger({ getAvailableTriggers }: CreateNotTriggerOpts)
3333

3434
async match({ ruleName, pluginData, context, triggerConfig }) {
3535
const definedEntries = Object.entries(triggerConfig.trigger).filter(([, v]) => v !== undefined);
36-
if (definedEntries.length !== 1) {
36+
if (definedEntries.length < 1) {
3737
return null;
3838
}
3939

40-
const [subTriggerName, subTriggerConfig] = definedEntries[0]!;
41-
const subTrigger = getAvailableTriggers()[subTriggerName];
42-
if (!subTrigger) {
43-
return null;
44-
}
40+
const testedNames: string[] = [];
4541

46-
const subMatch = await subTrigger.match({
47-
ruleName,
48-
pluginData,
49-
context,
50-
triggerConfig: subTriggerConfig,
51-
});
42+
for (const [subTriggerName, subTriggerConfig] of definedEntries) {
43+
const subTrigger = getAvailableTriggers()[subTriggerName];
44+
if (!subTrigger) {
45+
continue;
46+
}
47+
48+
testedNames.push(subTriggerName);
49+
50+
const subMatch = await subTrigger.match({
51+
ruleName,
52+
pluginData,
53+
context,
54+
triggerConfig: subTriggerConfig,
55+
});
5256

53-
if (subMatch) {
57+
if (subMatch) {
58+
return null;
59+
}
60+
}
61+
62+
if (testedNames.length === 0) {
5463
return null;
5564
}
5665

5766
const result: AutomodTriggerMatchResult<NotTriggerMatchResultExtra> = {
5867
extra: {
59-
triggerName: subTriggerName,
68+
triggerNames: testedNames,
6069
},
6170
};
6271

6372
return result;
6473
},
6574

6675
async renderMatchInformation({ matchResult }) {
67-
return `Did not match ${matchResult.extra.triggerName}`;
76+
const names = matchResult.extra.triggerNames;
77+
if (names.length === 1) {
78+
return `Did not match ${names[0]}`;
79+
}
80+
81+
return `Did not match any of: ${names.join(", ")}`;
6882
},
6983
});
7084
}

0 commit comments

Comments
 (0)