From f7649d225d8740f411a4634eba4128e7f740c122 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=B5=B5=E6=80=A1=E7=84=B6?= <63996691+zhaodice@users.noreply.github.com> Date: Sat, 30 Mar 2024 21:54:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=B3=E4=B8=80=E6=88=B3?= =?UTF-8?q?=20=EF=BC=8C=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=AF=AF=E4=BB=A5?= =?UTF-8?q?=E4=B8=BA=E6=9C=89=E4=BA=BA=E6=88=B3=E8=87=AA=E5=B7=B1=20(#2844?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复戳一戳 ,机器人误以为有人戳自己 * Update GroupNotificationProcessor.kt * 呃,我简单粗暴写成bot了,应该是group.botAsMemebr * 代码格式fix * Apply suggestions from code review --------- Co-authored-by: Him188 --- .../group/GroupNotificationProcessor.kt | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt index b59a4bb047f..f0e5ff910a1 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt @@ -11,6 +11,7 @@ package net.mamoe.mirai.internal.network.notice.group import io.ktor.utils.io.core.* import net.mamoe.mirai.contact.NormalMember +import net.mamoe.mirai.contact.UserOrBot import net.mamoe.mirai.contact.getMember import net.mamoe.mirai.data.GroupHonorType import net.mamoe.mirai.event.events.* @@ -315,6 +316,7 @@ internal class GroupNotificationProcessor( } } + /** * @see NudgeEvent * @see MemberHonorChangeEvent @@ -324,25 +326,45 @@ internal class GroupNotificationProcessor( private fun NoticePipelineContext.processGeneralGrayTip( data: MsgType0x2DC, ) = data.context { + val grayTip = buf.loadAs(TroopTips0x857.NotifyMsgBody.serializer(), 1).optGeneralGrayTip markAsConsumed() when (grayTip?.templId) { // 群戳一戳 10043L, 1133L, 1132L, 1134L, 1135L, 1136L -> { + + fun String.findUser(): UserOrBot? { + return if (this == bot.id.toString()) { + group.botAsMember + } else { + this.findMember() ?: this.findFriendOrStranger() + } + } + // group nudge // 预置数据,服务器将不会提供己方已知消息 val action = grayTip.msgTemplParam["action_str"].orEmpty() - val from = grayTip.msgTemplParam["uin_str1"]?.findMember() ?: group.botAsMember - val target = grayTip.msgTemplParam["uin_str2"]?.findMember() ?: group.botAsMember + val from = grayTip.msgTemplParam["uin_str1"] + val target = grayTip.msgTemplParam["uin_str2"] val suffix = grayTip.msgTemplParam["suffix_str"].orEmpty() - collected += NudgeEvent( - from = if (from.id == bot.id) bot else from, - target = if (target.id == bot.id) bot else target, - action = action, - suffix = suffix, - subject = group, - ) + val fromUser = from?.findUser() + val targetUser = target?.findUser() + + if (fromUser == null || targetUser == null) { + markNotConsumed() + logger.debug { + "Cannot find from or target in Transformers528 0x14 template\ntemplId=${grayTip.templId}\nPermList=${grayTip.msgTemplParam.structureToString()}" + } + } else { + collected += NudgeEvent( + from = fromUser, + target = targetUser, + action = action, + suffix = suffix, + subject = group, + ) + } } // 群签到/打卡 10036L, 10038L -> {