feat: add some feature

This commit is contained in:
2024-08-30 14:24:46 +08:00
parent e48f899f9e
commit bf75cfad38
21 files changed
+333 -24

No files matched your search

@@ -0,0 +1,16 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/8/30
*/
package cn.rtast.fancybot.util.file
import cn.rtast.fancybot.entity.Config
import cn.rtast.fancybot.util.JsonFileHandler
class ConfigManager : JsonFileHandler<Config>("config.json") {
val ncmAPI get() = this.read<Config>().cnmApi
}
@@ -0,0 +1,31 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/8/29
*/
package cn.rtast.fancybot.util.file
import cn.rtast.fancybot.entity.jrrp.JrrpRecord
import cn.rtast.fancybot.util.JsonFileHandler
import cn.rtast.fancybot.util.isSameDay
import java.time.Instant
import kotlin.random.Random
class JrrpManager : JsonFileHandler<List<JrrpRecord>>("jrrp.json", listOf()) {
fun isJrrped(id: Long): Boolean {
val allJrrp = this.readArray<List<JrrpRecord>>()
val user = allJrrp.find { it.id == id } ?: return false
return user.timestamp.isSameDay(Instant.now().epochSecond)
}
fun jrrp(id: Long): Int {
val allJrrp = this.readArray<MutableList<JrrpRecord>>()
allJrrp.removeAll { it.id == id }
allJrrp.add(JrrpRecord(id, Instant.now().epochSecond, 0))
this.write(allJrrp)
return Random.nextInt(0, 101)
}
}
@@ -0,0 +1,39 @@
/*
* Copyright © 2024 RTAkland
* Author: RTAkland
* Date: 2024/8/30
*/
package cn.rtast.fancybot.util.file
import cn.rtast.fancybot.entity.jrrp.JrrpRecord
import cn.rtast.fancybot.util.JsonFileHandler
import cn.rtast.fancybot.util.isSameDay
import java.time.Instant
import kotlin.random.Random
class SignManager : JsonFileHandler<List<JrrpRecord>>("sign.json", listOf()) {
fun isSigned(id: Long): Boolean {
val allSign = this.readArray<List<JrrpRecord>>()
val user = allSign.find { it.id == id } ?: return false
return user.timestamp.isSameDay(Instant.now().epochSecond)
}
fun sign(id: Long): Long {
val allSign = this.readArray<MutableList<JrrpRecord>>()
val randomPoint = Random.nextLong(0, 101)
val current = allSign.find { it.id == id } ?: JrrpRecord(id, Instant.now().epochSecond, 0)
current.points = randomPoint + current.points
allSign.remove(current)
allSign.add(current)
this.write(allSign)
return randomPoint + current.points
}
fun getStatus(id: Long): JrrpRecord? {
val allSign = this.readArray<List<JrrpRecord>>()
return allSign.find { it.id == id }
}
}