From a1344067643219d26fa76a9b8dd22ba27a55bca0 Mon Sep 17 00:00:00 2001 From: RTAkland Date: Thu, 22 May 2025 01:11:36 +0800 Subject: [PATCH] Remove --- src/main/kotlin/cn/rtast/fancybot/Const.kt | 2 +- .../commands/lookup/NslookupCommand.kt | 102 ------------------ 2 files changed, 1 insertion(+), 103 deletions(-) delete mode 100644 src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt diff --git a/src/main/kotlin/cn/rtast/fancybot/Const.kt b/src/main/kotlin/cn/rtast/fancybot/Const.kt index 5c674b2..2d91e99 100644 --- a/src/main/kotlin/cn/rtast/fancybot/Const.kt +++ b/src/main/kotlin/cn/rtast/fancybot/Const.kt @@ -99,7 +99,7 @@ val commands = listOf( EchoCommand(), JrrpCommand(), NiuziRedeemCommand(), HitokotoCommand(), KFCCommand(), GenerateQRCodeCommand(), AntiRevokeCommand(), MCPingCommand(), WeatherCommand(), CigaretteCommand(), RemakeCommand(), PixivCommand(), - RUACommand(), NslookupCommand(), CompilerCommand(), AICommand(), + RUACommand(), CompilerCommand(), AICommand(), GithubUserCommand(), AboutCommand(), MusicPlayUrlCommand(), DomainPriceCommand(), SendMailCommand(), ZiBiCommand(), UnsetZiBiCommand(), WikipediaCommand(), AsciiArtCommand(), StatusCommand(), JueCommand(), ShortLinkCommand(), diff --git a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt b/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt deleted file mode 100644 index b3f57e1..0000000 --- a/src/main/kotlin/cn/rtast/fancybot/commands/lookup/NslookupCommand.kt +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright © 2024 RTAkland - * Author: RTAkland - * Date: 2024/9/6 - */ - - -package cn.rtast.fancybot.commands.lookup - -import cn.rtast.fancybot.annotations.CommandDescription -import cn.rtast.fancybot.configManager -import cn.rtast.fancybot.entity.IPGeo -import cn.rtast.fancybot.util.Http -import cn.rtast.rob.entity.GroupMessage -import cn.rtast.rob.onebot.MessageChain -import cn.rtast.rob.onebot.toNode -import cn.rtast.rob.util.BaseCommand -import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.withContext -import java.net.InetAddress -import java.net.UnknownHostException -import java.util.Hashtable -import javax.naming.directory.InitialDirContext - -@CommandDescription("解析域名获取IP地址") -class NslookupCommand : BaseCommand() { - override val commandNames = listOf("/ns") - - companion object { - private const val MC_SRV_PREFIX = "_minecraft._tcp" - private const val IP_INFO_API = "https://ipinfo.io/###/json" - private val env = Hashtable().also { - it["java.naming.factory.initial"] = "com.sun.jndi.dns.DnsContextFactory" - } - private val dirContext = InitialDirContext(env) - - fun srv(host: String): MutableList { - val srvDomain = "$MC_SRV_PREFIX.$host" - val attrs = dirContext.getAttributes(srvDomain, arrayOf("SRV")) - val srvRecords = mutableListOf() - val srvAttr = attrs.get("SRV") - if (srvAttr != null) { - for (i in 0 until srvAttr.size()) { - val srvRecord = srvAttr.get(i) as String - srvRecords.add(srvRecord) - } - } - return srvRecords - } - } - - private fun geo(ip: String) = Http.get(IP_INFO_API.replace("###", ip)) - - override suspend fun executeGroup(message: GroupMessage, args: List) { - val host = args.first() - val nsType = if (args.size == 3) args[1] else "common" - val srvType = if (args.size == 3) args.last() else "mc" - try { - if (nsType == "srv") { - when (srvType) { - "mc" -> { - val srvRecords = srv(host) - val messages = mutableListOf() - srvRecords.forEach { - val srv = it.split(" ") - val priority = srv.first().toInt() - val weight = srv[1].toInt() - val port = srv[2].toInt() - val host = srv.last() - val ip = InetAddress.getByName(host).hostAddress - val geo = this.geo(ip) - val msg = MessageChain.Builder() - .addText("解析后的地址: $host:$port") - .addNewLine() - .addText("权重: $weight | 优先级: $priority") - .addNewLine() - .addText("$host -> $ip") - .addNewLine() - .addText("国家: ${if (geo.country == "HK") "CN" else geo.country} 地区: ${geo.region} 城市: ${geo.city} | 所属组织: ${geo.org}") - .build() - messages.add(msg) - } - message.reply(messages.toNode(configManager.selfId)) - } - } - } else { - val ip = withContext(Dispatchers.IO) { InetAddress.getByName(host) }.hostAddress - val geo = this.geo(ip) - val msg = MessageChain.Builder() - .addText("$host -> $ip") - .addNewLine() - .addText("国家: ${geo.country} 地区: ${geo.region} 城市: ${geo.city} | 所属组织: ${geo.org}") - .build() - message.reply(msg) - } - } catch (_: UnknownHostException) { - message.reply("未知的主机名: $host") - } catch (e: Exception) { - message.reply("未知错误: ${e.message}") - } - } -} \ No newline at end of file