mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-31 19:40:24 +08:00
Add BotConfiguration.autoReconnectOnForceOffline, close #835
This commit is contained in:
parent
209b2b7616
commit
c7c83bcd03
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
/**
|
||||
* 使用随机设备信息.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user