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
cbdc8bb0
Commit
cbdc8bb0
authored
May 09, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support Kotlin functional references in event subscribing
parent
346aecd6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
484 additions
and
309 deletions
+484
-309
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
...src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
+137
-309
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt
...Main/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt
+347
-0
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
View file @
cbdc8bb0
...
@@ -8,6 +8,8 @@
...
@@ -8,6 +8,8 @@
*/
*/
@
file
:
Suppress
(
"unused"
,
"DEPRECATION"
,
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
@
file
:
Suppress
(
"unused"
,
"DEPRECATION"
,
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
@
file
:
JvmName
(
"SubscriberKt"
)
@
file
:
JvmMultifileClass
package
net.mamoe.mirai.event
package
net.mamoe.mirai.event
...
@@ -23,12 +25,12 @@ import net.mamoe.mirai.event.Listener.EventPriority.*
...
@@ -23,12 +25,12 @@ import net.mamoe.mirai.event.Listener.EventPriority.*
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.event.internal.Handler
import
net.mamoe.mirai.event.internal.Handler
import
net.mamoe.mirai.event.internal.subscribeInternal
import
net.mamoe.mirai.event.internal.subscribeInternal
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.MiraiLogger
import
net.mamoe.mirai.utils.PlannedRemoval
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.internal.LowPriorityInOverloadResolution
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmStatic
import
kotlin.jvm.JvmStatic
import
kotlin.jvm.JvmSynthetic
import
kotlin.jvm.JvmSynthetic
...
@@ -128,7 +130,7 @@ interface Listener<in E : Event> : CompletableJob {
...
@@ -128,7 +130,7 @@ interface Listener<in E : Event> : CompletableJob {
suspend
fun
onEvent
(
event
:
E
):
ListeningStatus
suspend
fun
onEvent
(
event
:
E
):
ListeningStatus
}
}
// region
顶层方法 创建当前 coroutineContext 下的子 Job
// region
subscribe / subscribeAlways / subscribeOnce
/**
/**
* 在指定的 [协程作用域][CoroutineScope] 下创建一个事件监听器, 监听所有 [E] 及其子类事件.
* 在指定的 [协程作用域][CoroutineScope] 下创建一个事件监听器, 监听所有 [E] 及其子类事件.
...
@@ -298,352 +300,178 @@ fun <E : Event> CoroutineScope.subscribeOnce(
...
@@ -298,352 +300,178 @@ fun <E : Event> CoroutineScope.subscribeOnce(
Handler
(
coroutineContext
,
LOCKED
,
priority
)
{
it
.
handler
(
it
);
ListeningStatus
.
STOPPED
}
Handler
(
coroutineContext
,
LOCKED
,
priority
)
{
it
.
handler
(
it
);
ListeningStatus
.
STOPPED
}
)
)
//
// 以下为带筛选 Bot 的监听 (已启用)
// endregion
//
// region subscribe for Kotlin functional reference
/**
/**
* **注意:** 与 [CoroutineScope.subscribe] 不同的是,
* 支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.
* [Bot.subscribe] 会筛选事件来源 [Bot], 只监听来自 [this] 的事件.
*
*
* @see CoroutineScope.subscribe 获取更多说明
* ```
* fun onMessage(event: GroupMessageEvent): ListeningStatus {
* return ListeningStatus.LISTENING
* }
*
* scope.subscribe(::onMessage)
* ```
*/
*/
@PlannedRemoval
(
"1.3.0"
)
@Suppress
(
"DeprecatedCallableAddReplaceWith"
,
"DEPRECATION"
)
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot"
)
@LowPriorityInOverloadResolution
@OptIn
(
MiraiInternalAPI
::
class
)
@JvmName
(
"subscribe1"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
@Deprecated
(
crossinline
handler
:
(
E
)
->
ListeningStatus
,
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
):
Listener
<
E
>
=
this
.
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
,
handler
)
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
):
Listener
<
E
>
=
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
/**
/**
* **注意:** 与 [CoroutineScope.subscribe] 不同的是,
* 支持 Kotlin 带接收者的函数的函数引用的监听方式.
* [Bot.subscribe] 会筛选事件来源 [Bot], 只监听来自 [this] 的事件.
*
*
* @see Bot.subscribe
* ```
*/
* fun GroupMessageEvent.onMessage(event: GroupMessageEvent): ListeningStatus {
@PlannedRemoval
(
"1.3.0"
)
* return ListeningStatus.LISTENING
@Suppress
(
"DeprecatedCallableAddReplaceWith"
)
* }
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
E
:
BotEvent
>
Bot
.
subscribe
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
,
priority
)
{
if
(
it
.
bot
===
this
)
it
.
handler
(
it
)
else
ListeningStatus
.
LISTENING
}
)
/**
* **注意:** 与 [CoroutineScope.subscribe] 不同的是,
* [Bot.subscribe] 会筛选事件来源 [Bot], 只监听来自 [this] 的事件.
*
*
* @see CoroutineScope.subscribeAlways 获取更多说明
* scope.subscribe(GroupMessageEvent::onMessage)
* ```
*/
*/
@PlannedRemoval
(
"1.3.0"
)
@Suppress
(
"DeprecatedCallableAddReplaceWith"
)
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot1"
)
@LowPriorityInOverloadResolution
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@JvmName
(
"subscribe2"
)
@OptIn
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
@Deprecated
(
crossinline
handler
:
E
.(
E
)
->
ListeningStatus
,
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeAlways
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
,
listener
)
/**
* **注意:** 与 [CoroutineScope.subscribe] 不同的是,
* [Bot.subscribe] 会筛选事件来源 [Bot], 只监听来自 [this] 的事件.
*
* @see Bot.subscribeAlways
*/
@PlannedRemoval
(
"1.3.0"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeAlways
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
,
priority
)
{
if
(
it
.
bot
===
this
)
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
}
)
/**
/**
* **注意:** 与 [CoroutineScope.subscribe] 不同的是,
* 支持 Kotlin 挂起函数的函数引用的监听方式.
* [Bot.subscribe] 会筛选事件来源 [Bot], 只监听来自 [this] 的事件.
*
*
* @see subscribeOnce 获取更多说明
* ```
* suspend fun onMessage(event: GroupMessageEvent): ListeningStatus {
* return ListeningStatus.LISTENING
* }
*
* scope.subscribe(::onMessage)
* ```
*/
*/
@Suppress
(
"DeprecatedCallableAddReplaceWith"
)
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribeOnceForBot2"
)
@LowPriorityInOverloadResolution
@PlannedRemoval
(
"1.3.0"
)
@JvmName
(
"subscribe1"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
@Deprecated
(
crossinline
handler
:
suspend
(
E
)
->
ListeningStatus
,
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeOnce
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
):
Listener
<
E
>
=
subscribeOnce
(
E
::
class
,
coroutineContext
,
priority
,
listener
)
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
):
Listener
<
E
>
=
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
/**
/**
* **注意:** 与 [CoroutineScope.subscribe] 不同的是,
* 支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.
* [Bot.subscribe] 会筛选事件来源 [Bot], 只监听来自 [this] 的事件.
*
*
* @see Bot.subscribeOnce
* ```
* suspend fun GroupMessageEvent.onMessage(event: GroupMessageEvent): ListeningStatus {
* return ListeningStatus.LISTENING
* }
*
* scope.subscribe(GroupMessageEvent::onMessage)
* ```
*/
*/
@PlannedRemoval
(
"1.3.0"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeOnce
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
LOCKED
,
priority
)
{
if
(
it
.
bot
===
this
)
{
it
.
listener
(
it
)
ListeningStatus
.
STOPPED
}
else
ListeningStatus
.
LISTENING
})
// endregion
// region 为了兼容旧版本的方法
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribe"
)
@JvmSynthetic
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@LowPriorityInOverloadResolution
@Suppress
(
"unused"
)
@JvmName
(
"subscribe3"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeDeprecated
(
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
crossinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
):
Listener
<
E
>
=
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
coroutineContext
=
coroutineContext
,
):
Listener
<
E
>
=
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribe"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
subscribe
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribeAlways"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlwaysDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
// endregion
@JvmName
(
"subscribeAlways"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeAlwaysDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribeOnce"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeOnceDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
// region subscribeAlways for Kotlin functional references
@JvmName
(
"subscribeOnce"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeOnceDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot"
)
@OptIn
(
MiraiInternalAPI
::
class
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
this
.
subscribe
(
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
/**
* 支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.
* ```
* fun onMessage(event: GroupMessageEvent) {
*
* }
* scope.subscribeAlways(::onMessage)
* ```
*/
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribe"
)
@LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@JvmName
(
"subscribeAlways1"
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
fun
<
E
:
BotEvent
>
Bot
.
subscribeDeprecated
(
crossinline
handler
:
(
E
)
->
Unit
,
eventClass
:
KClass
<
E
>,
priority
:
Listener
.
EventPriority
=
NORMAL
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
):
Listener
<
E
>
=
subscribe
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
/**
* 支持 Kotlin 带接收者的函数的函数引用的监听方式.
* ```
* fun GroupMessageEvent.onMessage(event: GroupMessageEvent) {
*
* }
* scope.subscribeAlways(GroupMessageEvent::onMessage)
* ```
*/
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot1"
)
@LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@JvmName
(
"subscribeAlways1"
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
@OptIn
(
MiraiInternalAPI
::
class
)
crossinline
handler
:
E
.(
E
)
->
Unit
,
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeAlwaysDeprecated
(
priority
:
Listener
.
EventPriority
=
NORMAL
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
):
Listener
<
E
>
=
subscribeAlways
(
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
/**
* 支持 Kotlin 挂起函数的函数引用的监听方式.
* ```
* suspend fun onMessage(event: GroupMessageEvent) {
*
* }
* scope.subscribeAlways(::onMessage)
* ```
*/
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribeAlways"
)
@LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@JvmName
(
"subscribe4"
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
fun
<
E
:
BotEvent
>
Bot
.
subscribeAlwaysDeprecated
(
crossinline
handler
:
suspend
(
E
)
->
Unit
,
eventClass
:
KClass
<
E
>,
priority
:
Listener
.
EventPriority
=
NORMAL
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
listener
:
suspend
E
.(
E
)
->
Unit
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
):
Listener
<
E
>
=
subscribeAlways
(
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
/**
* 支持 Kotlin 带接收者的挂起函数的函数引用的监听方式.
* ```
* suspend fun GroupMessageEvent.onMessage(event: GroupMessageEvent) {
*
* }
* scope.subscribeAlways(GroupMessageEvent::onMessage)
* ```
*/
@JvmSynthetic
@JvmSynthetic
@JvmName
(
"subscribeOnceForBot2"
)
@LowPriorityInOverloadResolution
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@JvmName
(
"subscribe1"
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeOnceDeprecated
(
crossinline
handler
:
suspend
E
.(
E
)
->
Unit
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
):
Listener
<
E
>
=
subscribeOnce
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
coroutineContext
=
coroutineContext
,
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
)
{
handler
(
this
)
}
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeOnce"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeOnceDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
// endregion
// endregion
\ No newline at end of file
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriberDeprecated.kt
0 → 100644
View file @
cbdc8bb0
/*
* 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
*/
@
file
:
Suppress
(
"unused"
,
"DEPRECATION"
,
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
@
file
:
JvmName
(
"SubscriberKt"
)
@
file
:
JvmMultifileClass
package
net.mamoe.mirai.event
import
kotlinx.coroutines.CoroutineScope
import
net.mamoe.mirai.Bot
import
net.mamoe.mirai.event.Listener.ConcurrencyKind.CONCURRENT
import
net.mamoe.mirai.event.Listener.ConcurrencyKind.LOCKED
import
net.mamoe.mirai.event.Listener.EventPriority.MONITOR
import
net.mamoe.mirai.event.Listener.EventPriority.NORMAL
import
net.mamoe.mirai.event.events.BotEvent
import
net.mamoe.mirai.event.internal.Handler
import
net.mamoe.mirai.event.internal.subscribeInternal
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
net.mamoe.mirai.utils.PlannedRemoval
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.JvmMultifileClass
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmSynthetic
import
kotlin.reflect.KClass
//
// 以下为带筛选 Bot 的监听 (已启用)
//
@PlannedRemoval
(
"1.3.0"
)
@Suppress
(
"DeprecatedCallableAddReplaceWith"
,
"DEPRECATION"
)
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot"
)
@OptIn
(
MiraiInternalAPI
::
class
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
this
.
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
,
handler
)
@PlannedRemoval
(
"1.3.0"
)
@Suppress
(
"DeprecatedCallableAddReplaceWith"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
E
:
BotEvent
>
Bot
.
subscribe
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
,
priority
)
{
if
(
it
.
bot
===
this
)
it
.
handler
(
it
)
else
ListeningStatus
.
LISTENING
}
)
@PlannedRemoval
(
"1.3.0"
)
@Suppress
(
"DeprecatedCallableAddReplaceWith"
)
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot1"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@OptIn
(
MiraiInternalAPI
::
class
)
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeAlways
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
priority
,
listener
)
@PlannedRemoval
(
"1.3.0"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeAlways
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
,
priority
)
{
if
(
it
.
bot
===
this
)
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
}
)
@Suppress
(
"DeprecatedCallableAddReplaceWith"
)
@JvmSynthetic
@JvmName
(
"subscribeOnceForBot2"
)
@PlannedRemoval
(
"1.3.0"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeOnce
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
E
::
class
,
coroutineContext
,
priority
,
listener
)
@PlannedRemoval
(
"1.3.0"
)
@
kotlin
.
internal
.
LowPriorityInOverloadResolution
@Deprecated
(
"Deprecated for better Coroutine life cycle management. Please filter bot instance on your own."
,
level
=
DeprecationLevel
.
HIDDEN
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeOnce
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
priority
:
Listener
.
EventPriority
=
NORMAL
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
LOCKED
,
priority
)
{
if
(
it
.
bot
===
this
)
{
it
.
listener
(
it
)
ListeningStatus
.
STOPPED
}
else
ListeningStatus
.
LISTENING
})
// endregion
// region 为了兼容旧版本的方法
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribe"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
subscribe
(
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribe"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
subscribe
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribeAlways"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlwaysDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribeAlways"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeAlwaysDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribeOnce"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeOnceDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmName
(
"subscribeOnce"
)
@JvmSynthetic
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeOnceDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot"
)
@OptIn
(
MiraiInternalAPI
::
class
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
this
.
subscribe
(
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribe"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
LOCKED
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
subscribe
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
handler
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeAlwaysForBot1"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
@OptIn
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeAlwaysDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeAlways"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeAlwaysDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
CONCURRENT
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeAlways
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
concurrency
=
concurrency
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeOnceForBot2"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeOnceDeprecated
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
@PlannedRemoval
(
"1.2.0"
)
@JvmSynthetic
@JvmName
(
"subscribeOnce"
)
@Deprecated
(
"for binary compatibility"
,
level
=
DeprecationLevel
.
HIDDEN
)
@Suppress
(
"unused"
)
fun
<
E
:
BotEvent
>
Bot
.
subscribeOnceDeprecated
(
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
subscribeOnce
(
eventClass
=
eventClass
,
coroutineContext
=
coroutineContext
,
priority
=
MONITOR
,
handler
=
listener
)
// endregion
\ No newline at end of file
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