fix: fix mcping when no favicon throw exception
This commit is contained in:
2 files changed
+9
-12
No files matched your search
@@ -45,17 +45,14 @@ class MCPingCommand : BaseCommand() {
|
||||
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)
|
||||
val msg = MessageChain.Builder().addAt(message.sender.userId).addNewLine()
|
||||
if (jsonResponse.favicon != null) msg.addImage(jsonResponse.favicon, true)
|
||||
msg.addText("服务器地址: $host:$port")
|
||||
msg.addNewLine()
|
||||
msg.addText("协议版本号: ${jsonResponse.version.protocol}/${jsonResponse.version.name}")
|
||||
msg.addNewLine()
|
||||
msg.addText("玩家: ${jsonResponse.players.online}/${jsonResponse.players.max}")
|
||||
listener.sendGroupMessage(message.groupId, msg.build())
|
||||
} catch (_: Exception) {
|
||||
val msg = MessageChain.Builder()
|
||||
.addAt(message.sender.userId)
|
||||
|
||||
@@ -10,7 +10,7 @@ package cn.rtast.fancybot.entity
|
||||
data class MCPingResponse(
|
||||
val version: Version,
|
||||
val players: Players,
|
||||
val favicon: String
|
||||
val favicon: String?
|
||||
) {
|
||||
data class Version(
|
||||
val protocol: Int,
|
||||
|
||||
Reference in New Issue
Block a user