From 3c83883c66a08135f7db8bef520c882d767ed977 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sun, 9 Feb 2020 23:35:11 +0800 Subject: [PATCH] Add space automatically if necessary --- .../kotlin/net.mamoe.mirai/message/MessagePacket.kt | 2 +- .../commonMain/kotlin/net.mamoe.mirai/message/data/At.kt | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt index cbeb4f506..fa0d0f09a 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt @@ -92,7 +92,7 @@ abstract class MessagePacketBase(_bot: Bot) : // region /** - * 引用这个消息. + * 引用这个消息. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException] */ inline fun MessageChain.quote(): MessageChain = this.quote(sender as? Member ?: error("only group message can be quoted")) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt index d2fe95424..4295e4961 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/At.kt @@ -30,6 +30,15 @@ class At @MiraiInternalAPI constructor(val target: Long, val display: String) : override fun eq(other: Message): Boolean { return other is At && other.target == this.target } + + // 自动为消息补充 " " + + override fun followedBy(tail: Message): MessageChain { + if(tail is PlainText && !tail.stringValue.startsWith(' ')){ + return super.followedBy(PlainText(" ")) + tail + } + return super.followedBy(tail) + } } /**