[Fix] BotGlobal 修复BotGlobal初始化失败的问题;

[Fix] BotCommandProcess 修复Search命令未找到相关作品时提示语无法触发的问题;
[Change] BotCommandProcess 调整'isNoSafe(int, Properties, boolean)'方法中对于作品限制的判断方式;
This commit is contained in:
LamGC 2020-06-05 16:23:13 +08:00
parent 4bbed5fd55
commit 9a8aac1960
2 changed files with 15 additions and 11 deletions

View File

@ -305,6 +305,7 @@ public class BotCommandProcess {
} catch (Exception e) { } catch (Exception e) {
log.warn("参数转换异常!将使用默认值(" + limit + ")", e); log.warn("参数转换异常!将使用默认值(" + limit + ")", e);
} }
int totalCount = 0;
for (PixivSearchBuilder.SearchArea searchArea : PixivSearchBuilder.SearchArea.values()) { for (PixivSearchBuilder.SearchArea searchArea : PixivSearchBuilder.SearchArea.values()) {
if (!resultBody.has(searchArea.jsonKey) || if (!resultBody.has(searchArea.jsonKey) ||
resultBody.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data").size() == 0) { resultBody.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data").size() == 0) {
@ -371,12 +372,13 @@ public class BotCommandProcess {
.append(illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt()) .append(illustPreLoadData.get(PreLoadDataComparator.Attribute.COMMENT.attrName).getAsInt())
.append("\n").append(imageMsg).append("\n"); .append("\n").append(imageMsg).append("\n");
count++; count++;
totalCount++;
} }
if (count > limit) { if (count > limit) {
break; break;
} }
} }
return Strings.isNullOrEmpty(result.toString()) ? return totalCount <= 0 ?
"搜索完成,未找到相关作品。" : "搜索完成,未找到相关作品。" :
Strings.nullToEmpty(result.toString()) + "预览图片并非原图,使用“.cgj image -id 作品id”获取原图\n" + Strings.nullToEmpty(result.toString()) + "预览图片并非原图,使用“.cgj image -id 作品id”获取原图\n" +
"如有不当作品,可使用\".cgj report -id 作品id\"向色图姬反馈。"; "如有不当作品,可使用\".cgj report -id 作品id\"向色图姬反馈。";
@ -501,15 +503,17 @@ public class BotCommandProcess {
*/ */
public static boolean isNoSafe(int illustId, Properties settingProp, boolean returnRaw) public static boolean isNoSafe(int illustId, Properties settingProp, boolean returnRaw)
throws IOException, NoSuchElementException { throws IOException, NoSuchElementException {
// TODO(LamGC, 20200604): 看看能不能通过官方获得作品R18信息, 进而加强过滤; JsonObject illustInfo = CacheStoreCentral.getIllustInfo(illustId, false);
JsonArray tags = CacheStoreCentral.getIllustInfo(illustId, false).getAsJsonArray("tags"); JsonArray tags = illustInfo.getAsJsonArray("tags");
boolean rawValue = false; boolean rawValue = illustInfo.get("xRestrict").getAsInt() != 0;
for(JsonElement tag : tags) { if(!rawValue) {
boolean current = tag.getAsString().matches("R-*18") || tag.getAsString().contains("R18"); for(JsonElement tag : tags) {
// log.warn("Match: {}, Tag: {}", current, tag.getAsString()); boolean current = tag.getAsString().matches("R-*18") || tag.getAsString().contains("R18");
if (current) { // log.warn("Match: {}, Tag: {}", current, tag.getAsString());
rawValue = true; if (current) {
break; rawValue = true;
break;
}
} }
} }
return returnRaw || settingProp == null ? rawValue : return returnRaw || settingProp == null ? rawValue :

View File

@ -60,7 +60,7 @@ public final class BotGlobal {
this.dataStoreDir = new File((!dataStoreDirPath.endsWith("/") || !dataStoreDirPath.endsWith("\\")) ? this.dataStoreDir = new File((!dataStoreDirPath.endsWith("/") || !dataStoreDirPath.endsWith("\\")) ?
dataStoreDirPath + System.getProperty("file.separator") : dataStoreDirPath); 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"); String proxyAddress = System.getProperty("cgj.proxy");
HttpHost temp = null; HttpHost temp = null;