diff --git a/src/main/kotlin/ltd/guimc/lgzbot/listener/message/AntiMappLinkListener.kt b/src/main/kotlin/ltd/guimc/lgzbot/listener/message/AntiMappLinkListener.kt index 0aec192..6a882da 100644 --- a/src/main/kotlin/ltd/guimc/lgzbot/listener/message/AntiMappLinkListener.kt +++ b/src/main/kotlin/ltd/guimc/lgzbot/listener/message/AntiMappLinkListener.kt @@ -1,15 +1,23 @@ package ltd.guimc.lgzbot.listener.message import net.mamoe.mirai.event.events.GroupMessageEvent -import net.mamoe.mirai.message.data.QuoteReply -import net.mamoe.mirai.message.data.RichMessage +import net.mamoe.mirai.message.data.* object AntiMappLinkListener { suspend fun filter(e: GroupMessageEvent) { - for (singleMessage in e.message) { + if (check(e.message)) e.subject.sendMessage(QuoteReply(e.source) + "WARN: 本消息可能包含mqqapi链接 请注意安全") + } + + fun check(m: MessageChain): Boolean { + for (singleMessage in m) { if (singleMessage is RichMessage && singleMessage.content.contains("mqqapi:\\/\\/")) { - e.subject.sendMessage(QuoteReply(e.source) + "WARN: 本可能消息包含mqqapi链接 请注意安全") + return true + } + + if (singleMessage is ForwardMessage) { + return check(singleMessage.toMessageChain()) } } + return false } } \ No newline at end of file