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
ace74374
Commit
ace74374
authored
Feb 20, 2020
by
jasonczc
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
588bfef8
3d4ff807
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
60 additions
and
17 deletions
+60
-17
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
...net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
+2
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
...rc/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
+43
-12
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
.../net.mamoe.mirai/event/internal/InternalEventListeners.kt
+6
-2
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
...commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
+1
-1
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
...Main/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
+5
-0
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt
...kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt
+3
-2
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/message/MessageSourceFromMsg.kt
View file @
ace74374
...
...
@@ -21,6 +21,7 @@ import net.mamoe.mirai.qqandroid.network.protocol.data.proto.SourceMsg
internal
inline
class
MessageSourceFromServer
(
val
delegate
:
ImMsgBody
.
SourceMsg
)
:
MessageSource
{
override
val
time
:
Long
get
()
=
delegate
.
time
.
toLong
()
and
0
xFFFFFFFF
override
val
messageUid
:
Long
get
()
=
delegate
.
pbReserve
.
loadAs
(
SourceMsg
.
ResvAttr
.
serializer
()).
origUids
!!
override
val
sourceMessage
:
MessageChain
get
()
=
delegate
.
toMessageChain
()
override
val
senderId
:
Long
get
()
=
delegate
.
senderUin
...
...
@@ -32,6 +33,7 @@ internal inline class MessageSourceFromServer(
internal
inline
class
MessageSourceFromMsg
(
val
delegate
:
MsgComm
.
Msg
)
:
MessageSource
{
override
val
time
:
Long
get
()
=
delegate
.
msgHead
.
msgTime
.
toLong
()
and
0
xFFFFFFFF
override
val
messageUid
:
Long
get
()
=
delegate
.
msgBody
.
richText
.
attr
!!
.
random
.
toLong
()
override
val
sourceMessage
:
MessageChain
get
()
=
delegate
.
toMessageChain
()
override
val
senderId
:
Long
get
()
=
delegate
.
msgHead
.
fromUin
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/Subscribers.kt
View file @
ace74374
...
...
@@ -22,6 +22,7 @@ import kotlin.contracts.ExperimentalContracts
import
kotlin.contracts.InvocationKind
import
kotlin.contracts.contract
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.JvmName
/*
...
...
@@ -98,6 +99,8 @@ interface Listener<in E : Event> : CompletableJob {
*
*
**
注意
:**
事件处理是
`suspend`
的
,
请规范处理
JVM
阻塞方法
.
*
*
@
param
coroutineContext
给事件监听协程的额外的
[
CoroutineContext
]
*
*
@
see
subscribeAlways
一直监听
*
@
see
subscribeOnce
只监听一次
*
...
...
@@ -106,8 +109,11 @@ interface Listener<in E : Event> : CompletableJob {
*
@
see
subscribeFriendMessages
监听好友消息
DSL
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
{
it
.
handler
(
it
);
})
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
(
coroutineContext
)
{
it
.
handler
(
it
);
})
/**
* 在指定的 [CoroutineScope] 下订阅所有 [E] 及其子类事件.
...
...
@@ -116,14 +122,19 @@ inline fun <reified E : Event> CoroutineScope.subscribe(noinline handler: suspen
* 可在任意时候通过 [Listener.complete] 来主动停止监听.
* [Bot] 被关闭后事件监听会被 [取消][Listener.cancel].
*
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
*
* @see subscribe 获取更多说明
*/
@UseExperimental
(
MiraiInternalAPI
::
class
,
ExperimentalContracts
::
class
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeAlways
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
contract
{
callsInPlace
(
listener
,
InvocationKind
.
UNKNOWN
)
}
return
E
::
class
.
subscribeInternal
(
Handler
{
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
})
return
E
::
class
.
subscribeInternal
(
Handler
(
coroutineContext
)
{
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
})
}
/**
...
...
@@ -133,11 +144,16 @@ inline fun <reified E : Event> CoroutineScope.subscribeAlways(noinline listener:
* 可在任意时候通过 [Listener.complete] 来主动停止监听.
* [Bot] 被关闭后事件监听会被 [取消][Listener.cancel].
*
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
*
* @see subscribe 获取更多说明
*/
@UseExperimental
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeOnce
(
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
{
it
.
listener
(
it
);
ListeningStatus
.
STOPPED
})
inline
fun
<
reified
E
:
Event
>
CoroutineScope
.
subscribeOnce
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
(
coroutineContext
)
{
it
.
listener
(
it
);
ListeningStatus
.
STOPPED
})
//
...
...
@@ -153,12 +169,17 @@ inline fun <reified E : Event> CoroutineScope.subscribeOnce(noinline listener: s
* 可在任意时候通过 [Listener.complete] 来主动停止监听.
* [Bot] 被关闭后事件监听会被 [取消][Listener.cancel].
*
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
*
* @see subscribe 获取更多说明
*/
@JvmName
(
"subscribeAlwaysForBot"
)
@UseExperimental
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribe
(
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
{
if
(
it
.
bot
===
this
)
it
.
handler
(
it
)
else
ListeningStatus
.
LISTENING
})
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribe
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
handler
:
suspend
E
.(
E
)
->
ListeningStatus
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
(
coroutineContext
)
{
if
(
it
.
bot
===
this
)
it
.
handler
(
it
)
else
ListeningStatus
.
LISTENING
})
/**
...
...
@@ -168,12 +189,17 @@ inline fun <reified E : BotEvent> Bot.subscribe(noinline handler: suspend E.(E)
* 可在任意时候通过 [Listener.complete] 来主动停止监听.
* [Bot] 被关闭后事件监听会被 [取消][Listener.cancel].
*
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
*
* @see subscribe 获取更多说明
*/
@JvmName
(
"subscribeAlwaysForBot1"
)
@UseExperimental
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeAlways
(
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
return
E
::
class
.
subscribeInternal
(
Handler
{
if
(
it
.
bot
===
this
)
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
})
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeAlways
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
{
return
E
::
class
.
subscribeInternal
(
Handler
(
coroutineContext
)
{
if
(
it
.
bot
===
this
)
it
.
listener
(
it
);
ListeningStatus
.
LISTENING
})
}
/**
...
...
@@ -183,12 +209,17 @@ inline fun <reified E : BotEvent> Bot.subscribeAlways(noinline listener: suspend
* 可在任意时候通过 [Listener.complete] 来主动停止监听.
* [Bot] 被关闭后事件监听会被 [取消][Listener.cancel].
*
* @param coroutineContext 给事件监听协程的额外的 [CoroutineContext]
*
* @see subscribe 获取更多说明
*/
@JvmName
(
"subscribeOnceForBot2"
)
@UseExperimental
(
MiraiInternalAPI
::
class
)
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeOnce
(
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
{
inline
fun
<
reified
E
:
BotEvent
>
Bot
.
subscribeOnce
(
coroutineContext
:
CoroutineContext
=
EmptyCoroutineContext
,
noinline
listener
:
suspend
E
.(
E
)
->
Unit
):
Listener
<
E
>
=
E
::
class
.
subscribeInternal
(
Handler
(
coroutineContext
)
{
if
(
it
.
bot
===
this
)
{
it
.
listener
(
it
)
ListeningStatus
.
STOPPED
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/event/internal/InternalEventListeners.kt
View file @
ace74374
...
...
@@ -31,8 +31,12 @@ fun <L : Listener<E>, E : Event> KClass<out E>.subscribeInternal(listener: L): L
@PublishedApi
@Suppress
(
"FunctionName"
)
internal
fun
<
E
:
Event
>
CoroutineScope
.
Handler
(
handler
:
suspend
(
E
)
->
ListeningStatus
):
Handler
<
E
>
{
return
Handler
(
coroutineContext
[
Job
],
coroutineContext
,
handler
)
internal
fun
<
E
:
Event
>
CoroutineScope
.
Handler
(
coroutineContext
:
CoroutineContext
,
handler
:
suspend
(
E
)
->
ListeningStatus
):
Handler
<
E
>
{
val
context
=
this
.
newCoroutineContext
(
coroutineContext
)
return
Handler
(
context
[
Job
],
context
,
handler
)
}
private
inline
fun
inline
(
block
:
()
->
Unit
)
=
block
()
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/Message.kt
View file @
ace74374
...
...
@@ -57,7 +57,7 @@ interface Message {
*/
interface
Key
<
M
:
Message
>
infix
fun
eq
(
other
:
Message
):
Boolean
=
this
==
other
infix
fun
eq
(
other
:
Message
):
Boolean
=
this
.
toString
()
==
other
.
toString
()
/**
* 将 [toString] 与 [other] 比较
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/data/MessageSource.kt
View file @
ace74374
...
...
@@ -31,6 +31,11 @@ interface MessageSource : Message {
*/
val
messageUid
:
Long
/**
* 发送时间, 单位为秒
*/
val
time
:
Long
/**
* 发送人号码
*/
...
...
mirai-core/src/jvmMain/kotlin/net/mamoe/mirai/event/internal/EventInternalJvm.kt
View file @
ace74374
...
...
@@ -16,15 +16,16 @@ import net.mamoe.mirai.event.ListeningStatus
import
net.mamoe.mirai.utils.MiraiInternalAPI
import
java.util.function.Consumer
import
java.util.function.Function
import
kotlin.coroutines.EmptyCoroutineContext
@MiraiInternalAPI
@Suppress
(
"FunctionName"
)
fun
<
E
:
Event
>
Class
<
E
>.
_subscribeEventForJaptOnly
(
scope
:
CoroutineScope
,
onEvent
:
Function
<
E
,
ListeningStatus
>):
Listener
<
E
>
{
return
this
.
kotlin
.
subscribeInternal
(
scope
.
Handler
{
onEvent
.
apply
(
it
)
})
return
this
.
kotlin
.
subscribeInternal
(
scope
.
Handler
(
EmptyCoroutineContext
)
{
onEvent
.
apply
(
it
)
})
}
@MiraiInternalAPI
@Suppress
(
"FunctionName"
)
fun
<
E
:
Event
>
Class
<
E
>.
_subscribeEventForJaptOnly
(
scope
:
CoroutineScope
,
onEvent
:
Consumer
<
E
>):
Listener
<
E
>
{
return
this
.
kotlin
.
subscribeInternal
(
scope
.
Handler
{
onEvent
.
accept
(
it
);
ListeningStatus
.
LISTENING
;
})
return
this
.
kotlin
.
subscribeInternal
(
scope
.
Handler
(
EmptyCoroutineContext
)
{
onEvent
.
accept
(
it
);
ListeningStatus
.
LISTENING
;
})
}
\ 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