优化使 ip.186/whois 查询的返回值删除数据之后的注释行

This commit is contained in:
A.C.Sukazyo Eyre 2022-02-08 16:45:33 +08:00
parent ec83d1f3bc
commit 7ad7913a3c
Signed by: Eyre_S
GPG Key ID: EFB47D98FE082FAD
4 changed files with 18 additions and 4 deletions

View File

@ -1,6 +1,6 @@
## Core ## Core
VERSION = 0.5.0.4 VERSION = 0.5.0.5
# dependencies # dependencies

View File

@ -4,6 +4,6 @@ package cc.sukazyo.cono.morny;
* the final field that will be updated by gradle automatically. * the final field that will be updated by gradle automatically.
*/ */
public class GradleProjectConfigures { public class GradleProjectConfigures {
public static final String VERSION = "0.5.0.4"; public static final String VERSION = "0.5.0.5";
public static final long COMPILE_TIMESTAMP = 1643885546609L; public static final long COMPILE_TIMESTAMP = 1644309862037L;
} }

View File

@ -63,7 +63,7 @@ public class Ip186Query {
try { try {
IP186QueryResponse response = switch (command.getCommand()) { IP186QueryResponse response = switch (command.getCommand()) {
case "/ip" -> IP186QueryHandler.queryIp(arg); case "/ip" -> IP186QueryHandler.queryIp(arg);
case "/whois" -> IP186QueryHandler.queryWhois(arg); case "/whois" -> IP186QueryHandler.queryWhoisPretty(arg);
default -> throw new IllegalArgumentException("Unknown 186-IP query method " + command.getCommand()); default -> throw new IllegalArgumentException("Unknown 186-IP query method " + command.getCommand());
}; };
MornyCoeur.extra().exec(new SendMessage( MornyCoeur.extra().exec(new SendMessage(

View File

@ -62,6 +62,20 @@ public class IP186QueryHandler {
return commonQuery(requestUrl, QUERY_WHOIS_PARAM); return commonQuery(requestUrl, QUERY_WHOIS_PARAM);
} }
/**
* {@link #queryWhois(String)} 的结果进行裁剪.
* <br>
* 将会删除返回内容中 {@code >>> XXX <<<} 行以后的注释串
* 以达到只保留重要信息的目的
*
* @see #queryWhois(String)
*/
@Nonnull
public static IP186QueryResponse queryWhoisPretty (String domain) throws IOException {
final IP186QueryResponse raw = queryWhois(domain);
return new IP186QueryResponse(raw.url(), raw.body().substring(0, raw.body().indexOf("<<<")+3));
}
@Nonnull @Nonnull
private static IP186QueryResponse commonQuery (String requestUrl, String queryIpParam) throws IOException { private static IP186QueryResponse commonQuery (String requestUrl, String queryIpParam) throws IOException {
Request request = new Request.Builder().url(requestUrl + "?" + queryIpParam).build(); Request request = new Request.Builder().url(requestUrl + "?" + queryIpParam).build();