mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-08 09:10:11 +08:00
Supports friend message quote reply
This commit is contained in:
parent
17aff7d599
commit
5f141cdb6d
@ -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(
|
||||
|
@ -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<Group> = quoteReply(this)
|
||||
|
||||
@JvmName("reply2")
|
||||
suspend inline fun Message.quoteReply(): MessageReceipt<Group> = quoteReply(this)
|
||||
|
||||
@JvmName("reply2")
|
||||
suspend inline fun MessageChain.quoteReply(): MessageReceipt<Group> = quoteReply(this)
|
||||
|
||||
@MiraiExperimentalAPI
|
||||
suspend inline fun MessageChain.recall() = bot.recall(this)
|
||||
|
||||
|
@ -114,6 +114,15 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
|
||||
suspend inline fun quoteReply(message: Message): MessageReceipt<TSubject> = reply(this.message.quote() + message)
|
||||
suspend inline fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
|
||||
|
||||
@JvmName("reply2")
|
||||
suspend inline fun String.quoteReply(): MessageReceipt<TSubject> = quoteReply(this)
|
||||
|
||||
@JvmName("reply2")
|
||||
suspend inline fun Message.quoteReply(): MessageReceipt<TSubject> = quoteReply(this)
|
||||
|
||||
@JvmName("reply2")
|
||||
suspend inline fun MessageChain.quoteReply(): MessageReceipt<TSubject> = quoteReply(this)
|
||||
|
||||
/**
|
||||
* 引用这个消息. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException]
|
||||
*/
|
||||
|
@ -37,7 +37,7 @@ class QuoteReply @MiraiInternalAPI constructor(val source: MessageSource) : Mess
|
||||
fun MessageChain.quote(sender: QQ): MessageChain {
|
||||
this.firstOrNull<MessageSource>()?.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
|
||||
|
Loading…
Reference in New Issue
Block a user