This commit is contained in:
yutou 2021-04-13 18:26:48 +08:00
parent ed692199be
commit 3bce5d7fd9
2 changed files with 25 additions and 15 deletions

View File

@ -104,10 +104,12 @@ public class BangumiTools {
* @param id 番剧id * @param id 番剧id
* @return 详细内容 * @return 详细内容
*/ */
public static String reportBangumiInfo(int id) { public static List<String> reportBangumiInfo(int id) {
List<String> bangumiList=new ArrayList<>();
JSONObject json = getBangumiInfo(id); JSONObject json = getBangumiInfo(id);
if(json.containsKey("code")){ if(json.containsKey("code")){
return json.getString("error"); bangumiList.add("error = "+json.toJSONString());
return bangumiList;
} }
JSONArray eps = json.getJSONArray("eps"); JSONArray eps = json.getJSONArray("eps");
JSONArray crts = json.getJSONArray("crt"); JSONArray crts = json.getJSONArray("crt");
@ -181,7 +183,8 @@ public class BangumiTools {
builder.append("\n"); builder.append("\n");
} }
} }
return builder.toString(); bangumiList.add(builder.toString());
return bangumiList;
} }
/** /**
@ -275,7 +278,8 @@ public class BangumiTools {
* @param key 关键词 * @param key 关键词
* @return 详细内容 * @return 详细内容
*/ */
public static String reportSearchBangumi(String key) { public static List<String> reportSearchBangumi(String key) {
List<String> bangumiList=new ArrayList<>();
JSONObject main = search(key); JSONObject main = search(key);
if (main.getInteger("results") > 0) { if (main.getInteger("results") > 0) {
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
@ -283,6 +287,7 @@ public class BangumiTools {
Collections.reverse(list); Collections.reverse(list);
for (Object items : list) { for (Object items : list) {
JSONObject item = (JSONObject) items; JSONObject item = (JSONObject) items;
builder=new StringBuilder();
builder.append("标题:").append(item.getString("name_cn")).append("\n"); builder.append("标题:").append(item.getString("name_cn")).append("\n");
builder.append("日文标题:").append(item.getString("name")).append("\n"); builder.append("日文标题:").append(item.getString("name")).append("\n");
String type; String type;
@ -315,10 +320,12 @@ public class BangumiTools {
builder.append("Bangumi地址:").append(item.getString("url")).append("\n"); builder.append("Bangumi地址:").append(item.getString("url")).append("\n");
builder.append("介绍:").append(item.getString("summary")).append("\n"); builder.append("介绍:").append(item.getString("summary")).append("\n");
builder.append("\n").append("\n"); builder.append("\n").append("\n");
bangumiList.add(builder.toString());
} }
return builder.toString(); return bangumiList;
} else { } else {
return "搜索不到任何内容:" + key; bangumiList.add("搜索不到任何内容:" + key);
return bangumiList;
} }
} }

View File

@ -272,14 +272,15 @@ public class QQBotManager {
if (msg.startsWith(QQCommands.QQ_CMD)) { if (msg.startsWith(QQCommands.QQ_CMD)) {
RedisTools.Consumer.system("cmd", msg.replace(QQCommands.QQ_CMD, "")); RedisTools.Consumer.system("cmd", msg.replace(QQCommands.QQ_CMD, ""));
} else if (msg.startsWith(QQCommands.QQ_BANGUMI_SUB)) { } else if (msg.startsWith(QQCommands.QQ_BANGUMI_SUB)) {
String info = null; List<String> infos = null;
try { try {
int id = Integer.parseInt(msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim()); int id = Integer.parseInt(msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim());
info = BangumiTools.reportBangumiInfo(id); infos = BangumiTools.reportBangumiInfo(id);
} catch (Exception e) { } catch (Exception e) {
String key = msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim(); String key = msg.replace(QQCommands.QQ_BANGUMI_SUB, "").trim();
info = BangumiTools.reportSearchBangumi(key); infos = BangumiTools.reportSearchBangumi(key);
} }
for (String info : infos) {
List<String> imgs = new ArrayList<>(); List<String> imgs = new ArrayList<>();
if (info.contains("<img") && info.contains(" /img>")) { if (info.contains("<img") && info.contains(" /img>")) {
imgs = getImages(info); imgs = getImages(info);
@ -288,6 +289,8 @@ public class QQBotManager {
} }
} }
sendImagesMsg(imgs, info); sendImagesMsg(imgs, info);
}
} else if (msg.startsWith(QQCommands.QQ_AUDIO)) { } else if (msg.startsWith(QQCommands.QQ_AUDIO)) {
QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, "")); QQAudio.playText(msg.replace(QQCommands.QQ_AUDIO, ""));
} }