-
-
Notifications
You must be signed in to change notification settings - Fork 5
添加非标准API的OPT警告,重构转发消息API以使用OneBotForwardNode #251
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2024. ForteScarlet. | ||
| * Copyright (c) 2024-2025. ForteScarlet. | ||
| * | ||
| * This file is part of simbot-component-onebot. | ||
| * Project https://github.com/simple-robot/simbot-component-onebot | ||
| * Email [email protected] | ||
| * | ||
| * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms | ||
| * of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
| * either version 3 of the License, or (at your option) any later version. | ||
| * This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). | ||
| * | ||
| * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the GNU Lesser General Public License for more details. | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Lesser GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Lesser GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. | ||
| * If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package love.forte.simbot.component.onebot.common.annotations | ||
|
|
@@ -27,6 +33,7 @@ package love.forte.simbot.component.onebot.common.annotations | |
| ) | ||
| @Target( | ||
| AnnotationTarget.CLASS, | ||
| AnnotationTarget.TYPEALIAS, | ||
| AnnotationTarget.ANNOTATION_CLASS, | ||
| AnnotationTarget.PROPERTY, | ||
| AnnotationTarget.FUNCTION, | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2024. ForteScarlet. | ||
| * Copyright (c) 2024-2025. ForteScarlet. | ||
| * | ||
| * This file is part of simbot-component-onebot. | ||
| * Project https://github.com/simple-robot/simbot-component-onebot | ||
| * Email [email protected] | ||
| * | ||
| * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms | ||
| * of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
| * either version 3 of the License, or (at your option) any later version. | ||
| * This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). | ||
| * | ||
| * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the GNU Lesser General Public License for more details. | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Lesser GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Lesser GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. | ||
| * If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package love.forte.simbot.component.onebot.v11.core.api | ||
|
|
@@ -26,10 +32,16 @@ import kotlinx.serialization.descriptors.buildClassSerialDescriptor | |
| import kotlinx.serialization.encoding.Decoder | ||
| import kotlinx.serialization.encoding.Encoder | ||
| import love.forte.simbot.annotations.FragileSimbotAPI | ||
| import love.forte.simbot.component.onebot.common.annotations.ExperimentalOneBotAPI | ||
| import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot | ||
| import love.forte.simbot.component.onebot.v11.core.utils.resolveToOneBotSegmentList | ||
| import love.forte.simbot.component.onebot.v11.message.OneBotMessageElement | ||
| import love.forte.simbot.component.onebot.v11.message.OneBotMessageElementSerializer | ||
| import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegment | ||
| import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegmentSerializer | ||
| import love.forte.simbot.message.Message | ||
| import love.forte.simbot.message.Messages | ||
| import kotlin.jvm.JvmOverloads | ||
| import kotlin.jvm.JvmStatic | ||
|
|
||
|
|
||
|
|
@@ -60,16 +72,31 @@ public sealed class OneBotMessageOutgoing { | |
|
|
||
| @Serializable | ||
| public data class SegmentsValue( | ||
|
|
||
| public val segments: List<OneBotMessageSegment> | ||
| ) : OneBotMessageOutgoing() | ||
|
|
||
| public companion object { | ||
| /** | ||
| * 通过字符串值构建 [StringValue]。 | ||
| */ | ||
| @JvmStatic | ||
| public fun create(value: String): StringValue = StringValue(value) | ||
|
|
||
| /** | ||
| * 通过消息段列表构建 [SegmentsValue]。 | ||
| */ | ||
| @JvmStatic | ||
| public fun create(segments: List<OneBotMessageSegment>): SegmentsValue = SegmentsValue(segments) | ||
|
|
||
| /** | ||
| * 通过 [Messages] 构建 [SegmentsValue]。 | ||
| * @since 1.9.0 | ||
| */ | ||
| @JvmStatic | ||
| @ExperimentalOneBotAPI | ||
| @JvmOverloads | ||
| public fun create(message: Message, bot: OneBotBot? = null): SegmentsValue = | ||
| create(message.resolveToOneBotSegmentList(bot)) | ||
| } | ||
| } | ||
|
|
||
|
|
||
36 changes: 36 additions & 0 deletions
36
...otlin/love/forte/simbot/component/onebot/v11/core/api/nonstandard/OneBotNonStandardApi.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Copyright (c) 2025. ForteScarlet. | ||
| * | ||
| * Project https://github.com/simple-robot/simbot-component-onebot | ||
| * Email [email protected] | ||
| * | ||
| * This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Lesser GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Lesser GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| package love.forte.simbot.component.onebot.v11.core.api.nonstandard | ||
|
|
||
| /** | ||
| * 与非标准API相关的内容。 | ||
| * 非标准API的实现目前尚处于实验阶段。它们不保证兼容性,并且可能在未来发生变更或被移除。 | ||
| * | ||
| * @since 1.9.0 | ||
| * @author ForteScarlet | ||
| */ | ||
| @Retention(AnnotationRetention.BINARY) | ||
| @Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY) | ||
| @RequiresOptIn("This api is not part of the onebot protocol standard, and may not be available in the future.") | ||
| public annotation class OneBotNonStandardApi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2025. ForteScarlet. | ||
| * Copyright (c) 2025. ForteScarlet. | ||
| * | ||
| * This file is part of simbot-component-onebot. | ||
| * Project https://github.com/simple-robot/simbot-component-onebot | ||
| * Email [email protected] | ||
| * | ||
| * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms | ||
| * of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
| * either version 3 of the License, or (at your option) any later version. | ||
| * This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). | ||
| * | ||
| * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the GNU Lesser General Public License for more details. | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Lesser GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Lesser GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. | ||
| * If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package love.forte.simbot.component.onebot.v11.core.api.nonstandard | ||
|
|
@@ -22,12 +28,11 @@ import kotlinx.serialization.SerialName | |
| import kotlinx.serialization.Serializable | ||
| import love.forte.simbot.common.id.ID | ||
| import love.forte.simbot.common.id.IntID | ||
| import love.forte.simbot.common.id.StringID | ||
| import love.forte.simbot.common.id.literal | ||
| import love.forte.simbot.component.onebot.common.annotations.ApiResultConstructor | ||
| import love.forte.simbot.component.onebot.v11.core.api.OneBotApi | ||
| import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult | ||
| import love.forte.simbot.component.onebot.v11.core.api.OneBotMessageOutgoing | ||
| import love.forte.simbot.component.onebot.v11.message.segment.OneBotForwardNode | ||
| import kotlin.jvm.JvmStatic | ||
|
|
||
| /** | ||
|
|
@@ -36,6 +41,7 @@ import kotlin.jvm.JvmStatic | |
| * @since 1.9.0 | ||
| * @author Aliorpse | ||
| */ | ||
| @OneBotNonStandardApi | ||
| public class SendGroupForwardMsgApi private constructor( | ||
| override val body: Any, | ||
| ) : OneBotApi<SendGroupForwardMsgResult> { | ||
|
|
@@ -62,7 +68,7 @@ public class SendGroupForwardMsgApi private constructor( | |
| @JvmStatic | ||
| public fun create( | ||
| groupId: ID, | ||
| messages: OneBotMessageOutgoing, | ||
| messages: List<OneBotForwardNode>, | ||
| ): SendGroupForwardMsgApi = SendGroupForwardMsgApi(Body(groupId.literal, messages)) | ||
| } | ||
|
|
||
|
|
@@ -74,7 +80,7 @@ public class SendGroupForwardMsgApi private constructor( | |
| internal data class Body( | ||
| @SerialName("group_id") | ||
| val groupId: String, | ||
| val messages: OneBotMessageOutgoing, | ||
| val messages: List<OneBotForwardNode>, | ||
| ) | ||
| } | ||
|
|
||
|
|
@@ -85,9 +91,10 @@ public class SendGroupForwardMsgApi private constructor( | |
| * @property forwardId RES ID | ||
| */ | ||
| @Serializable | ||
| @OneBotNonStandardApi | ||
| public data class SendGroupForwardMsgResult @ApiResultConstructor constructor( | ||
| @SerialName("message_id") | ||
| public val messageId: IntID, | ||
| @SerialName("forward_id") | ||
| public val forwardId: StringID | ||
| public val forwardId: ID | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,24 @@ | ||
| /* | ||
| * Copyright (c) 2025. ForteScarlet. | ||
| * Copyright (c) 2025. ForteScarlet. | ||
| * | ||
| * This file is part of simbot-component-onebot. | ||
| * Project https://github.com/simple-robot/simbot-component-onebot | ||
| * Email [email protected] | ||
| * | ||
| * simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms | ||
| * of the GNU Lesser General Public License as published by the Free Software Foundation, | ||
| * either version 3 of the License, or (at your option) any later version. | ||
| * This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.). | ||
| * | ||
| * simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; | ||
| * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | ||
| * See the GNU Lesser General Public License for more details. | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * Lesser GNU General Public License for more details. | ||
| * | ||
| * You should have received a copy of the Lesser GNU General Public License | ||
| * along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
| * | ||
| * You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot. | ||
| * If not, see <https://www.gnu.org/licenses/>. | ||
| */ | ||
|
|
||
| package love.forte.simbot.component.onebot.v11.core.api.nonstandard | ||
|
|
@@ -24,8 +30,8 @@ import love.forte.simbot.common.id.ID | |
| import love.forte.simbot.common.id.literal | ||
| import love.forte.simbot.component.onebot.v11.core.api.OneBotApi | ||
| import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult | ||
| import love.forte.simbot.component.onebot.v11.core.api.OneBotMessageOutgoing | ||
| import love.forte.simbot.component.onebot.v11.core.api.SendMsgResult | ||
| import love.forte.simbot.component.onebot.v11.message.segment.OneBotForwardNode | ||
| import kotlin.jvm.JvmStatic | ||
|
|
||
| /** | ||
|
|
@@ -34,6 +40,7 @@ import kotlin.jvm.JvmStatic | |
| * @since 1.9.0 | ||
| * @author Aliorpse | ||
| */ | ||
| @OneBotNonStandardApi | ||
| public class SendPrivateForwardMsgApi private constructor( | ||
| override val body: Any | ||
| ) : OneBotApi<SendMsgResult> { | ||
|
|
@@ -59,7 +66,7 @@ public class SendPrivateForwardMsgApi private constructor( | |
| @JvmStatic | ||
| public fun create( | ||
| userId: ID, | ||
| messages: OneBotMessageOutgoing, | ||
| messages: List<OneBotForwardNode>, | ||
| ): SendPrivateForwardMsgApi = SendPrivateForwardMsgApi(Body(userId.literal, messages)) | ||
| } | ||
|
|
||
|
|
@@ -71,6 +78,6 @@ public class SendPrivateForwardMsgApi private constructor( | |
| internal data class Body( | ||
| @SerialName("user_id") | ||
| val userId: String, | ||
| val messages: OneBotMessageOutgoing, | ||
| val messages: List<OneBotForwardNode>, | ||
| ) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The change from StringID to ID for forwardId could be a breaking change for consumers expecting a specific ID type. Consider documenting this change or maintaining backward compatibility.