From 19a9fb0d1bf9a0620eee5458dd2371cfdf3a1cfd Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 18 Apr 2022 22:49:27 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=A9=E5=9B=BE=E6=A8=A1=E5=9D=97=EF=BC=9A?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E4=B8=8D=E5=88=B0=E5=90=8E=E4=BC=9A=E5=B0=9D?= =?UTF-8?q?=E8=AF=95=E6=90=9C=E7=B4=A2=E9=9D=9E18=E3=80=81=E6=A8=A1?= =?UTF-8?q?=E7=B3=8A=E6=90=9C=E7=B4=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/QQBotApplication.java | 2 +- .../com/yutou/qqbot/models/setu/GetSeTu.java | 125 ++++++++++-------- 2 files changed, 70 insertions(+), 57 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index 468d7d9..0558afa 100644 --- a/src/main/java/com/yutou/qqbot/QQBotApplication.java +++ b/src/main/java/com/yutou/qqbot/QQBotApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class QQBotApplication { - public static final String version="QQBot v.1.2.18"; + public static final String version="QQBot v.1.2.19"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index 88816d4..f610de4 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -47,70 +47,83 @@ public class GetSeTu extends Model { if (isRun) { Log.i(event.getSource().getFromId() + " > " + msg); Pattern pattern = Pattern.compile("来点(.*?)色图"); - Matcher matcher=pattern.matcher(msg); - String key=null; - if(matcher.find()){ - key=matcher.group(1); + Matcher matcher = pattern.matcher(msg); + String key = null; + if (matcher.find()) { + key = matcher.group(1); } - String url = "https://api.lolicon.app/setu/v2?r18=0&size=regular"; - if (isR18) { - url = "https://api.lolicon.app/setu/v2?r18=1&size=regular"; - } - if (!StringUtils.isEmpty(key)) { - if (isR18) { - url = "https://api.lolicon.app/setu/v2?tag=" + URLEncoder.encode(key, StandardCharsets.UTF_8) + "&r18=1&size=regular"; - } else { - url = "https://api.lolicon.app/setu/v2?tag=" + URLEncoder.encode(key, StandardCharsets.UTF_8) + "&r18=0&size=regular"; + if (!getSeTu("tag", key, isR18, false, qq, event)) { + if (!getSeTu("tag", key, isR18, true, qq, event)) { + if (!getSeTu("dec", key, isR18, true, qq, event)) { + QQBotManager.getInstance().sendMessage(qq, "找不到喵~"); + } } } - String ret = HttpTools.get(url); - JSONObject json = JSONObject.parseObject(ret); - if (json.getJSONArray("data").size() == 0) { - QQBotManager.getInstance().sendMessage(qq, "找不到喵~"); - return; - } - JSONObject item = json.getJSONArray("data").getJSONObject(0); - StringBuilder builder = new StringBuilder(); - builder.append(item.getString("title")); - builder.append("\n"); - builder.append("R18:"); - if (item.getBoolean("r18")) { - builder.append("YES!"); - } else { - builder.append("NO~"); - } - builder.append("\n"); - builder.append("tags:"); - for (Object tags : item.getJSONArray("tags")) { - builder.append(tags).append("、"); - } - HttpTools.download(item.getJSONObject("urls").getString("regular"), - System.currentTimeMillis() + "_setu.jpg", - true - , new DownloadInterface() { - @Override - public void onDownload(File file) { - super.onDownload(file); - QQBotManager.getInstance().sendMessage(file, qq,event.getMessage(), builder.toString()); - } - - @Override - public void onError(Exception e) { - super.onError(e); - QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); - e.printStackTrace(); - } - }); } } + private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event) { + String url = "https://api.lolicon.app/setu/v2?r18=0&size=regular"; + if (r18) { + url = "https://api.lolicon.app/setu/v2?r18=1&size=regular"; + } + if (!StringUtils.isEmpty(key)) { + if (r18) { + url = "https://api.lolicon.app/setu/v2?" + model + "=" + URLEncoder.encode(key, StandardCharsets.UTF_8) + "&r18=1&size=regular"; + } else { + url = "https://api.lolicon.app/setu/v2?" + model + "=" + URLEncoder.encode(key, StandardCharsets.UTF_8) + "&r18=0&size=regular"; + } + } + if (fuzzyR18) { + url = url.replace("&r18=0", "&r18=2").replace("&r18=1", "&r18=2"); + } + String ret = HttpTools.get(url); + JSONObject json = JSONObject.parseObject(ret); + if (json.getJSONArray("data").size() == 0) { + return false; + } + JSONObject item = json.getJSONArray("data").getJSONObject(0); + StringBuilder builder = new StringBuilder(); + builder.append(item.getString("title")); + builder.append("\n"); + builder.append("R18:"); + if (item.getBoolean("r18")) { + builder.append("YES!"); + } else { + builder.append("NO~"); + } + builder.append("\n"); + builder.append("tags:"); + for (Object tags : item.getJSONArray("tags")) { + builder.append(tags).append("、"); + } + HttpTools.download(item.getJSONObject("urls").getString("regular"), + System.currentTimeMillis() + "_setu.jpg", + true + , new DownloadInterface() { + @Override + public void onDownload(File file) { + super.onDownload(file); + QQBotManager.getInstance().sendMessage(file, qq, event.getMessage(), builder.toString()); + } + + @Override + public void onError(Exception e) { + super.onError(e); + QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); + e.printStackTrace(); + } + }); + return true; + } + public static void main(String[] args) { - String msg="来点1色图"; + String msg = "来点1色图"; Pattern pattern = Pattern.compile("来点(.*?)色图"); - Matcher matcher=pattern.matcher(msg); - String key=null; - if(matcher.find()){ - key=matcher.group(1); + Matcher matcher = pattern.matcher(msg); + String key = null; + if (matcher.find()) { + key = matcher.group(1); } System.out.println("key = " + key); }