Skip to content

Release: v1.8.0 #210

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 14 commits into from
May 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,15 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: |
assemble
allTests
--stacktrace
--warning-mode all
-Pkotlin.native.enableKlibsCrossCompilation=false

- name: Run all tests
run: gradle assemble allTests --stacktrace --warning-mode all
# - name: Run all tests
# run: gradle assemble allTests --stacktrace --warning-mode all -Pkotlin.native.enableKlibsCrossCompilation=false

publish-releases:
name: Publish releases
Expand Down
10 changes: 8 additions & 2 deletions .github/workflows/publish-snapshot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ jobs:
uses: gradle/actions/setup-gradle@v3
with:
gradle-version: ${{ env.GRADLE_VERSION }}
arguments: |
assemble
allTests
--stacktrace
--warning-mode all
-Pkotlin.native.enableKlibsCrossCompilation=false

- name: Run all tests
run: gradle assemble allTests --stacktrace --warning-mode all
# - name: Run all tests
# run: gradle assemble allTests --stacktrace --warning-mode all -Pkotlin.native.enableKlibsCrossCompilation=false

publish-snapshots:
name: Publish snapshots
Expand Down
3 changes: 3 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ apiValidation {
"love.forte.simbot.annotations.InternalSimbotAPI",
"love.forte.simbot.component.onebot.common.annotations.ApiResultConstructor",
"love.forte.simbot.component.onebot.common.annotations.SourceEventConstructor",

// CustomEventResolver
"love.forte.simbot.component.onebot.v11.core.event.ExperimentalCustomEventResolverApi"
),
)

Expand Down
12 changes: 7 additions & 5 deletions buildSrc/src/main/kotlin/JvmConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import org.jetbrains.kotlin.gradle.targets.jvm.KotlinJvmTarget


inline fun KotlinJvmTarget.configJava(jdkVersion: Int, crossinline block: KotlinJvmTarget.() -> Unit = {}) {
withJava()
compilerOptions {
javaParameters.set(true)
jvmTarget.set(JvmTarget.fromTarget(jdkVersion.toString()))
Expand Down Expand Up @@ -88,12 +87,15 @@ inline fun Project.configJavaCompileWithModule(
targetCompatibility = jvmVersion

if (moduleName != null) {
options.compilerArgumentProviders.add(
CommandLineArgumentProvider {
options.compilerArgumentProviders.add(CommandLineArgumentProvider {
val sourceSet = sourceSets.findByName("main") ?: sourceSets.findByName("jvmMain")
if (sourceSet != null) {
// Provide compiled Kotlin classes to javac – needed for Java/Kotlin mixed sources to work
listOf("--patch-module", "$moduleName=${sourceSets["main"].output.asPath}")
listOf("--patch-module", "$moduleName=${sourceSet.output.asPath}")
} else {
emptyList()
}
)
})
}

block()
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/P.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ object P {
override val description: String get() = DESCRIPTION
override val homepage: String get() = HOMEPAGE

const val VERSION = "1.7.0"
const val NEXT_VERSION = "1.7.1"
const val VERSION = "1.8.0"
const val NEXT_VERSION = "1.8.1"

override val snapshotVersion = "$NEXT_VERSION-SNAPSHOT"
override val version = if (isSnapshot()) snapshotVersion else VERSION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/


tasks.create("createChangelog") {
tasks.register("createChangelog") {
group = "documentation"
doFirst {
val realVersion = P.ComponentOneBot.version.toString()
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Thu Mar 21 17:22:56 CST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
6 changes: 0 additions & 6 deletions simbot-component-onebot-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ kotlin {
api(kotlin("test"))
}

jvmMain {
dependencies {
compileOnly(libs.simbot.api)
}
}

jvmTest.dependencies {
implementation(libs.log4j.api)
implementation(libs.log4j.core)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ kotlin {

sourceSets {
commonMain.dependencies {
implementation(project(":simbot-component-onebot-common"))
implementation(libs.simbot.common.annotations)
api(project(":simbot-component-onebot-common"))
api(libs.simbot.common.annotations)
api(libs.kotlinx.serialization.core)
}

Expand All @@ -62,10 +62,6 @@ kotlin {
api(libs.kotlinx.coroutines.test)
}

jvmMain.dependencies {
compileOnly(libs.simbot.common.annotations)
}

jvmTest.dependencies {
compileOnly(libs.simbot.common.annotations)
implementation(libs.log4j.api)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1104,7 +1104,10 @@ public abstract interface class love/forte/simbot/component/onebot/v11/core/api/
public abstract fun getAction ()Ljava/lang/String;
public abstract fun getApiResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
public abstract fun getBody ()Ljava/lang/Object;
public fun getMethod ()Lio/ktor/http/HttpMethod;
public abstract fun getResultDeserializer ()Lkotlinx/serialization/DeserializationStrategy;
public fun resolveUrlAction (Lio/ktor/http/URLBuilder;Ljava/util/Collection;)V
public fun resolveUrlExtensions (Lio/ktor/http/URLBuilder;)V
}

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

public final class love/forte/simbot/component/onebot/v11/core/api/OneBotApiKt {
public static final fun resolveUrl (Llove/forte/simbot/component/onebot/v11/core/api/OneBotApi;Lio/ktor/http/URLBuilder;Ljava/util/Collection;)V
}

public final class love/forte/simbot/component/onebot/v11/core/api/OneBotApiRequests {
public static final fun getApiLogger ()Lorg/slf4j/Logger;
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;
Expand Down Expand Up @@ -2125,6 +2132,29 @@ public final class love/forte/simbot/component/onebot/v11/core/component/OneBot1
public static synthetic fun useOneBot11Component$default (Llove/forte/simbot/application/ApplicationFactoryConfigurer;Llove/forte/simbot/common/function/ConfigurerFunction;ILjava/lang/Object;)V
}

public class love/forte/simbot/component/onebot/v11/core/event/CustomEventResolveException : java/lang/RuntimeException {
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun <init> (Ljava/lang/Throwable;)V
}

public abstract interface class love/forte/simbot/component/onebot/v11/core/event/CustomEventResolver$Context {
public abstract fun getBot ()Llove/forte/simbot/component/onebot/v11/core/bot/OneBotBot;
public abstract fun getJson ()Lkotlinx/serialization/json/Json;
public abstract fun getRawEventResolveResult ()Llove/forte/simbot/component/onebot/v11/core/event/RawEventResolveResult;
}

public class love/forte/simbot/component/onebot/v11/core/event/EventResolveException : java/lang/RuntimeException {
public fun <init> ()V
public fun <init> (Ljava/lang/String;)V
public fun <init> (Ljava/lang/String;Ljava/lang/Throwable;)V
public fun <init> (Ljava/lang/Throwable;)V
}

public abstract interface annotation class love/forte/simbot/component/onebot/v11/core/event/ExperimentalCustomEventResolverApi : java/lang/annotation/Annotation {
}

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 {
public abstract fun getBot ()Llove/forte/simbot/component/onebot/v11/core/bot/OneBotBot;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,20 @@ kotlin {
implementation(libs.log4j.slf4j2)
implementation(libs.kotlinPoet)
implementation(libs.kotlinx.coroutines.reactor)
api(libs.ktor.client.java)
implementation(libs.ktor.client.java)
implementation(libs.ktor.server.netty)
implementation(libs.ktor.server.ws)
}

appleTest.dependencies {
implementation(libs.ktor.client.darwin)
}
mingwTest.dependencies {
implementation(libs.ktor.client.winhttp)
}
linuxTest.dependencies {
implementation(libs.ktor.client.cio)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

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

import io.ktor.http.*
import kotlinx.serialization.*
import kotlinx.serialization.builtins.serializer
import kotlinx.serialization.descriptors.SerialDescriptor
Expand All @@ -37,10 +38,48 @@ import love.forte.simbot.component.onebot.v11.core.api.OneBotApiResult.Companion
*/
public interface OneBotApi<T : Any> {
/**
* API 的 action(要进行的动作)
* 此 API 的请求方式。
* OneBot协议中的标准API通常均为 POST,
* 但是一些额外的扩展或自定义API可能是 GET 或其他方式。
* @since 1.8.0
*/
public val method: HttpMethod
get() = HttpMethod.Post

/**
* API 的 action(要进行的动作),会通过 [resolveUrlAction] 附加在 url 中。
* 可以重写它来改变此逻辑。
*/
public val action: String

/**
* 根据 [action] 和可能额外要求的 [actionSuffixes] 构建一个完整的请求地址。
*
* [urlBuilder] 中已经添加了基础的 `host` 等信息。
*
* @since 1.8.0
*/
public fun resolveUrlAction(urlBuilder: URLBuilder, actionSuffixes: Collection<String>?) {
if (actionSuffixes?.isEmpty() != false) {
urlBuilder.appendPathSegments(action)
} else {
urlBuilder.appendPathSegments(
buildString(action.length) {
append(action)
actionSuffixes.forEach { sf -> append(sf) }
}
)
}
}

/**
* 对 [urlBuilder] 进行一些额外的处理,例如当method为GET时为其添加查询参数。
* 主要面向额外扩展的自定义实现来重写此方法。
* @since 1.8.0
*/
public fun resolveUrlExtensions(urlBuilder: URLBuilder) {
}

/**
* API的参数。
*/
Expand All @@ -52,7 +91,7 @@ public interface OneBotApi<T : Any> {
public val resultDeserializer: DeserializationStrategy<T>

/**
* 预期结果 [OneBotApi] 类型的反序列化器。
* 预期结果 [OneBotApiResult] 类型的反序列化器。
*/
public val apiResultDeserializer: DeserializationStrategy<OneBotApiResult<T>>

Expand All @@ -76,6 +115,15 @@ public interface OneBotApi<T : Any> {
}
}

/**
* 使用 [OneBotApi.resolveUrlAction] 和 [OneBotApi.resolveUrlExtensions] 。
* @since 1.8.0
*/
public fun OneBotApi<*>.resolveUrl(urlBuilder: URLBuilder, actionSuffixes: Collection<String>?) {
resolveUrlAction(urlBuilder, actionSuffixes)
resolveUrlExtensions(urlBuilder)
}

/**
* [响应](https://github.com/botuniverse/onebot-11/blob/master/api/README.md#响应)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,19 +102,13 @@ public suspend fun OneBotApi<*>.request(
accessToken: String? = null,
actionSuffixes: Collection<String>? = null,
): HttpResponse {
return client.post {
val api = this

return client.request {
this.method = api.method
url {
takeFrom(host)
if (actionSuffixes?.isEmpty() != false) {
appendPathSegments(action)
} else {
appendPathSegments(
buildString(action.length) {
append(action)
actionSuffixes.forEach { sf -> append(sf) }
}
)
}
api.resolveUrl(this, actionSuffixes)
}

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

var jsonStr: String? = null

when (val b = this@request.body) {
when (val b = api.body) {
null -> {
if (GlobalOneBotApiRequestConfiguration.emptyJsonStringIfBodyNull) {
setBody(EMPTY_JSON_STR)
Expand Down Expand Up @@ -163,7 +157,7 @@ public suspend fun OneBotApi<*>.request(
"API [{}] REQ ===> {}, body: {}, json: {}",
action,
url,
this@request.body,
api.body,
jsonStr
)
}.also { res ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import love.forte.simbot.component.onebot.v11.message.OneBotMessageContent
import love.forte.simbot.event.EventResult
import love.forte.simbot.message.MessageReference
import love.forte.simbot.suspendrunner.ST
import org.intellij.lang.annotations.Language
import kotlin.coroutines.CoroutineContext
import kotlin.jvm.JvmSynthetic

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

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

/**
Expand Down
Loading
Loading