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
a5b82c5e
Commit
a5b82c5e
authored
Apr 15, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rearrange `MessageSubscribersBuilder`
parent
e31805a8
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
627 additions
and
628 deletions
+627
-628
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribersBuilder.kt
...kotlin/net.mamoe.mirai/event/MessageSubscribersBuilder.kt
+508
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/messageSubscribersInternal.kt
....mamoe.mirai/event/internal/messageSubscribersInternal.kt
+118
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
...monMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
+1
-628
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribersBuilder.kt
0 → 100644
View file @
a5b82c5e
This diff is collapsed.
Click to expand it.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/messageSubscribersInternal.kt
0 → 100644
View file @
a5b82c5e
/*
* Copyright 2020 Mamoe Technologies and contributors.
*
* 此源代码的使用受 GNU AFFERO GENERAL PUBLIC LICENSE version 3 许可证的约束, 可以在以下链接找到该许可证.
* Use of this source code is governed by the GNU AGPLv3 license that can be found through the following link.
*
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
package
net.mamoe.mirai.event.internal
import
net.mamoe.mirai.event.MessageDsl
import
net.mamoe.mirai.event.MessageListener
import
net.mamoe.mirai.event.MessageSubscribersBuilder
import
net.mamoe.mirai.message.ContactMessage
/*
* 将 internal 移出 MessageSubscribersBuilder.kt 以减小其体积
*/
@MessageDsl
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
content
(
filter
:
M
.(
String
)
->
Boolean
,
onEvent
:
MessageListener
<
M
,
RR
>
):
Ret
=
subscriber
(
filter
)
{
onEvent
(
this
,
it
)
}
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
endsWithImpl
(
suffix
:
String
,
removeSuffix
:
Boolean
=
true
,
trim
:
Boolean
=
true
,
onEvent
:
@MessageDsl
suspend
M
.(
String
)
->
R
):
Ret
{
return
if
(
trim
)
{
val
toCheck
=
suffix
.
trim
()
content
({
it
.
trimEnd
().
endsWith
(
toCheck
)
})
{
if
(
removeSuffix
)
this
.
onEvent
(
this
.
message
.
contentToString
().
removeSuffix
(
toCheck
).
trim
())
else
onEvent
(
this
,
this
.
message
.
contentToString
().
trim
())
}
}
else
{
content
({
it
.
endsWith
(
suffix
)
})
{
if
(
removeSuffix
)
this
.
onEvent
(
this
.
message
.
contentToString
().
removeSuffix
(
suffix
))
else
onEvent
(
this
,
this
.
message
.
contentToString
())
}
}
}
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
startsWithImpl
(
prefix
:
String
,
removePrefix
:
Boolean
=
true
,
trim
:
Boolean
=
true
,
onEvent
:
@MessageDsl
suspend
M
.(
String
)
->
R
):
Ret
{
return
if
(
trim
)
{
val
toCheck
=
prefix
.
trim
()
content
({
it
.
trimStart
().
startsWith
(
toCheck
)
})
{
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
contentToString
().
substringAfter
(
toCheck
).
trim
())
else
onEvent
(
this
,
this
.
message
.
contentToString
().
trim
())
}
}
else
content
({
it
.
startsWith
(
prefix
)
})
{
if
(
removePrefix
)
this
.
onEvent
(
this
.
message
.
contentToString
().
removePrefix
(
prefix
))
else
onEvent
(
this
,
this
.
message
.
contentToString
())
}
}
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
containsAllImpl
(
sub
:
Array
<
out
String
>,
ignoreCase
:
Boolean
=
false
,
trim
:
Boolean
=
true
):
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
ListeningFilter
=
if
(
trim
)
{
val
list
=
sub
.
map
{
it
.
trim
()
}
content
{
list
.
all
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
}
}
else
{
content
{
sub
.
all
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
}
}
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
containsAnyImpl
(
vararg
sub
:
String
,
ignoreCase
:
Boolean
=
false
,
trim
:
Boolean
=
true
):
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
ListeningFilter
=
if
(
trim
)
{
val
list
=
sub
.
map
{
it
.
trim
()
}
content
{
list
.
any
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
}
}
else
content
{
sub
.
any
{
toCheck
->
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
}
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
caseImpl
(
equals
:
String
,
ignoreCase
:
Boolean
=
false
,
trim
:
Boolean
=
true
):
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
ListeningFilter
{
return
if
(
trim
)
{
val
toCheck
=
equals
.
trim
()
content
{
it
.
trim
().
equals
(
toCheck
,
ignoreCase
=
ignoreCase
)
}
}
else
{
content
{
it
.
equals
(
equals
,
ignoreCase
=
ignoreCase
)
}
}
}
internal
fun
<
M
:
ContactMessage
,
Ret
,
R
:
RR
,
RR
>
MessageSubscribersBuilder
<
M
,
Ret
,
R
,
RR
>.
containsImpl
(
sub
:
String
,
ignoreCase
:
Boolean
=
false
,
trim
:
Boolean
=
true
,
onEvent
:
MessageListener
<
M
,
R
>
):
Ret
{
return
if
(
trim
)
{
val
toCheck
=
sub
.
trim
()
content
({
it
.
contains
(
toCheck
,
ignoreCase
=
ignoreCase
)
})
{
onEvent
(
this
,
this
.
message
.
contentToString
().
trim
())
}
}
else
{
content
({
it
.
contains
(
sub
,
ignoreCase
=
ignoreCase
)
})
{
onEvent
(
this
,
this
.
message
.
contentToString
())
}
}
}
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
View file @
a5b82c5e
This diff is collapsed.
Click to expand it.
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