Skip to content

Commit ca84aba

Browse files
authored
Merge pull request #210 from simple-robot/dev/main
Release: v1.8.0
2 parents d72c15b + 1a846f2 commit ca84aba

File tree

29 files changed

+739
-82
lines changed

29 files changed

+739
-82
lines changed

.github/workflows/publish-release.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ jobs:
4141
uses: gradle/actions/setup-gradle@v3
4242
with:
4343
gradle-version: ${{ env.GRADLE_VERSION }}
44+
arguments: |
45+
assemble
46+
allTests
47+
--stacktrace
48+
--warning-mode all
49+
-Pkotlin.native.enableKlibsCrossCompilation=false
4450
45-
- name: Run all tests
46-
run: gradle assemble allTests --stacktrace --warning-mode all
51+
# - name: Run all tests
52+
# run: gradle assemble allTests --stacktrace --warning-mode all -Pkotlin.native.enableKlibsCrossCompilation=false
4753

4854
publish-releases:
4955
name: Publish releases

.github/workflows/publish-snapshot.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,15 @@ jobs:
6262
uses: gradle/actions/setup-gradle@v3
6363
with:
6464
gradle-version: ${{ env.GRADLE_VERSION }}
65+
arguments: |
66+
assemble
67+
allTests
68+
--stacktrace
69+
--warning-mode all
70+
-Pkotlin.native.enableKlibsCrossCompilation=false
6571
66-
- name: Run all tests
67-
run: gradle assemble allTests --stacktrace --warning-mode all
72+
# - name: Run all tests
73+
# run: gradle assemble allTests --stacktrace --warning-mode all -Pkotlin.native.enableKlibsCrossCompilation=false
6874

6975
publish-snapshots:
7076
name: Publish snapshots

build.gradle.kts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,9 @@ apiValidation {
138138
"love.forte.simbot.annotations.InternalSimbotAPI",
139139
"love.forte.simbot.component.onebot.common.annotations.ApiResultConstructor",
140140
"love.forte.simbot.component.onebot.common.annotations.SourceEventConstructor",
141+
142+
// CustomEventResolver
143+
"love.forte.simbot.component.onebot.v11.core.event.ExperimentalCustomEventResolverApi"
141144
),
142145
)
143146

buildSrc/src/main/kotlin/JvmConfig.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget
3030

3131

3232
inline fun KotlinJvmTarget.configJava(jdkVersion: Int, crossinline block: KotlinJvmTarget.() -> Unit = {}) {
33-
withJava()
3433
compilerOptions {
3534
javaParameters.set(true)
3635
jvmTarget.set(JvmTarget.fromTarget(jdkVersion.toString()))
@@ -88,12 +87,15 @@ inline fun Project.configJavaCompileWithModule(
8887
targetCompatibility = jvmVersion
8988

9089
if (moduleName != null) {
91-
options.compilerArgumentProviders.add(
92-
CommandLineArgumentProvider {
90+
options.compilerArgumentProviders.add(CommandLineArgumentProvider {
91+
val sourceSet = sourceSets.findByName("main") ?: sourceSets.findByName("jvmMain")
92+
if (sourceSet != null) {
9393
// Provide compiled Kotlin classes to javac – needed for Java/Kotlin mixed sources to work
94-
listOf("--patch-module", "$moduleName=${sourceSets["main"].output.asPath}")
94+
listOf("--patch-module", "$moduleName=${sourceSet.output.asPath}")
95+
} else {
96+
emptyList()
9597
}
96-
)
98+
})
9799
}
98100

99101
block()

buildSrc/src/main/kotlin/P.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ object P {
3737
override val description: String get() = DESCRIPTION
3838
override val homepage: String get() = HOMEPAGE
3939

40-
const val VERSION = "1.7.0"
41-
const val NEXT_VERSION = "1.7.1"
40+
const val VERSION = "1.8.0"
41+
const val NEXT_VERSION = "1.8.1"
4242

4343
override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
4444
override val version = if (isSnapshot()) snapshotVersion else VERSION

buildSrc/src/main/kotlin/simbot-onebot-changelog-generator.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*/
1717

1818

19-
tasks.create("createChangelog") {
19+
tasks.register("createChangelog") {
2020
group = "documentation"
2121
doFirst {
2222
val realVersion = P.ComponentOneBot.version.toString()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#Thu Mar 21 17:22:56 CST 2024
22
distributionBase=GRADLE_USER_HOME
33
distributionPath=wrapper/dists
4-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
55
zipStoreBase=GRADLE_USER_HOME
66
zipStorePath=wrapper/dists

simbot-component-onebot-common/build.gradle.kts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,6 @@ kotlin {
5959
api(kotlin("test"))
6060
}
6161

62-
jvmMain {
63-
dependencies {
64-
compileOnly(libs.simbot.api)
65-
}
66-
}
67-
6862
jvmTest.dependencies {
6963
implementation(libs.log4j.api)
7064
implementation(libs.log4j.core)

simbot-component-onebot-v11/simbot-component-onebot-v11-common/build.gradle.kts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ kotlin {
5151

5252
sourceSets {
5353
commonMain.dependencies {
54-
implementation(project(":simbot-component-onebot-common"))
55-
implementation(libs.simbot.common.annotations)
54+
api(project(":simbot-component-onebot-common"))
55+
api(libs.simbot.common.annotations)
5656
api(libs.kotlinx.serialization.core)
5757
}
5858

@@ -62,10 +62,6 @@ kotlin {
6262
api(libs.kotlinx.coroutines.test)
6363
}
6464

65-
jvmMain.dependencies {
66-
compileOnly(libs.simbot.common.annotations)
67-
}
68-
6965
jvmTest.dependencies {
7066
compileOnly(libs.simbot.common.annotations)
7167
implementation(libs.log4j.api)

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,10 @@ public abstract interface class love/forte/simbot/component/onebot/v11/core/api/
11041104
public abstract fun getAction ()Ljava/lang/String;
11051105
public abstract fun getApiResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
11061106
public abstract fun getBody ()Ljava/lang/Object;
1107+
public fun getMethod ()Lio/ktor/http/HttpMethod;
11071108
public abstract fun getResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
1109+
public fun resolveUrlAction (Lio/ktor/http/URLBuilder;Ljava/util/Collection;)V
1110+
public fun resolveUrlExtensions (Lio/ktor/http/URLBuilder;)V
11081111
}
11091112

11101113
public final class love/forte/simbot/component/onebot/v11/core/api/OneBotApi$Actions {
@@ -1161,6 +1164,10 @@ public final class love/forte/simbot/component/onebot/v11/core/api/OneBotApiExec
11611164
public final synthetic fun unbox-impl ()Llove/forte/simbot/component/onebot/v11/core/api/OneBotApiExecutable;
11621165
}
11631166

1167+
public final class love/forte/simbot/component/onebot/v11/core/api/OneBotApiKt {
1168+
public static final fun resolveUrl (Llove/forte/simbot/component/onebot/v11/core/api/OneBotApi;Lio/ktor/http/URLBuilder;Ljava/util/Collection;)V
1169+
}
1170+
11641171
public final class love/forte/simbot/component/onebot/v11/core/api/OneBotApiRequests {
11651172
public static final fun getApiLogger ()Lorg/slf4j/Logger;
11661173
public static final synthetic fun request (Llove/forte/simbot/component/onebot/v11/core/api/OneBotApi;Lio/ktor/client/HttpClient;Lio/ktor/http/Url;Ljava/lang/String;Ljava/util/Collection;Lkotlin/coroutines/Continuation;)Ljava/lang/Object;
@@ -2125,6 +2132,29 @@ public final class love/forte/simbot/component/onebot/v11/core/component/OneBot1
21252132
public static synthetic fun useOneBot11Component$default (Llove/forte/simbot/application/ApplicationFactoryConfigurer;Llove/forte/simbot/common/function/ConfigurerFunction;ILjava/lang/Object;)V
21262133
}
21272134

2135+
public class love/forte/simbot/component/onebot/v11/core/event/CustomEventResolveException : java/lang/RuntimeException {
2136+
public fun <init> ()V
2137+
public fun <init> (Ljava/lang/String;)V
2138+
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;)V
2139+
public fun <init> (Ljava/lang/Throwable;)V
2140+
}
2141+
2142+
public abstract interface class love/forte/simbot/component/onebot/v11/core/event/CustomEventResolver$Context {
2143+
public abstract fun getBot ()Llove/forte/simbot/component/onebot/v11/core/bot/OneBotBot;
2144+
public abstract fun getJson ()Lkotlinx/serialization/json/Json;
2145+
public abstract fun getRawEventResolveResult ()Llove/forte/simbot/component/onebot/v11/core/event/RawEventResolveResult;
2146+
}
2147+
2148+
public class love/forte/simbot/component/onebot/v11/core/event/EventResolveException : java/lang/RuntimeException {
2149+
public fun <init> ()V
2150+
public fun <init> (Ljava/lang/String;)V
2151+
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;)V
2152+
public fun <init> (Ljava/lang/Throwable;)V
2153+
}
2154+
2155+
public abstract interface annotation class love/forte/simbot/component/onebot/v11/core/event/ExperimentalCustomEventResolverApi : java/lang/annotation/Annotation {
2156+
}
2157+
21282158
public abstract interface class love/forte/simbot/component/onebot/v11/core/event/OneBotBotEvent : love/forte/simbot/component/onebot/v11/core/event/OneBotEvent, love/forte/simbot/event/BotEvent {
21292159
public abstract fun getBot ()Llove/forte/simbot/component/onebot/v11/core/bot/OneBotBot;
21302160
}

simbot-component-onebot-v11/simbot-component-onebot-v11-core/build.gradle.kts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,20 @@ kotlin {
105105
implementation(libs.log4j.slf4j2)
106106
implementation(libs.kotlinPoet)
107107
implementation(libs.kotlinx.coroutines.reactor)
108-
api(libs.ktor.client.java)
108+
implementation(libs.ktor.client.java)
109109
implementation(libs.ktor.server.netty)
110110
implementation(libs.ktor.server.ws)
111111
}
112+
113+
appleTest.dependencies {
114+
implementation(libs.ktor.client.darwin)
115+
}
116+
mingwTest.dependencies {
117+
implementation(libs.ktor.client.winhttp)
118+
}
119+
linuxTest.dependencies {
120+
implementation(libs.ktor.client.cio)
121+
}
112122
}
113123
}
114124

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

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package love.forte.simbot.component.onebot.v11.core.api
1919

20+
import io.ktor.http.*
2021
import kotlinx.serialization.*
2122
import kotlinx.serialization.builtins.serializer
2223
import kotlinx.serialization.descriptors.SerialDescriptor
@@ -37,10 +38,48 @@ import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult.Companion
3738
*/
3839
public interface OneBotApi<T : Any> {
3940
/**
40-
* API 的 action(要进行的动作)
41+
* 此 API 的请求方式。
42+
* OneBot协议中的标准API通常均为 POST,
43+
* 但是一些额外的扩展或自定义API可能是 GET 或其他方式。
44+
* @since 1.8.0
45+
*/
46+
public val method: HttpMethod
47+
get() = HttpMethod.Post
48+
49+
/**
50+
* API 的 action(要进行的动作),会通过 [resolveUrlAction] 附加在 url 中。
51+
* 可以重写它来改变此逻辑。
4152
*/
4253
public val action: String
4354

55+
/**
56+
* 根据 [action] 和可能额外要求的 [actionSuffixes] 构建一个完整的请求地址。
57+
*
58+
* [urlBuilder] 中已经添加了基础的 `host` 等信息。
59+
*
60+
* @since 1.8.0
61+
*/
62+
public fun resolveUrlAction(urlBuilder: URLBuilder, actionSuffixes: Collection<String>?) {
63+
if (actionSuffixes?.isEmpty() != false) {
64+
urlBuilder.appendPathSegments(action)
65+
} else {
66+
urlBuilder.appendPathSegments(
67+
buildString(action.length) {
68+
append(action)
69+
actionSuffixes.forEach { sf -> append(sf) }
70+
}
71+
)
72+
}
73+
}
74+
75+
/**
76+
* 对 [urlBuilder] 进行一些额外的处理,例如当method为GET时为其添加查询参数。
77+
* 主要面向额外扩展的自定义实现来重写此方法。
78+
* @since 1.8.0
79+
*/
80+
public fun resolveUrlExtensions(urlBuilder: URLBuilder) {
81+
}
82+
4483
/**
4584
* API的参数。
4685
*/
@@ -52,7 +91,7 @@ public interface OneBotApi<T : Any> {
5291
public val resultDeserializer: DeserializationStrategy<T>
5392

5493
/**
55-
* 预期结果 [OneBotApi] 类型的反序列化器。
94+
* 预期结果 [OneBotApiResult] 类型的反序列化器。
5695
*/
5796
public val apiResultDeserializer: DeserializationStrategy<OneBotApiResult<T>>
5897

@@ -76,6 +115,15 @@ public interface OneBotApi<T : Any> {
76115
}
77116
}
78117

118+
/**
119+
* 使用 [OneBotApi.resolveUrlAction] 和 [OneBotApi.resolveUrlExtensions] 。
120+
* @since 1.8.0
121+
*/
122+
public fun OneBotApi<*>.resolveUrl(urlBuilder: URLBuilder, actionSuffixes: Collection<String>?) {
123+
resolveUrlAction(urlBuilder, actionSuffixes)
124+
resolveUrlExtensions(urlBuilder)
125+
}
126+
79127
/**
80128
* [响应](https://github.com/botuniverse/onebot-11/blob/master/api/README.md#响应)
81129
*

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

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,13 @@ public suspend fun OneBotApi<*>.request(
102102
accessToken: String? = null,
103103
actionSuffixes: Collection<String>? = null,
104104
): HttpResponse {
105-
return client.post {
105+
val api = this
106+
107+
return client.request {
108+
this.method = api.method
106109
url {
107110
takeFrom(host)
108-
if (actionSuffixes?.isEmpty() != false) {
109-
appendPathSegments(action)
110-
} else {
111-
appendPathSegments(
112-
buildString(action.length) {
113-
append(action)
114-
actionSuffixes.forEach { sf -> append(sf) }
115-
}
116-
)
117-
}
111+
api.resolveUrl(this, actionSuffixes)
118112
}
119113

120114
headers {
@@ -124,7 +118,7 @@ public suspend fun OneBotApi<*>.request(
124118

125119
var jsonStr: String? = null
126120

127-
when (val b = this@request.body) {
121+
when (val b = api.body) {
128122
null -> {
129123
if (GlobalOneBotApiRequestConfiguration.emptyJsonStringIfBodyNull) {
130124
setBody(EMPTY_JSON_STR)
@@ -163,7 +157,7 @@ public suspend fun OneBotApi<*>.request(
163157
"API [{}] REQ ===> {}, body: {}, json: {}",
164158
action,
165159
url,
166-
this@request.body,
160+
api.body,
167161
jsonStr
168162
)
169163
}.also { res ->

simbot-component-onebot-v11/simbot-component-onebot-v11-core/src/commonMain/kotlin/love/forte/simbot/component/onebot/v11/core/bot/OneBotBot.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import love.forte.simbot.component.onebot.v11.message.OneBotMessageContent
4343
import love.forte.simbot.event.EventResult
4444
import love.forte.simbot.message.MessageReference
4545
import love.forte.simbot.suspendrunner.ST
46+
import org.intellij.lang.annotations.Language
4647
import kotlin.coroutines.CoroutineContext
4748
import kotlin.jvm.JvmSynthetic
4849

@@ -200,14 +201,14 @@ public interface OneBotBot : Bot, OneBotApiExecutable {
200201
*
201202
* @throws IllegalArgumentException 如果事件解析失败
202203
*/
203-
public fun push(rawEvent: String): Flow<EventResult>
204+
public fun push(@Language("json") rawEvent: String): Flow<EventResult>
204205

205206
/**
206207
* 直接推送一个外部的原始事件字符串,并在异步任务中处理事件。
207208
*
208209
* @throws IllegalArgumentException 如果事件解析失败
209210
*/
210-
public fun pushAndLaunch(rawEvent: String): Job =
211+
public fun pushAndLaunch(@Language("json") rawEvent: String): Job =
211212
push(rawEvent).launchIn(this)
212213

213214
/**

0 commit comments

Comments
 (0)