Skip to content

Commit

Permalink
Add automod support (#2429)
Browse files Browse the repository at this point in the history
* Add new intents
* Add events
* Add relevant audit-log features
* Add new ErrorResponses
  • Loading branch information
MinnDevelopment committed May 20, 2023
1 parent b877574 commit ab32257
Show file tree
Hide file tree
Showing 41 changed files with 4,591 additions and 22 deletions.
49 changes: 49 additions & 0 deletions src/main/java/net/dv8tion/jda/api/audit/ActionType.java
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
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
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
Expand Up @@ -22,6 +22,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 @@ -42,10 +46,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 @@ -406,6 +407,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

0 comments on commit ab32257

Please sign in to comment.