feat: add mcping and help command
This commit is contained in:
6 files changed
+135
-13
No files matched your search
+3
-4
@@ -13,10 +13,8 @@ version = fancyBotVersion
|
|||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
mavenLocal()
|
mavenLocal()
|
||||||
maven {
|
maven("https://repo.rtast.cn/api/v4/projects/33/packages/maven")
|
||||||
name = "repo.rtast.cn"
|
maven("https://repo.rtast.cn/api/v4/projects/19/packages/maven")
|
||||||
url = uri("https://repo.rtast.cn/api/v4/projects/33/packages/maven")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.compileKotlin {
|
tasks.compileKotlin {
|
||||||
@@ -35,6 +33,7 @@ dependencies {
|
|||||||
implementation(libs.exposedCore)
|
implementation(libs.exposedCore)
|
||||||
implementation(libs.exposedJDBC)
|
implementation(libs.exposedJDBC)
|
||||||
implementation(libs.sqliteJDBC)
|
implementation(libs.sqliteJDBC)
|
||||||
|
implementation(libs.motdPinger)
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.build {
|
tasks.build {
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
[versions]
|
[versions]
|
||||||
kotlinVersion = "2.0.10"
|
kotlinVersion = "2.0.10"
|
||||||
ronebotVersion = "1.5.7"
|
ronebotVersion = "1.5.8"
|
||||||
shadowVersion = "8.3.0"
|
shadowVersion = "8.3.0"
|
||||||
okhttpVersion = "5.0.0-alpha.14"
|
okhttpVersion = "5.0.0-alpha.14"
|
||||||
exposedVersion = "0.53.0"
|
exposedVersion = "0.53.0"
|
||||||
sqliteJDBCVersion = "3.46.1.0"
|
sqliteJDBCVersion = "3.46.1.0"
|
||||||
|
motdPingerVersion = "1.0.1"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
rOneBot = { group = "cn.rtast", name = "ROneBot", version.ref = "ronebotVersion" }
|
rOneBot = { group = "cn.rtast", name = "ROneBot", version.ref = "ronebotVersion" }
|
||||||
@@ -12,6 +13,7 @@ okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhtt
|
|||||||
exposedCore = { group = "org.jetbrains.exposed", name = "exposed-core", version.ref = "exposedVersion" }
|
exposedCore = { group = "org.jetbrains.exposed", name = "exposed-core", version.ref = "exposedVersion" }
|
||||||
exposedJDBC = { group = "org.jetbrains.exposed", name = "exposed-jdbc", version.ref = "exposedVersion" }
|
exposedJDBC = { group = "org.jetbrains.exposed", name = "exposed-jdbc", version.ref = "exposedVersion" }
|
||||||
sqliteJDBC = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqliteJDBCVersion" }
|
sqliteJDBC = { group = "org.xerial", name = "sqlite-jdbc", version.ref = "sqliteJDBCVersion" }
|
||||||
|
motdPinger = { group = "cn.rtast", name = "MotdPinger", version.ref = "motdPingerVersion" }
|
||||||
|
|
||||||
[bundles]
|
[bundles]
|
||||||
|
|
||||||
|
|||||||
@@ -10,8 +10,10 @@ package cn.rtast.fancybot
|
|||||||
import cn.rtast.fancybot.commands.AntiRevokeCommand
|
import cn.rtast.fancybot.commands.AntiRevokeCommand
|
||||||
import cn.rtast.fancybot.commands.EchoCommand
|
import cn.rtast.fancybot.commands.EchoCommand
|
||||||
import cn.rtast.fancybot.commands.FKXQSCommand
|
import cn.rtast.fancybot.commands.FKXQSCommand
|
||||||
|
import cn.rtast.fancybot.commands.HelpCommand
|
||||||
import cn.rtast.fancybot.commands.HitokotoCommand
|
import cn.rtast.fancybot.commands.HitokotoCommand
|
||||||
import cn.rtast.fancybot.commands.JrrpCommand
|
import cn.rtast.fancybot.commands.JrrpCommand
|
||||||
|
import cn.rtast.fancybot.commands.MCPingCommand
|
||||||
import cn.rtast.fancybot.commands.MusicCommand
|
import cn.rtast.fancybot.commands.MusicCommand
|
||||||
import cn.rtast.fancybot.commands.MyPointCommand
|
import cn.rtast.fancybot.commands.MyPointCommand
|
||||||
import cn.rtast.fancybot.commands.QRCodeCommand
|
import cn.rtast.fancybot.commands.QRCodeCommand
|
||||||
@@ -21,9 +23,9 @@ import cn.rtast.fancybot.entity.enums.WSType
|
|||||||
import cn.rtast.fancybot.items.BaisiItem
|
import cn.rtast.fancybot.items.BaisiItem
|
||||||
import cn.rtast.fancybot.items.HeisiItem
|
import cn.rtast.fancybot.items.HeisiItem
|
||||||
import cn.rtast.fancybot.items.SetuItem
|
import cn.rtast.fancybot.items.SetuItem
|
||||||
import cn.rtast.fancybot.util.item.ItemManager
|
|
||||||
import cn.rtast.fancybot.util.file.ConfigManager
|
import cn.rtast.fancybot.util.file.ConfigManager
|
||||||
import cn.rtast.fancybot.util.initDatabase
|
import cn.rtast.fancybot.util.initDatabase
|
||||||
|
import cn.rtast.fancybot.util.item.ItemManager
|
||||||
import cn.rtast.rob.ROneBotFactory
|
import cn.rtast.rob.ROneBotFactory
|
||||||
import cn.rtast.rob.entity.GetMessage
|
import cn.rtast.rob.entity.GetMessage
|
||||||
import cn.rtast.rob.entity.GroupMessage
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
@@ -64,14 +66,10 @@ class FancyBot : OBMessage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val commands = listOf(
|
val commands = listOf(
|
||||||
EchoCommand(),
|
EchoCommand(), JrrpCommand(), MusicCommand(),
|
||||||
JrrpCommand(),
|
|
||||||
MusicCommand(),
|
|
||||||
SignCommand(), RedeemCommand(), MyPointCommand(),
|
SignCommand(), RedeemCommand(), MyPointCommand(),
|
||||||
HitokotoCommand(),
|
HitokotoCommand(), FKXQSCommand(), QRCodeCommand(),
|
||||||
FKXQSCommand(),
|
AntiRevokeCommand(), MCPingCommand(), HelpCommand()
|
||||||
QRCodeCommand(),
|
|
||||||
AntiRevokeCommand()
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val items = listOf(
|
val items = listOf(
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/3
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.commands
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
|
class HelpCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/help", "/帮助")
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||||
|
val allCommands = commands.joinToString("\n") {
|
||||||
|
"[${it.javaClass.name.split(".").last().replace("Command", "")}] 命令:${it.commandNames.joinToString(",")}"
|
||||||
|
}
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addNewLine()
|
||||||
|
.addText(allCommands)
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/3
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.commands
|
||||||
|
|
||||||
|
import cn.rtast.fancybot.entity.MCPingResponse
|
||||||
|
import cn.rtast.fancybot.util.fromJson
|
||||||
|
import cn.rtast.motdpinger.MotdPinger
|
||||||
|
import cn.rtast.rob.entity.GroupMessage
|
||||||
|
import cn.rtast.rob.util.BaseCommand
|
||||||
|
import cn.rtast.rob.util.ob.MessageChain
|
||||||
|
import cn.rtast.rob.util.ob.OBMessage
|
||||||
|
|
||||||
|
class MCPingCommand : BaseCommand() {
|
||||||
|
override val commandNames = listOf("/mcping", "/mcPing")
|
||||||
|
|
||||||
|
private val pingInstance = MotdPinger()
|
||||||
|
|
||||||
|
override suspend fun executeGroup(listener: OBMessage, message: GroupMessage, args: List<String>) {
|
||||||
|
if (args.isEmpty()) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addNewLine()
|
||||||
|
.addText("使用方法: /mcping <host>:[port]")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("仅限Java版服务器哦~")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val parts = args.first().split(":")
|
||||||
|
val host: String
|
||||||
|
val port: Int
|
||||||
|
if (parts.size == 2) {
|
||||||
|
host = parts[0]
|
||||||
|
port = parts[1].toIntOrNull() ?: 25565
|
||||||
|
} else {
|
||||||
|
host = args.first()
|
||||||
|
port = 25565
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
val rawResponse = pingInstance.pingServer(host, port)
|
||||||
|
val jsonResponse = rawResponse?.fromJson<MCPingResponse>()!!
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addNewLine()
|
||||||
|
.addImage(jsonResponse.favicon, true)
|
||||||
|
.addText("服务器地址: $host:$port")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("协议版本号: ${jsonResponse.version.protocol}/${jsonResponse.version.name}")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("玩家: ${jsonResponse.players.online}/${jsonResponse.players.max}")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
} catch (_: Exception) {
|
||||||
|
val msg = MessageChain.Builder()
|
||||||
|
.addAt(message.sender.userId)
|
||||||
|
.addText("ping失败~")
|
||||||
|
.addNewLine()
|
||||||
|
.addText("检查一下地址或者端口是否正确吧~")
|
||||||
|
.build()
|
||||||
|
listener.sendGroupMessage(message.groupId, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
/*
|
||||||
|
* Copyright © 2024 RTAkland
|
||||||
|
* Author: RTAkland
|
||||||
|
* Date: 2024/9/3
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
package cn.rtast.fancybot.entity
|
||||||
|
|
||||||
|
data class MCPingResponse(
|
||||||
|
val version: Version,
|
||||||
|
val players: Players,
|
||||||
|
val favicon: String
|
||||||
|
) {
|
||||||
|
data class Version(
|
||||||
|
val protocol: Int,
|
||||||
|
val name: String,
|
||||||
|
)
|
||||||
|
|
||||||
|
data class Players(
|
||||||
|
val online: Int,
|
||||||
|
val max: Int,
|
||||||
|
)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user