Skip to content

Commit

Permalink
Add MemberProfileAutoModerationRule
Browse files Browse the repository at this point in the history
The DSL for creating/editing MemberProfileAutoModerationRules looks like
this:

val rule = guild.createMemberProfileAutoModerationRule("name") {
    anywhereKeyword("cat")
    regexPattern("^b(a|@)d\$w(o|0)rd(s|$)")
    allowPrefixKeyword("black cat")
    blockMemberInteraction()
    sendAlertMessage(channelId)
    enabled = true
}
println(rule)

See discord/discord-api-docs#6040
  • Loading branch information
lukellmann committed Aug 30, 2024
1 parent 4ecbb47 commit 6668dff
Show file tree
Hide file tree
Showing 20 changed files with 642 additions and 89 deletions.
12 changes: 12 additions & 0 deletions common/api/common.api
Original file line number Diff line number Diff line change
Expand Up @@ -1420,6 +1420,10 @@ public abstract class dev/kord/common/entity/AutoModerationActionType {
public final fun toString ()Ljava/lang/String;
}

public final class dev/kord/common/entity/AutoModerationActionType$BlockMemberInteraction : dev/kord/common/entity/AutoModerationActionType {
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationActionType$BlockMemberInteraction;
}

public final class dev/kord/common/entity/AutoModerationActionType$BlockMessage : dev/kord/common/entity/AutoModerationActionType {
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationActionType$BlockMessage;
}
Expand Down Expand Up @@ -1456,6 +1460,10 @@ public final class dev/kord/common/entity/AutoModerationRuleEventType$Companion
public final fun serializer ()Lkotlinx/serialization/KSerializer;
}

public final class dev/kord/common/entity/AutoModerationRuleEventType$MemberUpdate : dev/kord/common/entity/AutoModerationRuleEventType {
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationRuleEventType$MemberUpdate;
}

public final class dev/kord/common/entity/AutoModerationRuleEventType$MessageSend : dev/kord/common/entity/AutoModerationRuleEventType {
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationRuleEventType$MessageSend;
}
Expand Down Expand Up @@ -1516,6 +1524,10 @@ public final class dev/kord/common/entity/AutoModerationRuleTriggerType$KeywordP
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationRuleTriggerType$KeywordPreset;
}

public final class dev/kord/common/entity/AutoModerationRuleTriggerType$MemberProfile : dev/kord/common/entity/AutoModerationRuleTriggerType {
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationRuleTriggerType$MemberProfile;
}

public final class dev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam : dev/kord/common/entity/AutoModerationRuleTriggerType {
public static final field INSTANCE Ldev/kord/common/entity/AutoModerationRuleTriggerType$MentionSpam;
}
Expand Down
6 changes: 6 additions & 0 deletions common/api/common.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -7367,6 +7367,8 @@ sealed class dev.kord.common.entity/AutoModerationActionType { // dev.kord.commo

final class Unknown : dev.kord.common.entity/AutoModerationActionType // dev.kord.common.entity/AutoModerationActionType.Unknown|null[0]

final object BlockMemberInteraction : dev.kord.common.entity/AutoModerationActionType // dev.kord.common.entity/AutoModerationActionType.BlockMemberInteraction|null[0]

final object BlockMessage : dev.kord.common.entity/AutoModerationActionType // dev.kord.common.entity/AutoModerationActionType.BlockMessage|null[0]

final object Companion { // dev.kord.common.entity/AutoModerationActionType.Companion|null[0]
Expand Down Expand Up @@ -7402,6 +7404,8 @@ sealed class dev.kord.common.entity/AutoModerationRuleEventType { // dev.kord.co
final fun serializer(): kotlinx.serialization/KSerializer<dev.kord.common.entity/AutoModerationRuleEventType> // dev.kord.common.entity/AutoModerationRuleEventType.Companion.serializer|serializer(){}[0]
}

final object MemberUpdate : dev.kord.common.entity/AutoModerationRuleEventType // dev.kord.common.entity/AutoModerationRuleEventType.MemberUpdate|null[0]

final object MessageSend : dev.kord.common.entity/AutoModerationRuleEventType // dev.kord.common.entity/AutoModerationRuleEventType.MessageSend|null[0]
}

Expand Down Expand Up @@ -7456,6 +7460,8 @@ sealed class dev.kord.common.entity/AutoModerationRuleTriggerType { // dev.kord.

final object KeywordPreset : dev.kord.common.entity/AutoModerationRuleTriggerType // dev.kord.common.entity/AutoModerationRuleTriggerType.KeywordPreset|null[0]

final object MemberProfile : dev.kord.common.entity/AutoModerationRuleTriggerType // dev.kord.common.entity/AutoModerationRuleTriggerType.MemberProfile|null[0]

final object MentionSpam : dev.kord.common.entity/AutoModerationRuleTriggerType // dev.kord.common.entity/AutoModerationRuleTriggerType.MentionSpam|null[0]

final object Spam : dev.kord.common.entity/AutoModerationRuleTriggerType // dev.kord.common.entity/AutoModerationRuleTriggerType.Spam|null[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ public sealed class AutoModerationActionType(
*/
public object Timeout : AutoModerationActionType(3)

/**
* Prevents a member from using text, voice, or other interactions.
*/
public object BlockMemberInteraction : AutoModerationActionType(4)

internal object Serializer : KSerializer<AutoModerationActionType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationActionType",
Expand All @@ -90,6 +95,7 @@ public sealed class AutoModerationActionType(
BlockMessage,
SendAlertMessage,
Timeout,
BlockMemberInteraction,
)
}

Expand All @@ -101,6 +107,7 @@ public sealed class AutoModerationActionType(
1 -> BlockMessage
2 -> SendAlertMessage
3 -> Timeout
4 -> BlockMemberInteraction
else -> Unknown(value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public sealed class AutoModerationRuleEventType(
*/
public object MessageSend : AutoModerationRuleEventType(1)

/**
* When a member edits their profile.
*/
public object MemberUpdate : AutoModerationRuleEventType(2)

internal object Serializer : KSerializer<AutoModerationRuleEventType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleEventType",
Expand All @@ -70,6 +75,7 @@ public sealed class AutoModerationRuleEventType(
public val entries: List<AutoModerationRuleEventType> by lazy(mode = PUBLICATION) {
listOf(
MessageSend,
MemberUpdate,
)
}

Expand All @@ -79,6 +85,7 @@ public sealed class AutoModerationRuleEventType(
*/
public fun from(`value`: Int): AutoModerationRuleEventType = when (value) {
1 -> MessageSend
2 -> MemberUpdate
else -> Unknown(value)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ public sealed class AutoModerationRuleTriggerType(
*/
public object MentionSpam : AutoModerationRuleTriggerType(5)

/**
* Check if member profile contains words from a user defined list of keywords.
*/
public object MemberProfile : AutoModerationRuleTriggerType(6)

internal object Serializer : KSerializer<AutoModerationRuleTriggerType> {
override val descriptor: SerialDescriptor =
PrimitiveSerialDescriptor("dev.kord.common.entity.AutoModerationRuleTriggerType",
Expand All @@ -88,6 +93,7 @@ public sealed class AutoModerationRuleTriggerType(
Spam,
KeywordPreset,
MentionSpam,
MemberProfile,
)
}

Expand All @@ -100,6 +106,7 @@ public sealed class AutoModerationRuleTriggerType(
3 -> Spam
4 -> KeywordPreset
5 -> MentionSpam
6 -> MemberProfile
else -> Unknown(value)
}
}
Expand Down
9 changes: 9 additions & 0 deletions common/src/commonMain/kotlin/entity/AutoModeration.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
kDoc = "Check if content contains words from internal pre-defined wordsets."
),
Entry("MentionSpam", intValue = 5, kDoc = "Check if content contains more unique mentions than allowed."),
Entry(
"MemberProfile", intValue = 6,
kDoc = "Check if member profile contains words from a user defined list of keywords.",
),
],
)

Expand All @@ -30,6 +34,7 @@
docUrl = "https://discord.com/developers/docs/resources/auto-moderation#auto-moderation-rule-object-event-types",
entries = [
Entry("MessageSend", intValue = 1, kDoc = "When a member sends or edits a message in the guild."),
Entry("MemberUpdate", intValue = 2, kDoc = "When a member edits their profile."),
],
)

Expand All @@ -52,6 +57,10 @@
"[ModerateMembers][dev.kord.common.entity.Permission.ModerateMembers] permission is required to " +
"use the [Timeout] action type."
),
Entry(
"BlockMemberInteraction", intValue = 4,
kDoc = "Prevents a member from using text, voice, or other interactions.",
),
],
)

Expand Down
47 changes: 47 additions & 0 deletions core/api/core.api
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ public final class dev/kord/core/Unsafe {
public final fun keywordAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/automoderation/KeywordAutoModerationRuleBehavior;
public final fun keywordPresetAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/automoderation/KeywordPresetAutoModerationRuleBehavior;
public final fun member (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/MemberBehavior;
public final fun memberProfileAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;
public final fun mentionSpamAutoModerationRule (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/automoderation/MentionSpamAutoModerationRuleBehavior;
public final fun message (Ldev/kord/common/entity/Snowflake;Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/MessageBehavior;
public final fun messageChannel (Ldev/kord/common/entity/Snowflake;)Ldev/kord/core/behavior/channel/MessageChannelBehavior;
Expand Down Expand Up @@ -395,6 +396,8 @@ public final class dev/kord/core/behavior/GuildBehaviorKt {
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 createMediaChannel (Ldev/kord/core/behavior/GuildBehavior;Ljava/lang/String;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static synthetic fun createMediaChannel$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 createMemberProfileAutoModerationRule (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 createMemberProfileAutoModerationRule$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;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;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;
Expand Down Expand Up @@ -879,6 +882,7 @@ public final class dev/kord/core/behavior/automoderation/AutoModerationRuleBehav
public static final fun edit (Ldev/kord/core/behavior/automoderation/AutoModerationRuleBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun edit (Ldev/kord/core/behavior/automoderation/KeywordAutoModerationRuleBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun edit (Ldev/kord/core/behavior/automoderation/KeywordPresetAutoModerationRuleBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun edit (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun edit (Ldev/kord/core/behavior/automoderation/MentionSpamAutoModerationRuleBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static final fun edit (Ldev/kord/core/behavior/automoderation/SpamAutoModerationRuleBehavior;Lkotlin/jvm/functions/Function1;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
}
Expand Down Expand Up @@ -919,6 +923,24 @@ public final class dev/kord/core/behavior/automoderation/KeywordPresetAutoModera
public static fun getTriggerType (Ldev/kord/core/behavior/automoderation/KeywordPresetAutoModerationRuleBehavior;)Ldev/kord/common/entity/AutoModerationRuleTriggerType$KeywordPreset;
}

public abstract interface class dev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior : dev/kord/core/behavior/automoderation/TypedAutoModerationRuleBehavior {
public abstract fun asAutoModerationRule (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun asAutoModerationRuleOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MemberProfile;
public abstract fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;
}

public final class dev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior$DefaultImpls {
public static fun asAutoModerationRule (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun asAutoModerationRuleOrNull (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun compareTo (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Ldev/kord/core/entity/Entity;)I
public static fun delete (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Ljava/lang/String;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun getGuild (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;)Ldev/kord/core/behavior/GuildBehavior;
public static fun getGuild (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun getGuildOrNull (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public static fun getTriggerType (Ldev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior;)Ldev/kord/common/entity/AutoModerationRuleTriggerType$MemberProfile;
}

public abstract interface class dev/kord/core/behavior/automoderation/MentionSpamAutoModerationRuleBehavior : dev/kord/core/behavior/automoderation/TypedAutoModerationRuleBehavior {
public abstract fun asAutoModerationRule (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun asAutoModerationRuleOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down Expand Up @@ -7586,6 +7608,13 @@ public final class dev/kord/core/entity/automoderation/AutoModerationRuleKt {
public static synthetic fun AutoModerationRule$default (Ldev/kord/core/cache/data/AutoModerationRuleData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;ILjava/lang/Object;)Ldev/kord/core/entity/automoderation/AutoModerationRule;
}

public final class dev/kord/core/entity/automoderation/BlockMemberInteractionAutoModerationAction : dev/kord/core/entity/automoderation/AutoModerationAction {
public fun <init> (Ldev/kord/core/cache/data/AutoModerationActionData;Ldev/kord/core/Kord;)V
public fun getType ()Ldev/kord/common/entity/AutoModerationActionType$BlockMemberInteraction;
public synthetic fun getType ()Ldev/kord/common/entity/AutoModerationActionType;
public fun toString ()Ljava/lang/String;
}

public final class dev/kord/core/entity/automoderation/BlockMessageAutoModerationAction : dev/kord/core/entity/automoderation/AutoModerationAction {
public fun <init> (Ldev/kord/core/cache/data/AutoModerationActionData;Ldev/kord/core/Kord;)V
public final fun getCustomMessage ()Ljava/lang/String;
Expand Down Expand Up @@ -7629,6 +7658,24 @@ public final class dev/kord/core/entity/automoderation/KeywordPresetAutoModerati
public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/automoderation/KeywordPresetAutoModerationRule;
}

public final class dev/kord/core/entity/automoderation/MemberProfileAutoModerationRule : dev/kord/core/entity/automoderation/AutoModerationRule, dev/kord/core/behavior/automoderation/MemberProfileAutoModerationRuleBehavior {
public fun <init> (Ldev/kord/core/cache/data/AutoModerationRuleData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V
public fun asAutoModerationRule (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public fun asAutoModerationRuleOrNull (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
public final fun getAllowedKeywords ()Ljava/util/List;
public final fun getKeywords ()Ljava/util/List;
public final fun getRegexPatterns ()Ljava/util/List;
public fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType$MemberProfile;
public synthetic fun getTriggerType ()Ldev/kord/common/entity/AutoModerationRuleTriggerType;
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/MemberProfileAutoModerationRuleBehavior;
public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/behavior/automoderation/TypedAutoModerationRuleBehavior;
public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/Strategizable;
public synthetic fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/automoderation/AutoModerationRule;
public fun withStrategy (Ldev/kord/core/supplier/EntitySupplyStrategy;)Ldev/kord/core/entity/automoderation/MemberProfileAutoModerationRule;
}

public final class dev/kord/core/entity/automoderation/MentionSpamAutoModerationRule : dev/kord/core/entity/automoderation/AutoModerationRule, dev/kord/core/behavior/automoderation/MentionSpamAutoModerationRuleBehavior {
public fun <init> (Ldev/kord/core/cache/data/AutoModerationRuleData;Ldev/kord/core/Kord;Ldev/kord/core/supplier/EntitySupplier;)V
public fun asAutoModerationRule (Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
Expand Down
Loading

0 comments on commit 6668dff

Please sign in to comment.