From ca85eb6258fbfc76e78f869f2d3da7c661d0a94c Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 4 Apr 2020 23:31:35 +0800 Subject: [PATCH] Fix Message.Key --- .../kotlin/net.mamoe.mirai/message/data/MessageChain.kt | 9 +++++++++ .../kotlin/net.mamoe.mirai/message/data/MessageSource.kt | 4 ++++ 2 files changed, 13 insertions(+) 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 e48a29af1..bc569a0b2 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 @@ -147,6 +147,15 @@ fun MessageChain.firstOrNull(key: Message.Key): M? = when (key) Face -> firstOrNull() QuoteReply -> firstOrNull() MessageSource -> firstOrNull() + OnlineMessageSource -> firstOrNull() + OfflineMessageSource -> firstOrNull() + OnlineMessageSource.Outgoing -> firstOrNull() + OnlineMessageSource.Outgoing.ToGroup -> firstOrNull() + OnlineMessageSource.Outgoing.ToFriend -> firstOrNull() + OnlineMessageSource.Incoming -> firstOrNull() + OnlineMessageSource.Incoming.FromGroup -> firstOrNull() + OnlineMessageSource.Incoming.FromFriend -> firstOrNull() + OnlineMessageSource -> firstOrNull() XmlMessage -> firstOrNull() JsonMessage -> firstOrNull() RichMessage -> firstOrNull() diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt index dd41fa108..d71178fdd 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt @@ -193,11 +193,13 @@ fun MessageChain.quote(): QuoteReply { return QuoteReply(this.source as? OnlineMessageSource ?: error("only online messages can be quoted")) } +@JvmSynthetic suspend inline fun MessageSource.recall() = bot.recall(this) /** * 撤回这条消息 */ +@JvmSynthetic inline fun MessageSource.recallIn( timeMillis: Long, coroutineContext: CoroutineContext = EmptyCoroutineContext @@ -247,8 +249,10 @@ inline val MessageChain.id: Int inline val MessageChain.source: MessageSource get() = this[MessageSource] +@JvmSynthetic suspend inline fun MessageChain.recall() = this.source.recall() +@JvmSynthetic inline fun MessageChain.recallIn( millis: Long, coroutineContext: CoroutineContext = EmptyCoroutineContext