diff --git a/.idea/compiler.xml b/.idea/compiler.xml index b6c4da6..dd8bb3d 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -12,11 +12,11 @@ - + - + @@ -38,4 +38,4 @@ - \ No newline at end of file + diff --git a/.idea/misc.xml b/.idea/misc.xml index 89d68e4..28111c1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,11 +1,16 @@ + + + + \ No newline at end of file + diff --git a/.idea/vcs.xml b/.idea/vcs.xml index 94a25f7..dcb6b8c 100644 --- a/.idea/vcs.xml +++ b/.idea/vcs.xml @@ -1,6 +1,6 @@ - + - \ No newline at end of file + diff --git a/BarrageModule/pom.xml b/BarrageModule/pom.xml index 8800606..42a520a 100644 --- a/BarrageModule/pom.xml +++ b/BarrageModule/pom.xml @@ -39,5 +39,17 @@ 1.0-SNAPSHOT compile + + commons-io + commons-io + 2.11.0 + compile + + + io.jsonwebtoken + jjwt-api + 0.11.5 + compile + diff --git a/BarrageModule/src/main/java/org/example/anchor/小团团.json b/BarrageModule/src/main/java/org/example/anchor/小团团.json new file mode 100644 index 0000000..f8cddf6 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/anchor/小团团.json @@ -0,0 +1,17 @@ +[ + { + "roomId": "123456", + "plathForm":"斗鱼", + "nickName":"小团团", + "property":[ + { + "content":"666", + "weight":5 + }, + { + "content":"下播", + "weight":7 + } + ] + } +] diff --git a/BarrageModule/src/main/java/org/example/anchor/斗鱼-606118.json b/BarrageModule/src/main/java/org/example/anchor/斗鱼-606118.json new file mode 100644 index 0000000..3b3131b --- /dev/null +++ b/BarrageModule/src/main/java/org/example/anchor/斗鱼-606118.json @@ -0,0 +1,21 @@ +[{ + "name":"大司马", + "property":[ + { + "content":"哈哈哈", + "weight":10 + }, + { + "content":"素材", + "weight":10 + }, + { + "content":"gg", + "weight":10 + }, + { + "content":"???", + "weight":10 + } + ] +}] diff --git a/BarrageModule/src/main/java/org/example/anchor/水晶哥.json b/BarrageModule/src/main/java/org/example/anchor/水晶哥.json new file mode 100644 index 0000000..918c3bb --- /dev/null +++ b/BarrageModule/src/main/java/org/example/anchor/水晶哥.json @@ -0,0 +1,19 @@ +[ + { + "name":"水晶哥", + "property":[ + { + "content":"陌生", + "weight":10 + }, + { + "content":"没道理", + "weight":10 + }, + { + "content":"666", + "weight":5 + } + ] + } +] diff --git a/BarrageModule/src/main/java/org/example/anchor/虎牙-123456.json b/BarrageModule/src/main/java/org/example/anchor/虎牙-123456.json new file mode 100644 index 0000000..a7e58b2 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/anchor/虎牙-123456.json @@ -0,0 +1,11 @@ +{ + "nickName":"姿态", + "plathForm":"虎牙", + "property":[ + { + "content":"hahaha", + "weight":10 + } + ], + "roomId":"123456" +} \ No newline at end of file diff --git a/BarrageModule/src/main/java/org/example/api/BarrageModuleApi.java b/BarrageModule/src/main/java/org/example/api/BarrageModuleApi.java new file mode 100644 index 0000000..43fd9a2 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/api/BarrageModuleApi.java @@ -0,0 +1,19 @@ +package org.example.api; + +import org.example.config.BarrageScoreConfig; +import org.example.pojo.Anchor; + +import java.util.List; + +/** + * @Description + * @Author welsir + * @Date 2023/8/2 22:51 + */ +public class BarrageModuleApi { + +// public static void updateAnchorBarrageScore(String roomId, String plathForm, List anchorList){ +// BarrageScoreConfig.setAnchorConfig(roomId,plathForm,anchorList); +// } + +} diff --git a/BarrageModule/src/main/java/org/example/config/BarrageFileConfig.java b/BarrageModule/src/main/java/org/example/config/BarrageFileConfig.java index 9a08309..5c42f04 100644 --- a/BarrageModule/src/main/java/org/example/config/BarrageFileConfig.java +++ b/BarrageModule/src/main/java/org/example/config/BarrageFileConfig.java @@ -8,7 +8,7 @@ package org.example.config; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; -import org.example.entity.Barrage; +import org.example.pojo.Barrage; import org.example.util.JsonFileUtil; import java.io.File; @@ -39,6 +39,10 @@ public class BarrageFileConfig { return anchorMap; } + public static void setMap(Map map) { + anchorMap = (HashMap>)map; + } + private static void classifyAndProcessFolders(File folder) { File[] subFolders = folder.listFiles(File::isDirectory); if (subFolders != null) { @@ -68,9 +72,9 @@ public class BarrageFileConfig { } public static void main(String[] args) { -// getBarrageFile(); - String encode = URLEncoder.encode("config\\barrage\\大司马\\douyu_大司马_05-07-14_58_17.json", StandardCharsets.UTF_8); - Map map = JsonFileUtil.readJsonFile(encode); - System.out.println(map.size()); + getBarrageFile(); +// String encode = URLEncoder.encode("config\\barrage\\大司马\\douyu_大司马_05-07-14_58_17.json", StandardCharsets.UTF_8); +// Map map = JsonFileUtil.readJsonFile(encode); +// System.out.println(map.size()); } } diff --git a/BarrageModule/src/main/java/org/example/config/BarrageScoreConfig.java b/BarrageModule/src/main/java/org/example/config/BarrageScoreConfig.java index 795e340..63dffdc 100644 --- a/BarrageModule/src/main/java/org/example/config/BarrageScoreConfig.java +++ b/BarrageModule/src/main/java/org/example/config/BarrageScoreConfig.java @@ -6,73 +6,59 @@ package org.example.config; */ import com.alibaba.fastjson.JSON; -import org.example.entity.Anchor; +import org.example.constpool.BarrageModuleConstPool; +import org.example.core.listen.BarrageFileMonitor; +import org.example.pojo.Anchor; import org.example.util.FileUtil; import org.example.util.JsonFileUtil; -import java.util.ArrayList; -import java.util.HashMap; -import java.util.List; +import java.io.File; +import java.util.*; +import java.util.stream.Collectors; +import java.util.stream.Stream; /** * @author welsir * @date 2023/5/15 22:14 */ public class BarrageScoreConfig { - - private static List anchorList = new ArrayList<>(); private static final HashMap anchorScoreMap = new HashMap<>(); /** - * @description: 解析主播得分配置文件存入map + * @description: Set the anchor keyword and write to the file */ - public static void getConfigFile() throws Exception { - anchorList = JSON.parseArray(FileUtil.JSONFileToString("/anchor/score.json"), Anchor.class); - for (Anchor anchor : anchorList) { - anchorScoreMap.put(anchor.getName(),anchorList.indexOf(anchor)); - } - System.out.println("anchor count ::"+anchorList.size()); - } - - /** - * @description: 设置主播关键词并写入文件 - */ - public static void setAnchorConfig(List list){ - for (Anchor anchor : list) { - //判断追加还是写入 - int idx = anchorScoreMap.get(anchor.getName())==null?0:anchorScoreMap.get(anchor.getName()); - if(idx!=0){ - List property = anchorList.get(idx).getProperty(); - property.addAll(anchor.getProperty()); - }else { - anchorList.add(anchor); - } - } - JsonFileUtil.writeJsonFile("D:\\idea_Project\\Springboot\\ChopperBot\\BarrageModule\\src\\main\\resources\\anchor\\","score.json",anchorList); - } - - public static List getAnchorScoreList(){ - return anchorList; - } public static void main(String[] args) throws Exception { - getConfigFile(); - ArrayList list = new ArrayList<>(); - Anchor anchor = new Anchor(); - anchor.setName("水晶哥"); - ArrayList properties = new ArrayList<>(); - properties.add(new Anchor.property("666",5)); - properties.add(new Anchor.property("下播",7)); - anchor.setProperty(properties); - Anchor anchor1 = new Anchor(); - anchor1.setName("小团团"); - ArrayList properties1 = new ArrayList<>(); - properties1.add(new Anchor.property("666",5)); - properties1.add(new Anchor.property("下播",7)); - anchor1.setProperty(properties1); - list.add(anchor); - list.add(anchor1); - setAnchorConfig(list); +// getConfigFile(); +// ArrayList list = new ArrayList<>(); +// Anchor anchor = new Anchor(); +// anchor.setName("水晶哥"); +// ArrayList properties = new ArrayList<>(); +// properties.add(new Anchor.property("666",5)); +// properties.add(new Anchor.property("下播",7)); +// anchor.setProperty(properties); +// Anchor anchor1 = new Anchor(); +// anchor1.setName("小团团"); +// ArrayList properties1 = new ArrayList<>(); +// properties1.add(new Anchor.property("666",5)); +// properties1.add(new Anchor.property("下播",7)); +// anchor1.setProperty(properties1); +// list.add(anchor); +// list.add(anchor1); +// setAnchorConfig(list); + List list1 = new ArrayList<>(Arrays.asList(1, 2, 3)); + List list2 = new ArrayList<>(Arrays.asList(3, 4, 5)); + + // 合并两个List,并去重 + list1 = Stream.concat(list1.stream(), list2.stream()) + .distinct() + .collect(Collectors.toList()); + + // 输出去重并合并后的结果 + System.out.println("去重并合并后的结果:"); + for (Integer num : list1) { + System.out.print(num + " "); + } } } diff --git a/BarrageModule/src/main/java/org/example/constpool/BarrageModuleConstPool.java b/BarrageModule/src/main/java/org/example/constpool/BarrageModuleConstPool.java new file mode 100644 index 0000000..2f7eb16 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/constpool/BarrageModuleConstPool.java @@ -0,0 +1,13 @@ +package org.example.constpool; + +/** + * @Description + * @Author welsir + * @Date 2023/8/2 23:38 + */ +public class BarrageModuleConstPool { + public static final String BARRAGE_FILE_PATH = "config/barrage/"; + public static final String ANCHOR_FILE_PATH = "config/barrage/anchor/"; + + public static final String AnchorFileType = ".json"; +} diff --git a/BarrageModule/src/main/java/org/example/controller/ExceptionController.java b/BarrageModule/src/main/java/org/example/controller/ExceptionController.java deleted file mode 100644 index 9a1bcb9..0000000 --- a/BarrageModule/src/main/java/org/example/controller/ExceptionController.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.example.controller;/** - * @description : [描述说明该类的功能] - * @author : [Welsir] - * @createTime : [2023/5/21 19:45] - */ - -import org.example.exception.BaseException; -import org.example.exception.Impl.ResultCode; -import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RestController; - -/** - * @author welsir - * @date 2023/5/21 19:45 - */ -@RestController -public class ExceptionController { - - @GetMapping("test") - public void testLogin() throws BaseException { - throw new BaseException(); - } -} diff --git a/BarrageModule/src/main/java/org/example/core/listen/BarrageFileMonitor.java b/BarrageModule/src/main/java/org/example/core/listen/BarrageFileMonitor.java new file mode 100644 index 0000000..facf108 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/core/listen/BarrageFileMonitor.java @@ -0,0 +1,148 @@ +package org.example.core.listen; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import org.apache.commons.io.FileUtils; +import org.example.config.BarrageFileConfig; +import org.example.constpool.BarrageModuleConstPool; +import org.example.plugin.GuardPlugin; +import org.example.pojo.Anchor; +import org.example.pojo.Barrage; +import org.example.thread.ChopperBotGuardianTask; +import org.example.util.FileUtil; +import org.example.util.JsonFileUtil; +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.util.ResourceUtils; + +import java.io.*; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; + +/** + * @Description heartbeat event + * @Author welsir + * @Date 2023/8/1 12:44 + */ +public class BarrageFileMonitor extends GuardPlugin { + + private static final Logger logger = LoggerFactory.getLogger(BarrageFileMonitor.class); + + + private static BlockingQueue listenChangeEvent; + + private File rootFile; + + private static Map> anchorMap; + public BarrageFileMonitor(String module, String pluginName, List needPlugins, boolean isAutoStart) { + super(module, pluginName, needPlugins, isAutoStart); + } + + @Override + public boolean init() { + logger.info("BarrageModule init.."); + rootFile = new File(BarrageModuleConstPool.BARRAGE_FILE_PATH); + listenChangeEvent = new ArrayBlockingQueue<>(1024); + anchorMap = new HashMap<>(); + //Read the host configuration file and save it in the map + //Process streamer configuration files + processAnchorConfig(); + return super.init(); + } + @Override + public void start() { + try { + //file type --config + // --barrage + // --anchorA + // --fileA + // --fileB + // --anchorB + // --fileA + // --fileB + if("creepSuccess".equals(listenChangeEvent.poll(5, TimeUnit.SECONDS))){ + //get barrage file + Map map = BarrageFileConfig.getBarrageFile(); + File[] files = rootFile.listFiles(); + for (File anchorFile : files) { + if (anchorFile.isDirectory()&&anchorFile.length()>0) { + for (File barrageFile : Objects.requireNonNull(anchorFile.listFiles())) { + Object obj = map.get(anchorFile.getName() + "-" + barrageFile.getName()); + //If the map key cannot be obtained,then write to map + if (obj == null) { + try { + String fileJson = Files.readString(barrageFile.toPath()); + JSONObject jsonObject = JSON.parseObject(fileJson); + JSONArray data = jsonObject.getJSONArray("data"); + map.put(anchorFile.getName() + "-" + barrageFile.getName(), Barrage.copyProperty(data)); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + } + } + //update map + BarrageFileConfig.setMap(map); + } + } + if("updateAnchor".equals(listenChangeEvent.poll(5,TimeUnit.SECONDS))){ + processAnchorConfig(); + } + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + } + + public static void sendHotEvent(String msg){ + listenChangeEvent.offer(msg); + } + + //Obtain the barrage keyword score corresponding to the anchor + private static void processAnchorConfig(){ + anchorMap = new HashMap<>(); + File anchorFile; + anchorFile = new File(BarrageModuleConstPool.ANCHOR_FILE_PATH); + File[] anchors = anchorFile.listFiles(); + if (anchors != null) { + for (File anchor : anchors) { + List anchorConfig = JsonFileUtil.readJsonFileToArray(anchor.getAbsolutePath(), Anchor.class); + anchorMap.put(anchor.getName(), anchorConfig.get(0).getProperty()); + } + } + } + + private static String JSONFileToString(String filePath){ + String fileString = ""; + try (InputStream inputStream = FileUtil.class.getResourceAsStream(filePath); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { + String line; + while ((line = reader.readLine()) != null) { + fileString += line; + } + } catch (IOException e) { + e.printStackTrace(); + } + return fileString; + } + + public static Map getAnchorBarrageMap(){ + return anchorMap; + } + public static void main(String[] args) throws InterruptedException { + while (true){ + processAnchorConfig(); + Thread.sleep(5000); + } + } + +} diff --git a/BarrageModule/src/main/java/org/example/core/process/BarrageProcessor.java b/BarrageModule/src/main/java/org/example/core/process/BarrageProcessor.java new file mode 100644 index 0000000..906c71c --- /dev/null +++ b/BarrageModule/src/main/java/org/example/core/process/BarrageProcessor.java @@ -0,0 +1,10 @@ +package org.example.core.process; + +/** + * @Description + * @Author welsir + * @Date 2023/8/2 1:25 + */ +public class BarrageProcessor { + +} diff --git a/BarrageModule/src/main/java/org/example/core/update/UpdateBarrageScore.java b/BarrageModule/src/main/java/org/example/core/update/UpdateBarrageScore.java new file mode 100644 index 0000000..1737f44 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/core/update/UpdateBarrageScore.java @@ -0,0 +1,56 @@ +package org.example.core.update; + +import org.example.constpool.BarrageModuleConstPool; +import org.example.core.listen.BarrageFileMonitor; +import org.example.pojo.Anchor; +import org.example.util.JsonFileUtil; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * @Description + * @Author welsir + * @Date 2023/8/2 23:57 + */ +public class UpdateBarrageScore { + + //Batch Edit + public static void updateBarrageScore(List anchorList){ + + for (Anchor oneAnchor : anchorList) { + File anchorFiles = new File(BarrageModuleConstPool.ANCHOR_FILE_PATH); + String fileName = oneAnchor.getPlathForm()+"-"+oneAnchor.getRoomId(); + for(File anchorFile : Objects.requireNonNull(anchorFiles.listFiles())){ + //Whether to add + if(fileName.equals(anchorFile.getName())){ + Map anchorBarrageMap = BarrageFileMonitor.getAnchorBarrageMap(); + List originList = (List) anchorBarrageMap.get(fileName); + List newList = oneAnchor.getProperty(); + newList = Stream.concat(originList.stream(),oneAnchor.getProperty().stream()) + .distinct().collect(Collectors.toList()); + JsonFileUtil.writeJsonFileIsExist(BarrageModuleConstPool.ANCHOR_FILE_PATH+fileName+BarrageModuleConstPool.AnchorFileType,oneAnchor); + break; + } + } + JsonFileUtil.writeJsonFile(BarrageModuleConstPool.ANCHOR_FILE_PATH,fileName+BarrageModuleConstPool.AnchorFileType,oneAnchor); + } +// BarrageFileMonitor.sendHotEvent("updateAnchor"); + } + public static void main(String[] args) { + Anchor anchor = new Anchor(); + anchor.setNickName("姿态"); + anchor.setPlathForm("虎牙"); + anchor.setRoomId("123456"); + ArrayList arrayList = new ArrayList<>(); + Anchor.property property = new Anchor.property("hahaha",10); + arrayList.add(property); + anchor.setProperty(arrayList); + updateBarrageScore(List.of(anchor)); + } +} diff --git a/BarrageModule/src/main/java/org/example/entity/test.java b/BarrageModule/src/main/java/org/example/entity/test.java deleted file mode 100644 index af55fb7..0000000 --- a/BarrageModule/src/main/java/org/example/entity/test.java +++ /dev/null @@ -1,13 +0,0 @@ -package org.example.entity;/** - * @description : [描述说明该类的功能] - * @author : [Welsir] - * @createTime : [2023/5/16 17:06] - */ - -/** - * @author welsir - * @date 2023/5/16 17:06 - */ -public class test { - -} diff --git a/BarrageModule/src/main/java/org/example/init/BarrageFileListenInitMachine.java b/BarrageModule/src/main/java/org/example/init/BarrageFileListenInitMachine.java new file mode 100644 index 0000000..5aa7ed1 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/init/BarrageFileListenInitMachine.java @@ -0,0 +1,26 @@ +package org.example.init; + +import org.example.constpool.ModuleName; +import org.example.constpool.PluginName; +import org.example.core.listen.BarrageFileMonitor; +import org.example.init.CommonInitMachine; +import org.example.plugin.CommonPlugin; +import org.example.plugin.annotation.Plugin; + +import java.util.List; + +/** + * @Description + * @Author welsir + * @Date 2023/8/3 0:35 + */ + +@Plugin(moduleName = ModuleName.BARRAGE, + pluginName = PluginName.BARRAGE_FILE_PLUGIN, + needPlugin = {PluginName.CREEPER_CONFIG_PLUGIN,PluginName.TASK_CENTER_PLUGIN}, + pluginClass= BarrageFileMonitor.class) +public class BarrageFileListenInitMachine extends CommonInitMachine { + public BarrageFileListenInitMachine(List needPlugins, boolean isAutoStart, String moduleName, String name, Class clazz) { + super(needPlugins, isAutoStart, moduleName, name, clazz); + } +} diff --git a/BarrageModule/src/main/java/org/example/init/module/BarrageModuleInitMachine.java b/BarrageModule/src/main/java/org/example/init/module/BarrageModuleInitMachine.java new file mode 100644 index 0000000..cf20d9f --- /dev/null +++ b/BarrageModule/src/main/java/org/example/init/module/BarrageModuleInitMachine.java @@ -0,0 +1,24 @@ +package org.example.init.module; + +import org.example.constpool.ConstPool; +import org.example.init.ModuleInitMachine; +import org.example.log.ChopperLogFactory; +import org.slf4j.Logger; + +import java.util.List; + +/** + *

用于初始化弹幕模块所需

+ * + * @author welsir + * @date 2023/7/31 10:11 + */ + +public class BarrageModuleInitMachine extends ModuleInitMachine { + + public BarrageModuleInitMachine() { + super(List.of(ConstPool.CREEPER), + ChopperLogFactory.getLogger("BarrageModule"), + "Barrage"); + } +} diff --git a/BarrageModule/src/main/java/org/example/entity/Anchor.java b/BarrageModule/src/main/java/org/example/pojo/Anchor.java similarity index 64% rename from BarrageModule/src/main/java/org/example/entity/Anchor.java rename to BarrageModule/src/main/java/org/example/pojo/Anchor.java index 194b249..3057712 100644 --- a/BarrageModule/src/main/java/org/example/entity/Anchor.java +++ b/BarrageModule/src/main/java/org/example/pojo/Anchor.java @@ -1,4 +1,4 @@ -package org.example.entity; +package org.example.pojo; /** * @description : [配置文件实体类] * @author : [Welsir] @@ -6,30 +6,15 @@ package org.example.entity; */ import java.util.List; - -/** - * @author welsir - * @date 2023/5/15 22:51 - */ public class Anchor { - private String name; - public List getProperty() { - return property; - } + private String plathForm; - public void setProperty(List property) { - this.property = property; - } + private String roomId; + + private String nickName; private List property; - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } public static class property{ int weight; @@ -63,8 +48,40 @@ public class Anchor { } } + public String getNickName() { + return nickName; + } + + public void setNickName(String nickName) { + this.nickName = nickName; + } + + public void setProperty(List property) { + this.property = property; + } + + public List getProperty() { + return property; + } + + public String getPlathForm() { + return plathForm; + } + + public void setPlathForm(String plathForm) { + this.plathForm = plathForm; + } + + public String getRoomId() { + return roomId; + } + + public void setRoomId(String roomId) { + this.roomId = roomId; + } + @Override public String toString() { - return "{name:"+getName()+",property:"+getProperty()+"}"; + return "{name:"+getNickName()+",property:"+getProperty()+"}"; } } diff --git a/BarrageModule/src/main/java/org/example/entity/Barrage.java b/BarrageModule/src/main/java/org/example/pojo/Barrage.java similarity index 90% rename from BarrageModule/src/main/java/org/example/entity/Barrage.java rename to BarrageModule/src/main/java/org/example/pojo/Barrage.java index 355c783..58a0897 100644 --- a/BarrageModule/src/main/java/org/example/entity/Barrage.java +++ b/BarrageModule/src/main/java/org/example/pojo/Barrage.java @@ -1,11 +1,9 @@ -package org.example.entity; +package org.example.pojo; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import lombok.Data; -import netscape.javascript.JSObject; -import java.util.ArrayList; import java.util.List; /** diff --git a/BarrageModule/src/main/java/org/example/pojo/BarrageScore.java b/BarrageModule/src/main/java/org/example/pojo/BarrageScore.java new file mode 100644 index 0000000..c613cc2 --- /dev/null +++ b/BarrageModule/src/main/java/org/example/pojo/BarrageScore.java @@ -0,0 +1,44 @@ +package org.example.pojo; + +/** + * @Description Barrage scoring entity class + * @Author Welsir + * @Date 2023/5/29 20:20 + */ +public class BarrageScore { + + private int scoreValue; + private int contentValue; + private String content; + + public BarrageScore(){ + + } + public BarrageScore(int score){ + this.scoreValue = score; + } + + public int getScoreValue() { + return scoreValue; + } + + public void setScoreValue(int scoreValue) { + this.scoreValue = scoreValue; + } + + public int getContentValue() { + return contentValue; + } + + public void setContentValue(int contentValue) { + this.contentValue = contentValue; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } +} diff --git a/BarrageModule/src/main/java/org/example/score/BarrageScore.java b/BarrageModule/src/main/java/org/example/score/BarrageScore.java index e4e92a8..4122b39 100644 --- a/BarrageModule/src/main/java/org/example/score/BarrageScore.java +++ b/BarrageModule/src/main/java/org/example/score/BarrageScore.java @@ -8,8 +8,8 @@ package org.example.score; import com.alibaba.fastjson.JSON; import org.example.config.BarrageFileConfig; import org.example.config.BarrageScoreConfig; -import org.example.entity.Anchor; -import org.example.entity.Barrage; +import org.example.pojo.Anchor; +import org.example.pojo.Barrage; import org.example.util.FileUtil; import java.util.*; @@ -28,28 +28,28 @@ public class BarrageScore { * @Param [filePath(相对或全路径均可), anchorName(主播名称)] * @return void **/ - public static void analysisBarrageScore(String filePath,String anchorName){ - //parse score file to get weight - String result = FileUtil.JSONFileToString("/anchor/score.json"); - List objects = JSON.parseArray(result,Anchor.class); - anchorPropertMap = objects.stream().collect(Collectors.toMap(Anchor::getName, Anchor::getProperty, (existing, replacement) -> existing)); - //call the barrageScoreConfig to get barrage file - HashMap map = BarrageFileConfig.getBarrageFile(); - System.out.println("map size::"+map.size()); - //Traverse the map set to sort timeIdx - map.forEach((k,v)->{ - System.out.println(k); - String anchor = splitFileName((String) k); - ((List) v).sort(new BarrageComparator()); - List anchorScoreList = BarrageScoreConfig.getAnchorScoreList(); - for (Anchor anchor1 : anchorScoreList) { - if (anchor1.getName().equals(anchor)) { - - } - } - }); - System.out.println(anchorPropertMap); - } +// public static void analysisBarrageScore(String filePath,String anchorName){ +// //parse score file to get weight +//// String result = FileUtil.JSONFileToString("/anchor/score.json"); +// List objects = JSON.parseArray(result,Anchor.class); +// anchorPropertMap = objects.stream().collect(Collectors.toMap(Anchor::getName, Anchor::getProperty, (existing, replacement) -> existing)); +// //call the barrageScoreConfig to get barrage file +// HashMap map = BarrageFileConfig.getBarrageFile(); +// System.out.println("map size::"+map.size()); +// //Traverse the map set to sort timeIdx +// map.forEach((k,v)->{ +// System.out.println(k); +// String anchor = splitFileName((String) k); +// ((List) v).sort(new BarrageComparator()); +// List anchorScoreList = BarrageScoreConfig.getAnchorScoreList(); +// for (Anchor anchor1 : anchorScoreList) { +// if (anchor1.getName().equals(anchor)) { +// +// } +// } +// }); +// System.out.println(anchorPropertMap); +// } private static String splitFileName(String fileName){ int index = fileName.indexOf("-"); @@ -69,8 +69,8 @@ public class BarrageScore { return b1.getTimeIndex().compareTo(b2.getTimeIndex()); } } - + public static void main(String[] args) { - analysisBarrageScore("D:\\idea_Project\\Springboot\\ChopperBot\\BarrageModule\\src\\main\\resources\\anchor\\score.json",""); +// analysisBarrageScore("D:\\idea_Project\\Springboot\\ChopperBot\\BarrageModule\\src\\main\\resources\\anchor\\score.json",""); } } diff --git a/BarrageModule/src/main/java/org/example/util/FileUtil.java b/BarrageModule/src/main/java/org/example/util/FileUtil.java deleted file mode 100644 index b91033e..0000000 --- a/BarrageModule/src/main/java/org/example/util/FileUtil.java +++ /dev/null @@ -1,34 +0,0 @@ -package org.example.util; -/** - * @description : [fileUtils] - * @author : [Welsir] - * @createTime : [2023/5/18 18:14] - */ - -import org.example.config.BarrageScoreConfig; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; - -/** - * @author welsir - * @date 2023/5/18 18:14 - */ -public class FileUtil { - - public static String JSONFileToString(String filePath){ - String fileString = ""; - try (InputStream inputStream = FileUtil.class.getResourceAsStream(filePath); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { - String line; - while ((line = reader.readLine()) != null) { - fileString += line; - } - } catch (IOException e) { - e.printStackTrace(); - } - return fileString; - } -} diff --git a/BarrageModule/src/main/resources/anchor/score.json b/BarrageModule/src/main/resources/anchor/score.json deleted file mode 100644 index 58d36f7..0000000 --- a/BarrageModule/src/main/resources/anchor/score.json +++ /dev/null @@ -1,53 +0,0 @@ -[ - { - "name":"大司马", - "property":[ - { - "content":"哈哈哈", - "weight":10 - }, - { - "content":"素材", - "weight":10 - }, - { - "content":"gg", - "weight":10 - }, - { - "content":"???", - "weight":10 - } - ] - }, - { - "name":"水晶哥", - "property":[ - { - "content":"陌生", - "weight":10 - }, - { - "content":"没道理", - "weight":10 - }, - { - "content":"666", - "weight":5 - } - ] - }, - { - "name":"小团团", - "property":[ - { - "content":"666", - "weight":5 - }, - { - "content":"下播", - "weight":7 - } - ] - } -] \ No newline at end of file diff --git a/FileModule/src/main/java/org/example/util/JsonFileUtil.java b/FileModule/src/main/java/org/example/util/JsonFileUtil.java index 59f63cf..530da2c 100644 --- a/FileModule/src/main/java/org/example/util/JsonFileUtil.java +++ b/FileModule/src/main/java/org/example/util/JsonFileUtil.java @@ -83,6 +83,27 @@ public class JsonFileUtil { return t; } + /** 读取json文件转为数组 + * @param fullPath 文件路径,包含文件名 + * @param clazz 类 + * @return List + */ + public static List readJsonFileToArray(String fullPath, Class clazz){ + List t = null; + Path dir = Paths.get(fullPath); + try{ + if (FileUtil.isFileExist(dir.toString())) { + String res = Files.readString(dir, StandardCharsets.UTF_8); +// logger.debug("读取json文件成功, 文件内容为: {}", res); + + t = JSON.parseArray(res, clazz); + } + }catch (Exception e){ + logger.error("读取json文件失败", e); + } + return t; + } + /* ------------------write json file------------------ */ /** diff --git a/HotModule/src/main/java/org/example/core/guard/Guard.java b/HotModule/src/main/java/org/example/core/guard/Guard.java index 20d3ceb..58532ea 100644 --- a/HotModule/src/main/java/org/example/core/guard/Guard.java +++ b/HotModule/src/main/java/org/example/core/guard/Guard.java @@ -8,10 +8,8 @@ import org.example.constpool.PluginName; import org.example.core.HotModuleDataCenter; import org.example.core.control.HotModuleLoadTask; import org.example.core.recommend.HeatRecommendation; -import org.example.init.HeatRecommendationInitMachine; import org.example.init.InitPluginRegister; import org.example.log.ResultLogger; -import org.example.plugin.CommonPlugin; import org.slf4j.Logger; import java.util.List; diff --git a/HotModule/src/main/java/org/example/init/HeatRecommendationInitMachine.java b/HotModule/src/main/java/org/example/init/HeatRecommendationInitMachine.java index d114a30..e65fb53 100644 --- a/HotModule/src/main/java/org/example/init/HeatRecommendationInitMachine.java +++ b/HotModule/src/main/java/org/example/init/HeatRecommendationInitMachine.java @@ -20,10 +20,8 @@ import java.util.List; pluginClass= HeatRecommendation.class ) public class HeatRecommendationInitMachine extends CommonInitMachine{ - public HeatRecommendationInitMachine(List needPlugins, boolean isAutoStart, String moduleName, String name, Class clazz) { super(needPlugins, isAutoStart, moduleName, name, clazz); } - } diff --git a/HotModule/src/main/java/org/example/init/module/HotModuleInitMachine.java b/HotModule/src/main/java/org/example/init/module/HotModuleInitMachine.java index 6efc85d..9a982b4 100644 --- a/HotModule/src/main/java/org/example/init/module/HotModuleInitMachine.java +++ b/HotModule/src/main/java/org/example/init/module/HotModuleInitMachine.java @@ -2,9 +2,6 @@ package org.example.init.module; import org.example.constpool.ConstPool; import org.example.constpool.ModuleName; -import org.example.init.HeatRecommendationInitMachine; -import org.example.init.HotConfigInitMachine; -import org.example.init.HotGuardInitMachine; import org.example.init.ModuleInitMachine; import org.example.log.ChopperLogFactory; import org.example.log.LoggerType; diff --git a/common/src/main/java/org/example/constpool/ModuleName.java b/common/src/main/java/org/example/constpool/ModuleName.java index 6ac6a73..fac9dd2 100644 --- a/common/src/main/java/org/example/constpool/ModuleName.java +++ b/common/src/main/java/org/example/constpool/ModuleName.java @@ -13,4 +13,6 @@ public class ModuleName { public static final String CREEPER = ConstPool.CREEPER; public static final String FILE = ConstPool.FILE; + + public static final String BARRAGE = ConstPool.BARRAGE; } diff --git a/common/src/main/java/org/example/constpool/PluginName.java b/common/src/main/java/org/example/constpool/PluginName.java index a795f2b..b71b7f9 100644 --- a/common/src/main/java/org/example/constpool/PluginName.java +++ b/common/src/main/java/org/example/constpool/PluginName.java @@ -22,4 +22,7 @@ public class PluginName { public static final String HOT_CONFIG_PLUGIN = "HotConfig"; public static final String HOT_GUARD_PLUGIN = "HotGuard"; public static final String HOT_RECOMMENDATION_PLUGIN = "HotRecommendation"; + + //Barrage + public static final String BARRAGE_FILE_PLUGIN="BarrageFileListen"; } diff --git a/common/src/main/java/org/example/log/LoggerType.java b/common/src/main/java/org/example/log/LoggerType.java index b2f4551..ec563cd 100644 --- a/common/src/main/java/org/example/log/LoggerType.java +++ b/common/src/main/java/org/example/log/LoggerType.java @@ -8,7 +8,8 @@ public enum LoggerType { System("ChopperBot🤖"), Creeper("Creeper "), File("FileModule "), - Hot("HotModule "); + Hot("HotModule "), + Barrage("Barrage "); private String loggerName; LoggerType(String name){