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
70dd71cb
Commit
70dd71cb
authored
Mar 24, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate to Kotlin 1.4
parent
eb7afb6c
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
70 deletions
+56
-70
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
.../net.mamoe.mirai/event/internal/InternalEventListeners.kt
+2
-17
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
+3
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
...monMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
+39
-47
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/contentToString.kt
...ommonMain/kotlin/net.mamoe.mirai/utils/contentToString.kt
+12
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
View file @
70dd71cb
...
@@ -115,24 +115,9 @@ internal class Handler<in E : Event>
...
@@ -115,24 +115,9 @@ internal class Handler<in E : Event>
*/
*/
internal
fun
<
E
:
Event
>
KClass
<
out
E
>.
listeners
():
EventListeners
<
E
>
=
EventListenerManager
.
get
(
this
)
internal
fun
<
E
:
Event
>
KClass
<
out
E
>.
listeners
():
EventListeners
<
E
>
=
EventListenerManager
.
get
(
this
)
internal
class
EventListeners
<
E
:
Event
>(
clazz
:
KClass
<
E
>)
:
LockFreeLinkedList
<
Listener
<
E
>>()
{
internal
expect
class
EventListeners
<
E
:
Event
>(
clazz
:
KClass
<
E
>)
:
LockFreeLinkedList
<
Listener
<
E
>>
{
@Suppress
(
"UNCHECKED_CAST"
,
"UNSUPPORTED"
,
"NO_REFLECTION_IN_CLASS_PATH"
)
@Suppress
(
"UNCHECKED_CAST"
,
"UNSUPPORTED"
,
"NO_REFLECTION_IN_CLASS_PATH"
)
val
supertypes
:
Set
<
KClass
<
out
Event
>>
by
lazy
{
val
supertypes
:
Set
<
KClass
<
out
Event
>>
val
supertypes
=
mutableSetOf
<
KClass
<
out
Event
>>()
fun
addSupertypes
(
clazz
:
KClass
<
out
Event
>)
{
clazz
.
supertypes
.
forEach
{
val
classifier
=
it
.
classifier
as
?
KClass
<
out
Event
>
if
(
classifier
!=
null
)
{
supertypes
.
add
(
classifier
)
addSupertypes
(
classifier
)
}
}
}
addSupertypes
(
clazz
)
supertypes
}
}
}
internal
expect
class
MiraiAtomicBoolean
(
initial
:
Boolean
)
{
internal
expect
class
MiraiAtomicBoolean
(
initial
:
Boolean
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
View file @
70dd71cb
...
@@ -285,7 +285,7 @@ abstract class MessageSelectBuilderUnit<M : MessagePacket<*, *>, R> @PublishedAp
...
@@ -285,7 +285,7 @@ abstract class MessageSelectBuilderUnit<M : MessagePacket<*, *>, R> @PublishedAp
* 在超时后引用回复原消息
* 在超时后引用回复原消息
*
*
* 当 [block] 返回值为 [Unit] 时不回复, 为 [Message] 时回复 [Message], 其他将 [toString] 后回复为 [PlainText]
* 当 [block] 返回值为 [Unit] 时不回复, 为 [Message] 时回复 [Message], 其他将 [toString] 后回复为 [PlainText]
*
* @see timeout
* @see timeout
* @see reply
* @see reply
*/
*/
...
@@ -304,8 +304,7 @@ abstract class MessageSelectBuilderUnit<M : MessagePacket<*, *>, R> @PublishedAp
...
@@ -304,8 +304,7 @@ abstract class MessageSelectBuilderUnit<M : MessagePacket<*, *>, R> @PublishedAp
*/
*/
@MessageDsl
@MessageDsl
fun
defaultReply
(
block
:
suspend
()
->
Any
?):
Unit
=
subscriber
({
true
},
{
fun
defaultReply
(
block
:
suspend
()
->
Any
?):
Unit
=
subscriber
({
true
},
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false positive
this
@MessageSelectBuilderUnit
.
executeAndReply
(
block
)
executeAndReply
(
block
)
})
})
...
@@ -316,8 +315,7 @@ abstract class MessageSelectBuilderUnit<M : MessagePacket<*, *>, R> @PublishedAp
...
@@ -316,8 +315,7 @@ abstract class MessageSelectBuilderUnit<M : MessagePacket<*, *>, R> @PublishedAp
*/
*/
@MessageDsl
@MessageDsl
fun
defaultQuoteReply
(
block
:
suspend
()
->
Any
?):
Unit
=
subscriber
({
true
},
{
fun
defaultQuoteReply
(
block
:
suspend
()
->
Any
?):
Unit
=
subscriber
({
true
},
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
// false positive
this
@MessageSelectBuilderUnit
.
executeAndQuoteReply
(
block
)
executeAndQuoteReply
(
block
)
})
})
private
suspend
inline
fun
executeAndReply
(
noinline
block
:
suspend
()
->
Any
?)
{
private
suspend
inline
fun
executeAndReply
(
noinline
block
:
suspend
()
->
Any
?)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
View file @
70dd71cb
...
@@ -262,7 +262,6 @@ typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
...
@@ -262,7 +262,6 @@ typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
* @see subscribeFriendMessages
* @see subscribeFriendMessages
* @sample demo.subscribe.messageDSL
* @sample demo.subscribe.messageDSL
*/
*/
// TODO: 2019/12/23 应定义为 inline, 但这会导致一个 JVM run-time VerifyError. 等待 kotlin 修复 bug (Kotlin 1.3.61)
@Suppress
(
"unused"
,
"DSL_SCOPE_VIOLATION_WARNING"
)
@Suppress
(
"unused"
,
"DSL_SCOPE_VIOLATION_WARNING"
)
@MessageDsl
@MessageDsl
open
class
MessageSubscribersBuilder
<
M
:
MessagePacket
<
*
,
*
>,
out
Ret
,
R
:
RR
,
RR
>(
open
class
MessageSubscribersBuilder
<
M
:
MessagePacket
<
*
,
*
>,
out
Ret
,
R
:
RR
,
RR
>(
...
@@ -318,37 +317,36 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -318,37 +317,36 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
reply
(
toReply
:
String
):
Ret
{
internal
open
infix
fun
reply
(
toReply
:
String
):
Ret
{
return
content
(
filter
)
{
reply
(
toReply
);
stub
}
return
content
(
filter
)
{
reply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
reply
(
message
:
Message
):
Ret
{
internal
open
infix
fun
reply
(
message
:
Message
):
Ret
{
return
content
(
filter
)
{
reply
(
message
);
stub
}
return
content
(
filter
)
{
reply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
reply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
internal
open
infix
fun
reply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
return
content
(
filter
)
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
,
replier
)
executeAndReply
(
replier
)
}
}
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
quoteReply
(
toReply
:
String
):
Ret
{
internal
open
infix
fun
quoteReply
(
toReply
:
String
):
Ret
{
return
content
(
filter
)
{
quoteReply
(
toReply
);
stub
}
return
content
(
filter
)
{
quoteReply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
quoteReply
(
message
:
Message
):
Ret
{
internal
open
infix
fun
quoteReply
(
message
:
Message
):
Ret
{
return
content
(
filter
)
{
quoteReply
(
message
);
stub
}
return
content
(
filter
)
{
quoteReply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
quoteReply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
internal
open
infix
fun
quoteReply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
return
content
(
filter
)
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
executeAndQuoteReply
(
replier
)
this
@MessageSubscribersBuilder
.
executeAndQuoteReply
(
this
,
replier
)
}
}
}
}
...
@@ -372,13 +370,13 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -372,13 +370,13 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
open
infix
fun
ListeningFilter
.
reply
(
toReply
:
String
):
Ret
{
open
infix
fun
ListeningFilter
.
reply
(
toReply
:
String
):
Ret
{
return
content
(
filter
)
{
reply
(
toReply
);
stub
}
return
content
(
filter
)
{
reply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
open
infix
fun
ListeningFilter
.
reply
(
message
:
Message
):
Ret
{
open
infix
fun
ListeningFilter
.
reply
(
message
:
Message
):
Ret
{
return
content
(
filter
)
{
reply
(
message
);
stub
}
return
content
(
filter
)
{
reply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
...
@@ -386,20 +384,20 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -386,20 +384,20 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
open
infix
fun
ListeningFilter
.
reply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
open
infix
fun
ListeningFilter
.
reply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
return
content
(
filter
)
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
executeAndReply
(
replier
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
,
replier
)
}
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
open
infix
fun
ListeningFilter
.
quoteReply
(
toReply
:
String
):
Ret
{
open
infix
fun
ListeningFilter
.
quoteReply
(
toReply
:
String
):
Ret
{
return
content
(
filter
)
{
quoteReply
(
toReply
);
stub
}
return
content
(
filter
)
{
quoteReply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
open
infix
fun
ListeningFilter
.
quoteReply
(
message
:
Message
):
Ret
{
open
infix
fun
ListeningFilter
.
quoteReply
(
message
:
Message
):
Ret
{
return
content
(
filter
)
{
quoteReply
(
message
);
stub
}
return
content
(
filter
)
{
quoteReply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
...
@@ -407,11 +405,10 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -407,11 +405,10 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
open
infix
fun
ListeningFilter
.
quoteReply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
open
infix
fun
ListeningFilter
.
quoteReply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
return
content
(
filter
)
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
executeAndQuoteReply
(
replier
)
this
@MessageSubscribersBuilder
.
executeAndQuoteReply
(
this
,
replier
)
}
}
}
}
// TODO: 2020/3/6 这些 lambda 都应该 crossinline, 但这会导致异常时的 stacktrace 不准确 (Kotlin 1.3.70) 待 Kotlin 修复此问题后恢复 inline 结构
/**
/**
* 无任何触发条件.
* 无任何触发条件.
...
@@ -753,7 +750,10 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -753,7 +750,10 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
mapper
:
M
.(
String
)
->
N
?,
mapper
:
M
.(
String
)
->
N
?,
onEvent
:
@MessageDsl
suspend
M
.(
N
)
->
R
onEvent
:
@MessageDsl
suspend
M
.(
N
)
->
R
):
Ret
=
always
{
):
Ret
=
always
{
onEvent
.
invoke
(
this
,
mapper
.
invoke
(
this
,
message
.
toString
())
?:
return
@
always
stub
)
onEvent
.
invoke
(
this
,
mapper
.
invoke
(
this
,
message
.
toString
())
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
)
}
}
/**
/**
...
@@ -781,16 +781,14 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -781,16 +781,14 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
content
{
regex
.
matchEntire
(
it
)
!=
null
}
content
{
regex
.
matchEntire
(
it
)
!=
null
}
// TODO: 2020/3/20 支持新泛型
/**
/**
* 如果消息内容可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent`
* 如果消息内容可由正则表达式匹配([Regex.matchEntire]), 就执行 `onEvent`
*/
*/
@MessageDsl
@MessageDsl
fun
matching
(
regex
:
Regex
,
onEvent
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Unit
):
Ret
=
fun
matching
(
regex
:
Regex
,
onEvent
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Unit
):
Ret
=
always
{
always
{
val
find
=
regex
.
matchEntire
(
it
)
?:
return
@
always
stub
val
find
=
regex
.
matchEntire
(
it
)
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
this
.
executeAndReply
{
onEvent
.
invoke
(
this
,
find
)
onEvent
.
invoke
(
this
,
find
)
}
}
}
}
...
@@ -808,9 +806,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -808,9 +806,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@MessageDsl
@MessageDsl
fun
finding
(
regex
:
Regex
,
onEvent
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Unit
):
Ret
=
fun
finding
(
regex
:
Regex
,
onEvent
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Unit
):
Ret
=
always
{
always
{
val
find
=
regex
.
find
(
it
)
?:
return
@
always
stub
val
find
=
regex
.
find
(
it
)
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
this
.
executeAndReply
{
onEvent
.
invoke
(
this
,
find
)
onEvent
.
invoke
(
this
,
find
)
}
}
}
}
...
@@ -821,7 +818,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -821,7 +818,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
*/
*/
@MessageDsl
@MessageDsl
open
infix
fun
String
.
containsReply
(
reply
:
String
):
Ret
=
open
infix
fun
String
.
containsReply
(
reply
:
String
):
Ret
=
content
({
this
@
containsReply
in
it
},
{
reply
(
reply
);
stub
})
content
({
this
@
containsReply
in
it
},
{
reply
(
reply
);
this
@MessageSubscribersBuilder
.
stub
})
/**
/**
* 若消息内容包含 [this] 则执行 [replier] 并将其返回值回复给发信对象.
* 若消息内容包含 [this] 则执行 [replier] 并将其返回值回复给发信对象.
...
@@ -833,8 +830,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -833,8 +830,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@MessageDsl
@MessageDsl
open
infix
fun
String
.
containsReply
(
replier
:
@MessageDsl
suspend
M
.(
String
)
->
Any
?):
Ret
=
open
infix
fun
String
.
containsReply
(
replier
:
@MessageDsl
suspend
M
.(
String
)
->
Any
?):
Ret
=
content
({
this
@
containsReply
in
it
},
{
content
({
this
@
containsReply
in
it
},
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
,
replier
)
this
.
executeAndReply
(
replier
)
})
})
/**
/**
...
@@ -847,9 +843,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -847,9 +843,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@MessageDsl
@MessageDsl
open
infix
fun
Regex
.
matchingReply
(
replier
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Any
?):
Ret
=
open
infix
fun
Regex
.
matchingReply
(
replier
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Any
?):
Ret
=
always
{
always
{
val
find
=
this
@
matchingReply
.
matchEntire
(
it
)
?:
return
@
always
stub
val
find
=
this
@
matchingReply
.
matchEntire
(
it
)
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
this
.
executeAndReply
{
replier
.
invoke
(
this
,
find
)
replier
.
invoke
(
this
,
find
)
}
}
}
}
...
@@ -864,9 +859,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -864,9 +859,8 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@MessageDsl
@MessageDsl
open
infix
fun
Regex
.
findingReply
(
replier
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Any
?):
Ret
=
open
infix
fun
Regex
.
findingReply
(
replier
:
@MessageDsl
suspend
M
.(
MatchResult
)
->
Any
?):
Ret
=
always
{
always
{
val
find
=
this
@
findingReply
.
find
(
it
)
?:
return
@
always
stub
val
find
=
this
@
findingReply
.
find
(
it
)
?:
return
@
always
this
@MessageSubscribersBuilder
.
stub
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
this
.
executeAndReply
{
replier
.
invoke
(
this
,
find
)
replier
.
invoke
(
this
,
find
)
}
}
}
}
...
@@ -888,8 +882,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -888,8 +882,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
open
infix
fun
String
.
startsWithReply
(
replier
:
@MessageDsl
suspend
M
.(
String
)
->
Any
?):
Ret
{
open
infix
fun
String
.
startsWithReply
(
replier
:
@MessageDsl
suspend
M
.(
String
)
->
Any
?):
Ret
{
val
toCheck
=
this
.
trimStart
()
val
toCheck
=
this
.
trimStart
()
return
content
({
it
.
trim
().
startsWith
(
toCheck
)
},
{
return
content
({
it
.
trim
().
startsWith
(
toCheck
)
},
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
this
.
executeAndReply
{
replier
(
this
,
it
.
trim
().
removePrefix
(
toCheck
))
replier
(
this
,
it
.
trim
().
removePrefix
(
toCheck
))
}
}
})
})
...
@@ -912,8 +905,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -912,8 +905,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
open
infix
fun
String
.
endsWithReply
(
replier
:
@MessageDsl
suspend
M
.(
String
)
->
Any
?):
Ret
{
open
infix
fun
String
.
endsWithReply
(
replier
:
@MessageDsl
suspend
M
.(
String
)
->
Any
?):
Ret
{
val
toCheck
=
this
.
trimEnd
()
val
toCheck
=
this
.
trimEnd
()
return
content
({
it
.
trim
().
endsWith
(
toCheck
)
},
{
return
content
({
it
.
trim
().
endsWith
(
toCheck
)
},
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
this
.
executeAndReply
{
replier
(
this
,
it
.
trim
().
removeSuffix
(
toCheck
))
replier
(
this
,
it
.
trim
().
removeSuffix
(
toCheck
))
}
}
})
})
...
@@ -922,13 +914,13 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -922,13 +914,13 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@MessageDsl
@MessageDsl
open
infix
fun
String
.
reply
(
reply
:
String
):
Ret
{
open
infix
fun
String
.
reply
(
reply
:
String
):
Ret
{
val
toCheck
=
this
.
trim
()
val
toCheck
=
this
.
trim
()
return
content
({
it
.
trim
()
==
toCheck
},
{
reply
(
reply
);
stub
})
return
content
({
it
.
trim
()
==
toCheck
},
{
reply
(
reply
);
this
@MessageSubscribersBuilder
.
stub
})
}
}
@MessageDsl
@MessageDsl
open
infix
fun
String
.
reply
(
reply
:
Message
):
Ret
{
open
infix
fun
String
.
reply
(
reply
:
Message
):
Ret
{
val
toCheck
=
this
.
trim
()
val
toCheck
=
this
.
trim
()
return
content
({
it
.
trim
()
==
toCheck
},
{
reply
(
reply
);
stub
})
return
content
({
it
.
trim
()
==
toCheck
},
{
reply
(
reply
);
this
@MessageSubscribersBuilder
.
stub
})
}
}
@MessageDsl
@MessageDsl
...
@@ -936,7 +928,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -936,7 +928,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
val
toCheck
=
this
.
trim
()
val
toCheck
=
this
.
trim
()
return
content
({
it
.
trim
()
==
toCheck
},
{
return
content
({
it
.
trim
()
==
toCheck
},
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
.
executeAndReply
{
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
)
{
replier
(
this
,
it
.
trim
())
replier
(
this
,
it
.
trim
())
}
}
})
})
...
@@ -944,26 +936,26 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -944,26 +936,26 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@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
M
.
executeAndReply
(
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
internal
suspend
inline
fun
executeAndReply
(
m
:
M
,
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
when
(
val
message
=
replier
(
this
,
this
.
message
.
toString
()))
{
when
(
val
message
=
replier
(
m
,
m
.
message
.
toString
()))
{
is
Message
->
this
.
reply
(
message
)
is
Message
->
m
.
reply
(
message
)
is
Unit
->
{
is
Unit
->
{
}
}
else
->
this
.
reply
(
message
.
toString
())
else
->
m
.
reply
(
message
.
toString
())
}
}
return
stub
return
stub
}
}
@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
M
.
executeAndQuoteReply
(
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
internal
suspend
inline
fun
executeAndQuoteReply
(
m
:
M
,
replier
:
suspend
M
.(
String
)
->
Any
?):
RR
{
when
(
val
message
=
replier
(
this
,
this
.
message
.
toString
()))
{
when
(
val
message
=
replier
(
m
,
m
.
message
.
toString
()))
{
is
Message
->
this
.
quoteReply
(
message
)
is
Message
->
m
.
quoteReply
(
message
)
is
Unit
->
{
is
Unit
->
{
}
}
else
->
this
.
quoteReply
(
message
.
toString
())
else
->
m
.
quoteReply
(
message
.
toString
())
}
}
return
stub
return
stub
}
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/utils/contentToString.kt
View file @
70dd71cb
...
@@ -13,7 +13,9 @@ package net.mamoe.mirai.utils
...
@@ -13,7 +13,9 @@ package net.mamoe.mirai.utils
import
net.mamoe.mirai.utils.io.toUHexString
import
net.mamoe.mirai.utils.io.toUHexString
import
kotlin.reflect.KClass
import
kotlin.reflect.KClass
import
kotlin.reflect.KProperty
import
kotlin.reflect.KProperty1
import
kotlin.reflect.KProperty1
import
kotlin.reflect.KType
private
val
indent
:
String
=
" "
.
repeat
(
4
)
private
val
indent
:
String
=
" "
.
repeat
(
4
)
...
@@ -127,8 +129,14 @@ fun Any?._miraiContentToString(prefix: String = ""): String = when (this) {
...
@@ -127,8 +129,14 @@ fun Any?._miraiContentToString(prefix: String = ""): String = when (this) {
internal
expect
fun
KProperty1
<*,
*>.
getValueAgainstPermission
(
receiver
:
Any
):
Any
?
internal
expect
fun
KProperty1
<*,
*>.
getValueAgainstPermission
(
receiver
:
Any
):
Any
?
private
val
KProperty1
<*,
*>.
isConst
:
Boolean
get
()
=
false
// on JVM, it will be resolved to member function
private
val
KClass
<*>.
isData
:
Boolean
get
()
=
false
// on JVM, it will be resolved to member function
@MiraiDebugAPI
@MiraiDebugAPI
private
fun
Any
.
contentToStringReflectively
(
prefix
:
String
,
filter
:
((
name
:
String
,
value
:
Any
?)
->
Boolean
)?
=
null
):
String
{
private
fun
Any
.
contentToStringReflectively
(
prefix
:
String
,
filter
:
((
name
:
String
,
value
:
Any
?)
->
Boolean
)?
=
null
):
String
{
val
newPrefix
=
"$prefix "
val
newPrefix
=
"$prefix "
return
(
this
::
class
.
simpleName
?:
"<UnnamedClass>"
)
+
"#"
+
this
::
class
.
hashCode
()
+
" {\n"
+
return
(
this
::
class
.
simpleName
?:
"<UnnamedClass>"
)
+
"#"
+
this
::
class
.
hashCode
()
+
" {\n"
+
this
.
allMembersFromSuperClassesMatching
{
it
.
qualifiedName
?.
startsWith
(
"net.mamoe.mirai"
)
==
true
}
this
.
allMembersFromSuperClassesMatching
{
it
.
qualifiedName
?.
startsWith
(
"net.mamoe.mirai"
)
==
true
}
...
@@ -155,11 +163,14 @@ private fun Any.contentToStringReflectively(prefix: String, filter: ((name: Stri
...
@@ -155,11 +163,14 @@ private fun Any.contentToStringReflectively(prefix: String, filter: ((name: Stri
}
+
"\n$prefix}"
}
+
"\n$prefix}"
}
}
private
val
<
T
:
Any
>
KClass
<
T
>.
supertypes
:
List
<
KType
>
get
()
=
listOf
()
// on JVM, it will be resolved to member function
private
fun
KClass
<
out
Any
>.
thisClassAndSuperclassSequence
():
Sequence
<
KClass
<
out
Any
>>
{
private
fun
KClass
<
out
Any
>.
thisClassAndSuperclassSequence
():
Sequence
<
KClass
<
out
Any
>>
{
return
sequenceOf
(
this
)
+
return
sequenceOf
(
this
)
+
this
.
supertypes
.
asSequence
()
this
.
supertypes
.
asSequence
()
.
mapNotNull
{
type
->
type
.
classifier
?.
takeIf
{
it
is
KClass
<
*
>
}
?.
takeIf
{
it
!=
Any
::
class
} as?
KClass
<
out
Any
>
}.
flatMap
{
it
.
thisClassAndSuperclassSequence
()
}
.
mapNotNull
{
type
->
type
.
classifier
?.
takeIf
{
it
is
KClass
<
*
>
}
?.
takeIf
{
it
!=
Any
::
class
} as?
KClass
<
out
Any
>
}.
flatMap
{
it
.
thisClassAndSuperclassSequence
()
}
}
}
private
val
<
T
:
Any
>
KClass
<
T
>.
members
:
List
<
KProperty
<
*
>>
get
()
=
listOf
()
// on JVM, it will be resolved to member function
@Suppress
(
"UNCHECKED_CAST"
)
@Suppress
(
"UNCHECKED_CAST"
)
private
fun
Any
.
allMembersFromSuperClassesMatching
(
classFilter
:
(
KClass
<
out
Any
>)
->
Boolean
):
Sequence
<
KProperty1
<
Any
,
*
>>
{
private
fun
Any
.
allMembersFromSuperClassesMatching
(
classFilter
:
(
KClass
<
out
Any
>)
->
Boolean
):
Sequence
<
KProperty1
<
Any
,
*
>>
{
...
...
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