diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt index 994b396fc..7c5ef0aa1 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Image.kt @@ -85,6 +85,8 @@ abstract class AbstractImage internal constructor() : Image { * 一般由 [Contact.uploadImage] 得到 */ interface OnlineImage : Image { + companion object Key : Message.Key + /** * 原图下载链接. 包含域名 */ @@ -115,7 +117,9 @@ suspend fun Image.queryUrl(): String { * 一般由 [Contact.uploadImage] 得到 * @see queryOriginUrl */ -interface OfflineImage : Image +interface OfflineImage : Image { + companion object Key : Message.Key +} /** * 原图下载链接. 包含域名 @@ -142,6 +146,8 @@ suspend inline fun OfflineImage.queryOriginUrl(): String = queryUrl() // CustomFace @OptIn(MiraiInternalAPI::class) sealed class GroupImage : AbstractImage() { + companion object Key : Message.Key + abstract val filepath: String abstract val fileId: Int abstract val serverIp: Int @@ -213,6 +219,8 @@ abstract class OnlineGroupImage : GroupImage(), OnlineImage */ // NotOnlineImage @OptIn(MiraiInternalAPI::class) sealed class FriendImage : AbstractImage() { + companion object Key : Message.Key + abstract val resourceId: String abstract val md5: ByteArray abstract val filepath: String diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt index b532bf618..6aad7bbd9 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt @@ -127,6 +127,10 @@ fun MessageChain.firstOrNull(key: Message.Key): M? = when (key) AtAll -> first() PlainText -> first() Image -> first<Image>() + OnlineImage -> first<OnlineImage>() + OfflineImage -> first<OfflineImage>() + GroupImage -> first<GroupImage>() + FriendImage -> first<FriendImage>() Face -> first<Face>() QuoteReply -> first<QuoteReply>() MessageSource -> first<MessageSource>() @@ -360,7 +364,7 @@ fun Message.flatten(): Sequence<SingleMessage> { } fun CombinedMessage.flatten(): Sequence<SingleMessage> { - if (this.isFlat()){ + if (this.isFlat()) { @Suppress("UNCHECKED_CAST") return (this as Iterable<SingleMessage>).asSequence() } else return this.asSequence().flatten()