Add BotConfiguration.autoReconnectOnForceOffline, close #835

This commit is contained in:
Him188 2021-01-22 11:00:04 +08:00
parent 209b2b7616
commit c7c83bcd03
2 changed files with 19 additions and 1 deletions

View File

@ -60,7 +60,7 @@ public sealed class BotOfflineEvent : BotEvent, AbstractEvent() {
public val title: String,
public val message: String,
) : BotOfflineEvent(), Packet, BotPassiveEvent {
override var reconnect: Boolean = false
override var reconnect: Boolean = bot.configuration.autoReconnectOnForceOffline
}
/**

View File

@ -15,6 +15,7 @@ import kotlinx.coroutines.Job
import kotlinx.coroutines.SupervisorJob
import kotlinx.serialization.json.Json
import net.mamoe.mirai.Bot
import net.mamoe.mirai.event.events.BotOfflineEvent
import java.io.File
import kotlin.coroutines.CoroutineContext
import kotlin.coroutines.EmptyCoroutineContext
@ -95,6 +96,15 @@ public open class BotConfiguration { // open for Java
/** 最多尝试多少次重连 */
public var reconnectionRetryTimes: Int = Int.MAX_VALUE
/**
* 在被挤下线时 ([BotOfflineEvent.Force]) 自动重连. 默认为 `false`.
*
* 其他情况掉线都默认会自动重连, 详见 [BotOfflineEvent.reconnect]
*
* @since 2.1
*/
public var autoReconnectOnForceOffline: Boolean = false
/**
* 验证码处理器
*
@ -129,6 +139,14 @@ public open class BotConfiguration { // open for Java
}
}.getOrElse { Json {} }
/**
* 设置 [autoReconnectOnForceOffline] `true`, 即在被挤下线时自动重连.
* @since 2.1
*/
public fun autoReconnectOnForceOffline() {
autoReconnectOnForceOffline = true
}
/**
* 使用随机设备信息.
*