From f575d0f287acd078aa259648cb1266ebd578784b Mon Sep 17 00:00:00 2001 From: yutou Date: Wed, 2 Dec 2020 11:53:13 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=9C=BA=E5=99=A8=E4=BA=BA?= =?UTF-8?q?=E7=89=88=E6=9C=AC1.3.1=20=E2=86=92=201.3.3=20=E6=9B=B4?= =?UTF-8?q?=E6=96=B0=E9=9F=B3=E4=B9=90=E6=94=B6=E8=97=8F=E5=A4=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=20=E5=B7=A5=E5=85=B7=E7=B1=BB=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=B8=AA=E6=89=93=E5=8D=B0=E5=BC=82=E5=B8=B8=E7=9A=84=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../com/yutou/tools/ToolsApplication.java | 2 +- .../home/nas/MusicFavoritesController.java | 34 +++++++++++ .../com/yutou/tools/utils/MusicTools.java | 9 +-- .../com/yutou/tools/utils/QQBotManager.java | 58 ++++++++++++------- .../java/com/yutou/tools/utils/Tools.java | 12 ++++ 6 files changed, 89 insertions(+), 28 deletions(-) diff --git a/pom.xml b/pom.xml index b699b9b..4eebca0 100644 --- a/pom.xml +++ b/pom.xml @@ -109,7 +109,7 @@ net.mamoe mirai-core-qqandroid - 1.3.1 + 1.3.3 org.jetbrains.kotlin diff --git a/src/main/java/com/yutou/tools/ToolsApplication.java b/src/main/java/com/yutou/tools/ToolsApplication.java index d5e728c..800ded5 100644 --- a/src/main/java/com/yutou/tools/ToolsApplication.java +++ b/src/main/java/com/yutou/tools/ToolsApplication.java @@ -9,7 +9,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class ToolsApplication { - public static final String version="1.0.11"; + public static final String version="1.0.12"; public static void main(String[] args) { System.out.println("当前版本号:"+version); diff --git a/src/main/java/com/yutou/tools/home/nas/MusicFavoritesController.java b/src/main/java/com/yutou/tools/home/nas/MusicFavoritesController.java index 27aa331..235a603 100644 --- a/src/main/java/com/yutou/tools/home/nas/MusicFavoritesController.java +++ b/src/main/java/com/yutou/tools/home/nas/MusicFavoritesController.java @@ -13,6 +13,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import javax.annotation.Resource; +import java.util.Date; /** * 收藏夹相关 @@ -51,6 +52,8 @@ public class MusicFavoritesController{ json.put("data", JSONArray.toJSON(favoritesDirDao.selectByExample(new MusicFavoritesDirExample()))); return json.toJSONString(); } + @RequestMapping("dir/rename.do") + @ResponseBody public String renameFavoriteDir(String id,String title){ JSONObject json=new JSONObject(); MusicFavoritesDir favoritesDir=favoritesDirDao.selectByPrimaryKey(Integer.parseInt(id)); @@ -65,4 +68,35 @@ public class MusicFavoritesController{ } return json.toJSONString(); } + @RequestMapping("add.do") + @ResponseBody + public String addFavorite(int fid,String md5s){ + JSONObject json=new JSONObject(); + JSONArray array=JSONArray.parseArray(md5s); + if(array==null){ + json.put("code",-1); + json.put("msg","参数异常"); + return json.toJSONString(); + } + for (Object o : array) { + String md5= (String) o; + MusicFavorites favorites=new MusicFavorites(); + favorites.setMusisMd5(md5); + favorites.setFavoriteid(fid); + favorites.setSubTime(new Date()); + favoritesDao.insert(favorites); + } + json.put("code",0); + json.put("msg","添加成功"); + return json.toJSONString(); + } + @RequestMapping("remove.do") + @ResponseBody + public String removeFavorite(int fid){ + JSONObject json=new JSONObject(); + int ret=favoritesDao.deleteByPrimaryKey(fid); + json.put("code",ret==0?-1:0); + json.put("msg",ret==0?"移除失败":"已从收藏夹中移除"); + return json.toJSONString(); + } } diff --git a/src/main/java/com/yutou/tools/utils/MusicTools.java b/src/main/java/com/yutou/tools/utils/MusicTools.java index a6c68e4..53e5134 100644 --- a/src/main/java/com/yutou/tools/utils/MusicTools.java +++ b/src/main/java/com/yutou/tools/utils/MusicTools.java @@ -68,6 +68,9 @@ public class MusicTools implements MusicToolsService { if (isScan) { return; } + if(ConfigTools.load(ConfigTools.CONFIG,"musicScan").equals("false")){ + return; + } musicPath = (String) ConfigTools.load(ConfigTools.CONFIG, "musicDir"); musicDataDao.truncate(); System.out.println("执行扫描:" + musicPath); @@ -129,10 +132,8 @@ public class MusicTools implements MusicToolsService { } else { main = musicDataDao.selectByRegexp(path.replace(File.separator, replacement) + replacement + "([^" + replacement + "]+)$"); } - System.out.println(path + " " + isDir); - if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root") && main.size() > 0) { + if (!path.equals(MusicController.defaultMusicPath) && !path.equals("root")) { MusicData tmp = main.get(0); - System.out.println(tmp); MusicData t2 = new MusicData(); t2.setTitle("返回"); t2.setFile(new File(tmp.getLastdir()).getAbsolutePath()); @@ -141,7 +142,6 @@ public class MusicTools implements MusicToolsService { } getDirList(path, list); list.addAll(main); - System.out.println(list.size()); return list; } @@ -404,6 +404,7 @@ public class MusicTools implements MusicToolsService { data.setIsdir(file.isDirectory() ? 1 : 0); data.setLastdir(file.getParentFile().getParent()); data.setMd5(Tools.getFileMD5(file)); + QQBotManager.getInstance().sendMessage("添加音乐文件失败:\n"+data.toString()+"\n"+Tools.getExceptionString(e)); } return data; } diff --git a/src/main/java/com/yutou/tools/utils/QQBotManager.java b/src/main/java/com/yutou/tools/utils/QQBotManager.java index dfa1c67..232faa3 100644 --- a/src/main/java/com/yutou/tools/utils/QQBotManager.java +++ b/src/main/java/com/yutou/tools/utils/QQBotManager.java @@ -9,12 +9,12 @@ import net.mamoe.mirai.event.Events; import net.mamoe.mirai.event.ListeningStatus; import net.mamoe.mirai.event.SimpleListenerHost; import net.mamoe.mirai.message.GroupMessageEvent; +import net.mamoe.mirai.message.MessageEvent; import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.Image; import net.mamoe.mirai.message.data.MessageChain; import net.mamoe.mirai.message.data.MessageUtils; import net.mamoe.mirai.utils.BotConfiguration; -import net.mamoe.mirai.utils.MiraiLogger; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -23,13 +23,13 @@ public class QQBotManager { private static QQBotManager botManager = null; private Bot bot; private static final long qqGroup = 891655174L; - private boolean isLogin=false; + private boolean isLogin = false; private QQBotManager() { Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot"); if (isRun != null && (boolean) isRun) { init(); - isLogin=true; + isLogin = true; } } @@ -37,9 +37,9 @@ public class QQBotManager { new Thread(new Runnable() { @Override public void run() { - long qq=2476945931L; - String password="zhang34864394"; - if(ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) { + long qq = 2476945931L; + String password = "zhang34864394"; + if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("dev")) { qq = 3620756944L; password = "UAs6YBYMyxJU"; } @@ -47,7 +47,7 @@ public class QQBotManager { bot = BotFactoryJvm.newBot(qq, password, new BotConfiguration() { { fileBasedDeviceInfo("qq_bot_devices_info.json"); - if(ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) { + if (ConfigTools.load(ConfigTools.CONFIG, "model").equals("nas")) { noBotLog(); noNetworkLog(); } @@ -70,16 +70,23 @@ public class QQBotManager { } return botManager; } - public boolean isLogin(){ + + public boolean isLogin() { return isLogin; } - private String getNotLoginQQ(){ + + private String getNotLoginQQ() { return "没有登录QQ"; } + public String sendMessage(String text) { if (bot != null) { - MessageReceipt receipt= bot.getGroup(qqGroup).sendMessage(text); - return receipt.toString(); + try { + MessageReceipt receipt = bot.getGroup(qqGroup).sendMessage(text); + return receipt.toString(); + } catch (Exception e) { + e.printStackTrace(); + } } return getNotLoginQQ(); } @@ -88,7 +95,7 @@ public class QQBotManager { if (bot != null) { Image image = bot.getGroup(qqGroup).uploadImage(imageFile); MessageChain chain = MessageUtils.newImage(image.getImageId()).plus(text); - MessageReceipt receipt=bot.getGroup(qqGroup).sendMessage(chain); + MessageReceipt receipt = bot.getGroup(qqGroup).sendMessage(chain); return receipt.toString(); } return getNotLoginQQ(); @@ -102,31 +109,38 @@ public class QQBotManager { @Override public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) { super.handleException(context, exception); - System.out.println("error: "+exception.getLocalizedMessage()); + System.out.println("error: " + exception.getLocalizedMessage()); } @EventHandler public ListeningStatus onGroupMessage(GroupMessageEvent event) { - if(event.getGroup().getId()==qqGroup){ - String msg=event.getMessage().contentToString(); - msg=msg.replace("!","!"); - switch (msg){ + if (event.getGroup().getId() == qqGroup) { + String msg = event.getMessage().contentToString(); + msg = msg.replace("!", "!"); + switch (msg) { case "!开机": - RedisTools.Consumer.system("openPC",null); + RedisTools.Consumer.system("openPC", null); break; case "!更新IP": - RedisTools.Consumer.system("updateIP",null); + RedisTools.Consumer.system("updateIP", null); break; case "!ip": RedisTools.Consumer.bot("getip"); break; default: - if(msg.startsWith("!cmd")){ - RedisTools.Consumer.system("cmd",msg.replace("!cmd","")); + if (msg.startsWith("!cmd")) { + RedisTools.Consumer.system("cmd", msg.replace("!cmd", "")); } } - } + }/*else{ + sendMessage("群:"+event.getGroup().getId()+" 发来消息:\n"+event.getMessage().contentToString()); + }*/ return ListeningStatus.LISTENING; } + + @EventHandler + public void onMessage(@NotNull MessageEvent event) throws Exception { + // sendMessage("个人:"+event.getSender().getNick()+" 发来消息:"+event.getMessage().contentToString()); + } } } diff --git a/src/main/java/com/yutou/tools/utils/Tools.java b/src/main/java/com/yutou/tools/utils/Tools.java index b7c2fdb..88db304 100644 --- a/src/main/java/com/yutou/tools/utils/Tools.java +++ b/src/main/java/com/yutou/tools/utils/Tools.java @@ -376,4 +376,16 @@ public class Tools { base=base.replace(" ","+"); return new String(Base64.getDecoder().decode(base.replace("\r\n","").getBytes())); } + /** + * 异常输出 + * @param e 异常 + * @return + */ + public static String getExceptionString(Exception e) { + StringWriter writer=new StringWriter(); + PrintWriter printWriter=new PrintWriter(writer); + e.printStackTrace(printWriter); + printWriter.close(); + return writer.toString(); + } }