From 0a2152dc73e4e04fb3aa8461df3e59d0231ae2fe Mon Sep 17 00:00:00 2001 From: Him188 Date: Mon, 13 Apr 2020 18:56:20 +0800 Subject: [PATCH] Add `SingleMessage.asMessageChain` --- mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt | 3 ++- .../kotlin/net.mamoe.mirai/message/data/Message.kt | 2 +- .../kotlin/net.mamoe.mirai/message/data/MessageChain.kt | 6 ++++++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt index 516cc2243..07e1cede9 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt @@ -7,7 +7,8 @@ * https://github.com/mamoe/mirai/blob/master/LICENSE */ -@file:Suppress("EXPERIMENTAL_API_USAGE", "unused", "FunctionName", "NOTHING_TO_INLINE", "UnusedImport") +@file:Suppress("EXPERIMENTAL_API_USAGE", "unused", "FunctionName", "NOTHING_TO_INLINE", "UnusedImport", + "EXPERIMENTAL_OVERRIDE") package net.mamoe.mirai diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt index 54a141dc0..d8df84336 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt @@ -224,7 +224,7 @@ suspend inline fun Message.sendTo(contact: C): MessageReceipt { inline fun Message.repeat(count: Int): MessageChain { if (this is ConstrainSingle<*>) { // fast-path - return SingleMessageChainImpl(this) + return this.asMessageChain() } return buildMessageChain(count) { add(this@repeat) 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 e48671131..561c0d241 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 @@ -234,6 +234,12 @@ fun Message.asMessageChain(): MessageChain = when (this) { else -> SingleMessageChainImpl(this as SingleMessage) } +/** + * 直接将 [this] 委托为一个 [MessageChain] + */ +@JvmSynthetic +fun SingleMessage.asMessageChain(): MessageChain = SingleMessageChainImpl(this) + /** * 直接将 [this] 委托为一个 [MessageChain] */