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
db13a867
Commit
db13a867
authored
Feb 17, 2020
by
ryoii
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
8985c20c
9710e34d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
4 deletions
+31
-4
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
...onMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
+20
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
.../net.mamoe.mirai/event/internal/InternalEventListeners.kt
+11
-2
No files found.
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/MessageSubscribers.kt
View file @
db13a867
...
...
@@ -28,6 +28,8 @@ import kotlin.contracts.contract
/**
* 订阅来自所有 [Bot] 的所有联系人的消息事件. 联系人可以是任意群或任意好友或临时会话.
*
* @see CoroutineScope.incoming
*/
@UseExperimental
(
ExperimentalContracts
::
class
)
@MessageDsl
...
...
@@ -49,6 +51,8 @@ inline fun <R> CoroutineScope.subscribeMessages(crossinline listeners: MessageSu
/**
* 订阅来自所有 [Bot] 的所有群消息事件
*
* @see CoroutineScope.incoming
*/
@UseExperimental
(
ExperimentalContracts
::
class
)
@MessageDsl
...
...
@@ -65,6 +69,8 @@ inline fun <R> CoroutineScope.subscribeGroupMessages(crossinline listeners: Mess
/**
* 订阅来自所有 [Bot] 的所有好友消息事件
*
* @see CoroutineScope.incoming
*/
@UseExperimental
(
ExperimentalContracts
::
class
)
@MessageDsl
...
...
@@ -81,6 +87,8 @@ inline fun <R> CoroutineScope.subscribeFriendMessages(crossinline listeners: Mes
/**
* 订阅来自这个 [Bot] 的所有联系人的消息事件. 联系人可以是任意群或任意好友或临时会话.
*
* @see CoroutineScope.incoming
*/
@UseExperimental
(
ExperimentalContracts
::
class
)
@MessageDsl
...
...
@@ -97,6 +105,8 @@ inline fun <R> Bot.subscribeMessages(crossinline listeners: MessageSubscribersBu
/**
* 订阅来自这个 [Bot] 的所有群消息事件
*
* @see CoroutineScope.incoming
*/
@UseExperimental
(
ExperimentalContracts
::
class
)
@MessageDsl
...
...
@@ -113,6 +123,8 @@ inline fun <R> Bot.subscribeGroupMessages(crossinline listeners: MessageSubscrib
/**
* 订阅来自这个 [Bot] 的所有好友消息事件.
*
* @see CoroutineScope.incoming
*/
@UseExperimental
(
ExperimentalContracts
::
class
)
@MessageDsl
...
...
@@ -129,9 +141,15 @@ inline fun <R> Bot.subscribeFriendMessages(crossinline listeners: MessageSubscri
/**
* 返回一个指定事件的接收通道
*
* @param capacity 同 [Channel] 的参数, 参见 [Channel.Factory] 中的常量.
*
* @see subscribeFriendMessages
* @see subscribeMessages
* @see subscribeGroupMessages
*/
inline
fun
<
reified
E
:
Event
>
Bot
.
incoming
(
):
ReceiveChannel
<
E
>
{
return
Channel
<
E
>(
8
).
apply
{
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
incoming
(
capacity
:
Int
=
Channel
.
RENDEZVOUS
):
ReceiveChannel
<
E
>
{
return
Channel
<
E
>(
capacity
).
apply
{
subscribeAlways
<
E
>
{
send
(
this
)
}
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
View file @
db13a867
...
...
@@ -90,6 +90,15 @@ internal object EventListenerManager {
private
val
lock
=
atomic
(
false
)
private
fun
setLockValue
(
value
:
Boolean
)
{
lock
.
value
=
value
}
@Suppress
(
"BooleanLiteralArgument"
)
private
fun
trySetLockTrue
():
Boolean
{
return
lock
.
compareAndSet
(
false
,
true
)
}
@Suppress
(
"UNCHECKED_CAST"
,
"BooleanLiteralArgument"
)
internal
tailrec
fun
<
E
:
Event
>
get
(
clazz
:
KClass
<
out
E
>):
EventListeners
<
E
>
{
registries
.
forEach
{
...
...
@@ -97,10 +106,10 @@ internal object EventListenerManager {
return
it
.
listeners
as
EventListeners
<
E
>
}
}
if
(
lock
.
compareAndSet
(
false
,
true
))
{
if
(
trySetLockTrue
(
))
{
val
registry
=
Registry
(
clazz
,
EventListeners
())
registries
.
addLast
(
registry
)
lock
.
value
=
false
setLockValue
(
false
)
return
registry
.
listeners
as
EventListeners
<
E
>
}
return
get
(
clazz
)
...
...
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