From 05f87761b31959704f72faaf540e397bd0993fea Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 23 Feb 2020 01:29:26 +0800 Subject: [PATCH] Generify --- .../commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt index 06447bf96..79ac12731 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/ExternalImage.kt @@ -16,6 +16,7 @@ import kotlinx.io.core.Input import net.mamoe.mirai.contact.Contact import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.QQ +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.io.toUHexString @@ -115,7 +116,7 @@ class ExternalImage( /** * 将图片发送给指定联系人 */ -suspend fun ExternalImage.sendTo(contact: Contact) = when (contact) { +suspend fun ExternalImage.sendTo(contact: C): MessageReceipt = when (contact) { is Group -> contact.uploadImage(this).sendTo(contact) is QQ -> contact.uploadImage(this).sendTo(contact) else -> error("unreachable") @@ -136,7 +137,7 @@ suspend fun ExternalImage.upload(contact: Contact): Image = when (contact) { /** * 将图片发送给 [this] */ -suspend inline fun Contact.sendImage(image: ExternalImage) = image.sendTo(this) +suspend inline fun C.sendImage(image: ExternalImage): MessageReceipt = image.sendTo(this) private operator fun ByteArray.get(range: IntRange): String = buildString { range.forEach {