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
393e5d6c
Commit
393e5d6c
authored
Dec 15, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add regex matching for MessageSubscribersBuilder by @Hoshino_Tented
parent
2bdc6274
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
23 additions
and
0 deletions
+23
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+23
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
393e5d6c
...
@@ -245,6 +245,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
...
@@ -245,6 +245,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
suspend
inline
fun
content
(
noinline
filter
:
T
.(
String
)
->
Boolean
,
noinline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
content
(
noinline
filter
:
T
.(
String
)
->
Boolean
,
noinline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
subscriber
{
if
(
this
.
filter
(
message
.
stringValue
))
onEvent
(
this
)
}
subscriber
{
if
(
this
.
filter
(
message
.
stringValue
))
onEvent
(
this
)
}
/**
* 如果消息内容可由正则表达式匹配, 就执行 `onEvent`
*/
@MessageDsl
suspend
inline
fun
matching
(
regex
:
Regex
,
noinline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
{
content
({
regex
.
matchEntire
(
it
)
!=
null
},
onEvent
)
}
/**
/**
* 若消息内容包含 [this] 则回复 [reply]
* 若消息内容包含 [this] 则回复 [reply]
*/
*/
...
@@ -266,6 +274,21 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
...
@@ -266,6 +274,21 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
executeAndReply
(
replier
)
executeAndReply
(
replier
)
}
}
/**
* 若消息内容可由正则表达式匹配, 则执行 [replier] 并将其返回值回复给发信对象.
*
* [replier] 的 `it` 将会是消息内容 string.
*
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
suspend
inline
fun
Regex
.
matchingReply
(
noinline
replier
:
AnyReplier
<
T
>)
{
content
({
this
@
matchingReply
.
matchEntire
(
it
)
!=
null
}){
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false negative warning
executeAndReply
(
replier
)
}
}
/**
/**
* 不考虑空格, 若消息内容以 [this] 开始则执行 [replier] 并将其返回值回复给发信对象.
* 不考虑空格, 若消息内容以 [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