@@ -21,7 +21,6 @@ import kotlinx.serialization.descriptors.SerialDescriptor
2121import kotlinx.serialization.encoding.Decoder
2222import kotlinx.serialization.encoding.Encoder
2323import love.forte.simbot.*
24- import love.forte.simbot.application.ApplicationBuilder
2524import love.forte.simbot.application.ApplicationConfiguration
2625import love.forte.simbot.application.EventProviderAutoRegistrarFactory
2726import love.forte.simbot.application.EventProviderFactory
@@ -35,9 +34,7 @@ import love.forte.simbot.component.mirai.internal.InternalApi
3534import love.forte.simbot.component.mirai.internal.MiraiBotManagerImpl
3635import love.forte.simbot.event.EventProcessor
3736import net.mamoe.mirai.Bot
38- import net.mamoe.mirai.BotFactory
3937import net.mamoe.mirai.auth.BotAuthorization
40- import org.jetbrains.annotations.ApiStatus
4138import org.slf4j.Logger
4239import kotlin.coroutines.CoroutineContext
4340import kotlin.coroutines.EmptyCoroutineContext
@@ -75,7 +72,8 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
7572 val authorization = configuration.authorization
7673
7774 if (passwordInfo != null ) {
78- logger.warn("""
75+ logger.warn(
76+ """
7977 The `passwordInfo' configuration property is deprecated, you may want to replace the `passwordInfo' configuration property with `authorization`.
8078 ```json
8179 {
@@ -84,7 +82,8 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
8482 ...
8583 }
8684 ```
87- """ .trimIndent(), configuration.code)
85+ """ .trimIndent(), configuration.code
86+ )
8887 when (passwordInfo) {
8988 is TextPasswordInfoConfiguration -> {
9089 return register(
@@ -115,7 +114,8 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
115114
116115 return register(
117116 code = configuration.code,
118- authorization = authorization?.getBotAuthorization(configuration) ? : throw IllegalArgumentException (" The required attribute 'authorization' is not configured." ),
117+ authorization = authorization?.getBotAuthorization(configuration)
118+ ? : throw IllegalArgumentException (" The required attribute 'authorization' is not configured." ),
119119 configuration = configuration.simbotBotConfiguration
120120 )
121121 }
@@ -295,18 +295,6 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
295295 public companion object Factory : EventProviderFactory<MiraiBotManager, MiraiBotManagerConfiguration> {
296296 override val key: Attribute <MiraiBotManager > = attribute(" SIMBOT.MIRAI" )
297297
298- /* *
299- * @suppress install mirai component and bot manager in application.
300- */
301- @JvmStatic
302- @Suppress(" DeprecatedCallableAddReplaceWith" )
303- @Deprecated(" install mirai in simbotApplication." , level = DeprecationLevel .ERROR )
304- @ApiStatus.ScheduledForRemoval (inVersion = " 3.0.0.0" )
305- public fun newInstance (eventProcessor : EventProcessor ): MiraiBotManager {
306- return MiraiBotManagerImpl (eventProcessor, MiraiComponent (), MiraiBotManagerConfigurationImpl ())
307- }
308-
309-
310298 override suspend fun create (
311299 eventProcessor : EventProcessor ,
312300 components : List <Component >,
@@ -323,9 +311,7 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
323311 configurator(it)
324312 }
325313
326- return MiraiBotManagerImpl (eventProcessor, component, configuration).also {
327- configuration.useBotManager(it)
328- }
314+ return MiraiBotManagerImpl (eventProcessor, component, configuration)
329315 }
330316 }
331317
@@ -351,104 +337,6 @@ public interface MiraiBotManagerConfiguration {
351337 *
352338 */
353339 public var parentCoroutineContext: CoroutineContext
354-
355- /* *
356- * 注册一个mirai bot.
357- *
358- * 从此处注册bot将会早于通过 [ApplicationBuilder.bots] 中进行全局注册的bot被执行。
359- *
360- * @param code 账号
361- * @param password 密码
362- * @param configuration mirai的 bot 注册所需要的配置类。
363- * @param onBot 当bot被注册后执行函数。
364- *
365- * @suppress
366- */
367- @Deprecated(
368- " Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }" ,
369- level = DeprecationLevel .ERROR
370- )
371- @ApiStatus.ScheduledForRemoval (inVersion = " 3.0.0.0" )
372- public fun register (
373- code : Long ,
374- password : String ,
375- configuration : MiraiBotConfiguration ,
376- onBot : suspend (bot: MiraiBot ) -> Unit = {},
377- )
378-
379- /* *
380- * 注册一个mirai bot.
381- *
382- * @param code 账号
383- * @param passwordMd5 密码的md5数据
384- * @param configuration mirai的 bot 注册所需要的配置类。
385- * @param onBot 当bot被注册后执行函数。
386- *
387- * @suppress
388- */
389- @Deprecated(
390- " Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }" ,
391- level = DeprecationLevel .ERROR
392- )
393- @ApiStatus.ScheduledForRemoval (inVersion = " 3.0.0.0" )
394- public fun register (
395- code : Long ,
396- passwordMd5 : ByteArray ,
397- configuration : MiraiBotConfiguration ,
398- onBot : suspend (bot: MiraiBot ) -> Unit = {},
399- )
400-
401- /* *
402- * 注册一个mirai bot.
403- *
404- * 从此处注册bot将会早于通过 [ApplicationBuilder.bots] 中进行全局注册的bot被执行。
405- *
406- * @param code 账号
407- * @param password 密码
408- * @param configuration simbot组件的 bot 注册所需要的配置类。
409- * @param onBot 当bot被注册后执行函数。
410- *
411- * @suppress
412- */
413- @Suppress(" DeprecatedCallableAddReplaceWith" )
414- @Deprecated(
415- " Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }" ,
416- level = DeprecationLevel .ERROR
417- )
418- @ApiStatus.ScheduledForRemoval (inVersion = " 3.0.0.0" )
419- public fun register (
420- code : Long ,
421- password : String ,
422- configuration : BotFactory .BotConfigurationLambda = BotFactory .BotConfigurationLambda {},
423- onBot : suspend (bot: MiraiBot ) -> Unit = {},
424- ) {
425- register(code, password, MiraiBotConfiguration ().botConfiguration(configuration), onBot)
426- }
427-
428- /* *
429- * 注册一个mirai bot.
430- *
431- * @param code 账号
432- * @param passwordMd5 密码的md5数据
433- * @param configuration mirai的 bot 注册所需要的配置类。
434- * @param onBot 当bot被注册后执行函数。
435- *
436- * @suppress
437- */
438- @Suppress(" DeprecatedCallableAddReplaceWith" )
439- @Deprecated(
440- " Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }" ,
441- level = DeprecationLevel .ERROR
442- )
443- @ApiStatus.ScheduledForRemoval (inVersion = " 3.0.0.0" )
444- public fun register (
445- code : Long ,
446- passwordMd5 : ByteArray ,
447- configuration : BotFactory .BotConfigurationLambda = BotFactory .BotConfigurationLambda {},
448- onBot : suspend (bot: MiraiBot ) -> Unit = {},
449- ) {
450- register(code, passwordMd5, MiraiBotConfiguration ().botConfiguration(configuration), onBot)
451- }
452340}
453341
454342
@@ -467,55 +355,8 @@ public class MiraiBotManagerAutoRegistrarFactory :
467355 */
468356private class MiraiBotManagerConfigurationImpl : MiraiBotManagerConfiguration {
469357 override var parentCoroutineContext: CoroutineContext = EmptyCoroutineContext
470-
471- private var botManagerProcessor: (suspend (MiraiBotManager ) -> Unit )? = null
472-
473- private fun newProcessor (p : suspend (MiraiBotManager ) -> Unit ) {
474- botManagerProcessor.also { old ->
475- botManagerProcessor = { manager ->
476- old?.invoke(manager)
477- p(manager)
478- }
479- }
480- }
481-
482- @Suppress(" OVERRIDE_DEPRECATION" , " OverridingDeprecatedMember" )
483- override fun register (
484- code : Long ,
485- password : String ,
486- configuration : MiraiBotConfiguration ,
487- onBot : suspend (bot: MiraiBot ) -> Unit ,
488- ) {
489- newProcessor { manager -> onBot(manager.register(code, password, configuration)) }
490- }
491-
492-
493- @Suppress(" OVERRIDE_DEPRECATION" , " OverridingDeprecatedMember" )
494- override fun register (
495- code : Long ,
496- passwordMd5 : ByteArray ,
497- configuration : MiraiBotConfiguration ,
498- onBot : suspend (bot: MiraiBot ) -> Unit ,
499- ) {
500- newProcessor { manager -> onBot(manager.register(code, passwordMd5, configuration)) }
501- }
502-
503- suspend fun useBotManager (botManager : MiraiBotManager ) {
504- botManagerProcessor?.invoke(botManager)
505- }
506-
507-
508358}
509359
510- /* *
511- * @suppress install mirai component and bot manager in application.
512- */
513- @Suppress(" DeprecatedCallableAddReplaceWith" , " DEPRECATION_ERROR" )
514- @Deprecated(" Use simbotApplication and install MiraiBotManager." , level = DeprecationLevel .ERROR )
515- @ApiStatus.ScheduledForRemoval (inVersion = " 3.0.0.0" )
516- public fun miraiBotManager (eventProcessor : EventProcessor ): MiraiBotManager =
517- MiraiBotManager .newInstance(eventProcessor)
518-
519360
520361/* *
521362 * 枚举名称序列化器。永远转为大写并允许段横杠-。
0 commit comments