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
eb0696be
Commit
eb0696be
authored
Apr 05, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adapt for new `Message.contentToString`
parent
7e6badb8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
25 deletions
+25
-25
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
...monMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
+25
-25
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
View file @
eb0696be
...
@@ -57,8 +57,8 @@ fun <R> CoroutineScope.subscribeMessages(
...
@@ -57,8 +57,8 @@ fun <R> CoroutineScope.subscribeMessages(
// subscribeAlways 即注册一个监听器. 这个监听器收到消息后就传递给 [messageListener]
// subscribeAlways 即注册一个监听器. 这个监听器收到消息后就传递给 [messageListener]
// messageListener 即为 DSL 里 `contains(...) { }`, `startsWith(...) { }` 的代码块.
// messageListener 即为 DSL 里 `contains(...) { }`, `startsWith(...) { }` 的代码块.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
// this.message.
t
oString() 即为 messageListener 中 it 接收到的值
// this.message.
contentT
oString() 即为 messageListener 中 it 接收到的值
val
toString
=
this
.
message
.
t
oString
()
val
toString
=
this
.
message
.
contentT
oString
()
if
(
filter
.
invoke
(
this
,
toString
))
if
(
filter
.
invoke
(
this
,
toString
))
messageListener
.
invoke
(
this
,
toString
)
messageListener
.
invoke
(
this
,
toString
)
}
}
...
@@ -83,7 +83,7 @@ fun <R> CoroutineScope.subscribeGroupMessages(
...
@@ -83,7 +83,7 @@ fun <R> CoroutineScope.subscribeGroupMessages(
}
}
return
GroupMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
return
GroupMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
val
toString
=
this
.
message
.
t
oString
()
val
toString
=
this
.
message
.
contentT
oString
()
if
(
filter
(
this
,
toString
))
if
(
filter
(
this
,
toString
))
listener
(
this
,
toString
)
listener
(
this
,
toString
)
}
}
...
@@ -108,7 +108,7 @@ fun <R> CoroutineScope.subscribeFriendMessages(
...
@@ -108,7 +108,7 @@ fun <R> CoroutineScope.subscribeFriendMessages(
}
}
return
FriendMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
return
FriendMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
val
toString
=
this
.
message
.
t
oString
()
val
toString
=
this
.
message
.
contentT
oString
()
if
(
filter
(
this
,
toString
))
if
(
filter
(
this
,
toString
))
listener
(
this
,
toString
)
listener
(
this
,
toString
)
}
}
...
@@ -131,7 +131,7 @@ fun <R> Bot.subscribeMessages(
...
@@ -131,7 +131,7 @@ fun <R> Bot.subscribeMessages(
}
}
return
MessagePacketSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
return
MessagePacketSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
this
.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
this
.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
val
toString
=
this
.
message
.
t
oString
()
val
toString
=
this
.
message
.
contentT
oString
()
if
(
filter
(
this
,
toString
))
if
(
filter
(
this
,
toString
))
listener
(
this
,
toString
)
listener
(
this
,
toString
)
}
}
...
@@ -156,7 +156,7 @@ fun <R> Bot.subscribeGroupMessages(
...
@@ -156,7 +156,7 @@ fun <R> Bot.subscribeGroupMessages(
}
}
return
GroupMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
return
GroupMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
this
.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
this
.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
val
toString
=
this
.
message
.
t
oString
()
val
toString
=
this
.
message
.
contentT
oString
()
if
(
filter
(
this
,
toString
))
if
(
filter
(
this
,
toString
))
listener
(
this
,
toString
)
listener
(
this
,
toString
)
}
}
...
@@ -179,7 +179,7 @@ fun <R> Bot.subscribeFriendMessages(
...
@@ -179,7 +179,7 @@ fun <R> Bot.subscribeFriendMessages(
}
}
return
FriendMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
return
FriendMessageSubscribersBuilder
(
Unit
)
{
filter
,
listener
->
this
.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
this
.
subscribeAlways
(
coroutineContext
,
concurrencyKind
)
{
val
toString
=
this
.
message
.
t
oString
()
val
toString
=
this
.
message
.
contentT
oString
()
if
(
filter
(
this
,
toString
))
if
(
filter
(
this
,
toString
))
listener
(
this
,
toString
)
listener
(
this
,
toString
)
}
}
...
@@ -420,7 +420,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -420,7 +420,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
):
Ret
{
):
Ret
{
val
toCheck
=
if
(
trim
)
equals
.
trim
()
else
equals
val
toCheck
=
if
(
trim
)
equals
.
trim
()
else
equals
return
content
({
(
if
(
trim
)
it
.
trim
()
else
it
).
equals
(
toCheck
,
ignoreCase
=
ignoreCase
)
},
{
return
content
({
(
if
(
trim
)
it
.
trim
()
else
it
).
equals
(
toCheck
,
ignoreCase
=
ignoreCase
)
},
{
onEvent
(
this
,
this
.
message
.
t
oString
())
onEvent
(
this
,
this
.
message
.
contentT
oString
())
})
})
}
}
...
@@ -444,11 +444,11 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -444,11 +444,11 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
return
if
(
trim
)
{
return
if
(
trim
)
{
val
toCheck
=
sub
.
trim
()
val
toCheck
=
sub
.
trim
()
content
({
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
},
{
content
({
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
},
{
onEvent
(
this
,
this
.
message
.
t
oString
().
trim
())
onEvent
(
this
,
this
.
message
.
contentT
oString
().
trim
())
})
})
}
else
{
}
else
{
content
({
it
.
contains
(
sub
,
ignoreCase
=
ignoreCase
)
},
{
content
({
it
.
contains
(
sub
,
ignoreCase
=
ignoreCase
)
},
{
onEvent
(
this
,
this
.
message
.
t
oString
())
onEvent
(
this
,
this
.
message
.
contentT
oString
())
})
})
}
}
}
}
...
@@ -475,13 +475,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -475,13 +475,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
content
({
content
({
list
.
any
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
list
.
any
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
},
{
},
{
onEvent
(
this
,
this
.
message
.
t
oString
().
trim
())
onEvent
(
this
,
this
.
message
.
contentT
oString
().
trim
())
})
})
}
else
{
}
else
{
content
({
content
({
sub
.
any
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
sub
.
any
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
},
{
},
{
onEvent
(
this
,
this
.
message
.
t
oString
())
onEvent
(
this
,
this
.
message
.
contentT
oString
())
})
})
}
}
}
}
...
@@ -508,13 +508,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -508,13 +508,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
content
({
content
({
list
.
all
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
list
.
all
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
},
{
},
{
onEvent
(
this
,
this
.
message
.
t
oString
().
trim
())
onEvent
(
this
,
this
.
message
.
contentT
oString
().
trim
())
})
})
}
else
{
}
else
{
content
({
content
({
sub
.
all
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
sub
.
all
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
},
{
},
{
onEvent
(
this
,
this
.
message
.
t
oString
())
onEvent
(
this
,
this
.
message
.
contentT
oString
())
})
})
}
}
}
}
...
@@ -544,13 +544,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -544,13 +544,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
return
if
(
trim
)
{
return
if
(
trim
)
{
val
toCheck
=
prefix
.
trim
()
val
toCheck
=
prefix
.
trim
()
content
({
it
.
trimStart
().
startsWith
(
toCheck
)
},
{
content
({
it
.
trimStart
().
startsWith
(
toCheck
)
},
{
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
t
oString
().
substringAfter
(
toCheck
).
trim
())
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
contentT
oString
().
substringAfter
(
toCheck
).
trim
())
else
onEvent
(
this
,
this
.
message
.
t
oString
().
trim
())
else
onEvent
(
this
,
this
.
message
.
contentT
oString
().
trim
())
})
})
}
else
{
}
else
{
content
({
it
.
startsWith
(
prefix
)
},
{
content
({
it
.
startsWith
(
prefix
)
},
{
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
t
oString
().
removePrefix
(
prefix
))
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
contentT
oString
().
removePrefix
(
prefix
))
else
onEvent
(
this
,
this
.
message
.
t
oString
())
else
onEvent
(
this
,
this
.
message
.
contentT
oString
())
})
})
}
}
}
}
...
@@ -575,13 +575,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -575,13 +575,13 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
return
if
(
trim
)
{
return
if
(
trim
)
{
val
toCheck
=
suffix
.
trim
()
val
toCheck
=
suffix
.
trim
()
content
({
it
.
trimEnd
().
endsWith
(
toCheck
)
},
{
content
({
it
.
trimEnd
().
endsWith
(
toCheck
)
},
{
if
(
removeSuffix
)
this
.
onEvent
(
this
.
message
.
t
oString
().
removeSuffix
(
toCheck
).
trim
())
if
(
removeSuffix
)
this
.
onEvent
(
this
.
message
.
contentT
oString
().
removeSuffix
(
toCheck
).
trim
())
else
onEvent
(
this
,
this
.
message
.
t
oString
().
trim
())
else
onEvent
(
this
,
this
.
message
.
contentT
oString
().
trim
())
})
})
}
else
{
}
else
{
content
({
it
.
endsWith
(
suffix
)
},
{
content
({
it
.
endsWith
(
suffix
)
},
{
if
(
removeSuffix
)
this
.
onEvent
(
this
.
message
.
t
oString
().
removeSuffix
(
suffix
))
if
(
removeSuffix
)
this
.
onEvent
(
this
.
message
.
contentT
oString
().
removeSuffix
(
suffix
))
else
onEvent
(
this
,
this
.
message
.
t
oString
())
else
onEvent
(
this
,
this
.
message
.
contentT
oString
())
})
})
}
}
}
}
...
@@ -713,7 +713,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -713,7 +713,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
):
Ret
=
always
{
):
Ret
=
always
{
onEvent
.
invoke
(
onEvent
.
invoke
(
this
,
this
,
mapper
.
invoke
(
this
,
message
.
t
oString
())
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
mapper
.
invoke
(
this
,
message
.
contentT
oString
())
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
)
)
}
}
...
@@ -898,7 +898,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -898,7 +898,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
@PublishedApi
@PublishedApi
@Suppress
(
"REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE"
,
"UNCHECKED_CAST"
)
// false positive
@Suppress
(
"REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE"
,
"UNCHECKED_CAST"
)
// false positive
internal
suspend
inline
fun
executeAndReply
(
m
:
M
,
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
internal
suspend
inline
fun
executeAndReply
(
m
:
M
,
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
when
(
val
message
=
replier
(
m
,
m
.
message
.
t
oString
()))
{
when
(
val
message
=
replier
(
m
,
m
.
message
.
contentT
oString
()))
{
is
Message
->
m
.
reply
(
message
)
is
Message
->
m
.
reply
(
message
)
is
Unit
->
{
is
Unit
->
{
...
@@ -911,7 +911,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
...
@@ -911,7 +911,7 @@ open class MessageSubscribersBuilder<M : ContactMessage, out Ret, R : RR, RR>(
@PublishedApi
@PublishedApi
@Suppress
(
"REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE"
,
"UNCHECKED_CAST"
)
// false positive
@Suppress
(
"REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE"
,
"UNCHECKED_CAST"
)
// false positive
internal
suspend
inline
fun
executeAndQuoteReply
(
m
:
M
,
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
internal
suspend
inline
fun
executeAndQuoteReply
(
m
:
M
,
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
when
(
val
message
=
replier
(
m
,
m
.
message
.
t
oString
()))
{
when
(
val
message
=
replier
(
m
,
m
.
message
.
contentT
oString
()))
{
is
Message
->
m
.
quoteReply
(
message
)
is
Message
->
m
.
quoteReply
(
message
)
is
Unit
->
{
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