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
dcddcc92
Commit
dcddcc92
authored
Feb 16, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change lambda parameter of `onEvent` for `matching(Regex)` and `finding(Regex)` to `MatchResult`
parent
0e020afe
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
13 deletions
+38
-13
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+38
-13
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
dcddcc92
...
...
@@ -477,26 +477,45 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
}
/**
* 如果消息内容可由正则表达式匹配([Regex.matchEntire])
, 就执行 `onEvent`
* 如果消息内容可由正则表达式匹配([Regex.matchEntire])
*/
@MessageDsl
fun
matching
(
regex
:
Regex
):
ListeningFilter
=
content
{
regex
.
matchEntire
(
it
)
!=
null
}
/**
* 如果
[filter] 返回 `true`
就执行 `onEvent`
* 如果
消息内容可由正则表达式匹配([Regex.matchEntire]),
就执行 `onEvent`
*/
@MessageDsl
inline
fun
matching
(
regex
:
Regex
,
crossinline
onEvent
:
MessageListener
<
T
>):
Listener
<
T
>
=
content
({
regex
.
matchEntire
(
it
)
!=
null
},
onEvent
)
inline
fun
matching
(
regex
:
Regex
,
crossinline
onEvent
:
@MessageDsl
suspend
T
.(
MatchResult
)
->
Unit
):
Listener
<
T
>
=
always
{
val
find
=
regex
.
matchEntire
(
it
)
?:
return
@
always
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
.
executeAndReply
{
onEvent
.
invoke
(
this
,
find
)
}
}
/**
* 如果消息内容可由正则表达式查找([Regex.find])
, 就执行 `onEvent`
* 如果消息内容可由正则表达式查找([Regex.find])
*/
@MessageDsl
fun
finding
(
regex
:
Regex
):
ListeningFilter
=
content
{
regex
.
find
(
it
)
!=
null
}
/**
* 如果消息内容可由正则表达式查找([Regex.find]), 就执行 `onEvent`
*/
@MessageDsl
inline
fun
finding
(
regex
:
Regex
,
crossinline
onEvent
:
@MessageDsl
suspend
T
.(
MatchResult
)
->
Unit
):
Listener
<
T
>
=
always
{
val
find
=
regex
.
find
(
it
)
?:
return
@
always
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
.
executeAndReply
{
onEvent
.
invoke
(
this
,
find
)
}
}
/**
* 若消息内容包含 [this] 则回复 [reply]
...
...
@@ -527,11 +546,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
inline
infix
fun
Regex
.
matchingReply
(
crossinline
replier
:
@MessageDsl
suspend
T
.(
String
)
->
Any
?):
Listener
<
T
>
=
content
({
this
@
matchingReply
.
matchEntire
(
it
)
!=
null
},
{
inline
infix
fun
Regex
.
matchingReply
(
crossinline
replier
:
@MessageDsl
suspend
T
.(
MatchResult
)
->
Any
?):
Listener
<
T
>
=
always
{
val
find
=
this
@
matchingReply
.
matchEntire
(
it
)
?:
return
@
always
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
.
executeAndReply
(
replier
)
})
this
.
executeAndReply
{
replier
.
invoke
(
this
,
find
)
}
}
/**
* 若消息内容可由正则表达式查找([Regex.find]), 则执行 [replier] 并将其返回值回复给发信对象.
...
...
@@ -541,11 +563,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
inline
infix
fun
Regex
.
findingReply
(
crossinline
replier
:
@MessageDsl
suspend
T
.(
String
)
->
Any
?):
Listener
<
T
>
=
content
({
this
@
findingReply
.
find
(
it
)
!=
null
},
{
inline
infix
fun
Regex
.
findingReply
(
crossinline
replier
:
@MessageDsl
suspend
T
.(
MatchResult
)
->
Any
?):
Listener
<
T
>
=
always
{
val
find
=
this
@
findingReply
.
find
(
it
)
?:
return
@
always
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
.
executeAndReply
(
replier
)
})
this
.
executeAndReply
{
replier
.
invoke
(
this
,
find
)
}
}
/**
* 不考虑空格, 若消息内容以 [this] 开始则执行 [replier] 并将其返回值回复给发信对象.
...
...
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