Skip to content

Commit 0ac6928

Browse files
committed
refactor(automod): replace "has" with "min_count"/"max_count" in has_attachments trigger
1 parent 63510a5 commit 0ac6928

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ interface HasAttachmentsMatchResult {
99
}
1010

1111
const configSchema = z.strictObject({
12-
has: z.boolean(),
12+
min_count: z.number().int().min(0).nullable().default(1),
13+
max_count: z.number().int().nullable().default(null),
1314
});
1415

1516
export const HasAttachmentsTrigger = automodTrigger<HasAttachmentsMatchResult>()({
@@ -19,12 +20,17 @@ export const HasAttachmentsTrigger = automodTrigger<HasAttachmentsMatchResult>()
1920
if (!context.message) {
2021
return;
2122
}
23+
if (triggerConfig.min_count == null && triggerConfig.max_count == null) {
24+
return;
25+
}
2226

2327
const attachments = context.message.data.attachments;
2428
const attachmentCount = attachments?.length ?? 0;
2529
const hasAttachments = attachmentCount > 0;
30+
const matchesMinCount = triggerConfig.min_count != null ? attachmentCount >= triggerConfig.min_count : true;
31+
const matchesMaxCount = triggerConfig.max_count != null ? attachmentCount <= triggerConfig.max_count : true;
2632

27-
if (hasAttachments === triggerConfig.has) {
33+
if (matchesMinCount && matchesMaxCount) {
2834
return {
2935
extra: {
3036
hasAttachments,

0 commit comments

Comments
 (0)