Skip to content

Commit

Permalink
Merge pull request #148 from simple-robot/dev/clear_deprecated
Browse files Browse the repository at this point in the history
清理(删除)计划删除的过时API
  • Loading branch information
ForteScarlet authored Jul 11, 2023
2 parents d542c4c + 978651d commit 2a8c139
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 328 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ import love.forte.simbot.CharSequenceID
import love.forte.simbot.ID
import love.forte.simbot.action.DeleteSupport
import love.forte.simbot.action.ReplySupport
import love.forte.simbot.component.mirai.message.MiraiQuoteReply
import love.forte.simbot.component.mirai.message.toOriginalMiraiMessage
import love.forte.simbot.literal
import love.forte.simbot.message.Message
import love.forte.simbot.message.MessageContent
import love.forte.simbot.message.SingleMessageReceipt
import net.mamoe.mirai.contact.Contact
import net.mamoe.mirai.message.MessageSerializers
import net.mamoe.mirai.message.data.*
import org.jetbrains.annotations.ApiStatus
import net.mamoe.mirai.message.data.MessageSource
import net.mamoe.mirai.message.data.MessageSourceBuilder
import net.mamoe.mirai.message.data.MessageSourceKind
import net.mamoe.mirai.message.data.buildMessageSource
import net.mamoe.mirai.message.MessageReceipt as OriginalMiraiMessageReceipt


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

/**
* @suppress '回执'并没有 Reply 的语义,将会择期取消对 ReplySupport 的实现。
* 如果希望达到'引用回复'的效果,参考使用 [MiraiQuoteReply].
*/
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public abstract suspend fun reply(message: Message): SimbotMiraiMessageReceipt<Contact>

/**
* @suppress '回执'并没有 Reply 的语义,将会择期取消对 ReplySupport 的实现。
* 如果希望达到'引用回复'的效果,参考使用 [MiraiQuoteReply].
*/
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public abstract suspend fun reply(text: String): SimbotMiraiMessageReceipt<Contact>

/**
* @suppress '回执'并没有 Reply 的语义,将会择期取消对 ReplySupport 的实现。
* 如果希望达到'引用回复'的效果,参考使用 [MiraiQuoteReply].
*/
@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public abstract suspend fun reply(message: MessageContent): SimbotMiraiMessageReceipt<Contact>

/**
* 删除/撤回这条消息.
*/
Expand Down Expand Up @@ -115,32 +89,6 @@ internal class SimbotMiraiMessageReceiptImpl<out C : Contact>(
receipt.recall()
return true
}

@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
override suspend fun reply(message: Message): SimbotMiraiMessageReceipt<Contact> {
val quote = receipt.quote()
val sendMessage = message.toOriginalMiraiMessage(receipt.target)
val newReceipt = receipt.target.sendMessage(quote + sendMessage)
return SimbotMiraiMessageReceiptImpl(newReceipt)
}

@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
override suspend fun reply(text: String): SimbotMiraiMessageReceipt<Contact> {
val quote = receipt.quote()
val newReceipt = receipt.target.sendMessage(quote + text.toPlainText())
return SimbotMiraiMessageReceiptImpl(newReceipt)
}

@Deprecated("Will remove.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
override suspend fun reply(message: MessageContent): SimbotMiraiMessageReceipt<Contact> {
val quote = receipt.quote()
val sendMessage = message.messages.toOriginalMiraiMessage(receipt.target)
val newReceipt = receipt.target.sendMessage(quote + sendMessage)
return SimbotMiraiMessageReceiptImpl(newReceipt)
}
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ import love.forte.simbot.bot.*
import love.forte.simbot.component.mirai.*
import love.forte.simbot.component.mirai.message.MiraiImage
import love.forte.simbot.component.mirai.message.MiraiSendOnlyImage
import love.forte.simbot.definition.*
import love.forte.simbot.definition.FriendsContainer
import love.forte.simbot.definition.GroupBot
import love.forte.simbot.definition.Guild
import love.forte.simbot.definition.SocialRelationsContainer.Companion.COUNT_NOT_SUPPORTED
import love.forte.simbot.definition.UserInfo
import love.forte.simbot.message.Image
import love.forte.simbot.resources.Resource
import love.forte.simbot.utils.item.Items
Expand All @@ -31,7 +34,6 @@ import net.mamoe.mirai.contact.AvatarSpec
import net.mamoe.mirai.contact.NormalMember
import net.mamoe.mirai.contact.friendgroup.FriendGroups
import net.mamoe.mirai.supervisorJob
import org.jetbrains.annotations.ApiStatus
import kotlin.coroutines.CoroutineContext
import net.mamoe.mirai.Bot as OriginalMiraiBot

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

/**
* @see sendOnlyImage
* @suppress will be removed.
*/
@JvmSynthetic
@Deprecated("Just use sendOnlyImage(resource, flash)", ReplaceWith("sendOnlyImage(resource, flash)"), level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public suspend fun uploadImage(resource: Resource, flash: Boolean): MiraiSendOnlyImage =
sendOnlyImage(resource, flash)

/**
* @see sendOnlyImage
* @suppress will be removed.
*/
@Deprecated("Just use sendOnlyImage(resource, flash)", ReplaceWith("sendOnlyImage(resource, flash)"), level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun uploadImageBlocking(resource: Resource, flash: Boolean): MiraiSendOnlyImage =
sendOnlyImage(resource, flash)


//// id image

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
import love.forte.simbot.*
import love.forte.simbot.application.ApplicationBuilder
import love.forte.simbot.application.ApplicationConfiguration
import love.forte.simbot.application.EventProviderAutoRegistrarFactory
import love.forte.simbot.application.EventProviderFactory
Expand All @@ -35,9 +34,7 @@ import love.forte.simbot.component.mirai.internal.InternalApi
import love.forte.simbot.component.mirai.internal.MiraiBotManagerImpl
import love.forte.simbot.event.EventProcessor
import net.mamoe.mirai.Bot
import net.mamoe.mirai.BotFactory
import net.mamoe.mirai.auth.BotAuthorization
import org.jetbrains.annotations.ApiStatus
import org.slf4j.Logger
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
Expand Down Expand Up @@ -75,7 +72,8 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
val authorization = configuration.authorization

if (passwordInfo != null) {
logger.warn("""
logger.warn(
"""
The `passwordInfo' configuration property is deprecated, you may want to replace the `passwordInfo' configuration property with `authorization`.
```json
{
Expand All @@ -84,7 +82,8 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
...
}
```
""".trimIndent(), configuration.code)
""".trimIndent(), configuration.code
)
when (passwordInfo) {
is TextPasswordInfoConfiguration -> {
return register(
Expand Down Expand Up @@ -115,7 +114,8 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {

return register(
code = configuration.code,
authorization = authorization?.getBotAuthorization(configuration) ?: throw IllegalArgumentException("The required attribute 'authorization' is not configured."),
authorization = authorization?.getBotAuthorization(configuration)
?: throw IllegalArgumentException("The required attribute 'authorization' is not configured."),
configuration = configuration.simbotBotConfiguration
)
}
Expand Down Expand Up @@ -295,18 +295,6 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
public companion object Factory : EventProviderFactory<MiraiBotManager, MiraiBotManagerConfiguration> {
override val key: Attribute<MiraiBotManager> = attribute("SIMBOT.MIRAI")

/**
* @suppress install mirai component and bot manager in application.
*/
@JvmStatic
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated("install mirai in simbotApplication.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun newInstance(eventProcessor: EventProcessor): MiraiBotManager {
return MiraiBotManagerImpl(eventProcessor, MiraiComponent(), MiraiBotManagerConfigurationImpl())
}


override suspend fun create(
eventProcessor: EventProcessor,
components: List<Component>,
Expand All @@ -323,9 +311,7 @@ public abstract class MiraiBotManager : BotManager<MiraiBot>() {
configurator(it)
}

return MiraiBotManagerImpl(eventProcessor, component, configuration).also {
configuration.useBotManager(it)
}
return MiraiBotManagerImpl(eventProcessor, component, configuration)
}
}

Expand All @@ -351,104 +337,6 @@ public interface MiraiBotManagerConfiguration {
*
*/
public var parentCoroutineContext: CoroutineContext

/**
* 注册一个mirai bot.
*
* 从此处注册bot将会早于通过 [ApplicationBuilder.bots] 中进行全局注册的bot被执行。
*
* @param code 账号
* @param password 密码
* @param configuration mirai的 bot 注册所需要的配置类。
* @param onBot 当bot被注册后执行函数。
*
* @suppress
*/
@Deprecated(
"Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }",
level = DeprecationLevel.ERROR
)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun register(
code: Long,
password: String,
configuration: MiraiBotConfiguration,
onBot: suspend (bot: MiraiBot) -> Unit = {},
)

/**
* 注册一个mirai bot.
*
* @param code 账号
* @param passwordMd5 密码的md5数据
* @param configuration mirai的 bot 注册所需要的配置类。
* @param onBot 当bot被注册后执行函数。
*
* @suppress
*/
@Deprecated(
"Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }",
level = DeprecationLevel.ERROR
)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun register(
code: Long,
passwordMd5: ByteArray,
configuration: MiraiBotConfiguration,
onBot: suspend (bot: MiraiBot) -> Unit = {},
)

/**
* 注册一个mirai bot.
*
* 从此处注册bot将会早于通过 [ApplicationBuilder.bots] 中进行全局注册的bot被执行。
*
* @param code 账号
* @param password 密码
* @param configuration simbot组件的 bot 注册所需要的配置类。
* @param onBot 当bot被注册后执行函数。
*
* @suppress
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
"Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }",
level = DeprecationLevel.ERROR
)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun register(
code: Long,
password: String,
configuration: BotFactory.BotConfigurationLambda = BotFactory.BotConfigurationLambda {},
onBot: suspend (bot: MiraiBot) -> Unit = {},
) {
register(code, password, MiraiBotConfiguration().botConfiguration(configuration), onBot)
}

/**
* 注册一个mirai bot.
*
* @param code 账号
* @param passwordMd5 密码的md5数据
* @param configuration mirai的 bot 注册所需要的配置类。
* @param onBot 当bot被注册后执行函数。
*
* @suppress
*/
@Suppress("DeprecatedCallableAddReplaceWith")
@Deprecated(
"Use ApplicationBuilder.miraiBots { ... } or BotRegistrar.mirai { ... }",
level = DeprecationLevel.ERROR
)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun register(
code: Long,
passwordMd5: ByteArray,
configuration: BotFactory.BotConfigurationLambda = BotFactory.BotConfigurationLambda {},
onBot: suspend (bot: MiraiBot) -> Unit = {},
) {
register(code, passwordMd5, MiraiBotConfiguration().botConfiguration(configuration), onBot)
}
}


Expand All @@ -467,55 +355,8 @@ public class MiraiBotManagerAutoRegistrarFactory :
*/
private class MiraiBotManagerConfigurationImpl : MiraiBotManagerConfiguration {
override var parentCoroutineContext: CoroutineContext = EmptyCoroutineContext

private var botManagerProcessor: (suspend (MiraiBotManager) -> Unit)? = null

private fun newProcessor(p: suspend (MiraiBotManager) -> Unit) {
botManagerProcessor.also { old ->
botManagerProcessor = { manager ->
old?.invoke(manager)
p(manager)
}
}
}

@Suppress("OVERRIDE_DEPRECATION", "OverridingDeprecatedMember")
override fun register(
code: Long,
password: String,
configuration: MiraiBotConfiguration,
onBot: suspend (bot: MiraiBot) -> Unit,
) {
newProcessor { manager -> onBot(manager.register(code, password, configuration)) }
}


@Suppress("OVERRIDE_DEPRECATION", "OverridingDeprecatedMember")
override fun register(
code: Long,
passwordMd5: ByteArray,
configuration: MiraiBotConfiguration,
onBot: suspend (bot: MiraiBot) -> Unit,
) {
newProcessor { manager -> onBot(manager.register(code, passwordMd5, configuration)) }
}

suspend fun useBotManager(botManager: MiraiBotManager) {
botManagerProcessor?.invoke(botManager)
}


}

/**
* @suppress install mirai component and bot manager in application.
*/
@Suppress("DeprecatedCallableAddReplaceWith", "DEPRECATION_ERROR")
@Deprecated("Use simbotApplication and install MiraiBotManager.", level = DeprecationLevel.ERROR)
@ApiStatus.ScheduledForRemoval(inVersion = "3.0.0.0")
public fun miraiBotManager(eventProcessor: EventProcessor): MiraiBotManager =
MiraiBotManager.newInstance(eventProcessor)


/**
* 枚举名称序列化器。永远转为大写并允许段横杠-。
Expand Down
Loading

0 comments on commit 2a8c139

Please sign in to comment.