diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt b/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt index 4eb12c2a9..888ac90a7 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/ForwardMessage.kt @@ -196,7 +196,7 @@ public fun Iterable.toForwardMessage(displayStrategy: DisplayStrat @JvmOverloads public fun Message.toForwardMessage( sender: User, - time: Int = currentTimeSeconds.toInt(), + time: Int = currentTimeSeconds().toInt(), displayStrategy: DisplayStrategy = DisplayStrategy ): ForwardMessage = this.toForwardMessage(sender.id, sender.nameCardOrNick, time, displayStrategy) @@ -207,7 +207,7 @@ public fun Message.toForwardMessage( public fun Message.toForwardMessage( senderId: Long, senderName: String, - time: Int = currentTimeSeconds.toInt(), + time: Int = currentTimeSeconds().toInt(), displayStrategy: DisplayStrategy = DisplayStrategy ): ForwardMessage = RawForwardMessage(listOf(ForwardMessage.Node(senderId, time, senderName, this))).render(displayStrategy) @@ -331,7 +331,7 @@ public class ForwardMessageBuilder private constructor( * 当前时间. * 在使用 [says] 时若不指定时间, 则会使用 [currentTime] 自增 1 的时间. */ - public var currentTime: Int = currentTimeSeconds.toInt() + public var currentTime: Int = currentTimeSeconds().toInt() public inner class BuilderNode : ForwardMessage.INode { diff --git a/mirai-core-api/src/commonMain/kotlin/message/data/MessageSourceBuilder.kt b/mirai-core-api/src/commonMain/kotlin/message/data/MessageSourceBuilder.kt index 32509734b..c1ae9e1a7 100644 --- a/mirai-core-api/src/commonMain/kotlin/message/data/MessageSourceBuilder.kt +++ b/mirai-core-api/src/commonMain/kotlin/message/data/MessageSourceBuilder.kt @@ -137,7 +137,7 @@ public abstract class MessageSourceBuilder { internal val originalMessages: MessageChainBuilder = MessageChainBuilder() public fun time(from: MessageSource): MessageSourceBuilder = apply { this.time = from.time } - public val now: Int get() = currentTimeSeconds.toInt() + public val now: Int get() = currentTimeSeconds().toInt() public fun time(value: Int): MessageSourceBuilder = apply { this.time = value } public fun internalId(from: MessageSource): MessageSourceBuilder = apply { this.internalIds = from.internalIds } @@ -218,7 +218,7 @@ internal class MessageSourceBuilderImpl : MessageSourceBuilder() { override var targetUin: Long = 0 override var ids: IntArray = intArrayOf() - override var time: Int = currentTimeSeconds.toInt() + override var time: Int = currentTimeSeconds().toInt() override var internalIds: IntArray = intArrayOf() @JvmSynthetic diff --git a/mirai-core-api/src/commonMain/kotlin/utils/TimeUtils.kt b/mirai-core-api/src/commonMain/kotlin/utils/TimeUtils.kt index a69ff3119..1dfe23369 100644 --- a/mirai-core-api/src/commonMain/kotlin/utils/TimeUtils.kt +++ b/mirai-core-api/src/commonMain/kotlin/utils/TimeUtils.kt @@ -19,12 +19,15 @@ import kotlin.time.ExperimentalTime /** * 时间戳 + * + * @see System.currentTimeMillis */ public fun currentTimeMillis(): Long = System.currentTimeMillis() -@get:JvmSynthetic -public inline val currentTimeSeconds: Long - get() = currentTimeMillis() / 1000 +/** + * 时间戳到秒 + */ +public fun currentTimeSeconds(): Long = currentTimeMillis() / 1000 // 临时使用, 待 Kotlin Duration 稳定后使用 Duration. diff --git a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt index 9b41affd3..9a4f4463c 100644 --- a/mirai-core/src/commonMain/kotlin/MiraiImpl.kt +++ b/mirai-core/src/commonMain/kotlin/MiraiImpl.kt @@ -564,7 +564,7 @@ internal open class MiraiImpl : IMirai, LowLevelApiAccessor { val group = getGroup(groupCode) - val time = currentTimeSeconds + val time = currentTimeSeconds() val sequenceId = client.atomicNextMessageSequenceId() network.run { diff --git a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt index a22fb1bf1..5959fbc25 100644 --- a/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/GroupImpl.kt @@ -323,7 +323,7 @@ internal class GroupImpl( listOf( ForwardMessage.Node( senderId = bot.id, - time = currentTimeSeconds.toInt(), + time = currentTimeSeconds().toInt(), message = chain, senderName = bot.nick ) diff --git a/mirai-core/src/commonMain/kotlin/contact/MemberImpl.kt b/mirai-core/src/commonMain/kotlin/contact/MemberImpl.kt index 0c875f94b..f486c53f8 100644 --- a/mirai-core/src/commonMain/kotlin/contact/MemberImpl.kt +++ b/mirai-core/src/commonMain/kotlin/contact/MemberImpl.kt @@ -136,7 +136,7 @@ internal class MemberImpl constructor( get() = if (_muteTimestamp == 0 || _muteTimestamp == 0xFFFFFFFF.toInt()) { 0 } else { - (_muteTimestamp - currentTimeSeconds.toInt()).coerceAtLeast(0) + (_muteTimestamp - currentTimeSeconds().toInt()).coerceAtLeast(0) } override var nameCard: String diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/ImageRequest.kt b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/ImageRequest.kt index 4764716b2..92dd6b620 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/ImageRequest.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/data/proto/ImageRequest.kt @@ -13,7 +13,6 @@ import kotlinx.serialization.Serializable import kotlinx.serialization.protobuf.ProtoNumber import net.mamoe.mirai.internal.utils.io.ProtoBuf import net.mamoe.mirai.utils.currentTimeSeconds -import kotlin.jvm.JvmField internal interface ImgReq : ProtoBuf @@ -37,6 +36,6 @@ internal class GetImgUrlReq( @ProtoNumber(11) @JvmField val addressBook: Int = 0,//[ChatType.internalID]== 1006为1[为CONTACT时] 我觉得发0没问题 @ProtoNumber(12) @JvmField val buType: Int = 1,//确定 @ProtoNumber(13) @JvmField val buildVer: String = "8.2.7.4410",//版本号 - @ProtoNumber(14) @JvmField val timestamp: Int = currentTimeSeconds.toInt(),//(pic_up_timestamp) + @ProtoNumber(14) @JvmField val timestamp: Int = currentTimeSeconds().toInt(),//(pic_up_timestamp) @ProtoNumber(15) @JvmField val requestTransferType: Int = 1 ) : ImgReq \ No newline at end of file diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbSendMsg.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbSendMsg.kt index e31bcb9a9..b6013bde6 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbSendMsg.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/MessageSvc.PbSendMsg.kt @@ -189,7 +189,7 @@ internal inline fun MessageSvcPbSendMsg.createToTemp( internalIds = intArrayOf(Random.nextInt().absoluteValue), sender = client.bot, target = member, - time = currentTimeSeconds.toInt(), + time = currentTimeSeconds().toInt(), sequenceIds = intArrayOf(client.atomicNextMessageSequenceId()), originalMessage = message ) @@ -217,7 +217,7 @@ internal inline fun MessageSvcPbSendMsg.createToFriend( internalIds = intArrayOf(rand), sender = client.bot, target = qq, - time = currentTimeSeconds.toInt(), + time = currentTimeSeconds().toInt(), sequenceIds = intArrayOf(client.nextFriendSeq()), originalMessage = message ) @@ -245,7 +245,7 @@ internal inline fun MessageSvcPbSendMsg.createToGroup( internalIds = intArrayOf(Random.nextInt().absoluteValue), sender = client.bot, target = group, - time = currentTimeSeconds.toInt(), + time = currentTimeSeconds().toInt(), originalMessage = message//, // sourceMessage = message ) diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt index 56706d32a..ebdbfcfa5 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/chat/receive/OnlinePush.ReqPush.kt @@ -207,7 +207,7 @@ private object Transformers732 : Map by mapOf( } else -> { group.botAsMember.checkIsMemberImpl()._muteTimestamp = - currentTimeSeconds.toInt() + timeSeconds + currentTimeSeconds().toInt() + timeSeconds sequenceOf(BotMuteEvent(timeSeconds, operator)) } } @@ -220,7 +220,7 @@ private object Transformers732 : Map by mapOf( return@lambda732 emptySequence() } - member._muteTimestamp = currentTimeSeconds.toInt() + timeSeconds + member._muteTimestamp = currentTimeSeconds().toInt() + timeSeconds return@lambda732 if (timeSeconds == 0) sequenceOf(MemberUnmuteEvent(member, operator)) else sequenceOf(MemberMuteEvent(member, timeSeconds, operator)) }, diff --git a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt index 384b75eb4..1ec66ff04 100644 --- a/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt +++ b/mirai-core/src/commonMain/kotlin/network/protocol/packet/login/WtLogin.kt @@ -516,7 +516,7 @@ internal class WtLogin { // TODO sigMap??? =0x21410e0 // from qq - val creationTime = currentTimeSeconds + val creationTime = currentTimeSeconds() val expireTime = creationTime + 2160000L val outPSKeyMap: PSKeyMap = mutableMapOf() @@ -689,7 +689,7 @@ internal class WtLogin { */ private fun QQAndroidClient.analysisTlv130(t130: ByteArray) = t130.read { discardExact(2) - timeDifference = readUInt().toLong() - currentTimeSeconds + timeDifference = readUInt().toLong() - currentTimeSeconds() ipFromT149 = readBytes(4) }