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
bb6cd9a0
Commit
bb6cd9a0
authored
Dec 04, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
XML Message basics
parent
9ad35592
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
83 additions
and
0 deletions
+83
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/XML.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/message/XML.kt
+83
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/XML.kt
0 → 100644
View file @
bb6cd9a0
package
net.mamoe.mirai.message
/**
* XML 消息, 如分享, 卡片等.
*
* @see buildXMLMessage
*/
inline
class
XMLMessage
(
override
val
stringValue
:
String
)
:
Message
,
SingleOnly
{
override
fun
followedBy
(
tail
:
Message
):
Nothing
=
error
(
"XMLMessage Message cannot be followed"
)
}
/**
* 构造一条 XML 消息
*/
@XMLDsl
inline
fun
buildXMLMessage
(
block
:
@XMLDsl
XMLMessageBuilder
.()
->
Unit
):
XMLMessage
=
XMLMessage
(
XMLMessageBuilder
().
apply
(
block
).
text
)
@Suppress
(
"NOTHING_TO_INLINE"
)
@XMLDsl
class
ItemBuilder
(
var
bg
:
Int
=
0
,
var
layout
:
Int
=
4
)
{
@PublishedApi
internal
val
builder
:
StringBuilder
=
StringBuilder
()
val
text
:
String
get
()
=
"<item bg='$bg' layout='$layout'>$builder</item>"
inline
fun
summary
(
text
:
String
,
color
:
String
=
"#FFFFFF"
)
{
this
.
builder
.
append
(
"<summary color='$color'>$text</summary>"
)
}
inline
fun
title
(
text
:
String
,
size
:
Int
=
18
,
color
:
String
=
"#FFFFFF"
)
{
this
.
builder
.
append
(
"<title size='$size', color='$color'>$text</title>"
)
}
inline
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
,
var
action
:
String
=
"plugin"
,
/**
* 一般为点击这条消息后跳转的链接
*/
var
actionData
:
String
=
""
,
/**
* 摘要
*/
var
brief
:
String
=
""
,
var
flag
:
Int
=
3
,
var
url
:
String
=
""
,
// TODO: 2019/12/3 unknown
var
sourceName
:
String
=
""
,
var
sourceIconURL
:
String
=
""
)
{
@PublishedApi
internal
val
builder
:
StringBuilder
=
StringBuilder
()
val
text
:
String
get
()
=
"<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>"
+
"<msg templateID='$templateId' serviceID='$serviceId' action='$action' actionData='$actionData' brief='$brief' flag='$flag' url='$url'>"
+
builder
.
toString
()
+
"<source name='$sourceName' icon='$sourceIconURL'/>"
+
"</msg>"
@XMLDsl
inline
fun
item
(
block
:
@XMLDsl
ItemBuilder
.()
->
Unit
)
{
builder
.
append
(
ItemBuilder
().
apply
(
block
).
text
)
}
inline
fun
source
(
name
:
String
,
iconURL
:
String
=
""
)
{
sourceName
=
name
sourceIconURL
=
iconURL
}
}
@Target
(
AnnotationTarget
.
CLASS
,
AnnotationTarget
.
FUNCTION
,
AnnotationTarget
.
TYPE
)
@DslMarker
internal
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