feat: add niuzi command
This commit is contained in:
6 files changed
+247
-24
No files matched your search
@@ -7,24 +7,7 @@
|
||||
|
||||
package cn.rtast.fancybot
|
||||
|
||||
import cn.rtast.fancybot.commands.AntiRevokeCommand
|
||||
import cn.rtast.fancybot.commands.CigaretteCommand
|
||||
import cn.rtast.fancybot.commands.EchoCommand
|
||||
import cn.rtast.fancybot.commands.FKXQSCommand
|
||||
import cn.rtast.fancybot.commands.HelpCommand
|
||||
import cn.rtast.fancybot.commands.HitokotoCommand
|
||||
import cn.rtast.fancybot.commands.JrrpCommand
|
||||
import cn.rtast.fancybot.commands.MCPingCommand
|
||||
import cn.rtast.fancybot.commands.MusicCommand
|
||||
import cn.rtast.fancybot.commands.MyPointCommand
|
||||
import cn.rtast.fancybot.commands.NslookupCommand
|
||||
import cn.rtast.fancybot.commands.PixivCommand
|
||||
import cn.rtast.fancybot.commands.QRCodeCommand
|
||||
import cn.rtast.fancybot.commands.RUACommand
|
||||
import cn.rtast.fancybot.commands.RedeemCommand
|
||||
import cn.rtast.fancybot.commands.RemakeCommand
|
||||
import cn.rtast.fancybot.commands.SignCommand
|
||||
import cn.rtast.fancybot.commands.WeatherCommand
|
||||
import cn.rtast.fancybot.commands.*
|
||||
import cn.rtast.fancybot.commands.misc.BVParseCommand
|
||||
import cn.rtast.fancybot.commands.misc.ImageURLCommand
|
||||
import cn.rtast.fancybot.entity.enums.WSType
|
||||
@@ -32,6 +15,7 @@ import cn.rtast.fancybot.items.BaisiItem
|
||||
import cn.rtast.fancybot.items.HeisiItem
|
||||
import cn.rtast.fancybot.items.SetuItem
|
||||
import cn.rtast.fancybot.util.file.ConfigManager
|
||||
import cn.rtast.fancybot.util.file.NiuziManager
|
||||
import cn.rtast.fancybot.util.file.SignManager
|
||||
import cn.rtast.fancybot.util.initDatabase
|
||||
import cn.rtast.fancybot.util.item.ItemManager
|
||||
@@ -88,6 +72,7 @@ class FancyBot : OBMessage {
|
||||
val configManager = ConfigManager()
|
||||
val itemManager = ItemManager()
|
||||
val signManager = SignManager()
|
||||
val niuziManager = NiuziManager()
|
||||
|
||||
val items = listOf(
|
||||
HeisiItem(),
|
||||
@@ -104,7 +89,9 @@ val commands = listOf(
|
||||
MCPingCommand(), HelpCommand(),
|
||||
WeatherCommand(), CigaretteCommand(),
|
||||
RemakeCommand(), PixivCommand(),
|
||||
RUACommand(), NslookupCommand()
|
||||
RUACommand(), NslookupCommand(),
|
||||
NiuziSignCommand(), MyNiuziSignCommand(),
|
||||
JiJianCommand()
|
||||
)
|
||||
|
||||
suspend fun main() {
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/8
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.commands
|
||||
|
||||
import cn.rtast.fancybot.niuziManager
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.enums.ArrayMessageType
|
||||
import cn.rtast.rob.util.BaseCommand
|
||||
import cn.rtast.rob.util.ob.MessageChain
|
||||
import cn.rtast.rob.util.ob.OBMessage
|
||||
|
||||
class NiuziSignCommand : BaseCommand() {
|
||||
override val commandNames = listOf("牛子签到")
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
if (niuziManager.isSigned(message.sender.userId)) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("你今天已经对你的牛子使用了签到啦,明天再来吧~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
val afterStatus = niuziManager.sign(message.sender.userId)
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("签到成功~")
|
||||
.addNewLine()
|
||||
.addText("你的牛子增加了${afterStatus.first}cm~ 总长度为: ${afterStatus.second?.length}")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
}
|
||||
|
||||
class JiJianCommand : BaseCommand() {
|
||||
override val commandNames = listOf("击剑", "jj")
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("发送`击剑 @xxx`即可对某人进行击剑")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
|
||||
val target = message.message.find { it.type == ArrayMessageType.at }!!.data
|
||||
val targetId = target.qq!!.toLong()
|
||||
if (!niuziManager.exists(message.sender.userId)) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("你还没有牛子呢, 发送`牛子签到`领取你的牛子吧~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
if (!niuziManager.exists(targetId)) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(targetId)
|
||||
.addText("对方还没有牛子呢, 提醒他领取一根牛子吧~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
if (niuziManager.getUser(targetId)?.length!! < 0.0) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("他已经没有牛子啦!(他的牛子已经凹进去了!!)你不能和他击剑")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
val result = niuziManager.jijian(message.sender.userId, targetId)
|
||||
if (result.first) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("你以已绝对的长度在这场击剑中获胜了~, 你的牛子增加了${result.second}cm")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
} else {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("很不幸你的牛子没能战胜${target.name}, 你的牛子缩短了${result.second}cm")
|
||||
.addNewLine()
|
||||
.addText("对方的牛子增加了${result.second}cm~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MyNiuziSignCommand : BaseCommand() {
|
||||
override val commandNames = listOf("我的牛子")
|
||||
|
||||
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||
val niuzi = niuziManager.getUser(message.sender.userId)
|
||||
if (niuzi == null) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("你还没有牛子呢, 发送`牛子签到`来领取一根专属于你的牛子吧~")
|
||||
.build()
|
||||
listener.sendGroupMessage(message.groupId, msg)
|
||||
return
|
||||
}
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
.addText("你的牛子长度为: ${niuzi.length}cm")
|
||||
|
||||
val niuziString = when (niuzi.length) {
|
||||
in -999.0..0.0 -> "你的牛子已经凹进去了!!!!"
|
||||
in 0.1..6.0 -> "小小的也很可爱呢~"
|
||||
in 6.1..15.0 -> "好长的牛子!"
|
||||
in 15.1..30.0 -> "你的牛子已经快突破天际了!!!"
|
||||
else -> "牛子也太长啦把天捅穿啦!!!!!!"
|
||||
}
|
||||
msg.addText(niuziString)
|
||||
listener.sendGroupMessage(message.groupId, msg.build())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/8
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.entity.db
|
||||
|
||||
import org.jetbrains.exposed.sql.Table
|
||||
|
||||
object NiuziTable : Table("niuzu") {
|
||||
val length = double("length")
|
||||
val id = long("id").autoIncrement()
|
||||
val userId = long("userId").uniqueIndex()
|
||||
val timestamp = long("timestamp")
|
||||
override val primaryKey = PrimaryKey(id)
|
||||
}
|
||||
|
||||
data class Niuzi(
|
||||
val userId: Long,
|
||||
val length: Double,
|
||||
val timestamp: Long
|
||||
)
|
||||
@@ -9,6 +9,7 @@ package cn.rtast.fancybot.util
|
||||
|
||||
import cn.rtast.fancybot.ROOT_PATH
|
||||
import cn.rtast.fancybot.entity.db.JrrpTable
|
||||
import cn.rtast.fancybot.entity.db.NiuziTable
|
||||
import cn.rtast.fancybot.entity.db.SignTable
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import org.jetbrains.exposed.sql.Database
|
||||
@@ -20,6 +21,7 @@ suspend fun initDatabase() {
|
||||
suspendedTransaction {
|
||||
SchemaUtils.createMissingTablesAndColumns(JrrpTable)
|
||||
SchemaUtils.createMissingTablesAndColumns(SignTable)
|
||||
SchemaUtils.createMissingTablesAndColumns(NiuziTable)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
/*
|
||||
* Copyright © 2024 RTAkland
|
||||
* Author: RTAkland
|
||||
* Date: 2024/9/8
|
||||
*/
|
||||
|
||||
|
||||
package cn.rtast.fancybot.util.file
|
||||
|
||||
import cn.rtast.fancybot.entity.db.Niuzi
|
||||
import cn.rtast.fancybot.entity.db.NiuziTable
|
||||
import cn.rtast.fancybot.entity.db.NiuziTable.length
|
||||
import cn.rtast.fancybot.entity.db.NiuziTable.timestamp
|
||||
import cn.rtast.fancybot.entity.db.NiuziTable.userId
|
||||
import cn.rtast.fancybot.util.isSameDay
|
||||
import cn.rtast.fancybot.util.suspendedTransaction
|
||||
import org.jetbrains.exposed.sql.insert
|
||||
import org.jetbrains.exposed.sql.selectAll
|
||||
import org.jetbrains.exposed.sql.update
|
||||
import java.time.Instant
|
||||
import kotlin.random.Random
|
||||
|
||||
class NiuziManager {
|
||||
suspend fun getUser(id: Long): Niuzi? {
|
||||
return suspendedTransaction {
|
||||
NiuziTable.selectAll().where { userId eq id }.map {
|
||||
Niuzi(
|
||||
it[userId],
|
||||
it[length],
|
||||
it[timestamp]
|
||||
)
|
||||
}.singleOrNull()
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun isSigned(id: Long): Boolean {
|
||||
val record = getUser(id)
|
||||
return record?.timestamp?.isSameDay(Instant.now().epochSecond) ?: false
|
||||
}
|
||||
|
||||
suspend fun sign(id: Long): Pair<Double, Niuzi?> {
|
||||
val randomLength = Random.nextDouble(-5.0, 10.0)
|
||||
if (getUser(id) == null) {
|
||||
suspendedTransaction {
|
||||
NiuziTable.insert {
|
||||
it[userId] = id
|
||||
it[timestamp] = Instant.now().epochSecond
|
||||
it[length] = 0.0
|
||||
}
|
||||
}
|
||||
}
|
||||
val record = getUser(id)
|
||||
suspendedTransaction {
|
||||
NiuziTable.update({ userId eq id }) {
|
||||
it[length] = record?.length!! + randomLength
|
||||
it[timestamp] = Instant.now().epochSecond
|
||||
}
|
||||
}
|
||||
return randomLength to this.getUser(id)
|
||||
}
|
||||
|
||||
suspend fun updateLength(id: Long, newLength: Double) {
|
||||
val current = getUser(id)
|
||||
suspendedTransaction {
|
||||
NiuziTable.update({ userId eq id }) {
|
||||
it[length] = current?.length!! + newLength
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun exists(userId: Long): Boolean {
|
||||
return getUser(userId) != null
|
||||
}
|
||||
|
||||
suspend fun jijian(fromUser: Long, targetUser: Long): Pair<Boolean, Double> {
|
||||
val fromUserStatus = getUser(fromUser)!!
|
||||
val targetUserStatus = getUser(targetUser)!!
|
||||
val randomLength = Random.nextDouble(1.0, 10.0)
|
||||
val success = Random.nextBoolean()
|
||||
if (success) {
|
||||
this.updateLength(fromUser, randomLength)
|
||||
this.updateLength(targetUser, -randomLength)
|
||||
} else {
|
||||
this.updateLength(fromUser, -randomLength)
|
||||
this.updateLength(targetUser, randomLength)
|
||||
}
|
||||
return success to randomLength
|
||||
}
|
||||
}
|
||||
@@ -36,11 +36,7 @@ class SignManager {
|
||||
|
||||
suspend fun isSigned(id: Long): Boolean {
|
||||
val record = getRecord(id)
|
||||
return if (record != null) {
|
||||
record.timestamp.isSameDay(Instant.now().epochSecond)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
return record?.timestamp?.isSameDay(Instant.now().epochSecond) ?: false
|
||||
}
|
||||
|
||||
suspend fun sign(id: Long): Long {
|
||||
|
||||
Reference in New Issue
Block a user