-
-
Notifications
You must be signed in to change notification settings - Fork 5
支持注册自定义事件解析器 #206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
支持注册自定义事件解析器 #206
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for registering custom event resolvers in the OneBot protocol implementation, enabling users to plug in their own parsing logic for “custom” post types.
- Introduces the
CustomEventResolverAPI (and Kotlin-serialization variant) under an opt-in experimental flag - Extends
OneBotBotConfigurationto collect custom resolvers and updatesOneBotBotImplto invoke them during event resolution - Adds related exception types, result interfaces, and tests for the new feature
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| RawEventDeserializationException.kt | New exception type for raw event deserialization failures |
| CustomEventResolverTests.kt | Tests for custom resolver and KTX serialization resolver |
| RawEventResolveResult.kt | Interface for the initial parse result of a raw event |
| ExperimentalCustomEventResolverApi.kt | Opt-in annotation for the custom resolver API |
| CustomKotlinSerializationEventResolver.kt | Functional interface for Kotlin-serialization-based resolvers |
| CustomEventResolver.kt | Core functional interface for custom event resolution |
| CustomEventResolveException.kt | Exception for errors during custom resolution |
| RawEventResolveResultImpl.kt | Internal data class implementing RawEventResolveResult |
| OneBotBotImpl.kt | Implements resolveEvent to apply custom resolvers and fallback logic |
| OneBotBotConfiguration.kt | Adds addCustomEventResolver and KTX helper to configuration |
| OneBotBot.kt | Annotates push and pushAndLaunch parameters as JSON strings |
| OneBotApi.kt | Fixes doc comment for API result deserializer |
| build.gradle.kts | Adjusts source-set dependency declarations |
| P.kt | Bumps project version to 1.8.0 |
Comments suppressed due to low confidence (2)
simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonTest/kotlin/love/forte/simbot/component/onebot/v11/core/event/CustomEventResolverTests.kt:150
- [nitpick] Add tests for the fallback behavior when no custom resolver matches, verifying that default parsing or an UnknownEvent is emitted as expected.
// end of existing tests
buildSrc/src/main/kotlin/P.kt:41
- NEXT_VERSION is identical to VERSION; consider bumping NEXT_VERSION beyond the current release (e.g. 1.9.0) to ensure snapshot/versioning semantics remain clear.
const val NEXT_VERSION = "1.8.0"
.../commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/internal/OneBotBotImpl.kt
Outdated
Show resolved
Hide resolved
| * 解析数据包为 Event。 | ||
| */ | ||
| @OptIn(FragileSimbotAPI::class, ExperimentalCustomEventResolverApi::class) | ||
| internal fun OneBotBotImpl.resolveEvent(text: String): Event { |
Copilot
AI
May 17, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The resolveEvent method is quite long and handles multiple concerns; consider refactoring into smaller helper functions (e.g., applyCustomResolvers, resolveDefaultEvent, logErrors) for improved readability and testability.
Co-authored-by: Copilot <[email protected]>
Qodana Community for JVM2 new problems were found
💡 Qodana analysis was run in the pull request mode: only the changed files were checked Contact Qodana teamContact us at [email protected]
|
|
在 simple-robot/simpler-robot#1071 结束前, 在 val bot = ...
bot.configuration.addCustomKotlinSerializationEventResolver("custom", "test") {
CustomEvent.serializer()
} |
OneBot协议中可能存在很多额外的、自定义的事件。
在配置中增加注册
CustomEventResolver的配置项以支持对初步解析的事件进行处理,允许自定义事件解析。假设自定义的事件是这样的:
{ "post_type": "custom", "custom_type": "test", "value": "test1" }那么注册解析器:
Note
postType和subType要符合OneBot协议的一贯风格。即subType的 key 为${postType}_type,以上述代码示例为例,当postType=custom时,subType的 key 名称为custom_type,此时subType的实际值为test。Warning
相关API和类型处于实验阶段。
Warning
自定义事件处理器优先级高于的 RawEvent 处理,因此当自定义事件处理器得到了结果,会覆盖原本默认的处理方案。
close #204