Skip to content

Commit 3550b49

Browse files
authored
feat(structures): add AutoModeration structures (#11381)
* feat(structures): add barrel exports in preparation new structures * feat(structures): add AutoModerationRule structure * feat(structures): add AutoModerationRuleTriggerMetadata structure * feat(structures): add AutoModerationAction substructure * feat(structure): add AutoModerationActionMetadata substructure * chore: correct typo * chore: do not expose exemptRoles and exemptChannels as getters * feat(structures): rename substructure files * chore(structures): update barrel exports * chore(structures): export automod structures in package barrel exports
1 parent 838cd2d commit 3550b49

File tree

7 files changed

+280
-0
lines changed

7 files changed

+280
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import type { APIAutoModerationRule } from 'discord-api-types/v10';
2+
import { Structure } from '../Structure.js';
3+
import { kData } from '../utils/symbols.js';
4+
import type { Partialize } from '../utils/types.js';
5+
6+
/**
7+
* Represents an auto moderation rule on Discord.
8+
*
9+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
10+
* @remarks has substructure `TriggerMetadata` which needs to be instantiated and stored by an extending class using it
11+
* @remarks intentionally does not export `exemptRoles` and `exemptChannels` so that extending classes can resolve `Snowflake[]` to `Role[]` and `Channel[]`, respectively
12+
*/
13+
export class AutoModerationRule<Omitted extends keyof APIAutoModerationRule | '' = ''> extends Structure<
14+
APIAutoModerationRule,
15+
Omitted
16+
> {
17+
/**
18+
* The template used for removing data from the raw data stored for each auto moderation rule
19+
*/
20+
public static override DataTemplate: Partial<APIAutoModerationRule> = {};
21+
22+
/**
23+
* @param data - The raw data received from the API for the auto moderation rule
24+
*/
25+
public constructor(data: Partialize<APIAutoModerationRule, Omitted>) {
26+
super(data);
27+
}
28+
29+
/**
30+
* The id of this rule
31+
*/
32+
public get id() {
33+
return this[kData].id;
34+
}
35+
36+
/**
37+
* The id of the guild which this rule belongs to
38+
*/
39+
public get guildId() {
40+
return this[kData].guild_id;
41+
}
42+
43+
/**
44+
* The rule name
45+
*/
46+
public get name() {
47+
return this[kData].name;
48+
}
49+
50+
/**
51+
* The user who first created this rule
52+
*/
53+
public get creatorId() {
54+
return this[kData].creator_id;
55+
}
56+
57+
/**
58+
* The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types | event type}
59+
*/
60+
public get eventType() {
61+
return this[kData].event_type;
62+
}
63+
64+
/**
65+
* The rule {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | trigger type}
66+
*/
67+
public get triggerType() {
68+
return this[kData].trigger_type;
69+
}
70+
71+
/**
72+
* Whether the rule is enabled
73+
*/
74+
public get enabled() {
75+
return this[kData].enabled;
76+
}
77+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
import type { APIAutoModerationRuleTriggerMetadata, AutoModerationRuleTriggerType } from 'discord-api-types/v10';
2+
import { Structure } from '../Structure.js';
3+
import { kData } from '../utils/symbols.js';
4+
import type { Partialize } from '../utils/types.js';
5+
6+
/**
7+
* Represents an auto moderation rule trigger metadata on Discord.
8+
*
9+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
10+
*/
11+
export class AutoModerationRuleTriggerMetadata<
12+
Omitted extends keyof APIAutoModerationRuleTriggerMetadata | '' = '',
13+
> extends Structure<APIAutoModerationRuleTriggerMetadata, Omitted> {
14+
/**
15+
* The template used for removing data from the raw data stored for each auto moderation rule trigger metadata
16+
*/
17+
public static override DataTemplate: Partial<APIAutoModerationRuleTriggerMetadata> = {};
18+
19+
/**
20+
* @param data - The raw data received from the API for the auto moderation rule trigger metadata
21+
*/
22+
public constructor(data: Partialize<APIAutoModerationRuleTriggerMetadata, Omitted>) {
23+
super(data);
24+
}
25+
26+
/**
27+
* Substrings which will be searched for in content (Maximum of 1000)
28+
*
29+
* A keyword can be a phrase which contains multiple words.
30+
*
31+
* Wildcard symbols can be used to customize how each keyword will be matched. Each keyword must be 60 characters or less.
32+
*
33+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies | Keyword matching strategies}
34+
*
35+
* Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.MemberProfile}
36+
*/
37+
public get keywordFilter() {
38+
return this[kData].keyword_filter;
39+
}
40+
41+
/**
42+
* Regular expression patterns which will be matched against content (Maximum of 10)
43+
*
44+
* Only Rust flavored regex is currently supported, which can be tested in online editors such as {@link https://rustexp.lpil.uk/ | Rustexp}.
45+
*
46+
* Each regex pattern must be 260 characters or less.
47+
*
48+
* Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.MemberProfile}
49+
*/
50+
public get regexPatterns() {
51+
return this[kData].regex_patterns;
52+
}
53+
54+
/**
55+
* The internally pre-defined wordsets which will be searched for in content
56+
*
57+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types | Keyword preset types}
58+
*
59+
* Associated trigger types: {@link AutoModerationRuleTriggerType.KeywordPreset}
60+
*/
61+
public get presets() {
62+
return this[kData].presets;
63+
}
64+
65+
/**
66+
* Substrings which should not trigger the rule (Maximum of 100 or 1000).
67+
*
68+
* Wildcard symbols can be used to customize how each keyword will be matched (see Keyword matching strategies).
69+
*
70+
* Each `allow_list` keyword can be a phrase which contains multiple words.
71+
*
72+
* Rules with `KEYWORD` triggerType accept a maximum of 100 keywords.
73+
*
74+
* Rules with `KEYWORD_PRESET` triggerType accept a maximum of 1000 keywords.
75+
*
76+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types | triggerType}
77+
* @see {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies | Keyword matching strategies}
78+
*
79+
* Associated trigger types: {@link AutoModerationRuleTriggerType.Keyword}, {@link AutoModerationRuleTriggerType.KeywordPreset}, {@link AutoModerationRuleTriggerType.MemberProfile}
80+
*/
81+
public get allowList() {
82+
return this[kData].allow_list;
83+
}
84+
85+
/**
86+
* Total number of unique role and user mentions allowed per message (Maximum of 50)
87+
*
88+
* Associated trigger types: {@link AutoModerationRuleTriggerType.MentionSpam}
89+
*/
90+
public get mentionTotalLimit() {
91+
return this[kData].mention_total_limit;
92+
}
93+
94+
/**
95+
* Whether to automatically detect mention raids
96+
*
97+
* Associated trigger types: {@link AutoModerationRuleTriggerType.MentionSpam}
98+
*/
99+
public get mentionRaidProtectionEnabled() {
100+
return this[kData].mention_raid_protection_enabled;
101+
}
102+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import type { APIAutoModerationAction } from 'discord-api-types/v10';
2+
import { Structure } from '../../Structure.js';
3+
import { kData } from '../../utils/symbols.js';
4+
import type { Partialize } from '../../utils/types.js';
5+
6+
/**
7+
* Represents an auto moderation action on Discord.
8+
*
9+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
10+
* @remarks has substructure `ActionMetadata` which needs to be instantiated and stored by an extending class using it
11+
*/
12+
export class AutoModerationAction<Omitted extends keyof APIAutoModerationAction | '' = ''> extends Structure<
13+
APIAutoModerationAction,
14+
Omitted
15+
> {
16+
/**
17+
* The template used for removing data from the raw data stored for each auto moderation action
18+
*/
19+
public static override DataTemplate: Partial<APIAutoModerationAction> = {};
20+
21+
/**
22+
* @param data - The raw data received from the API for the auto moderation action
23+
*/
24+
public constructor(data: Partialize<APIAutoModerationAction, Omitted>) {
25+
super(data);
26+
}
27+
28+
/**
29+
* The {@link https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types | action type}
30+
*/
31+
public get type() {
32+
return this[kData].type;
33+
}
34+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import type {
2+
APIAutoModerationActionMetadata,
3+
AutoModerationActionType,
4+
AutoModerationRuleTriggerType,
5+
} from 'discord-api-types/v10';
6+
import { Structure } from '../../Structure.js';
7+
import { kData } from '../../utils/symbols.js';
8+
import type { Partialize } from '../../utils/types.js';
9+
10+
/**
11+
* Represents an auto moderation action metadata on Discord.
12+
*
13+
* @typeParam Omitted - Specify the properties that will not be stored in the raw data field as a union, implement via `DataTemplate`
14+
*/
15+
export class AutoModerationActionMetadata<
16+
Omitted extends keyof APIAutoModerationActionMetadata | '' = '',
17+
> extends Structure<APIAutoModerationActionMetadata, Omitted> {
18+
/**
19+
* The template used for removing data from the raw data stored for each auto moderation action metadata
20+
*/
21+
public static override DataTemplate: Partial<APIAutoModerationActionMetadata> = {};
22+
23+
/**
24+
* @param data - The raw data received from the API for the auto moderation action metadata
25+
*/
26+
public constructor(data: Partialize<APIAutoModerationActionMetadata, Omitted>) {
27+
super(data);
28+
}
29+
30+
/**
31+
* Channel to which user content should be logged. This must be an existing channel
32+
*
33+
* Associated action types: {@link AutoModerationActionType.SendAlertMessage}
34+
*/
35+
public get channelId() {
36+
return this[kData].channel_id;
37+
}
38+
39+
/**
40+
* Timeout duration in seconds. Maximum of 2419200 seconds (4 weeks).
41+
*
42+
* A `TIMEOUT` action can only be set up for {@link AutoModerationRuleTriggerType.Keyword} and {@link AutoModerationRuleTriggerType.MentionSpam}.
43+
*
44+
* The `MODERATE_MEMBERS` permission is required to use {@link AutoModerationActionType.Timeout} actions.
45+
*
46+
* Associated action types: {@link AutoModerationActionType.Timeout}
47+
*/
48+
public get durationSeconds() {
49+
return this[kData].duration_seconds;
50+
}
51+
52+
/**
53+
* Additional explanation that will be shown to members whenever their message is blocked. Maximum of 150 characters
54+
*
55+
* Associated action types: {@link AutoModerationActionType.BlockMessage}
56+
*/
57+
public get customMessage() {
58+
return this[kData].custom_message;
59+
}
60+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './AutoModerationAction.js';
2+
export * from './AutoModerationActionMetadata.js';
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export * from './actions/index.js';
2+
3+
export * from './AutoModerationRule.js';
4+
export * from './AutoModerationRuleTriggerMetadata.js';

packages/structures/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export * from './automoderation/index.js';
12
export * from './bitfields/index.js';
23
export * from './channels/index.js';
34
export * from './emojis/index.js';

0 commit comments

Comments
 (0)