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
a49e97d2
Commit
a49e97d2
authored
Nov 16, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add contracts
parent
ae86e67f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
0 deletions
+16
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+16
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
a49e97d2
...
...
@@ -136,6 +136,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*>>(
* @param trim `true` 则删除首尾空格后比较
* @param ignoreCase `true` 则不区分大小写
*/
@MessageDsl
suspend
fun
case
(
equals
:
String
,
trim
:
Boolean
=
true
,
...
...
@@ -147,11 +148,13 @@ class MessageSubscribersBuilder<T : MessagePacket<*>>(
/**
* 如果消息内容包含 [sub], 就执行 [onEvent]
*/
@MessageDsl
suspend
fun
contains
(
sub
:
String
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
sub
in
it
},
onEvent
)
/**
* 如果消息的前缀是 [prefix], 就执行 [onEvent]
*/
@MessageDsl
suspend
fun
startsWith
(
prefix
:
String
,
removePrefix
:
Boolean
=
true
,
...
...
@@ -165,59 +168,72 @@ class MessageSubscribersBuilder<T : MessagePacket<*>>(
/**
* 如果消息的结尾是 [suffix], 就执行 [onEvent]
*/
@MessageDsl
suspend
fun
endsWith
(
suffix
:
String
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
it
.
endsWith
(
suffix
)
},
onEvent
)
/**
* 如果是这个人发的消息, 就执行 [onEvent]. 消息可以是好友消息也可以是群消息
*/
@MessageDsl
suspend
fun
sentBy
(
qqId
:
UInt
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
sender
.
id
==
qqId
},
onEvent
)
/**
* 如果是这个人发的消息, 就执行 [onEvent]. 消息可以是好友消息也可以是群消息
*/
@MessageDsl
suspend
fun
sentBy
(
qqId
:
Long
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
sentBy
(
qqId
.
toUInt
(),
onEvent
)
/**
* 如果是来自这个群的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
fun
sentFrom
(
id
:
UInt
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
if
(
this
is
GroupMessage
)
group
.
id
==
id
else
false
},
onEvent
)
/**
* 如果是来自这个群的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
fun
sentFrom
(
id
:
Long
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
sentFrom
(
id
.
toUInt
(),
onEvent
)
/**
* 如果消息内容包含 [M] 类型的 [Message], 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
<
reified
M
:
Message
>
has
(
noinline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
subscriber
{
if
(
message
.
any
<
M
>())
onEvent
(
this
)
}
/**
* 如果 [filter] 返回 `true` 就执行 `onEvent`
*/
@MessageDsl
suspend
fun
content
(
filter
:
T
.(
String
)
->
Boolean
,
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
subscriber
{
if
(
this
.
filter
(
message
.
stringValue
))
onEvent
(
this
)
}
@MessageDsl
suspend
infix
fun
String
.
containsReply
(
replier
:
String
)
=
content
({
this
@
containsReply
in
it
})
{
this
@
content
.
reply
(
replier
)
}
@MessageDsl
suspend
infix
fun
String
.
containsReply
(
replier
:
StringReplier
<
T
>)
=
content
({
this
@
containsReply
in
it
})
{
replier
(
this
)
}
@MessageDsl
suspend
infix
fun
String
.
startsWithReply
(
replier
:
StringReplier
<
T
>)
=
content
({
it
.
startsWith
(
this
@
startsWithReply
)
})
{
replier
(
this
)
}
@MessageDsl
suspend
infix
fun
String
.
endswithReply
(
replier
:
StringReplier
<
T
>)
=
content
({
it
.
endsWith
(
this
@
endswithReply
)
})
{
replier
(
this
)
}
@MessageDsl
suspend
infix
fun
String
.
reply
(
reply
:
String
)
=
case
(
this
)
{
this
@
case
.
reply
(
reply
)
}
@MessageDsl
suspend
infix
fun
String
.
reply
(
reply
:
StringReplier
<
T
>)
=
case
(
this
)
{
this
@
case
.
reply
(
reply
(
this
))
}
...
...
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