diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt index 74251e0..baa54ec 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt @@ -14,18 +14,24 @@ import cn.rtast.rob.util.ob.OneBotListener import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import java.net.InetAddress +import java.net.UnknownHostException class NslookupCommand : BaseCommand() { override val commandNames = listOf("/nslookup", "/ns") override suspend fun executeGroup(listener: OneBotListener, message: GroupMessage, args: List) { - val msg = MessageChain.Builder() - .addReply(message.messageId) - .addText("域名: ${args.first()}解析后的IP地址为: ") - .addText(withContext(Dispatchers.IO) { - InetAddress.getByName(args.first()) - }.hostAddress) - .build() - listener.sendGroupMessage(message.groupId, msg) + val host = args.joinToString(" ") + try { + val msg = MessageChain.Builder() + .addReply(message.messageId) + .addText("域名: ${host}解析后的IP地址为: ") + .addText(withContext(Dispatchers.IO) { InetAddress.getByName(host) }.hostAddress) + .build() + listener.sendGroupMessage(message.groupId, msg) + } catch (_: UnknownHostException) { + message.reply("未知的主机名: $host") + } catch (e: Exception) { + message.reply("未知错误: ${e.message}") + } } } \ No newline at end of file diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt index 8bebcc5..6df591c 100644 --- a/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt +++ b/src/main/kotlin/cn/rtast/fancybot/commands/parse/AsciiArtCommand.kt @@ -86,9 +86,7 @@ class AsciiArtCommand : BaseCommand() { if (message.sender.userId in waitingList) { if (message.message.any { it.type == ArrayMessageType.image }) { val url = message.message.find { it.type == ArrayMessageType.image }!!.data.file!! - val bufferedImage = withContext(Dispatchers.IO) { - ImageIO.read(URI(url).toURL()) - } + val bufferedImage = withContext(Dispatchers.IO) { ImageIO.read(URI(url).toURL()) } val imageBase64 = bufferedImage.convertToAscii().saveAsciiArtToImage(bufferedImage.width, bufferedImage.height) val msg = MessageChain.Builder().addImage(imageBase64, true).build()