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..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 @@ -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,128 @@ 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 = { + // 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 } } - - + + + conf.heartbeatPeriodMillis = this.heartbeatPeriodMillis conf.heartbeatTimeoutMillis = this.heartbeatTimeoutMillis // conf.firstReconnectDelayMillis = this.firstReconnectDelayMillis @@ -188,8 +197,8 @@ public class MiraiConfiguration { conf.reconnectionRetryTimes = this.reconnectionRetryTimes conf.protocol = this.protocol conf.highwayUploadCoroutineCount = highwayUploadCoroutineCount - - + + if (noBotLog) { conf.noBotLog() } @@ -223,12 +232,12 @@ public class MiraiConfiguration { if (logger is MiraiLoggerWithSwitch) logger else logger.withSwitch(true) } } - + conf } } - +@Deprecated("Unused") internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo { val r = Random(c * s) return DeviceInfo( @@ -241,9 +250,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 +268,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