Closed ForliyScarlet closed 5 months ago
比如自定义一个 TestCustomComponent,其中:
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。
TestSegment
OneBotUnknownSegment
[!warning] OneBotUnknownSegment 中的 data 由 JsonObject 类型变更为 JsonElement。
data
JsonObject
JsonElement
字面意思,OneBotBotConfiguration 增加一个可配置属性 serializersModule
OneBotBotConfiguration
serializersModule
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
支持通过注册自定义Component的形式向OneBot提供额外的序列化模块支持
比如自定义一个
TestCustomComponent
,其中:然后注册此组件:
那么后续则可以支持解析
TestSegment
而不是直接解析为OneBotUnknownSegment
。OneBotBotConfiguration支持配置额外的序列化模块
字面意思,
OneBotBotConfiguration
增加一个可配置属性serializersModule