fix: fix mcping when no favicon throw exception

This commit is contained in:
2024-09-03 16:50:05 +08:00
parent 40aceb0b9d
commit e6255f93eb
2 files changed
+9 -12

No files matched your search

@@ -45,17 +45,14 @@ class MCPingCommand : BaseCommand() {
try { try {
val rawResponse = pingInstance.pingServer(host, port) val rawResponse = pingInstance.pingServer(host, port)
val jsonResponse = rawResponse?.fromJson<MCPingResponse>()!! val jsonResponse = rawResponse?.fromJson<MCPingResponse>()!!
val msg = MessageChain.Builder() val msg = MessageChain.Builder().addAt(message.sender.userId).addNewLine()
.addAt(message.sender.userId) if (jsonResponse.favicon != null) msg.addImage(jsonResponse.favicon, true)
.addNewLine() msg.addText("服务器地址: $host:$port")
.addImage(jsonResponse.favicon, true) msg.addNewLine()
.addText("服务器地址: $host:$port") msg.addText("协议版本号: ${jsonResponse.version.protocol}/${jsonResponse.version.name}")
.addNewLine() msg.addNewLine()
.addText("协议版本号: ${jsonResponse.version.protocol}/${jsonResponse.version.name}") msg.addText("玩家: ${jsonResponse.players.online}/${jsonResponse.players.max}")
.addNewLine() listener.sendGroupMessage(message.groupId, msg.build())
.addText("玩家: ${jsonResponse.players.online}/${jsonResponse.players.max}")
.build()
listener.sendGroupMessage(message.groupId, msg)
} catch (_: Exception) { } catch (_: Exception) {
val msg = MessageChain.Builder() val msg = MessageChain.Builder()
.addAt(message.sender.userId) .addAt(message.sender.userId)
@@ -10,7 +10,7 @@ package cn.rtast.fancybot.entity
data class MCPingResponse( data class MCPingResponse(
val version: Version, val version: Version,
val players: Players, val players: Players,
val favicon: String val favicon: String?
) { ) {
data class Version( data class Version(
val protocol: Int, val protocol: Int,