feat: add black list manager to manage group who kicked the bot
This commit is contained in:
10 files changed
+123
-8
No files matched your search
@@ -26,6 +26,7 @@ import cn.rtast.fancybot.enums.ImageBedType
|
|||||||
import cn.rtast.fancybot.enums.ImageType
|
import cn.rtast.fancybot.enums.ImageType
|
||||||
import cn.rtast.fancybot.enums.WSType
|
import cn.rtast.fancybot.enums.WSType
|
||||||
import cn.rtast.fancybot.items.*
|
import cn.rtast.fancybot.items.*
|
||||||
|
import cn.rtast.fancybot.util.file.BlackListManager
|
||||||
import cn.rtast.fancybot.util.file.ConfigManager
|
import cn.rtast.fancybot.util.file.ConfigManager
|
||||||
import cn.rtast.fancybot.util.file.NiuziBankManager
|
import cn.rtast.fancybot.util.file.NiuziBankManager
|
||||||
import cn.rtast.fancybot.util.file.NiuziManager
|
import cn.rtast.fancybot.util.file.NiuziManager
|
||||||
@@ -67,7 +68,7 @@ val DEFAULT_CONFIG = Config(
|
|||||||
llamaUrl = "http://127.0.0.1",
|
llamaUrl = "http://127.0.0.1",
|
||||||
llamaModel = "llama3.1",
|
llamaModel = "llama3.1",
|
||||||
qqMusicApiUrl = "http://127.0.0.1:3200",
|
qqMusicApiUrl = "http://127.0.0.1:3200",
|
||||||
startUpNoticeUser = 114514L,
|
noticeUser = 114514L,
|
||||||
selfId = 114514L,
|
selfId = 114514L,
|
||||||
tianXingApiKey = "1145141919810",
|
tianXingApiKey = "1145141919810",
|
||||||
githubUser = "RTAkland",
|
githubUser = "RTAkland",
|
||||||
@@ -86,6 +87,7 @@ val configManager = ConfigManager()
|
|||||||
val itemManager = ItemManager()
|
val itemManager = ItemManager()
|
||||||
val niuziManager = NiuziManager()
|
val niuziManager = NiuziManager()
|
||||||
val niuziBankManager = NiuziBankManager()
|
val niuziBankManager = NiuziBankManager()
|
||||||
|
val blackListManager = BlackListManager()
|
||||||
|
|
||||||
val START_UP_TIME = Instant.now().epochSecond
|
val START_UP_TIME = Instant.now().epochSecond
|
||||||
|
|
||||||
@@ -120,5 +122,6 @@ val commands = listOf(
|
|||||||
ReactionCommand(), MCSkinCommand(), GithubLatestCommitCommand(), RandomMusicCommand(),
|
ReactionCommand(), MCSkinCommand(), GithubLatestCommitCommand(), RandomMusicCommand(),
|
||||||
ZDJDCommand(), ScanQRCodeCommand(), TTSCommand(), SlimeChunkHelperCommand(),
|
ZDJDCommand(), ScanQRCodeCommand(), TTSCommand(), SlimeChunkHelperCommand(),
|
||||||
SupportMeCommand(), TheCatCommand(), TheHistoryOfTodayCommand(), MCVersionCommand(),
|
SupportMeCommand(), TheCatCommand(), TheHistoryOfTodayCommand(), MCVersionCommand(),
|
||||||
MinecraftWikiCommand(), GaoKaoDaysRemainCommand(), IdiomExplainCommand(), NiuziManagerCommand()
|
MinecraftWikiCommand(), GaoKaoDaysRemainCommand(), IdiomExplainCommand(), NiuziManagerCommand(),
|
||||||
|
TodayEatCommand(), TodayDrinkCommand()
|
||||||
)
|
)
|
||||||
@@ -14,6 +14,7 @@ import cn.rtast.fancybot.enums.WSType
|
|||||||
import cn.rtast.fancybot.util.*
|
import cn.rtast.fancybot.util.*
|
||||||
import cn.rtast.fancybot.util.file.getFileType
|
import cn.rtast.fancybot.util.file.getFileType
|
||||||
import cn.rtast.fancybot.util.misc.ImageBed
|
import cn.rtast.fancybot.util.misc.ImageBed
|
||||||
|
import cn.rtast.fancybot.util.misc.convertToDate
|
||||||
import cn.rtast.fancybot.util.misc.initCommandAndItem
|
import cn.rtast.fancybot.util.misc.initCommandAndItem
|
||||||
import cn.rtast.fancybot.util.misc.initFilesDir
|
import cn.rtast.fancybot.util.misc.initFilesDir
|
||||||
import cn.rtast.fancybot.util.misc.initSetuIndex
|
import cn.rtast.fancybot.util.misc.initSetuIndex
|
||||||
@@ -40,7 +41,7 @@ class FancyBot : OneBotListener {
|
|||||||
private val githubRegex = Regex("""github\.com/([^/]+)/([^/]+)""")
|
private val githubRegex = Regex("""github\.com/([^/]+)/([^/]+)""")
|
||||||
|
|
||||||
override suspend fun onWebsocketOpenEvent() {
|
override suspend fun onWebsocketOpenEvent() {
|
||||||
this.sendPrivateMessage(configManager.startUpNoticeUser, "FancyBot启动完成~")
|
this.sendPrivateMessage(configManager.noticeUser, "FancyBot启动完成~")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onGroupMessage(message: GroupMessage, json: String) {
|
override suspend fun onGroupMessage(message: GroupMessage, json: String) {
|
||||||
@@ -182,6 +183,14 @@ class FancyBot : OneBotListener {
|
|||||||
this.sendGroupMessage(event.groupId!!, msg)
|
this.sendGroupMessage(event.groupId!!, msg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override suspend fun onBeKicked(groupId: Long, operator: Long, time: Long) {
|
||||||
|
blackListManager.insertGroup(groupId, operator, time)
|
||||||
|
this.sendPrivateMessage(
|
||||||
|
configManager.noticeUser,
|
||||||
|
"被: ${groupId}踢出! 操作人: $operator 时间: ${time.convertToDate()} 已将其拉入黑名单!"
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun main() {
|
suspend fun main() {
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/11
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.misc
|
||||||
|
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
|
||||||
|
class TodayEatCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("今天吃什么")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
message.reply("你吃牛魔, 别吃了")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class TodayDrinkCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("今天喝什么")
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/11
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.db
|
||||||
|
|
||||||
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
|
||||||
|
object BlackListTable: Table("blacklist") {
|
||||||
|
val id = integer("id").autoIncrement()
|
||||||
|
val groupId = long("group_id")
|
||||||
|
val operator = long("operator")
|
||||||
|
val timestamp = long("timestamp")
|
||||||
|
override val primaryKey = PrimaryKey(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class BlackListEntity(
|
||||||
|
val groupId: Long,
|
||||||
|
val operator: Long,
|
||||||
|
val timestamp: Long,
|
||||||
|
)
|
||||||
@@ -34,7 +34,7 @@ data class Config(
|
|||||||
val llamaUrl: String,
|
val llamaUrl: String,
|
||||||
val llamaModel: String,
|
val llamaModel: String,
|
||||||
val qqMusicApiUrl: String,
|
val qqMusicApiUrl: String,
|
||||||
val startUpNoticeUser: Long,
|
val noticeUser: Long,
|
||||||
val selfId: Long,
|
val selfId: Long,
|
||||||
val tianXingApiKey: String,
|
val tianXingApiKey: String,
|
||||||
val githubUser: String,
|
val githubUser: String,
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package cn.rtast.fancybot.util
|
|||||||
|
|
||||||
import cn.rtast.fancybot.ROOT_PATH
|
import cn.rtast.fancybot.ROOT_PATH
|
||||||
import cn.rtast.fancybot.db.ActionTable
|
import cn.rtast.fancybot.db.ActionTable
|
||||||
|
import cn.rtast.fancybot.db.BlackListTable
|
||||||
import cn.rtast.fancybot.db.JrrpTable
|
import cn.rtast.fancybot.db.JrrpTable
|
||||||
import cn.rtast.fancybot.db.NiuziBankTable
|
import cn.rtast.fancybot.db.NiuziBankTable
|
||||||
import cn.rtast.fancybot.db.NiuziTable
|
import cn.rtast.fancybot.db.NiuziTable
|
||||||
@@ -24,6 +25,7 @@ suspend fun initDatabase() {
|
|||||||
SchemaUtils.createMissingTablesAndColumns(NiuziBankTable)
|
SchemaUtils.createMissingTablesAndColumns(NiuziBankTable)
|
||||||
SchemaUtils.createMissingTablesAndColumns(NiuziTable)
|
SchemaUtils.createMissingTablesAndColumns(NiuziTable)
|
||||||
SchemaUtils.createMissingTablesAndColumns(ActionTable)
|
SchemaUtils.createMissingTablesAndColumns(ActionTable)
|
||||||
|
SchemaUtils.createMissingTablesAndColumns(BlackListTable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/10/11
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.util.file
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.db.BlackListEntity
|
||||||
|
import cn.rtast.fancybot.db.BlackListTable
|
||||||
|
import cn.rtast.fancybot.db.BlackListTable.operator
|
||||||
|
import cn.rtast.fancybot.db.BlackListTable.timestamp
|
||||||
|
import cn.rtast.fancybot.util.suspendedTransaction
|
||||||
|
import org.jetbrains.exposed.sql.insert
|
||||||
|
import org.jetbrains.exposed.sql.selectAll
|
||||||
|
|
||||||
|
class BlackListManager {
|
||||||
|
|
||||||
|
suspend fun getGroup(groupId: Long) = suspendedTransaction {
|
||||||
|
BlackListTable.selectAll()
|
||||||
|
.where { BlackListTable.groupId eq groupId }
|
||||||
|
.map {
|
||||||
|
BlackListEntity(
|
||||||
|
it[BlackListTable.groupId],
|
||||||
|
it[operator],
|
||||||
|
it[timestamp]
|
||||||
|
)
|
||||||
|
}.singleOrNull()
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun isBlackListed(groupId: Long): Boolean {
|
||||||
|
val group = this.getGroup(groupId)
|
||||||
|
return group != null
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun insertGroup(groupId: Long, operator: Long, timestamp: Long) {
|
||||||
|
suspendedTransaction {
|
||||||
|
BlackListTable.insert {
|
||||||
|
it[BlackListTable.groupId] = groupId
|
||||||
|
it[BlackListTable.operator] = operator
|
||||||
|
it[BlackListTable.timestamp] = timestamp
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,7 +8,6 @@
|
|||||||
package cn.rtast.fancybot.util.file
|
package cn.rtast.fancybot.util.file
|
||||||
|
|
||||||
import cn.rtast.fancybot.entity.Config
|
import cn.rtast.fancybot.entity.Config
|
||||||
import cn.rtast.fancybot.enums.ImageBedType
|
|
||||||
import cn.rtast.fancybot.util.str.JsonFileHandler
|
import cn.rtast.fancybot.util.str.JsonFileHandler
|
||||||
|
|
||||||
class ConfigManager : JsonFileHandler<Config>("config.json") {
|
class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||||
@@ -35,7 +34,7 @@ class ConfigManager : JsonFileHandler<Config>("config.json") {
|
|||||||
val llamaUrl = config.llamaUrl
|
val llamaUrl = config.llamaUrl
|
||||||
val llamaModel = config.llamaModel
|
val llamaModel = config.llamaModel
|
||||||
val qqMusicApiUrl = config.qqMusicApiUrl
|
val qqMusicApiUrl = config.qqMusicApiUrl
|
||||||
val startUpNoticeUser = config.startUpNoticeUser
|
val noticeUser = config.noticeUser
|
||||||
val selfId = config.selfId
|
val selfId = config.selfId
|
||||||
val tianXingApiKey = config.tianXingApiKey
|
val tianXingApiKey = config.tianXingApiKey
|
||||||
val githubUser = config.githubUser
|
val githubUser = config.githubUser
|
||||||
|
|||||||
@@ -9,10 +9,18 @@ package cn.rtast.fancybot.util.misc
|
|||||||
|
|
||||||
import java.time.Instant
|
import java.time.Instant
|
||||||
import java.time.ZoneId
|
import java.time.ZoneId
|
||||||
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
|
private val zoneId = ZoneId.of("Asia/Shanghai")
|
||||||
|
|
||||||
fun Long.isSameDay(timestamp2: Long): Boolean {
|
fun Long.isSameDay(timestamp2: Long): Boolean {
|
||||||
val zoneId = ZoneId.of("Asia/Shanghai")
|
|
||||||
val date1 = Instant.ofEpochSecond(this).atZone(zoneId).toLocalDate()
|
val date1 = Instant.ofEpochSecond(this).atZone(zoneId).toLocalDate()
|
||||||
val date2 = Instant.ofEpochSecond(timestamp2).atZone(zoneId).toLocalDate()
|
val date2 = Instant.ofEpochSecond(timestamp2).atZone(zoneId).toLocalDate()
|
||||||
return date1 == date2
|
return date1 == date2
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Long.convertToDate(): String {
|
||||||
|
val instant = Instant.ofEpochSecond(this)
|
||||||
|
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd").withZone(zoneId)
|
||||||
|
return formatter.format(instant)
|
||||||
|
}
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
"llamaUrl": "http://127.0.0.1",
|
"llamaUrl": "http://127.0.0.1",
|
||||||
"llamaModel": "llama3.1",
|
"llamaModel": "llama3.1",
|
||||||
"qqMusicApiUrl": "http://127.0.0.1:3200",
|
"qqMusicApiUrl": "http://127.0.0.1:3200",
|
||||||
"startUpNoticeUser": 114514,
|
"noticeUser": 114514,
|
||||||
"selfId": 114514,
|
"selfId": 114514,
|
||||||
"tianXingApiKey": "1145141919810",
|
"tianXingApiKey": "1145141919810",
|
||||||
"githubUser": "RTAkland",
|
"githubUser": "RTAkland",
|
||||||
|
|||||||
Reference in New Issue
Block a user