Skip to content

Commit ab9b521

Browse files
committed
feat: implement time for constructed outgoing forwards
1 parent ffe18cc commit ab9b521

5 files changed

Lines changed: 17 additions & 6 deletions

File tree

acidify-core/src/commonMain/kotlin/org/ntqqrev/acidify/message/BotOutgoingMessageBuilder.kt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import org.ntqqrev.acidify.common.AcidifyDsl
88
import org.ntqqrev.acidify.common.MediaSource
99
import org.ntqqrev.acidify.common.MediaSource.Companion.toMediaSource
1010
import kotlin.js.JsName
11+
import kotlin.time.Clock
1112

1213
/**
1314
* 构建发送消息
@@ -175,11 +176,13 @@ class BotOutgoingMessageBuilder {
175176
* 添加一个伪造合并转发消息
176177
* @param senderUin 该消息的发送者 QQ 号
177178
* @param senderName 该消息的发送者昵称
179+
* @param timestamp 该消息的 Unix 事件戳(秒)
178180
* @param block 构建该消息的内容
179181
*/
180182
inline fun node(
181183
senderUin: Long,
182184
senderName: String,
185+
timestamp: Long = Clock.System.now().epochSeconds,
183186
block: BotOutgoingMessageBuilder.() -> Unit
184187
) {
185188
val messageBuilder = BotOutgoingMessageBuilder()
@@ -188,7 +191,8 @@ class BotOutgoingMessageBuilder {
188191
BotOutgoingSegment.Forward.Node(
189192
senderUin,
190193
senderName,
191-
messageBuilder.segments
194+
messageBuilder.segments,
195+
timestamp,
192196
)
193197
)
194198
}

acidify-core/src/commonMain/kotlin/org/ntqqrev/acidify/message/BotOutgoingSegment.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import org.ntqqrev.acidify.common.MediaSource
44
import org.ntqqrev.acidify.common.MediaSource.Companion.toMediaSource
55
import kotlin.js.JsExport
66
import kotlin.js.JsName
7+
import kotlin.time.Clock
78

89
/**
910
* 发送消息段
@@ -185,11 +186,13 @@ sealed class BotOutgoingSegment {
185186
* @property senderUin 发送者 QQ 号
186187
* @property senderName 发送者名称
187188
* @property segments 消息内容
189+
* @property timestamp 消息的 Unix 事件戳(秒)
188190
*/
189191
data class Node(
190192
val senderUin: Long,
191193
val senderName: String,
192194
val segments: List<BotOutgoingSegment>,
195+
val timestamp: Long = Clock.System.now().epochSeconds,
193196
)
194197
}
195198

acidify-core/src/commonMain/kotlin/org/ntqqrev/acidify/message/internal/MessageBuildingContext.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import org.ntqqrev.acidify.internal.util.pbEncode
2929
import org.ntqqrev.acidify.message.BotOutgoingSegment
3030
import org.ntqqrev.acidify.message.MessageScene
3131
import kotlin.random.Random
32-
import kotlin.time.Clock
3332

3433
internal class MessageBuildingContext(
3534
val bot: AbstractBot,
@@ -556,7 +555,7 @@ internal class MessageBuildingContext(
556555
},
557556
random = Random.nextInt(),
558557
sequence = fakeSequence,
559-
time = Clock.System.now().epochSeconds,
558+
time = timestamp,
560559
clientSequence = fakeSequence,
561560
msgUid = Random.nextLong(1000000000000, 9999999999999),
562561
forwardExt = ContentHead.Forward(

acidify-core/src/jsMain/kotlin/org/ntqqrev/acidify/js/JsBotForwardBlockBuilder.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.ntqqrev.acidify.js
22

33
import org.ntqqrev.acidify.message.BotOutgoingMessageBuilder
4+
import kotlin.time.Clock
45

56
@JsExport
67
@JsName("BotForwardBlockBuilder")
@@ -11,11 +12,13 @@ class JsBotForwardBlockBuilder internal constructor(
1112
fun node(
1213
senderUin: Long,
1314
senderName: String,
14-
block: (JsBotOutgoingMessageBuilder) -> Unit
15+
block: (JsBotOutgoingMessageBuilder) -> Unit,
16+
timestamp: Long = Clock.System.now().epochSeconds
1517
) {
1618
underlying.node(
1719
senderUin,
18-
senderName
20+
senderName,
21+
timestamp,
1922
) {
2023
val b = JsBotOutgoingMessageBuilder(this)
2124
block(b)

acidify-milky/src/commonMain/kotlin/org/ntqqrev/acidify/milky/transform/MessageTransform.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import org.ntqqrev.acidify.milky.MediaSourceScope
1414
import org.ntqqrev.acidify.milky.MilkyContext
1515
import org.ntqqrev.acidify.milky.tracked
1616
import org.ntqqrev.milky.*
17+
import kotlin.time.Clock
1718

1819
suspend fun MilkyContext.transformIncomingMessage(msg: BotIncomingMessage): IncomingMessage? {
1920
val bot = application.dependencies.resolve<AbstractBot>()
@@ -282,7 +283,8 @@ suspend fun MilkyContext.transformOutgoingSegment(
282283
senderName = msg.senderName,
283284
segments = msg.segments.map { seg ->
284285
async { transformOutgoingSegment(scene, peerUin, seg) }
285-
}.awaitAll()
286+
}.awaitAll(),
287+
timestamp = msg.time ?: Clock.System.now().epochSeconds,
286288
)
287289
}
288290
BotOutgoingSegment.Forward(

0 commit comments

Comments
 (0)