From 4a34822f5c1ff85a26c1178b2a7088583d8fe027 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sun, 30 Oct 2022 22:49:06 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(mirai):=20=E6=9B=B4=E6=96=B0mirai?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=B9=B6=E8=B0=83=E6=95=B4=E8=AE=BE=E5=A4=87?= =?UTF-8?q?=E4=BF=A1=E6=81=AF=E9=85=8D=E7=BD=AE=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/component-ding/pom.xml | 2 +- component/component-kaiheila-parent/pom.xml | 2 +- component/component-lovelycat-httpapi/pom.xml | 2 +- component/component-mirai/pom.xml | 4 +- .../mirai/configuration/MiraiConfiguration.kt | 144 ++++++++++-------- component/pom.xml | 2 +- core-api/api/pom.xml | 2 +- core-api/core/pom.xml | 2 +- http/client-core/pom.xml | 2 +- http/client-ktor/pom.xml | 2 +- http/client-restTemplate/pom.xml | 2 +- http/pom.xml | 2 +- parent/pom.xml | 4 +- pom.xml | 2 +- serialization/json-core/pom.xml | 2 +- serialization/json-fastjson/pom.xml | 2 +- serialization/json-jackson/pom.xml | 2 +- serialization/json-moshi/pom.xml | 2 +- serialization/pom.xml | 2 +- simbot-x/plugin-core/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- ...imbotCompMiraiConfigurationProperties.java | 10 +- .../core-spring-boot-starter/pom.xml | 2 +- spring-boot-starter/pom.xml | 2 +- time-task/pom.xml | 2 +- time-task/time-task-core/pom.xml | 2 +- time-task/time-task-quartz/pom.xml | 2 +- 28 files changed, 114 insertions(+), 96 deletions(-) diff --git a/component/component-ding/pom.xml b/component/component-ding/pom.xml index 1723b34b..a2ede5c0 100644 --- a/component/component-ding/pom.xml +++ b/component/component-ding/pom.xml @@ -19,7 +19,7 @@ component-parent love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/component/component-kaiheila-parent/pom.xml b/component/component-kaiheila-parent/pom.xml index 8eab1d9f..ba6317d7 100644 --- a/component/component-kaiheila-parent/pom.xml +++ b/component/component-kaiheila-parent/pom.xml @@ -5,7 +5,7 @@ component-parent love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml diff --git a/component/component-lovelycat-httpapi/pom.xml b/component/component-lovelycat-httpapi/pom.xml index 1c16a692..645206b9 100644 --- a/component/component-lovelycat-httpapi/pom.xml +++ b/component/component-lovelycat-httpapi/pom.xml @@ -5,7 +5,7 @@ component-parent love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/component/component-mirai/pom.xml b/component/component-mirai/pom.xml index 49e55cc0..80eb1c5a 100644 --- a/component/component-mirai/pom.xml +++ b/component/component-mirai/pom.xml @@ -5,7 +5,7 @@ love.forte.simple-robot component-parent - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 @@ -22,7 +22,7 @@ https://github.com/ForteScarlet/simpler-robot/tree/dev/component/component-mirai - 2.11.1 + 2.13.0-RC2 diff --git a/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt b/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt index 829cc28c..38a3562a 100644 --- a/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt +++ b/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt @@ -16,7 +16,6 @@ package love.forte.simbot.component.mirai.configuration import cn.hutool.crypto.SecureUtil -import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import love.forte.common.configuration.annotation.ConfigInject @@ -52,16 +51,16 @@ public fun miraiBotLogger(botCode: Long, type: String? = null): Logger { @Beans("miraiConfiguration") @AsMiraiConfig public class MiraiConfiguration { - + private companion object : TypedCompLogger(MiraiConfiguration::class.java) - + /** * mirai心跳周期. 过长会导致被服务器断开连接. 单位毫秒 * @see BotConfiguration.heartbeatPeriodMillis */ @field:ConfigInject var heartbeatPeriodMillis: Long = BotConfiguration.Default.heartbeatPeriodMillis - + /** * 每次心跳时等待结果的时间. * 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响. @@ -69,118 +68,130 @@ public class MiraiConfiguration { */ @field:ConfigInject var heartbeatTimeoutMillis: Long = BotConfiguration.Default.heartbeatTimeoutMillis - + /** * mirai 心跳策略. */ @field:ConfigInject var heartbeatStrategy: BotConfiguration.HeartbeatStrategy = BotConfiguration.Default.heartbeatStrategy - - + + /** 最多尝试多少次重连 */ @field:ConfigInject var reconnectionRetryTimes: Int = BotConfiguration.Default.reconnectionRetryTimes - - + + /** * 使用协议类型。 * 默认使用 [安卓手机协议][BotConfiguration.MiraiProtocol.ANDROID_PHONE]。 */ @field:ConfigInject var protocol: BotConfiguration.MiraiProtocol = BotConfiguration.Default.protocol - + /** 关闭mirai的bot logger */ @field:ConfigInject var noBotLog: Boolean = false - + /** 关闭mirai网络日志 */ @field:ConfigInject var noNetworkLog: Boolean = false - + /** mirai bot log切换使用simbot的log(slf4j-api) */ @field:ConfigInject var useSimbotBotLog: Boolean = true - + /** mirai 网络log 切换使用simbot的log(slf4j-api) */ @field:ConfigInject var useSimbotNetworkLog: Boolean = true - + /** mirai配置自定义deviceInfoSeed的时候使用的随机种子。默认为1. */ @field:ConfigInject var deviceInfoSeed: Long = 1L - - + + @field:ConfigInject - var deviceInfoFile: String? = "" - + var deviceInfoFile: String? = "device.json" + + /** + * 如果为true,则通过 [deviceInfoFile] 的值进行基于文件的随机设备信息配置。 + */ + @field:ConfigInject + var deviceInfoFileBased: Boolean = true + /** * 是否输出设备信息 */ @field:ConfigInject var deviceInfoOutput: Boolean = false - + /** * @see BotConfiguration.highwayUploadCoroutineCount */ @field:ConfigInject var highwayUploadCoroutineCount: Int = BotConfiguration.Default.highwayUploadCoroutineCount - + private val json = Json { isLenient = true ignoreUnknownKeys = true prettyPrint = true } - + /** * mirai官方配置类获取函数,默认为其默认值 * */ // @set:Deprecated("use setPostBotConfigurationProcessor((code, conf) -> {...})") - - @OptIn(ExperimentalSerializationApi::class) + val botConfiguration: (String) -> BotConfiguration = { val conf = BotConfiguration() - - deviceInfoFile.takeIf { it?.isNotBlank() == true }?.runCatching { - logger.info("Try to use device info file: $this") - val jsonReader = ResourceUtil.getResourceUtf8Reader(this) - val json = jsonReader.use { it.readText() } - conf.loadDeviceInfoJson(json) - }?.getOrElse { e -> - logger.error("Load device Info json file: $deviceInfoFile failed. get device by simbot default.", e) - null - } ?: run { - conf.deviceInfo = { - val devInfo = simbotMiraiDeviceInfo(it.id, deviceInfoSeed) - - if (deviceInfoOutput) { - runCatching { - val devInfoJson = json.encodeToString(devInfo) - val outFile = File("simbot-devInfo.json") - if (!outFile.exists()) { - outFile.apply { - parentFile?.mkdirs() - createNewFile() + + if (deviceInfoFileBased) { + conf.fileBasedDeviceInfo(deviceInfoFile?.takeIf { it.isNotEmpty() } ?: "device.json") + } else { + deviceInfoFile.takeIf { it?.isNotBlank() == true }?.runCatching { + logger.info("Try to use device info file: $this") + val jsonReader = ResourceUtil.getResourceUtf8Reader(this) + val json = jsonReader.use { it.readText() } + conf.loadDeviceInfoJson(json) + }?.getOrElse { e -> + logger.error("Load device info json file: $deviceInfoFile failed. get device via mirai random.", e) + null + } ?: run { + // conf.fileBasedDeviceInfo(deviceInfoFile ?: "device.json") + conf.deviceInfo = { + conf.deviceInfo = { DeviceInfo.random() } + val devInfo = simbotMiraiDeviceInfo(it.id, deviceInfoSeed) + + if (deviceInfoOutput) { + runCatching { + val devInfoJson = json.encodeToString(devInfo) + val outFile = File("simbot-devInfo.json") + if (!outFile.exists()) { + outFile.apply { + parentFile?.mkdirs() + createNewFile() + } } + FileWriter(outFile).use { w -> + w.write(devInfoJson) + logger.info("DevInfo write to ${outFile.canonicalPath}") + } + }.getOrElse { e -> + logger.error("Write devInfo failed: {}", e.localizedMessage) + if (!logger.isDebugEnabled) { + logger.error("Enable debug log for more information.") + } + logger.debug("Write devInfo failed.", e) } - FileWriter(outFile).use { w -> - w.write(devInfoJson) - logger.info("DevInfo write to ${outFile.canonicalPath}") - } - }.getOrElse { e -> - logger.error("Write devInfo failed: {}", e.localizedMessage) - if (!logger.isDebugEnabled) { - logger.error("Enable debug log for more information.") - } - logger.debug("Write devInfo failed.", e) } + + + devInfo } - - - devInfo } } - - + + + conf.heartbeatPeriodMillis = this.heartbeatPeriodMillis conf.heartbeatTimeoutMillis = this.heartbeatTimeoutMillis // conf.firstReconnectDelayMillis = this.firstReconnectDelayMillis @@ -188,8 +199,8 @@ public class MiraiConfiguration { conf.reconnectionRetryTimes = this.reconnectionRetryTimes conf.protocol = this.protocol conf.highwayUploadCoroutineCount = highwayUploadCoroutineCount - - + + if (noBotLog) { conf.noBotLog() } @@ -223,12 +234,11 @@ public class MiraiConfiguration { if (logger is MiraiLoggerWithSwitch) logger else logger.withSwitch(true) } } - + conf } } - internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo { val r = Random(c * s) return DeviceInfo( @@ -241,9 +251,11 @@ internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo { bootloader = "unknown".toByteArray(), // mamoe/mirai/mirai:10/MIRAI.200122.001/ fingerprint = "mamoe/mirai/mirai:10/MIRAI.200122.001/${ - getRandomString(7, + getRandomString( + 7, '0'..'9', - r) + r + ) }:user/release-keys".toByteArray(), bootId = generateUUID(SecureUtil.md5().digest(getRandomByteArray(16, r))).toByteArray(), procVersion = "Linux version 3.0.31-${getRandomString(8, r)} (android-build@xxx.xxx.xxx.xxx.com)".toByteArray(), @@ -257,7 +269,7 @@ internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo { imsiMd5 = SecureUtil.md5().digest(getRandomByteArray(16, r)), imei = getRandomString(15, '0'..'9', r), apn = "wifi".toByteArray() - + ) } diff --git a/component/pom.xml b/component/pom.xml index 91b43637..06ebb33d 100644 --- a/component/pom.xml +++ b/component/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/core-api/api/pom.xml b/core-api/api/pom.xml index a2b6790d..14417c57 100644 --- a/core-api/api/pom.xml +++ b/core-api/api/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../../pom.xml 4.0.0 diff --git a/core-api/core/pom.xml b/core-api/core/pom.xml index ab859d28..c09f5ecf 100644 --- a/core-api/core/pom.xml +++ b/core-api/core/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../../pom.xml 4.0.0 diff --git a/http/client-core/pom.xml b/http/client-core/pom.xml index 212e6e2f..26369a97 100644 --- a/http/client-core/pom.xml +++ b/http/client-core/pom.xml @@ -5,7 +5,7 @@ http-parent love.forte.simple-robot.http - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/http/client-ktor/pom.xml b/http/client-ktor/pom.xml index f39a6901..59a1f07a 100644 --- a/http/client-ktor/pom.xml +++ b/http/client-ktor/pom.xml @@ -5,7 +5,7 @@ http-parent love.forte.simple-robot.http - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/http/client-restTemplate/pom.xml b/http/client-restTemplate/pom.xml index 7d0ec9c0..f2496886 100644 --- a/http/client-restTemplate/pom.xml +++ b/http/client-restTemplate/pom.xml @@ -6,7 +6,7 @@ http-parent love.forte.simple-robot.http - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/http/pom.xml b/http/pom.xml index d424cf9f..71a97196 100644 --- a/http/pom.xml +++ b/http/pom.xml @@ -6,7 +6,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/parent/pom.xml b/parent/pom.xml index ef242f2d..2896cb0a 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -6,7 +6,7 @@ love.forte.simple-robot parent - 2.4.1 + 2.5.0 pom @@ -23,7 +23,7 @@ simple-robot是一个通用bot开发框架,以同一种灵活的标准来编写不同平台的bot应用。而simpler-robot便是simple-robot 2.x版本命名。 - 2.4.1 + 2.5.0 0.0.1-ALPHA.1 8 diff --git a/pom.xml b/pom.xml index 77a43dad..13964aff 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ love.forte.simple-robot parent - 2.4.1 + 2.5.0 ./parent/pom.xml diff --git a/serialization/json-core/pom.xml b/serialization/json-core/pom.xml index c62fbcc1..0725fd65 100644 --- a/serialization/json-core/pom.xml +++ b/serialization/json-core/pom.xml @@ -5,7 +5,7 @@ serialization-parent love.forte.simple-robot.serialization - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/serialization/json-fastjson/pom.xml b/serialization/json-fastjson/pom.xml index 0c224fa3..dd21e09b 100644 --- a/serialization/json-fastjson/pom.xml +++ b/serialization/json-fastjson/pom.xml @@ -5,7 +5,7 @@ serialization-parent love.forte.simple-robot.serialization - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/serialization/json-jackson/pom.xml b/serialization/json-jackson/pom.xml index e968b92a..76a6aced 100644 --- a/serialization/json-jackson/pom.xml +++ b/serialization/json-jackson/pom.xml @@ -5,7 +5,7 @@ serialization-parent love.forte.simple-robot.serialization - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/serialization/json-moshi/pom.xml b/serialization/json-moshi/pom.xml index b5ef7ae0..3b36d84a 100644 --- a/serialization/json-moshi/pom.xml +++ b/serialization/json-moshi/pom.xml @@ -5,7 +5,7 @@ serialization-parent love.forte.simple-robot.serialization - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/serialization/pom.xml b/serialization/pom.xml index 71c6e59f..3a6476d0 100644 --- a/serialization/pom.xml +++ b/serialization/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/simbot-x/plugin-core/pom.xml b/simbot-x/plugin-core/pom.xml index 0c70cb1e..476917d0 100644 --- a/simbot-x/plugin-core/pom.xml +++ b/simbot-x/plugin-core/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../../pom.xml 4.0.0 diff --git a/spring-boot-starter/component-lovelycat-httpapi-spring-boot-starter/pom.xml b/spring-boot-starter/component-lovelycat-httpapi-spring-boot-starter/pom.xml index d47eefa9..955412d6 100644 --- a/spring-boot-starter/component-lovelycat-httpapi-spring-boot-starter/pom.xml +++ b/spring-boot-starter/component-lovelycat-httpapi-spring-boot-starter/pom.xml @@ -6,7 +6,7 @@ spring-boot-starter love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/spring-boot-starter/component-mirai-spring-boot-starter/pom.xml b/spring-boot-starter/component-mirai-spring-boot-starter/pom.xml index 2a4e1f35..3af1d4f7 100644 --- a/spring-boot-starter/component-mirai-spring-boot-starter/pom.xml +++ b/spring-boot-starter/component-mirai-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ spring-boot-starter love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/spring-boot-starter/component-mirai-spring-boot-starter/src/main/java/love/forte/simbot/spring/autoconfigure/properties/SimbotCompMiraiConfigurationProperties.java b/spring-boot-starter/component-mirai-spring-boot-starter/src/main/java/love/forte/simbot/spring/autoconfigure/properties/SimbotCompMiraiConfigurationProperties.java index 9acf4f33..24c79be3 100644 --- a/spring-boot-starter/component-mirai-spring-boot-starter/src/main/java/love/forte/simbot/spring/autoconfigure/properties/SimbotCompMiraiConfigurationProperties.java +++ b/spring-boot-starter/component-mirai-spring-boot-starter/src/main/java/love/forte/simbot/spring/autoconfigure/properties/SimbotCompMiraiConfigurationProperties.java @@ -20,7 +20,7 @@ /** * simbot配置文件对应实例。实际上没有被使用到,仅用作提供springboot的配置文件快捷提醒。 - * + *

* 真正使用到的配置类为 {@link love.forte.simbot.component.mirai.configuration.MiraiConfiguration} * * @author ForteScarlet @@ -93,5 +93,11 @@ private static BotConfiguration getDef() { /** * mirai设备信息文件路径。 */ - private String deviceInfoFile = ""; + private String deviceInfoFile = "device.json"; + + /** + * 如果为true,则通过 {@link #deviceInfoFile} 的值进行基于文件的随机设备信息配置。 + * 默认为true + */ + private boolean deviceInfoFileBased = true; } diff --git a/spring-boot-starter/core-spring-boot-starter/pom.xml b/spring-boot-starter/core-spring-boot-starter/pom.xml index 655a9498..6311872a 100644 --- a/spring-boot-starter/core-spring-boot-starter/pom.xml +++ b/spring-boot-starter/core-spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ spring-boot-starter love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/spring-boot-starter/pom.xml b/spring-boot-starter/pom.xml index 773f5061..77466e89 100644 --- a/spring-boot-starter/pom.xml +++ b/spring-boot-starter/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 ../pom.xml 4.0.0 diff --git a/time-task/pom.xml b/time-task/pom.xml index 5e10d290..a61bf12c 100644 --- a/time-task/pom.xml +++ b/time-task/pom.xml @@ -5,7 +5,7 @@ project love.forte.simple-robot - 2.4.1 + 2.5.0 4.0.0 diff --git a/time-task/time-task-core/pom.xml b/time-task/time-task-core/pom.xml index c16ecd90..18d8e823 100644 --- a/time-task/time-task-core/pom.xml +++ b/time-task/time-task-core/pom.xml @@ -6,7 +6,7 @@ time-task-parent love.forte.simple-robot.time-task - 2.4.1 + 2.5.0 4.0.0 diff --git a/time-task/time-task-quartz/pom.xml b/time-task/time-task-quartz/pom.xml index 2c505308..54c6692f 100644 --- a/time-task/time-task-quartz/pom.xml +++ b/time-task/time-task-quartz/pom.xml @@ -5,7 +5,7 @@ time-task-parent love.forte.simple-robot.time-task - 2.4.1 + 2.5.0 4.0.0 From 459286fb61fcfd296c813f12350b88dc62d20898 Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sun, 30 Oct 2022 22:55:15 +0800 Subject: [PATCH 2/3] =?UTF-8?q?feat(mirai):=20=E8=B0=83=E6=95=B4=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E4=BF=A1=E6=81=AF=E9=85=8D=E7=BD=AE=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mirai/configuration/MiraiConfiguration.kt | 47 +++++++++---------- 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt b/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt index 38a3562a..d0d68898 100644 --- a/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt +++ b/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt @@ -158,34 +158,32 @@ public class MiraiConfiguration { } ?: run { // conf.fileBasedDeviceInfo(deviceInfoFile ?: "device.json") conf.deviceInfo = { - conf.deviceInfo = { DeviceInfo.random() } - val devInfo = simbotMiraiDeviceInfo(it.id, deviceInfoSeed) - - if (deviceInfoOutput) { - runCatching { - val devInfoJson = json.encodeToString(devInfo) - val outFile = File("simbot-devInfo.json") - if (!outFile.exists()) { - outFile.apply { - parentFile?.mkdirs() - createNewFile() + // random. + DeviceInfo.random().also { devInfo -> + if (deviceInfoOutput) { + logger.warn("The configuration property 'deviceInfoOutput' is not recommended") + runCatching { + val devInfoJson = json.encodeToString(devInfo) + val outFile = File("simbot-devInfo.json") + if (!outFile.exists()) { + outFile.apply { + parentFile?.mkdirs() + createNewFile() + } } + FileWriter(outFile).use { w -> + w.write(devInfoJson) + logger.info("DevInfo write to ${outFile.canonicalPath}") + } + }.getOrElse { e -> + logger.error("Write devInfo failed: {}", e.localizedMessage) + if (!logger.isDebugEnabled) { + logger.error("Enable debug log for more information.") + } + logger.debug("Write devInfo failed.", e) } - FileWriter(outFile).use { w -> - w.write(devInfoJson) - logger.info("DevInfo write to ${outFile.canonicalPath}") - } - }.getOrElse { e -> - logger.error("Write devInfo failed: {}", e.localizedMessage) - if (!logger.isDebugEnabled) { - logger.error("Enable debug log for more information.") - } - logger.debug("Write devInfo failed.", e) } } - - - devInfo } } } @@ -239,6 +237,7 @@ public class MiraiConfiguration { } } +@Deprecated("Unused") internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo { val r = Random(c * s) return DeviceInfo( From 153c815a55249ac388121ffa61cdb9e0f1e965dd Mon Sep 17 00:00:00 2001 From: ForteScarlet Date: Sun, 30 Oct 2022 23:44:18 +0800 Subject: [PATCH 3/3] =?UTF-8?q?refactor:=20=E4=BC=98=E5=8C=96&=E6=B8=85?= =?UTF-8?q?=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../simbot/component/mirai/message/MiraiMessageContent.kt | 7 +++---- .../main/java/love/forte/simbot/api/sender/ErrorSender.kt | 3 ++- .../core/src/main/java/love/forte/simbot/core/SimbotApp.kt | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/message/MiraiMessageContent.kt b/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/message/MiraiMessageContent.kt index 9ac4f5fd..b2ce15b8 100644 --- a/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/message/MiraiMessageContent.kt +++ b/component/component-mirai/src/main/java/love/forte/simbot/component/mirai/message/MiraiMessageContent.kt @@ -78,13 +78,13 @@ public abstract class MiraiMessageContent : MessageContent { public data class MiraiListMessageContent(val list: List) : MiraiMessageContent() { override suspend fun getMessage(contact: Contact): Message { return when { - list.isEmpty() -> EmptyMessageChain + list.isEmpty() -> emptyMessageChain() list.size == 1 -> list[0].getMessage(contact) list.size == 2 -> list.first().getMessage(contact) + list.last().getMessage(contact) else -> list.map { it.getMessage(contact) } .asSequence() .filter { it.isNotEmptyMsg() } - .reduceOrNull { m1, m2 -> m1 + m2 } ?: EmptyMessageChain + .reduceOrNull { m1, m2 -> m1 + m2 } ?: emptyMessageChain() } } @@ -392,10 +392,9 @@ constructor( @Deprecated("Use MiraiAudioMessageContent", replaceWith = ReplaceWith("MiraiAudioMessageContent")) public class MiraiVoiceMessageContent( override val neko: Neko, - @Suppress("DEPRECATION") private val voiceFunction: suspend (Contact) -> Audio, + private val voiceFunction: suspend (Contact) -> Audio, ) : MiraiMessageContent(), NekoAble { - @Suppress("DEPRECATION") @Volatile private lateinit var voice: Audio diff --git a/core-api/api/src/main/java/love/forte/simbot/api/sender/ErrorSender.kt b/core-api/api/src/main/java/love/forte/simbot/api/sender/ErrorSender.kt index 148d2a78..1a71c7c3 100644 --- a/core-api/api/src/main/java/love/forte/simbot/api/sender/ErrorSender.kt +++ b/core-api/api/src/main/java/love/forte/simbot/api/sender/ErrorSender.kt @@ -23,7 +23,7 @@ import love.forte.simbot.api.message.results.Result /** * [Sender] 的 无效化实现,所有的方法均会抛出异常。 */ -@Suppress("DEPRECATION", "OverridingDeprecatedMember") +@Suppress("OverridingDeprecatedMember") object ErrorSender : Sender.Def { override suspend fun groupMsg( parent: String?, @@ -45,6 +45,7 @@ object ErrorSender : Sender.Def { ): Nothing = NO("Sender.sendGroupNotice") + @Deprecated("此方法未来将会被从标注接口中移除,且从2.3.0后、移除之前不会在进行维护。") override fun sendGroupSign(group: String, title: String, message: String): Nothing = NO("Sender.sendGroupSign") diff --git a/core-api/core/src/main/java/love/forte/simbot/core/SimbotApp.kt b/core-api/core/src/main/java/love/forte/simbot/core/SimbotApp.kt index 032214ff..b75ea250 100644 --- a/core-api/core/src/main/java/love/forte/simbot/core/SimbotApp.kt +++ b/core-api/core/src/main/java/love/forte/simbot/core/SimbotApp.kt @@ -50,7 +50,8 @@ import java.nio.file.Path import java.util.* import kotlin.concurrent.thread import kotlin.io.path.* -import kotlin.time.Duration +import kotlin.time.Duration.Companion.days +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.ExperimentalTime @@ -478,7 +479,6 @@ protected constructor( ): SimbotContext { // 资源配置数据,获取appType的注解。 - @Suppress("UNCHECKED_CAST") val resourceData: List = AnnotationUtil.getAnnotation(appType, SimbotApplication::class.java)?.value ?.map { @@ -661,7 +661,7 @@ private class Tips { } val lastMod = local.getLastModifiedTime().toMillis() - if (Duration.milliseconds(System.currentTimeMillis() - lastMod) > Duration.days(7)) { + if ((System.currentTimeMillis() - lastMod).milliseconds > 7.days) { local.deleteIfExists() }