2
0
Эх сурвалжийг харах

Fix improper receiver use

Him188 6 жил өмнө
parent
commit
ee2dcc8584

+ 6 - 6
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<HttpResponse>(url()).content
+    override suspend fun openChannel(image: Image): ByteReadChannel {
+        return Http.get<HttpResponse>(queryImageUrl(image)).content
     }
 
     override suspend fun approveFriendAddRequest(id: Long, remark: String?) {

+ 2 - 2
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
 
     /**
      * 添加一个好友

+ 2 - 2
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)