chore: control
This commit is contained in:
3 files changed
+23
-17
No files matched your search
@@ -9,7 +9,9 @@ package cn.rtast.fancybot
|
|||||||
|
|
||||||
import cn.rtast.fancybot.commands.parse.*
|
import cn.rtast.fancybot.commands.parse.*
|
||||||
import cn.rtast.fancybot.enums.WSType
|
import cn.rtast.fancybot.enums.WSType
|
||||||
|
import cn.rtast.fancybot.util.initCommandAndItem
|
||||||
import cn.rtast.fancybot.util.initDatabase
|
import cn.rtast.fancybot.util.initDatabase
|
||||||
|
import cn.rtast.fancybot.util.initFilesDir
|
||||||
import cn.rtast.rob.ROneBotFactory
|
import cn.rtast.rob.ROneBotFactory
|
||||||
import cn.rtast.rob.entity.*
|
import cn.rtast.rob.entity.*
|
||||||
import cn.rtast.rob.entity.lagrange.FileEvent
|
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() {
|
suspend fun main() {
|
||||||
val fancyBot = FancyBot()
|
val fancyBot = FancyBot()
|
||||||
val workType = configManager.wsType
|
val workType = configManager.wsType
|
||||||
@@ -160,10 +158,5 @@ suspend fun main() {
|
|||||||
}
|
}
|
||||||
initDatabase()
|
initDatabase()
|
||||||
initFilesDir()
|
initFilesDir()
|
||||||
val commandManager = rob.commandManager
|
initCommandAndItem(rob)
|
||||||
commands.forEach { commandManager.register(it) }
|
|
||||||
items.forEach { itemManager.register(it) }
|
|
||||||
tasks.forEach {
|
|
||||||
rob.scheduler.scheduleTask(it.value, 1000L, it.key)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -22,14 +22,13 @@ class NiuziRedeemCommand : BaseCommand() {
|
|||||||
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List<String>) {
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addReply(message.messageId)
|
|
||||||
.addText("发送 /rdm <物品名称> 即可兑换哦!")
|
.addText("发送 /rdm <物品名称> 即可兑换哦!")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText("发送 /rdm list 即可查看所有可兑换的物品~")
|
.addText("发送 /rdm list 即可查看所有可兑换的物品~")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText("发送 `我的牛子` 可以查看自己的牛子长度~")
|
.addText("发送 `我的牛子` 可以查看自己的牛子长度~")
|
||||||
.build()
|
.build()
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
message.reply(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val status = niuziManager.getUser(message.sender.userId)
|
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 } }
|
val selectedItem = itemManager.items.find { it.itemNames.any { any -> any == item } }
|
||||||
if (selectedItem == null) {
|
if (selectedItem == null) {
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addReply(message.messageId)
|
|
||||||
.addText("没有找到你想兑换的东西呢")
|
.addText("没有找到你想兑换的东西呢")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText("你可以发送 /rdm list来查看所有可兑换的物品")
|
.addText("你可以发送 /rdm list来查看所有可兑换的物品")
|
||||||
.build()
|
.build()
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
message.reply(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val selectedItemPrice = selectedItem.itemPrice
|
val selectedItemPrice = selectedItem.itemPrice
|
||||||
if (selectedItemPrice > status.length) {
|
if (selectedItemPrice > status.length) {
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addReply(message.messageId)
|
|
||||||
.addText("你的牛子长度不够兑换这个物品呢~")
|
.addText("你的牛子长度不够兑换这个物品呢~")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText("你有: ${status.length}cm, 兑换需要: $selectedItemPrice cm~\"")
|
.addText("你有: ${status.length}cm, 兑换需要: $selectedItemPrice cm~\"")
|
||||||
.build()
|
.build()
|
||||||
listener.sendGroupMessage(message.groupId, msg)
|
message.reply(msg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
val afterStatus = niuziManager.redeemItem(message.sender.userId, selectedItemPrice)?.length!!
|
val afterStatus = niuziManager.redeemItem(message.sender.userId, selectedItemPrice)?.length!!
|
||||||
val action = selectedItem.redeemInGroup(listener, message, afterStatus)
|
val action = selectedItem.redeemInGroup(listener, message, afterStatus)
|
||||||
val msg = MessageChain.Builder()
|
val msg = MessageChain.Builder()
|
||||||
.addReply(message.messageId)
|
|
||||||
.addText("兑换成功! 你花费了${selectedItemPrice}cm来兑换奖品, 还剩${afterStatus}cm")
|
.addText("兑换成功! 你花费了${selectedItemPrice}cm来兑换奖品, 还剩${afterStatus}cm")
|
||||||
.addNewLine()
|
.addNewLine()
|
||||||
.addText("-------------------")
|
.addText("-------------------")
|
||||||
|
|||||||
@@ -7,7 +7,13 @@
|
|||||||
|
|
||||||
package cn.rtast.fancybot.util
|
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 cn.rtast.rob.util.ob.OneBotListener
|
||||||
|
import java.io.File
|
||||||
import kotlin.random.Random
|
import kotlin.random.Random
|
||||||
|
|
||||||
fun randomBooleanWithProbability(probability: Double): Boolean {
|
fun randomBooleanWithProbability(probability: Double): Boolean {
|
||||||
@@ -19,3 +25,14 @@ suspend fun OneBotListener.getUserName(groupId: Long, userId: Long): String {
|
|||||||
val info = this.getGroupMemberInfo(groupId, userId)
|
val info = this.getGroupMemberInfo(groupId, userId)
|
||||||
return info.card ?: info.nickname
|
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() }
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user