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

Introducing auto moderation #2159

Closed
Closed
Show file tree
Hide file tree
Changes from 11 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
29b546c
update the intents for auto moderation.
RealYusufIsmail Jun 18, 2022
5749089
Finished with all the Auto Moderation enums and interfaces.
RealYusufIsmail Jun 18, 2022
054d1dd
Added copyright
RealYusufIsmail Jun 18, 2022
6da8270
Finished with impls and Entity builder
RealYusufIsmail Jun 18, 2022
db47def
Finished with the java doc
RealYusufIsmail Jun 18, 2022
5e3b8ad
Continued adding the AuditLogKey tomorrow
RealYusufIsmail Jun 18, 2022
4ad07c6
Finished with the Audit for auto moderation
RealYusufIsmail Jun 19, 2022
8fa3cb3
Adding missing </ul>
RealYusufIsmail Jun 19, 2022
fb5ca0a
Finished with auto moderation create handler
RealYusufIsmail Jun 19, 2022
bc7d164
added create event to ListenerAdapter
RealYusufIsmail Jun 19, 2022
e7a0a0a
Added Java Doc
RealYusufIsmail Jun 19, 2022
aee3126
Updated some java doc
RealYusufIsmail Jun 19, 2022
bcd71b0
Update more java doc and some tweaks
RealYusufIsmail Jun 19, 2022
a882a4e
Thats it for today
RealYusufIsmail Jun 19, 2022
d654a7b
some minor tweaks and also added delete event
RealYusufIsmail Jun 19, 2022
b3d9675
Merge branch 'master' into updat/intents
RealYusufIsmail Jun 19, 2022
21d5f7c
Pretty much done
RealYusufIsmail Jun 20, 2022
f981524
Save
RealYusufIsmail Jun 20, 2022
16846a7
Fixed an error
RealYusufIsmail Jun 20, 2022
04e3c81
modifyAutoModerationRule left
RealYusufIsmail Jun 20, 2022
1541b9f
Added a todo
RealYusufIsmail Jun 20, 2022
3e1bafb
Added java doc for update events
RealYusufIsmail Jun 21, 2022
0088004
cleaned up the handlers
RealYusufIsmail Jun 21, 2022
ce4caf2
Cleaned up most of the code.
RealYusufIsmail Jun 21, 2022
bab9490
fixed an error
RealYusufIsmail Jun 21, 2022
26b5444
missing doc + minor class cleanup
RealYusufIsmail Jun 21, 2022
4e977df
Finished with modify
RealYusufIsmail Jun 21, 2022
80cc57b
Update intents to match the breaking changes
RealYusufIsmail Jun 22, 2022
e8cd6ac
doc update
RealYusufIsmail Jun 22, 2022
f8c4415
forgot about AUTO_MODERATION_ACTION_EXECUTION
RealYusufIsmail Jun 22, 2022
71eb683
hmm
RealYusufIsmail Jun 22, 2022
2601a05
return null;
RealYusufIsmail Jun 22, 2022
b928040
Added a TODO
RealYusufIsmail Jun 22, 2022
a1169f4
Reformatted most of the code.
RealYusufIsmail Jun 22, 2022
8dbae4d
Merge branch 'master' into updat/intents
RealYusufIsmail Jun 22, 2022
0bb88f3
Update some java doc and some code
RealYusufIsmail Jun 23, 2022
feb2832
quick fix
RealYusufIsmail Jun 23, 2022
a82925b
some import clean up
RealYusufIsmail Jun 23, 2022
4620db0
some minor doc updates
RealYusufIsmail Jun 23, 2022
70fa2f7
add ignore ds store
RealYusufIsmail Jun 23, 2022
2336a0e
Made the required changes
RealYusufIsmail Jun 26, 2022
2d6c7e0
optimising imports
RealYusufIsmail Jun 26, 2022
223a2af
Merge branch 'master' into updat/intents
RealYusufIsmail Jun 28, 2022
f0893db
Updated the alignment
RealYusufIsmail Jun 28, 2022
b7697a6
Update ActionType.java
RealYusufIsmail Jun 28, 2022
8346dc8
Made some required changes(not all of it)
RealYusufIsmail Jun 28, 2022
570d180
Made some doc changes and move some classess
RealYusufIsmail Jun 29, 2022
1398909
Changed code to rule_id
RealYusufIsmail Jun 29, 2022
1074469
Updated the event update names
RealYusufIsmail Jun 29, 2022
412bc65
Fixed some import issues
RealYusufIsmail Jun 30, 2022
de4650d
Updated event java doc
RealYusufIsmail Jun 30, 2022
0bd8c05
Trying something with the create rule
RealYusufIsmail Jun 30, 2022
d1f6b60
remove ```@NotNul```
RealYusufIsmail Jun 30, 2022
a11bfa2
AutoModerationRuledDataImpl to AutoModerationRuledData in createAutoM…
RealYusufIsmail Jun 30, 2022
1c2b00f
casr
RealYusufIsmail Jun 30, 2022
71f436d
renamed from AutoModerationRuledData to AutoModerationRuleData
RealYusufIsmail Jul 1, 2022
8e03086
added Collections.unmodifiableList
RealYusufIsmail Jul 1, 2022
5b5db14
Finished with Modify
RealYusufIsmail Jul 1, 2022
e5e0af1
some minor java doc fixeses
RealYusufIsmail Jul 1, 2022
f07ffc7
Update AutoModerationRuleDataImpl.java
RealYusufIsmail Jul 1, 2022
3a352dc
some minor tweaks
RealYusufIsmail Jul 2, 2022
55a398e
removed SortedSnowflakeCacheViewImpl<AutoModerationRule>
RealYusufIsmail Jul 3, 2022
c8ab12e
Update GuildImpl.java
RealYusufIsmail Jul 3, 2022
9dffc59
Merge branch 'master' into updat/intents
RealYusufIsmail Jul 3, 2022
3918023
Adding missing java doc
RealYusufIsmail Jul 11, 2022
bd453fe
Merge branch 'master' into updat/intents
RealYusufIsmail Jul 11, 2022
7203946
fixed the error
RealYusufIsmail Jul 11, 2022
5297aa2
Update AutoModerationRuleData.java
RealYusufIsmail Jul 11, 2022
d78e9e1
finished java doc
RealYusufIsmail Jul 11, 2022
50de4c9
pretty much finish
RealYusufIsmail Jul 11, 2022
97a8c94
Thnking about how it should work
RealYusufIsmail Jul 11, 2022
fc792c5
save
RealYusufIsmail Jul 11, 2022
0c612d0
Improved rule create system
RealYusufIsmail Jul 12, 2022
8435e05
hard coded the trigger types for keyword and preset
RealYusufIsmail Jul 12, 2022
4623d5a
Updated rule java doc
RealYusufIsmail Jul 12, 2022
2d1fab4
Merge branch 'master' into updat/intents
RealYusufIsmail Jul 17, 2022
529199a
Merge branch 'master' into updat/intents
RealYusufIsmail Jul 29, 2022
1dd766e
added some new changes
RealYusufIsmail Aug 5, 2022
e2cbbc7
Merge branch 'master' into updat/intents
RealYusufIsmail Aug 5, 2022
91618af
setKeyword to setExemptSubstrings in ExemptSubstrings
RealYusufIsmail Aug 6, 2022
400659e
Not done yet
RealYusufIsmail Aug 24, 2022
5e21963
added MentionTotalLimit
RealYusufIsmail Aug 24, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions src/main/java/net/dv8tion/jda/api/audit/ActionType.java
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,71 @@ public enum ActionType
*/
THREAD_DELETE(112, TargetType.THREAD),

/**
* A user created a {@link net.dv8tion.jda.api.entities.AutoModerationRule auto-moderation rule}
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <h4>Possible Keys</h4>
* <ul>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#ID ID}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_GUILD_ID GUILD}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_RULE_NAME RULE_NAME}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_CREATOR CREATOR}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EVENT_TYPE EVENT_TYPE}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_TRIGGER_TYPE TRIGGER_TYPE}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_TRIGGER_METADATA METADETA}</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_ACTIONS}&gt;</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_ENABLED ENABLED}</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EXEMPT_ROLES}&gt;</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EXEMPT_CHANNELS}&gt;</li>
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
* </ul>
*/
AUTO_MODERATION_RULE_CREATE(140, TargetType.AUTO_MODERATION_RULE),

/**
* A user updated a {@link net.dv8tion.jda.api.entities.AutoModerationRule auto-moderation rule}
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <h4>Possible Keys</h4>
* <ul>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#ID ID}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_GUILD_ID GUILD}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_RULE_NAME RULE_NAME}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_CREATOR CREATOR}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EVENT_TYPE EVENT_TYPE}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_TRIGGER_TYPE TRIGGER_TYPE}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_TRIGGER_METADATA METADETA}</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_ACTIONS}&gt;</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_ENABLED ENABLED}</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EXEMPT_ROLES}&gt;</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EXEMPT_CHANNELS}&gt;</li>
* </ul>
*/
AUTO_MODERATION_RULE_UPDATE(141, TargetType.AUTO_MODERATION_RULE),

/**
* A user deleted a {@link net.dv8tion.jda.api.entities.AutoModerationRule auto-moderation rule}
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <h4>Possible Keys</h4>
* <ul>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#ID ID}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_GUILD_ID GUILD}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_RULE_NAME RULE_NAME}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_CREATOR CREATOR}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EVENT_TYPE EVENT_TYPE}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_TRIGGER_TYPE TRIGGER_TYPE}</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_TRIGGER_METADATA METADETA}</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_ACTIONS}&gt;</li>
* <li>{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_ENABLED ENABLED}</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EXEMPT_ROLES}&gt;</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.audit.AuditLogKey#AUTO_MODERATION_EXEMPT_CHANNELS}&gt;</li>
* </ul>
*/
AUTO_MODERATION_RULE_DELETE(142, TargetType.AUTO_MODERATION_RULE),

/**
* When a message is blocked by the {@link net.dv8tion.jda.api.entities.AutoModerationRule auto-moderation rule}
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
AUTO_MODERATION_BLOCK_MESSAGE(143, TargetType.AUTO_MODERATION_RULE),

UNKNOWN(-1, TargetType.UNKNOWN);

private final int key;
Expand Down
79 changes: 78 additions & 1 deletion src/main/java/net/dv8tion/jda/api/audit/AuditLogKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,85 @@ public enum AuditLogKey
*
* <p>Expected type: <b>int</b>
*/
INVITE_MAX_USES("max_uses");
INVITE_MAX_USES("max_uses"),

/**
* The guild where the auto moderation rule was created in.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_GUILD_ID("guild_id"),

/**
* The name of the rule which was created/updated/deleted.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_RULE_NAME("name"),

/**
* The name of the user who created/updated/deleted the rule.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_CREATOR("user"),

/**
* The event will cause the auto-moderation system to check for a specific trigger.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>Integer</b>
*/
AUTO_MODERATION_EVENT_TYPE("event_type"),

/**
* What caused the auto moderation system to be triggered.
*
* <p>Expected type: <b>Integer</b>
*/
AUTO_MODERATION_TRIGGER_TYPE("trigger_type"),

/**
* This is additional data used whether a rule should be executed or not.
*
* <p>Expected types:
* <ul>
* <li>{@link java.util.List}&lt;{@link java.lang.String}&gt;</li>
* <li>{@link java.util.List}&lt;{@link net.dv8tion.jda.api.entities.KeywordPresetType}&gt;</li>
* </ul>
*/
AUTO_MODERATION_TRIGGER_METADATA("trigger_metadata"),

/**
* The actions which will carried out when the rule is triggered.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected types:
* <ul>
* <li>{@link net.dv8tion.jda.api.entities.ActionType}</li>
* <li>{@link net.dv8tion.jda.api.entities.ActionMetadata}</li>
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
* </ul>
*/
AUTO_MODERATION_ACTIONS("actions"),

/**
* Weather this rule is enabled or not.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>boolean</b>
*/
AUTO_MODERATION_ENABLED("enabled"),

/**
* The role which is exempt from the rules
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_EXEMPT_ROLES("exempt_roles"),

/**
* The channel which is exempt from the rules
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_EXEMPT_CHANNELS("exempt_channels");

private final String key;

Expand Down
1 change: 1 addition & 0 deletions src/main/java/net/dv8tion/jda/api/audit/TargetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ public enum TargetType
INTEGRATION,
STAGE_INSTANCE,
THREAD,
AUTO_MODERATION_RULE,
UNKNOWN
}
39 changes: 39 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ActionMetadata.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA 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.
*/

package net.dv8tion.jda.api.entities;
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved

/**
* This is additional data which is used when an action is executed by the auto-moderation system.
*
* <br>
* Different values depend on the {@link ActionType ActionType} of the action.
*/
public interface ActionMetadata {
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
/**
* The channel where the logging of the auto-moderation rule breaking should be sent to.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* @return {@link net.dv8tion.jda.api.entities.TextChannel TextChannel}
*/
TextChannel getChannel();

/**
* The duration of the timeout in seconds.
*
* @return {@link java.lang.Integer Integer}
*/
int getDuration();
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
}
59 changes: 59 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/ActionType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA 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.
*/

package net.dv8tion.jda.api.entities;
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved

/**
* Represents the type of action that was performed when a one rules set in the auto-moderation system was broken.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
public enum ActionType
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* Blocks the message if the message breaks the auto-moderation rules.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
BLOCK_MESSAGE(1),
/**
* Sends an alert to a specific channel if a member breaks the auto-moderation rules.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
SEND_ALERT_MESSAGE(2),
/**
* Times out the member who broke the auto-moderation rules.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
TIMEOUT(3),
/**
* An unknown action type.
*/
UNKNOWN(-1);

private final int value;

ActionType(int value) {
this.value = value;
}

public int getValue() {
return value;
}

public static ActionType fromValue(int value) {
for (ActionType type : values()) {
if (type.value == value) {
return type;
}
}
return UNKNOWN;
}
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* Copyright 2015 Austin Keener, Michael Ritter, Florian Spieß, and the JDA 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.
*/

package net.dv8tion.jda.api.entities;
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* This is the action which will be executed by the auto-moderation system when a rule is triggered.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
public interface AutoModerationAction {
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
/**
* Gets the action type.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* @return {@link ActionType ActionTypes}
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
@Nonnull
ActionType getActionType();

/**
* Additional metadata needed during the execution for this specific action type
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*
* @return {@link ActionMetadata ActionMetadata}
*/
@Nullable
ActionMetadata getActionMetadata();
}
Loading