diff --git a/chopperbot-common/src/main/java/org/example/bean/ConfigFile.java b/chopperbot-common/src/main/java/org/example/bean/ConfigFile.java index e84c9f7..b105475 100644 --- a/chopperbot-common/src/main/java/org/example/bean/ConfigFile.java +++ b/chopperbot-common/src/main/java/org/example/bean/ConfigFile.java @@ -38,6 +38,34 @@ public abstract class ConfigFile extends CommonPlugin { this.updateTime = LocalDateTime.now(); } + public ConfigFile(String filePath, String fileName, T data,FileType fileType) { + super(null, null, null, true); + this.fileType = fileType; + this.filePath = filePath; + this.fileName = fileName; + this.data = data; + this.updateTime = LocalDateTime.now(); + } + + public ConfigFile(String module, String pluginName, List needPlugins, boolean isAutoStart, + String filePath, String fileName, T data) { + super(module, pluginName, needPlugins, isAutoStart); + this.fileType = FileType.CONFIG; + this.filePath = filePath; + this.fileName = fileName; + this.data = data; + this.updateTime = LocalDateTime.now(); + } + + public ConfigFile(String module, String pluginName, List needPlugins, boolean isAutoStart, + String filePath, String fileName, T data,FileType fileType) { + super(module, pluginName, needPlugins, isAutoStart); + this.fileType = fileType; + this.filePath = filePath; + this.fileName = fileName; + this.data = data; + this.updateTime = LocalDateTime.now(); + } /** * 用于最开始创建配置文件结构的打包 * @return Map @@ -79,17 +107,6 @@ public abstract class ConfigFile extends CommonPlugin { } - public ConfigFile(String module, String pluginName, List needPlugins, boolean isAutoStart, - String filePath, String fileName, T data) { - super(module, pluginName, needPlugins, isAutoStart); - this.fileType = FileType.CONFIG; - this.filePath = filePath; - this.fileName = fileName; - this.data = data; - this.updateTime = LocalDateTime.now(); - } - - public String getFilePath() { return this.filePath; } diff --git a/chopperbot-creeper/src/main/java/org/example/init/module/CreeperModuleInitMachine.java b/chopperbot-creeper/src/main/java/org/example/init/module/CreeperModuleInitMachine.java index 0748f3e..ca21f9d 100644 --- a/chopperbot-creeper/src/main/java/org/example/init/module/CreeperModuleInitMachine.java +++ b/chopperbot-creeper/src/main/java/org/example/init/module/CreeperModuleInitMachine.java @@ -6,8 +6,7 @@ import org.example.log.LoggerType; import java.util.List; -import static org.example.constpool.ConstPool.CREEPER; -import static org.example.constpool.ConstPool.FILE; +import static org.example.constpool.ConstPool.*; /** * @author Genius @@ -15,7 +14,7 @@ import static org.example.constpool.ConstPool.FILE; **/ public class CreeperModuleInitMachine extends ModuleInitMachine { public CreeperModuleInitMachine() { - super(List.of(FILE), ChopperLogFactory.getLogger(LoggerType.Creeper), CREEPER); + super(List.of(FILE,LIVE_RECORD), ChopperLogFactory.getLogger(LoggerType.Creeper), CREEPER); } } diff --git a/chopperbot-hot/src/main/java/org/example/core/guard/HotModuleGuard.java b/chopperbot-hot/src/main/java/org/example/core/guard/HotModuleGuard.java index f04797f..9c57576 100644 --- a/chopperbot-hot/src/main/java/org/example/core/guard/HotModuleGuard.java +++ b/chopperbot-hot/src/main/java/org/example/core/guard/HotModuleGuard.java @@ -35,7 +35,7 @@ public class HotModuleGuard extends CommonPlugin { } @Override - public boolean init() { + public boolean init(){ try { FileCache HotModuleFileCache = FileCacheManagerInstance.getInstance().getFileCache(HotModuleConfig.getFullFilePath()); @@ -74,7 +74,7 @@ public class HotModuleGuard extends CommonPlugin { runningGuards = new ConcurrentHashMap<>(); start(); }catch (Exception e){ - return false; + throw e; } return true; } diff --git a/chopperbot-hot/src/main/java/org/example/core/recommend/HeatRecommendation.java b/chopperbot-hot/src/main/java/org/example/core/recommend/HeatRecommendation.java index b84d5b6..3c4477b 100644 --- a/chopperbot-hot/src/main/java/org/example/core/recommend/HeatRecommendation.java +++ b/chopperbot-hot/src/main/java/org/example/core/recommend/HeatRecommendation.java @@ -102,7 +102,6 @@ public class HeatRecommendation extends GuardPlugin { for (Live live : needRecommend(lives, followDog.getBanLiver(), followDog.getTop())) { String tempPlatform = live.getPlatform(); this.info(String.format("推荐请求:平台 %s,直播间 %s,主播 %s",tempPlatform,live.getLiveId(),live.getLiver())); - new DouyuLiveLoadBarrageConfig(live.getLiver(),String.valueOf(live.getLiveId())); LoadLiveConfig loadLiveConfig = LiveLoadConfigFactory.buildLiveConfig( tempPlatform, live.getLiveId(), live.getLiver(), true, true); diff --git a/chopperbot-hot/src/main/java/org/example/init/HotConfigInitMachine.java b/chopperbot-hot/src/main/java/org/example/init/HotConfigInitMachine.java index 73d8ded..455d2a4 100644 --- a/chopperbot-hot/src/main/java/org/example/init/HotConfigInitMachine.java +++ b/chopperbot-hot/src/main/java/org/example/init/HotConfigInitMachine.java @@ -28,4 +28,23 @@ public class HotConfigInitMachine extends ConfigInitMachine { public HotConfigInitMachine(List needPlugins, boolean isAutoStart, String moduleName, String name, Class clazz) { super(needPlugins, isAutoStart, moduleName, name, clazz); } + + public static void main(String[] args) throws InterruptedException { + int i = 0; + while (true){ + clearConsole(2); + System.out.printf("A times:%s\n", i); + System.out.printf("B times:%s\n", i); + Thread.sleep(1000); + i++; + } + } + + private static void clearConsole(int lines) { + for (int i = 0; i < lines; i++) { + System.out.print("\033[2K"); // 清除当前行 + System.out.print("\033[1A"); // 上移一行 + } + System.out.print("\033[2K"); // 清除最后一行 + } } diff --git a/chopperbot-live/src/main/java/org/example/core/factory/LiveLoadConfigFactory.java b/chopperbot-live/src/main/java/org/example/core/factory/LiveLoadConfigFactory.java index 0439626..0883cc2 100644 --- a/chopperbot-live/src/main/java/org/example/core/factory/LiveLoadConfigFactory.java +++ b/chopperbot-live/src/main/java/org/example/core/factory/LiveLoadConfigFactory.java @@ -6,6 +6,13 @@ import org.example.core.creeper.loadconfig.DouyuLiveOnlineConfig; import org.example.core.creeper.loadconfig.LoadLiveConfig; import org.example.pool.LiveModuleConstPool; +import javax.swing.*; +import java.awt.*; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.PrintWriter; + /** * @author Genius @@ -52,5 +59,4 @@ public class LiveLoadConfigFactory { return null; } - } diff --git a/chopperbot-live/src/main/java/org/example/init/LiveConfigInitMachine.java b/chopperbot-live/src/main/java/org/example/init/LiveConfigInitMachine.java new file mode 100644 index 0000000..8b6a02d --- /dev/null +++ b/chopperbot-live/src/main/java/org/example/init/LiveConfigInitMachine.java @@ -0,0 +1,63 @@ +package org.example.init; + +import org.example.config.LiveModuleConfigFile; +import org.example.constpool.ConstPool; +import org.example.constpool.ModuleName; +import org.example.constpool.PluginName; +import org.example.plugin.CommonPlugin; +import org.example.plugin.annotation.Plugin; +import org.example.pool.LiveModuleConstPool; +import org.example.util.FileUtil; + +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; + +/** + * @author Genius + * @date 2023/09/01 01:13 + **/ +@Plugin(moduleName = ModuleName.LIVE, + pluginName = PluginName.LIVE_CONFIG_PLUGIN, + pluginName_CN = "直播模块配置文件", + needPlugin = {PluginName.FILE_CACHE_PLUGIN}, + pluginClass= LiveModuleConfigFile.class ) +public class LiveConfigInitMachine extends ConfigInitMachine{ + + public LiveConfigInitMachine(List needPlugins, boolean isAutoStart, String moduleName, String name, Class clazz) { + super(needPlugins, isAutoStart, moduleName, name, clazz); + } + + @Override + public boolean init() { + String fullPath = LiveModuleConstPool.LIVE_MODULE_CONFIG_ROOT; + String online = "online"; + String record = "record"; + try { + Path onlinePath = Path.of(fullPath,online); + Path recordPath = Path.of(fullPath,record); + if(!FileUtil.isFileExist(onlinePath.toString())){ + Files.createDirectory(onlinePath); + } + if(!FileUtil.isFileExist(recordPath.toString())){ + Files.createDirectory(recordPath); + } + for (ConstPool.PLATFORM value : ConstPool.PLATFORM.values()) { + String name = value.getName(); + Path onlinePlatformPath = Path.of(onlinePath.toString(), name); + Path recordPlatformPath = Path.of(recordPath.toString(), name); + if(!FileUtil.isFileExist(onlinePlatformPath.toString())){ + logger.info("[{}}] 构建文件夹 {}",pluginName,onlinePlatformPath); + Files.createDirectory(onlinePlatformPath); + } + if(!FileUtil.isFileExist(recordPlatformPath.toString())){ + logger.info("[{}}] 构建文件夹 {}",pluginName,recordPlatformPath); + Files.createDirectory(recordPlatformPath); + } + } + }catch (Exception e){ + return fail(e.getMessage()); + } + return super.init(); + } +} diff --git a/chopperbot-live/src/main/java/org/example/init/module/LiveModuleInitMachine.java b/chopperbot-live/src/main/java/org/example/init/module/LiveModuleInitMachine.java index 344ffbe..739b69e 100644 --- a/chopperbot-live/src/main/java/org/example/init/module/LiveModuleInitMachine.java +++ b/chopperbot-live/src/main/java/org/example/init/module/LiveModuleInitMachine.java @@ -20,7 +20,7 @@ public class LiveModuleInitMachine extends ModuleInitMachine { public LiveModuleInitMachine() { super( - List.of(ConstPool.FILE,ConstPool.CREEPER), + List.of(ConstPool.FILE), ChopperLogFactory.getLogger(LoggerType.LiveRecord), ModuleName.LIVE ); diff --git a/config/chopperBotConfig.json b/config/chopperBotConfig.json index af7cf15..30a4599 100644 --- a/config/chopperBotConfig.json +++ b/config/chopperBotConfig.json @@ -19,8 +19,9 @@ "TaskCenter":true, "CreeperConfig":true, "LiveDownLoadManager":true, + "LiveConfig":true, "HotRecommendation":true } }, - "updateTime":"2023-09-01 00:47:33" + "updateTime":"2023-09-01 01:31:43" } \ No newline at end of file