From 2558545ffea0db3e6505c047f495dc894a93d0f0 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 17 Apr 2022 01:20:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E4=BD=9C=E5=85=B3=E9=94=AE=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/qqbot/models/setu/GetSeTu.java | 12 ++++++++++-- src/main/java/com/yutou/qqbot/utlis/HttpTools.java | 14 +++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) 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 bea11b8..91ea621 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -5,10 +5,13 @@ import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.models.Model; import com.yutou.qqbot.utlis.HttpTools; +import com.yutou.qqbot.utlis.StringUtils; import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.message.data.MessageChainBuilder; import java.io.File; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; public class GetSeTu extends Model { @Override @@ -29,8 +32,13 @@ public class GetSeTu extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if ("来点色图".equals(msg) || "来点涩图".equals(msg)) { - String ret = HttpTools.get("https://api.lolicon.app/setu/v2?r18=2"); + if (msg.startsWith("来点")&&(msg.endsWith("色图")||msg.endsWith("涩图"))) { + String key=msg.replace("来点","").replace("色图","").replace("涩图",""); + String url="https://api.lolicon.app/setu/v2?r18=2"; + if(!StringUtils.isEmpty(key)){ + url="https://api.lolicon.app/setu/v2?tag="+ URLEncoder.encode(key, StandardCharsets.UTF_8)+"&r18=2"; + } + String ret = HttpTools.get(url); JSONObject json = JSONObject.parseObject(ret); HttpTools.download(json.getJSONArray("data").getJSONObject(0).getJSONObject("urls").getString("original"), System.currentTimeMillis()+"_setu.jpg", diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index 63488e7..c80d546 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -161,7 +161,7 @@ public class HttpTools { } - private static String donwloadPath = "tmp" + File.separator; + public static String downloadPath = "tmp" + File.separator; public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) { download(url,saveName,false,downloadInterface); @@ -172,7 +172,7 @@ public class HttpTools { public void run() { File jar = null; try { - File savePath = new File(donwloadPath); + File savePath = new File(downloadPath); Proxy proxy=null; if (!savePath.exists()) { savePath.mkdirs(); @@ -200,7 +200,7 @@ public class HttpTools { // Log.i(TAG,"获取到网络请求:"+connection.getResponseCode()); InputStream inputStream = connection.getInputStream(); - jar = new File(donwloadPath + saveName + "_tmp.tmp"); + jar = new File(downloadPath + saveName + "_tmp.tmp"); jar.createNewFile(); Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath()); OutputStream outputStream = new FileOutputStream(jar); @@ -217,7 +217,7 @@ public class HttpTools { } outputStream.close(); inputStream.close(); - File oldJar = new File(donwloadPath + saveName); + File oldJar = new File(downloadPath + saveName); if (oldJar.exists()) { oldJar.delete(); } @@ -247,7 +247,7 @@ public class HttpTools { } File jar = null; try { - File savePath = new File(donwloadPath); + File savePath = new File(downloadPath); if (!savePath.exists()) { savePath.mkdirs(); } @@ -258,7 +258,7 @@ public class HttpTools { connection.addRequestProperty("Content-type","image/jpeg"); InputStream inputStream = connection.getInputStream(); - jar = new File(donwloadPath + saveName + "_tmp.tmp"); + jar = new File(downloadPath + saveName + "_tmp.tmp"); jar.createNewFile(); Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath()); OutputStream outputStream = new FileOutputStream(jar); @@ -271,7 +271,7 @@ public class HttpTools { } outputStream.close(); inputStream.close(); - File oldJar = new File(donwloadPath + saveName); + File oldJar = new File(downloadPath + saveName); if (oldJar.exists()) { oldJar.delete(); }