From bba8a9965889bfa1a41176105caf10e50564a2f5 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Wed, 4 Sep 2024 11:36:41 +0800 Subject: [PATCH] chore: format code --- gradle/libs.versions.toml | 2 +- src/main/kotlin/cn/rtast/fancybot/FancyBot.kt | 12 +++-- .../rtast/fancybot/commands/MCPingCommand.kt | 4 +- .../rtast/fancybot/commands/MyPointCommand.kt | 53 +++++++++++++++++++ .../rtast/fancybot/commands/RedeemCommand.kt | 1 + .../cn/rtast/fancybot/commands/SignCommand.kt | 42 +-------------- .../entity/{MCPingResponse.kt => MCPing.kt} | 2 +- 7 files changed, 67 insertions(+), 49 deletions(-) create mode 100644 src/main/kotlin/cn/rtast/fancybot/commands/MyPointCommand.kt rename src/main/kotlin/cn/rtast/fancybot/entity/{MCPingResponse.kt => MCPing.kt} (92%) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 0e5a404..23e7af2 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] kotlinVersion = "2.0.10" -ronebotVersion = "1.5.8" +ronebotVersion = "1.5.9" shadowVersion = "8.3.0" okhttpVersion = "5.0.0-alpha.14" exposedVersion = "0.53.0" diff --git a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt index e427b20..97de207 100644 --- a/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt +++ b/src/main/kotlin/cn/rtast/fancybot/FancyBot.kt @@ -24,6 +24,7 @@ import cn.rtast.fancybot.items.BaisiItem import cn.rtast.fancybot.items.HeisiItem import cn.rtast.fancybot.items.SetuItem import cn.rtast.fancybot.util.file.ConfigManager +import cn.rtast.fancybot.util.file.SignManager import cn.rtast.fancybot.util.initDatabase import cn.rtast.fancybot.util.item.ItemManager import cn.rtast.rob.ROneBotFactory @@ -66,10 +67,12 @@ class FancyBot : OBMessage { } val commands = listOf( - EchoCommand(), JrrpCommand(), MusicCommand(), - SignCommand(), RedeemCommand(), MyPointCommand(), - HitokotoCommand(), FKXQSCommand(), QRCodeCommand(), - AntiRevokeCommand(), MCPingCommand(), HelpCommand() + EchoCommand(), JrrpCommand(), + MusicCommand(), SignCommand(), + RedeemCommand(), MyPointCommand(), + HitokotoCommand(), FKXQSCommand(), + QRCodeCommand(), AntiRevokeCommand(), + MCPingCommand(), HelpCommand() ) val items = listOf( @@ -80,6 +83,7 @@ val items = listOf( val configManager = ConfigManager() val itemManager = ItemManager() +val signManager = SignManager() suspend fun main() { val fancyBot = FancyBot() diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/MCPingCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/MCPingCommand.kt index d1d4129..4171d72 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/MCPingCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/MCPingCommand.kt @@ -7,7 +7,7 @@ package cn.rtast.fancybot.commands -import cn.rtast.fancybot.entity.MCPingResponse +import cn.rtast.fancybot.entity.MCPing import cn.rtast.fancybot.util.fromJson import cn.rtast.motdpinger.MotdPinger import cn.rtast.rob.entity.GroupMessage @@ -44,7 +44,7 @@ class MCPingCommand : BaseCommand() { } try { val rawResponse = pingInstance.pingServer(host, port) - val jsonResponse = rawResponse?.fromJson()!! + val jsonResponse = rawResponse?.fromJson()!! val msg = MessageChain.Builder().addAt(message.sender.userId).addNewLine() if (jsonResponse.favicon != null) msg.addImage(jsonResponse.favicon, true) msg.addText("服务器地址: $host:$port") diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/MyPointCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/MyPointCommand.kt new file mode 100644 index 0000000..6d0a2e5 --- /dev/null +++ b/src/main/kotlin/cn/rtast/fancybot/commands/MyPointCommand.kt @@ -0,0 +1,53 @@ +/* + * Copyright © 2024 RTAkland + * Author: RTAkland + * Date: 2024/9/4 + */ + + +package cn.rtast.fancybot.commands + +import cn.rtast.fancybot.ADMINS +import cn.rtast.fancybot.signManager +import cn.rtast.rob.entity.GroupMessage +import cn.rtast.rob.enums.UserRole +import cn.rtast.rob.util.BaseCommand +import cn.rtast.rob.util.ob.MessageChain +import cn.rtast.rob.util.ob.OBMessage + +class MyPointCommand : BaseCommand() { + override val commandNames = listOf("/我的点数", "/mp") + + override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List) { + // query target's point + if (args.isNotEmpty() && (message.sender.role == UserRole.admin || message.sender.userId in ADMINS)) { + val targetId = args.first().toLong() + val targetData = signManager.getStatus(targetId) + val msg = MessageChain.Builder().addAt(message.sender.userId) + + if (targetData == null) { + msg.addText("用户不存在, 需要先签到一次才能查询点数呢~") + } else { + msg.addText("用户: ${targetData.id} 的点数有: ${targetData.points}") + } + listener.sendGroupMessage(message.groupId, msg.build()) + return + } + // query self point + val status = signManager.getStatus(message.sender.userId) + if (status == null) { + val msg = MessageChain.Builder() + .addAt(message.sender.userId) + .addText("你还没有签到过呢! 先发送‘/签到’再来查询吧~") + .build() + listener.sendGroupMessage(message.groupId, msg) + return + } else { + val msg = MessageChain.Builder() + .addAt(message.sender.userId) + .addText("你当前的点数为: ${status.points}") + .build() + listener.sendGroupMessage(message.groupId, msg) + } + } +} diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/RedeemCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/RedeemCommand.kt index 4f1e46e..d51700e 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/RedeemCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/RedeemCommand.kt @@ -8,6 +8,7 @@ package cn.rtast.fancybot.commands import cn.rtast.fancybot.itemManager +import cn.rtast.fancybot.signManager import cn.rtast.rob.entity.GroupMessage import cn.rtast.rob.util.BaseCommand import cn.rtast.rob.util.ob.MessageChain diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/SignCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/SignCommand.kt index 8628d26..fdebcbb 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/SignCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/SignCommand.kt @@ -7,15 +7,12 @@ package cn.rtast.fancybot.commands -import cn.rtast.fancybot.ADMINS -import cn.rtast.fancybot.util.file.SignManager +import cn.rtast.fancybot.signManager import cn.rtast.rob.entity.GroupMessage -import cn.rtast.rob.enums.UserRole import cn.rtast.rob.util.BaseCommand import cn.rtast.rob.util.ob.MessageChain import cn.rtast.rob.util.ob.OBMessage -val signManager = SignManager() class SignCommand : BaseCommand() { override val commandNames = listOf("/签到", "/sign") @@ -39,40 +36,3 @@ class SignCommand : BaseCommand() { listener.sendGroupMessage(message.groupId, msg) } } - -class MyPointCommand : BaseCommand() { - override val commandNames = listOf("/我的点数", "/mp") - - override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List) { - // query target's point - if (args.isNotEmpty() && (message.sender.role == UserRole.admin || message.sender.userId in ADMINS)) { - val targetId = args.first().toLong() - val targetData = signManager.getStatus(targetId) - val msg = MessageChain.Builder().addAt(message.sender.userId) - - if (targetData == null) { - msg.addText("用户不存在, 需要先签到一次才能查询点数呢~") - } else { - msg.addText("用户: ${targetData.id} 的点数有: ${targetData.points}") - } - listener.sendGroupMessage(message.groupId, msg.build()) - return - } - // query self point - val status = signManager.getStatus(message.sender.userId) - if (status == null) { - val msg = MessageChain.Builder() - .addAt(message.sender.userId) - .addText("你还没有签到过呢! 先发送‘/签到’再来查询吧~") - .build() - listener.sendGroupMessage(message.groupId, msg) - return - } else { - val msg = MessageChain.Builder() - .addAt(message.sender.userId) - .addText("你当前的点数为: ${status.points}") - .build() - listener.sendGroupMessage(message.groupId, msg) - } - } -} diff --git a/src/main/kotlin/cn/rtast/fancybot/entity/MCPingResponse.kt b/src/main/kotlin/cn/rtast/fancybot/entity/MCPing.kt similarity index 92% rename from src/main/kotlin/cn/rtast/fancybot/entity/MCPingResponse.kt rename to src/main/kotlin/cn/rtast/fancybot/entity/MCPing.kt index 015073d..a439545 100644 --- a/src/main/kotlin/cn/rtast/fancybot/entity/MCPingResponse.kt +++ b/src/main/kotlin/cn/rtast/fancybot/entity/MCPing.kt @@ -7,7 +7,7 @@ package cn.rtast.fancybot.entity -data class MCPingResponse( +data class MCPing( val version: Version, val players: Players, val favicon: String?