From 9a8aac1960f49aa79b26203713d2858528e2b43d Mon Sep 17 00:00:00 2001 From: LamGC Date: Fri, 5 Jun 2020 16:23:13 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20BotGlobal=20=E4=BF=AE=E5=A4=8DBotGlobal?= =?UTF-8?q?=E5=88=9D=E5=A7=8B=E5=8C=96=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98;=20[Fix]=20BotCommandProcess=20=E4=BF=AE=E5=A4=8DSear?= =?UTF-8?q?ch=E5=91=BD=E4=BB=A4=E6=9C=AA=E6=89=BE=E5=88=B0=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BD=9C=E5=93=81=E6=97=B6=E6=8F=90=E7=A4=BA=E8=AF=AD?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E8=A7=A6=E5=8F=91=E7=9A=84=E9=97=AE=E9=A2=98?= =?UTF-8?q?;=20[Change]=20BotCommandProcess=20=E8=B0=83=E6=95=B4'isNoSafe(?= =?UTF-8?q?int,=20Properties,=20boolean)'=E6=96=B9=E6=B3=95=E4=B8=AD?= =?UTF-8?q?=E5=AF=B9=E4=BA=8E=E4=BD=9C=E5=93=81=E9=99=90=E5=88=B6=E7=9A=84?= =?UTF-8?q?=E5=88=A4=E6=96=AD=E6=96=B9=E5=BC=8F;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/bot/BotCommandProcess.java | 24 +++++++++++-------- .../net/lamgc/cgj/bot/boot/BotGlobal.java | 2 +- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index a94c1c7..56b57bd 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -305,6 +305,7 @@ public class BotCommandProcess { } catch (Exception e) { log.warn("参数转换异常!将使用默认值(" + limit + ")", e); } + int totalCount = 0; for (PixivSearchBuilder.SearchArea searchArea : PixivSearchBuilder.SearchArea.values()) { if (!resultBody.has(searchArea.jsonKey) || resultBody.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data").size() == 0) { @@ -371,12 +372,13 @@ public class BotCommandProcess { .append(illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt()) .append("\n").append(imageMsg).append("\n"); count++; + totalCount++; } if (count > limit) { break; } } - return Strings.isNullOrEmpty(result.toString()) ? + return totalCount <= 0 ? "搜索完成,未找到相关作品。" : Strings.nullToEmpty(result.toString()) + "预览图片并非原图,使用“.cgj image -id 作品id”获取原图\n" + "如有不当作品,可使用\".cgj report -id 作品id\"向色图姬反馈。"; @@ -501,15 +503,17 @@ public class BotCommandProcess { */ public static boolean isNoSafe(int illustId, Properties settingProp, boolean returnRaw) throws IOException, NoSuchElementException { - // TODO(LamGC, 20200604): 看看能不能通过官方获得作品R18信息, 进而加强过滤; - JsonArray tags = CacheStoreCentral.getIllustInfo(illustId, false).getAsJsonArray("tags"); - boolean rawValue = false; - for(JsonElement tag : tags) { - boolean current = tag.getAsString().matches("R-*18") || tag.getAsString().contains("R18"); - // log.warn("Match: {}, Tag: {}", current, tag.getAsString()); - if (current) { - rawValue = true; - break; + JsonObject illustInfo = CacheStoreCentral.getIllustInfo(illustId, false); + JsonArray tags = illustInfo.getAsJsonArray("tags"); + boolean rawValue = illustInfo.get("xRestrict").getAsInt() != 0; + if(!rawValue) { + for(JsonElement tag : tags) { + boolean current = tag.getAsString().matches("R-*18") || tag.getAsString().contains("R18"); + // log.warn("Match: {}, Tag: {}", current, tag.getAsString()); + if (current) { + rawValue = true; + break; + } } } return returnRaw || settingProp == null ? rawValue : diff --git a/src/main/java/net/lamgc/cgj/bot/boot/BotGlobal.java b/src/main/java/net/lamgc/cgj/bot/boot/BotGlobal.java index 28663c4..9f7f823 100644 --- a/src/main/java/net/lamgc/cgj/bot/boot/BotGlobal.java +++ b/src/main/java/net/lamgc/cgj/bot/boot/BotGlobal.java @@ -60,7 +60,7 @@ public final class BotGlobal { this.dataStoreDir = new File((!dataStoreDirPath.endsWith("/") || !dataStoreDirPath.endsWith("\\")) ? dataStoreDirPath + System.getProperty("file.separator") : dataStoreDirPath); - this.imageStoreDir = new File(BotGlobal.getGlobal().getDataStoreDir(), "data/image/cgj/"); + this.imageStoreDir = new File(getDataStoreDir(), "data/image/cgj/"); String proxyAddress = System.getProperty("cgj.proxy"); HttpHost temp = null;