Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Auto Moderation #7938

Merged
merged 102 commits into from Nov 19, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
102 commits
Select commit Hold shift + click to select a range
f2ec0c8
feat: initial AutoMod commit
Jiralite May 17, 2022
e20d0ae
types: Typo in class name
Jiralite May 17, 2022
3c527db
refactor: move things around
Jiralite May 19, 2022
406e170
refactor: remove undocumented property
Jiralite May 19, 2022
49841d1
chore: add new intents to issue form
Jiralite May 19, 2022
5c861aa
feat: add initial basic manager
Jiralite May 20, 2022
b7d63d8
feat(AutoModRule): add new properties
Jiralite May 20, 2022
0d56612
feat: add events
Jiralite May 20, 2022
4e204a1
feat(GuildAuditLog): cache rules
Jiralite May 20, 2022
cf635cb
refactor: move JSDoc to where it is actually used
Jiralite May 20, 2022
0fb3b5b
refactor(AutoModRule): add `_patch()` method
Jiralite May 20, 2022
790b9d2
feat(AutoModRuleManager): add resolvers
Jiralite May 20, 2022
57192d6
feat(Sweepers): add new manager
Jiralite May 20, 2022
de8ec4e
types: nullify first parameter of `autoModerationRuleUpdate`
Jiralite May 20, 2022
9554813
types: add manager to `Caches`
Jiralite May 21, 2022
5b13783
docs(AutoModRule): update `metadata` docstring
Jiralite Jun 8, 2022
2e2418a
feat: add execution event
Jiralite Jun 8, 2022
1e0a755
fix(AutoModActionExecution): export class
Jiralite Jun 8, 2022
0bea5a9
refactor(AutoModRule): `triggerType` is not modifiable
Jiralite Jun 8, 2022
e5242e2
docs(AutoModRule): link class
Jiralite Jun 8, 2022
20370ee
feat: add trigger metadata definitions
Jiralite Jun 8, 2022
a211767
docs(AutoModRule): typos
Jiralite Jun 9, 2022
f795acc
feat(AutoModRule): action metadata
Jiralite Jun 9, 2022
edaf89c
types: Proper casing of name
Jiralite Jun 11, 2022
71c06a6
refactor: only patch data if exists
Jiralite Jun 11, 2022
f3c4ffd
types: `preset` is an array
Jiralite Jun 16, 2022
4ba5980
types(AutoModRuleActionMetadata): nullify all
Jiralite Jun 16, 2022
38db382
feat(AutoModRuleManager): add `fetch()`
Jiralite Jun 16, 2022
944e114
docs(AutoModRule): tweak some wording
Jiralite Jun 17, 2022
6b02e27
docs(AutoModRule): use "array" over "list"
Jiralite Jun 17, 2022
1ec9501
docs(AutoModRuleResolvable): fix union
Jiralite Jun 17, 2022
1b3aaab
types: adjust some names
Jiralite Jun 17, 2022
a2df499
feat(AutoModRuleManager): add `create()`
Jiralite Jun 17, 2022
d51dcae
feat(AutoModRuleManager): add `delete()`
Jiralite Jun 17, 2022
80ce437
refactor: prefer full auto moderation name
Jiralite Jun 17, 2022
cf4984c
docs(AutoModerationRuleManager): fix a fetch example
Jiralite Jun 17, 2022
e0895cc
refactor(Sweepers): alphabetise methods
Jiralite Jun 17, 2022
3e0b486
chore: remove testing
Jiralite Jun 17, 2022
7263219
fix(AutoModerationRuleCreateOptions): add `reason`
Jiralite Jun 17, 2022
1c4b392
fix: typo for `presets`
Jiralite Jun 17, 2022
99fc5cd
fix(AutoModerationRuleCreateOptions): `actions` is required
Jiralite Jun 17, 2022
a603557
fix(AutoModerationRuleManager): handle properties that are unrequired
Jiralite Jun 17, 2022
c044f38
feat(AutoModerationRuleManager): add `edit()`
Jiralite Jun 17, 2022
f0cc3fc
feat(GuildAuditLogsEntry): add auto moderation rules
Jiralite Jun 17, 2022
e827509
refactor: prefer "AutoModerationActionExecutionAction"
Jiralite Jun 17, 2022
29191e8
refactor: annotate todos and doc fixes
Jiralite Jun 17, 2022
02a7757
feat(AutoModerationRule): add guild getter
Jiralite Jun 17, 2022
337ad25
docs(AutoModerationRule): rule -> auto moderation rule
Jiralite Jun 17, 2022
de72ff0
docs(AutoModerationRuleEditOptions): `eventType` is optional
Jiralite Jun 17, 2022
108e30f
feat(AutoModerationRule): add helpers
Jiralite Jun 17, 2022
caf42ad
docs: random string updates
Jiralite Jun 17, 2022
0c2c238
chore: add TODOs
Jiralite Jun 17, 2022
89d24a1
feat(AutoModerationActionExecution): add helpers
Jiralite Jun 17, 2022
0af612f
feat: support role and channel resolvables
Jiralite Jun 17, 2022
3e43408
chore: high priority todo to keep me in solitary
Jiralite Jun 17, 2022
de5383d
refactor(AutoModerationActionMetadataOptions): allow resolvables
Jiralite Jun 17, 2022
ea94eae
chore: tidy up from merge
Jiralite Jun 17, 2022
a8ac01d
docs(AutoModerationRule): document extension
Jiralite Jun 17, 2022
7d2eb34
feat: export `AutoModerationRuleManager`
Jiralite Jun 17, 2022
e2b232c
chore(ActionsManager): add new actions
Jiralite Jun 17, 2022
fc4dedf
chore: add to websocket index
Jiralite Jun 17, 2022
5c8c0f8
refactor(AutoModerationActionExecution): send the guild across
Jiralite Jun 18, 2022
e5dd9b8
docs(AutoModerationActionExecution): typo
Jiralite Jun 18, 2022
a3e56ab
docs(AutoModerationRule): deduplicate a word
Jiralite Jun 18, 2022
b82fd48
docs(Guild): dot
Jiralite Jun 18, 2022
1d6f8af
test: add some basic tests
Jiralite Jun 18, 2022
91594dc
docs(AutoModerationRuleManager): fetch is optional
Jiralite Jun 19, 2022
8a712b5
docs(AutoModerationActionExecution): prefer non-links
Jiralite Jun 19, 2022
e01eb2b
types: `presets` is an array of numbers
Jiralite Jun 19, 2022
178871f
docs(AutoModerationRuleEditOptions): `name` is optional
Jiralite Jun 19, 2022
e8792f6
docs(AutoModerationRule): fix type for `exemptChannels`
Jiralite Jun 19, 2022
ab0fe49
docs(AutoModerationRuleUpdateAction): remove "object"
Jiralite Jun 19, 2022
c90725d
feat: add `allow_list`
Jiralite Jun 25, 2022
d8be2b3
fix(GuildAuditLogsEntry): pass guild
Jiralite Jul 3, 2022
8188229
docs(AutoModerationRuleManager): correct fetch example
Jiralite Jul 8, 2022
99ab9a8
chore: prettier
Jiralite Jul 8, 2022
eb2e542
refactor: remove unneeded optional chaining operator
Jiralite Jul 9, 2022
7facfa3
feat: add mention limit
Jiralite Jul 20, 2022
5139c84
docs(AutoModerationRuleManager): document new requirement
Jiralite Jul 20, 2022
9bb046b
refactor: conform to message content intent
Jiralite Jul 25, 2022
cd19ff8
docs: document permission for event
Jiralite Jul 25, 2022
59f8f0a
docs: refactor intent message
Jiralite Jul 25, 2022
ed22cf7
docs: dot
Jiralite Jul 25, 2022
10c038d
docs: remove string in link
Jiralite Jul 26, 2022
3107426
refactor: document upstream changes
Jiralite Aug 8, 2022
c105294
fix(AutoModerationRuleDelete): Correct event fire
Jiralite Aug 15, 2022
d097687
feat(AutoModerationRule): Add `setMentionTotalLimit()` helper method
Jiralite Aug 15, 2022
6a238f6
feat(AuditLogEntries): add new extra fields
Jiralite Aug 18, 2022
a96e166
types: add `guild` in constructors
Jiralite Aug 20, 2022
253687d
types: update typings
Jiralite Sep 18, 2022
5a0df6a
refactor(AutoModerationRuleManager): `&&` shorthand
Jiralite Oct 13, 2022
9a0a84a
types: remove leftover type
Jiralite Oct 13, 2022
eeca7bc
chore: types
Jiralite Oct 14, 2022
06a7736
docs: update API types
Jiralite Oct 14, 2022
d9e4027
docs: Tweak guild wording
Jiralite Nov 4, 2022
058ba33
Merge remote-tracking branch 'upstream/main' into feat/auto-moderation
Jiralite Nov 7, 2022
d1140b6
feat: add regular expression matching
Jiralite Nov 7, 2022
40e5f15
docs: update `allowList` wording
Jiralite Nov 15, 2022
e057483
refactor: deduplicate `guildId`
Jiralite Nov 15, 2022
86050d0
Merge branch 'main' into feat/auto-moderation
Jiralite Nov 19, 2022
7fa11cc
Merge branch 'main' into feat/auto-moderation
Jiralite Nov 19, 2022
e4c1f63
Merge branch 'main' into feat/auto-moderation
Jiralite Nov 19, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -28,6 +28,8 @@ class AutoModerationRuleManager extends CachedManager {
* Options used to set the trigger metadata of an auto moderation rule.
* @typedef {Object} AutoModerationTriggerMetadataOptions
* @property {string[]} [keywordFilter] The substrings that will be searched for in the content
* @property {string[]} [regexPatterns] The regular expression patterns which will be matched against the content
* <info>Only Rust-flavored regular expressions are supported.</info>
* @property {AutoModerationRuleKeywordPresetType[]} [presets]
* The internally pre-defined wordsets which will be searched for in the content
* @property {string[]} [allowList] The substrings that will be exempt from triggering trigger type 4
Expand Down Expand Up @@ -93,6 +95,7 @@ class AutoModerationRuleManager extends CachedManager {
trigger_type: triggerType,
trigger_metadata: triggerMetadata && {
keyword_filter: triggerMetadata.keywordFilter,
regex_patterns: triggerMetadata.regexPatterns,
presets: triggerMetadata.presets,
allow_list: triggerMetadata.allowList,
mention_total_limit: triggerMetadata.mentionTotalLimit,
Expand Down Expand Up @@ -148,6 +151,7 @@ class AutoModerationRuleManager extends CachedManager {
event_type: eventType,
trigger_metadata: triggerMetadata && {
keyword_filter: triggerMetadata.keywordFilter,
regex_patterns: triggerMetadata.regexPatterns,
presets: triggerMetadata.presets,
allow_list: triggerMetadata.allowList,
mention_total_limit: triggerMetadata.mentionTotalLimit,
Expand Down
14 changes: 14 additions & 0 deletions packages/discord.js/src/structures/AutoModerationRule.js
Expand Up @@ -66,6 +66,8 @@ class AutoModerationRule extends Base {
* Additional data used to determine whether an auto moderation rule should be triggered.
* @typedef {Object} AutoModerationTriggerMetadata
* @property {string[]} keywordFilter The substrings that will be searched for in the content
* @property {string[]} regexPatterns The regular expression patterns which will be matched against the content
* <info>Only Rust-flavored regular expressions are supported.</info>
* @property {AutoModerationRuleKeywordPresetType[]} presets
* The internally pre-defined wordsets which will be searched for in the content
* @property {string[]} allowList The substrings that will be exempt from triggering
Expand All @@ -79,6 +81,7 @@ class AutoModerationRule extends Base {
*/
this.triggerMetadata = {
keywordFilter: data.trigger_metadata.keyword_filter ?? [],
regexPatterns: data.trigger_metadata.regex_patterns ?? [],
presets: data.trigger_metadata.presets ?? [],
allowList: data.trigger_metadata.allow_list ?? [],
mentionTotalLimit: data.trigger_metadata.mention_total_limit ?? null,
Expand Down Expand Up @@ -190,6 +193,17 @@ class AutoModerationRule extends Base {
return this.edit({ triggerMetadata: { keywordFilter }, reason });
}

/**
* Sets the regular expression patterns for this auto moderation rule.
* @param {string[]} regexPatterns The regular expression patterns of this auto moderation rule
* <info>Only Rust-flavored regular expressions are supported.</info>
* @param {string} [reason] The reason for changing the regular expression patterns of this auto moderation rule
* @returns {Promise<AutoModerationRule>}
*/
setRegexPatterns(regexPatterns, reason) {
Jiralite marked this conversation as resolved.
Show resolved Hide resolved
return this.edit({ triggerMetadata: { regexPatterns }, reason });
}

/**
* Sets the presets for this auto moderation rule.
* @param {AutoModerationRuleKeywordPresetType[]} presets The presets of this auto moderation rule
Expand Down
2 changes: 2 additions & 0 deletions packages/discord.js/typings/index.d.ts
Expand Up @@ -362,6 +362,7 @@ export class AutoModerationRule extends Base {
public setName(name: string, reason?: string): Promise<AutoModerationRule>;
public setEventType(eventType: AutoModerationRuleEventType, reason?: string): Promise<AutoModerationRule>;
public setKeywordFilter(keywordFilter: string[], reason?: string): Promise<AutoModerationRule>;
public setRegexPatterns(regexPatterns: string[], reason?: string): Promise<AutoModerationRule>;
public setPresets(presets: AutoModerationRuleKeywordPresetType[], reason?: string): Promise<AutoModerationRule>;
public setAllowList(allowList: string[], reason?: string): Promise<AutoModerationRule>;
public setMentionTotalLimit(mentionTotalLimit: number, reason?: string): Promise<AutoModerationRule>;
Expand Down Expand Up @@ -4443,6 +4444,7 @@ export interface AutoModerationActionMetadata {

export interface AutoModerationTriggerMetadata {
keywordFilter: string[];
regexPatterns: string[];
presets: AutoModerationRuleKeywordPresetType[];
allowList: string[];
mentionTotalLimit: number | null;
Expand Down