Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

Commit 894daed

Browse files
authored
Merge pull request #2 from simple-robot/v2-dev
Release: v2.5.0
2 parents 6c88095 + 153c815 commit 894daed

File tree

31 files changed

+121
-104
lines changed

31 files changed

+121
-104
lines changed

component/component-ding/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<artifactId>component-parent</artifactId>
2121
<groupId>love.forte.simple-robot</groupId>
22-
<version>2.4.1<!--v--></version>
22+
<version>2.5.0<!--v--></version>
2323
<relativePath>../pom.xml</relativePath>
2424
</parent>
2525
<modelVersion>4.0.0</modelVersion>

component/component-kaiheila-parent/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>component-parent</artifactId>
77
<groupId>love.forte.simple-robot</groupId>
8-
<version>2.4.1<!--v--></version>
8+
<version>2.5.0<!--v--></version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111

component/component-lovelycat-httpapi/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>component-parent</artifactId>
77
<groupId>love.forte.simple-robot</groupId>
8-
<version>2.4.1<!--v--></version>
8+
<version>2.5.0<!--v--></version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

component/component-mirai/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<groupId>love.forte.simple-robot</groupId>
77
<artifactId>component-parent</artifactId>
8-
<version>2.4.1<!--v--></version>
8+
<version>2.5.0<!--v--></version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>
@@ -22,7 +22,7 @@
2222
<url>https://github.com/ForteScarlet/simpler-robot/tree/dev/component/component-mirai</url>
2323

2424
<properties>
25-
<mirai.version>2.11.1</mirai.version>
25+
<mirai.version>2.13.0-RC2</mirai.version>
2626
</properties>
2727

2828

component/component-mirai/src/main/java/love/forte/simbot/component/mirai/configuration/MiraiConfiguration.kt

Lines changed: 77 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package love.forte.simbot.component.mirai.configuration
1717

1818
import cn.hutool.crypto.SecureUtil
19-
import kotlinx.serialization.ExperimentalSerializationApi
2019
import kotlinx.serialization.encodeToString
2120
import kotlinx.serialization.json.Json
2221
import love.forte.common.configuration.annotation.ConfigInject
@@ -52,144 +51,154 @@ public fun miraiBotLogger(botCode: Long, type: String? = null): Logger {
5251
@Beans("miraiConfiguration")
5352
@AsMiraiConfig
5453
public class MiraiConfiguration {
55-
54+
5655
private companion object : TypedCompLogger(MiraiConfiguration::class.java)
57-
56+
5857
/**
5958
* mirai心跳周期. 过长会导致被服务器断开连接. 单位毫秒
6059
* @see BotConfiguration.heartbeatPeriodMillis
6160
*/
6261
@field:ConfigInject
6362
var heartbeatPeriodMillis: Long = BotConfiguration.Default.heartbeatPeriodMillis
64-
63+
6564
/**
6665
* 每次心跳时等待结果的时间.
6766
* 一旦心跳超时, 整个网络服务将会重启 (将消耗约 1s). 除正在进行的任务 (如图片上传) 会被中断外, 事件和插件均不受影响.
6867
* @see BotConfiguration.heartbeatTimeoutMillis
6968
*/
7069
@field:ConfigInject
7170
var heartbeatTimeoutMillis: Long = BotConfiguration.Default.heartbeatTimeoutMillis
72-
71+
7372
/**
7473
* mirai 心跳策略.
7574
*/
7675
@field:ConfigInject
7776
var heartbeatStrategy: BotConfiguration.HeartbeatStrategy = BotConfiguration.Default.heartbeatStrategy
78-
79-
77+
78+
8079
/** 最多尝试多少次重连 */
8180
@field:ConfigInject
8281
var reconnectionRetryTimes: Int = BotConfiguration.Default.reconnectionRetryTimes
83-
84-
82+
83+
8584
/**
8685
* 使用协议类型。
8786
* 默认使用 [安卓手机协议][BotConfiguration.MiraiProtocol.ANDROID_PHONE]。
8887
*/
8988
@field:ConfigInject
9089
var protocol: BotConfiguration.MiraiProtocol = BotConfiguration.Default.protocol
91-
90+
9291
/** 关闭mirai的bot logger */
9392
@field:ConfigInject
9493
var noBotLog: Boolean = false
95-
94+
9695
/** 关闭mirai网络日志 */
9796
@field:ConfigInject
9897
var noNetworkLog: Boolean = false
99-
98+
10099
/** mirai bot log切换使用simbot的log(slf4j-api) */
101100
@field:ConfigInject
102101
var useSimbotBotLog: Boolean = true
103-
102+
104103
/** mirai 网络log 切换使用simbot的log(slf4j-api) */
105104
@field:ConfigInject
106105
var useSimbotNetworkLog: Boolean = true
107-
106+
108107
/** mirai配置自定义deviceInfoSeed的时候使用的随机种子。默认为1. */
109108
@field:ConfigInject
110109
var deviceInfoSeed: Long = 1L
111-
112-
110+
111+
113112
@field:ConfigInject
114-
var deviceInfoFile: String? = ""
115-
113+
var deviceInfoFile: String? = "device.json"
114+
115+
/**
116+
* 如果为true,则通过 [deviceInfoFile] 的值进行基于文件的随机设备信息配置。
117+
*/
118+
@field:ConfigInject
119+
var deviceInfoFileBased: Boolean = true
120+
116121
/**
117122
* 是否输出设备信息
118123
*/
119124
@field:ConfigInject
120125
var deviceInfoOutput: Boolean = false
121-
126+
122127
/**
123128
* @see BotConfiguration.highwayUploadCoroutineCount
124129
*/
125130
@field:ConfigInject
126131
var highwayUploadCoroutineCount: Int = BotConfiguration.Default.highwayUploadCoroutineCount
127-
132+
128133
private val json = Json {
129134
isLenient = true
130135
ignoreUnknownKeys = true
131136
prettyPrint = true
132137
}
133-
138+
134139
/**
135140
* mirai官方配置类获取函数,默认为其默认值
136141
* */
137142
// @set:Deprecated("use setPostBotConfigurationProcessor((code, conf) -> {...})")
138-
139-
@OptIn(ExperimentalSerializationApi::class)
143+
140144
val botConfiguration: (String) -> BotConfiguration = {
141145
val conf = BotConfiguration()
142-
143-
deviceInfoFile.takeIf { it?.isNotBlank() == true }?.runCatching {
144-
logger.info("Try to use device info file: $this")
145-
val jsonReader = ResourceUtil.getResourceUtf8Reader(this)
146-
val json = jsonReader.use { it.readText() }
147-
conf.loadDeviceInfoJson(json)
148-
}?.getOrElse { e ->
149-
logger.error("Load device Info json file: $deviceInfoFile failed. get device by simbot default.", e)
150-
null
151-
} ?: run {
152-
conf.deviceInfo = {
153-
val devInfo = simbotMiraiDeviceInfo(it.id, deviceInfoSeed)
154-
155-
if (deviceInfoOutput) {
156-
runCatching<Unit> {
157-
val devInfoJson = json.encodeToString(devInfo)
158-
val outFile = File("simbot-devInfo.json")
159-
if (!outFile.exists()) {
160-
outFile.apply {
161-
parentFile?.mkdirs()
162-
createNewFile()
146+
147+
if (deviceInfoFileBased) {
148+
conf.fileBasedDeviceInfo(deviceInfoFile?.takeIf { it.isNotEmpty() } ?: "device.json")
149+
} else {
150+
deviceInfoFile.takeIf { it?.isNotBlank() == true }?.runCatching {
151+
logger.info("Try to use device info file: $this")
152+
val jsonReader = ResourceUtil.getResourceUtf8Reader(this)
153+
val json = jsonReader.use { it.readText() }
154+
conf.loadDeviceInfoJson(json)
155+
}?.getOrElse { e ->
156+
logger.error("Load device info json file: $deviceInfoFile failed. get device via mirai random.", e)
157+
null
158+
} ?: run {
159+
// conf.fileBasedDeviceInfo(deviceInfoFile ?: "device.json")
160+
conf.deviceInfo = {
161+
// random.
162+
DeviceInfo.random().also { devInfo ->
163+
if (deviceInfoOutput) {
164+
logger.warn("The configuration property 'deviceInfoOutput' is not recommended")
165+
runCatching<Unit> {
166+
val devInfoJson = json.encodeToString(devInfo)
167+
val outFile = File("simbot-devInfo.json")
168+
if (!outFile.exists()) {
169+
outFile.apply {
170+
parentFile?.mkdirs()
171+
createNewFile()
172+
}
173+
}
174+
FileWriter(outFile).use { w ->
175+
w.write(devInfoJson)
176+
logger.info("DevInfo write to ${outFile.canonicalPath}")
177+
}
178+
}.getOrElse { e ->
179+
logger.error("Write devInfo failed: {}", e.localizedMessage)
180+
if (!logger.isDebugEnabled) {
181+
logger.error("Enable debug log for more information.")
182+
}
183+
logger.debug("Write devInfo failed.", e)
163184
}
164185
}
165-
FileWriter(outFile).use { w ->
166-
w.write(devInfoJson)
167-
logger.info("DevInfo write to ${outFile.canonicalPath}")
168-
}
169-
}.getOrElse { e ->
170-
logger.error("Write devInfo failed: {}", e.localizedMessage)
171-
if (!logger.isDebugEnabled) {
172-
logger.error("Enable debug log for more information.")
173-
}
174-
logger.debug("Write devInfo failed.", e)
175186
}
176187
}
177-
178-
179-
devInfo
180188
}
181189
}
182-
183-
190+
191+
192+
184193
conf.heartbeatPeriodMillis = this.heartbeatPeriodMillis
185194
conf.heartbeatTimeoutMillis = this.heartbeatTimeoutMillis
186195
// conf.firstReconnectDelayMillis = this.firstReconnectDelayMillis
187196
// conf.reconnectPeriodMillis = this.reconnectPeriodMillis
188197
conf.reconnectionRetryTimes = this.reconnectionRetryTimes
189198
conf.protocol = this.protocol
190199
conf.highwayUploadCoroutineCount = highwayUploadCoroutineCount
191-
192-
200+
201+
193202
if (noBotLog) {
194203
conf.noBotLog()
195204
}
@@ -223,12 +232,12 @@ public class MiraiConfiguration {
223232
if (logger is MiraiLoggerWithSwitch) logger else logger.withSwitch(true)
224233
}
225234
}
226-
235+
227236
conf
228237
}
229238
}
230239

231-
240+
@Deprecated("Unused")
232241
internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo {
233242
val r = Random(c * s)
234243
return DeviceInfo(
@@ -241,9 +250,11 @@ internal fun simbotMiraiDeviceInfo(c: Long, s: Long): DeviceInfo {
241250
bootloader = "unknown".toByteArray(),
242251
// mamoe/mirai/mirai:10/MIRAI.200122.001/
243252
fingerprint = "mamoe/mirai/mirai:10/MIRAI.200122.001/${
244-
getRandomString(7,
253+
getRandomString(
254+
7,
245255
'0'..'9',
246-
r)
256+
r
257+
)
247258
}:user/release-keys".toByteArray(),
248259
bootId = generateUUID(SecureUtil.md5().digest(getRandomByteArray(16, r))).toByteArray(),
249260
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 {
257268
imsiMd5 = SecureUtil.md5().digest(getRandomByteArray(16, r)),
258269
imei = getRandomString(15, '0'..'9', r),
259270
apn = "wifi".toByteArray()
260-
271+
261272
)
262273
}
263274

component/component-mirai/src/main/java/love/forte/simbot/component/mirai/message/MiraiMessageContent.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,13 @@ public abstract class MiraiMessageContent : MessageContent {
7878
public data class MiraiListMessageContent(val list: List<MiraiMessageContent>) : MiraiMessageContent() {
7979
override suspend fun getMessage(contact: Contact): Message {
8080
return when {
81-
list.isEmpty() -> EmptyMessageChain
81+
list.isEmpty() -> emptyMessageChain()
8282
list.size == 1 -> list[0].getMessage(contact)
8383
list.size == 2 -> list.first().getMessage(contact) + list.last().getMessage(contact)
8484
else -> list.map { it.getMessage(contact) }
8585
.asSequence()
8686
.filter { it.isNotEmptyMsg() }
87-
.reduceOrNull { m1, m2 -> m1 + m2 } ?: EmptyMessageChain
87+
.reduceOrNull { m1, m2 -> m1 + m2 } ?: emptyMessageChain()
8888
}
8989

9090
}
@@ -392,10 +392,9 @@ constructor(
392392
@Deprecated("Use MiraiAudioMessageContent", replaceWith = ReplaceWith("MiraiAudioMessageContent"))
393393
public class MiraiVoiceMessageContent(
394394
override val neko: Neko,
395-
@Suppress("DEPRECATION") private val voiceFunction: suspend (Contact) -> Audio,
395+
private val voiceFunction: suspend (Contact) -> Audio,
396396
) : MiraiMessageContent(), NekoAble {
397397

398-
@Suppress("DEPRECATION")
399398
@Volatile
400399
private lateinit var voice: Audio
401400

component/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>project</artifactId>
77
<groupId>love.forte.simple-robot</groupId>
8-
<version>2.4.1<!--v--></version>
8+
<version>2.5.0<!--v--></version>
99
<relativePath>../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

core-api/api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>project</artifactId>
77
<groupId>love.forte.simple-robot</groupId>
8-
<version>2.4.1<!--v--></version>
8+
<version>2.5.0<!--v--></version>
99
<relativePath>../../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

core-api/api/src/main/java/love/forte/simbot/api/sender/ErrorSender.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import love.forte.simbot.api.message.results.Result
2323
/**
2424
* [Sender] 的 无效化实现,所有的方法均会抛出异常。
2525
*/
26-
@Suppress("DEPRECATION", "OverridingDeprecatedMember")
26+
@Suppress("OverridingDeprecatedMember")
2727
object ErrorSender : Sender.Def {
2828
override suspend fun groupMsg(
2929
parent: String?,
@@ -45,6 +45,7 @@ object ErrorSender : Sender.Def {
4545
): Nothing =
4646
NO("Sender.sendGroupNotice")
4747

48+
@Deprecated("此方法未来将会被从标注接口中移除,且从2.3.0后、移除之前不会在进行维护。")
4849
override fun sendGroupSign(group: String, title: String, message: String): Nothing =
4950
NO("Sender.sendGroupSign")
5051

core-api/core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>project</artifactId>
77
<groupId>love.forte.simple-robot</groupId>
8-
<version>2.4.1<!--v--></version>
8+
<version>2.5.0<!--v--></version>
99
<relativePath>../../pom.xml</relativePath>
1010
</parent>
1111
<modelVersion>4.0.0</modelVersion>

0 commit comments

Comments
 (0)