diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt index a5040dc75..5b400fca4 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/QQAndroidBot.kt @@ -151,20 +151,20 @@ internal abstract class QQAndroidBotBase constructor( } } - override suspend fun Image.url(): String = "http://gchat.qpic.cn" + when (this) { - is NotOnlineImageFromServer -> this.delegate.origUrl - is CustomFaceFromServer -> this.delegate.origUrl + override suspend fun queryImageUrl(image: Image): String = "http://gchat.qpic.cn" + when (image) { + is NotOnlineImageFromServer -> image.delegate.origUrl + is CustomFaceFromServer -> image.delegate.origUrl is CustomFaceFromFile -> { TODO() } is NotOnlineImageFromFile -> { TODO() } - else -> error("unsupported image class: ${this::class.simpleName}") + else -> error("unsupported image class: ${image::class.simpleName}") } - override suspend fun Image.channel(): ByteReadChannel { - return Http.get(url()).content + override suspend fun openChannel(image: Image): ByteReadChannel { + return Http.get(queryImageUrl(image)).content } override suspend fun approveFriendAddRequest(id: Long, remark: String?) { diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt index 77e7e1d08..248ac05f1 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -239,7 +239,7 @@ abstract class Bot : CoroutineScope { /** * 获取图片下载链接 */ - abstract suspend fun Image.url(): String + abstract suspend fun queryImageUrl(image: Image): String /** * 获取图片下载链接并开始下载. @@ -247,7 +247,7 @@ abstract class Bot : CoroutineScope { * @see ByteReadChannel.copyAndClose * @see ByteReadChannel.copyTo */ - abstract suspend fun Image.channel(): ByteReadChannel + abstract suspend fun openChannel(image: Image): ByteReadChannel /** * 添加一个好友 diff --git a/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt b/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt index 9bf139816..3d93a3dbd 100644 --- a/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt +++ b/mirai-japt/src/main/kotlin/net/mamoe/mirai/japt/internal/BlockingBotImpl.kt @@ -54,8 +54,8 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot { override fun getGroup(id: Long): BlockingGroup = runBlocking { bot.getGroup(id).blocking() } override fun getNetwork(): BotNetworkHandler = bot.network override fun login() = runBlocking { bot.login() } - override fun downloadTo(image: Image, outputStream: OutputStream) = bot.run { runBlocking { image.channel().copyTo(outputStream) } } - override fun downloadAndClose(image: Image, outputStream: OutputStream) = bot.run { runBlocking { image.channel().copyAndClose(outputStream) } } + override fun downloadTo(image: Image, outputStream: OutputStream) = bot.run { runBlocking { openChannel(image).copyTo(outputStream) } } + override fun downloadAndClose(image: Image, outputStream: OutputStream) = bot.run { runBlocking { openChannel(image).copyAndClose(outputStream) } } override fun addFriend(id: Long, message: String?, remark: String?): AddFriendResult = runBlocking { bot.addFriend(id, message, remark) } override fun approveFriendAddRequest(id: Long, remark: String?) = runBlocking { bot.approveFriendAddRequest(id, remark) } override fun close(throwable: Throwable?) = bot.close(throwable)