diff --git a/src/main/java/com/yutou/nas/bangumi/BangumiTools.java b/src/main/java/com/yutou/nas/bangumi/BangumiTools.java index 10f7f41..51ffa13 100644 --- a/src/main/java/com/yutou/nas/bangumi/BangumiTools.java +++ b/src/main/java/com/yutou/nas/bangumi/BangumiTools.java @@ -104,10 +104,12 @@ public class BangumiTools { * @param id 番剧id * @return 详细内容 */ - public static String reportBangumiInfo(int id) { + public static List reportBangumiInfo(int id) { + List bangumiList=new ArrayList<>(); JSONObject json = getBangumiInfo(id); if(json.containsKey("code")){ - return json.getString("error"); + bangumiList.add("error = "+json.toJSONString()); + return bangumiList; } JSONArray eps = json.getJSONArray("eps"); JSONArray crts = json.getJSONArray("crt"); @@ -181,7 +183,8 @@ public class BangumiTools { builder.append("\n"); } } - return builder.toString(); + bangumiList.add(builder.toString()); + return bangumiList; } /** @@ -275,7 +278,8 @@ public class BangumiTools { * @param key 关键词 * @return 详细内容 */ - public static String reportSearchBangumi(String key) { + public static List reportSearchBangumi(String key) { + List bangumiList=new ArrayList<>(); JSONObject main = search(key); if (main.getInteger("results") > 0) { StringBuilder builder = new StringBuilder(); @@ -283,6 +287,7 @@ public class BangumiTools { Collections.reverse(list); for (Object items : list) { JSONObject item = (JSONObject) items; + builder=new StringBuilder(); builder.append("标题:").append(item.getString("name_cn")).append("\n"); builder.append("日文标题:").append(item.getString("name")).append("\n"); String type; @@ -315,10 +320,12 @@ public class BangumiTools { builder.append("Bangumi地址:").append(item.getString("url")).append("\n"); builder.append("介绍:").append(item.getString("summary")).append("\n"); builder.append("\n").append("\n"); + bangumiList.add(builder.toString()); } - return builder.toString(); + return bangumiList; } else { - return "搜索不到任何内容:" + key; + bangumiList.add("搜索不到任何内容:" + key); + return bangumiList; } } diff --git a/src/main/java/com/yutou/nas/utils/QQBotManager.java b/src/main/java/com/yutou/nas/utils/QQBotManager.java index 069cd02..ee160f6 100644 --- a/src/main/java/com/yutou/nas/utils/QQBotManager.java +++ b/src/main/java/com/yutou/nas/utils/QQBotManager.java @@ -272,22 +272,25 @@ public class QQBotManager { if (msg.startsWith(QQCommands.QQ_CMD)) { RedisTools.Consumer.system("cmd", msg.replace(QQCommands.QQ_CMD, "")); } else if (msg.startsWith(QQCommands.QQ_BANGUMI_SUB)) { - String info = null; + List infos = null; try { int id = Integer.parseInt(msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim()); - info = BangumiTools.reportBangumiInfo(id); + infos = BangumiTools.reportBangumiInfo(id); } catch (Exception e) { String key = msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim(); - info = BangumiTools.reportSearchBangumi(key); + infos = BangumiTools.reportSearchBangumi(key); } - List imgs = new ArrayList<>(); - if (info.contains("")) { - imgs = getImages(info); - for (String img : imgs) { - info = info.replace("", ""); + for (String info : infos) { + List imgs = new ArrayList<>(); + if (info.contains("")) { + imgs = getImages(info); + for (String img : imgs) { + info = info.replace("", ""); + } } + sendImagesMsg(imgs, info); } - sendImagesMsg(imgs, info); + } else if (msg.startsWith(QQCommands.QQ_AUDIO)) { QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, "")); }