-
-
Notifications
You must be signed in to change notification settings - Fork 170
/
Copy pathautomod.h
403 lines (351 loc) · 10.6 KB
/
automod.h
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
/************************************************************************************
*
* D++, A Lightweight C++ library for Discord
*
* SPDX-License-Identifier: Apache-2.0
* Copyright 2021 Craig Edwards and D++ contributors
* (https://github.com/brainboxdotcc/DPP/graphs/contributors)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
************************************************************************************/
#pragma once
#include <dpp/export.h>
#include <dpp/snowflake.h>
#include <dpp/managed.h>
#include <dpp/utility.h>
#include <dpp/json_fwd.h>
#include <dpp/json_interface.h>
namespace dpp {
/**
* @brief Possible types of preset filter lists
*/
enum automod_preset_type : uint8_t {
/**
* @brief Strong swearing
*/
amod_preset_profanity = 1,
/**
* @brief Sexual phrases and words
*/
amod_preset_sexual_content = 2,
/**
* @brief Racial and other slurs, hate speech
*/
amod_preset_slurs = 3,
};
/**
* @brief Action types to perform on filtering
*/
enum automod_action_type : uint8_t {
/**
* @brief Blocks the message and prevents it from being posted.
* A custom explanation can be specified and shown to members whenever their message is blocked
*/
amod_action_block_message = 1,
/**
* @brief Send an alert to a given channel
*/
amod_action_send_alert = 2,
/**
* @brief timeout the user
* @note Can only be set up for rules with trigger types of dpp::amod_type_keyword and dpp::amod_type_mention_spam
*/
amod_action_timeout = 3,
};
/**
* @brief Event types, only message send is currently supported
*/
enum automod_event_type : uint8_t {
/**
* @brief Trigger on message send or edit
*/
amod_message_send = 1,
};
/**
* @brief Types of moderation to trigger
*/
enum automod_trigger_type : uint8_t {
/**
* @brief Check if content contains words from a user defined list of keywords (max 6 of this type per guild)
*/
amod_type_keyword = 1,
/**
* @brief Harmful/malware links
* @deprecated Removed by Discord
*/
amod_type_harmful_link = 2,
/**
* @brief Check if content represents generic spam (max 1 of this type per guild)
*/
amod_type_spam = 3,
/**
* @brief Check if content contains words from discord pre-defined wordsets (max 1 of this type per guild)
*/
amod_type_keyword_preset = 4,
/**
* @brief Check if content contains more mentions than allowed (max 1 of this type per guild)
*/
amod_type_mention_spam = 5,
};
/**
* @brief Metadata associated with an automod action. Different fields are relevant based on the value of dpp::automod_rule::trigger_type.
*/
struct DPP_EXPORT automod_metadata : public json_interface<automod_metadata> {
protected:
friend struct json_interface<automod_metadata>;
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return automod_metadata& Reference to self
*/
automod_metadata& fill_from_json_impl(nlohmann::json* j);
/**
* @brief Build a json for this object
*
* @return json JSON object
*/
virtual json to_json_impl(bool with_id = false) const;
public:
/**
* @brief @brief Substrings which will be searched for in content (Maximum of 1000).
*
* Each keyword can be a phrase which contains multiple words.
* All keywords are case insensitive and can be up to 60 characters.
*
* Wildcard symbols (`*`) can be used to customize how each keyword will be matched.
*
* **Examples for the `*` wildcard symbol:**
*
* Prefix - word must start with the keyword
*
* | keyword | matches |
* |----------|-------------------------------------|
* | cat* | <u><b>cat</b></u>ch, <u><b>Cat</b></u>apult, <u><b>CAt</b></u>tLE |
* | the mat* | <u><b>the mat</b></u>rix |
*
* Suffix - word must end with the keyword
*
* | keyword | matches |
* |----------|--------------------------|
* | *cat | wild<u><b>cat</b></u>, copy<u><b>Cat</b></u> |
* | *the mat | brea<u><b>the mat</b></u> |
*
* Anywhere - keyword can appear anywhere in the content
*
* | keyword | matches |
* |-----------|-----------------------------|
* | \*cat* | lo<u><b>cat</b></u>ion, edu<u><b>Cat</b></u>ion |
* | \*the mat* | brea<u><b>the mat</b></u>ter |
*
* Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end
*
* | keyword | matches |
* |---------|-------------|
* | cat | <u><b>Cat</b></u> |
* | the mat | <u><b>the mat</b></u> |
*
*/
std::vector<std::string> keywords;
/**
* @brief Regular expression patterns which will be matched against content (Maximum of 10).
*
* Only Rust flavored regex is currently supported, which can be tested in online editors such as [Rustexp](https://rustexp.lpil.uk/).
* Each regex pattern can be up to 260 characters.
*/
std::vector<std::string> regex_patterns;
/**
* @brief Preset keyword list types to moderate
* @see automod_preset_type
*/
std::vector<automod_preset_type> presets;
/**
* @brief Substrings which should not trigger the rule (Maximum of 100 for the trigger type dpp::amod_type_keyword, Maximum of 1000 for the trigger type dpp::amod_type_keyword_preset).
*
* Each keyword can be a phrase which contains multiple words.
* All keywords are case insensitive and can be up to 60 characters.
*
* Wildcard symbols (`*`) can be used to customize how each keyword will be matched.
*
* **Examples for the `*` wildcard symbol:**
*
* Prefix - word must start with the keyword
*
* | keyword | matches |
* |----------|-------------------------------------|
* | cat* | <u><b>cat</b></u>ch, <u><b>Cat</b></u>apult, <u><b>CAt</b></u>tLE |
* | the mat* | <u><b>the mat</b></u>rix |
*
* Suffix - word must end with the keyword
*
* | keyword | matches |
* |----------|--------------------------|
* | *cat | wild<u><b>cat</b></u>, copy<u><b>Cat</b></u> |
* | *the mat | brea<u><b>the mat</b></u> |
*
* Anywhere - keyword can appear anywhere in the content
*
* | keyword | matches |
* |-----------|-----------------------------|
* | \*cat* | lo<u><b>cat</b></u>ion, edu<u><b>Cat</b></u>ion |
* | \*the mat* | brea<u><b>the mat</b></u>ter |
*
* Whole Word - keyword is a full word or phrase and must be surrounded by whitespace at the beginning and end
*
* | keyword | matches |
* |---------|-------------|
* | cat | <u><b>Cat</b></u> |
* | the mat | <u><b>the mat</b></u> |
*
*/
std::vector<std::string> allow_list;
/**
* @brief Total number of unique role and user mentions allowed per message (Maximum of 50)
*/
uint8_t mention_total_limit;
/**
* @brief Whether to automatically detect mention raids
*/
bool mention_raid_protection_enabled;
/**
* @brief Construct a new automod metadata object
*/
automod_metadata();
/**
* @brief Destroy the automod metadata object
*/
virtual ~automod_metadata();
};
/**
* @brief Represents an automod action
*/
struct DPP_EXPORT automod_action : public json_interface<automod_action> {
protected:
friend struct json_interface<automod_action>;
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return automod_action& Reference to self
*/
automod_action& fill_from_json_impl(nlohmann::json* j);
/**
* @brief Build a json for this object
*
* @return json JSON object
*/
virtual json to_json_impl(bool with_id = false) const;
public:
/**
* @brief Type of action to take
*/
automod_action_type type;
/**
* @brief Channel ID to which user content should be logged, for type dpp::amod_action_send_alert
*/
snowflake channel_id;
/**
* @brief Additional explanation that will be shown to members whenever their message is blocked. For type dpp::amod_action_block_message
*/
std::string custom_message;
/**
* @brief Timeout duration in seconds (Maximum of 2419200), for dpp::amod_action_timeout
*/
uint32_t duration_seconds;
/**
* @brief Construct a new automod action object
*/
automod_action();
/**
* @brief Destroy the automod action object
*/
virtual ~automod_action();
};
/**
* @brief Represents an automod rule
*/
class DPP_EXPORT automod_rule : public managed, public json_interface<automod_rule> {
protected:
friend struct json_interface<automod_rule>;
/**
* @brief Fill object properties from JSON
*
* @param j JSON to fill from
* @return automod_rule& Reference to self
*/
automod_rule& fill_from_json_impl(nlohmann::json* j);
/**
* @brief Build a json string for this object
*
* @return json JSON object
*/
virtual json to_json_impl(bool with_id = false) const;
public:
/**
* @brief the id of this rule
*/
snowflake id;
/**
* @brief the guild which this rule belongs to
*/
snowflake guild_id;
/**
* @brief the rule name
*/
std::string name;
/**
* @brief The user which first created this rule
*/
snowflake creator_id;
/**
* @brief The rule event type
*/
automod_event_type event_type;
/**
* @brief The rule trigger type
*/
automod_trigger_type trigger_type;
/**
* @brief The rule trigger metadata
*/
automod_metadata trigger_metadata;
/**
* @brief the actions which will execute when the rule is triggered
*/
std::vector<automod_action> actions;
/**
* @brief Whether the rule is enabled
*/
bool enabled;
/**
* @brief the role ids that should not be affected by the rule (Maximum of 20)
*/
std::vector<snowflake> exempt_roles;
/**
* @brief the channel ids that should not be affected by the rule (Maximum of 50)
*/
std::vector<snowflake> exempt_channels;
/**
* @brief Construct a new automod rule object
*/
automod_rule();
/**
* @brief Destroy the automod rule object
*/
virtual ~automod_rule();
};
/** A group of automod rules.
*/
typedef std::unordered_map<snowflake, automod_rule> automod_rule_map;
}