From c326e2269905d17e5d27e7a9007d40b82bbb2a7f Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 8 May 2021 22:18:25 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E8=8E=B7=E5=8F=96idea?= =?UTF-8?q?=E6=BF=80=E6=B4=BB=E7=A0=81=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/nas/NasApplication.java | 2 +- .../java/com/yutou/nas/utils/IdeaTools.java | 53 +++++++++++++++++++ .../com/yutou/nas/utils/QQBotManager.java | 14 ++++- .../java/com/yutou/nas/utils/StreamTools.java | 22 ++++++++ 4 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/yutou/nas/utils/IdeaTools.java create mode 100644 src/main/java/com/yutou/nas/utils/StreamTools.java diff --git a/src/main/java/com/yutou/nas/NasApplication.java b/src/main/java/com/yutou/nas/NasApplication.java index 35502a6..cfc1865 100644 --- a/src/main/java/com/yutou/nas/NasApplication.java +++ b/src/main/java/com/yutou/nas/NasApplication.java @@ -12,7 +12,7 @@ import org.springframework.context.annotation.Import; @Import(BTDownloadManager.class) @SpringBootApplication public class NasApplication { - public static final String version="1.0.0"; + public static final String version="1.1.0"; public static void main(String[] args) { SpringApplication.run(NasApplication.class, args); AppData.defaultMusicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir"); diff --git a/src/main/java/com/yutou/nas/utils/IdeaTools.java b/src/main/java/com/yutou/nas/utils/IdeaTools.java new file mode 100644 index 0000000..18d2386 --- /dev/null +++ b/src/main/java/com/yutou/nas/utils/IdeaTools.java @@ -0,0 +1,53 @@ +package com.yutou.nas.utils; + +import org.springframework.util.StringUtils; + +import java.io.File; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +public class IdeaTools { + public static String getIdea(String name) { + if(StringUtils.isEmpty(name)){ + return ""; + } + File file = new File("tmp" + File.separator + "idea.zip"); + try { + ZipFile zipFile = new ZipFile(file, Charset.forName("gbk")); + String data = ""; + if (file.exists()) { + data = StreamTools.streamReadLine(zipFile.getInputStream(zipFile.getEntry(name))); + } + zipFile.close(); + return data; + } catch (IOException e) { + e.printStackTrace(); + } + return ""; + } + + public static List getIdeaList() { + File file = HttpTools.syncDownload("http://idea.medeming.com/a/jihuoma.zip", "idea.zip"); + List list = new ArrayList<>(); + try { + ZipFile zip = new ZipFile(file, Charset.forName("gbk")); + Enumeration ez = zip.entries(); + while (ez.hasMoreElements()) { + ZipEntry entry = ez.nextElement(); + if (entry.getName().endsWith(".txt")) { + list.add(entry.getName()); + } + } + zip.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + return list; + } +} diff --git a/src/main/java/com/yutou/nas/utils/QQBotManager.java b/src/main/java/com/yutou/nas/utils/QQBotManager.java index 0053c77..38f067c 100644 --- a/src/main/java/com/yutou/nas/utils/QQBotManager.java +++ b/src/main/java/com/yutou/nas/utils/QQBotManager.java @@ -43,6 +43,8 @@ public class QQBotManager { private final static String QQ_AUDIO_OPEN_LAMP = "!开灯"; private final static String QQ_AUDIO_OPEN_AIR = "!开空调"; private final static String QQ_BT_RELOAD = "!刷BT"; + private final static String QQ_TOOLS_IDEA = "!idea"; + private final static String QQ_TOOLS_IDEA_FILE = "!idea>"; } private static QQBotManager botManager = null; @@ -223,6 +225,7 @@ public class QQBotManager { } private void myGroup(String msg) { + StringBuilder builder; msg = msg.replace("!", "!").toLowerCase(); switch (msg) { case QQCommands.QQ_OPEN_PC: @@ -262,7 +265,7 @@ public class QQBotManager { System.exit(0); break; case QQCommands.QQ_HELP: - StringBuilder builder = new StringBuilder(); + builder = new StringBuilder(); for (Field field : QQCommands.class.getDeclaredFields()) { try { field.setAccessible(true); @@ -273,6 +276,13 @@ public class QQBotManager { } getInstance().sendMessage(builder.toString()); break; + case QQCommands.QQ_TOOLS_IDEA: + builder = new StringBuilder(); + for (String name : IdeaTools.getIdeaList()) { + builder.append(QQCommands.QQ_TOOLS_IDEA_FILE).append(name).append("\n"); + } + getInstance().sendMessage(builder.toString()); + break; default: if (msg.startsWith(QQCommands.QQ_CMD)) { RedisTools.Consumer.system("cmd", msg.replace(QQCommands.QQ_CMD, "")); @@ -298,6 +308,8 @@ public class QQBotManager { } else if (msg.startsWith(QQCommands.QQ_AUDIO)) { QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, "")); + }else if(msg.startsWith(QQCommands.QQ_TOOLS_IDEA_FILE)){ + getInstance().sendMessage(IdeaTools.getIdea(msg.replace(QQCommands.QQ_TOOLS_IDEA_FILE,""))); } } } diff --git a/src/main/java/com/yutou/nas/utils/StreamTools.java b/src/main/java/com/yutou/nas/utils/StreamTools.java new file mode 100644 index 0000000..bba8478 --- /dev/null +++ b/src/main/java/com/yutou/nas/utils/StreamTools.java @@ -0,0 +1,22 @@ +package com.yutou.nas.utils; + +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class StreamTools { + public static String streamReadLine(InputStream stream) { + StringBuilder builder = new StringBuilder(); + try { + BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); + String tmp; + while ((tmp = reader.readLine()) != null) { + builder.append(tmp); + } + reader.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return builder.toString(); + } +}