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
5485ffe8
Commit
5485ffe8
authored
May 24, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support Bot.isOnline, close #342
parent
ab464388
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
43 additions
and
13 deletions
+43
-13
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt
...rc/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt
+2
-0
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt
...in/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt
+7
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt
...in/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/BotNetworkHandler.kt
...in/net/mamoe/mirai/qqandroid/network/BotNetworkHandler.kt
+1
-1
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
...moe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
+4
-2
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt
...protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt
+1
-0
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
+27
-8
No files found.
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/BotImpl.kt
View file @
5485ffe8
...
...
@@ -45,6 +45,8 @@ internal abstract class BotImpl<N : BotNetworkHandler> constructor(
@Suppress
(
"PropertyName"
)
internal
lateinit
var
_network
:
N
override
val
isOnline
:
Boolean
get
()
=
_network
.
areYouOk
()
/**
* Close server connection, resend login packet, BUT DOESN'T [BotNetworkHandler.init]
*/
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/FriendImpl.kt
View file @
5485ffe8
...
...
@@ -8,7 +8,13 @@
*/
@
file
:
OptIn
(
LowLevelAPI
::
class
)
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"DEPRECATION_ERROR"
,
"NOTHING_TO_INLINE"
)
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"DEPRECATION_ERROR"
,
"NOTHING_TO_INLINE"
,
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
package
net.mamoe.mirai.qqandroid.contact
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/contact/MemberImpl.kt
View file @
5485ffe8
...
...
@@ -7,7 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"DEPRECATION_ERROR"
)
@
file
:
Suppress
(
"EXPERIMENTAL_API_USAGE"
,
"DEPRECATION_ERROR"
,
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
package
net.mamoe.mirai.qqandroid.contact
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/BotNetworkHandler.kt
View file @
5485ffe8
...
...
@@ -86,10 +86,10 @@ internal abstract class BotNetworkHandler : CoroutineScope {
/**
* 当 [Bot] 正常运作时, 这个函数将一直挂起协程到 [Bot] 被 [Bot.close]
* 当 [Bot] 离线时, 这个函数立即返回.
*/
abstract
suspend
fun
join
()
// cool name
abstract
fun
areYouOk
():
Boolean
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/QQAndroidBotNetworkHandler.kt
View file @
5485ffe8
...
...
@@ -64,8 +64,10 @@ internal class QQAndroidBotNetworkHandler(coroutineContext: CoroutineContext, bo
private
val
packetReceiveLock
:
Mutex
=
Mutex
()
override
fun
areYouOk
():
Boolean
{
return
this
.
isActive
&&
::
channel
.
isInitialized
&&
channel
.
isOpen
&&
heartbeatJob
?.
isActive
==
true
&&
_packetReceiverJob
?.
isActive
==
true
return
kotlin
.
runCatching
{
this
.
isActive
&&
::
channel
.
isInitialized
&&
channel
.
isOpen
&&
heartbeatJob
?.
isActive
==
true
&&
_packetReceiverJob
?.
isActive
==
true
}.
getOrElse
{
false
}
}
private
suspend
fun
startPacketReceiverJobOrKill
(
cancelCause
:
CancellationException
?
=
null
):
Job
{
...
...
mirai-core-qqandroid/src/commonMain/kotlin/net/mamoe/mirai/qqandroid/network/protocol/packet/chat/receive/OnlinePush.PbPushGroupMsg.kt
View file @
5485ffe8
...
...
@@ -7,6 +7,7 @@
* https://github.com/mamoe/mirai/blob/master/LICENSE
*/
@
file
:
Suppress
(
"INVISIBLE_MEMBER"
,
"INVISIBLE_REFERENCE"
)
package
net.mamoe.mirai.qqandroid.network.protocol.packet.chat.receive
import
kotlinx.io.core.ByteReadPacket
...
...
mirai-core/src/commonMain/kotlin/net.mamoe.mirai/Bot.kt
View file @
5485ffe8
...
...
@@ -25,6 +25,7 @@ import net.mamoe.mirai.network.LoginFailedException
import
net.mamoe.mirai.utils.*
import
kotlin.coroutines.CoroutineContext
import
kotlin.coroutines.EmptyCoroutineContext
import
kotlin.jvm.JvmField
import
kotlin.jvm.JvmStatic
import
kotlin.jvm.JvmSynthetic
...
...
@@ -41,22 +42,25 @@ suspend inline fun <B : Bot> B.alsoLogin(): B = also { login() }
* 有关 [Bot] 生命管理, 请查看 [BotConfiguration.inheritCoroutineContext]
*
* @see Contact 联系人
* @see kotlinx.coroutines.isActive 判断 [Bot] 是否正常运行中. (
在线, 且没有被 [clos
e])
* @see kotlinx.coroutines.isActive 判断 [Bot] 是否正常运行中. (
协程正常运行) (但不能判断是否在线, 需使用 [isOnlin
e])
*
* @see BotFactory 构造 [Bot] 的工厂, [Bot] 唯一的构造方式.
*/
@Suppress
(
"INAPPLICABLE_JVM_NAME"
,
"EXPOSED_SUPER_CLASS"
)
abstract
class
Bot
(
abstract
class
Bot
internal
constructor
(
val
configuration
:
BotConfiguration
)
:
CoroutineScope
,
LowLevelBotAPIAccessor
,
BotJavaFriendlyAPI
,
ContactOrBot
{
final
override
val
coroutineContext
:
CoroutineContext
=
configuration
.
parentCoroutineContext
+
SupervisorJob
(
configuration
.
parentCoroutineContext
[
Job
])
+
(
configuration
.
parentCoroutineContext
[
CoroutineExceptionHandler
]
?:
CoroutineExceptionHandler
{
_
,
e
->
logger
.
error
(
"An exception was thrown under a coroutine of Bot"
,
e
)
})
configuration
.
parentCoroutineContext
.
plus
(
SupervisorJob
(
configuration
.
parentCoroutineContext
[
Job
]))
.
plus
(
configuration
.
parentCoroutineContext
[
CoroutineExceptionHandler
]
?:
CoroutineExceptionHandler
{
_
,
e
->
logger
.
error
(
"An exception was thrown under a coroutine of Bot"
,
e
)
}
)
companion
object
{
@JvmField
@Suppress
(
"ObjectPropertyName"
)
internal
val
_instances
:
LockFreeLinkedList
<
WeakRef
<
Bot
>>
=
LockFreeLinkedList
()
...
...
@@ -133,6 +137,12 @@ abstract class Bot(
*/
abstract
val
logger
:
MiraiLogger
/**
* 判断 Bot 是否在线 (可正常收发消息)
*/
@SinceMirai
(
"1.0.1"
)
abstract
val
isOnline
:
Boolean
// region contacts
/**
...
...
@@ -206,6 +216,7 @@ abstract class Bot(
*
* @see Image.queryUrl [Image] 的扩展函数
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use extension."
,
replaceWith
=
ReplaceWith
(
"image.queryUrl()"
,
imports
=
[
"net.mamoe.mirai.message.data.queryUrl"
])
...
...
@@ -236,6 +247,7 @@ abstract class Bot(
*
* @param event 好友验证的事件对象
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.accept()"
))
@JvmSynthetic
abstract
suspend
fun
acceptNewFriendRequest
(
event
:
NewFriendRequestEvent
)
...
...
@@ -246,6 +258,7 @@ abstract class Bot(
* @param event 好友验证的事件对象
* @param blackList 拒绝后是否拉入黑名单
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.reject(blackList)"
))
@JvmSynthetic
abstract
suspend
fun
rejectNewFriendRequest
(
event
:
NewFriendRequestEvent
,
blackList
:
Boolean
=
false
)
...
...
@@ -255,6 +268,7 @@ abstract class Bot(
*
* @param event 加群验证的事件对象
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.accept()"
))
@JvmSynthetic
abstract
suspend
fun
acceptMemberJoinRequest
(
event
:
MemberJoinRequestEvent
)
...
...
@@ -265,6 +279,7 @@ abstract class Bot(
* @param event 加群验证的事件对象
* @param blackList 拒绝后是否拉入黑名单
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.reject(blackList)"
))
@JvmSynthetic
abstract
suspend
fun
rejectMemberJoinRequest
(
event
:
MemberJoinRequestEvent
,
blackList
:
Boolean
=
false
)
...
...
@@ -275,6 +290,7 @@ abstract class Bot(
* @param event 加群验证的事件对象
* @param blackList 忽略后是否拉入黑名单
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.ignore(blackList)"
))
@JvmSynthetic
abstract
suspend
fun
ignoreMemberJoinRequest
(
event
:
MemberJoinRequestEvent
,
blackList
:
Boolean
=
false
)
...
...
@@ -284,6 +300,7 @@ abstract class Bot(
*
* @param event 邀请入群的事件对象
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.accept"
))
@JvmSynthetic
abstract
suspend
fun
acceptInvitedJoinGroupRequest
(
event
:
BotInvitedJoinGroupRequestEvent
)
...
...
@@ -293,6 +310,7 @@ abstract class Bot(
*
* @param event 邀请入群的事件对象
*/
@PlannedRemoval
(
"1.2.0"
)
@Deprecated
(
"use member function."
,
replaceWith
=
ReplaceWith
(
"event.ignore"
))
@JvmSynthetic
abstract
suspend
fun
ignoreInvitedJoinGroupRequest
(
event
:
BotInvitedJoinGroupRequestEvent
)
...
...
@@ -322,7 +340,8 @@ inline val Bot.supervisorJob: CompletableJob
get
()
=
this
.
coroutineContext
[
Job
]
as
CompletableJob
/**
* 挂起协程直到 [Bot] 下线.
* 挂起协程直到 [Bot] 协程被关闭 ([Bot.close]).
* 即使 [Bot] 离线, 也会等待直到协程关闭.
*/
@JvmSynthetic
suspend
inline
fun
Bot
.
join
()
=
this
.
coroutineContext
[
Job
]
!!
.
join
()
...
...
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