Skip to content

Commit 6f1925d

Browse files
committed
v4.0.0-dev13
桥接函数的 Reserve API 部分位置同样调整 baseName; 调整 Spring starter 中部分命名、以及部分修复
1 parent bb3db1a commit 6f1925d

File tree

16 files changed

+90
-38
lines changed

16 files changed

+90
-38
lines changed

.changelog/v4.0.0-dev13.md

Whitespace-only changes.

CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# v4.0.0-dev13
2+
> [!warning]
3+
> 这是一个尚在开发中的**预览版**,它可能不稳定,可能会频繁变更,且没有可用性保证。
4+
5+
6+
> Release & Pull Notes: [v4.0.0-dev13](https://github.com/simple-robot/simpler-robot/releases/tag/v4.0.0-dev13)
7+
8+
19
# v4.0.0-dev12
210
> [!warning]
311
> 这是一个尚在开发中的**预览版**,它可能不稳定,可能会频繁变更,且没有可用性保证。

simbot-api/src/commonMain/kotlin/love/forte/simbot/bot/Bot.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public interface GuildRelation {
183183
*
184184
* 如果实现者不支持也可能始终得到 `null`。
185185
*/
186-
@ST(blockingBaseName = "getGuild", blockingSuffix = "", asyncBaseName = "getGuild")
186+
@ST(blockingBaseName = "getGuild", blockingSuffix = "", asyncBaseName = "getGuild", reserveBaseName = "getGuild")
187187
public suspend fun guild(id: ID): Guild?
188188

189189
/**
@@ -214,7 +214,7 @@ public interface GroupRelation {
214214
*
215215
* 如果实现者不支持也可能始终得到 `null`。
216216
*/
217-
@ST(blockingBaseName = "getGroup", blockingSuffix = "", asyncBaseName = "getGroup")
217+
@ST(blockingBaseName = "getGroup", blockingSuffix = "", asyncBaseName = "getGroup", reserveBaseName = "getGroup")
218218
public suspend fun group(id: ID): ChatGroup?
219219

220220
/**
@@ -247,7 +247,7 @@ public interface ContactRelation {
247247
*
248248
* 如果实现者不支持也可能始终得到 `null`。
249249
*/
250-
@ST(blockingBaseName = "getContact", blockingSuffix = "", asyncBaseName = "getContact")
250+
@ST(blockingBaseName = "getContact", blockingSuffix = "", asyncBaseName = "getContact", reserveBaseName = "getContact")
251251
public suspend fun contact(id: ID): Contact?
252252

253253
/**

simbot-api/src/commonMain/kotlin/love/forte/simbot/component/ComponentFactoryProvider.kt

+5-5
Original file line numberDiff line numberDiff line change
@@ -95,24 +95,24 @@ internal class ProviderComponentFactory<COM : Component, CONF : Any>(
9595
* 添加一个用于获取 [ComponentFactoryProvider] 的函数。
9696
* 这是用于兼容在非 `JVM` 平台下没有 `ServiceLoader` 的方案,
9797
* 在 `JVM` 中应直接使用 `ServiceLoader` 加载 SPI 的方式
98-
* 但是如果强行使用 [addProvider] 添加结果,
98+
* 但是如果强行使用 [addComponentFactoryProvider] 添加结果,
9999
* [loadComponentProviders] 也还是会得到这些结果的。
100100
*/
101-
public fun addProvider(providerCreator: () -> ComponentFactoryProvider<*>) {
101+
public fun addComponentFactoryProvider(providerCreator: () -> ComponentFactoryProvider<*>) {
102102
Services.addProvider<ComponentFactoryProvider<*>>(providerCreator)
103103
}
104104

105105
/**
106-
* 清理所有通过 [addProvider] 添加的 provider 构建器。
106+
* 清理所有通过 [addComponentFactoryProvider] 添加的 provider 构建器。
107107
*/
108-
public fun clearProviders() {
108+
public fun clearComponentFactoryProviders() {
109109
Services.clearProviders<ComponentFactoryProvider<*>>()
110110
}
111111

112112
/**
113113
* 尝试自动加载环境中可获取的所有 [ComponentFactoryProvider] 实例。
114114
* 在 `JVM` 平台下通过 `ServiceLoader` 加载 [ComponentFactoryProvider] 并得到结果,
115-
* 而在其他平台则会得到预先从 [addProvider] 中添加的所有函数构建出来的结果。
115+
* 而在其他平台则会得到预先从 [addComponentFactoryProvider] 中添加的所有函数构建出来的结果。
116116
*
117117
*/
118118
public expect fun loadComponentProviders(): Sequence<ComponentFactoryProvider<*>>

simbot-api/src/commonMain/kotlin/love/forte/simbot/definition/ChatRoom.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public interface Guild : Organization {
9292
* 根据ID获取一个指定的频道。
9393
* 如果找不到则会得到 `null`。
9494
*/
95-
@ST(blockingBaseName = "getChannel", blockingSuffix = "", asyncBaseName = "getChannel")
95+
@ST(blockingBaseName = "getChannel", blockingSuffix = "", asyncBaseName = "getChannel", reserveBaseName = "getChannel")
9696
public suspend fun channel(id: ID): Channel?
9797

9898
/**
@@ -104,7 +104,7 @@ public interface Guild : Organization {
104104
* 根据ID获取一个指定的聊天频道。
105105
* 如果找不到则会得到 `null`。
106106
*/
107-
@ST(blockingBaseName = "getChatChannel", blockingSuffix = "", asyncBaseName = "getChatChannel")
107+
@ST(blockingBaseName = "getChatChannel", blockingSuffix = "", asyncBaseName = "getChatChannel", reserveBaseName = "getChatChannel")
108108
public suspend fun chatChannel(id: ID): ChatChannel?
109109

110110
/**

simbot-api/src/commonMain/kotlin/love/forte/simbot/definition/Organization.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public interface Organization : Actor {
5959
*
6060
* @throws Exception 可能产生任何异常
6161
*/
62-
@ST(blockingBaseName = "getMember", blockingSuffix = "", asyncBaseName = "getMember")
62+
@ST(blockingBaseName = "getMember", blockingSuffix = "", asyncBaseName = "getMember", reserveBaseName = "getMember")
6363
public suspend fun member(id: ID): Member?
6464

6565
/**

simbot-api/src/commonMain/kotlin/love/forte/simbot/plugin/PluginFactoryProvider.kt

+6-6
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ package love.forte.simbot.plugin
2929
import love.forte.simbot.common.function.ConfigurerFunction
3030
import love.forte.simbot.common.function.invokeWith
3131
import love.forte.simbot.common.services.Services
32-
import love.forte.simbot.component.addProvider
32+
import love.forte.simbot.component.addComponentFactoryProvider
3333
import kotlin.jvm.JvmMultifileClass
3434
import kotlin.jvm.JvmName
3535

@@ -93,24 +93,24 @@ public interface PluginFactoryConfigurerProvider<CONF : Any> {
9393
* 添加一个用于获取 [PluginFactoryProvider] 的函数。
9494
* 这是用于兼容在非 `JVM` 平台下没有 `ServiceLoader` 的方案,
9595
* 在 `JVM` 中应直接使用 `ServiceLoader` 加载 SPI 的方式,
96-
* 但是如果使用 [addProvider] 强行添加结果,[loadPluginProviders]
96+
* 但是如果使用 [addComponentFactoryProvider] 强行添加结果,[loadPluginProviders]
9797
* 也还是会得到这些结果的。
9898
*/
99-
public fun addProvider(providerCreator: () -> PluginFactoryProvider<*>) {
99+
public fun addPluginFactoryProvider(providerCreator: () -> PluginFactoryProvider<*>) {
100100
Services.addProvider<PluginFactoryProvider<*>>(providerCreator)
101101
}
102102

103103
/**
104-
* 清理所有通过 [addProvider] 添加的 provider 构建器。
104+
* 清理所有通过 [addComponentFactoryProvider] 添加的 provider 构建器。
105105
*/
106-
public fun clearProviders() {
106+
public fun clearPluginFactoryProviders() {
107107
Services.clearProviders<PluginFactoryProvider<*>>()
108108
}
109109

110110
/**
111111
* 尝试自动加载环境中可获取的所有 [PluginFactoryProvider] 实例。
112112
* 在 `JVM` 平台下通过 `ServiceLoader` 加载 [PluginFactoryProvider] 并得到结果,
113-
* 而在其他平台则会得到预先从 [addProvider] 中添加的所有函数构建出来的结果。
113+
* 而在其他平台则会得到预先从 [addComponentFactoryProvider] 中添加的所有函数构建出来的结果。
114114
*/
115115
public expect fun loadPluginProviders(): Sequence<PluginFactoryProvider<*>>
116116

simbot-api/src/commonTest/kotlin/ComponentFactoryProviderTests.kt

+8-8
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,14 @@ class ComponentFactoryProviderTests {
7777

7878
@Test
7979
fun addAndGet() {
80-
addProvider { FacP() }
81-
addProvider { FacP() }
82-
addProvider { FacP() }
80+
addComponentFactoryProvider { FacP() }
81+
addComponentFactoryProvider { FacP() }
82+
addComponentFactoryProvider { FacP() }
8383

8484
val list = loadComponentProviders().toList()
8585
assertEquals(3, list.size)
8686

87-
clearProviders()
87+
clearComponentFactoryProviders()
8888
}
8989

9090
@Test
@@ -93,25 +93,25 @@ class ComponentFactoryProviderTests {
9393
withContext(Dispatchers.Default) {
9494
launch {
9595
repeat(100) {
96-
addProvider { FacP() }
96+
addComponentFactoryProvider { FacP() }
9797
}
9898
}
9999
launch {
100100
repeat(100) {
101-
addProvider { FacP() }
101+
addComponentFactoryProvider { FacP() }
102102
}
103103
}
104104
launch {
105105
repeat(100) {
106-
addProvider { FacP() }
106+
addComponentFactoryProvider { FacP() }
107107
}
108108
}
109109
}
110110
}
111111

112112
val list = loadComponentProviders().toList()
113113
assertEquals(300, list.size)
114-
clearProviders()
114+
clearComponentFactoryProviders()
115115
}
116116

117117
}

simbot-api/src/jsMain/kotlin/love/forte/simbot/component/ComponentFactoryProvider.js.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package love.forte.simbot.component
2626
import love.forte.simbot.common.services.Services
2727

2828
/**
29-
* 获取通过 [addProvider] 添加的内容的副本序列。
29+
* 获取通过 [addComponentFactoryProvider] 添加的内容的副本序列。
3030
*/
3131
public actual fun loadComponentProviders(): Sequence<ComponentFactoryProvider<*>> =
3232
Services.loadProviders<ComponentFactoryProvider<*>>().map { it() }

simbot-api/src/jsMain/kotlin/love/forte/simbot/plugin/PluginFactoryProvider.js.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
package love.forte.simbot.plugin
2525

2626
import love.forte.simbot.common.services.Services
27-
import love.forte.simbot.component.addProvider
27+
import love.forte.simbot.component.addComponentFactoryProvider
2828

2929
/**
30-
* 加载所有通过 [addProvider] 添加的函数构建出来的 [PluginFactoryProvider] 实例。
30+
* 加载所有通过 [addComponentFactoryProvider] 添加的函数构建出来的 [PluginFactoryProvider] 实例。
3131
*/
3232
public actual fun loadPluginProviders(): Sequence<PluginFactoryProvider<*>> =
3333
Services.loadProviders<PluginFactoryProvider<*>>().map { it() }

simbot-api/src/nativeMain/kotlin/love/forte/simbot/component/ComponentFactoryProvider.native.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ package love.forte.simbot.component
2626
import love.forte.simbot.common.services.Services
2727

2828
/**
29-
* 获取通过 [addProvider] 添加的内容的副本序列。
29+
* 获取通过 [addComponentFactoryProvider] 添加的内容的副本序列。
3030
*/
3131
public actual fun loadComponentProviders(): Sequence<ComponentFactoryProvider<*>> =
3232
Services.loadProviders<ComponentFactoryProvider<*>>().map { it() }

simbot-api/src/nativeMain/kotlin/love/forte/simbot/plugin/PluginFactoryProvider.native.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@
2424
package love.forte.simbot.plugin
2525

2626
import love.forte.simbot.common.services.Services
27-
import love.forte.simbot.component.addProvider
27+
import love.forte.simbot.component.addComponentFactoryProvider
2828

2929
/**
30-
* 加载所有通过 [addProvider] 添加的函数构建出来的 [PluginFactoryProvider] 实例。
30+
* 加载所有通过 [addComponentFactoryProvider] 添加的函数构建出来的 [PluginFactoryProvider] 实例。
3131
*/
3232
public actual fun loadPluginProviders(): Sequence<PluginFactoryProvider<*>> =
3333
Services.loadProviders<PluginFactoryProvider<*>>().map { it() }

simbot-commons/simbot-common-core/src/nativeMain/kotlin/love/forte/simbot/common/services/Services.native.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ internal actual fun <T : Any> loadProvidersInternal(type: KClass<T>): Sequence<(
6161
return synchronized(lock) {
6262
globalProviderCreators[type]?.toList()
6363
?.asSequence()
64-
?.map { provider -> { type.cast(provider) } }
64+
?.map { provider -> { type.cast(provider()) } }
6565
?: emptySequence()
6666
}
6767
}

simbot-cores/simbot-core-spring-boot-starter/src/main/kotlin/love/forte/simbot/spring/EnableSimbot.kt

+42-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,48 @@ import love.forte.simbot.spring.configuration.config.DefaultSimbotApplicationCon
3131
import love.forte.simbot.spring.configuration.listener.SimbotEventListenerFunctionProcessor
3232
import org.springframework.context.annotation.Import
3333

34-
34+
/**
35+
* 启用 simbot 的各项配置。
36+
*
37+
* 将其标记在你的启动类或某个配置类上。
38+
*
39+
* Kotlin
40+
*
41+
* ```kotlin
42+
* @EnableSimbot
43+
* @SpringBootApplication
44+
* open class MyApplication {
45+
* // ...
46+
* }
47+
* ```
48+
*
49+
* ```kotlin
50+
* @EnableSimbot
51+
* @Configuration
52+
* open class MyConfig {
53+
* // ...
54+
* }
55+
* ```
56+
*
57+
* Java
58+
*
59+
* ```java
60+
* @EnableSimbot
61+
* @SpringBootApplication
62+
* public class MyApplication {
63+
* // ...
64+
* }
65+
* ```
66+
*
67+
* ```java
68+
* @EnableSimbot
69+
* @Configuration
70+
* public class MyConfig {
71+
* // ...
72+
* }
73+
* ```
74+
*
75+
*/
3576
@Target(AnnotationTarget.CLASS)
3677
@Import(
3778
SimbotSpringPropertiesConfiguration::class,
@@ -40,7 +81,6 @@ import org.springframework.context.annotation.Import
4081
DefaultSimbotDispatcherProcessorConfiguration::class,
4182
DefaultSimbotComponentInstallProcessorConfiguration::class,
4283
DefaultSimbotPluginInstallProcessorConfiguration::class,
43-
DefaultSimbotSpringApplicationLauncherFactoryConfiguration::class,
4484
DefaultSimbotEventDispatcherProcessorConfiguration::class,
4585
DefaultBinderManagerProvidersConfiguration::class,
4686
// listeners directly
@@ -56,6 +96,5 @@ import org.springframework.context.annotation.Import
5696
// post listeners
5797
SimbotEventListenerFunctionProcessor::class,
5898
SimbotApplicationRunner::class
59-
6099
)
61100
public annotation class EnableSimbot

simbot-cores/simbot-core-spring-boot-starter/src/main/kotlin/love/forte/simbot/spring/configuration/application/DefaultSimbotApplicationProcessor.kt

+7-3
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import love.forte.simbot.spring.common.BotAutoStartOnFailureException
3838
import love.forte.simbot.spring.common.BotConfigResourceLoadOnFailureException
3939
import love.forte.simbot.spring.common.MismatchConfigurableBotManagerException
4040
import love.forte.simbot.spring.common.application.*
41+
import love.forte.simbot.spring.configuration.SimbotEventDispatcherProcessor
4142
import love.forte.simbot.spring.configuration.listener.SimbotEventListenerResolver
4243
import love.forte.simbot.suspendrunner.runInNoScopeBlocking
4344
import org.springframework.beans.factory.annotation.Autowired
@@ -63,13 +64,15 @@ public open class DefaultSimbotSpringApplicationProcessorConfiguration {
6364
properties: SpringApplicationConfigurationProperties,
6465
@Autowired(required = false) eventListenerResolvers: List<SimbotEventListenerResolver>? = null,
6566
@Autowired(required = false) preConfigurer: List<SimbotApplicationPreConfigurer>? = null,
66-
@Autowired(required = false) postConfigurer: List<SimbotApplicationPostConfigurer>? = null
67+
@Autowired(required = false) postConfigurer: List<SimbotApplicationPostConfigurer>? = null,
68+
@Autowired(required = false) eventDispatcherProcessor: SimbotEventDispatcherProcessor,
6769
): DefaultSimbotApplicationProcessor =
6870
DefaultSimbotApplicationProcessor(
6971
properties = properties,
7072
eventListenerResolvers = eventListenerResolvers ?: emptyList(),
7173
preConfigurer = preConfigurer ?: emptyList(),
7274
postConfigurer = postConfigurer ?: emptyList(),
75+
eventDispatcherProcessor
7376
)
7477

7578
public companion object {
@@ -91,7 +94,8 @@ public class DefaultSimbotApplicationProcessor(
9194
private val properties: SpringApplicationConfigurationProperties,
9295
private val eventListenerResolvers: List<SimbotEventListenerResolver>,
9396
private val preConfigurer: List<SimbotApplicationPreConfigurer>,
94-
private val postConfigurer: List<SimbotApplicationPostConfigurer>
97+
private val postConfigurer: List<SimbotApplicationPostConfigurer>,
98+
private val eventDispatcherProcessor: SimbotEventDispatcherProcessor,
9599
) : SimbotApplicationProcessor {
96100
override fun process(application: SpringApplication) {
97101
preConfigurer.forEach {
@@ -114,8 +118,8 @@ public class DefaultSimbotApplicationProcessor(
114118

115119

116120
private fun process0(application: SpringApplication) {
121+
eventDispatcherProcessor.process(application.eventDispatcher)
117122
loadBots(application)
118-
119123
}
120124

121125
private fun loadBots(application: SpringApplication) {

simbot-cores/simbot-core-spring-boot-starter/src/main/kotlin/love/forte/simbot/spring/configuration/listener/SimbotEventListenerFunctionProcessor.kt

+1
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import kotlin.reflect.KFunction
4848

4949
/**
5050
* 用于通过 [Application] 注册 [EventListener] 的函数接口。
51+
* 主要是用于通过 [SimbotEventListenerFunctionProcessor] 生成。
5152
*/
5253
public fun interface SimbotEventListenerResolver {
5354
public fun resolve(application: Application)

0 commit comments

Comments
 (0)