From 10fd1d6863f0d6b47e1c02f92826384cffce06be Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 17 Apr 2022 15:25:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B6=A9=E5=9B=BE=E6=A8=A1=E5=9D=97=EF=BC=9A?= =?UTF-8?q?=E5=8C=BA=E5=88=86=E8=89=B2=E5=9B=BE=E5=92=8C=E6=B6=A9=E5=9B=BE?= =?UTF-8?q?=E5=85=B3=E9=94=AE=E8=AF=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/models/setu/GetSeTu.java | 44 ++++++++++++------- 1 file changed, 29 insertions(+), 15 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 e5f05c7..47c78aa 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -33,28 +33,42 @@ public class GetSeTu extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if (msg.startsWith("来点")&&(msg.endsWith("色图")||msg.endsWith("涩图"))) { - Log.i(event.getSource().getFromId()+" > "+msg); - 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"; + boolean isRun = false; + boolean isR18 = false; + if (msg.contains("来点") && msg.contains("色图")) { + isRun = true; + } else if (msg.contains("来点") && msg.contains("涩图")) { + isRun = true; + isR18 = true; + } + if (isRun) { + Log.i(event.getSource().getFromId() + " > " + msg); + String key = msg.replace("来点", "").replace("色图", "").replace("涩图", ""); + String url = "https://api.lolicon.app/setu/v2?r18=0"; + if (isR18) { + url = "https://api.lolicon.app/setu/v2?r18=1"; + } + if (!StringUtils.isEmpty(key)) { + if (isR18) { + url = "https://api.lolicon.app/setu/v2?tag=" + URLEncoder.encode(key, StandardCharsets.UTF_8) + "&r18=1"; + } else { + url = "https://api.lolicon.app/setu/v2?tag=" + URLEncoder.encode(key, StandardCharsets.UTF_8) + "&r18=0"; + } } String ret = HttpTools.get(url); JSONObject json = JSONObject.parseObject(ret); - System.out.println("json = " + json); - if(json.getJSONArray("data").size()==0){ - QQBotManager.getInstance().sendMessage(qq,"找不到喵~"); + if (json.getJSONArray("data").size() == 0) { + QQBotManager.getInstance().sendMessage(qq, "找不到喵~"); return; } - JSONObject item=json.getJSONArray("data").getJSONObject(0); - StringBuilder builder=new StringBuilder(); + 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")){ + if (item.getBoolean("r18")) { builder.append("YES!"); - }else{ + } else { builder.append("NO~"); } builder.append("\n"); @@ -63,7 +77,7 @@ public class GetSeTu extends Model { builder.append(tags).append("、"); } HttpTools.download(item.getJSONObject("urls").getString("original"), - System.currentTimeMillis()+"_setu.jpg", + System.currentTimeMillis() + "_setu.jpg", true , new DownloadInterface() { @Override @@ -75,7 +89,7 @@ public class GetSeTu extends Model { @Override public void onError(Exception e) { super.onError(e); - QQBotManager.getInstance().sendMessage(qq,"获取失败喵~"); + QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); } }); }