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
@@ -9,6 +9,7 @@ package cn.rtast.fancybot.util
|
||||
|
||||
import cn.rtast.fancybot.ROOT_PATH
|
||||
import cn.rtast.fancybot.db.ActionTable
|
||||
import cn.rtast.fancybot.db.BlackListTable
|
||||
import cn.rtast.fancybot.db.JrrpTable
|
||||
import cn.rtast.fancybot.db.NiuziBankTable
|
||||
import cn.rtast.fancybot.db.NiuziTable
|
||||
@@ -24,6 +25,7 @@ suspend fun initDatabase() {
|
||||
SchemaUtils.createMissingTablesAndColumns(NiuziBankTable)
|
||||
SchemaUtils.createMissingTablesAndColumns(NiuziTable)
|
||||
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
|
||||
|
||||
import cn.rtast.fancybot.entity.Config
|
||||
import cn.rtast.fancybot.enums.ImageBedType
|
||||
import cn.rtast.fancybot.util.str.JsonFileHandler
|
||||
|
||||
class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||
@@ -35,7 +34,7 @@ class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||
val llamaUrl = config.llamaUrl
|
||||
val llamaModel = config.llamaModel
|
||||
val qqMusicApiUrl = config.qqMusicApiUrl
|
||||
val startUpNoticeUser = config.startUpNoticeUser
|
||||
val noticeUser = config.noticeUser
|
||||
val selfId = config.selfId
|
||||
val tianXingApiKey = config.tianXingApiKey
|
||||
val githubUser = config.githubUser
|
||||
|
||||
@@ -9,10 +9,18 @@ package cn.rtast.fancybot.util.misc
|
||||
|
||||
import java.time.Instant
|
||||
import java.time.ZoneId
|
||||
import java.time.format.DateTimeFormatter
|
||||
|
||||
private val zoneId = ZoneId.of("Asia/Shanghai")
|
||||
|
||||
fun Long.isSameDay(timestamp2: Long): Boolean {
|
||||
val zoneId = ZoneId.of("Asia/Shanghai")
|
||||
val date1 = Instant.ofEpochSecond(this).atZone(zoneId).toLocalDate()
|
||||
val date2 = Instant.ofEpochSecond(timestamp2).atZone(zoneId).toLocalDate()
|
||||
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)
|
||||
}
|
||||
Reference in New Issue
Block a user