From f95b208ca818808275692e8d971a1c9a6b196828 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: Fri, 22 Mar 2024 01:25:48 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=88=B3=E4=B8=80?= =?UTF-8?q?=E6=88=B3=20=EF=BC=8C=E6=9C=BA=E5=99=A8=E4=BA=BA=E8=AF=AF?= =?UTF-8?q?=E4=BB=A5=E4=B8=BA=E6=9C=89=E4=BA=BA=E6=88=B3=E8=87=AA=E5=B7=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../group/GroupNotificationProcessor.kt | 39 ++++++++++++++----- 1 file changed, 30 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..ac71a97fac4 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,6 +326,15 @@ internal class GroupNotificationProcessor( private fun NoticePipelineContext.processGeneralGrayTip( data: MsgType0x2DC, ) = data.context { + + fun String.findUser(): UserOrBot? { + return if (this == bot.id.toString()) { + bot + } else { + this.findMember()?: this.findFriendOrStranger() + } + } + val grayTip = buf.loadAs(TroopTips0x857.NotifyMsgBody.serializer(), 1).optGeneralGrayTip markAsConsumed() when (grayTip?.templId) { @@ -332,17 +343,27 @@ internal class GroupNotificationProcessor( // 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 -> { From 852a888aa5396e1e44e112ad7ab45ab5d7518099 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: Fri, 22 Mar 2024 01:32:39 +0800 Subject: [PATCH 2/5] Update GroupNotificationProcessor.kt --- .../kotlin/network/notice/group/GroupNotificationProcessor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ac71a97fac4..31a99ae98cc 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt @@ -331,7 +331,7 @@ internal class GroupNotificationProcessor( return if (this == bot.id.toString()) { bot } else { - this.findMember()?: this.findFriendOrStranger() + this.findMember() ?: this.findFriendOrStranger() } } From c609bd12f37ca8b1810793ad73644c2ad13e4e69 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: Fri, 22 Mar 2024 01:44:13 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=E5=91=83=EF=BC=8C=E6=88=91=E7=AE=80?= =?UTF-8?q?=E5=8D=95=E7=B2=97=E6=9A=B4=E5=86=99=E6=88=90bot=E4=BA=86?= =?UTF-8?q?=EF=BC=8C=E5=BA=94=E8=AF=A5=E6=98=AFgroup.botAsMemebr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notice/group/GroupNotificationProcessor.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 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 31a99ae98cc..7a90283a205 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt @@ -327,19 +327,20 @@ internal class GroupNotificationProcessor( data: MsgType0x2DC, ) = data.context { - fun String.findUser(): UserOrBot? { - return if (this == bot.id.toString()) { - bot - } else { - this.findMember() ?: this.findFriendOrStranger() - } - } - 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() From 919080871f113d762ea5bd9114785aed551ebce6 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: Fri, 22 Mar 2024 02:18:11 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E4=BB=A3=E7=A0=81=E6=A0=BC=E5=BC=8Ffix?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kotlin/network/notice/group/GroupNotificationProcessor.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 7a90283a205..890ebb6d1b2 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt @@ -337,7 +337,7 @@ internal class GroupNotificationProcessor( return if (this == bot.id.toString()) { group.botAsMember } else { - this.findMember()?: this.findFriendOrStranger() + this.findMember() ?: this.findFriendOrStranger() } } From e78b8474c21fcf211bbd30659e1e3bcf08400d37 Mon Sep 17 00:00:00 2001 From: Him188 Date: Sat, 30 Mar 2024 13:54:34 +0000 Subject: [PATCH 5/5] Apply suggestions from code review --- .../kotlin/network/notice/group/GroupNotificationProcessor.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 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 890ebb6d1b2..f0e5ff910a1 100644 --- a/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt +++ b/mirai-core/src/commonMain/kotlin/network/notice/group/GroupNotificationProcessor.kt @@ -351,12 +351,12 @@ internal class GroupNotificationProcessor( val fromUser = from?.findUser() val targetUser = target?.findUser() - if(fromUser == null || targetUser == null){ + 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{ + } else { collected += NudgeEvent( from = fromUser, target = targetUser,