feat: add bad word filter
This commit is contained in:
8 files changed
+49
-4
No files matched your search
@@ -37,5 +37,6 @@ val DEFAULT_CONFIG = Config(
|
||||
smtpUser = "114514",
|
||||
smtpPassword = "1919810",
|
||||
smtpFromAddress = "fancybot@repo.rtast.cn",
|
||||
admins = listOf(3458671395L)
|
||||
admins = listOf(3458671395L),
|
||||
enableAntiRevoke = true
|
||||
)
|
||||
@@ -24,6 +24,7 @@ import cn.rtast.fancybot.commands.parse.BVParseCommand
|
||||
import cn.rtast.fancybot.commands.parse.GitHubParseCommand
|
||||
import cn.rtast.fancybot.commands.parse.ImageURLCommand
|
||||
import cn.rtast.fancybot.commands.parse.ReverseGIFCommand
|
||||
import cn.rtast.fancybot.commands.parse.filterBadWord
|
||||
import cn.rtast.fancybot.commands.record.JiJianCommand
|
||||
import cn.rtast.fancybot.commands.record.JrrpCommand
|
||||
import cn.rtast.fancybot.commands.record.MyNiuziCommand
|
||||
@@ -36,6 +37,7 @@ import cn.rtast.fancybot.entity.enums.WSType
|
||||
import cn.rtast.fancybot.items.BaisiItem
|
||||
import cn.rtast.fancybot.items.HeisiItem
|
||||
import cn.rtast.fancybot.items.SetuItem
|
||||
import cn.rtast.fancybot.util.file.BadWordManager
|
||||
import cn.rtast.fancybot.util.file.ConfigManager
|
||||
import cn.rtast.fancybot.util.file.NiuziManager
|
||||
import cn.rtast.fancybot.util.file.SignManager
|
||||
@@ -59,6 +61,8 @@ class FancyBot : OBMessage {
|
||||
val groupId = message.groupId
|
||||
println("$sender($senderId: $groupId): $msg")
|
||||
|
||||
filterBadWord(message)
|
||||
|
||||
if (message.rawMessage.startsWith("https://github.com/") || message.rawMessage.startsWith("git@github.com:")) {
|
||||
GitHubParseCommand.parse(this, message)
|
||||
}
|
||||
@@ -105,6 +109,7 @@ class FancyBot : OBMessage {
|
||||
}
|
||||
|
||||
override suspend fun onGroupMessageRevoke(message: GroupRevokeMessage) {
|
||||
if (!configManager.enableAntiRevoke) return
|
||||
val msg = MessageChain.Builder()
|
||||
.addText("用户: ${message.userId} 被: ${message.operatorId} 撤回了一条消息")
|
||||
.addNewLine()
|
||||
@@ -131,6 +136,7 @@ val configManager = ConfigManager()
|
||||
val itemManager = ItemManager()
|
||||
val signManager = SignManager()
|
||||
val niuziManager = NiuziManager()
|
||||
val badWordManager = BadWordManager()
|
||||
|
||||
val items = listOf(
|
||||
HeisiItem(),
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/18
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands.parse
|
||||
|
||||
import cn.rtast.fancybot.badWordManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
|
||||
suspend fun filterBadWord(message: GroupMessage) {
|
||||
if (badWordManager.contain(message.rawMessage)) {
|
||||
message.reply("你不许说脏话")
|
||||
message.revoke()
|
||||
}
|
||||
}
|
||||
@@ -27,5 +27,6 @@ data class Config(
|
||||
val smtpUser: String,
|
||||
val smtpPassword: String,
|
||||
val smtpFromAddress: String,
|
||||
val admins: List<Long>
|
||||
val admins: List<Long>,
|
||||
val enableAntiRevoke: Boolean
|
||||
)
|
||||
@@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/18
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.util.file
|
||||
|
||||
import cn.rtast.fancybot.util.JsonFileHandler
|
||||
|
||||
class BadWordManager: JsonFileHandler<List<String>>("bd.json", listOf<String>()) {
|
||||
|
||||
fun contain(word: String): Boolean {
|
||||
return this.read<List<String>>().any { word.contains(it) }
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,5 @@ class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||
val smtpPassword get() = this.read<Config>().smtpPassword
|
||||
val smtpFromAddress get() = this.read<Config>().smtpFromAddress
|
||||
val admins get() = this.read<Config>().admins
|
||||
val enableAntiRevoke get() = this.read<Config>().enableAntiRevoke
|
||||
}
|
||||
@@ -20,5 +20,6 @@
|
||||
"smtpFromAddress": "fancybot@repo.rtast.cn",
|
||||
"admins": [
|
||||
3458671395
|
||||
]
|
||||
],
|
||||
"enableAntiRevoke": true
|
||||
}
|
||||
Reference in New Issue
Block a user