Commit ee2dcc85 authored by Him188's avatar Him188

Fix improper receiver use

parent 37416f14
...@@ -151,20 +151,20 @@ internal abstract class QQAndroidBotBase constructor( ...@@ -151,20 +151,20 @@ internal abstract class QQAndroidBotBase constructor(
} }
} }
override suspend fun Image.url(): String = "http://gchat.qpic.cn" + when (this) { override suspend fun queryImageUrl(image: Image): String = "http://gchat.qpic.cn" + when (image) {
is NotOnlineImageFromServer -> this.delegate.origUrl is NotOnlineImageFromServer -> image.delegate.origUrl
is CustomFaceFromServer -> this.delegate.origUrl is CustomFaceFromServer -> image.delegate.origUrl
is CustomFaceFromFile -> { is CustomFaceFromFile -> {
TODO() TODO()
} }
is NotOnlineImageFromFile -> { is NotOnlineImageFromFile -> {
TODO() TODO()
} }
else -> error("unsupported image class: ${this::class.simpleName}") else -> error("unsupported image class: ${image::class.simpleName}")
} }
override suspend fun Image.channel(): ByteReadChannel { override suspend fun openChannel(image: Image): ByteReadChannel {
return Http.get<HttpResponse>(url()).content return Http.get<HttpResponse>(queryImageUrl(image)).content
} }
override suspend fun approveFriendAddRequest(id: Long, remark: String?) { override suspend fun approveFriendAddRequest(id: Long, remark: String?) {
......
...@@ -239,7 +239,7 @@ abstract class Bot : CoroutineScope { ...@@ -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 { ...@@ -247,7 +247,7 @@ abstract class Bot : CoroutineScope {
* @see ByteReadChannel.copyAndClose * @see ByteReadChannel.copyAndClose
* @see ByteReadChannel.copyTo * @see ByteReadChannel.copyTo
*/ */
abstract suspend fun Image.channel(): ByteReadChannel abstract suspend fun openChannel(image: Image): ByteReadChannel
/** /**
* 添加一个好友 * 添加一个好友
......
...@@ -54,8 +54,8 @@ internal class BlockingBotImpl(private val bot: Bot) : BlockingBot { ...@@ -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 getGroup(id: Long): BlockingGroup = runBlocking { bot.getGroup(id).blocking() }
override fun getNetwork(): BotNetworkHandler = bot.network override fun getNetwork(): BotNetworkHandler = bot.network
override fun login() = runBlocking { bot.login() } override fun login() = runBlocking { bot.login() }
override fun downloadTo(image: Image, outputStream: OutputStream) = bot.run { runBlocking { image.channel().copyTo(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 { image.channel().copyAndClose(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 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 approveFriendAddRequest(id: Long, remark: String?) = runBlocking { bot.approveFriendAddRequest(id, remark) }
override fun close(throwable: Throwable?) = bot.close(throwable) override fun close(throwable: Throwable?) = bot.close(throwable)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment