mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 11:30:16 +08:00
Fix improper receiver use
This commit is contained in:
parent
37416f1401
commit
ee2dcc8584
@ -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?) {
|
||||
|
@ -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
|
||||
|
||||
/**
|
||||
* 添加一个好友
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user