From cb42aadb15f8456a86efd06745c5830f654ca105 Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 6 May 2020 10:55:32 +0800 Subject: [PATCH] =?UTF-8?q?[Fix]=20SettingProperties=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E5=9C=A8=E5=88=9D=E6=AC=A1=E8=AE=BE=E7=BD=AE=E7=BE=A4=E7=BB=84?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=97=B6=E6=9C=AA=E5=88=9B=E5=BB=BA=E8=AF=A5?= =?UTF-8?q?=E7=BE=A4=E7=BB=84=E6=89=80=E5=B1=9EProperties=E5=AF=BC?= =?UTF-8?q?=E8=87=B4NPE=E7=9A=84=E9=97=AE=E9=A2=98;=20[Update]=20BotAdminC?= =?UTF-8?q?ommandProcess=20=E6=9B=B4=E6=96=B0=E6=97=A5=E5=BF=97=E5=86=85?= =?UTF-8?q?=E5=AE=B9=E5=8F=8A=E5=91=BD=E4=BB=A4=E8=BF=94=E5=9B=9E=E4=BF=A1?= =?UTF-8?q?=E6=81=AF;=20[Change]=20BotCommandProcess=20=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E9=A1=B9key=E6=A0=BC=E5=BC=8F;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/bot/BotAdminCommandProcess.java | 5 +++-- .../java/net/lamgc/cgj/bot/BotCommandProcess.java | 6 +++--- .../java/net/lamgc/cgj/bot/SettingProperties.java | 11 ++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/main/java/net/lamgc/cgj/bot/BotAdminCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotAdminCommandProcess.java index 8621373..dad3011 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotAdminCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotAdminCommandProcess.java @@ -64,9 +64,10 @@ public class BotAdminCommandProcess { @Command public static String saveProperties() { - log.info("正在保存全局配置文件..."); + log.info("正在保存配置文件..."); SettingProperties.saveProperties(); - return "保存全局配置文件 - 操作已完成."; + log.info("配置文件保存操作已完成."); + return "保存配置 - 操作已完成."; } @Command diff --git a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java index 03bbe94..7d5f315 100644 --- a/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java +++ b/src/main/java/net/lamgc/cgj/bot/BotCommandProcess.java @@ -218,7 +218,7 @@ public class BotCommandProcess { try { int index = 0; int itemLimit = 10; - String itemLimitPropertyKey = "ranking.ItemCountLimit"; + String itemLimitPropertyKey = "ranking.itemCountLimit"; try { itemLimit = Integer.parseInt(SettingProperties .getProperty(SettingProperties.GLOBAL, itemLimitPropertyKey, "10")); @@ -379,7 +379,7 @@ public class BotCommandProcess { int limit = 8; try { limit = Integer.parseInt(SettingProperties. - getProperty(SettingProperties.GLOBAL, "search.ItemCountLimit", "8")); + getProperty(SettingProperties.GLOBAL, "search.itemCountLimit", "8")); } catch (Exception e) { log.warn("参数转换异常!将使用默认值(" + limit + ")", e); } @@ -424,7 +424,7 @@ public class BotCommandProcess { //pageCount String imageMsg = getImageById(fromGroup, illustId, PixivDownload.PageQuality.REGULAR, 1); - if (isNoSafe(illustId, SettingProperties.getProperties(SettingProperties.GLOBAL), true)) { + if (isNoSafe(illustId, SettingProperties.getProperties(fromGroup), true)) { log.warn("作品Id {} 为R-18作品, 跳过.", illustId); continue; } else if(isReported(illustId)) { diff --git a/src/main/java/net/lamgc/cgj/bot/SettingProperties.java b/src/main/java/net/lamgc/cgj/bot/SettingProperties.java index eb4b3e4..835b021 100644 --- a/src/main/java/net/lamgc/cgj/bot/SettingProperties.java +++ b/src/main/java/net/lamgc/cgj/bot/SettingProperties.java @@ -186,7 +186,13 @@ public final class SettingProperties { */ public static String setProperty(long groupId, String key, String value) { Objects.requireNonNull(key); - Properties targetProperties = groupId <= 0 ? globalProp : getGroupProperties(groupId); + Properties targetProperties; + if(groupId <= 0) { + changeList.add(groupId); + targetProperties = getGroupProperties(groupId); + } else { + targetProperties = globalProp; + } String lastValue = targetProperties.getProperty(key); if(value != null) { targetProperties.setProperty(key, value); @@ -214,6 +220,9 @@ public final class SettingProperties { if (groupId <= 0) { throw new IllegalArgumentException("Group number cannot be 0 or negative: " + groupId); } + if(!groupPropMap.containsKey(groupId)) { + groupPropMap.put(groupId, new Properties(globalProp)); + } return groupPropMap.get(groupId); }