Skip to content
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
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
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.0"

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 @@ -2125,6 +2125,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 @@ -52,7 +52,7 @@ public interface OneBotApi<T : Any> {
public val resultDeserializer: DeserializationStrategy<T>

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

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
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,17 @@ import io.ktor.client.*
import io.ktor.client.engine.*
import io.ktor.client.plugins.*
import io.ktor.http.*
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.modules.SerializersModule
import kotlinx.serialization.modules.overwriteWith
import love.forte.simbot.common.function.ConfigurerFunction
import love.forte.simbot.common.function.invokeBy
import love.forte.simbot.component.onebot.common.annotations.ExperimentalOneBotAPI
import love.forte.simbot.component.onebot.v11.core.event.CustomEventResolver
import love.forte.simbot.component.onebot.v11.core.event.CustomKotlinSerializationEventResolver
import love.forte.simbot.component.onebot.v11.core.event.ExperimentalCustomEventResolverApi
import love.forte.simbot.component.onebot.v11.message.segment.OneBotImage
import love.forte.simbot.event.Event
import love.forte.simbot.resource.Resource
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
Expand Down Expand Up @@ -252,4 +257,56 @@ public class OneBotBotConfiguration {
public fun defaultImageAdditionalParams(params: OneBotImage.AdditionalParams?) {
defaultImageAdditionalParamsProvider = { params }
}

/**
*
* @since 1.8.0
*/
@ExperimentalCustomEventResolverApi
internal val customEventResolvers: MutableList<CustomEventResolver> = mutableListOf()

/**
* 注册一个 [CustomEventResolver]。
* @since 1.8.0
*/
@ExperimentalCustomEventResolverApi
public fun addCustomEventResolver(customEventResolver: CustomEventResolver) {
customEventResolvers.add(customEventResolver)
}
}

/**
* 添加一个 [CustomKotlinSerializationEventResolver]。
*
* @see OneBotBotConfiguration.addCustomEventResolver
* @since 1.8.0
*/
@ExperimentalCustomEventResolverApi
public fun OneBotBotConfiguration.addCustomKotlinSerializationEventResolver(
resolver: CustomKotlinSerializationEventResolver
) {
addCustomEventResolver(resolver)
}

/**
* 添加一个 [CustomKotlinSerializationEventResolver]。
* 原则上通过 `postType` 和 `subType` 可以定位唯一一个事件类型。
*
* @see OneBotBotConfiguration.addCustomEventResolver
* @since 1.8.0
*/
@ExperimentalCustomEventResolverApi
public inline fun OneBotBotConfiguration.addCustomKotlinSerializationEventResolver(
postType: String,
subType: String,
crossinline deserializationStrategy: () -> DeserializationStrategy<Event>
) {
addCustomKotlinSerializationEventResolver { context ->
val rawEventResolveResult = context.rawEventResolveResult
if (rawEventResolveResult.postType == postType && rawEventResolveResult.subType == subType) {
deserializationStrategy()
} else {
null
}
}
}
Loading
Loading