Add Bot.closeAndJoin

This commit is contained in:
Him188 2020-02-17 09:39:02 +08:00
parent 7d283808f7
commit 9b3bc88b3d

View File

@ -236,6 +236,8 @@ abstract class Bot : CoroutineScope {
* : 不可重新登录. 必须重新实例化一个 [Bot].
*
* @param cause 原因. null 时视为正常关闭, null 时视为异常关闭
*
* @see closeAndJoin
*/
abstract fun close(cause: Throwable? = null)
@ -260,6 +262,18 @@ abstract class Bot : CoroutineScope {
// endregion
}
/**
* 关闭这个 [Bot], 停止一切相关活动. 所有引用都会被释放.
*
* : 不可重新登录. 必须重新实例化一个 [Bot].
*
* @param cause 原因. null 时视为正常关闭, null 时视为异常关闭
*/
suspend inline fun Bot.closeAndJoin(cause: Throwable? = null) {
close(cause)
coroutineContext[Job]?.join()
}
inline fun Bot.containsFriend(id: Long): Boolean = this.qqs.contains(id)
inline fun Bot.containsGroup(id: Long): Boolean = this.groups.contains(id)