Skip to content

Commit

Permalink
anti mqqapi link
Browse files Browse the repository at this point in the history
  • Loading branch information
guimc233 committed Jul 6, 2024
1 parent 5f5ea76 commit 903e610
Showing 1 changed file with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package ltd.guimc.lgzbot.listener.message

import net.mamoe.mirai.event.events.GroupMessageEvent
import net.mamoe.mirai.message.data.*
import net.mamoe.mirai.message.data.ForwardMessage
import net.mamoe.mirai.message.data.MessageChain
import net.mamoe.mirai.message.data.QuoteReply
import net.mamoe.mirai.message.data.RichMessage

object AntiMappLinkListener {
suspend fun filter(e: GroupMessageEvent) {
Expand All @@ -10,14 +13,24 @@ object AntiMappLinkListener {

fun check(m: MessageChain): Boolean {
for (singleMessage in m) {
if (singleMessage is RichMessage && singleMessage.content.contains("mqqapi:\\/\\/")) {
if (singleMessage is RichMessage && (singleMessage.content.contains("mqqapi:\\/\\/") || singleMessage.content.contains(
"mqqapi://"
))
) {
return true
}

if (singleMessage is ForwardMessage) {
return check(singleMessage.toMessageChain())
return checkForwarded(singleMessage)
}
}
return false
}

fun checkForwarded(m: ForwardMessage): Boolean {
for (singleNode in m.nodeList) {
if (check(singleNode.messageChain)) return true
}
return false
}
}

0 comments on commit 903e610

Please sign in to comment.