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
54794a6e
Commit
54794a6e
authored
May 10, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix references
parent
4bbdd588
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
48 additions
and
47 deletions
+48
-47
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
...core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
+2
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt
...src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt
+13
-13
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
.../net.mamoe.mirai/event/internal/InternalEventListeners.kt
+3
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/linear.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/event/linear.kt
+4
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/nextEvent.kt
.../src/commonMain/kotlin/net.mamoe.mirai/event/nextEvent.kt
+3
-3
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
...ore/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
+7
-7
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
...monMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
+5
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
...src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
+5
-5
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/utils.kt
...re/src/commonMain/kotlin/net.mamoe.mirai/message/utils.kt
+4
-4
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/JvmMethodListeners.kt
...vmMain/kotlin/net/mamoe/mirai/event/JvmMethodListeners.kt
+1
-1
mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt
...mTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt
+1
-1
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Event.kt
View file @
54794a6e
...
...
@@ -11,6 +11,7 @@
package
net.mamoe.mirai.event
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.event.internal.broadcastInternal
import
net.mamoe.mirai.utils.MiraiExperimentalAPI
import
net.mamoe.mirai.utils.MiraiInternalAPI
...
...
@@ -31,7 +32,7 @@ import kotlin.jvm.Volatile
* @see subscribeMessages
*
* @see [broadcast] 广播事件
* @see [subscribe] 监听事件
* @see [
CoroutineScope.
subscribe] 监听事件
*/
interface
Event
{
/**
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/deprecated.kt
View file @
54794a6e
...
...
@@ -68,7 +68,7 @@ abstract class AbstractCancellableEvent : AbstractEvent(), CancellableEvent
fun
<
R
>
Bot
.
subscribeMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
MessagePacketSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -94,7 +94,7 @@ fun <R> Bot.subscribeMessages(
fun
<
R
>
Bot
.
subscribeGroupMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
GroupMessageSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -120,7 +120,7 @@ fun <R> Bot.subscribeGroupMessages(
fun
<
R
>
Bot
.
subscribeFriendMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
FriendMessageSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -147,7 +147,7 @@ fun <R> Bot.subscribeFriendMessages(
fun
<
R
>
Bot
.
subscribeTempMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
TempMessageSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -172,7 +172,7 @@ fun <R> Bot.subscribeTempMessages(
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
incoming
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
capacity
:
Int
=
Channel
.
UNLIMITED
):
ReceiveChannel
<
E
>
{
return
Channel
<
E
>(
capacity
).
apply
{
...
...
@@ -192,7 +192,7 @@ fun <R> CoroutineScope.subscribeMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
MessagePacketSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
...
...
@@ -201,7 +201,7 @@ fun <R> CoroutineScope.subscribeGroupMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
GroupMessageSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeGroupMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeGroupMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -210,7 +210,7 @@ fun <R> CoroutineScope.subscribeFriendMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
FriendMessageSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeFriendMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeFriendMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -219,7 +219,7 @@ fun <R> CoroutineScope.subscribeTempMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
TempMessageSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeTempMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeTempMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -228,7 +228,7 @@ fun <R> Bot.subscribeMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
MessagePacketSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -237,7 +237,7 @@ fun <R> Bot.subscribeGroupMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
GroupMessageSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeGroupMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeGroupMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -246,7 +246,7 @@ fun <R> Bot.subscribeFriendMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
FriendMessageSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeFriendMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
):
R
=
this
.
subscribeFriendMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
...
...
@@ -255,4 +255,4 @@ fun <R> Bot.subscribeTempMessages(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listeners
:
TempMessageSubscribersBuilder
.()
->
R
):
R
=
this
.
subscribeTempMessages
(
coroutineContext
,
concurrencyKind
,
Listener
.
EventPriority
.
MONITOR
,
listeners
)
\ No newline at end of file
):
R
=
this
.
subscribeTempMessages
(
coroutineContext
,
concurrencyKind
,
EventPriority
.
MONITOR
,
listeners
)
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
View file @
54794a6e
...
...
@@ -47,7 +47,7 @@ internal fun <E : Event> CoroutineScope.Handler(
):
Handler
<
E
>
{
@OptIn
(
ExperimentalCoroutinesApi
::
class
)
// don't remove
val
context
=
this
.
newCoroutineContext
(
coroutineContext
)
return
Handler
(
context
[
Job
],
context
,
handler
,
concurrencyKind
,
Listener
.
EventPriority
.
NORMAL
)
return
Handler
(
context
[
Job
],
context
,
handler
,
concurrencyKind
,
EventPriority
.
NORMAL
)
}
...
...
@@ -55,7 +55,7 @@ internal fun <E : Event> CoroutineScope.Handler(
internal
fun
<
E
:
Event
>
CoroutineScope
.
Handler
(
coroutineContext
:
CoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
NORMAL
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
NORMAL
,
handler
:
suspend
(
E
)
->
ListeningStatus
):
Handler
<
E
>
{
@OptIn
(
ExperimentalCoroutinesApi
::
class
)
// don't remove
...
...
@@ -163,7 +163,7 @@ internal suspend fun <E : AbstractEvent> callAndRemoveIfRequired(
}
}
coroutineScope
{
GlobalEventListeners
[
Listener
.
EventPriority
.
MONITOR
].
forEachNode
{
eventNode
->
GlobalEventListeners
[
EventPriority
.
MONITOR
].
forEachNode
{
eventNode
->
if
(
event
.
isIntercepted
)
{
return
@
coroutineScope
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/linear.kt
View file @
54794a6e
...
...
@@ -35,7 +35,7 @@ import kotlin.reflect.KClass
@JvmSynthetic
suspend
inline
fun
<
reified
E
:
Event
,
R
:
Any
>
syncFromEvent
(
timeoutMillis
:
Long
=
-
1
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
crossinline
mapper
:
suspend
E
.(
E
)
->
R
?
):
R
{
require
(
timeoutMillis
==
-
1L
||
timeoutMillis
>
0
)
{
"timeoutMillis must be -1 or > 0"
}
...
...
@@ -68,7 +68,7 @@ suspend inline fun <reified E : Event, R : Any> syncFromEvent(
@JvmSynthetic
suspend
inline
fun
<
reified
E
:
Event
,
R
:
Any
>
syncFromEventOrNull
(
timeoutMillis
:
Long
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
crossinline
mapper
:
suspend
E
.(
E
)
->
R
?
):
R
?
{
require
(
timeoutMillis
>
0
)
{
"timeoutMillis must be > 0"
}
...
...
@@ -97,7 +97,7 @@ suspend inline fun <reified E : Event, R : Any> syncFromEventOrNull(
inline
fun
<
reified
E
:
Event
,
R
:
Any
>
CoroutineScope
.
asyncFromEventOrNull
(
timeoutMillis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
crossinline
mapper
:
suspend
E
.(
E
)
->
R
?
):
Deferred
<
R
?
>
{
require
(
timeoutMillis
==
-
1L
||
timeoutMillis
>
0
)
{
"timeoutMillis must be -1 or > 0"
}
...
...
@@ -126,7 +126,7 @@ inline fun <reified E : Event, R : Any> CoroutineScope.asyncFromEventOrNull(
inline
fun
<
reified
E
:
Event
,
R
:
Any
>
CoroutineScope
.
asyncFromEvent
(
timeoutMillis
:
Long
=
-
1
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
crossinline
mapper
:
suspend
E
.(
E
)
->
R
?
):
Deferred
<
R
>
{
require
(
timeoutMillis
==
-
1L
||
timeoutMillis
>
0
)
{
"timeoutMillis must be -1 or > 0"
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/nextEvent.kt
View file @
54794a6e
...
...
@@ -33,7 +33,7 @@ import kotlin.reflect.KClass
@JvmSynthetic
suspend
inline
fun
<
reified
E
:
Event
>
nextEvent
(
timeoutMillis
:
Long
=
-
1
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
):
E
{
require
(
timeoutMillis
==
-
1L
||
timeoutMillis
>
0
)
{
"timeoutMillis must be -1 or > 0"
}
return
withTimeoutOrCoroutineScope
(
timeoutMillis
)
{
...
...
@@ -55,7 +55,7 @@ suspend inline fun <reified E : Event> nextEvent(
@JvmSynthetic
suspend
inline
fun
<
reified
E
:
Event
>
nextEventOrNull
(
timeoutMillis
:
Long
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
):
E
?
{
return
withTimeoutOrNull
(
timeoutMillis
)
{
nextEventImpl
(
E
::
class
,
this
,
priority
)
...
...
@@ -79,7 +79,7 @@ suspend inline fun <reified E : Event> nextEventOrNull(
@JvmSynthetic
suspend
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
nextEvent
(
timeoutMillis
:
Long
=
-
1
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
):
E
{
require
(
timeoutMillis
==
-
1L
||
timeoutMillis
>
0
)
{
"timeoutMillis must be -1 or > 0"
}
return
withTimeoutOrCoroutineScope
(
timeoutMillis
)
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/select.kt
View file @
54794a6e
...
...
@@ -28,7 +28,7 @@ import kotlin.jvm.JvmSynthetic
*
* 创建的所有事件监听器都会判断发送人信息 ([isContextIdenticalWith]), 监听之后的所有消息.
*
* [selectBuilder] DSL 类似于 [subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
* [selectBuilder] DSL 类似于 [
CoroutineScope.
subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
*
* ```kotlin
* reply("开启复读模式")
...
...
@@ -62,7 +62,7 @@ import kotlin.jvm.JvmSynthetic
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
whileSelectMessages
(
timeoutMillis
:
Long
=
-
1
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
Boolean
>.()
->
Unit
)
=
whileSelectMessagesImpl
(
timeoutMillis
,
filterContext
,
priority
,
selectBuilder
)
...
...
@@ -75,7 +75,7 @@ suspend inline fun <reified T : MessageEvent> T.whileSelectMessages(
suspend
inline
fun
<
reified
T
:
MessageEvent
>
T
.
selectMessagesUnit
(
timeoutMillis
:
Long
=
-
1
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilderUnit
<
T
,
Unit
>.()
->
Unit
)
=
selectMessagesImpl
(
timeoutMillis
,
true
,
filterContext
,
priority
,
selectBuilder
)
...
...
@@ -85,7 +85,7 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
*
* 创建的所有事件监听器都会判断发送人信息 ([isContextIdenticalWith]), 监听之后的所有消息.
*
* [selectBuilder] DSL 类似于 [subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
* [selectBuilder] DSL 类似于 [
CoroutineScope.
subscribeMessages] 的 DSL, 屏蔽了一些 `reply` DSL 以确保类型安全
*
* ```kotlin
* val value: String = selectMessages {
...
...
@@ -105,7 +105,7 @@ suspend inline fun <reified T : MessageEvent> T.selectMessagesUnit(
suspend
inline
fun
<
reified
T
:
MessageEvent
,
R
>
T
.
selectMessages
(
timeoutMillis
:
Long
=
-
1
,
filterContext
:
Boolean
=
true
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
// @BuilderInference
crossinline
selectBuilder
:
@MessageDsl
MessageSelectBuilder
<
T
,
R
>.()
->
Unit
):
R
=
...
...
@@ -117,7 +117,7 @@ suspend inline fun <reified T : MessageEvent, R> T.selectMessages(
/**
* [selectMessages] 时的 DSL 构建器.
*
* 它是特殊化的消息监听 ([subscribeMessages]) DSL, 屏蔽了一些 `reply` DSL 以确保作用域安全性
* 它是特殊化的消息监听 ([
CoroutineScope.
subscribeMessages]) DSL, 屏蔽了一些 `reply` DSL 以确保作用域安全性
*
* @see MessageSelectBuilderUnit 查看上层 API
*/
...
...
@@ -232,7 +232,7 @@ abstract class MessageSelectBuilder<M : MessageEvent, R> @PublishedApi internal
/**
* [selectMessagesUnit] 或 [selectMessages] 时的 DSL 构建器.
*
* 它是特殊化的消息监听 ([subscribeMessages]) DSL
* 它是特殊化的消息监听 ([
CoroutineScope.
subscribeMessages]) DSL
*
* @see MessageSubscribersBuilder 查看上层 API
*/
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscribeMessages.kt
View file @
54794a6e
...
...
@@ -43,7 +43,7 @@ typealias MessagePacketSubscribersBuilder = MessageSubscribersBuilder<MessageEve
fun
<
R
>
CoroutineScope
.
subscribeMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
MessagePacketSubscribersBuilder
.()
->
R
):
R
{
// contract 可帮助 IDE 进行类型推断. 无实际代码作用.
...
...
@@ -77,7 +77,7 @@ typealias GroupMessageSubscribersBuilder = MessageSubscribersBuilder<GroupMessag
fun
<
R
>
CoroutineScope
.
subscribeGroupMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
GroupMessageSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -105,7 +105,7 @@ typealias FriendMessageSubscribersBuilder = MessageSubscribersBuilder<FriendMess
fun
<
R
>
CoroutineScope
.
subscribeFriendMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
FriendMessageSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -133,7 +133,7 @@ typealias TempMessageSubscribersBuilder = MessageSubscribersBuilder<TempMessageE
fun
<
R
>
CoroutineScope
.
subscribeTempMessages
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
listeners
:
TempMessageSubscribersBuilder
.()
->
R
):
R
{
contract
{
...
...
@@ -166,7 +166,7 @@ fun <R> CoroutineScope.subscribeTempMessages(
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
incoming
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrencyKind
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
capacity
:
Int
=
Channel
.
UNLIMITED
):
ReceiveChannel
<
E
>
{
return
Channel
<
E
>(
capacity
).
apply
{
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
View file @
54794a6e
...
...
@@ -62,7 +62,7 @@ enum class ListeningStatus {
/**
* 事件监听器.
* 由 [subscribe] 等方法返回.
* 由 [
CoroutineScope.
subscribe] 等方法返回.
*
* 取消监听: [complete]
*/
...
...
@@ -123,9 +123,9 @@ interface Listener<in E : Event> : CompletableJob {
val
priority
:
EventPriority
get
()
=
NORMAL
/**
* 这个方法将会调用 [subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`.
* 这个方法将会调用 [
CoroutineScope.
subscribe] 时提供的参数 `noinline handler: suspend E.(E) -> ListeningStatus`.
*
* 这个函数不会抛出任何异常, 详见 [subscribe]
* 这个函数不会抛出任何异常, 详见 [
CoroutineScope.
subscribe]
*/
suspend
fun
onEvent
(
event
:
E
):
ListeningStatus
}
...
...
@@ -220,7 +220,7 @@ inline fun <reified E : Event> CoroutineScope.subscribe(
):
Listener
<
E
>
=
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
,
handler
)
/**
* 与 [subscribe] 的区别是接受 [eventClass] 参数, 而不使用 `reified` 泛型
* 与 [
CoroutineScope.
subscribe] 的区别是接受 [eventClass] 参数, 而不使用 `reified` 泛型
*
* @see CoroutineScope.subscribe
*
...
...
@@ -281,7 +281,7 @@ fun <E : Event> CoroutineScope.subscribeAlways(
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
* @param priority 处理优先级, 优先级高的先执行
*
* @see subscribe 获取更多说明
* @see
CoroutineScope.
subscribe 获取更多说明
*/
@JvmSynthetic
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeOnce
(
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/utils.kt
View file @
54794a6e
...
...
@@ -48,7 +48,7 @@ fun MessageEvent.isContextIdenticalWith(another: MessageEvent): Boolean {
@JvmSynthetic
suspend
inline
fun
<
reified
P
:
MessageEvent
>
P
.
nextMessage
(
timeoutMillis
:
Long
=
-
1
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
noinline
filter
:
suspend
P
.(
P
)
->
Boolean
=
{
true
}
):
MessageChain
{
return
syncFromEvent
<
P
,
P
>(
timeoutMillis
,
priority
)
{
...
...
@@ -70,7 +70,7 @@ suspend inline fun <reified P : MessageEvent> P.nextMessage(
@JvmSynthetic
suspend
inline
fun
<
reified
P
:
MessageEvent
>
P
.
nextMessageOrNull
(
timeoutMillis
:
Long
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
noinline
filter
:
suspend
P
.(
P
)
->
Boolean
=
{
true
}
):
MessageChain
?
{
require
(
timeoutMillis
>
0
)
{
"timeoutMillis must be > 0"
}
...
...
@@ -86,7 +86,7 @@ suspend inline fun <reified P : MessageEvent> P.nextMessageOrNull(
inline
fun
<
reified
P
:
MessageEvent
>
P
.
nextMessageAsync
(
timeoutMillis
:
Long
=
-
1
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
noinline
filter
:
suspend
P
.(
P
)
->
Boolean
=
{
true
}
):
Deferred
<
MessageChain
>
{
return
this
.
bot
.
async
(
coroutineContext
)
{
...
...
@@ -103,7 +103,7 @@ inline fun <reified P : MessageEvent> P.nextMessageAsync(
inline
fun
<
reified
P
:
MessageEvent
>
P
.
nextMessageOrNullAsync
(
timeoutMillis
:
Long
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
MONITOR
,
priority
:
Listener
.
EventPriority
=
EventPriority
.
MONITOR
,
noinline
filter
:
suspend
P
.(
P
)
->
Boolean
=
{
true
}
):
Deferred
<
MessageChain
?
>
{
require
(
timeoutMillis
>
0
)
{
"timeoutMillis must be > 0"
}
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/JvmMethodListeners.kt
View file @
54794a6e
...
...
@@ -71,7 +71,7 @@ annotation class EventHandler(
* @see Listener.EventPriority
* @see Event.intercept
*/
val
priority
:
Listener
.
EventPriority
=
Listener
.
EventPriority
.
NORMAL
,
val
priority
:
Listener
.
EventPriority
=
EventPriority
.
NORMAL
,
/**
* 是否自动忽略被 [取消][CancellableEvent.isCancelled]
* @see CancellableEvent
...
...
mirai-core/src/jvmTest/kotlin/net/mamoe/mirai/event/JvmMethodEventsTest.kt
View file @
54794a6e
...
...
@@ -97,7 +97,7 @@ internal class JvmMethodEventsTest {
called
.
getAndIncrement
()
}
@EventHandler
(
Listener
.
EventPriority
.
MONITOR
)
@EventHandler
(
EventPriority
.
MONITOR
)
private
fun
TestEvent
.
`receiver
param
LS`
(
event
:
TestEvent
):
ListeningStatus
{
called
.
getAndIncrement
()
return
ListeningStatus
.
STOPPED
...
...
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