From 0016fa578de46f7a7a01b8366fb5805ef308efa8 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Thu, 26 Sep 2024 21:56:44 +0800 Subject: [PATCH] chore: improve niuzi bank command --- src/main/kotlin/cn/rtast/fancybot/Const.kt | 3 +- src/main/kotlin/cn/rtast/fancybot/FancyBot.kt | 2 +- .../commands/niuzi/NiuziBankCommand.kt | 18 +++++--- .../commands/niuzi/NiuziSignCommand.kt | 3 +- .../kotlin/cn/rtast/fancybot/entity/Config.kt | 3 +- .../kotlin/cn/rtast/fancybot/util/Misc.kt | 6 +++ .../rtast/fancybot/util/file/ConfigManager.kt | 46 ++++++++++--------- src/main/resources/config.json | 3 +- 8 files changed, 50 insertions(+), 34 deletions(-) diff --git a/src/main/kotlin/cn/rtast/fancybot/Const.kt b/src/main/kotlin/cn/rtast/fancybot/Const.kt index 7cff94b..d15f531 100644 --- a/src/main/kotlin/cn/rtast/fancybot/Const.kt +++ b/src/main/kotlin/cn/rtast/fancybot/Const.kt @@ -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() diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index 2921964..ba7ed35 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -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) { diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt index 419b87e..b49ae12 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziBankCommand.kt @@ -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) { + 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() diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt index 5d0cf52..d2c3f1b 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziSignCommand.kt @@ -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) diff --git a/src/main/kotlin/cn/rtast/fancybot/entity/Config.kt b/src/main/kotlin/cn/rtast/fancybot/entity/Config.kt index 8ce8b8f..f360e11 100644 --- a/src/main/kotlin/cn/rtast/fancybot/entity/Config.kt +++ b/src/main/kotlin/cn/rtast/fancybot/entity/Config.kt @@ -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 ) \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt b/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt index e704fd0..cc17a6f 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt @@ -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 } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/util/file/ConfigManager.kt b/src/main/kotlin/cn/rtast/fancybot/util/file/ConfigManager.kt index a2c3b94..4100529 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/file/ConfigManager.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/file/ConfigManager.kt @@ -11,26 +11,28 @@ import cn.rtast.fancybot.entity.Config import cn.rtast.fancybot.util.JsonFileHandler class ConfigManager : JsonFileHandler("config.json") { - val ncmAPI get() = this.read().ncmAPI - val wsAddress get() = this.read().wsAddress - val wsPort get() = this.read().port - val accessToken get() = this.read().accessToken - val wsType get() = this.read().wsType - val listeningGroups get() = this.read().listeningGroups - val qweatherKey get() = this.read().qweatherKey - val githubKey get() = this.read().githubKey - val imageType get() = this.read().imageType - val openAIAPIHost get() = this.read().openAIAPIHost - val openAIAPIKey get() = this.read().openAIAPIKey - val openAIModel get() = this.read().openAIModel - val smtpHost get() = this.read().smtpHost - val smtpPort get() = this.read().smtpPort - val smtpUser get() = this.read().smtpUser - val smtpPassword get() = this.read().smtpPassword - val smtpFromAddress get() = this.read().smtpFromAddress - val admins get() = this.read().admins - val enableAntiRevoke get() = this.read().enableAntiRevoke - val llamaUrl get() = this.read().llamaUrl - val llamaModel get() = this.read().llamaModel - val qqMusicApiUrl get() = this.read().qqMusicApiUrl + private val config = this.read() + 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 } \ No newline at end of file diff --git a/src/main/resources/config.json b/src/main/resources/config.json index 1aa0ad3..174c5c4 100644 --- a/src/main/resources/config.json +++ b/src/main/resources/config.json @@ -25,5 +25,6 @@ "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": 114514 } \ No newline at end of file