feat: add niuzi bank commands
This commit is contained in:
14 files changed
+486
-197
No files matched your search
@@ -13,6 +13,7 @@ import cn.rtast.fancybot.commands.HelpCommand
|
|||||||
import cn.rtast.fancybot.commands.StatusCommand
|
import cn.rtast.fancybot.commands.StatusCommand
|
||||||
import cn.rtast.fancybot.commands.lookup.*
|
import cn.rtast.fancybot.commands.lookup.*
|
||||||
import cn.rtast.fancybot.commands.misc.*
|
import cn.rtast.fancybot.commands.misc.*
|
||||||
|
import cn.rtast.fancybot.commands.niuzi.*
|
||||||
import cn.rtast.fancybot.commands.parse.AsciiArtCommand
|
import cn.rtast.fancybot.commands.parse.AsciiArtCommand
|
||||||
import cn.rtast.fancybot.commands.parse.BVParseCommand
|
import cn.rtast.fancybot.commands.parse.BVParseCommand
|
||||||
import cn.rtast.fancybot.commands.parse.CalculateCommand
|
import cn.rtast.fancybot.commands.parse.CalculateCommand
|
||||||
@@ -26,6 +27,7 @@ import cn.rtast.fancybot.items.BaisiItem
|
|||||||
import cn.rtast.fancybot.items.HeisiItem
|
import cn.rtast.fancybot.items.HeisiItem
|
||||||
import cn.rtast.fancybot.items.SetuItem
|
import cn.rtast.fancybot.items.SetuItem
|
||||||
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.NiuziManager
|
import cn.rtast.fancybot.util.file.NiuziManager
|
||||||
import cn.rtast.fancybot.util.initDatabase
|
import cn.rtast.fancybot.util.initDatabase
|
||||||
import cn.rtast.fancybot.util.item.ItemManager
|
import cn.rtast.fancybot.util.item.ItemManager
|
||||||
@@ -166,6 +168,7 @@ class FancyBot : OneBotListener {
|
|||||||
val configManager = ConfigManager()
|
val configManager = ConfigManager()
|
||||||
val itemManager = ItemManager()
|
val itemManager = ItemManager()
|
||||||
val niuziManager = NiuziManager()
|
val niuziManager = NiuziManager()
|
||||||
|
val niuziBankManager = NiuziBankManager()
|
||||||
|
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
HeisiItem(),
|
HeisiItem(),
|
||||||
@@ -181,8 +184,6 @@ val commands = listOf(
|
|||||||
WeatherCommand(), CigaretteCommand(),
|
WeatherCommand(), CigaretteCommand(),
|
||||||
RemakeCommand(), PixivCommand(),
|
RemakeCommand(), PixivCommand(),
|
||||||
RUACommand(), NslookupCommand(),
|
RUACommand(), NslookupCommand(),
|
||||||
NiuziSignCommand(), MyNiuziCommand(),
|
|
||||||
JiJianCommand(), LikeMeCommand(),
|
|
||||||
CompilerCommand(), AICommand(),
|
CompilerCommand(), AICommand(),
|
||||||
GithubUserCommand(), AboutCommand(),
|
GithubUserCommand(), AboutCommand(),
|
||||||
MusicPlayUrlCommand(), DomainPriceCommand(),
|
MusicPlayUrlCommand(), DomainPriceCommand(),
|
||||||
@@ -192,8 +193,13 @@ val commands = listOf(
|
|||||||
JueCommand(), ShortLinkCommand(),
|
JueCommand(), ShortLinkCommand(),
|
||||||
TenSetuCommand(), ShotSelfCommand(),
|
TenSetuCommand(), ShotSelfCommand(),
|
||||||
ShotOtherCommand(), ReverseGIFCommand(),
|
ShotOtherCommand(), ReverseGIFCommand(),
|
||||||
NiuziTransferCommand(), NiuziQueryCommand(),
|
|
||||||
HelpCommand(), MusicCommand(),
|
HelpCommand(), MusicCommand(),
|
||||||
|
LikeMeCommand(), NiuziTransferCommand(),
|
||||||
|
NiuziSignCommand(), NiuziJiJianCommand(),
|
||||||
|
NiuziQueryCommand(), MyNiuziCommand(),
|
||||||
|
NiuziBankCommand(), WithdrawCommand(),
|
||||||
|
BankTransferCommand(), CreateBankAccountCommand(),
|
||||||
|
BankBalanceCommand(), DepositCommand(),
|
||||||
)
|
)
|
||||||
|
|
||||||
val START_UP_TIME = Instant.now().epochSecond
|
val START_UP_TIME = Instant.now().epochSecond
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.niuziManager
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
|
||||||
|
|
||||||
|
class MyNiuziCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("我的牛子", "/mp", "mp")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val niuzi = niuziManager.getUser(message.sender.userId)
|
||||||
|
if (niuzi == null) {
|
||||||
|
message.reply("你还没有牛子呢, 发送`牛子签到`来领取一根专属于你的牛子吧~")
|
||||||
|
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,135 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.niuziBankManager
|
||||||
|
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.OneBotListener
|
||||||
|
|
||||||
|
private suspend fun noAccount(message: GroupMessage) {
|
||||||
|
message.reply("你还没有银行账户呢, 发送`创建账户`来创建一个账户吧~")
|
||||||
|
}
|
||||||
|
|
||||||
|
private const val INTEREST_RATE = 0.54
|
||||||
|
|
||||||
|
class NiuziBankCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("牛子银行", "/银行")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addText("发送`余额查询` `银行转账` `取牛子` `存牛子` `创建账户` 即可做出对应的操作")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("银行利率是0.54%")
|
||||||
|
.build()
|
||||||
|
message.reply(msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BankBalanceCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("余额查询")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val balanceData = niuziBankManager.getUser(message.sender.userId)
|
||||||
|
if (balanceData == null) {
|
||||||
|
noAccount(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
message.reply("你的账户余额还有: ${balanceData.balance}cm")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CreateBankAccountCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("创建账户")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
if (niuziBankManager.getUser(message.sender.userId) != null) {
|
||||||
|
message.reply("你已经有账户了!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
niuziBankManager.createBlankAccount(message.sender.userId)
|
||||||
|
message.reply("成功创建了一个账户!")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class BankTransferCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("银行转账")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val currentUserBalance = niuziBankManager.getUser(message.sender.userId)
|
||||||
|
if (currentUserBalance == null) {
|
||||||
|
noAccount(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val target = message.message.find { it.type == ArrayMessageType.at }?.data?.qq!!.toLong()
|
||||||
|
if (niuziBankManager.getUser(target) == null) {
|
||||||
|
message.reply("他还没有银行账户呢, 提醒他创建一个账户吧~(发送`创建账户`)")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val amount = args.last().toDouble()
|
||||||
|
if (amount > currentUserBalance.balance) {
|
||||||
|
message.reply("你的牛子长度不够转账!")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val result = niuziBankManager.transfer(message.sender.userId, target, amount)
|
||||||
|
message.reply("转账成功! 你在银行内剩余的牛子长度为: ${result?.balance}")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class WithdrawCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("取牛子")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val amount = args.last().toDouble()
|
||||||
|
val currentBalance = niuziBankManager.getUser(message.sender.userId)
|
||||||
|
val niuzi = niuziManager.getUser(message.sender.userId)
|
||||||
|
if (currentBalance == null) {
|
||||||
|
noAccount(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (niuzi == null) {
|
||||||
|
message.reply("你还没有认领牛子呢, 发送`牛子签到`来领取一根吧")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (amount > currentBalance.balance) {
|
||||||
|
message.reply("你的牛子长度不足无法取出 >>> $amount")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val result = niuziBankManager.withdraw(message.sender.userId, amount)
|
||||||
|
niuziManager.updateLength(message.sender.userId, amount + amount * INTEREST_RATE)
|
||||||
|
message.reply("取牛子成功, 你现在还剩${result.balance}cm的牛子在银行内")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class DepositCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("存牛子")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val currentBalance = niuziBankManager.getUser(message.sender.userId)
|
||||||
|
val niuzi = niuziManager.getUser(message.sender.userId)
|
||||||
|
val amount = args.last().toDouble()
|
||||||
|
if (currentBalance == null) {
|
||||||
|
noAccount(message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (niuzi == null) {
|
||||||
|
message.reply("你还没有认领牛子呢, 发送`牛子签到`来领取一根吧")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (amount > niuzi.length) {
|
||||||
|
message.reply("你身上的牛子不够用啦, 没办法存进银行! >>> ${niuzi.length}")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val self = niuziManager.updateLength(message.sender.userId, -amount)
|
||||||
|
val result = niuziBankManager.deposit(message.sender.userId, amount)
|
||||||
|
message.reply("存入成功你身上的牛子还有${self?.length}cm 银行账户内还有: ${result.balance}cm")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,73 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
|
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.OneBotListener
|
||||||
|
|
||||||
|
class NiuziJiJianCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("击剑", "jj")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
message.reply("发送`击剑 @xxx`即可对某人进行击剑")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
val target = message.message.find { it.type == ArrayMessageType.at }!!.data
|
||||||
|
val targetId = target.qq!!.toLong()
|
||||||
|
if (targetId == 0L) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addReply(message.messageId)
|
||||||
|
.addText("你的只有一根牛子,他们牛子太多啦你战胜不了他们的~")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("所以你不能和他们击剑~")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (message.sender.userId == targetId) {
|
||||||
|
message.reply("你不能和自己击剑啊")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!niuziManager.exists(message.sender.userId)) {
|
||||||
|
message.reply("你还没有牛子呢, 发送`牛子签到`领取你的牛子吧~")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!niuziManager.exists(targetId)) {
|
||||||
|
message.reply("对方还没有牛子呢, 提醒他领取一根牛子吧~")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (niuziManager.getUser(message.sender.userId)?.length!! < 0.0) {
|
||||||
|
message.reply("你的牛子已经凹进去了没办法进行击剑~发送`牛子签到`来增加你的牛子长度吧~")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if (niuziManager.getUser(targetId)?.length!! < 0.0) {
|
||||||
|
message.reply("他已经没有牛子啦!(他的牛子已经凹进去了!!)你不能和他击剑")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val result = niuziManager.jijian(message.sender.userId, targetId)
|
||||||
|
if (result.first) {
|
||||||
|
message.reply("你以已绝对的长度在这场击剑中获胜了~, 你的牛子增加了${result.second}cm")
|
||||||
|
} 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
|
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.OneBotListener
|
||||||
|
|
||||||
|
class NiuziQueryCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("牛子查询", "nq")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
message.reply("输入`牛子查询 @某人`即可查询他的牛子长度")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val target = message.message.find { it.type == ArrayMessageType.at }?.data?.qq!!.toLong()
|
||||||
|
val targetNiuzi = niuziManager.getUser(target)
|
||||||
|
if (targetNiuzi == null) {
|
||||||
|
message.reply("他还没有牛子")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
message.reply("他的牛子长度为: ${targetNiuzi.length}cm")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.niuziManager
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
|
||||||
|
class NiuziSignCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("牛子签到", "签到")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
if (niuziManager.isSigned(message.sender.userId)) {
|
||||||
|
message.reply("你今天已经对你的牛子使用了签到啦,明天再来吧~")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val afterStatus = niuziManager.sign(message.sender.userId)
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addReply(message.messageId)
|
||||||
|
.addText("签到成功~")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("你的牛子增加了${afterStatus.first}cm~ 总长度为: ${afterStatus.second?.length}")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
|
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.OneBotListener
|
||||||
|
|
||||||
|
class NiuziTransferCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("牛子转账", "转账", "/zz")
|
||||||
|
|
||||||
|
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")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,170 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2024 RTAkland
|
|
||||||
* Author: RTAkland
|
|
||||||
* Date: 2024/9/8
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package cn.rtast.fancybot.commands.record
|
|
||||||
|
|
||||||
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.OneBotListener
|
|
||||||
|
|
||||||
class NiuziSignCommand : BaseCommand() {
|
|
||||||
override val commandNames = listOf("牛子签到", "签到")
|
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
|
||||||
if (niuziManager.isSigned(message.sender.userId)) {
|
|
||||||
message.reply("你今天已经对你的牛子使用了签到啦,明天再来吧~")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val afterStatus = niuziManager.sign(message.sender.userId)
|
|
||||||
val msg = MessageChain.Builder()
|
|
||||||
.addReply(message.messageId)
|
|
||||||
.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: OneBotListener, message: GroupMessage, args: List<String>) {
|
|
||||||
if (args.isEmpty()) {
|
|
||||||
message.reply("发送`击剑 @xxx`即可对某人进行击剑")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val target = message.message.find { it.type == ArrayMessageType.at }!!.data
|
|
||||||
val targetId = target.qq!!.toLong()
|
|
||||||
if (targetId == 0L) {
|
|
||||||
val msg = MessageChain.Builder()
|
|
||||||
.addReply(message.messageId)
|
|
||||||
.addText("你的只有一根牛子,他们牛子太多啦你战胜不了他们的~")
|
|
||||||
.addNewLine()
|
|
||||||
.addText("所以你不能和他们击剑~")
|
|
||||||
.build()
|
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (message.sender.userId == targetId) {
|
|
||||||
message.reply("你不能和自己击剑啊")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!niuziManager.exists(message.sender.userId)) {
|
|
||||||
message.reply("你还没有牛子呢, 发送`牛子签到`领取你的牛子吧~")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if (!niuziManager.exists(targetId)) {
|
|
||||||
message.reply("对方还没有牛子呢, 提醒他领取一根牛子吧~")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (niuziManager.getUser(message.sender.userId)?.length!! < 0.0) {
|
|
||||||
message.reply("你的牛子已经凹进去了没办法进行击剑~发送`牛子签到`来增加你的牛子长度吧~")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if (niuziManager.getUser(targetId)?.length!! < 0.0) {
|
|
||||||
message.reply("他已经没有牛子啦!(他的牛子已经凹进去了!!)你不能和他击剑")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val result = niuziManager.jijian(message.sender.userId, targetId)
|
|
||||||
if (result.first) {
|
|
||||||
message.reply("你以已绝对的长度在这场击剑中获胜了~, 你的牛子增加了${result.second}cm")
|
|
||||||
} 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 MyNiuziCommand : BaseCommand() {
|
|
||||||
override val commandNames = listOf("我的牛子", "/mp", "mp")
|
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
|
||||||
val niuzi = niuziManager.getUser(message.sender.userId)
|
|
||||||
if (niuzi == null) {
|
|
||||||
message.reply("你还没有牛子呢, 发送`牛子签到`来领取一根专属于你的牛子吧~")
|
|
||||||
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())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class NiuziTransferCommand : BaseCommand() {
|
|
||||||
override val commandNames = listOf("牛子转账", "转账", "/zz")
|
|
||||||
|
|
||||||
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("牛子查询", "nq")
|
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
|
||||||
if (args.isEmpty()) {
|
|
||||||
message.reply("输入`牛子查询 @某人`即可查询他的牛子长度")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
val target = message.message.find { it.type == ArrayMessageType.at }?.data?.qq!!.toLong()
|
|
||||||
val targetNiuzi = niuziManager.getUser(target)
|
|
||||||
if (targetNiuzi == null) {
|
|
||||||
message.reply("他还没有牛子")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
message.reply("他的牛子长度为: ${targetNiuzi.length}cm")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity.db
|
||||||
|
|
||||||
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
|
||||||
|
object NiuziBankTable: Table("niuzi_bank") {
|
||||||
|
val id = long("id").autoIncrement()
|
||||||
|
val userId = long("userId").uniqueIndex()
|
||||||
|
val timestamp = long("timestamp")
|
||||||
|
val balance = double("balance")
|
||||||
|
val interestRate = double("interest_rate")
|
||||||
|
override val primaryKey = PrimaryKey(id)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class NiuziBankAccount(
|
||||||
|
val userId: Long,
|
||||||
|
val balance: Double,
|
||||||
|
val interestRate: Double,
|
||||||
|
val timestamp: Long
|
||||||
|
)
|
||||||
@@ -9,7 +9,7 @@ package cn.rtast.fancybot.entity.db
|
|||||||
|
|
||||||
import org.jetbrains.exposed.sql.Table
|
import org.jetbrains.exposed.sql.Table
|
||||||
|
|
||||||
object NiuziTable : Table("niuzu") {
|
object NiuziTable : Table("niuzi") {
|
||||||
val length = double("length")
|
val length = double("length")
|
||||||
val id = long("id").autoIncrement()
|
val id = long("id").autoIncrement()
|
||||||
val userId = long("userId").uniqueIndex()
|
val userId = long("userId").uniqueIndex()
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright © 2024 RTAkland
|
|
||||||
* Author: RTAkland
|
|
||||||
* Date: 2024/8/30
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
package cn.rtast.fancybot.entity.db
|
|
||||||
|
|
||||||
import org.jetbrains.exposed.sql.Table
|
|
||||||
|
|
||||||
object SignTable : Table("sign") {
|
|
||||||
val id = integer("id").autoIncrement()
|
|
||||||
val userId = long("userId").uniqueIndex()
|
|
||||||
val timestamp = long("timestamp")
|
|
||||||
val point = long("point")
|
|
||||||
|
|
||||||
override val primaryKey = PrimaryKey(id)
|
|
||||||
}
|
|
||||||
@@ -9,8 +9,8 @@ package cn.rtast.fancybot.util
|
|||||||
|
|
||||||
import cn.rtast.fancybot.ROOT_PATH
|
import cn.rtast.fancybot.ROOT_PATH
|
||||||
import cn.rtast.fancybot.entity.db.JrrpTable
|
import cn.rtast.fancybot.entity.db.JrrpTable
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankTable
|
||||||
import cn.rtast.fancybot.entity.db.NiuziTable
|
import cn.rtast.fancybot.entity.db.NiuziTable
|
||||||
import cn.rtast.fancybot.entity.db.SignTable
|
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import org.jetbrains.exposed.sql.Database
|
import org.jetbrains.exposed.sql.Database
|
||||||
import org.jetbrains.exposed.sql.SchemaUtils
|
import org.jetbrains.exposed.sql.SchemaUtils
|
||||||
@@ -20,7 +20,7 @@ suspend fun initDatabase() {
|
|||||||
Database.connect("jdbc:sqlite:file:$ROOT_PATH/data.sqlite", "org.sqlite.JDBC")
|
Database.connect("jdbc:sqlite:file:$ROOT_PATH/data.sqlite", "org.sqlite.JDBC")
|
||||||
suspendedTransaction {
|
suspendedTransaction {
|
||||||
SchemaUtils.createMissingTablesAndColumns(JrrpTable)
|
SchemaUtils.createMissingTablesAndColumns(JrrpTable)
|
||||||
SchemaUtils.createMissingTablesAndColumns(SignTable)
|
SchemaUtils.createMissingTablesAndColumns(NiuziBankTable)
|
||||||
SchemaUtils.createMissingTablesAndColumns(NiuziTable)
|
SchemaUtils.createMissingTablesAndColumns(NiuziTable)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,84 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/24
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.util.file
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankAccount
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankTable
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankTable.balance
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankTable.interestRate
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankTable.timestamp
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziBankTable.userId
|
||||||
|
import cn.rtast.fancybot.entity.db.NiuziTable
|
||||||
|
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
|
||||||
|
|
||||||
|
class NiuziBankManager {
|
||||||
|
|
||||||
|
suspend fun getUser(id: Long): NiuziBankAccount? {
|
||||||
|
return suspendedTransaction {
|
||||||
|
NiuziBankTable.selectAll().where { userId eq id }.map {
|
||||||
|
NiuziBankAccount(
|
||||||
|
it[userId],
|
||||||
|
it[balance],
|
||||||
|
it[interestRate],
|
||||||
|
it[timestamp]
|
||||||
|
)
|
||||||
|
}.singleOrNull()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun increaseBalance(id: Long, amount: Double) {
|
||||||
|
val current = this.getUser(id)
|
||||||
|
suspendedTransaction {
|
||||||
|
NiuziBankTable.update({ userId eq id }) {
|
||||||
|
it[balance] = current?.balance!! + amount
|
||||||
|
it[NiuziTable.timestamp] = Instant.now().epochSecond
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private suspend fun decreaseBalance(id: Long, amount: Double) {
|
||||||
|
this.increaseBalance(id, -amount)
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun createBlankAccount(id: Long) {
|
||||||
|
suspendedTransaction {
|
||||||
|
NiuziBankTable.insert {
|
||||||
|
it[userId] = id
|
||||||
|
it[balance] = 0.0
|
||||||
|
it[timestamp] = Instant.now().epochSecond
|
||||||
|
it[interestRate] = 0.54
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun withdraw(id: Long, amount: Double): NiuziBankAccount {
|
||||||
|
suspendedTransaction {
|
||||||
|
this.decreaseBalance(id, amount)
|
||||||
|
}
|
||||||
|
return this.getUser(id)!!
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun deposit(id: Long, amount: Double): NiuziBankAccount {
|
||||||
|
suspendedTransaction {
|
||||||
|
this.increaseBalance(id, amount)
|
||||||
|
}
|
||||||
|
return this.getUser(id)!!
|
||||||
|
}
|
||||||
|
|
||||||
|
suspend fun transfer(from: Long, target: Long, amount: Double): NiuziBankAccount? {
|
||||||
|
suspendedTransaction {
|
||||||
|
this.decreaseBalance(from, -amount)
|
||||||
|
this.increaseBalance(target, amount)
|
||||||
|
}
|
||||||
|
return this.getUser(from)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,7 +12,6 @@ import cn.rtast.fancybot.entity.db.NiuziTable
|
|||||||
import cn.rtast.fancybot.entity.db.NiuziTable.length
|
import cn.rtast.fancybot.entity.db.NiuziTable.length
|
||||||
import cn.rtast.fancybot.entity.db.NiuziTable.timestamp
|
import cn.rtast.fancybot.entity.db.NiuziTable.timestamp
|
||||||
import cn.rtast.fancybot.entity.db.NiuziTable.userId
|
import cn.rtast.fancybot.entity.db.NiuziTable.userId
|
||||||
import cn.rtast.fancybot.entity.db.SignTable
|
|
||||||
import cn.rtast.fancybot.util.isSameDay
|
import cn.rtast.fancybot.util.isSameDay
|
||||||
import cn.rtast.fancybot.util.suspendedTransaction
|
import cn.rtast.fancybot.util.suspendedTransaction
|
||||||
import org.jetbrains.exposed.sql.insert
|
import org.jetbrains.exposed.sql.insert
|
||||||
@@ -23,13 +22,14 @@ import kotlin.random.Random
|
|||||||
|
|
||||||
class NiuziManager {
|
class NiuziManager {
|
||||||
|
|
||||||
suspend fun updateLength(id: Long, newLength: Double) {
|
suspend fun updateLength(id: Long, newLength: Double): Niuzi? {
|
||||||
val current = getUser(id)
|
val current = getUser(id)
|
||||||
suspendedTransaction {
|
suspendedTransaction {
|
||||||
NiuziTable.update({ userId eq id }) {
|
NiuziTable.update({ userId eq id }) {
|
||||||
it[length] = current?.length!! + newLength
|
it[length] = current?.length!! + newLength
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return getUser(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun createBlankUser(id: Long) {
|
suspend fun createBlankUser(id: Long) {
|
||||||
|
|||||||
Reference in New Issue
Block a user