mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-31 03:30:08 +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 sourceMessage: MessageChain get() = delegate.toMessageChain()
|
||||||
override val senderId: Long get() = delegate.msgHead.fromUin
|
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 {
|
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(
|
return ImMsgBody.SourceMsg(
|
||||||
origSeqs = listOf(delegate.msgHead.msgSeq),
|
origSeqs = listOf(delegate.msgHead.msgSeq),
|
||||||
@ -78,9 +119,8 @@ internal inline class MessageSourceFromMsg(
|
|||||||
c2cCmd = delegate.msgHead.c2cCmd,
|
c2cCmd = delegate.msgHead.c2cCmd,
|
||||||
msgSeq = delegate.msgHead.msgSeq,
|
msgSeq = delegate.msgHead.msgSeq,
|
||||||
msgTime = delegate.msgHead.msgTime,
|
msgTime = delegate.msgHead.msgTime,
|
||||||
msgUid = messageRandom.toLong() and 0xffFFffFF
|
msgUid = messageRandom.toLong() and 0xffFFffFF, // ok
|
||||||
, // ok
|
groupInfo = MsgComm.GroupInfo(groupCode = groupId),
|
||||||
groupInfo = MsgComm.GroupInfo(groupCode = delegate.msgHead.groupInfo.groupCode),
|
|
||||||
isSrcMsg = true
|
isSrcMsg = true
|
||||||
),
|
),
|
||||||
msgBody = ImMsgBody.MsgBody(
|
msgBody = ImMsgBody.MsgBody(
|
||||||
|
@ -15,7 +15,6 @@ import net.mamoe.mirai.contact.Group
|
|||||||
import net.mamoe.mirai.contact.Member
|
import net.mamoe.mirai.contact.Member
|
||||||
import net.mamoe.mirai.contact.MemberPermission
|
import net.mamoe.mirai.contact.MemberPermission
|
||||||
import net.mamoe.mirai.event.Event
|
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.MessageChain
|
||||||
import net.mamoe.mirai.message.data.MessageSource
|
import net.mamoe.mirai.message.data.MessageSource
|
||||||
import net.mamoe.mirai.recall
|
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.MiraiExperimentalAPI
|
||||||
import net.mamoe.mirai.utils.getValue
|
import net.mamoe.mirai.utils.getValue
|
||||||
import net.mamoe.mirai.utils.unsafeWeakRef
|
import net.mamoe.mirai.utils.unsafeWeakRef
|
||||||
import kotlin.jvm.JvmName
|
|
||||||
|
|
||||||
@Suppress("unused", "NOTHING_TO_INLINE")
|
@Suppress("unused", "NOTHING_TO_INLINE")
|
||||||
class GroupMessage(
|
class GroupMessage(
|
||||||
@ -43,15 +41,6 @@ class GroupMessage(
|
|||||||
|
|
||||||
inline fun Long.member(): Member = group[this]
|
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
|
@MiraiExperimentalAPI
|
||||||
suspend inline fun MessageChain.recall() = bot.recall(this)
|
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(message: Message): MessageReceipt<TSubject> = reply(this.message.quote() + message)
|
||||||
suspend inline fun quoteReply(plain: String): MessageReceipt<TSubject> = reply(this.message.quote() + plain)
|
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]
|
* 引用这个消息. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException]
|
||||||
*/
|
*/
|
||||||
|
@ -37,7 +37,7 @@ class QuoteReply @MiraiInternalAPI constructor(val source: MessageSource) : Mess
|
|||||||
fun MessageChain.quote(sender: QQ): MessageChain {
|
fun MessageChain.quote(sender: QQ): MessageChain {
|
||||||
this.firstOrNull<MessageSource>()?.let {
|
this.firstOrNull<MessageSource>()?.let {
|
||||||
return if (it.groupId == 0L) {
|
return if (it.groupId == 0L) {
|
||||||
QuoteReply(it) + " " // required
|
QuoteReply(it).toChain() // required
|
||||||
} else {
|
} else {
|
||||||
check(sender is Member) { "sender must be Member to quote a GroupMessage" }
|
check(sender is Member) { "sender must be Member to quote a GroupMessage" }
|
||||||
QuoteReply(it) + sender.at() + " " // required
|
QuoteReply(it) + sender.at() + " " // required
|
||||||
|
Loading…
Reference in New Issue
Block a user