From 275d9f8f6e95237206be5241e5a65e11b3156859 Mon Sep 17 00:00:00 2001 From: Karlatemp Date: Sun, 19 Feb 2023 22:39:46 +0800 Subject: [PATCH] [core] Fix replying unavailable member's message --- .../protocol/impl/QuoteReplyProtocol.kt | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt b/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt index ec516245f..ad4eda88e 100644 --- a/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt +++ b/mirai-core/src/commonMain/kotlin/message/protocol/impl/QuoteReplyProtocol.kt @@ -157,17 +157,27 @@ internal class QuoteReplyProtocol : MessageProtocol(PRIORITY_METADATA) { markAsConsumed() collect(ImMsgBody.Elem(srcMsg = source.toJceData())) if (sourceCommon.kind == MessageSourceKind.GROUP) { - if (source is OnlineMessageSource.Incoming.FromGroup) { - val sender0 = source.sender - if (sender0 !is AnonymousMember) { - processAlso(At(sender0)) + + @Suppress("RemoveExplicitTypeArguments") + val needPlusAt = sequence { + if (source is OnlineMessageSource.Incoming.FromGroup) { + try { + val sender0 = source.sender + yield(sender0 !is AnonymousMember) + } catch (_: IllegalStateException) { + // Member not available now + } } + + yield(sourceCommon.fromId != 80000000L) + } + + if (needPlusAt.first()) { + processAlso(At(sourceCommon.fromId)) + // transformOneMessage(PlainText(" ")) // removed by https://github.com/mamoe/mirai/issues/524 // 发送 QuoteReply 消息时无可避免的产生多余空格 #524 - } else if (sourceCommon.fromId != 80000000L) { - // https://github.com/mamoe/mirai/issues/2501 OfflineMessageSource quote replying - processAlso(At(sourceCommon.fromId)) } } }