Fix improper receiver use

This commit is contained in:
Him188 2020-02-22 23:45:40 +08:00
parent 37416f1401
commit ee2dcc8584
3 changed files with 10 additions and 10 deletions

View File

@ -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?) {

View File

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

View File

@ -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)