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