BotConfiguration

open class BotConfiguration

Bot 配置. 用于 BotFactory.newBot

Kotlin 使用方法:

val bot = BotFactory.newBot(...) {
// 在这里配置 Bot

bogLoggerSupplier = { bot -> ... }
fileBasedDeviceInfo()
inheritCoroutineContext() // 使用 `coroutineScope` 的 Job 作为父 Job
}

Java 使用方法:

Bot bot = BotFactory.newBot(..., new BotConfiguration() {{
setBogLoggerSupplier((Bot bot) -> { ... })
fileBasedDeviceInfo()
...
}})

Constructors

BotConfiguration
Link copied to clipboard
fun BotConfiguration()

Types

Companion
Link copied to clipboard
object Companion
ConfigurationDsl
Link copied to clipboard
annotation class ConfigurationDsl

标注一个配置 DSL 函数

ContactListCache
Link copied to clipboard
class ContactListCache

联系人信息缓存配置

HeartbeatStrategy
Link copied to clipboard
enum HeartbeatStrategy : Enum<BotConfiguration.HeartbeatStrategy>

心跳策略.

MiraiProtocol
Link copied to clipboard
enum MiraiProtocol : Enum<BotConfiguration.MiraiProtocol>

Functions

autoReconnectOnForceOffline
Link copied to clipboard
fun autoReconnectOnForceOffline()

设置 autoReconnectOnForceOfflinetrue, 即在被挤下线时自动重连.

contactListCache
Link copied to clipboard
inline fun contactListCache(action: BotConfiguration.ContactListCache.() -> Unit)
copy
Link copied to clipboard
fun copy(): BotConfiguration
disableContactCache
Link copied to clipboard
fun disableContactCache()

禁用好友列表和群成员列表的缓存.

enableContactCache
Link copied to clipboard
fun enableContactCache()

启用好友列表和群成员列表的缓存.

fileBasedDeviceInfo
Link copied to clipboard
fun fileBasedDeviceInfo(filepath: String = "device.json")

使用文件存储设备信息.

inheritCoroutineContext
Link copied to clipboard
inline suspend fun inheritCoroutineContext()

使用当前协程的 coroutineContext 作为 parentCoroutineContext.

loadDeviceInfoJson
Link copied to clipboard
fun loadDeviceInfoJson(json: String)

使用特定由 DeviceInfo 序列化产生的 JSON 的设备信息

noBotLog
Link copied to clipboard
fun noBotLog()

不显示 Bot 日志. 不推荐.

noNetworkLog
Link copied to clipboard
fun noNetworkLog()

不显示网络日志. 不推荐.

randomDeviceInfo
Link copied to clipboard
fun randomDeviceInfo()

使用随机设备信息.

redirectBotLogToDirectory
Link copied to clipboard
fun redirectBotLogToDirectory(dir: <ERROR CLASS> = File("logs"), retain: Long = 1.weeksToMillis, identity: (bot: Bot) -> String = { "Bot ${it.id}" })

重定向 Bot 日志 到指定目录. 若目录不存在将会自动创建 (File.mkdirs)

redirectBotLogToFile
Link copied to clipboard
fun redirectBotLogToFile(file: <ERROR CLASS> = File("mirai.log"), identity: (bot: Bot) -> String = { "Bot ${it.id}" })

重定向 Bot 日志 到指定文件. 日志将会逐行追加到此文件. 若文件不存在将会自动创建 (File.createNewFile)

redirectNetworkLogToDirectory
Link copied to clipboard
fun redirectNetworkLogToDirectory(dir: <ERROR CLASS> = File("logs"), retain: Long = 1.weeksToMillis, identity: (bot: Bot) -> String = { "Net ${it.id}" })

重定向 网络日志 到指定目录. 若目录不存在将会自动创建 (File.mkdirs) 默认目录路径为 "$workingDir/logs/".

redirectNetworkLogToFile
Link copied to clipboard
fun redirectNetworkLogToFile(file: <ERROR CLASS> = File("mirai.log"), identity: (bot: Bot) -> String = { "Net ${it.id}" })

重定向 网络日志 到指定文件. 默认文件路径为 "$workingDir/mirai.log". 日志将会逐行追加到此文件. 若文件不存在将会自动创建 (File.createNewFile)

Properties

autoReconnectOnForceOffline
Link copied to clipboard
var autoReconnectOnForceOffline: Boolean = false

在被挤下线时 (BotOfflineEvent.Force) 自动重连. 默认为 false.

botLoggerSupplier
Link copied to clipboard
var botLoggerSupplier: (Bot) -> MiraiLogger

日志记录器

cacheDir
Link copied to clipboard
var cacheDir: <ERROR CLASS>

缓存数据目录, 相对于 workingDir.

contactListCache
Link copied to clipboard
var contactListCache: BotConfiguration.ContactListCache

联系人信息缓存配置. 将会保存在 cacheDircontacts 目录

convertLineSeparator
Link copied to clipboard
var convertLineSeparator: Boolean = true

是否处理接受到的特殊换行符, 默认为 true

deviceInfo
Link copied to clipboard
var deviceInfo: (Bot) -> DeviceInfo?

设备信息覆盖. 在没有手动指定时将会通过日志警告, 并使用随机设备信息.

firstReconnectDelayMillis
Link copied to clipboard
var firstReconnectDelayMillis: Long

心跳失败后的第一次重连前的等待时间.

heartbeatPeriodMillis
Link copied to clipboard
var heartbeatPeriodMillis: Long

连接心跳包周期. 过长会导致被服务器断开连接.

heartbeatStrategy
Link copied to clipboard

心跳策略.

heartbeatTimeoutMillis
Link copied to clipboard
var heartbeatTimeoutMillis: Long

每次心跳时等待结果的时间. 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.

highwayUploadCoroutineCount
Link copied to clipboard
var highwayUploadCoroutineCount: Int

Highway 通道上传图片, 语音, 文件等资源时的协程数量.

isShowingVerboseEventLog
Link copied to clipboard
var isShowingVerboseEventLog: Boolean = false

是否显示过于冗长的事件日志

json
Link copied to clipboard
var json: <ERROR CLASS>

Json 序列化器, 使用 'kotlinx.serialization'

loginCacheEnabled
Link copied to clipboard
var loginCacheEnabled: Boolean = true

登录缓存.

loginSolver
Link copied to clipboard
var loginSolver: LoginSolver?

验证码处理器

networkLoggerSupplier
Link copied to clipboard
var networkLoggerSupplier: (Bot) -> MiraiLogger

网络层日志构造器

parentCoroutineContext
Link copied to clipboard
var parentCoroutineContext: CoroutineContext

CoroutineContext. Bot 创建后会使用 SupervisorJob 覆盖其 Job, 但会将这个 Job 作为父 Job

protocol
Link copied to clipboard
var protocol: BotConfiguration.MiraiProtocol

使用协议类型

reconnectionRetryTimes
Link copied to clipboard
var reconnectionRetryTimes: Int

最多尝试多少次重连

reconnectPeriodMillis
Link copied to clipboard
var reconnectPeriodMillis: Long

重连失败后, 继续尝试的每次等待时间

statHeartbeatPeriodMillis
Link copied to clipboard
var statHeartbeatPeriodMillis: Long

状态心跳包周期. 过长会导致掉线. 该值会在登录时根据服务器下发的配置自动进行更新.

workingDir
Link copied to clipboard
var workingDir: <ERROR CLASS>

工作目录. 默认为 "."