Skip to content

Commit f8f44bc

Browse files
committed
improve(nonstandard-apis): 添加非标准API的OPT经过,重构转发消息API以使用OneBotForwardNode
1 parent a2c232f commit f8f44bc

File tree

11 files changed

+315
-182
lines changed

11 files changed

+315
-182
lines changed

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,10 @@ apiValidation {
148148
"love.forte.simbot.component.onebot.v11.core.event.ExperimentalCustomEventResolverApi",
149149

150150
// CustomOneBotApi
151-
"love.forte.simbot.component.onebot.v11.core.api.ExperimentalCustomOneBotApi"
151+
"love.forte.simbot.component.onebot.v11.core.api.ExperimentalCustomOneBotApi",
152+
153+
// OneBotNonStandardApi
154+
"love.forte.simbot.component.onebot.v11.core.api.nonstandard.OneBotNonStandardApi"
152155
),
153156
)
154157

simbot-component-onebot-common/src/commonMain/kotlin/love/forte/simbot/component/onebot/common/annotations/ComponentOpts.kt

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
/*
2-
* Copyright (c) 2024. ForteScarlet.
2+
* Copyright (c) 2024-2025. ForteScarlet.
33
*
4-
* This file is part of simbot-component-onebot.
4+
* Project https://github.com/simple-robot/simbot-component-onebot
5+
56
*
6-
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
7-
* of the GNU Lesser General Public License as published by the Free Software Foundation,
8-
* either version 3 of the License, or (at your option) any later version.
7+
* This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
98
*
10-
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11-
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
* See the GNU Lesser General Public License for more details.
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1321
*
14-
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
15-
* If not, see <https://www.gnu.org/licenses/>.
1622
*/
1723

1824
package love.forte.simbot.component.onebot.common.annotations
@@ -27,6 +33,7 @@ package love.forte.simbot.component.onebot.common.annotations
2733
)
2834
@Target(
2935
AnnotationTarget.CLASS,
36+
AnnotationTarget.TYPEALIAS,
3037
AnnotationTarget.ANNOTATION_CLASS,
3138
AnnotationTarget.PROPERTY,
3239
AnnotationTarget.FUNCTION,

simbot-component-onebot-v11/simbot-component-onebot-v11-core/api/simbot-component-onebot-v11-core.api

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1800,31 +1800,11 @@ public final class love/forte/simbot/component/onebot/v11/core/api/SetRestartApi
18001800
public static synthetic fun create$default (Llove/forte/simbot/component/onebot/v11/core/api/SetRestartApi$Factory;Ljava/lang/Long;ILjava/lang/Object;)Llove/forte/simbot/component/onebot/v11/core/api/SetRestartApi;
18011801
}
18021802

1803-
public final class love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi : love/forte/simbot/component/onebot/v11/core/api/OneBotApi {
1804-
public static final field Factory Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi$Factory;
1805-
public synthetic fun <init> (Ljava/lang/Object;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
1806-
public static final fun create (Llove/forte/simbot/common/id/ID;Llove/forte/simbot/component/onebot/v11/core/api/OneBotMessageOutgoing;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi;
1807-
public fun getAction ()Ljava/lang/String;
1808-
public fun getApiResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
1809-
public fun getBody ()Ljava/lang/Object;
1810-
public fun getResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
1803+
public abstract interface annotation class love/forte/simbot/component/onebot/v11/core/api/nonstandard/OneBotNonStandardApi : java/lang/annotation/Annotation {
18111804
}
18121805

18131806
public final class love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi$Factory {
1814-
public final fun create (Llove/forte/simbot/common/id/ID;Llove/forte/simbot/component/onebot/v11/core/api/OneBotMessageOutgoing;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi;
1815-
}
1816-
1817-
public final class love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgResult {
1818-
public static final field Companion Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgResult$Companion;
1819-
public final fun component1 ()Llove/forte/simbot/common/id/IntID;
1820-
public final fun component2 ()Llove/forte/simbot/common/id/StringID;
1821-
public final fun copy (Llove/forte/simbot/common/id/IntID;Llove/forte/simbot/common/id/StringID;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgResult;
1822-
public static synthetic fun copy$default (Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgResult;Llove/forte/simbot/common/id/IntID;Llove/forte/simbot/common/id/StringID;ILjava/lang/Object;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgResult;
1823-
public fun equals (Ljava/lang/Object;)Z
1824-
public final fun getForwardId ()Llove/forte/simbot/common/id/StringID;
1825-
public final fun getMessageId ()Llove/forte/simbot/common/id/IntID;
1826-
public fun hashCode ()I
1827-
public fun toString ()Ljava/lang/String;
1807+
public final fun create (Llove/forte/simbot/common/id/ID;Ljava/util/List;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi;
18281808
}
18291809

18301810
public synthetic class love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgResult$$serializer : kotlinx/serialization/internal/GeneratedSerializer {
@@ -1842,18 +1822,8 @@ public final class love/forte/simbot/component/onebot/v11/core/api/nonstandard/S
18421822
public final fun serializer ()Lkotlinx/serialization/KSerializer;
18431823
}
18441824

1845-
public final class love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi : love/forte/simbot/component/onebot/v11/core/api/OneBotApi {
1846-
public static final field Factory Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi$Factory;
1847-
public synthetic fun <init> (Ljava/lang/Object;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
1848-
public static final fun create (Llove/forte/simbot/common/id/ID;Llove/forte/simbot/component/onebot/v11/core/api/OneBotMessageOutgoing;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi;
1849-
public fun getAction ()Ljava/lang/String;
1850-
public fun getApiResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
1851-
public fun getBody ()Ljava/lang/Object;
1852-
public fun getResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
1853-
}
1854-
18551825
public final class love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi$Factory {
1856-
public final fun create (Llove/forte/simbot/common/id/ID;Llove/forte/simbot/component/onebot/v11/core/api/OneBotMessageOutgoing;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi;
1826+
public final fun create (Llove/forte/simbot/common/id/ID;Ljava/util/List;)Llove/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi;
18571827
}
18581828

18591829
public abstract interface class love/forte/simbot/component/onebot/v11/core/bot/OneBotBot : love/forte/simbot/bot/Bot, love/forte/simbot/component/onebot/v11/core/api/OneBotApiExecutable {

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/OneBotMessageOutgoing.kt

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
/*
2-
* Copyright (c) 2024. ForteScarlet.
2+
* Copyright (c) 2024-2025. ForteScarlet.
33
*
4-
* This file is part of simbot-component-onebot.
4+
* Project https://github.com/simple-robot/simbot-component-onebot
5+
56
*
6-
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
7-
* of the GNU Lesser General Public License as published by the Free Software Foundation,
8-
* either version 3 of the License, or (at your option) any later version.
7+
* This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
98
*
10-
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11-
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
* See the GNU Lesser General Public License for more details.
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1321
*
14-
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
15-
* If not, see <https://www.gnu.org/licenses/>.
1622
*/
1723

1824
package love.forte.simbot.component.onebot.v11.core.api
@@ -26,10 +32,16 @@ import kotlinx.serialization.descriptors.buildClassSerialDescriptor
2632
import kotlinx.serialization.encoding.Decoder
2733
import kotlinx.serialization.encoding.Encoder
2834
import love.forte.simbot.annotations.FragileSimbotAPI
35+
import love.forte.simbot.component.onebot.common.annotations.ExperimentalOneBotAPI
36+
import love.forte.simbot.component.onebot.v11.core.bot.OneBotBot
37+
import love.forte.simbot.component.onebot.v11.core.utils.resolveToOneBotSegmentList
2938
import love.forte.simbot.component.onebot.v11.message.OneBotMessageElement
3039
import love.forte.simbot.component.onebot.v11.message.OneBotMessageElementSerializer
3140
import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegment
3241
import love.forte.simbot.component.onebot.v11.message.segment.OneBotMessageSegmentSerializer
42+
import love.forte.simbot.message.Message
43+
import love.forte.simbot.message.Messages
44+
import kotlin.jvm.JvmOverloads
3345
import kotlin.jvm.JvmStatic
3446

3547

@@ -60,16 +72,31 @@ public sealed class OneBotMessageOutgoing {
6072

6173
@Serializable
6274
public data class SegmentsValue(
63-
6475
public val segments: List<OneBotMessageSegment>
6576
) : OneBotMessageOutgoing()
6677

6778
public companion object {
79+
/**
80+
* 通过字符串值构建 [StringValue]。
81+
*/
6882
@JvmStatic
6983
public fun create(value: String): StringValue = StringValue(value)
7084

85+
/**
86+
* 通过消息段列表构建 [SegmentsValue]。
87+
*/
7188
@JvmStatic
7289
public fun create(segments: List<OneBotMessageSegment>): SegmentsValue = SegmentsValue(segments)
90+
91+
/**
92+
* 通过 [Messages] 构建 [SegmentsValue]。
93+
* @since 1.9.0
94+
*/
95+
@JvmStatic
96+
@ExperimentalOneBotAPI
97+
@JvmOverloads
98+
public fun create(message: Message, bot: OneBotBot? = null): SegmentsValue =
99+
create(message.resolveToOneBotSegmentList(bot))
73100
}
74101
}
75102

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Copyright (c) 2025. ForteScarlet.
3+
*
4+
* Project https://github.com/simple-robot/simbot-component-onebot
5+
6+
*
7+
* This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
21+
*
22+
*/
23+
24+
package love.forte.simbot.component.onebot.v11.core.api.nonstandard
25+
26+
/**
27+
* 与非标准API相关的内容。
28+
* 非标准API的实现目前尚处于实验阶段。它们不保证兼容性,并且可能在未来发生变更或被移除。
29+
*
30+
* @since 1.9.0
31+
* @author ForteScarlet
32+
*/
33+
@Retention(AnnotationRetention.BINARY)
34+
@Target(AnnotationTarget.CLASS, AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY)
35+
@RequiresOptIn("This api is not part of the onebot protocol standard, and may not be available in the future.")
36+
public annotation class OneBotNonStandardApi

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendGroupForwardMsgApi.kt

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
/*
2-
* Copyright (c) 2025. ForteScarlet.
2+
* Copyright (c) 2025. ForteScarlet.
33
*
4-
* This file is part of simbot-component-onebot.
4+
* Project https://github.com/simple-robot/simbot-component-onebot
5+
56
*
6-
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
7-
* of the GNU Lesser General Public License as published by the Free Software Foundation,
8-
* either version 3 of the License, or (at your option) any later version.
7+
* This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
98
*
10-
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11-
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
* See the GNU Lesser General Public License for more details.
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1321
*
14-
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
15-
* If not, see <https://www.gnu.org/licenses/>.
1622
*/
1723

1824
package love.forte.simbot.component.onebot.v11.core.api.nonstandard
@@ -22,12 +28,11 @@ import kotlinx.serialization.SerialName
2228
import kotlinx.serialization.Serializable
2329
import love.forte.simbot.common.id.ID
2430
import love.forte.simbot.common.id.IntID
25-
import love.forte.simbot.common.id.StringID
2631
import love.forte.simbot.common.id.literal
2732
import love.forte.simbot.component.onebot.common.annotations.ApiResultConstructor
2833
import love.forte.simbot.component.onebot.v11.core.api.OneBotApi
2934
import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult
30-
import love.forte.simbot.component.onebot.v11.core.api.OneBotMessageOutgoing
35+
import love.forte.simbot.component.onebot.v11.message.segment.OneBotForwardNode
3136
import kotlin.jvm.JvmStatic
3237

3338
/**
@@ -36,6 +41,7 @@ import kotlin.jvm.JvmStatic
3641
* @since 1.9.0
3742
* @author Aliorpse
3843
*/
44+
@OneBotNonStandardApi
3945
public class SendGroupForwardMsgApi private constructor(
4046
override val body: Any,
4147
) : OneBotApi<SendGroupForwardMsgResult> {
@@ -62,7 +68,7 @@ public class SendGroupForwardMsgApi private constructor(
6268
@JvmStatic
6369
public fun create(
6470
groupId: ID,
65-
messages: OneBotMessageOutgoing,
71+
messages: List<OneBotForwardNode>,
6672
): SendGroupForwardMsgApi = SendGroupForwardMsgApi(Body(groupId.literal, messages))
6773
}
6874

@@ -74,7 +80,7 @@ public class SendGroupForwardMsgApi private constructor(
7480
internal data class Body(
7581
@SerialName("group_id")
7682
val groupId: String,
77-
val messages: OneBotMessageOutgoing,
83+
val messages: List<OneBotForwardNode>,
7884
)
7985
}
8086

@@ -85,9 +91,10 @@ public class SendGroupForwardMsgApi private constructor(
8591
* @property forwardId RES ID
8692
*/
8793
@Serializable
94+
@OneBotNonStandardApi
8895
public data class SendGroupForwardMsgResult @ApiResultConstructor constructor(
8996
@SerialName("message_id")
9097
public val messageId: IntID,
9198
@SerialName("forward_id")
92-
public val forwardId: StringID
99+
public val forwardId: ID
93100
)

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/api/nonstandard/SendPrivateForwardMsgApi.kt

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
11
/*
2-
* Copyright (c) 2025. ForteScarlet.
2+
* Copyright (c) 2025. ForteScarlet.
33
*
4-
* This file is part of simbot-component-onebot.
4+
* Project https://github.com/simple-robot/simbot-component-onebot
5+
56
*
6-
* simbot-component-onebot is free software: you can redistribute it and/or modify it under the terms
7-
* of the GNU Lesser General Public License as published by the Free Software Foundation,
8-
* either version 3 of the License, or (at your option) any later version.
7+
* This project and this file are part of the Simple Robot Library (Alias: simple-robot, simbot, etc.).
98
*
10-
* simbot-component-onebot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
11-
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
12-
* See the GNU Lesser General Public License for more details.
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Lesser General Public License as published by
11+
* the Free Software Foundation, either version 3 of the License, or
12+
* (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* Lesser GNU General Public License for more details.
18+
*
19+
* You should have received a copy of the Lesser GNU General Public License
20+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
1321
*
14-
* You should have received a copy of the GNU Lesser General Public License along with simbot-component-onebot.
15-
* If not, see <https://www.gnu.org/licenses/>.
1622
*/
1723

1824
package love.forte.simbot.component.onebot.v11.core.api.nonstandard
@@ -24,8 +30,8 @@ import love.forte.simbot.common.id.ID
2430
import love.forte.simbot.common.id.literal
2531
import love.forte.simbot.component.onebot.v11.core.api.OneBotApi
2632
import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult
27-
import love.forte.simbot.component.onebot.v11.core.api.OneBotMessageOutgoing
2833
import love.forte.simbot.component.onebot.v11.core.api.SendMsgResult
34+
import love.forte.simbot.component.onebot.v11.message.segment.OneBotForwardNode
2935
import kotlin.jvm.JvmStatic
3036

3137
/**
@@ -34,6 +40,7 @@ import kotlin.jvm.JvmStatic
3440
* @since 1.9.0
3541
* @author Aliorpse
3642
*/
43+
@OneBotNonStandardApi
3744
public class SendPrivateForwardMsgApi private constructor(
3845
override val body: Any
3946
) : OneBotApi<SendMsgResult> {
@@ -59,7 +66,7 @@ public class SendPrivateForwardMsgApi private constructor(
5966
@JvmStatic
6067
public fun create(
6168
userId: ID,
62-
messages: OneBotMessageOutgoing,
69+
messages: List<OneBotForwardNode>,
6370
): SendPrivateForwardMsgApi = SendPrivateForwardMsgApi(Body(userId.literal, messages))
6471
}
6572

@@ -71,6 +78,6 @@ public class SendPrivateForwardMsgApi private constructor(
7178
internal data class Body(
7279
@SerialName("user_id")
7380
val userId: String,
74-
val messages: OneBotMessageOutgoing,
81+
val messages: List<OneBotForwardNode>,
7582
)
7683
}

0 commit comments

Comments
 (0)