diff --git a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt index ac8fa65ee..ac7ffb316 100644 --- a/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt +++ b/mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt @@ -53,11 +53,52 @@ internal inline class MessageSourceFromMsg( // override val sourceMessage: MessageChain get() = delegate.toMessageChain() override val senderId: Long get() = delegate.msgHead.fromUin - override val groupId: Long get() = delegate.msgHead.groupInfo!!.groupCode + override val groupId: Long get() = delegate.msgHead.groupInfo?.groupCode ?: 0 fun toJceData(): ImMsgBody.SourceMsg { + return if (groupId == 0L) { + toJceDataImplForFriend() + } else toJceDataImplForGroup() + } - val groupUin = Group.calculateGroupUinByGroupCode(delegate.msgHead.groupInfo!!.groupCode) + private fun toJceDataImplForFriend(): ImMsgBody.SourceMsg { + return ImMsgBody.SourceMsg( + origSeqs = listOf(delegate.msgHead.msgSeq), + senderUin = delegate.msgHead.fromUin, + toUin = delegate.msgHead.toUin, + flag = 1, + elems = delegate.msgBody.richText.elems, + type = 0, + time = delegate.msgHead.msgTime, + pbReserve = SourceMsg.ResvAttr( + origUids = messageRandom.toLong() and 0xffFFffFF + ).toByteArray(SourceMsg.ResvAttr.serializer()), + srcMsg = MsgComm.Msg( + msgHead = MsgComm.MsgHead( + fromUin = delegate.msgHead.fromUin, // qq + toUin = delegate.msgHead.toUin, // group + msgType = delegate.msgHead.msgType, // 82? + c2cCmd = delegate.msgHead.c2cCmd, + msgSeq = delegate.msgHead.msgSeq, + msgTime = delegate.msgHead.msgTime, + msgUid = messageRandom.toLong() and 0xffFFffFF, // ok + // groupInfo = MsgComm.GroupInfo(groupCode = delegate.msgHead.groupInfo.groupCode), + isSrcMsg = true + ), + msgBody = ImMsgBody.MsgBody( + richText = ImMsgBody.RichText( + elems = delegate.msgBody.richText.elems.also { + if (it.last().elemFlags2 == null) it.add(ImMsgBody.Elem(elemFlags2 = ImMsgBody.ElemFlags2())) + } + ) + ) + ).toByteArray(MsgComm.Msg.serializer()) + ) + } + + private fun toJceDataImplForGroup(): ImMsgBody.SourceMsg { + + val groupUin = Group.calculateGroupUinByGroupCode(groupId) return ImMsgBody.SourceMsg( origSeqs = listOf(delegate.msgHead.msgSeq), @@ -78,9 +119,8 @@ internal inline class MessageSourceFromMsg( c2cCmd = delegate.msgHead.c2cCmd, msgSeq = delegate.msgHead.msgSeq, msgTime = delegate.msgHead.msgTime, - msgUid = messageRandom.toLong() and 0xffFFffFF - , // ok - groupInfo = MsgComm.GroupInfo(groupCode = delegate.msgHead.groupInfo.groupCode), + msgUid = messageRandom.toLong() and 0xffFFffFF, // ok + groupInfo = MsgComm.GroupInfo(groupCode = groupId), isSrcMsg = true ), msgBody = ImMsgBody.MsgBody( diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt index 8a8981f4b..cd9e848ee 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt @@ -15,7 +15,6 @@ import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Member import net.mamoe.mirai.contact.MemberPermission import net.mamoe.mirai.event.Event -import net.mamoe.mirai.message.data.Message import net.mamoe.mirai.message.data.MessageChain import net.mamoe.mirai.message.data.MessageSource import net.mamoe.mirai.recall @@ -23,7 +22,6 @@ import net.mamoe.mirai.recallIn import net.mamoe.mirai.utils.MiraiExperimentalAPI import net.mamoe.mirai.utils.getValue import net.mamoe.mirai.utils.unsafeWeakRef -import kotlin.jvm.JvmName @Suppress("unused", "NOTHING_TO_INLINE") class GroupMessage( @@ -43,15 +41,6 @@ class GroupMessage( inline fun Long.member(): Member = group[this] - @JvmName("reply2") - suspend inline fun String.quoteReply(): MessageReceipt = quoteReply(this) - - @JvmName("reply2") - suspend inline fun Message.quoteReply(): MessageReceipt = quoteReply(this) - - @JvmName("reply2") - suspend inline fun MessageChain.quoteReply(): MessageReceipt = quoteReply(this) - @MiraiExperimentalAPI suspend inline fun MessageChain.recall() = bot.recall(this) 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 99a355364..b0d0ed8de 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 @@ -114,6 +114,15 @@ abstract class MessagePacketBase : Packet, Bot suspend inline fun quoteReply(message: Message): MessageReceipt = reply(this.message.quote() + message) suspend inline fun quoteReply(plain: String): MessageReceipt = reply(this.message.quote() + plain) + @JvmName("reply2") + suspend inline fun String.quoteReply(): MessageReceipt = quoteReply(this) + + @JvmName("reply2") + suspend inline fun Message.quoteReply(): MessageReceipt = quoteReply(this) + + @JvmName("reply2") + suspend inline fun MessageChain.quoteReply(): MessageReceipt = quoteReply(this) + /** * 引用这个消息. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException] */ diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt index c8d08e0eb..aad8047a1 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt @@ -37,7 +37,7 @@ class QuoteReply @MiraiInternalAPI constructor(val source: MessageSource) : Mess fun MessageChain.quote(sender: QQ): MessageChain { this.firstOrNull()?.let { return if (it.groupId == 0L) { - QuoteReply(it) + " " // required + QuoteReply(it).toChain() // required } else { check(sender is Member) { "sender must be Member to quote a GroupMessage" } QuoteReply(it) + sender.at() + " " // required