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 40 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ src-old/examples/java/TestReceive.java
src-old/main/java/net/dv8tion/jda/events/audio/AudioMovedEvent.java
src-old/main/java/net/dv8tion/jda/ratelimit/Bucket.java
src-old/main/java/net/dv8tion/jda/ratelimit/RateLimitControl.java

# MacOS files
.DS_Store
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 @@ -533,6 +533,71 @@ public enum ActionType
*/
THREAD_DELETE(112, TargetType.THREAD),

/**
* A user created an {@link net.dv8tion.jda.api.entities.AutoModerationRule auto moderation rule}
*
* <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 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 an {@link net.dv8tion.jda.api.entities.AutoModerationRule auto moderation rule}
*
* <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 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 an {@link net.dv8tion.jda.api.entities.AutoModerationRule auto moderation rule}
*
* <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 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 an {@link net.dv8tion.jda.api.entities.AutoModerationRule auto moderation rule}
*/
AUTO_MODERATION_BLOCK_MESSAGE(143, TargetType.AUTO_MODERATION_RULE),

UNKNOWN(-1, TargetType.UNKNOWN);

private final int key;
Expand Down
81 changes: 80 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 @@ -20,6 +20,8 @@
import net.dv8tion.jda.api.entities.GuildChannel;
import net.dv8tion.jda.api.entities.ICategorizableChannel;
import net.dv8tion.jda.api.entities.ThreadChannel;
import net.dv8tion.jda.api.entities.automod.AutoModerationActionType;
import net.dv8tion.jda.api.entities.automod.KeywordPresetType;
import net.dv8tion.jda.api.entities.emoji.RichCustomEmoji;

/**
Expand Down Expand Up @@ -560,8 +562,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.
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_GUILD("guild_id"),

/**
* The name of the auto moderation rule that was created/updated/deleted.
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_RULE_NAME("name"),

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

/**
* The event that will cause the auto moderation system to check for a specific trigger.
*
* <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><b>A list of keyword filter (String)</b></li>
* <li><b>A list of presets values (int)</b></li>
* </ul>
*/
AUTO_MODERATION_TRIGGER_METADATA("trigger_metadata"),

/**
* The actions which will be carried out when the auto moderation rule is executed.
*
* <p>Expected types:
* <ul>
* <li><b>action type object</b></li>
* <li><b>action metadata object</b></li>
* </ul>
*/
AUTO_MODERATION_ACTIONS("actions"),

/**
* Whether this auto moderation rule is enabled or not.
*
* <p>Expected type: <b>boolean</b>
*/
AUTO_MODERATION_ENABLED("enabled"),

/**
* The roles that are exempt from an auto moderation rule.
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_EXEMPT_ROLES("exempt_roles"),

/**
* The guild channels that are exempt from an auto moderation rule.
*
* <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
}
111 changes: 111 additions & 0 deletions src/main/java/net/dv8tion/jda/api/entities/AutoModerationRule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* 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
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved

import net.dv8tion.jda.api.entities.automod.AutoModerationAction;
import net.dv8tion.jda.api.entities.automod.EventType;
import net.dv8tion.jda.api.entities.automod.TriggerMetadata;
import net.dv8tion.jda.api.entities.automod.TriggerType;

import javax.annotation.Nonnull;
import java.util.List;

/**
* Represents a Discord auto moderation rule.
* <br>
* Auto Moderation is a feature which allows each guild to set up rules that trigger based on some criteria.
* For example, a rule can trigger whenever a message contains a specific keyword.
*/
public interface AutoModerationRule extends ISnowflake, Comparable<AutoModerationRule>
{
/**
* Returns the Guild that the rule belongs to.
*
* @return {@link Guild Guild}
*/
@Nonnull
Guild getGuild();

/**
* Returns the name of the rule.
*
* @return {@link String String}
*/
@Nonnull
String getName();

/**
* Returns the user who created the rule.
*
* @return {@link User User}
*/
@Nonnull
User getUser();

/**
* Returns the type of event that can potentially trigger this rule.
*
* @return {@link EventType EventType}
*/
@Nonnull
EventType getEventType();

/**
* Returns the type of trigger that can cause this rule to be executed.
*
* @return {@link TriggerType TriggerTypes}
*/
@Nonnull
TriggerType getTriggerType();

/**
* Returns additional metadata for the trigger of this rule, used whenever this rule is executed.
*
* @return {@link TriggerMetadata TriggerMetadata}
*/
@Nonnull
TriggerMetadata getTriggerMetadata();

/**
* Returns the actions that will be performed when this rule is executed.
*
* @return A {@link List List} of {@link AutoModerationAction Actions}
*/
@Nonnull
List<AutoModerationAction> getActions();

/**
* Returns whether this rule is enabled or not.
*
* @return True, if this is enabled
*/
boolean isEnabled();

/**
* Returns the roles that are exempt from this rule.
*
* @return A {@link List List} of {@link Role Roles} which are exempt from the rules.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
List<Role> getExemptRoles();

/**
* Returns the channels that are exempt from this rule.
*
* @return A {@link List List} of {@link GuildChannel Channels} which are exempt from the rules.
RealYusufIsmail marked this conversation as resolved.
Show resolved Hide resolved
*/
List<GuildChannel> getExemptChannels();
}
Loading