/
autoModeration.ts
216 lines (207 loc) · 6.36 KB
/
autoModeration.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
/**
* Types extracted from https://discord.com/developers/docs/resources/auto-moderation
*/
import type { Snowflake } from '../../globals';
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-auto-moderation-rule-structure
*/
export interface APIAutoModerationRule {
/**
* The id of this rule
*/
id: Snowflake;
/**
* The guild which this rule belongs to
*/
guild_id: Snowflake;
/**
* The rule name
*/
name: string;
/**
* The user id who created this rule
*/
creator_id: Snowflake;
/**
* The rule event type
*/
event_type: AutoModerationRuleEventType;
/**
* The rule trigger type
*/
trigger_type: AutoModerationRuleTriggerType;
/**
* The rule trigger metadata
*/
trigger_metadata: APIAutoModerationRuleTriggerMetadata;
/**
* The actions which will execute when this rule is triggered
*/
actions: APIAutoModerationAction[];
/**
* Whether this rule is enabled
*/
enabled: boolean;
/**
* The role ids that shouldn't be affected by this rule (Maximum of 20)
*/
exempt_roles: Snowflake[];
/**
* The channel ids that shouldn't be affected by this rule (Maximum of 50)
*/
exempt_channels: Snowflake[];
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-types
*/
export enum AutoModerationRuleTriggerType {
/**
* Check if content contains words from a user defined list of keywords (Maximum of 6 per guild)
*/
Keyword = 1,
/**
* Check if content represents generic spam (Maximum of 1 per guild)
*/
Spam = 3,
/**
* Check if content contains words from internal pre-defined wordsets (Maximum of 1 per guild)
*/
KeywordPreset,
/**
* Check if content contains more mentions than allowed (Maximum of 1 per guild)
*/
MentionSpam,
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata
*/
export interface APIAutoModerationRuleTriggerMetadata {
/**
* Substrings which will be searched for in content (Maximum of 1000)
*
* A keyword can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 60 characters or less
* See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies)
*
* Associated trigger type: {@link AutoModerationRuleTriggerType.Keyword}
*/
keyword_filter?: string[];
/**
* The internally pre-defined wordsets which will be searched for in content
*
* Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset}
*/
presets?: AutoModerationRuleKeywordPresetType[];
/**
* Substrings which will be exempt from triggering the preset trigger type (Maximum of 1000)
*
* A allowed-word can be a phrase which contains multiple words. Wildcard symbols can be used to customize how each string will be matched. Each keyword must be 60 characters or less
* See [keyword matching strategies](https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies)
*
* Associated trigger type: {@link AutoModerationRuleTriggerType.KeywordPreset}
*/
allow_list?: string[];
/**
* Regular expression patterns which will be matched against content (Maximum of 10)
*
* Only Rust flavored regex is currently supported (Maximum of 260 characters)
*
* Associated trigger type: {@link AutoModerationRuleTriggerType.Keyword}
*/
regex_patterns?: string[];
/**
* Total number of mentions (role & user) allowed per message (Maximum of 50)
*
* Associated trigger type: {@link AutoModerationRuleTriggerType.MentionSpam}
*/
mention_total_limit?: number;
/**
* Whether to automatically detect mention raids
*
* Associated trigger type: {@link AutoModerationRuleTriggerType.MentionSpam}
*/
mention_raid_protection_enabled?: boolean;
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types
*/
export enum AutoModerationRuleKeywordPresetType {
/**
* Words that may be considered forms of swearing or cursing
*/
Profanity = 1,
/**
* Words that refer to sexually explicit behavior or activity
*/
SexualContent,
/**
* Personal insults or words that may be considered hate speech
*/
Slurs,
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types
*/
export enum AutoModerationRuleEventType {
/**
* When a member sends or edits a message in the guild
*/
MessageSend = 1,
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-auto-moderation-action-structure
*/
export interface APIAutoModerationAction {
/**
* The action type
*/
type: AutoModerationActionType;
/**
* Additional metadata needed during execution for this specific action type
*
* Will only be omitted if the action type is {@link AutoModerationActionType.BlockMessage}
*/
metadata?: APIAutoModerationActionMetadata;
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-types
*/
export enum AutoModerationActionType {
/**
* Blocks a member's message and prevents it from being posted.
* A custom explanation can be specified and shown to members whenever their message is blocked
*/
BlockMessage = 1,
/**
* Logs user content to a specified channel
*/
SendAlertMessage,
/**
* Timeout user for specified duration, this action type can be set if the bot has `MODERATE_MEMBERS` permission
*/
Timeout,
}
/**
* https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-action-object-action-metadata
*/
export interface APIAutoModerationActionMetadata {
/**
* Channel to which user content should be logged
*
* Associated action type: {@link AutoModerationActionType.SendAlertMessage}
*/
channel_id?: Snowflake;
/**
* Timeout duration in seconds (Maximum of 4 weeks - 2419200 seconds)
*
* Only available if using {@link AutoModerationRuleTriggerType.Keyword}
*
* Associated action type: {@link AutoModerationActionType.Timeout}
*/
duration_seconds?: number;
/**
* Additional explanation that will be shown to members whenever their message is blocked (Maximum 150 characters)
*
* Associated action type {@link AutoModerationActionType.BlockMessage}
*/
custom_message?: string;
}