Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
guimc233 committed Aug 7, 2024
1 parent c62beb1 commit 088c6c4
Show file tree
Hide file tree
Showing 6 changed files with 923 additions and 891 deletions.
3 changes: 3 additions & 0 deletions src/main/kotlin/ltd/guimc/lgzbot/PluginMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import ltd.guimc.lgzbot.utils.FbUtils.getFbValue
import ltd.guimc.lgzbot.utils.LL4JUtils
import ltd.guimc.lgzbot.utils.RegexUtils.getDefaultPinyinRegex
import ltd.guimc.lgzbot.utils.RegexUtils.getDefaultRegex
import ltd.guimc.lgzbot.utils.RegexUtils.getSeriousRegex
import ltd.guimc.lgzbot.utils.RequestUtils
import ltd.guimc.lgzbot.webhook.GithubWebHookReciver
import ltd.guimc.lgzbot.webhook.WebHookService
Expand Down Expand Up @@ -72,6 +73,7 @@ object PluginMain : KotlinPlugin(
lateinit var disableRoot: Permission
lateinit var adRegex: Array<Regex>
lateinit var adPinyinRegex: Array<Regex>
lateinit var seriousRegex: Array<Regex>
lateinit var fbValue: Array<String>
lateinit var webHookService: WebHookService
lateinit var configReloadThread: Thread
Expand All @@ -89,6 +91,7 @@ object PluginMain : KotlinPlugin(

adRegex = getDefaultRegex()
adPinyinRegex = getDefaultPinyinRegex()
seriousRegex = getSeriousRegex()
fbValue = getFbValue()
webHookService = WebHookService(GithubWebHookReciver())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ltd.guimc.lgzbot.PluginMain.adPinyinRegex
import ltd.guimc.lgzbot.PluginMain.adRegex
import ltd.guimc.lgzbot.PluginMain.disableImageCheck
import ltd.guimc.lgzbot.PluginMain.logger
import ltd.guimc.lgzbot.PluginMain.seriousRegex
import ltd.guimc.lgzbot.files.ModuleStateConfig
import ltd.guimc.lgzbot.listener.message.MessageFilter.historyMessage
import ltd.guimc.lgzbot.listener.message.MessageFilter.messagesHandled
Expand Down Expand Up @@ -91,7 +92,13 @@ object ImageOCRFilter {

val predictedResult = LL4JUtils.predictAllResult(content)
val predicted = predictedResult[1] > predictedResult[0]
if (RegexUtils.matchRegex(adRegex, content) && content.length >= 30) {
if (RegexUtils.matchRegex(seriousRegex, content)) {
recalledMessage++
e.message.recall()
e.sender.mute(7 * 24 * 60 * 60, "非法发言内容 (图片OCR识别) (敏感内容)")
muted = true
}
if (!muted && RegexUtils.matchRegex(adRegex, content) && content.length >= 30) {
try {
recalledMessage++
e.message.recall()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import ltd.guimc.lgzbot.PluginMain.bypassMute
import ltd.guimc.lgzbot.PluginMain.disableADCheck
import ltd.guimc.lgzbot.PluginMain.disableSpamCheck
import ltd.guimc.lgzbot.PluginMain.logger
import ltd.guimc.lgzbot.PluginMain.seriousRegex
import ltd.guimc.lgzbot.counter.VLManager
import ltd.guimc.lgzbot.files.Config
import ltd.guimc.lgzbot.files.ModuleStateConfig
Expand Down Expand Up @@ -77,9 +78,15 @@ object MessageFilter {

allCheckedMessage++
if (!e.group.permitteeId.hasPermission(disableADCheck)) {
if (RegexUtils.matchRegex(seriousRegex, textMessage)) {
recalledMessage++
e.message.recall()
e.sender.mute(14 * 24 * 60 * 60, "非法发言内容 (敏感内容)")
muted = true
}
val predictedResult = LL4JUtils.predictAllResult(textMessage)
val predicted = predictedResult[1] > predictedResult[0]
if (RegexUtils.matchRegex(adRegex, textMessage) && textMessage.length >= stringLength) {
if (!muted && RegexUtils.matchRegex(adRegex, textMessage) && textMessage.length >= stringLength) {
try {
recalledMessage++
e.message.recall()
Expand Down Expand Up @@ -156,6 +163,12 @@ object MessageFilter {
if (!muted && forwardMessage != null) {
forwardMessage!!.nodeList.forEach {
val forwardMessageItemString = it.messageChain.getPlainText()
if (RegexUtils.matchRegex(seriousRegex, forwardMessageItemString)) {
recalledMessage++
e.message.recall()
e.sender.mute(14 * 24 * 60 * 60, "非法发言内容 (在合并转发消息内) (敏感内容)")
muted = true
}
if (!muted && RegexUtils.matchRegex(
adRegex,
forwardMessageItemString
Expand Down
14 changes: 14 additions & 0 deletions src/main/kotlin/ltd/guimc/lgzbot/utils/RegexUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,20 @@ object RegexUtils {
return regexList.toTypedArray()
}

fun getSeriousRegex(): Array<Regex> {
// Read from resources regex.txt
val regexFile = RegexUtils::class.java.getResourceAsStream("/serious.txt")
val regexList = mutableListOf<Regex>()
regexFile?.bufferedReader()?.use { reader ->
reader.lines().forEach {
// regexList.add(Regex(PinyinUtils.convertToPinyin(it)))
regexList.add(Regex(it))
}
}

return regexList.toTypedArray()
}

// 匹配正则表达式列表 返回是否匹配
fun matchRegex(regexList: Array<Regex>, message: String): Boolean {
try {
Expand Down
Loading

0 comments on commit 088c6c4

Please sign in to comment.