From 04b6823d7e5b145b8ebbf3405fcb16d9f67c84d5 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Sun, 6 Oct 2024 11:28:56 +0800 Subject: [PATCH] chore: control --- src/main/kotlin/cn/rtast/fancybot/FancyBot.kt | 13 +++---------- .../commands/niuzi/NiuziRedeemCommand.kt | 10 +++------- src/main/kotlin/cn/rtast/fancybot/util/Misc.kt | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index 9179ba8..86a2744 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -9,7 +9,9 @@ package cn.rtast.fancybot import cn.rtast.fancybot.commands.parse.* import cn.rtast.fancybot.enums.WSType +import cn.rtast.fancybot.util.initCommandAndItem import cn.rtast.fancybot.util.initDatabase +import cn.rtast.fancybot.util.initFilesDir import cn.rtast.rob.ROneBotFactory import cn.rtast.rob.entity.* import cn.rtast.rob.entity.lagrange.FileEvent @@ -141,10 +143,6 @@ class FancyBot : OneBotListener { } } -fun initFilesDir() { - File("./files/images").also { it.mkdirs() } -} - suspend fun main() { val fancyBot = FancyBot() val workType = configManager.wsType @@ -160,10 +158,5 @@ suspend fun main() { } initDatabase() initFilesDir() - val commandManager = rob.commandManager - commands.forEach { commandManager.register(it) } - items.forEach { itemManager.register(it) } - tasks.forEach { - rob.scheduler.scheduleTask(it.value, 1000L, it.key) - } + initCommandAndItem(rob) } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziRedeemCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziRedeemCommand.kt index 8f8f69b..24a758f 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziRedeemCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/niuzi/NiuziRedeemCommand.kt @@ -22,14 +22,13 @@ class NiuziRedeemCommand : BaseCommand() { override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { if (args.isEmpty()) { val msg = MessageChain.Builder() - .addReply(message.messageId) .addText("发送 /rdm <物品名称> 即可兑换哦!") .addNewLine() .addText("发送 /rdm list 即可查看所有可兑换的物品~") .addNewLine() .addText("发送 `我的牛子` 可以查看自己的牛子长度~") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } val status = niuziManager.getUser(message.sender.userId) @@ -47,29 +46,26 @@ class NiuziRedeemCommand : BaseCommand() { val selectedItem = itemManager.items.find { it.itemNames.any { any -> any == item } } if (selectedItem == null) { val msg = MessageChain.Builder() - .addReply(message.messageId) .addText("没有找到你想兑换的东西呢") .addNewLine() .addText("你可以发送 /rdm list来查看所有可兑换的物品") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } val selectedItemPrice = selectedItem.itemPrice if (selectedItemPrice > status.length) { val msg = MessageChain.Builder() - .addReply(message.messageId) .addText("你的牛子长度不够兑换这个物品呢~") .addNewLine() .addText("你有: ${status.length}cm, 兑换需要: $selectedItemPrice cm~\"") .build() - listener.sendGroupMessage(message.groupId, msg) + message.reply(msg) return } val afterStatus = niuziManager.redeemItem(message.sender.userId, selectedItemPrice)?.length!! val action = selectedItem.redeemInGroup(listener, message, afterStatus) val msg = MessageChain.Builder() - .addReply(message.messageId) .addText("兑换成功! 你花费了${selectedItemPrice}cm来兑换奖品, 还剩${afterStatus}cm") .addNewLine() .addText("-------------------") diff --git a/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt b/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt index cc17a6f..21e0075 100644 --- a/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt +++ b/src/main/kotlin/cn/rtast/fancybot/util/Misc.kt @@ -7,7 +7,13 @@ package cn.rtast.fancybot.util +import cn.rtast.fancybot.commands +import cn.rtast.fancybot.itemManager +import cn.rtast.fancybot.items +import cn.rtast.fancybot.tasks +import cn.rtast.rob.ROneBotFactory import cn.rtast.rob.util.ob.OneBotListener +import java.io.File import kotlin.random.Random fun randomBooleanWithProbability(probability: Double): Boolean { @@ -18,4 +24,15 @@ fun randomBooleanWithProbability(probability: Double): Boolean { suspend fun OneBotListener.getUserName(groupId: Long, userId: Long): String { val info = this.getGroupMemberInfo(groupId, userId) return info.card ?: info.nickname +} + +fun initCommandAndItem(rob: ROneBotFactory) { + val commandManager = rob.commandManager + commands.forEach { commandManager.register(it) } + items.forEach { itemManager.register(it) } + tasks.forEach { rob.scheduler.scheduleTask(it.value, 1000L, it.key) } +} + +fun initFilesDir() { + File("./files/images").also { it.mkdirs() } } \ No newline at end of file