chore: improve niuzi bank command
This commit is contained in:
8 files changed
+50
-34
No files matched your search
@@ -62,7 +62,8 @@ val DEFAULT_CONFIG = Config(
|
|||||||
enableAntiRevoke = true,
|
enableAntiRevoke = true,
|
||||||
llamaUrl = "http://127.0.0.1",
|
llamaUrl = "http://127.0.0.1",
|
||||||
llamaModel = "llama3.1",
|
llamaModel = "llama3.1",
|
||||||
qqMusicApiUrl = "http://127.0.0.1:3200"
|
qqMusicApiUrl = "http://127.0.0.1:3200",
|
||||||
|
startUpNoticeUser = 114514L
|
||||||
)
|
)
|
||||||
|
|
||||||
val configManager = ConfigManager()
|
val configManager = ConfigManager()
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ class FancyBot : OneBotListener {
|
|||||||
private val coroutineScope = CoroutineScope(Dispatchers.IO)
|
private val coroutineScope = CoroutineScope(Dispatchers.IO)
|
||||||
|
|
||||||
override suspend fun onWebsocketOpenEvent() {
|
override suspend fun onWebsocketOpenEvent() {
|
||||||
this.broadcastMessage("FancyBot启动成功了呢~")
|
this.sendPrivateMessage(configManager.startUpNoticeUser, "FancyBot启动完成~")
|
||||||
}
|
}
|
||||||
|
|
||||||
override suspend fun onGroupMessage(message: GroupMessage, json: String) {
|
override suspend fun onGroupMessage(message: GroupMessage, json: String) {
|
||||||
|
|||||||
@@ -8,8 +8,10 @@
|
|||||||
package cn.rtast.fancybot.commands.niuzi
|
package cn.rtast.fancybot.commands.niuzi
|
||||||
|
|
||||||
import cn.rtast.fancybot.annotations.CommandDescription
|
import cn.rtast.fancybot.annotations.CommandDescription
|
||||||
|
import cn.rtast.fancybot.commands
|
||||||
import cn.rtast.fancybot.niuziBankManager
|
import cn.rtast.fancybot.niuziBankManager
|
||||||
import cn.rtast.fancybot.niuziManager
|
import cn.rtast.fancybot.niuziManager
|
||||||
|
import cn.rtast.fancybot.util.getUserName
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.enums.ArrayMessageType
|
import cn.rtast.rob.enums.ArrayMessageType
|
||||||
import cn.rtast.rob.util.BaseCommand
|
import cn.rtast.rob.util.BaseCommand
|
||||||
@@ -20,20 +22,22 @@ private suspend fun noAccount(message: GroupMessage) {
|
|||||||
message.reply("你还没有银行账户呢, 发送`创建账户`来创建一个账户吧~")
|
message.reply("你还没有银行账户呢, 发送`创建账户`来创建一个账户吧~")
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun OneBotListener.getUserName(groupId: Long, userId: Long): String {
|
private const val INTEREST_RATE = 0.0054
|
||||||
val info = this.getGroupMemberInfo(groupId, userId)
|
|
||||||
return info.card ?: info.nickname
|
|
||||||
}
|
|
||||||
|
|
||||||
private const val INTEREST_RATE = 0.54
|
|
||||||
|
|
||||||
@CommandDescription("牛子银行根命令")
|
@CommandDescription("牛子银行根命令")
|
||||||
class NiuziBankCommand : BaseCommand() {
|
class NiuziBankCommand : BaseCommand() {
|
||||||
override val commandNames = listOf("牛子银行")
|
override val commandNames = listOf("牛子银行")
|
||||||
|
|
||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
|
val niuziCommands = commands.filter {
|
||||||
|
it::class.simpleName?.startsWith("Niuzi")!! && !it::class.simpleName?.lowercase()?.contains("redeem")!!
|
||||||
|
}.joinToString("\n") { it.commandNames.joinToString(",") { join -> "`$join`" } }
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addText("发送`余额查询` `银行转账` `取牛子` `存牛子` `创建账户` 即可做出对应的操作")
|
.addText("发送")
|
||||||
|
.addNewLine()
|
||||||
|
.addText(niuziCommands)
|
||||||
|
.addNewLine()
|
||||||
|
.addText("即可做出对应的操作")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText("银行利率是0.54%")
|
.addText("银行利率是0.54%")
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ package cn.rtast.fancybot.commands.niuzi
|
|||||||
|
|
||||||
import cn.rtast.fancybot.annotations.CommandDescription
|
import cn.rtast.fancybot.annotations.CommandDescription
|
||||||
import cn.rtast.fancybot.niuziManager
|
import cn.rtast.fancybot.niuziManager
|
||||||
|
import cn.rtast.fancybot.util.getUserName
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
import cn.rtast.rob.util.BaseCommand
|
import cn.rtast.rob.util.BaseCommand
|
||||||
import cn.rtast.rob.util.ob.MessageChain
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
@@ -23,7 +24,7 @@ class NiuziSignCommand : BaseCommand() {
|
|||||||
message.reply("你今天已经对你的牛子使用了签到啦,明天再来吧~")
|
message.reply("你今天已经对你的牛子使用了签到啦,明天再来吧~")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val username = listener .getUserName(message.groupId, message.sender.userId)
|
val username = listener.getUserName(message.groupId, message.sender.userId)
|
||||||
val afterStatus = niuziManager.sign(message.sender.userId, username)
|
val afterStatus = niuziManager.sign(message.sender.userId, username)
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addReply(message.messageId)
|
.addReply(message.messageId)
|
||||||
|
|||||||
@@ -32,5 +32,6 @@ data class Config(
|
|||||||
val enableAntiRevoke: Boolean,
|
val enableAntiRevoke: Boolean,
|
||||||
val llamaUrl: String,
|
val llamaUrl: String,
|
||||||
val llamaModel: String,
|
val llamaModel: String,
|
||||||
val qqMusicApiUrl: String
|
val qqMusicApiUrl: String,
|
||||||
|
val startUpNoticeUser: Long
|
||||||
)
|
)
|
||||||
@@ -7,9 +7,15 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot.util
|
package cn.rtast.fancybot.util
|
||||||
|
|
||||||
|
import cn.rtast.rob.util.ob.OneBotListener
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
fun randomBooleanWithProbability(probability: Double): Boolean {
|
fun randomBooleanWithProbability(probability: Double): Boolean {
|
||||||
val randomValue = Random.nextInt(100)
|
val randomValue = Random.nextInt(100)
|
||||||
return randomValue <= (probability * 100)
|
return randomValue <= (probability * 100)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun OneBotListener.getUserName(groupId: Long, userId: Long): String {
|
||||||
|
val info = this.getGroupMemberInfo(groupId, userId)
|
||||||
|
return info.card ?: info.nickname
|
||||||
|
}
|
||||||
@@ -11,26 +11,28 @@ import cn.rtast.fancybot.entity.Config
|
|||||||
import cn.rtast.fancybot.util.JsonFileHandler
|
import cn.rtast.fancybot.util.JsonFileHandler
|
||||||
|
|
||||||
class ConfigManager : JsonFileHandler<Config>("config.json") {
|
class ConfigManager : JsonFileHandler<Config>("config.json") {
|
||||||
val ncmAPI get() = this.read<Config>().ncmAPI
|
private val config = this.read<Config>()
|
||||||
val wsAddress get() = this.read<Config>().wsAddress
|
val ncmAPI = config.ncmAPI
|
||||||
val wsPort get() = this.read<Config>().port
|
val wsAddress = config.wsAddress
|
||||||
val accessToken get() = this.read<Config>().accessToken
|
val wsPort = config.port
|
||||||
val wsType get() = this.read<Config>().wsType
|
val accessToken = config.accessToken
|
||||||
val listeningGroups get() = this.read<Config>().listeningGroups
|
val wsType = config.wsType
|
||||||
val qweatherKey get() = this.read<Config>().qweatherKey
|
val listeningGroups = config.listeningGroups
|
||||||
val githubKey get() = this.read<Config>().githubKey
|
val qweatherKey = config.qweatherKey
|
||||||
val imageType get() = this.read<Config>().imageType
|
val githubKey = config.githubKey
|
||||||
val openAIAPIHost get() = this.read<Config>().openAIAPIHost
|
val imageType = config.imageType
|
||||||
val openAIAPIKey get() = this.read<Config>().openAIAPIKey
|
val openAIAPIHost = config.openAIAPIHost
|
||||||
val openAIModel get() = this.read<Config>().openAIModel
|
val openAIAPIKey = config.openAIAPIKey
|
||||||
val smtpHost get() = this.read<Config>().smtpHost
|
val openAIModel = config.openAIModel
|
||||||
val smtpPort get() = this.read<Config>().smtpPort
|
val smtpHost = config.smtpHost
|
||||||
val smtpUser get() = this.read<Config>().smtpUser
|
val smtpPort = config.smtpPort
|
||||||
val smtpPassword get() = this.read<Config>().smtpPassword
|
val smtpUser = config.smtpUser
|
||||||
val smtpFromAddress get() = this.read<Config>().smtpFromAddress
|
val smtpPassword = config.smtpPassword
|
||||||
val admins get() = this.read<Config>().admins
|
val smtpFromAddress = config.smtpFromAddress
|
||||||
val enableAntiRevoke get() = this.read<Config>().enableAntiRevoke
|
val admins = config.admins
|
||||||
val llamaUrl get() = this.read<Config>().llamaUrl
|
val enableAntiRevoke = config.enableAntiRevoke
|
||||||
val llamaModel get() = this.read<Config>().llamaModel
|
val llamaUrl = config.llamaUrl
|
||||||
val qqMusicApiUrl get() = this.read<Config>().qqMusicApiUrl
|
val llamaModel = config.llamaModel
|
||||||
|
val qqMusicApiUrl = config.qqMusicApiUrl
|
||||||
|
val startUpNoticeUser = config.startUpNoticeUser
|
||||||
}
|
}
|
||||||
@@ -25,5 +25,6 @@
|
|||||||
"enableAntiRevoke": true,
|
"enableAntiRevoke": true,
|
||||||
"llamaUrl": "http://127.0.0.1",
|
"llamaUrl": "http://127.0.0.1",
|
||||||
"llamaModel": "llama3.1",
|
"llamaModel": "llama3.1",
|
||||||
"qqMusicApiUrl": "http://127.0.0.1:3200"
|
"qqMusicApiUrl": "http://127.0.0.1:3200",
|
||||||
|
"startUpNoticeUser": 114514
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user