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
8b96c072
Commit
8b96c072
authored
Dec 04, 2019
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change to noinline since there is a CompilationException when using crossinline.
parent
b9fdb2e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
20 deletions
+20
-20
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+20
-20
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
8b96c072
...
...
@@ -137,9 +137,9 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* 无任何触发条件.
*/
@MessageDsl
suspend
inline
fun
always
(
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
{
suspend
inline
fun
always
(
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
{
content
({
true
},
onEvent
)
}
}
// TODO: 2019/12/4 这些 onEvent 都应该为 crossinline, 而这会导致一个 CompilationException
/**
* 如果消息内容 `==` [equals], 就执行 [onEvent]
...
...
@@ -151,7 +151,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
equals
:
String
,
trim
:
Boolean
=
true
,
ignoreCase
:
Boolean
=
false
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
{
val
toCheck
=
if
(
trim
)
equals
.
trim
()
else
equals
content
({
toCheck
.
equals
(
if
(
trim
)
it
.
trim
()
else
it
,
ignoreCase
=
ignoreCase
)
},
onEvent
)
...
...
@@ -161,7 +161,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* 如果消息内容包含 [sub], 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
contains
(
sub
:
String
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
sub
in
it
},
onEvent
)
suspend
inline
fun
contains
(
sub
:
String
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
sub
in
it
},
onEvent
)
/**
* 如果消息的前缀是 [prefix], 就执行 [onEvent]
...
...
@@ -170,7 +170,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
suspend
inline
fun
startsWith
(
prefix
:
String
,
removePrefix
:
Boolean
=
true
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
it
.
startsWith
(
prefix
)
})
{
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
stringValue
.
substringAfter
(
prefix
))
...
...
@@ -181,68 +181,68 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* 如果消息的结尾是 [suffix], 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
endsWith
(
suffix
:
String
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
endsWith
(
suffix
:
String
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
it
.
endsWith
(
suffix
)
},
onEvent
)
/**
* 如果是这个人发的消息, 就执行 [onEvent]. 消息可以是好友消息也可以是群消息
*/
@MessageDsl
suspend
inline
fun
sentBy
(
qqId
:
UInt
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
sentBy
(
qqId
:
UInt
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
sender
.
id
==
qqId
},
onEvent
)
/**
* 如果是这个人发的消息, 就执行 [onEvent]. 消息可以是好友消息也可以是群消息
*/
@MessageDsl
suspend
inline
fun
sentBy
(
qqId
:
Long
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
sentBy
(
qqId
.
toUInt
(),
onEvent
)
suspend
inline
fun
sentBy
(
qqId
:
Long
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
sentBy
(
qqId
.
toUInt
(),
onEvent
)
/**
* 如果是管理员或群主发的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
sentByOperator
(
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
sentByOperator
(
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
this
is
GroupMessage
&&
sender
.
permission
.
isOperator
()
},
onEvent
)
/**
* 如果是管理员发的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
sentByAdministrator
(
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
sentByAdministrator
(
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
this
is
GroupMessage
&&
sender
.
permission
.
isAdministrator
()
},
onEvent
)
/**
* 如果是群主发的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
sentByOwner
(
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
sentByOwner
(
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
this
is
GroupMessage
&&
sender
.
permission
.
isOwner
()
},
onEvent
)
/**
* 如果是来自这个群的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
sentFrom
(
id
:
UInt
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
sentFrom
(
id
:
UInt
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
content
({
if
(
this
is
GroupMessage
)
group
.
id
==
id
else
false
},
onEvent
)
/**
* 如果是来自这个群的消息, 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
sentFrom
(
id
:
Long
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
sentFrom
(
id
.
toUInt
(),
onEvent
)
suspend
inline
fun
sentFrom
(
id
:
Long
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
sentFrom
(
id
.
toUInt
(),
onEvent
)
/**
* 如果消息内容包含 [M] 类型的 [Message], 就执行 [onEvent]
*/
@MessageDsl
suspend
inline
fun
<
reified
M
:
Message
>
has
(
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
<
reified
M
:
Message
>
has
(
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
subscriber
{
if
(
message
.
any
<
M
>())
onEvent
(
this
)
}
/**
* 如果 [filter] 返回 `true` 就执行 `onEvent`
*/
@MessageDsl
suspend
inline
fun
content
(
crossinline
filter
:
T
.(
String
)
->
Boolean
,
cross
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
suspend
inline
fun
content
(
noinline
filter
:
T
.(
String
)
->
Boolean
,
no
inline
onEvent
:
@MessageDsl
suspend
T
.(
String
)
->
Unit
)
=
subscriber
{
if
(
this
.
filter
(
message
.
stringValue
))
onEvent
(
this
)
}
/**
...
...
@@ -260,7 +260,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
suspend
inline
infix
fun
String
.
containsReply
(
cross
inline
replier
:
AnyReplier
<
T
>)
=
suspend
inline
infix
fun
String
.
containsReply
(
no
inline
replier
:
AnyReplier
<
T
>)
=
content
({
this
@
containsReply
in
it
})
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false negative warning
executeAndReply
(
replier
)
...
...
@@ -280,7 +280,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他类型则 [Any.toString] 后回复
*/
@MessageDsl
suspend
inline
infix
fun
String
.
startsWithReply
(
cross
inline
replier
:
AnyReplier
<
T
>)
{
suspend
inline
infix
fun
String
.
startsWithReply
(
no
inline
replier
:
AnyReplier
<
T
>)
{
val
toCheck
=
this
.
trimStart
()
content
({
it
.
trimStart
().
startsWith
(
toCheck
)
})
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false negative warning
...
...
@@ -304,7 +304,7 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
* @param replier 若返回 [Message] 则直接发送; 若返回 [Unit] 则不回复; 其他情况则 [Any.toString] 后回复
*/
@MessageDsl
suspend
inline
infix
fun
String
.
endswithReply
(
cross
inline
replier
:
AnyReplier
<
T
>)
{
suspend
inline
infix
fun
String
.
endswithReply
(
no
inline
replier
:
AnyReplier
<
T
>)
{
val
toCheck
=
this
.
trimEnd
()
content
({
it
.
endsWith
(
this
@
endswithReply
)
})
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false negative warning
...
...
@@ -320,14 +320,14 @@ class MessageSubscribersBuilder<T : MessagePacket<*, *>>(
}
@MessageDsl
suspend
inline
infix
fun
String
.
reply
(
cross
inline
replier
:
AnyReplier
<
T
>)
=
case
(
this
)
{
suspend
inline
infix
fun
String
.
reply
(
no
inline
replier
:
AnyReplier
<
T
>)
=
case
(
this
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false negative warning
executeAndReply
(
replier
)
}
@PublishedApi
@Suppress
(
"NOTHING_TO_INLINE"
)
internal
suspend
inline
fun
T
.
executeAndReply
(
cross
inline
replier
:
AnyReplier
<
T
>)
{
internal
suspend
inline
fun
T
.
executeAndReply
(
no
inline
replier
:
AnyReplier
<
T
>)
{
when
(
val
message
=
replier
(
this
))
{
is
Message
->
this
.
reply
(
message
)
is
Unit
->
{
...
...
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