Merge branch 'add-MultiProperties'

This commit is contained in:
LamGC 2020-05-06 11:08:16 +08:00
commit f452c1c128
3 changed files with 16 additions and 6 deletions

View File

@ -64,9 +64,10 @@ public class BotAdminCommandProcess {
@Command
public static String saveProperties() {
log.info("正在保存全局配置文件...");
log.info("正在保存配置文件...");
SettingProperties.saveProperties();
return "保存全局配置文件 - 操作已完成.";
log.info("配置文件保存操作已完成.");
return "保存配置 - 操作已完成.";
}
@Command

View File

@ -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)) {

View File

@ -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);
}