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 {
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)