From 45bcd0fa83e5bdb983f18e7eeb35348f173ba5f2 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 1 Jan 2020 19:01:07 +0800 Subject: [PATCH] Ignore group messages sent by bot itself --- .../kotlin/net.mamoe.mirai/message/GroupMessage.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt index 193f39a7a..e15e5b4fe 100644 --- a/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt +++ b/mirai-core/src/commonMain/kotlin/net.mamoe.mirai/message/GroupMessage.kt @@ -4,8 +4,10 @@ import net.mamoe.mirai.Bot import net.mamoe.mirai.contact.Group import net.mamoe.mirai.contact.Member import net.mamoe.mirai.contact.MemberPermission +import net.mamoe.mirai.event.BroadcastControllable import net.mamoe.mirai.message.data.At import net.mamoe.mirai.message.data.MessageChain +import net.mamoe.mirai.qqAccount import net.mamoe.mirai.utils.unsafeWeakRef @Suppress("unused", "NOTHING_TO_INLINE") @@ -19,7 +21,7 @@ class GroupMessage( val permission: MemberPermission, sender: Member, override val message: MessageChain -) : MessagePacket(bot) { +) : MessagePacket(bot), BroadcastControllable { val group: Group by group.unsafeWeakRef() override val sender: Member by sender.unsafeWeakRef() @@ -32,4 +34,8 @@ class GroupMessage( inline fun Long.member(): Member = group.getMember(this) override fun toString(): String = "GroupMessage(group=${group.id}, senderName=$senderName, sender=${sender.id}, permission=${permission.name}, message=$message)" + + + override val shouldBroadcast: Boolean + get() = bot.qqAccount != sender.id // 自己会收到自己发的消息 } \ No newline at end of file