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
069a88e8
Commit
069a88e8
authored
Apr 21, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove senseless contracts
parent
d94b1d32
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
42 deletions
+16
-42
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
...src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
+16
-42
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/subscriber.kt
View file @
069a88e8
...
@@ -20,9 +20,6 @@ import net.mamoe.mirai.event.internal.Handler
...
@@ -20,9 +20,6 @@ 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.MiraiInternalAPI
import
net.mamoe.mirai.utils.SinceMirai
import
net.mamoe.mirai.utils.SinceMirai
import
kotlin.contracts.ExperimentalContracts
import
kotlin.contracts.InvocationKind
import
kotlin.contracts.contract
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.JvmName
import
kotlin.jvm.JvmName
...
@@ -125,7 +122,7 @@ interface Listener<in E : Event> : CompletableJob {
...
@@ -125,7 +122,7 @@ interface Listener<in E : Event> : CompletableJob {
*
@
param
concurrency
并发类型
.
查看
[
Listener
.
ConcurrencyKind
]
*
@
param
concurrency
并发类型
.
查看
[
Listener
.
ConcurrencyKind
]
*
*
*
@
see
syncFromEvent
监听一个事件
,
并尝试从这个事件中获取一个值
.
*
@
see
syncFromEvent
监听一个事件
,
并尝试从这个事件中获取一个值
.
*
@
see
syncFromEventAsync
异步监听一个事件
,
并尝试从这个事件中获取一个值
.
*
@
see
asyncFromEvent
异步监听一个事件
,
并尝试从这个事件中获取一个值
.
*
*
*
@
see
selectMessages
以
`when`
的语法
'选择'
即将到来的一条消息
.
*
@
see
selectMessages
以
`when`
的语法
'选择'
即将到来的一条消息
.
*
@
see
whileSelectMessages
以
`when`
的语法
'选择'
即将到来的所有消息
,
直到不满足筛选结果
.
*
@
see
whileSelectMessages
以
`when`
的语法
'选择'
即将到来的所有消息
,
直到不满足筛选结果
.
...
@@ -137,17 +134,11 @@ interface Listener<in E : Event> : CompletableJob {
...
@@ -137,17 +134,11 @@ interface Listener<in E : Event> : CompletableJob {
*
@
see
subscribeGroupMessages
监听群消息
DSL
*
@
see
subscribeGroupMessages
监听群消息
DSL
*
@
see
subscribeFriendMessages
监听好友消息
DSL
*
@
see
subscribeFriendMessages
监听好友消息
DSL
*/
*/
@OptIn
(
ExperimentalContracts
::
class
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
{
):
Listener
<
E
>
=
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
handler
)
contract
{
callsInPlace
(
handler
,
InvocationKind
.
UNKNOWN
)
}
return
subscribe
(
E
::
class
,
coroutineContext
,
concurrency
,
handler
)
}
/**
/**
* @see CoroutineScope.subscribe
* @see CoroutineScope.subscribe
...
@@ -158,8 +149,7 @@ fun <E : Event> CoroutineScope.subscribe(
...
@@ -158,8 +149,7 @@ fun <E : Event> CoroutineScope.subscribe(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
)
{
it
.
handler
(
it
);
})
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
)
{
it
.
handler
(
it
);
})
/**
/**
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
...
@@ -172,36 +162,24 @@ fun <E : Event> CoroutineScope.subscribe(
...
@@ -172,36 +162,24 @@ fun <E : Event> CoroutineScope.subscribe(
*
*
* @see CoroutineScope.subscribe 获取更多说明
* @see CoroutineScope.subscribe 获取更多说明
*/
*/
@OptIn
(
ExperimentalContracts
::
class
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
):
Listener
<
E
>
=
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
listener
)
contract
{
callsInPlace
(
listener
,
InvocationKind
.
UNKNOWN
)
}
return
subscribeAlways
(
E
::
class
,
coroutineContext
,
concurrency
,
listener
)
}
/**
/**
* @see CoroutineScope.subscribeAlways
* @see CoroutineScope.subscribeAlways
*/
*/
@SinceMirai
(
"0.38.0"
)
@SinceMirai
(
"0.38.0"
)
@OptIn
(
ExperimentalContracts
::
class
)
fun
<
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
fun
<
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
eventClass
:
KClass
<
E
>,
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
listener
:
suspend
E
.(
E
)
->
Unit
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
contract
{
Handler
(
coroutineContext
,
concurrency
)
{
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
}
callsInPlace
(
listener
,
InvocationKind
.
UNKNOWN
)
)
}
return
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
)
{
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
}
)
}
/**
/**
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
...
@@ -228,10 +206,9 @@ fun <E : Event> CoroutineScope.subscribeOnce(
...
@@ -228,10 +206,9 @@ fun <E : Event> CoroutineScope.subscribeOnce(
eventClass
:
KClass
<
E
>,
eventClass
:
KClass
<
E
>,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
listener
:
suspend
E
.(
E
)
->
Unit
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
Listener
.
ConcurrencyKind
.
LOCKED
)
{
it
.
listener
(
it
);
ListeningStatus
.
STOPPED
}
Handler
(
coroutineContext
,
Listener
.
ConcurrencyKind
.
LOCKED
)
{
it
.
listener
(
it
);
ListeningStatus
.
STOPPED
}
)
)
//
//
// 以下为带筛选 Bot 的监听
// 以下为带筛选 Bot 的监听
...
@@ -268,10 +245,9 @@ fun <E : BotEvent> Bot.subscribe(
...
@@ -268,10 +245,9 @@ fun <E : BotEvent> Bot.subscribe(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
LOCKED
,
handler
:
suspend
E
.(
E
)
->
ListeningStatus
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
)
{
if
(
it
.
bot
===
this
)
it
.
handler
(
it
)
else
ListeningStatus
.
LISTENING
}
Handler
(
coroutineContext
,
concurrency
)
{
if
(
it
.
bot
===
this
)
it
.
handler
(
it
)
else
ListeningStatus
.
LISTENING
}
)
)
/**
/**
...
@@ -303,11 +279,9 @@ fun <E : BotEvent> Bot.subscribeAlways(
...
@@ -303,11 +279,9 @@ fun <E : BotEvent> Bot.subscribeAlways(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
concurrency
:
Listener
.
ConcurrencyKind
=
Listener
.
ConcurrencyKind
.
CONCURRENT
,
listener
:
suspend
E
.(
E
)
->
Unit
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
):
Listener
<
E
>
=
eventClass
.
subscribeInternal
(
return
eventClass
.
subscribeInternal
(
Handler
(
coroutineContext
,
concurrency
)
{
if
(
it
.
bot
===
this
)
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
}
Handler
(
coroutineContext
,
concurrency
)
{
if
(
it
.
bot
===
this
)
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
}
)
)
}
/**
/**
* 在 [Bot] 的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
* 在 [Bot] 的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
...
...
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