simple-robot / simbot-component-onebot

一个Kotlin多平台的 OneBot SDK 实现,一个异步高效、Java 友好的 Simple Robot 组件库 ~ 🐱🐱🐱
https://simbot.forte.love/component-onebot.html
GNU Lesser General Public License v3.0
10 stars 3 forks source link

支持通过注册自定义Component的形式向OneBot提供额外的序列化模块支持; OneBotBotConfiguration支持配置额外的序列化模块 #43

Closed ForliyScarlet closed 5 months ago

ForliyScarlet commented 5 months ago

支持通过注册自定义Component的形式向OneBot提供额外的序列化模块支持

比如自定义一个 TestCustomComponent,其中:

private val TestCustomComponent = object : Component {
    override val id: String = "TestCustomComponent"

    override val serializersModule: SerializersModule = SerializersModule {
        polymorphic(OneBotMessageSegment::class) {
            subclass(TestSegment.serializer())
        }
    }
}

private val TestCustomComponentFac = object : ComponentFactory<Component, Unit> {
    override val key: ComponentFactory.Key = object : ComponentFactory.Key {}

    override fun create(context: ComponentConfigureContext, configurer: ConfigurerFunction<Unit>): Component {
        return TestCustomComponent
    }
}

@SerialName("test")
@Serializable
private data class TestSegment(override val data: String) : OneBotMessageSegment

然后注册此组件:

val app = launchSimpleApplication {
    useOneBot11()
    install(TestCustomComponentFac)
}

那么后续则可以支持解析 TestSegment 而不是直接解析为 OneBotUnknownSegment

[!warning] OneBotUnknownSegment 中的 dataJsonObject 类型变更为 JsonElement

OneBotBotConfiguration支持配置额外的序列化模块

字面意思,OneBotBotConfiguration 增加一个可配置属性 serializersModule

github-actions[bot] commented 5 months ago

Qodana Community for JVM

It seems all right 👌

No new problems were found according to the checks applied

💡 Qodana analysis was run in the pull request mode: only the changed files were checked ☁️ View the detailed Qodana report

Contact Qodana team Contact us at [qodana-support@jetbrains.com](mailto:qodana-support@jetbrains.com) - Or via our issue tracker: https://jb.gg/qodana-issue - Or share your feedback: https://jb.gg/qodana-discussions