涩图模块:区分色图和涩图关键词

This commit is contained in:
Yutousama 2022-04-17 15:25:51 +08:00
parent 4e56d31e43
commit 10fd1d6863

View File

@ -33,28 +33,42 @@ public class GetSeTu extends Model {
@Override @Override
public void onMessage(Long qq, MessageEvent event, boolean isGroup) { public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
super.onMessage(qq, event, isGroup); super.onMessage(qq, event, isGroup);
if (msg.startsWith("来点")&&(msg.endsWith("色图")||msg.endsWith("涩图"))) { boolean isRun = false;
Log.i(event.getSource().getFromId()+" > "+msg); boolean isR18 = false;
String key=msg.replace("来点","").replace("色图","").replace("涩图",""); if (msg.contains("来点") && msg.contains("色图")) {
String url="https://api.lolicon.app/setu/v2?r18=2"; isRun = true;
if(!StringUtils.isEmpty(key)){ } else if (msg.contains("来点") && msg.contains("涩图")) {
url="https://api.lolicon.app/setu/v2?tag="+ URLEncoder.encode(key, StandardCharsets.UTF_8)+"&r18=2"; 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); String ret = HttpTools.get(url);
JSONObject json = JSONObject.parseObject(ret); JSONObject json = JSONObject.parseObject(ret);
System.out.println("json = " + json); if (json.getJSONArray("data").size() == 0) {
if(json.getJSONArray("data").size()==0){ QQBotManager.getInstance().sendMessage(qq, "找不到喵~");
QQBotManager.getInstance().sendMessage(qq,"找不到喵~");
return; return;
} }
JSONObject item=json.getJSONArray("data").getJSONObject(0); JSONObject item = json.getJSONArray("data").getJSONObject(0);
StringBuilder builder=new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(item.getString("title")); builder.append(item.getString("title"));
builder.append("\n"); builder.append("\n");
builder.append("R18:"); builder.append("R18:");
if(item.getBoolean("r18")){ if (item.getBoolean("r18")) {
builder.append("YES!"); builder.append("YES!");
}else{ } else {
builder.append("NO~"); builder.append("NO~");
} }
builder.append("\n"); builder.append("\n");
@ -63,7 +77,7 @@ public class GetSeTu extends Model {
builder.append(tags).append(""); builder.append(tags).append("");
} }
HttpTools.download(item.getJSONObject("urls").getString("original"), HttpTools.download(item.getJSONObject("urls").getString("original"),
System.currentTimeMillis()+"_setu.jpg", System.currentTimeMillis() + "_setu.jpg",
true true
, new DownloadInterface() { , new DownloadInterface() {
@Override @Override
@ -75,7 +89,7 @@ public class GetSeTu extends Model {
@Override @Override
public void onError(Exception e) { public void onError(Exception e) {
super.onError(e); super.onError(e);
QQBotManager.getInstance().sendMessage(qq,"获取失败喵~"); QQBotManager.getInstance().sendMessage(qq, "获取失败喵~");
} }
}); });
} }