mirror of
https://github.com/mamoe/mirai.git
synced 2025-03-24 06:10:09 +08:00
Remove all unstable kotlin.Duration usages
This commit is contained in:
parent
a7a4879d05
commit
eb80a4836b
@ -125,7 +125,6 @@ val experimentalAnnotations = arrayOf(
|
||||
"kotlin.RequiresOptIn",
|
||||
"kotlin.contracts.ExperimentalContracts",
|
||||
"kotlin.experimental.ExperimentalTypeInference",
|
||||
"kotlin.ExperimentalUnsignedTypes",
|
||||
|
||||
"kotlinx.serialization.ExperimentalSerializationApi",
|
||||
|
||||
|
@ -186,7 +186,7 @@ public val UserOrBot.nameCardOrNick: String
|
||||
public suspend inline fun NormalMember.mute(duration: Duration) {
|
||||
require(duration.toDouble(DurationUnit.DAYS) <= 30) { "duration must be at most 1 month" }
|
||||
require(duration.toDouble(DurationUnit.SECONDS) > 0) { "duration must be greater than 0 second" }
|
||||
this.mute(duration.toLong(DurationUnit.SECONDS).toInt())
|
||||
this.mute(duration.toDouble(DurationUnit.SECONDS).toInt())
|
||||
}
|
||||
|
||||
@OptIn(ExperimentalTime::class)
|
||||
|
@ -25,8 +25,8 @@ import net.mamoe.mirai.internal.network.handler.NetworkHandler
|
||||
import net.mamoe.mirai.internal.network.handler.NetworkHandler.State
|
||||
import net.mamoe.mirai.utils.castOrNull
|
||||
import net.mamoe.mirai.utils.info
|
||||
import net.mamoe.mirai.utils.toHumanReadableString
|
||||
import kotlin.time.measureTime
|
||||
import net.mamoe.mirai.utils.millisToHumanReadableString
|
||||
import kotlin.system.measureTimeMillis
|
||||
|
||||
/**
|
||||
* Handles [BotOfflineEvent]
|
||||
@ -92,14 +92,14 @@ internal class BotOfflineEventMonitorImpl : BotOfflineEventMonitor {
|
||||
if (event.reconnect) {
|
||||
bot.launch {
|
||||
val success: Boolean
|
||||
val time = measureTime {
|
||||
val time = measureTimeMillis {
|
||||
success = kotlin.runCatching {
|
||||
bot.login() // selector will create new NH to replace the old, closed one, with some further comprehensive considerations. For example, limitation for attempts.
|
||||
}.isSuccess
|
||||
}
|
||||
|
||||
if (success) {
|
||||
bot.logger.info { "Reconnected successfully in ${time.toHumanReadableString()}." }
|
||||
bot.logger.info { "Reconnected successfully in ${time.millisToHumanReadableString()}." }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,8 @@ import net.mamoe.mirai.internal.network.protocol.packet.sendAndExpect
|
||||
import net.mamoe.mirai.network.LoginFailedException
|
||||
import net.mamoe.mirai.utils.MiraiLogger
|
||||
import net.mamoe.mirai.utils.info
|
||||
import net.mamoe.mirai.utils.toHumanReadableString
|
||||
import kotlin.time.minutes
|
||||
import kotlin.time.seconds
|
||||
import net.mamoe.mirai.utils.millisToHumanReadableString
|
||||
import net.mamoe.mirai.utils.minutesToMillis
|
||||
|
||||
internal interface KeyRefreshProcessor {
|
||||
suspend fun keyRefreshLoop(handler: NetworkHandler)
|
||||
@ -39,8 +38,8 @@ internal class KeyRefreshProcessorImpl(
|
||||
while (isActive) {
|
||||
client.wLoginSigInfo.vKey.run {
|
||||
//由过期时间最短的且不会被skey更换更新的vkey计算重新登录的时间
|
||||
val delay = (expireTime - creationTime).toInt().seconds - 5.minutes
|
||||
logger.info { "Scheduled refresh login session in ${delay.toHumanReadableString()}." }
|
||||
val delay = (expireTime - creationTime).times(1000) - 5.minutesToMillis
|
||||
logger.info { "Scheduled refresh login session in ${delay.millisToHumanReadableString()}." }
|
||||
delay(delay)
|
||||
}
|
||||
runCatching {
|
||||
@ -53,8 +52,8 @@ internal class KeyRefreshProcessorImpl(
|
||||
launch(CoroutineName("Key Refresh Scheduler")) {
|
||||
while (isActive) {
|
||||
client.wLoginSigInfo.sKey.run {
|
||||
val delay = (expireTime - creationTime).seconds - 5.minutes
|
||||
logger.info { "Scheduled key refresh in ${delay.toHumanReadableString()}." }
|
||||
val delay = (expireTime - creationTime).times(1000) - 5.minutesToMillis
|
||||
logger.info { "Scheduled key refresh in ${delay.millisToHumanReadableString()}." }
|
||||
delay(delay)
|
||||
}
|
||||
runCatching {
|
||||
|
Loading…
Reference in New Issue
Block a user