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
584b5e98
Commit
584b5e98
authored
Mar 08, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
xml and Json messages support
parent
21abfe4a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
92 additions
and
35 deletions
+92
-35
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt
...Main/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt
+12
-16
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Json.kt
...rc/commonMain/kotlin/net.mamoe.mirai/message/data/Json.kt
+24
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
...nMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
+6
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt
...onMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt
+29
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt
...src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt
+21
-16
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/messages.kt
View file @
584b5e98
...
...
@@ -273,9 +273,9 @@ internal fun MessageChain.toRichTextElems(forGroup: Boolean): MutableList<ImMsgB
}
this
.
forEach
(
::
transformOneMessage
)
// if(this.any<QuoteReply>())
{
elements
.
add
(
ImMsgBody
.
Elem
(
generalFlags
=
ImMsgBody
.
GeneralFlags
(
pbReserve
=
"78 00 F8 01 00 C8 02
00"
.
hexToBytes
())))
// }
if
(
this
.
any
<
RichMessage
>())
{
elements
.
add
(
ImMsgBody
.
Elem
(
generalFlags
=
ImMsgBody
.
GeneralFlags
(
pbReserve
=
"08 09 78 00 C8 01 00 F0 01 00 F8 01 00 90 02 00 C8 02 00 98 03 00 A0 03 20 B0 03 00 C0 03 00 D0 03 00 E8 03 00 8A 04 02 08 03 90 04 80 80 80 10 B8 04 00 C0 04
00"
.
hexToBytes
())))
}
else
elements
.
add
(
ImMsgBody
.
Elem
(
generalFlags
=
ImMsgBody
.
GeneralFlags
(
pbReserve
=
"78 00 F8 01 00 C8 02 00"
.
hexToBytes
())))
return
elements
}
...
...
@@ -343,6 +343,10 @@ internal class OnlineFriendImageImpl(
internal
fun
MsgComm
.
Msg
.
toMessageChain
():
MessageChain
{
val
elements
=
this
.
msgBody
.
richText
.
elems
if
(
this
.
msgHead
.
fromUin
==
1040400290L
){
println
(
this
.
_miraiContentToString
())
}
return
buildMessageChain
(
elements
.
size
+
1
)
{
+
MessageSourceFromMsg
(
delegate
=
this
@
toMessageChain
)
elements
.
joinToMessageChain
(
this
)
...
...
@@ -405,27 +409,19 @@ internal fun List<ImMsgBody.Elem>.joinToMessageChain(message: MessageChainBuilde
}
}
it
.
richMsg
!=
null
->
{
println
(
this
.
_miraiContentToString
())
val
content
=
MiraiPlatformUtils
.
unzip
(
it
.
richMsg
.
template1
,
1
).
encodeToString
()
when
(
it
.
richMsg
.
serviceId
)
{
60
->
message
.
add
(
XMLMessage
(
content
=
MiraiPlatformUtils
.
unzip
(
it
.
richMsg
.
template1
,
1
).
encodeToString
()
)
)
1
->
message
.
add
(
JsonMessage
(
content
))
60
->
message
.
add
(
XmlMessage
(
content
))
else
->
{
@Suppress
(
"DEPRECATION"
)
MiraiLogger
.
debug
{
"unknown richMsg.serviceId: ${it.richMsg.serviceId}, content=${it.richMsg.template1.contentToString()}, \ntryUnzip=${
kotlin
.
runCatching
{
MiraiPlatformUtils
.
unzip
(
it
.
richMsg
.
template1
,
1
).
encodeToString
()
}.
getOrElse
{
"<failed>"
}
}
"
"unknown richMsg.serviceId: ${it.richMsg.serviceId}, content=${it.richMsg.template1.contentToString()}, \ntryUnzip=${content}"
}
}
}
}
else
->
{
println
(
it
.
_miraiContentToString
())
}
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Json.kt
0 → 100644
View file @
584b5e98
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.message.data
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.SinceMirai
@SinceMirai
(
"0.27.0"
)
@OptIn
(
MiraiExperimentalAPI
::
class
)
class
JsonMessage
(
override
val
content
:
String
)
:
RichMessage
{
companion
object
Key
:
Message
.
Key
<
JsonMessage
>
override
val
serviceId
:
Int
get
()
=
1
override
fun
toString
():
String
=
content
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageChain.kt
View file @
584b5e98
...
...
@@ -61,7 +61,7 @@ interface MessageChain : Message, Iterable<SingleMessage> {
fun
<
M
:
Message
>
getOrNull
(
key
:
Message
.
Key
<
M
>):
M
?
=
firstOrNull
(
key
)
/**
* 遍历每一个有内容的消息, 即 [At], [AtAll], [PlainText], [Image], [Face], [X
ML
Message], [QuoteReply].
* 遍历每一个有内容的消息, 即 [At], [AtAll], [PlainText], [Image], [Face], [X
ml
Message], [QuoteReply].
* 仅供 `Java` 使用
*/
@Suppress
(
"FunctionName"
,
"INAPPLICABLE_JVM_NAME"
)
...
...
@@ -73,7 +73,7 @@ interface MessageChain : Message, Iterable<SingleMessage> {
}
/**
* 遍历每一个消息, 即 [MessageSource] [At], [AtAll], [PlainText], [Image], [Face], [X
ML
Message], [QuoteReply].
* 遍历每一个消息, 即 [MessageSource] [At], [AtAll], [PlainText], [Image], [Face], [X
ml
Message], [QuoteReply].
* 仅供 `Java` 使用
*/
@Suppress
(
"FunctionName"
,
"INAPPLICABLE_JVM_NAME"
)
...
...
@@ -88,7 +88,7 @@ interface MessageChain : Message, Iterable<SingleMessage> {
// region accessors
/**
* 遍历每一个有内容的消息, 即 [At], [AtAll], [PlainText], [Image], [Face], [X
ML
Message], [QuoteReply]
* 遍历每一个有内容的消息, 即 [At], [AtAll], [PlainText], [Image], [Face], [X
ml
Message], [QuoteReply]
*/
@JvmSynthetic
inline
fun
MessageChain
.
foreachContent
(
block
:
(
Message
)
->
Unit
)
{
...
...
@@ -130,6 +130,9 @@ fun <M : Message> MessageChain.firstOrNull(key: Message.Key<M>): M? = when (key)
Face
->
first
<
Face
>()
QuoteReply
->
first
<
QuoteReply
>()
MessageSource
->
first
<
MessageSource
>()
XmlMessage
->
first
<
XmlMessage
>()
JsonMessage
->
first
<
JsonMessage
>()
RichMessage
->
first
<
RichMessage
>()
else
->
null
}
as
M
?
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/RichMessage.kt
0 → 100644
View file @
584b5e98
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.message.data
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.SinceMirai
/**
* XML 消息等富文本消息
*
* @see XmlMessage
*/
@SinceMirai
(
"0.27.0"
)
interface
RichMessage
:
MessageContent
{
companion
object
Key
:
Message
.
Key
<
RichMessage
>
@MiraiExperimentalAPI
val
serviceId
:
Int
@MiraiExperimentalAPI
val
content
:
String
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/XML.kt
View file @
584b5e98
...
...
@@ -15,6 +15,7 @@
package
net.mamoe.mirai.message.data
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
...
...
@@ -23,20 +24,25 @@ import kotlin.jvm.JvmName
*
* @see buildXMLMessage
*/
@MiraiExperimentalAPI
inline
class
XMLMessage
(
val
stringValue
:
String
)
:
Message
,
MessageContent
{
override
fun
followedBy
(
tail
:
Message
):
Nothing
=
error
(
"XMLMessage Message cannot be followed"
)
override
fun
toString
():
String
=
stringValue
@SinceMirai
(
"0.27.0"
)
@OptIn
(
MiraiExperimentalAPI
::
class
)
class
XmlMessage
constructor
(
override
val
content
:
String
)
:
RichMessage
{
companion
object
Key
:
Message
.
Key
<
XmlMessage
>
override
val
serviceId
:
Int
get
()
=
60
override
fun
toString
():
String
=
content
}
/**
* 构造一条 XML 消息
*/
@MiraiExperimentalAPI
(
"还未支持"
)
inline
fun
buildXMLMessage
(
block
:
@XMLDsl
XMLMessageBuilder
.()
->
Unit
):
XMLMessage
=
XMLMessage
(
XMLMessageBuilder
().
apply
(
block
).
text
)
@SinceMirai
(
"0.27.0"
)
@MiraiExperimentalAPI
inline
fun
buildXMLMessage
(
block
:
@XMLDsl
XMLMessageBuilder
.()
->
Unit
):
XmlMessage
=
XmlMessage
(
XMLMessageBuilder
().
apply
(
block
).
text
)
@S
uppress
(
"NOTHING_TO_INLINE
"
)
@S
inceMirai
(
"0.27.0
"
)
@XMLDsl
class
ItemBuilder
(
var
bg
:
Int
=
0
,
...
...
@@ -46,21 +52,20 @@ class ItemBuilder(
internal
val
builder
:
StringBuilder
=
StringBuilder
()
val
text
:
String
get
()
=
"<item bg='$bg' layout='$layout'>$builder</item>"
inline
fun
summary
(
text
:
String
,
color
:
String
=
"#FFFFFF
"
)
{
fun
summary
(
text
:
String
,
color
:
String
=
"#000000
"
)
{
this
.
builder
.
append
(
"<summary color='$color'>$text</summary>"
)
}
inline
fun
title
(
text
:
String
,
size
:
Int
=
18
,
color
:
String
=
"#FFFFFF
"
)
{
fun
title
(
text
:
String
,
size
:
Int
=
25
,
color
:
String
=
"#000000
"
)
{
this
.
builder
.
append
(
"<title size='$size' color='$color'>$text</title>"
)
}
inline
fun
picture
(
coverUrl
:
String
)
{
fun
picture
(
coverUrl
:
String
)
{
this
.
builder
.
append
(
"<picture cover='$coverUrl'/>"
)
}
}
@XMLDsl
@Suppress
(
"NOTHING_TO_INLINE"
)
class
XMLMessageBuilder
(
var
templateId
:
Int
=
1
,
var
serviceId
:
Int
=
1
,
...
...
@@ -70,7 +75,7 @@ class XMLMessageBuilder(
*/
var
actionData
:
String
=
""
,
/**
* 摘要
* 摘要
, 在官方客户端内消息列表中显示
*/
var
brief
:
String
=
""
,
var
flag
:
Int
=
3
,
...
...
@@ -89,11 +94,11 @@ class XMLMessageBuilder(
"</msg>"
@XMLDsl
inline
fun
item
(
block
:
@XMLDsl
ItemBuilder
.()
->
Unit
)
{
fun
item
(
block
:
@XMLDsl
ItemBuilder
.()
->
Unit
)
{
builder
.
append
(
ItemBuilder
().
apply
(
block
).
text
)
}
inline
fun
source
(
name
:
String
,
iconURL
:
String
=
""
)
{
fun
source
(
name
:
String
,
iconURL
:
String
=
""
)
{
sourceName
=
name
sourceIconURL
=
iconURL
}
...
...
@@ -101,4 +106,4 @@ class XMLMessageBuilder(
@Target
(
AnnotationTarget
.
CLASS
,
AnnotationTarget
.
FUNCTION
,
AnnotationTarget
.
TYPE
)
@DslMarker
internal
annotation
class
XMLDsl
\ No newline at end of file
annotation
class
XMLDsl
\ 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