feat: add niuzi transfer and niuzi query command
This commit is contained in:
3 files changed
+64
-12
No files matched your search
@@ -19,14 +19,7 @@ import cn.rtast.fancybot.commands.parse.CalculateCommand
|
||||
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.record.JiJianCommand
|
||||
import cn.rtast.fancybot.commands.record.JrrpCommand
|
||||
import cn.rtast.fancybot.commands.record.MyNiuziCommand
|
||||
import cn.rtast.fancybot.commands.record.MyPointCommand
|
||||
import cn.rtast.fancybot.commands.record.NiuziSignCommand
|
||||
import cn.rtast.fancybot.commands.record.RedeemCommand
|
||||
import cn.rtast.fancybot.commands.record.ShortLinkCommand
|
||||
import cn.rtast.fancybot.commands.record.SignCommand
|
||||
import cn.rtast.fancybot.commands.record.*
|
||||
import cn.rtast.fancybot.entity.bili.CardShare
|
||||
import cn.rtast.fancybot.entity.enums.WSType
|
||||
import cn.rtast.fancybot.items.BaisiItem
|
||||
@@ -41,7 +34,6 @@ import cn.rtast.fancybot.util.str.fromJson
|
||||
import cn.rtast.rob.ROneBotFactory
|
||||
import cn.rtast.rob.entity.AddFriendRequest
|
||||
import cn.rtast.rob.entity.FileEvent
|
||||
import cn.rtast.rob.entity.GetMessage
|
||||
import cn.rtast.rob.entity.GroupMessage
|
||||
import cn.rtast.rob.entity.GroupRevokeMessage
|
||||
import cn.rtast.rob.enums.ArrayMessageType
|
||||
@@ -199,7 +191,8 @@ val commands = listOf(
|
||||
AsciiArtCommand(), StatusCommand(),
|
||||
JueCommand(), ShortLinkCommand(),
|
||||
TenSetuCommand(), ShotSelfCommand(),
|
||||
ShotOtherCommand(), ReverseGIFCommand()
|
||||
ShotOtherCommand(), ReverseGIFCommand(),
|
||||
NiuziTransferCommand(), NiuziQueryCommand()
|
||||
)
|
||||
|
||||
val START_UP_TIME = Instant.now().epochSecond
|
||||
|
||||
@@ -150,4 +150,53 @@ class MyNiuziCommand : BaseCommand() {
|
||||
msg.addText(niuziString)
|
||||
listener.sendGroupMessage(message.groupId, msg.build())
|
||||
}
|
||||
}
|
||||
|
||||
class NiuziTransferCommand : BaseCommand() {
|
||||
override val commandNames = listOf("牛子转账")
|
||||
|
||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||
if (args.isEmpty()) {
|
||||
message.reply("发送`牛子转账 @某人 <长度>` 即可把自己的牛子长度转账给TA")
|
||||
return
|
||||
}
|
||||
val target = message.message.find { it.type == ArrayMessageType.at }!!.data.qq!!.toLong()
|
||||
val targetNiuzi = niuziManager.getUser(target)
|
||||
if (targetNiuzi == null) niuziManager.createBlankUser(target)
|
||||
val transferLength = args.last().toDouble()
|
||||
val currentNiuzi = niuziManager.getUser(message.sender.userId)
|
||||
if (currentNiuzi == null) {
|
||||
message.reply("你没有牛子没办法转账")
|
||||
return
|
||||
}
|
||||
if (currentNiuzi.length <= 0.0) {
|
||||
message.reply("你已经没有牛子可以转账了")
|
||||
return
|
||||
}
|
||||
if (currentNiuzi.length < transferLength) {
|
||||
message.reply("你的牛子长度不够转账这么多 >>>${transferLength}cm")
|
||||
return
|
||||
}
|
||||
if (transferLength <= 0) {
|
||||
message.reply("长度必须大于0!")
|
||||
return
|
||||
}
|
||||
niuziManager.updateLength(message.sender.userId, -transferLength)
|
||||
niuziManager.updateLength(target, transferLength)
|
||||
message.reply("转账成功, 你的长度减少了: ${transferLength}cm, 对方的长度增加了 ${transferLength}cm")
|
||||
}
|
||||
}
|
||||
|
||||
class NiuziQueryCommand : BaseCommand() {
|
||||
override val commandNames = listOf("牛子查询")
|
||||
|
||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||
val target = args.last().toLong()
|
||||
val targetNiuzi = niuziManager.getUser(target)
|
||||
if (targetNiuzi == null) {
|
||||
message.reply("他还没有牛子")
|
||||
return
|
||||
}
|
||||
message.reply("他的牛子长度为: ${targetNiuzi.length}cm")
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ import kotlin.random.Random
|
||||
|
||||
class NiuziManager {
|
||||
|
||||
private suspend fun updateLength(id: Long, newLength: Double) {
|
||||
suspend fun updateLength(id: Long, newLength: Double) {
|
||||
val current = getUser(id)
|
||||
suspendedTransaction {
|
||||
NiuziTable.update({ userId eq id }) {
|
||||
@@ -31,6 +31,16 @@ class NiuziManager {
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun createBlankUser(id: Long) {
|
||||
suspendedTransaction {
|
||||
NiuziTable.insert {
|
||||
it[timestamp] = Instant.now().epochSecond
|
||||
it[length] = 0.0
|
||||
it[userId] = id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
suspend fun getUser(id: Long): Niuzi? {
|
||||
return suspendedTransaction {
|
||||
NiuziTable.selectAll().where { userId eq id }.map {
|
||||
@@ -49,7 +59,7 @@ class NiuziManager {
|
||||
}
|
||||
|
||||
suspend fun sign(id: Long): Pair<Double, Niuzi?> {
|
||||
val randomLength = Random.nextDouble(-5.0, 10.0)
|
||||
val randomLength = Random.nextDouble(1.0, 10.0)
|
||||
if (getUser(id) == null) {
|
||||
suspendedTransaction {
|
||||
NiuziTable.insert {
|
||||
|
||||
Reference in New Issue
Block a user