Skip to content

Commit e61ca36

Browse files
authored
Merge pull request #175 from simple-robot/dev/fix-174
修复事件中接收的 MessageContent 中, `referenceMessage` 的行为与 `reference` 不一致,会错误地获取自身消息详情而非引用消息详情的问题
2 parents ffc382f + 517e442 commit e61ca36

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

simbot-component-kook-core/src/commonMain/kotlin/love/forte/simbot/component/kook/message/KookReceiveMessageContent.kt

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,10 @@ public class KookReceiveMessageContent internal constructor(
262262
}
263263
}
264264

265-
override suspend fun referenceMessage(): KookMessageContent {
265+
override suspend fun referenceMessage(): KookMessageContent? {
266266
return if (isDirect) {
267-
val details = detailsFromDirect(bot, source.msgId, source.authorId)
267+
val ref = referenceFromDirect(bot, source.msgId, source.authorId) ?: return null
268+
val details = detailsFromDirect(bot, ref.quote.id, source.authorId)
268269
KookUpdatedMessageContent(
269270
bot = bot,
270271
isDirect = false,
@@ -277,7 +278,8 @@ public class KookReceiveMessageContent internal constructor(
277278
isMentionHere = false
278279
)
279280
} else {
280-
val details = detailsFromChannel(bot, source.msgId)
281+
val ref = referenceFromChannel(bot, source.msgId) ?: return null
282+
val details = detailsFromChannel(bot, ref.quote.id)
281283
details.toContent(bot)
282284
}
283285
}
@@ -344,9 +346,11 @@ public class KookUpdatedMessageContent internal constructor(
344346
}
345347

346348
@JvmSynthetic
347-
override suspend fun referenceMessage(): KookMessageContent {
349+
override suspend fun referenceMessage(): KookMessageContent? {
348350
return if (isDirect) {
349-
val details = detailsFromDirectWithChatCode(bot, msgId, chatCode!!)
351+
val chatCode = chatCode!!
352+
val ref = referenceFromDirectWithChatCode(bot, msgId, chatCode) ?: return null
353+
val details = detailsFromDirectWithChatCode(bot, ref.quote.id, chatCode)
350354
KookUpdatedMessageContent(
351355
bot = bot,
352356
isDirect = false,
@@ -359,7 +363,8 @@ public class KookUpdatedMessageContent internal constructor(
359363
isMentionHere = false
360364
)
361365
} else {
362-
val details = detailsFromChannel(bot, msgId)
366+
val ref = referenceFromChannel(bot, msgId) ?: return null
367+
val details = detailsFromChannel(bot, ref.quote.id)
363368
details.toContent(bot)
364369
}
365370
}

0 commit comments

Comments
 (0)