Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
ec30eef2
Commit
ec30eef2
authored
Feb 23, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Powerful QuoteReply
parent
5de27d47
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
24 deletions
+45
-24
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt
...Main/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt
+14
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
...ndroid/network/protocol/packet/chat/receive/MessageSvc.kt
+2
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
...ommonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
+2
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
...mmonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
...monMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
+26
-17
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt
View file @
ec30eef2
...
...
@@ -12,6 +12,7 @@ package net.mamoe.mirai.qqandroid.message
import
kotlinx.io.core.buildPacket
import
kotlinx.io.core.readBytes
import
kotlinx.io.core.readUInt
import
net.mamoe.mirai.contact.Member
import
net.mamoe.mirai.message.data.*
import
net.mamoe.mirai.qqandroid.network.protocol.data.proto.ImMsgBody
import
net.mamoe.mirai.qqandroid.network.protocol.data.proto.MsgComm
...
...
@@ -220,7 +221,8 @@ private val atAllData = ImMsgBody.Elem(
)
)
internal
fun
MessageChain
.
toRichTextElems
():
MutableList
<
ImMsgBody
.
Elem
>
{
@UseExperimental
(
MiraiInternalAPI
::
class
)
internal
fun
MessageChain
.
toRichTextElems
(
forGroup
:
Boolean
):
MutableList
<
ImMsgBody
.
Elem
>
{
val
elements
=
mutableListOf
<
ImMsgBody
.
Elem
>()
if
(
this
.
any
<
QuoteReply
>())
{
...
...
@@ -231,7 +233,8 @@ internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
}
}
this
.
forEach
{
fun
transformOneMessage
(
it
:
Message
)
{
when
(
it
)
{
is
PlainText
->
elements
.
add
(
ImMsgBody
.
Elem
(
text
=
ImMsgBody
.
Text
(
str
=
it
.
stringValue
)))
is
At
->
elements
.
add
(
ImMsgBody
.
Elem
(
text
=
it
.
toJceData
())).
also
{
elements
.
add
(
ImMsgBody
.
Elem
(
text
=
ImMsgBody
.
Text
(
str
=
" "
)))
}
...
...
@@ -241,6 +244,14 @@ internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
is
NotOnlineImageFromFile
->
elements
.
add
(
ImMsgBody
.
Elem
(
notOnlineImage
=
it
.
toJceData
()))
is
AtAll
->
elements
.
add
(
atAllData
)
is
Face
->
elements
.
add
(
ImMsgBody
.
Elem
(
face
=
it
.
toJceData
()))
is
QuoteReplyToSend
->
{
if
(
forGroup
)
{
if
(
it
.
sender
is
Member
)
{
transformOneMessage
(
it
.
createAt
())
}
transformOneMessage
(
" "
.
toMessage
())
}
}
is
QuoteReply
,
is
MessageSource
->
{
...
...
@@ -248,6 +259,7 @@ internal fun MessageChain.toRichTextElems(): MutableList<ImMsgBody.Elem> {
else
->
error
(
"unsupported message type: ${it::class.simpleName}"
)
}
}
this
.
forEach
(
::
transformOneMessage
)
// if(this.any<QuoteReply>()){
elements
.
add
(
ImMsgBody
.
Elem
(
generalFlags
=
ImMsgBody
.
GeneralFlags
(
pbReserve
=
"78 00 F8 01 00 C8 02 00"
.
hexToBytes
())))
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/MessageSvc.kt
View file @
ec30eef2
...
...
@@ -338,7 +338,7 @@ internal class MessageSvc {
contentHead
=
MsgComm
.
ContentHead
(
pkgNum
=
1
),
msgBody
=
ImMsgBody
.
MsgBody
(
richText
=
ImMsgBody
.
RichText
(
elems
=
message
.
toRichTextElems
()
elems
=
message
.
toRichTextElems
(
false
)
)
),
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
...
...
@@ -389,7 +389,7 @@ internal class MessageSvc {
contentHead
=
MsgComm
.
ContentHead
(
pkgNum
=
1
),
msgBody
=
ImMsgBody
.
MsgBody
(
richText
=
ImMsgBody
.
RichText
(
elems
=
message
.
toRichTextElems
()
elems
=
message
.
toRichTextElems
(
true
)
)
),
msgSeq
=
client
.
atomicNextMessageSequenceId
(),
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessagePacket.kt
View file @
ec30eef2
...
...
@@ -124,9 +124,9 @@ abstract class MessagePacketBase<TSender : QQ, TSubject : Contact> : Packet, Bot
suspend
inline
fun
MessageChain
.
quoteReply
():
MessageReceipt
<
TSubject
>
=
quoteReply
(
this
)
/**
* 引用这个消息
. 当且仅当消息为群消息时可用. 否则将会抛出 [IllegalArgumentException]
* 引用这个消息
*/
inline
fun
MessageChain
.
quote
():
MessageChain
=
this
.
quote
(
sender
)
inline
fun
MessageChain
.
quote
():
QuoteReplyToSend
=
this
.
quote
(
sender
)
operator
fun
<
M
:
Message
>
get
(
at
:
Message
.
Key
<
M
>):
M
{
return
this
.
message
[
at
]
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageReceipt.kt
View file @
ec30eef2
...
...
@@ -97,7 +97,7 @@ open class MessageReceipt<C : Contact>(
* @throws IllegalStateException 当此消息不是群消息时
*/
@MiraiExperimentalAPI
(
"unstable"
)
open
fun
quote
():
MessageChain
{
open
fun
quote
():
QuoteReplyToSend
{
val
target
=
target
check
(
target
is
Group
)
{
"quote is only available for GroupMessage"
}
return
this
.
source
.
quote
(
target
.
botAsMember
)
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/QuoteReply.kt
View file @
ec30eef2
...
...
@@ -14,48 +14,57 @@ package net.mamoe.mirai.message.data
import
net.mamoe.mirai.contact.Member
import
net.mamoe.mirai.contact.QQ
import
net.mamoe.mirai.message.MessageReceipt
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
/**
* 群内的引用回复.
* 总是使用 [quote] 来构造实例.
* 群内的或好友的引用回复.
*
* 可以引用一条群消息并发送给一个好友, 或是引用好友消息发送给群.
* 可以引用自己发出的消息. 详见 [MessageReceipt.quote]
*
* 总是使用 [quote] 来构造这个实例.
*/
class
QuoteReply
@MiraiInternalAPI
constructor
(
val
source
:
MessageSource
)
:
Message
{
open
class
QuoteReply
@MiraiInternalAPI
constructor
(
val
source
:
MessageSource
)
:
Message
{
companion
object
Key
:
Message
.
Key
<
QuoteReply
>
override
fun
toString
():
String
=
""
}
/**
* 群内的引用回复.
* 总是使用 [quote] 来构造实例.
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
class
QuoteReplyToSend
@MiraiInternalAPI
constructor
(
source
:
MessageSource
,
val
sender
:
QQ
)
:
QuoteReply
(
source
)
{
fun
createAt
():
At
=
At
(
sender
as
Member
)
}
/**
* 引用这条消息.
* 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
* 好友消息: 返回 `[QuoteReply]`
* 群消息: 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
fun
MessageChain
.
quote
(
sender
:
QQ
):
MessageChain
{
fun
MessageChain
.
quote
(
sender
:
QQ
):
QuoteReplyToSend
{
this
.
firstOrNull
<
MessageSource
>()
?.
let
{
return
if
(
it
.
groupId
==
0L
)
{
QuoteReply
(
it
).
toChain
()
// required
}
else
{
check
(
sender
is
Member
)
{
"sender must be Member to quote a GroupMessage"
}
QuoteReply
(
it
)
+
sender
.
at
()
+
" "
// required
}
return
it
.
quote
(
sender
)
}
error
(
"cannot find MessageSource"
)
}
/**
* 引用这条消息.
* 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
* 好友消息: 返回 `[QuoteReply]`
* 群消息: 返回 `[QuoteReply] + [At] + [PlainText]`(必要的结构)
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
fun
MessageSource
.
quote
(
sender
:
QQ
):
MessageChain
{
return
if
(
this
.
groupId
==
0L
)
{
QuoteReply
(
this
)
+
" "
// required
}
else
{
fun
MessageSource
.
quote
(
sender
:
QQ
):
QuoteReplyToSend
{
if
(
this
.
groupId
!=
0L
)
{
check
(
sender
is
Member
)
{
"sender must be Member to quote a GroupMessage"
}
QuoteReply
(
this
)
+
sender
.
at
()
+
" "
// required
}
return
QuoteReplyToSend
(
this
,
sender
)
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment