mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
[Change] 调整包路径, 增加 loadGlobalProperties 命令以提供重载方式;
This commit is contained in:
parent
841a368767
commit
e20f9d34c9
@ -1,4 +1,4 @@
|
||||
package net.lamgc.cgj;
|
||||
package net.lamgc.cgj.bot;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import net.lamgc.utils.base.runner.Argument;
|
||||
@ -6,25 +6,26 @@ import net.lamgc.utils.base.runner.Command;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.*;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
|
||||
public class CQBotAdminProcess {
|
||||
public class BotAdminCommandProcess {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger("CQBotAdminProcess");
|
||||
private final static Logger log = LoggerFactory.getLogger(BotAdminCommandProcess.class.getSimpleName());
|
||||
|
||||
private final static File globalPropFile = new File("./global.properties");
|
||||
|
||||
@Command
|
||||
public String clearCache() {
|
||||
CQProcess.clearCache();
|
||||
BotCommandProcess.clearCache();
|
||||
return "操作已完成.";
|
||||
}
|
||||
|
||||
@Command
|
||||
public String setGlobalProperty(@Argument(name = "key") String key, @Argument(name = "value") String value, @Argument(name = "save", force = false) boolean saveNow) {
|
||||
String lastValue = CQPluginMain.globalProp.getProperty(key);
|
||||
CQPluginMain.globalProp.setProperty(key, Strings.nullToEmpty(value));
|
||||
String lastValue = BotCommandProcess.globalProp.getProperty(key);
|
||||
BotCommandProcess.globalProp.setProperty(key, Strings.nullToEmpty(value));
|
||||
if(saveNow) {
|
||||
saveGlobalProperties();
|
||||
}
|
||||
@ -33,13 +34,13 @@ public class CQBotAdminProcess {
|
||||
|
||||
@Command
|
||||
public String getGlobalProperty(@Argument(name = "key") String key) {
|
||||
return "全局配置项 " + key + " 当前值: " + CQPluginMain.globalProp.getProperty(key, "(Empty)");
|
||||
return "全局配置项 " + key + " 当前值: " + BotCommandProcess.globalProp.getProperty(key, "(Empty)");
|
||||
}
|
||||
|
||||
@Command
|
||||
public String saveGlobalProperties() {
|
||||
log.info("正在保存全局配置文件...");
|
||||
File globalPropFile = new File("./global.properties");
|
||||
|
||||
try {
|
||||
if(!globalPropFile.exists()) {
|
||||
if(!globalPropFile.createNewFile()) {
|
||||
@ -47,7 +48,7 @@ public class CQBotAdminProcess {
|
||||
return "全局配置项文件保存失败!";
|
||||
}
|
||||
}
|
||||
CQPluginMain.globalProp.store(new FileOutputStream(globalPropFile), "");
|
||||
BotCommandProcess.globalProp.store(new FileOutputStream(globalPropFile), "");
|
||||
log.info("全局配置文件保存成功!");
|
||||
return "保存全局配置文件 - 操作已完成.";
|
||||
} catch (IOException e) {
|
||||
@ -56,10 +57,31 @@ public class CQBotAdminProcess {
|
||||
}
|
||||
}
|
||||
|
||||
@Command
|
||||
public String loadGlobalProperties(@Argument(name = "reload", force = false) boolean reload) {
|
||||
Properties cache = new Properties();
|
||||
if(!globalPropFile.exists()) {
|
||||
return "未找到全局配置文件, 无法重载";
|
||||
}
|
||||
|
||||
try(Reader reader = new BufferedReader(new FileReader(globalPropFile))) {
|
||||
cache.load(reader);
|
||||
} catch (IOException e) {
|
||||
log.error("重载全局配置文件时发生异常", e);
|
||||
return "加载全局配置文件时发生错误!";
|
||||
}
|
||||
|
||||
if(reload) {
|
||||
BotCommandProcess.globalProp.clear();
|
||||
}
|
||||
BotCommandProcess.globalProp.putAll(cache);
|
||||
return "全局配置文件重载完成.";
|
||||
}
|
||||
|
||||
@Command
|
||||
public String runUpdateTask(@Argument(force = false, name = "date") Date queryTime) {
|
||||
try {
|
||||
CQProcess.runUpdateTimer(queryTime);
|
||||
BotCommandProcess.runUpdateTimer(queryTime);
|
||||
} catch (Exception e) {
|
||||
log.error("执行更新任务时发生异常", e);
|
||||
return "操作执行时发生错误!";
|
Loading…
Reference in New Issue
Block a user