Move Contact.sendImage from ExternalResource to Contact

This commit is contained in:
Him188 2020-12-27 20:19:04 +08:00
parent 7fe0eb23b6
commit fc3d880e19
2 changed files with 11 additions and 10 deletions

View File

@ -21,6 +21,7 @@ import net.mamoe.mirai.message.MessageReceipt.Companion.quote
import net.mamoe.mirai.message.MessageReceipt.Companion.recall
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.utils.*
import net.mamoe.mirai.utils.ExternalResource.Companion.sendAsImageTo
import java.io.File
import java.io.InputStream
@ -114,6 +115,16 @@ public interface Contact : ContactOrBot, CoroutineScope {
@JvmStatic
@JvmBlockingBridge
public suspend fun <C : Contact> C.sendImage(file: File): MessageReceipt<C> = file.sendAsImageTo(this)
/**
* 将资源作为单独的图片消息发送给 [this]
*
* @see Contact.sendMessage 最终调用, 发送消息.
*/
@JvmBlockingBridge
@JvmStatic
public suspend inline fun <C : Contact> C.sendImage(resource: ExternalResource): MessageReceipt<C> =
resource.sendAsImageTo(this)
}
}

View File

@ -21,7 +21,6 @@ import net.mamoe.mirai.message.MessageReceipt
import net.mamoe.mirai.message.data.Image
import net.mamoe.mirai.message.data.sendTo
import net.mamoe.mirai.utils.ExternalResource.Companion.sendAsImageTo
import net.mamoe.mirai.utils.ExternalResource.Companion.sendImage
import net.mamoe.mirai.utils.ExternalResource.Companion.toExternalResource
import net.mamoe.mirai.utils.ExternalResource.Companion.uploadAsImage
import java.io.*
@ -171,15 +170,6 @@ public interface ExternalResource : Closeable {
is User -> contact.uploadImage(this)
else -> error("unreachable")
}
/**
* 将图片作为单独的消息发送给 [this]
*
* @see Contact.sendMessage 最终调用, 发送消息.
*/
@JvmSynthetic
public suspend inline fun <C : Contact> C.sendImage(image: ExternalResource): MessageReceipt<C> =
image.sendAsImageTo(this)
}
}