From 9c9037d02e6b71bf02ca1e04e6eb4d261b047447 Mon Sep 17 00:00:00 2001 From: "lizheng.lz1998" Date: Mon, 5 Oct 2020 17:14:43 +0800 Subject: [PATCH] update device --- src/main/kotlin/net/lz1998/mirai/entity/WebSocketBotClient.kt | 2 +- src/main/kotlin/net/lz1998/mirai/ext/MyDeviceInfo.kt | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/net/lz1998/mirai/entity/WebSocketBotClient.kt b/src/main/kotlin/net/lz1998/mirai/entity/WebSocketBotClient.kt index 48d86c5..dcdd069 100644 --- a/src/main/kotlin/net/lz1998/mirai/entity/WebSocketBotClient.kt +++ b/src/main/kotlin/net/lz1998/mirai/entity/WebSocketBotClient.kt @@ -96,7 +96,7 @@ class WebsocketBotClient(override var botId: Long, override var password: String override suspend fun initBot() { wsClient = httpClient.newWebSocket(wsRequest, wsListener) bot = Bot(botId, password) { - fileStrBasedDeviceInfo("device.json") + fileStrBasedDeviceInfo("device/${botId}.json") loginSolver = MyLoginSolver noNetworkLog() }.alsoLogin() diff --git a/src/main/kotlin/net/lz1998/mirai/ext/MyDeviceInfo.kt b/src/main/kotlin/net/lz1998/mirai/ext/MyDeviceInfo.kt index 43a231a..8a6ea09 100644 --- a/src/main/kotlin/net/lz1998/mirai/ext/MyDeviceInfo.kt +++ b/src/main/kotlin/net/lz1998/mirai/ext/MyDeviceInfo.kt @@ -189,6 +189,9 @@ fun BotConfiguration.getFileStrBasedDeviceInfoSupplier(filename: String): ((Cont fun File.loadStrAsDeviceInfo(json: Json, context: Context = ContextImpl()): DeviceInfo { if (!this.exists() || this.length() == 0L) { return MyDeviceInfo(context).also { + if (!this.parentFile.exists()) { + this.parentFile.mkdirs() + } this.writeText(json.encodeToString(MyDeviceInfo.serializer(), it)) } }