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

Add automod support #2429

Merged
merged 39 commits into from
May 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
ad93737
Basic automod support
MinnDevelopment Mar 26, 2023
2dc6f4e
Add keyword rules
MinnDevelopment Mar 26, 2023
71c699a
Add anit-spam rule
MinnDevelopment Mar 26, 2023
f1dd910
Add some basic checks
MinnDevelopment Mar 26, 2023
381e306
Add some docs for factory methods
MinnDevelopment Mar 26, 2023
e0c652b
Add new intents
MinnDevelopment Mar 26, 2023
6b528b9
Add events
MinnDevelopment Mar 26, 2023
a2b171d
Use correct dispatch method (copilot moment)
MinnDevelopment Mar 26, 2023
2de9e1d
Make channel nullable
MinnDevelopment Mar 26, 2023
dd65785
Rework builders
MinnDevelopment Mar 27, 2023
0097c21
Rename types for consistency
MinnDevelopment Mar 27, 2023
9c88e62
Add permission checks
MinnDevelopment Mar 27, 2023
008096b
Add some more checks
MinnDevelopment Mar 27, 2023
33a1b52
Update GatewayIntent#fromEvents
MinnDevelopment Mar 29, 2023
9ababb8
Allow passing keywords and presets in factory
MinnDevelopment Mar 29, 2023
cd711e4
Add check for unknown preset
MinnDevelopment Mar 29, 2023
c5f2efa
Add TriggerConfig#patternFilter
MinnDevelopment Mar 29, 2023
ebbdf9a
Add relevant audit-log features
MinnDevelopment Mar 29, 2023
0870ddf
Add docs to trigger configs
MinnDevelopment Mar 29, 2023
e8ba84d
Add docs to AutoModRuleData
MinnDevelopment Mar 29, 2023
bb8eea1
Update audit-logs
MinnDevelopment Mar 30, 2023
9caf9a3
Fix indentation
MinnDevelopment Mar 30, 2023
e90818b
Add docs for response and event type
MinnDevelopment Mar 31, 2023
8b2f9ec
Fix wrong json keys
MinnDevelopment Mar 31, 2023
858a835
Add docs to AutoModExecution
MinnDevelopment Mar 31, 2023
54944d2
Add event docs
MinnDevelopment Mar 31, 2023
4d89d37
Handle guild lock in execution handler
MinnDevelopment Mar 31, 2023
7775523
Add docs to AutoModRule
MinnDevelopment Apr 2, 2023
536f355
Add docs to AutoModRuleManager
MinnDevelopment Apr 2, 2023
6c5b1ba
Add checks to manager
MinnDevelopment Apr 2, 2023
5430394
Improve checks
MinnDevelopment Apr 2, 2023
97a4221
Add new ErrorResponses
MinnDevelopment Apr 2, 2023
d8f85af
Add remaining docs
MinnDevelopment Apr 2, 2023
fb335d1
Rename action type
MinnDevelopment Apr 2, 2023
6ca4831
Update TargetType
MinnDevelopment Apr 2, 2023
6b17e4c
Add support for member profile automod
MinnDevelopment May 5, 2023
044c648
Add mention raid protection
MinnDevelopment May 5, 2023
17697ea
Improve type checks
MinnDevelopment May 7, 2023
b2ad2e8
Remove profile api again
MinnDevelopment May 20, 2023
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
49 changes: 49 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 @@ -586,6 +586,55 @@ public enum ActionType
*/
APPLICATION_COMMAND_PRIVILEGES_UPDATE(121, TargetType.INTEGRATION),

/**
* A moderator created a new {@link net.dv8tion.jda.api.entities.automod.AutoModRule AutoModRule}
*/
AUTO_MODERATION_RULE_CREATE(140, TargetType.AUTO_MODERATION_RULE),

/**
* A moderator updated an existing {@link net.dv8tion.jda.api.entities.automod.AutoModRule AutoModRule}
*/
AUTO_MODERATION_RULE_UPDATE(141, TargetType.AUTO_MODERATION_RULE),

/**
* A moderator deleted an existing {@link net.dv8tion.jda.api.entities.automod.AutoModRule AutoModRule}
*/
AUTO_MODERATION_RULE_DELETE(142, TargetType.AUTO_MODERATION_RULE),

/**
* An automod rule blocked a message from being sent
*
* <p><b>Possible Keys</b><br>
* <ul>
* <li>{@link AuditLogKey#AUTO_MODERATION_RULE_NAME AUTO_MODERATION_RULE_NAME}</li>
* <li>{@link AuditLogKey#AUTO_MODERATION_RULE_TRIGGER_TYPE AUTO_MODERATION_RULE_TRIGGER_TYPE}</li>
* <li>{@link AuditLogKey#CHANNEL_ID CHANNEL_ID}</li>
* </ul>
*/
AUTO_MODERATION_RULE_BLOCK_MESSAGE(143, TargetType.MEMBER),

/**
* An automod rule sent an alert to a channel
*
* <p><b>Possible Keys</b><br>
* <ul>
* <li>{@link AuditLogKey#AUTO_MODERATION_RULE_NAME AUTO_MODERATION_RULE_NAME}</li>
* <li>{@link AuditLogKey#AUTO_MODERATION_RULE_TRIGGER_TYPE AUTO_MODERATION_RULE_TRIGGER_TYPE}</li>
* </ul>
*/
AUTO_MODERATION_FLAG_TO_CHANNEL( 144, TargetType.MEMBER),

/**
* An automod rule put a user in {@link Member#isTimedOut() timeout}
*
* <p><b>Possible Keys</b><br>
* <ul>
* <li>{@link AuditLogKey#AUTO_MODERATION_RULE_NAME AUTO_MODERATION_RULE_NAME}</li>
* <li>{@link AuditLogKey#AUTO_MODERATION_RULE_TRIGGER_TYPE AUTO_MODERATION_RULE_TRIGGER_TYPE}</li>
* </ul>
*/
AUTO_MODERATION_MEMBER_TIMEOUT( 145, TargetType.MEMBER),

UNKNOWN(-1, TargetType.UNKNOWN);

private final int key;
Expand Down
29 changes: 28 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.annotations.ForRemoval;
import net.dv8tion.jda.annotations.ReplaceWith;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.automod.AutoModRule;
import net.dv8tion.jda.api.entities.automod.AutoModTriggerType;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.ChannelType;
import net.dv8tion.jda.api.entities.channel.attribute.ICategorizableChannel;
Expand Down Expand Up @@ -312,6 +314,13 @@ public enum AuditLogKey
*/
CHANNEL_AVAILABLE_TAGS("available_tags"),

/**
* The relevant channel for the audit log entry.
*
* <p>Expected type: <b>String</b>
*/
CHANNEL_ID("channel_id"),

// /**
// * The {@link ForumChannel#getDefaultSortOrder()} value.
// * <br>Only for {@link ChannelType#FORUM}.
Expand Down Expand Up @@ -657,7 +666,25 @@ public enum AuditLogKey
*
* <p>Expected type: <b>int</b>
*/
INVITE_MAX_USES("max_uses");
INVITE_MAX_USES("max_uses"),

// AUTO MODERATION
/**
* Change of the {@link AutoModRule#getName()} for the target {@link AutoModRule}
*
* <p>Expected type: <b>String</b>
*/
AUTO_MODERATION_RULE_NAME("auto_moderation_rule_name"),

/**
* The {@link AutoModRule#getTriggerType()} for an {@link AutoModRule} trigger
*
* <p>Use with {@link AutoModTriggerType#fromKey(int)}
*
* <p>Expected type: <b>int</b>
*/
AUTO_MODERATION_RULE_TRIGGER_TYPE("auto_moderation_rule_trigger_type"),
;


private final String key;
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/dv8tion/jda/api/audit/TargetType.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public enum TargetType
STAGE_INSTANCE,
STICKER,
THREAD,
SCHEDULED_EVENT,
SCHEDULED_EVENT,
AUTO_MODERATION_RULE,
UNKNOWN
}
145 changes: 141 additions & 4 deletions src/main/java/net/dv8tion/jda/api/entities/Guild.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
import net.dv8tion.jda.api.JDA;
import net.dv8tion.jda.api.Permission;
import net.dv8tion.jda.api.Region;
import net.dv8tion.jda.api.entities.automod.AutoModResponse;
import net.dv8tion.jda.api.entities.automod.AutoModRule;
import net.dv8tion.jda.api.entities.automod.AutoModTriggerType;
import net.dv8tion.jda.api.entities.automod.build.AutoModRuleData;
import net.dv8tion.jda.api.entities.channel.Channel;
import net.dv8tion.jda.api.entities.channel.attribute.ICopyableChannel;
import net.dv8tion.jda.api.entities.channel.attribute.IGuildChannelContainer;
Expand All @@ -41,10 +45,7 @@
import net.dv8tion.jda.api.interactions.commands.build.CommandData;
import net.dv8tion.jda.api.interactions.commands.build.Commands;
import net.dv8tion.jda.api.interactions.commands.privileges.IntegrationPrivilege;
import net.dv8tion.jda.api.managers.AudioManager;
import net.dv8tion.jda.api.managers.GuildManager;
import net.dv8tion.jda.api.managers.GuildStickerManager;
import net.dv8tion.jda.api.managers.GuildWelcomeScreenManager;
import net.dv8tion.jda.api.managers.*;
import net.dv8tion.jda.api.requests.GatewayIntent;
import net.dv8tion.jda.api.requests.RestAction;
import net.dv8tion.jda.api.requests.restaction.*;
Expand Down Expand Up @@ -405,6 +406,142 @@ default RestAction<EnumSet<Region>> retrieveRegions()
@CheckReturnValue
RestAction<EnumSet<Region>> retrieveRegions(boolean includeDeprecated);

/**
* Retrieves all current {@link AutoModRule AutoModRules} for this guild.
*
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
*
* @return {@link RestAction} - Type: {@link List} of {@link AutoModRule}
*/
@Nonnull
@CheckReturnValue
RestAction<List<AutoModRule>> retrieveAutoModRules();

/**
* Retrieves the {@link AutoModRule} for the provided id.
*
* @param id
* The id of the rule
*
* @throws IllegalArgumentException
* If the provided id is not a valid snowflake
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
*
* @return {@link RestAction} - Type: {@link AutoModRule}
*/
@Nonnull
@CheckReturnValue
RestAction<AutoModRule> retrieveAutoModRuleById(@Nonnull String id);

/**
* Retrieves the {@link AutoModRule} for the provided id.
*
* @param id
* The id of the rule
*
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
*
* @return {@link RestAction} - Type: {@link AutoModRule}
*/
@Nonnull
@CheckReturnValue
default RestAction<AutoModRule> retrieveAutoModRuleById(long id)
{
return retrieveAutoModRuleById(Long.toUnsignedString(id));
}

/**
* Creates a new {@link AutoModRule} for this guild.
*
* <p>You can only create a certain number of rules for each {@link AutoModTriggerType AutoModTriggerType}.
* The maximum is provided by {@link AutoModTriggerType#getMaxPerGuild()}.
*
* @param data
* The data for the new rule
*
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link AutoModRuleData#getRequiredPermissions() required permissions}
* @throws IllegalStateException
* <ul>
* <li>If the provided data does not have any {@link AutoModResponse} configured</li>
* <li>If any of the configured {@link AutoModResponse AutoModResponses} is not supported by the {@link AutoModTriggerType}</li>
* </ul>
*
* @return {@link AuditableRestAction} - Type: {@link AutoModRule}
*/
@Nonnull
@CheckReturnValue
AuditableRestAction<AutoModRule> createAutoModRule(@Nonnull AutoModRuleData data);

/**
* Returns an {@link AutoModRuleManager}, which can be used to modify the rule for the provided id.
* <p>The manager allows modifying multiple fields in a single request.
* <br>You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.api.requests.RestAction#queue() RestAction.queue()}.
*
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission.
*
* @return The manager instance
*/
@Nonnull
@CheckReturnValue
AutoModRuleManager modifyAutoModRuleById(@Nonnull String id);

/**
* Returns an {@link AutoModRuleManager}, which can be used to modify the rule for the provided id.
* <p>The manager allows modifying multiple fields in a single request.
* <br>You modify multiple fields in one request by chaining setters before calling {@link net.dv8tion.jda.api.requests.RestAction#queue() RestAction.queue()}.
*
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission.
*
* @return The manager instance
*/
@Nonnull
@CheckReturnValue
default AutoModRuleManager modifyAutoModRuleById(long id)
{
return modifyAutoModRuleById(Long.toUnsignedString(id));
}

/**
* Deletes the {@link AutoModRule} for the provided id.
*
* @param id
* The id of the rule
*
* @throws IllegalArgumentException
* If the provided id is not a valid snowflake
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
*
* @return {@link AuditableRestAction} - Type: {@link Void}
*/
@Nonnull
@CheckReturnValue
AuditableRestAction<Void> deleteAutoModRuleById(@Nonnull String id);

/**
* Deletes the {@link AutoModRule} for the provided id.
*
* @param id
* The id of the rule
*
* @throws InsufficientPermissionException
* If the currently logged in account does not have the {@link net.dv8tion.jda.api.Permission#MANAGE_SERVER MANAGE_SERVER} permission
*
* @return {@link AuditableRestAction} - Type: {@link Void}
*/
@Nonnull
@CheckReturnValue
default AuditableRestAction<Void> deleteAutoModRuleById(long id)
{
return deleteAutoModRuleById(Long.toUnsignedString(id));
}

/**
* Adds the user to this guild as a member.
* <br>This requires an <b>OAuth2 Access Token</b> with the scope {@code guilds.join}.
Expand Down
Loading