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
ca212ca7
Commit
ca212ca7
authored
Dec 04, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename the connecting function from concat to followed by
parent
84a9e51c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
13 deletions
+24
-13
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
.../src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
+12
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageChain.kt
...commonMain/kotlin/net.mamoe.mirai/message/MessageChain.kt
+12
-9
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/Message.kt
View file @
ca212ca7
...
...
@@ -93,14 +93,22 @@ interface Message {
* println(c)// "Hello world!"
* ```
*/
fun
concat
(
tail
:
Message
):
MessageChain
=
if
(
tail
is
MessageChain
)
tail
.
concat
(
this
)
/*MessageChainImpl(this).also { tail.forEach { child -> it.concat(child) } }*/
fun
followedBy
(
tail
:
Message
):
MessageChain
{
require
(
tail
!
is
SingleOnly
)
{
"SingleOnly Message cannot follow another message"
}
require
(
this
!
is
SingleOnly
)
{
"SingleOnly Message cannot be followed"
}
return
if
(
tail
is
MessageChain
)
tail
.
followedBy
(
this
)
/*MessageChainImpl(this).also { tail.forEach { child -> it.concat(child) } }*/
else
MessageChainImpl
(
this
,
tail
)
}
operator
fun
plus
(
another
:
Message
):
MessageChain
=
this
.
concat
(
another
)
operator
fun
plus
(
another
:
String
):
MessageChain
=
this
.
concat
(
another
.
toMessage
())
operator
fun
plus
(
another
:
Message
):
MessageChain
=
this
.
followedBy
(
another
)
operator
fun
plus
(
another
:
String
):
MessageChain
=
this
.
followedBy
(
another
.
toMessage
())
}
/**
* 表示这个 [Message] 仅能单个存在, 无法被连接.
*/
interface
SingleOnly
:
Message
/**
* 将 [this] 发送给指定联系人
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/MessageChain.kt
View file @
ca212ca7
...
...
@@ -22,11 +22,11 @@ interface MessageChain : Message, MutableList<Message> {
override
val
stringValue
:
String
override
operator
fun
contains
(
sub
:
String
):
Boolean
override
fun
concat
(
tail
:
Message
):
MessageChain
override
fun
followedBy
(
tail
:
Message
):
MessageChain
// endregion
operator
fun
plusAssign
(
message
:
Message
)
{
this
.
concat
(
message
)
this
.
followedBy
(
message
)
}
operator
fun
plusAssign
(
plain
:
String
)
{
...
...
@@ -162,7 +162,7 @@ fun <M : Message> MessageChain.any(key: Message.Key<M>): Boolean = firstOrNull(k
*
* 它不包含任何元素, 但维护一个 'lazy' 的 [MessageChainImpl].
*
* 只有在必要的时候(如迭代([iterator]), 插入([add]), 连接([
concat
], [plus], [plusAssign]))才会创建这个对象代表的 list
* 只有在必要的时候(如迭代([iterator]), 插入([add]), 连接([
followedBy
], [plus], [plusAssign]))才会创建这个对象代表的 list
*
* 它是一个正常的 [Message] 和 [MessageChain]. 可以做所有 [Message] 能做的事.
*/
...
...
@@ -187,7 +187,7 @@ class EmptyMessageChain : MessageChain {
override
fun
contains
(
sub
:
String
):
Boolean
=
if
(
initialized
)
delegate
.
contains
(
sub
)
else
false
override
fun
contains
(
element
:
Message
):
Boolean
=
if
(
initialized
)
delegate
.
contains
(
element
)
else
false
override
fun
concat
(
tail
:
Message
):
MessageChain
=
delegate
.
concat
(
tail
)
override
fun
followedBy
(
tail
:
Message
):
MessageChain
=
delegate
.
followedBy
(
tail
)
override
val
size
:
Int
=
if
(
initialized
)
delegate
.
size
else
0
override
fun
containsAll
(
elements
:
Collection
<
Message
>):
Boolean
=
...
...
@@ -244,7 +244,7 @@ object NullMessageChain : MessageChain {
override
fun
contains
(
sub
:
String
):
Boolean
=
false
override
fun
contains
(
element
:
Message
):
Boolean
=
false
override
fun
concat
(
tail
:
Message
):
MessageChain
=
override
fun
followedBy
(
tail
:
Message
):
MessageChain
=
MessageChainImpl
(
tail
)
override
val
size
:
Int
=
0
...
...
@@ -297,8 +297,9 @@ internal inline class MessageChainImpl constructor(
override
fun
toString
():
String
=
stringValue
override
operator
fun
contains
(
sub
:
String
):
Boolean
=
delegate
.
any
{
it
.
contains
(
sub
)
}
override
fun
concat
(
tail
:
Message
):
MessageChain
{
if
(
tail
is
MessageChain
)
tail
.
forEach
{
child
->
this
.
concat
(
child
)
}
override
fun
followedBy
(
tail
:
Message
):
MessageChain
{
require
(
tail
!
is
SingleOnly
)
{
"SingleOnly Message cannot follow another message"
}
if
(
tail
is
MessageChain
)
tail
.
forEach
{
child
->
this
.
followedBy
(
child
)
}
else
this
.
delegate
.
add
(
tail
)
return
this
}
...
...
@@ -345,9 +346,11 @@ internal inline class SingleMessageChainImpl(
override
val
stringValue
:
String
get
()
=
this
.
delegate
.
stringValue
override
operator
fun
contains
(
sub
:
String
):
Boolean
=
delegate
.
contains
(
sub
)
override
fun
concat
(
tail
:
Message
):
MessageChain
=
if
(
tail
is
MessageChain
)
tail
.
apply
{
concat
(
delegate
)
}
override
fun
followedBy
(
tail
:
Message
):
MessageChain
{
require
(
tail
!
is
SingleOnly
)
{
"SingleOnly Message cannot follow another message"
}
return
if
(
tail
is
MessageChain
)
tail
.
apply
{
followedBy
(
delegate
)
}
else
MessageChain
(
delegate
,
tail
)
}
override
fun
plusAssign
(
message
:
Message
)
=
throw
UnsupportedOperationException
(
"SingleMessageChainImpl cannot be plusAssigned"
)
...
...
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