commonMain.cache.data.AutoModeration.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kord-core Show documentation
Show all versions of kord-core Show documentation
Idiomatic Kotlin Wrapper for The Discord API
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.*
import dev.kord.common.serialization.DurationInSeconds
import kotlinx.serialization.Serializable
@Serializable
public data class AutoModerationRuleData(
val id: Snowflake,
val guildId: Snowflake,
val name: String,
val creatorId: Snowflake,
val eventType: AutoModerationRuleEventType,
val triggerType: AutoModerationRuleTriggerType,
val triggerMetadata: AutoModerationRuleTriggerMetadataData,
val actions: List,
val enabled: Boolean,
val exemptRoles: List,
val exemptChannels: List,
) {
public companion object {
public val description: DataDescription =
description(AutoModerationRuleData::id)
public fun from(rule: DiscordAutoModerationRule): AutoModerationRuleData = with(rule) {
AutoModerationRuleData(
id = id,
guildId = guildId,
name = name,
creatorId = creatorId,
eventType = eventType,
triggerType = triggerType,
triggerMetadata = AutoModerationRuleTriggerMetadataData.from(triggerMetadata),
actions = actions.map { AutoModerationActionData.from(it) },
enabled = enabled,
exemptRoles = exemptRoles,
exemptChannels = exemptChannels,
)
}
}
}
@Serializable
public data class AutoModerationRuleTriggerMetadataData(
val keywordFilter: Optional> = Optional.Missing(),
val regexPatterns: Optional> = Optional.Missing(),
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 =
with(metadata) {
AutoModerationRuleTriggerMetadataData(
keywordFilter = keywordFilter,
regexPatterns = regexPatterns,
presets = presets,
allowList = allowList,
mentionTotalLimit = mentionTotalLimit,
mentionRaidProtectionEnabled = mentionRaidProtectionEnabled,
)
}
}
}
@Serializable
public data class AutoModerationActionData(
val type: AutoModerationActionType,
val metadata: Optional = Optional.Missing(),
) {
public companion object {
public fun from(action: DiscordAutoModerationAction): AutoModerationActionData = with(action) {
AutoModerationActionData(
type = type,
metadata = metadata.map { AutoModerationActionMetadataData.from(it) },
)
}
}
}
@Serializable
public data class AutoModerationActionMetadataData(
val channelId: OptionalSnowflake = OptionalSnowflake.Missing,
val durationSeconds: Optional = Optional.Missing(),
val customMessage: Optional = Optional.Missing(),
) {
public companion object {
public fun from(metadata: DiscordAutoModerationActionMetadata): AutoModerationActionMetadataData =
with(metadata) {
AutoModerationActionMetadataData(
channelId = channelId,
durationSeconds = durationSeconds,
customMessage = customMessage,
)
}
}
}