diff --git a/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/SimpleWelcomeChannelConfig.kt b/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/SimpleWelcomeChannelConfig.kt index ffc16124..afdb6d47 100644 --- a/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/SimpleWelcomeChannelConfig.kt +++ b/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/SimpleWelcomeChannelConfig.kt @@ -9,11 +9,16 @@ package org.quiltmc.community.cozy.modules.welcome.config import com.kotlindiscord.kord.extensions.checks.types.Check import dev.kord.core.entity.Guild import dev.kord.core.entity.channel.GuildMessageChannel +import kotlinx.serialization.modules.PolymorphicModuleBuilder +import org.quiltmc.community.cozy.modules.welcome.blocks.Block import kotlin.time.Duration internal typealias LogChannelGetter = (suspend (channel: GuildMessageChannel, guild: Guild) -> GuildMessageChannel?)? public class SimpleWelcomeChannelConfig(private val builder: Builder) : WelcomeChannelConfig() { + override val serializerBuilders: List.() -> Unit> = + builder.serializerBuilders + override suspend fun getLoggingChannel(channel: GuildMessageChannel, guild: Guild): GuildMessageChannel? = builder.loggingChannelGetter?.invoke(channel, guild) @@ -24,8 +29,13 @@ public class SimpleWelcomeChannelConfig(private val builder: Builder) : WelcomeC internal val staffCommandChecks: MutableList> = mutableListOf() internal var loggingChannelGetter: LogChannelGetter = null + public val serializerBuilders: MutableList.() -> Unit> = mutableListOf() public var refreshDuration: Duration? = null + public fun serializer(body: PolymorphicModuleBuilder.() -> Unit) { + serializerBuilders.add(body) + } + public fun staffCommandCheck(body: Check<*>) { staffCommandChecks.add(body) } diff --git a/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/WelcomeChannelConfig.kt b/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/WelcomeChannelConfig.kt index 11034f86..19e1ab1e 100644 --- a/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/WelcomeChannelConfig.kt +++ b/module-welcome/src/main/kotlin/org/quiltmc/community/cozy/modules/welcome/config/WelcomeChannelConfig.kt @@ -9,6 +9,7 @@ package org.quiltmc.community.cozy.modules.welcome.config import com.kotlindiscord.kord.extensions.checks.types.Check import dev.kord.core.entity.Guild import dev.kord.core.entity.channel.GuildMessageChannel +import kotlinx.serialization.modules.PolymorphicModuleBuilder import kotlinx.serialization.modules.SerializersModule import kotlinx.serialization.modules.polymorphic import kotlinx.serialization.modules.subclass @@ -16,9 +17,13 @@ import org.quiltmc.community.cozy.modules.welcome.blocks.* import kotlin.time.Duration public abstract class WelcomeChannelConfig { - public val defaultSerializersModule: SerializersModule = + public open val serializerBuilders: List.() -> Unit> = mutableListOf() + + public val defaultSerializersModule: SerializersModule by lazy { SerializersModule { polymorphic(Block::class) { + serializerBuilders.forEach { it() } + subclass(ComplianceBlock::class) subclass(EmbedBlock::class) subclass(LinksBlock::class) @@ -29,6 +34,7 @@ public abstract class WelcomeChannelConfig { subclass(ThreadListBlock::class) } } + } /** Get the configured logging channel for the given channel and guild. **/ public abstract suspend fun getLoggingChannel(channel: GuildMessageChannel, guild: Guild): GuildMessageChannel?