generated from project-mirai/mirai-console-plugin-template
-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
12 additions
and
4 deletions.
There are no files selected for viewing
16 changes: 12 additions & 4 deletions
16
src/main/kotlin/ltd/guimc/lgzbot/listener/message/AntiMappLinkListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} | ||
} |