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
936ed3ff
Commit
936ed3ff
authored
Mar 24, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix compilation error
parent
70dd71cb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
23 additions
and
104 deletions
+23
-104
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
+19
-10
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
...monMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
+4
-94
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
View file @
936ed3ff
...
@@ -386,12 +386,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
...
@@ -386,12 +386,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
val
defaultListeners
:
MutableList
<
MessageListener
<
T
,
Any
?
>>
=
mutableListOf
()
val
defaultListeners
:
MutableList
<
MessageListener
<
T
,
Any
?
>>
=
mutableListOf
()
if
(
isUnit
)
{
if
(
isUnit
)
{
// https://youtrack.jetbrains.com/issue/KT-37716
val
outside
=
{
filter
:
T
.(
String
)
->
Boolean
,
listener
:
MessageListener
<
T
,
Any
?
>
->
listeners
+=
filter
to
listener
}
object
:
MessageSelectBuilderUnit
<
T
,
R
>(
object
:
MessageSelectBuilderUnit
<
T
,
R
>(
this
@
selectMessagesImpl
,
this
@
selectMessagesImpl
,
SELECT_MESSAGE_STUB
,
SELECT_MESSAGE_STUB
,
{
filter
:
T
.(
String
)
->
Boolean
,
listener
:
MessageListener
<
T
,
Any
?
>
->
outside
listeners
+=
filter
to
listener
)
{
})
{
override
fun
obtainCurrentCoroutineScope
():
CoroutineScope
=
this
@
withTimeoutOrCoroutineScope
override
fun
obtainCurrentCoroutineScope
():
CoroutineScope
=
this
@
withTimeoutOrCoroutineScope
override
fun
obtainCurrentDeferred
():
CompletableDeferred
<
R
>?
=
deferred
override
fun
obtainCurrentDeferred
():
CompletableDeferred
<
R
>?
=
deferred
override
fun
default
(
onEvent
:
MessageListener
<
T
,
R
>)
{
override
fun
default
(
onEvent
:
MessageListener
<
T
,
R
>)
{
...
@@ -399,12 +402,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
...
@@ -399,12 +402,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
}
}
}
}
}
else
{
}
else
{
// https://youtrack.jetbrains.com/issue/KT-37716
val
outside
=
{
filter
:
T
.(
String
)
->
Boolean
,
listener
:
MessageListener
<
T
,
Any
?
>
->
listeners
+=
filter
to
listener
}
object
:
MessageSelectBuilder
<
T
,
R
>(
object
:
MessageSelectBuilder
<
T
,
R
>(
this
@
selectMessagesImpl
,
this
@
selectMessagesImpl
,
SELECT_MESSAGE_STUB
,
SELECT_MESSAGE_STUB
,
{
filter
:
T
.(
String
)
->
Boolean
,
listener
:
MessageListener
<
T
,
Any
?
>
->
outside
listeners
+=
filter
to
listener
)
{
})
{
override
fun
obtainCurrentCoroutineScope
():
CoroutineScope
=
this
@
withTimeoutOrCoroutineScope
override
fun
obtainCurrentCoroutineScope
():
CoroutineScope
=
this
@
withTimeoutOrCoroutineScope
override
fun
obtainCurrentDeferred
():
CompletableDeferred
<
R
>?
=
deferred
override
fun
obtainCurrentDeferred
():
CompletableDeferred
<
R
>?
=
deferred
override
fun
default
(
onEvent
:
MessageListener
<
T
,
R
>)
{
override
fun
default
(
onEvent
:
MessageListener
<
T
,
R
>)
{
...
@@ -414,7 +420,7 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
...
@@ -414,7 +420,7 @@ internal suspend inline fun <reified T : MessagePacket<*, *>, R> T.selectMessage
}.
apply
(
selectBuilder
)
}.
apply
(
selectBuilder
)
// we don't have any way to reduce duplication yet,
// we don't have any way to reduce duplication yet,
// until local functions
is
supported in inline functions
// until local functions
are
supported in inline functions
@Suppress
(
"DuplicatedCode"
)
@Suppress
(
"DuplicatedCode"
)
subscribeAlways
<
T
>
{
event
->
subscribeAlways
<
T
>
{
event
->
if
(!
this
.
isContextIdenticalWith
(
this
@
selectMessagesImpl
))
if
(!
this
.
isContextIdenticalWith
(
this
@
selectMessagesImpl
))
...
@@ -470,12 +476,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>> T.whileSelectMessa
...
@@ -470,12 +476,15 @@ internal suspend inline fun <reified T : MessagePacket<*, *>> T.whileSelectMessa
val
listeners
:
MutableList
<
Pair
<
T
.(
String
)
-
>
Boolean
,
MessageListener
<
T
,
Any
?
>>>
=
mutableListOf
()
val
listeners
:
MutableList
<
Pair
<
T
.(
String
)
-
>
Boolean
,
MessageListener
<
T
,
Any
?
>>>
=
mutableListOf
()
val
defaltListeners
:
MutableList
<
MessageListener
<
T
,
Any
?
>>
=
mutableListOf
()
val
defaltListeners
:
MutableList
<
MessageListener
<
T
,
Any
?
>>
=
mutableListOf
()
// https://youtrack.jetbrains.com/issue/KT-37716
val
outside
=
{
filter
:
T
.(
String
)
->
Boolean
,
listener
:
MessageListener
<
T
,
Any
?
>
->
listeners
+=
filter
to
listener
}
object
:
MessageSelectBuilder
<
T
,
Boolean
>(
object
:
MessageSelectBuilder
<
T
,
Boolean
>(
this
@
whileSelectMessagesImpl
,
this
@
whileSelectMessagesImpl
,
SELECT_MESSAGE_STUB
,
SELECT_MESSAGE_STUB
,
{
filter
:
T
.(
String
)
->
Boolean
,
listener
:
MessageListener
<
T
,
Any
?
>
->
outside
listeners
+=
filter
to
listener
)
{
})
{
override
fun
obtainCurrentCoroutineScope
():
CoroutineScope
=
this
@
withTimeoutOrCoroutineScope
override
fun
obtainCurrentCoroutineScope
():
CoroutineScope
=
this
@
withTimeoutOrCoroutineScope
override
fun
obtainCurrentDeferred
():
CompletableDeferred
<
Boolean
>?
=
deferred
override
fun
obtainCurrentDeferred
():
CompletableDeferred
<
Boolean
>?
=
deferred
override
fun
default
(
onEvent
:
MessageListener
<
T
,
Boolean
>)
{
override
fun
default
(
onEvent
:
MessageListener
<
T
,
Boolean
>)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
View file @
936ed3ff
...
@@ -33,7 +33,6 @@ import kotlin.coroutines.CoroutineContext
...
@@ -33,7 +33,6 @@ import kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.js.JsName
import
kotlin.js.JsName
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmSynthetic
typealias
MessagePacketSubscribersBuilder
=
MessageSubscribersBuilder
<
MessagePacket
<
*
,
*
>,
Listener
<
MessagePacket
<
*
,
*
>>,
Unit
,
Unit
>
typealias
MessagePacketSubscribersBuilder
=
MessageSubscribersBuilder
<
MessagePacket
<
*
,
*
>,
Listener
<
MessagePacket
<
*
,
*
>>,
Unit
,
Unit
>
...
@@ -260,7 +259,6 @@ typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
...
@@ -260,7 +259,6 @@ typealias MessageListener<T, R> = @MessageDsl suspend T.(String) -> R
* @param Ret 每个 DSL 函数创建监听器之后的返回值
* @param Ret 每个 DSL 函数创建监听器之后的返回值
*
*
* @see subscribeFriendMessages
* @see subscribeFriendMessages
* @sample demo.subscribe.messageDSL
*/
*/
@Suppress
(
"unused"
,
"DSL_SCOPE_VIOLATION_WARNING"
)
@Suppress
(
"unused"
,
"DSL_SCOPE_VIOLATION_WARNING"
)
@MessageDsl
@MessageDsl
...
@@ -277,7 +275,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -277,7 +275,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
/**
/**
* 监听的条件
* 监听的条件
*/
*/
open
inner
class
ListeningFilter
@Deprecated
(
open
inner
class
ListeningFilter
@Deprecated
(
// keep it for development warning
"use newListeningFilter instead"
,
"use newListeningFilter instead"
,
ReplaceWith
(
"newListeningFilter(filter)"
),
ReplaceWith
(
"newListeningFilter(filter)"
),
level
=
DeprecationLevel
.
ERROR
level
=
DeprecationLevel
.
ERROR
...
@@ -314,93 +312,42 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -314,93 +312,42 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
fun
not
():
ListeningFilter
=
fun
not
():
ListeningFilter
=
newListeningFilter
{
!
filter
.
invoke
(
this
,
it
)
}
newListeningFilter
{
!
filter
.
invoke
(
this
,
it
)
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
reply
(
toReply
:
String
):
Ret
{
return
content
(
filter
)
{
reply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
reply
(
message
:
Message
):
Ret
{
return
content
(
filter
)
{
reply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
reply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
return
content
(
filter
)
{
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
,
replier
)
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
quoteReply
(
toReply
:
String
):
Ret
{
return
content
(
filter
)
{
quoteReply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
quoteReply
(
message
:
Message
):
Ret
{
return
content
(
filter
)
{
quoteReply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
internal
open
infix
fun
quoteReply
(
replier
:
(
@MessageDsl
suspend
M
.(
String
)
->
Any
?)):
Ret
{
return
content
(
filter
)
{
@Suppress
(
"DSL_SCOPE_VIOLATION_WARNING"
)
this
@MessageSubscribersBuilder
.
executeAndQuoteReply
(
this
,
replier
)
}
}
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@JvmName
(
"invoke"
)
internal
fun
invoke0
(
onEvent
:
MessageListener
<
M
,
R
>):
Listener
<
*
>
{
return
content
(
filter
,
onEvent
)
as
Listener
<
*
>
}
/**
/**
* 启动事件监听.
* 启动事件监听.
*/
*/
@JvmName
(
"invoke1"
)
// do not inline due to kotlin (1.3.61) bug: java.lang.IllegalAccessError
// do not inline due to kotlin (1.3.61) bug: java.lang.IllegalAccessError
operator
fun
invoke
(
onEvent
:
MessageListener
<
M
,
R
>):
Ret
{
operator
fun
invoke
(
onEvent
:
MessageListener
<
M
,
R
>):
Ret
{
return
content
(
filter
,
onEvent
)
return
content
(
filter
,
onEvent
)
}
}
}
}
@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
);
this
@MessageSubscribersBuilder
.
stub
}
return
content
(
filter
)
{
reply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@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
);
this
@MessageSubscribersBuilder
.
stub
}
return
content
(
filter
)
{
reply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
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"
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
,
replier
)
this
@MessageSubscribersBuilder
.
executeAndReply
(
this
,
replier
)
}
}
}
}
@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
);
this
@MessageSubscribersBuilder
.
stub
}
return
content
(
filter
)
{
quoteReply
(
toReply
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@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
);
this
@MessageSubscribersBuilder
.
stub
}
return
content
(
filter
)
{
quoteReply
(
message
);
this
@MessageSubscribersBuilder
.
stub
}
}
}
@Suppress
(
"EXTENSION_SHADOWED_BY_MEMBER"
)
// binary compatibility
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
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
)
{
...
@@ -440,7 +387,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -440,7 +387,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@JvmName
(
"case1"
)
@JvmName
(
"case1"
)
@JsName
(
"case1"
)
@JsName
(
"case1"
)
@SinceMirai
(
"0.29.0"
)
@SinceMirai
(
"0.29.0"
)
@Suppress
(
"INVALID_CHARACTERS"
,
"NAME_CONTAINS_ILLEGAL_CHARS"
)
@Suppress
(
"INVALID_CHARACTERS"
,
"NAME_CONTAINS_ILLEGAL_CHARS"
,
"FunctionName"
)
infix
fun
String
.
`->`(
block
:
MessageListener
<
M
,
R
>):
Ret
{
infix
fun
String
.
`->`(
block
:
MessageListener
<
M
,
R
>):
Ret
{
return
case
(
this
,
onEvent
=
block
)
return
case
(
this
,
onEvent
=
block
)
}
}
...
@@ -739,7 +686,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -739,7 +686,7 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@MessageDsl
@MessageDsl
@SinceMirai
(
"0.30.0"
)
@SinceMirai
(
"0.30.0"
)
inline
fun
<
reified
N
:
Message
>
has
(
noinline
onEvent
:
@MessageDsl
suspend
M
.(
N
)
->
R
):
Ret
=
inline
fun
<
reified
N
:
Message
>
has
(
noinline
onEvent
:
@MessageDsl
suspend
M
.(
N
)
->
R
):
Ret
=
content
({
message
.
any
{
it
is
N
}
},
{
onEvent
.
invoke
(
this
,
message
.
first
<
N
>
())
})
content
({
message
.
any
{
it
is
N
}
},
{
onEvent
.
invoke
(
this
,
message
.
first
())
})
/**
/**
* 如果 [mapper] 返回值非空, 就执行 [onEvent]
* 如果 [mapper] 返回值非空, 就执行 [onEvent]
...
@@ -973,41 +920,4 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
...
@@ -973,41 +920,4 @@ open class MessageSubscribersBuilder<M : MessagePacket<*, *>, out Ret, R : RR, R
@Retention
(
AnnotationRetention
.
SOURCE
)
@Retention
(
AnnotationRetention
.
SOURCE
)
@Target
(
AnnotationTarget
.
FUNCTION
,
AnnotationTarget
.
CLASS
,
AnnotationTarget
.
TYPE
)
@Target
(
AnnotationTarget
.
FUNCTION
,
AnnotationTarget
.
CLASS
,
AnnotationTarget
.
TYPE
)
@DslMarker
@DslMarker
annotation
class
MessageDsl
annotation
class
MessageDsl
\ No newline at end of file
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
R
>
CoroutineScope
.
subscribeMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listeners
:
MessagePacketSubscribersBuilder
.()
->
R
):
R
=
subscribeMessages
(
coroutineContext
,
listeners
=
listeners
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
R
>
CoroutineScope
.
subscribeGroupMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listeners
:
GroupMessageSubscribersBuilder
.()
->
R
):
R
=
subscribeGroupMessages
(
coroutineContext
,
listeners
=
listeners
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
R
>
CoroutineScope
.
subscribeFriendMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listeners
:
FriendMessageSubscribersBuilder
.()
->
R
):
R
=
subscribeFriendMessages
(
coroutineContext
,
listeners
=
listeners
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
R
>
Bot
.
subscribeMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listeners
:
MessagePacketSubscribersBuilder
.()
->
R
):
R
=
subscribeMessages
(
coroutineContext
,
listeners
=
listeners
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
R
>
Bot
.
subscribeGroupMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listeners
:
GroupMessageSubscribersBuilder
.()
->
R
):
R
=
subscribeGroupMessages
(
coroutineContext
,
listeners
=
listeners
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
R
>
Bot
.
subscribeFriendMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listeners
:
FriendMessageSubscribersBuilder
.()
->
R
):
R
=
subscribeFriendMessages
(
coroutineContext
,
listeners
=
listeners
)
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