Skip to content

Commit 2a8c139

Browse files
authored
Merge pull request #148 from simple-robot/dev/clear_deprecated
清理(删除)计划删除的过时API
2 parents d542c4c + 978651d commit 2a8c139

File tree

5 files changed

+36
-328
lines changed

5 files changed

+36
-328
lines changed

simbot-component-mirai-core/src/main/kotlin/love/forte/simbot/component/mirai/SimbotMiraiMessageReceiptImpl.kt

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,14 @@ import love.forte.simbot.CharSequenceID
2222
import love.forte.simbot.ID
2323
import love.forte.simbot.action.DeleteSupport
2424
import love.forte.simbot.action.ReplySupport
25-
import love.forte.simbot.component.mirai.message.MiraiQuoteReply
26-
import love.forte.simbot.component.mirai.message.toOriginalMiraiMessage
2725
import love.forte.simbot.literal
28-
import love.forte.simbot.message.Message
29-
import love.forte.simbot.message.MessageContent
3026
import love.forte.simbot.message.SingleMessageReceipt
3127
import net.mamoe.mirai.contact.Contact
3228
import net.mamoe.mirai.message.MessageSerializers
33-
import net.mamoe.mirai.message.data.*
34-
import org.jetbrains.annotations.ApiStatus
29+
import net.mamoe.mirai.message.data.MessageSource
30+
import net.mamoe.mirai.message.data.MessageSourceBuilder
31+
import net.mamoe.mirai.message.data.MessageSourceKind
32+
import net.mamoe.mirai.message.data.buildMessageSource
3533
import net.mamoe.mirai.message.MessageReceipt as OriginalMiraiMessageReceipt
3634

3735

@@ -64,30 +62,6 @@ public abstract class SimbotMiraiMessageReceipt<out C : Contact> : SingleMessage
6462
*/
6563
public abstract val fullId: ID
6664

67-
/**
68-
* @suppress '回执'并没有 Reply 的语义,将会择期取消对 ReplySupport 的实现。
69-
* 如果希望达到'引用回复'的效果,参考使用 [MiraiQuoteReply].
70-
*/
71-
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
72-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
73-
public abstract suspend fun reply(message: Message): SimbotMiraiMessageReceipt<Contact>
74-
75-
/**
76-
* @suppress '回执'并没有 Reply 的语义,将会择期取消对 ReplySupport 的实现。
77-
* 如果希望达到'引用回复'的效果,参考使用 [MiraiQuoteReply].
78-
*/
79-
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
80-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
81-
public abstract suspend fun reply(text: String): SimbotMiraiMessageReceipt<Contact>
82-
83-
/**
84-
* @suppress '回执'并没有 Reply 的语义,将会择期取消对 ReplySupport 的实现。
85-
* 如果希望达到'引用回复'的效果,参考使用 [MiraiQuoteReply].
86-
*/
87-
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
88-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
89-
public abstract suspend fun reply(message: MessageContent): SimbotMiraiMessageReceipt<Contact>
90-
9165
/**
9266
* 删除/撤回这条消息.
9367
*/
@@ -115,32 +89,6 @@ internal class SimbotMiraiMessageReceiptImpl<out C : Contact>(
11589
receipt.recall()
11690
return true
11791
}
118-
119-
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
120-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
121-
override suspend fun reply(message: Message): SimbotMiraiMessageReceipt<Contact> {
122-
val quote = receipt.quote()
123-
val sendMessage = message.toOriginalMiraiMessage(receipt.target)
124-
val newReceipt = receipt.target.sendMessage(quote + sendMessage)
125-
return SimbotMiraiMessageReceiptImpl(newReceipt)
126-
}
127-
128-
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
129-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
130-
override suspend fun reply(text: String): SimbotMiraiMessageReceipt<Contact> {
131-
val quote = receipt.quote()
132-
val newReceipt = receipt.target.sendMessage(quote + text.toPlainText())
133-
return SimbotMiraiMessageReceiptImpl(newReceipt)
134-
}
135-
136-
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
137-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
138-
override suspend fun reply(message: MessageContent): SimbotMiraiMessageReceipt<Contact> {
139-
val quote = receipt.quote()
140-
val sendMessage = message.messages.toOriginalMiraiMessage(receipt.target)
141-
val newReceipt = receipt.target.sendMessage(quote + sendMessage)
142-
return SimbotMiraiMessageReceiptImpl(newReceipt)
143-
}
14492
}
14593

14694

simbot-component-mirai-core/src/main/kotlin/love/forte/simbot/component/mirai/bot/MiraiBot.kt

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ import love.forte.simbot.bot.*
2121
import love.forte.simbot.component.mirai.*
2222
import love.forte.simbot.component.mirai.message.MiraiImage
2323
import love.forte.simbot.component.mirai.message.MiraiSendOnlyImage
24-
import love.forte.simbot.definition.*
24+
import love.forte.simbot.definition.FriendsContainer
25+
import love.forte.simbot.definition.GroupBot
26+
import love.forte.simbot.definition.Guild
2527
import love.forte.simbot.definition.SocialRelationsContainer.Companion.COUNT_NOT_SUPPORTED
28+
import love.forte.simbot.definition.UserInfo
2629
import love.forte.simbot.message.Image
2730
import love.forte.simbot.resources.Resource
2831
import love.forte.simbot.utils.item.Items
@@ -31,7 +34,6 @@ import net.mamoe.mirai.contact.AvatarSpec
3134
import net.mamoe.mirai.contact.NormalMember
3235
import net.mamoe.mirai.contact.friendgroup.FriendGroups
3336
import net.mamoe.mirai.supervisorJob
34-
import org.jetbrains.annotations.ApiStatus
3537
import kotlin.coroutines.CoroutineContext
3638
import net.mamoe.mirai.Bot as OriginalMiraiBot
3739

@@ -287,26 +289,6 @@ public interface MiraiBot : Bot, UserInfo, FriendsContainer, MiraiUserProfileQue
287289
*/
288290
public fun sendOnlyImage(resource: Resource, flash: Boolean): MiraiSendOnlyImage
289291

290-
/**
291-
* @see sendOnlyImage
292-
* @suppress will be removed.
293-
*/
294-
@JvmSynthetic
295-
@Deprecated("Just use sendOnlyImage(resource, flash)", ReplaceWith("sendOnlyImage(resource, flash)"), level = DeprecationLevel.ERROR)
296-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
297-
public suspend fun uploadImage(resource: Resource, flash: Boolean): MiraiSendOnlyImage =
298-
sendOnlyImage(resource, flash)
299-
300-
/**
301-
* @see sendOnlyImage
302-
* @suppress will be removed.
303-
*/
304-
@Deprecated("Just use sendOnlyImage(resource, flash)", ReplaceWith("sendOnlyImage(resource, flash)"), level = DeprecationLevel.ERROR)
305-
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
306-
public fun uploadImageBlocking(resource: Resource, flash: Boolean): MiraiSendOnlyImage =
307-
sendOnlyImage(resource, flash)
308-
309-
310292
//// id image
311293

312294
/**

simbot-component-mirai-core/src/main/kotlin/love/forte/simbot/component/mirai/bot/MiraiBotManager.kt

Lines changed: 7 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import kotlinx.serialization.descriptors.SerialDescriptor
2121
import kotlinx.serialization.encoding.Decoder
2222
import kotlinx.serialization.encoding.Encoder
2323
import love.forte.simbot.*
24-
import love.forte.simbot.application.ApplicationBuilder
2524
import love.forte.simbot.application.ApplicationConfiguration
2625
import love.forte.simbot.application.EventProviderAutoRegistrarFactory
2726
import love.forte.simbot.application.EventProviderFactory
@@ -35,9 +34,7 @@ import love.forte.simbot.component.mirai.internal.InternalApi
3534
import love.forte.simbot.component.mirai.internal.MiraiBotManagerImpl
3635
import love.forte.simbot.event.EventProcessor
3736
import net.mamoe.mirai.Bot
38-
import net.mamoe.mirai.BotFactory
3937
import net.mamoe.mirai.auth.BotAuthorization
40-
import org.jetbrains.annotations.ApiStatus
4138
import org.slf4j.Logger
4239
import kotlin.coroutines.CoroutineContext
4340
import 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
*/
468356
private 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

Comments
 (0)