From c47d45c6b4b6bc577ad3e6e57954b156cc71f576 Mon Sep 17 00:00:00 2001 From: lukellmann <47486203+lukellmann@users.noreply.github.com> Date: Sat, 17 Jun 2023 14:43:26 +0200 Subject: [PATCH] Add mention raid protection to Auto Moderation (#830) The DSL looks like this: val rule = guild.createMentionSpamAutoModerationRule("name") { mentionRaidProtectionEnabled = true blockMessage() enabled = true } println(rule.isMentionRaidProtectionEnabled) see https://github.com/discord/discord-api-docs/pull/5778 and https://github.com/discord/discord-api-docs/pull/6133 --- common/api/common.api | 12 ++--- .../kotlin/entity/AutoModeration.kt | 3 ++ core/api/core.api | 15 ++++--- .../kotlin/behavior/GuildBehavior.kt | 26 +++++++++-- .../kotlin/cache/data/AutoModeration.kt | 7 ++- .../automoderation/AutoModerationRule.kt | 4 ++ rest/api/rest.api | 10 +++++ .../AutoModerationRuleBuilder.kt | 10 ++++- .../AutoModerationRuleCreateBuilder.kt | 44 ++++++++++++++++++- .../AutoModerationRuleModifyBuilder.kt | 23 ++++++++-- .../kotlin/service/AutoModerationService.kt | 25 ++++++++++- 11 files changed, 152 insertions(+), 27 deletions(-) diff --git a/common/api/common.api b/common/api/common.api index d02a5a2763b..dfa9199a6da 100644 --- a/common/api/common.api +++ b/common/api/common.api @@ -2690,19 +2690,21 @@ public final class dev/kord/common/entity/DiscordAutoModerationRule$Companion { public final class dev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata { public static final field Companion Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata$Companion; public fun ()V - public synthetic fun (ILdev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;)V - public synthetic fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;)V + public synthetic fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/optional/Optional; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/Optional; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; public final fun component5 ()Ldev/kord/common/entity/optional/OptionalInt; - public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;)Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata; - public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata; + public final fun component6 ()Ldev/kord/common/entity/optional/OptionalBoolean; + public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;)Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata; + public static synthetic fun copy$default (Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;ILjava/lang/Object;)Ldev/kord/common/entity/DiscordAutoModerationRuleTriggerMetadata; public fun equals (Ljava/lang/Object;)Z public final fun getAllowList ()Ldev/kord/common/entity/optional/Optional; public final fun getKeywordFilter ()Ldev/kord/common/entity/optional/Optional; + public final fun getMentionRaidProtectionEnabled ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun getMentionTotalLimit ()Ldev/kord/common/entity/optional/OptionalInt; public final fun getPresets ()Ldev/kord/common/entity/optional/Optional; public final fun getRegexPatterns ()Ldev/kord/common/entity/optional/Optional; diff --git a/common/src/commonMain/kotlin/entity/AutoModeration.kt b/common/src/commonMain/kotlin/entity/AutoModeration.kt index fa0b31ca442..e7b3f7c504b 100644 --- a/common/src/commonMain/kotlin/entity/AutoModeration.kt +++ b/common/src/commonMain/kotlin/entity/AutoModeration.kt @@ -58,6 +58,7 @@ package dev.kord.common.entity import dev.kord.common.entity.optional.Optional +import dev.kord.common.entity.optional.OptionalBoolean import dev.kord.common.entity.optional.OptionalInt import dev.kord.common.entity.optional.OptionalSnowflake import dev.kord.common.serialization.DurationInSeconds @@ -100,6 +101,8 @@ public data class DiscordAutoModerationRuleTriggerMetadata( val allowList: Optional> = Optional.Missing(), @SerialName("mention_total_limit") val mentionTotalLimit: OptionalInt = OptionalInt.Missing, + @SerialName("mention_raid_protection_enabled") + val mentionRaidProtectionEnabled: OptionalBoolean = OptionalBoolean.Missing, ) @Serializable diff --git a/core/api/core.api b/core/api/core.api index 95e178503dd..41e0a856226 100644 --- a/core/api/core.api +++ b/core/api/core.api @@ -393,7 +393,9 @@ public final class dev/kord/core/behavior/GuildBehaviorKt { public static final fun createKeywordPresetAutoModerationRule (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createKeywordPresetAutoModerationRule$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createMentionSpamAutoModerationRule (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public static final fun createMentionSpamAutoModerationRule (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createMentionSpamAutoModerationRule$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; + public static synthetic fun createMentionSpamAutoModerationRule$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createMessageCommand (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun createMessageCommand$default (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; public static final fun createNewsChannel (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; @@ -2825,19 +2827,21 @@ public final class dev/kord/core/cache/data/AutoModerationRuleData$Companion { public final class dev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData { public static final field Companion Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData$Companion; public fun ()V - public synthetic fun (ILdev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V - public fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;)V - public synthetic fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;ILkotlin/jvm/internal/DefaultConstructorMarker;)V + public synthetic fun (ILdev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;Lkotlinx/serialization/internal/SerializationConstructorMarker;)V + public fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;)V + public synthetic fun (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;ILkotlin/jvm/internal/DefaultConstructorMarker;)V public final fun component1 ()Ldev/kord/common/entity/optional/Optional; public final fun component2 ()Ldev/kord/common/entity/optional/Optional; public final fun component3 ()Ldev/kord/common/entity/optional/Optional; public final fun component4 ()Ldev/kord/common/entity/optional/Optional; public final fun component5 ()Ldev/kord/common/entity/optional/OptionalInt; - public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;)Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData; - public static synthetic fun copy$default (Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;ILjava/lang/Object;)Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData; + public final fun component6 ()Ldev/kord/common/entity/optional/OptionalBoolean; + public final fun copy (Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;)Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData; + public static synthetic fun copy$default (Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/Optional;Ldev/kord/common/entity/optional/OptionalInt;Ldev/kord/common/entity/optional/OptionalBoolean;ILjava/lang/Object;)Ldev/kord/core/cache/data/AutoModerationRuleTriggerMetadataData; public fun equals (Ljava/lang/Object;)Z public final fun getAllowList ()Ldev/kord/common/entity/optional/Optional; public final fun getKeywordFilter ()Ldev/kord/common/entity/optional/Optional; + public final fun getMentionRaidProtectionEnabled ()Ldev/kord/common/entity/optional/OptionalBoolean; public final fun getMentionTotalLimit ()Ldev/kord/common/entity/optional/OptionalInt; public final fun getPresets ()Ldev/kord/common/entity/optional/Optional; public final fun getRegexPatterns ()Ldev/kord/common/entity/optional/Optional; @@ -7750,6 +7754,7 @@ public final class dev/kord/core/entity/automoderation/MentionSpamAutoModeration public final fun getMentionLimit ()I public fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam; public synthetic fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType; + public final fun isMentionRaidProtectionEnabled ()Z public fun toString ()Ljava/lang/String; public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/automoderation/AutoModerationRuleBehavior; public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/automoderation/MentionSpamAutoModerationRuleBehavior; diff --git a/core/src/commonMain/kotlin/behavior/GuildBehavior.kt b/core/src/commonMain/kotlin/behavior/GuildBehavior.kt index e2841835534..e04f3693bc7 100644 --- a/core/src/commonMain/kotlin/behavior/GuildBehavior.kt +++ b/core/src/commonMain/kotlin/behavior/GuildBehavior.kt @@ -1068,18 +1068,36 @@ public suspend inline fun GuildBehavior.createKeywordPresetAutoModerationRule( * * @param name the rule name. * @param eventType the rule [event type][AutoModerationRuleEventType]. - * @param mentionLimit total number of unique role and user mentions allowed per message (maximum of 50). * * @throws RestRequestException if something went wrong during the request. */ public suspend inline fun GuildBehavior.createMentionSpamAutoModerationRule( name: String, eventType: AutoModerationRuleEventType = MessageSend, - mentionLimit: Int, builder: MentionSpamAutoModerationRuleCreateBuilder.() -> Unit, ): MentionSpamAutoModerationRule { contract { callsInPlace(builder, EXACTLY_ONCE) } - val rule = kord.rest.autoModeration - .createMentionSpamAutoModerationRule(guildId = id, name, eventType, mentionLimit, builder) + val rule = kord.rest.autoModeration.createMentionSpamAutoModerationRule(guildId = id, name, eventType, builder) return MentionSpamAutoModerationRule(AutoModerationRuleData.from(rule), kord, supplier) } + +@Deprecated( + "The 'mentionLimit' parameter is optional, only 'mentionLimit' OR 'mentionRaidProtectionEnabled' is required.", + ReplaceWith( + "this.createMentionSpamAutoModerationRule(name, eventType) { this@createMentionSpamAutoModerationRule" + + ".mentionLimit = mentionLimit\nbuilder() }" + ), + DeprecationLevel.WARNING, +) +public suspend inline fun GuildBehavior.createMentionSpamAutoModerationRule( + name: String, + eventType: AutoModerationRuleEventType = MessageSend, + mentionLimit: Int, + builder: MentionSpamAutoModerationRuleCreateBuilder.() -> Unit, +): MentionSpamAutoModerationRule { + contract { callsInPlace(builder, EXACTLY_ONCE) } + return createMentionSpamAutoModerationRule(name, eventType) { + this.mentionLimit = mentionLimit + builder() + } +} diff --git a/core/src/commonMain/kotlin/cache/data/AutoModeration.kt b/core/src/commonMain/kotlin/cache/data/AutoModeration.kt index ba1eeb70872..aa8b492a0dd 100644 --- a/core/src/commonMain/kotlin/cache/data/AutoModeration.kt +++ b/core/src/commonMain/kotlin/cache/data/AutoModeration.kt @@ -3,10 +3,7 @@ package dev.kord.core.cache.data import dev.kord.cache.api.data.DataDescription import dev.kord.cache.api.data.description import dev.kord.common.entity.* -import dev.kord.common.entity.optional.Optional -import dev.kord.common.entity.optional.OptionalInt -import dev.kord.common.entity.optional.OptionalSnowflake -import dev.kord.common.entity.optional.map +import dev.kord.common.entity.optional.* import dev.kord.common.serialization.DurationInSeconds import kotlinx.serialization.Serializable @@ -53,6 +50,7 @@ public data class AutoModerationRuleTriggerMetadataData( val presets: Optional> = Optional.Missing(), val allowList: Optional> = Optional.Missing(), val mentionTotalLimit: OptionalInt = OptionalInt.Missing, + val mentionRaidProtectionEnabled: OptionalBoolean = OptionalBoolean.Missing, ) { public companion object { public fun from(metadata: DiscordAutoModerationRuleTriggerMetadata): AutoModerationRuleTriggerMetadataData = @@ -63,6 +61,7 @@ public data class AutoModerationRuleTriggerMetadataData( presets = presets, allowList = allowList, mentionTotalLimit = mentionTotalLimit, + mentionRaidProtectionEnabled = mentionRaidProtectionEnabled, ) } } diff --git a/core/src/commonMain/kotlin/entity/automoderation/AutoModerationRule.kt b/core/src/commonMain/kotlin/entity/automoderation/AutoModerationRule.kt index 35aba19c4a8..7b22b0c193f 100644 --- a/core/src/commonMain/kotlin/entity/automoderation/AutoModerationRule.kt +++ b/core/src/commonMain/kotlin/entity/automoderation/AutoModerationRule.kt @@ -200,6 +200,10 @@ public class MentionSpamAutoModerationRule(data: AutoModerationRuleData, kord: K /** Total number of unique role and user mentions allowed per message. */ public val mentionLimit: Int get() = data.triggerMetadata.mentionTotalLimit.value!! + /** Whether to automatically detect mention raids. */ + public val isMentionRaidProtectionEnabled: Boolean + get() = data.triggerMetadata.mentionRaidProtectionEnabled.orElse(false) + override suspend fun asAutoModerationRuleOrNull(): MentionSpamAutoModerationRule = this override suspend fun asAutoModerationRule(): MentionSpamAutoModerationRule = this diff --git a/rest/api/rest.api b/rest/api/rest.api index e929bfd92ba..a63fe2bb2fe 100644 --- a/rest/api/rest.api +++ b/rest/api/rest.api @@ -276,7 +276,10 @@ public final class dev/kord/rest/builder/automoderation/KeywordPresetAutoModerat public abstract interface class dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleBuilder : dev/kord/rest/builder/automoderation/TimeoutAutoModerationRuleBuilder { public abstract fun assignMentionLimit (I)V public abstract fun getMentionLimit ()Ljava/lang/Integer; + public abstract fun getMentionRaidProtectionEnabled ()Ljava/lang/Boolean; public abstract fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam; + public abstract fun setMentionLimit (Ljava/lang/Integer;)V + public abstract fun setMentionRaidProtectionEnabled (Ljava/lang/Boolean;)V } public final class dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleBuilder$DefaultImpls { @@ -284,22 +287,28 @@ public final class dev/kord/rest/builder/automoderation/MentionSpamAutoModeratio } public final class dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleCreateBuilder : dev/kord/rest/builder/automoderation/AutoModerationRuleCreateBuilder, dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleBuilder { + public fun (Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;)V public fun (Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;I)V public fun assignMentionLimit (I)V public synthetic fun buildTriggerMetadata ()Ldev/kord/common/entity/optional/Optional; public fun getMentionLimit ()Ljava/lang/Integer; + public fun getMentionRaidProtectionEnabled ()Ljava/lang/Boolean; public fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam; public synthetic fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType; public fun setMentionLimit (I)V + public fun setMentionLimit (Ljava/lang/Integer;)V + public fun setMentionRaidProtectionEnabled (Ljava/lang/Boolean;)V } public final class dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleModifyBuilder : dev/kord/rest/builder/automoderation/AutoModerationRuleModifyBuilder, dev/kord/rest/builder/automoderation/MentionSpamAutoModerationRuleBuilder { public fun ()V public fun assignMentionLimit (I)V public fun getMentionLimit ()Ljava/lang/Integer; + public fun getMentionRaidProtectionEnabled ()Ljava/lang/Boolean; public fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam; public synthetic fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType; public fun setMentionLimit (Ljava/lang/Integer;)V + public fun setMentionRaidProtectionEnabled (Ljava/lang/Boolean;)V } public final class dev/kord/rest/builder/automoderation/SendAlertMessageAutoModerationActionBuilder : dev/kord/rest/builder/automoderation/AutoModerationActionBuilder { @@ -7011,6 +7020,7 @@ public final class dev/kord/rest/service/AutoModerationService : dev/kord/rest/s public final fun createKeywordAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun createKeywordPresetAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun createMentionSpamAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;ILkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; + public final fun createMentionSpamAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun createSpamAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Ldev/kord/common/entity/AutoModerationRuleEventType;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public final fun deleteAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object; public static synthetic fun deleteAutoModerationRule$default (Ldev/kord/rest/service/AutoModerationService;Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;Ljava/lang/String;Lkotlin/coroutines/Continuation;ILjava/lang/Object;)Ljava/lang/Object; diff --git a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt index 6e5107b6b6e..7198c5fd659 100644 --- a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleBuilder.kt @@ -314,11 +314,19 @@ public sealed interface MentionSpamAutoModerationRuleBuilder : TimeoutAutoModera override val triggerType: MentionSpam get() = MentionSpam /** Total number of unique role and user mentions allowed per message (maximum of 50). */ - public val mentionLimit: Int? + public var mentionLimit: Int? /** * Use this to set [mentionLimit][MentionSpamAutoModerationRuleBuilder.mentionLimit] for * [MentionSpamAutoModerationRuleBuilder]. */ + @Deprecated( + "This can be replaced with 'mentionLimit', it is now a 'var'.", + ReplaceWith("this.run { this@run.mentionLimit = mentionLimit }"), + DeprecationLevel.WARNING, + ) public fun assignMentionLimit(mentionLimit: Int) + + /** Whether to automatically detect mention raids. */ + public var mentionRaidProtectionEnabled: Boolean? } diff --git a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt index b056b98c135..c6be4406d5d 100644 --- a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleCreateBuilder.kt @@ -119,14 +119,54 @@ public class KeywordPresetAutoModerationRuleCreateBuilder( public class MentionSpamAutoModerationRuleCreateBuilder( name: String, eventType: AutoModerationRuleEventType, - override var mentionLimit: Int, ) : AutoModerationRuleCreateBuilder(name, eventType), MentionSpamAutoModerationRuleBuilder { + @Deprecated( + "The 'mentionLimit' parameter is optional, only 'mentionLimit' OR 'mentionRaidProtectionEnabled' is required.", + ReplaceWith( + "MentionSpamAutoModerationRuleCreateBuilder(name, eventType).apply { this@apply.mentionLimit = mentionLimit }", + imports = ["dev.kord.rest.builder.automoderation.MentionSpamAutoModerationRuleCreateBuilder"], + ), + DeprecationLevel.WARNING, + ) + public constructor(name: String, eventType: AutoModerationRuleEventType, mentionLimit: Int) : this( + name, + eventType, + ) { + this.mentionLimit = mentionLimit + } /** @suppress Use `this.mentionLimit = mentionLimit` instead. */ + @Deprecated( + "This can be replaced with 'mentionLimit', it is now a 'var'.", + ReplaceWith("this.run { this@run.mentionLimit = mentionLimit }"), + DeprecationLevel.WARNING, + ) override fun assignMentionLimit(mentionLimit: Int) { this.mentionLimit = mentionLimit } + /** @suppress This declaration only exists to preserve binary compatibility. */ + @Suppress("NON_FINAL_MEMBER_IN_FINAL_CLASS") + @Deprecated( + "This can be replaced with 'mentionLimit', it is now a 'var'.", + ReplaceWith("this.run { this@run.mentionLimit = mentionLimit }"), + DeprecationLevel.WARNING, + ) + public open fun setMentionLimit(mentionLimit: Int) { + this.mentionLimit = mentionLimit + } + + private var _mentionLimit: OptionalInt = OptionalInt.Missing + override var mentionLimit: Int? by ::_mentionLimit.delegate() + + private var _mentionRaidProtectionEnabled: OptionalBoolean = OptionalBoolean.Missing + override var mentionRaidProtectionEnabled: Boolean? by ::_mentionRaidProtectionEnabled.delegate() + + // one of mentionTotalLimit or mentionRaidProtectionEnabled is required, don't bother to send missing trigger + // metadata if both are missing override fun buildTriggerMetadata(): Optional.Value = - DiscordAutoModerationRuleTriggerMetadata(mentionTotalLimit = mentionLimit.optionalInt()).optional() + DiscordAutoModerationRuleTriggerMetadata( + mentionTotalLimit = _mentionLimit, + mentionRaidProtectionEnabled = _mentionRaidProtectionEnabled, + ).optional() } diff --git a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt index 3eb224de706..9aa309752e9 100644 --- a/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt +++ b/rest/src/commonMain/kotlin/builder/automoderation/AutoModerationRuleModifyBuilder.kt @@ -148,15 +148,30 @@ public class MentionSpamAutoModerationRuleModifyBuilder : override var mentionLimit: Int? by ::_mentionLimit.delegate() /** @suppress Use `this.mentionLimit = mentionLimit` instead. */ + @Deprecated( + "This can be replaced with 'mentionLimit', it is now a 'var'.", + ReplaceWith("this.run { this@run.mentionLimit = mentionLimit }"), + DeprecationLevel.WARNING, + ) override fun assignMentionLimit(mentionLimit: Int) { this.mentionLimit = mentionLimit } - override fun buildTriggerMetadata(): Optional = - when (val limit = _mentionLimit) { - OptionalInt.Missing -> Optional.Missing() - is OptionalInt.Value -> DiscordAutoModerationRuleTriggerMetadata(mentionTotalLimit = limit).optional() + private var _mentionRaidProtectionEnabled: OptionalBoolean = OptionalBoolean.Missing + override var mentionRaidProtectionEnabled: Boolean? by ::_mentionRaidProtectionEnabled.delegate() + + override fun buildTriggerMetadata(): Optional { + val mentionLimit = _mentionLimit + val mentionRaidProtectionEnabled = _mentionRaidProtectionEnabled + return if (mentionLimit is OptionalInt.Value || mentionRaidProtectionEnabled is OptionalBoolean.Value) { + DiscordAutoModerationRuleTriggerMetadata( + mentionTotalLimit = mentionLimit, + mentionRaidProtectionEnabled = mentionRaidProtectionEnabled, + ).optional() + } else { + Optional.Missing() } + } } private inline fun ifAnyPresent(vararg optionals: Optional<*>, block: () -> T): Optional { diff --git a/rest/src/commonMain/kotlin/service/AutoModerationService.kt b/rest/src/commonMain/kotlin/service/AutoModerationService.kt index 5b0840f91d6..7a63c1e7977 100644 --- a/rest/src/commonMain/kotlin/service/AutoModerationService.kt +++ b/rest/src/commonMain/kotlin/service/AutoModerationService.kt @@ -72,14 +72,35 @@ public class AutoModerationService(requestHandler: RequestHandler) : RestService guildId: Snowflake, name: String, eventType: AutoModerationRuleEventType, - mentionLimit: Int, builder: MentionSpamAutoModerationRuleCreateBuilder.() -> Unit, ): DiscordAutoModerationRule { contract { callsInPlace(builder, EXACTLY_ONCE) } - val request = MentionSpamAutoModerationRuleCreateBuilder(name, eventType, mentionLimit).apply(builder) + val request = MentionSpamAutoModerationRuleCreateBuilder(name, eventType).apply(builder) return createAutoModerationRule(guildId, request.toRequest(), request.reason) } + @Deprecated( + "The 'mentionLimit' parameter is optional, only 'mentionLimit' OR 'mentionRaidProtectionEnabled' is required.", + ReplaceWith( + "this.createMentionSpamAutoModerationRule(guildId, name, eventType) { " + + "this@createMentionSpamAutoModerationRule.mentionLimit = mentionLimit\nbuilder() }" + ), + DeprecationLevel.WARNING, + ) + public suspend inline fun createMentionSpamAutoModerationRule( + guildId: Snowflake, + name: String, + eventType: AutoModerationRuleEventType, + mentionLimit: Int, + builder: MentionSpamAutoModerationRuleCreateBuilder.() -> Unit, + ): DiscordAutoModerationRule { + contract { callsInPlace(builder, EXACTLY_ONCE) } + return createMentionSpamAutoModerationRule(guildId, name, eventType) { + this.mentionLimit = mentionLimit + builder() + } + } + public suspend fun modifyAutoModerationRule( guildId: Snowflake, ruleId: Snowflake,