新作关键词

This commit is contained in:
Yutousama 2022-04-17 01:20:40 +08:00
parent f6c9748f48
commit 2558545ffe
2 changed files with 17 additions and 9 deletions

View File

@ -5,10 +5,13 @@ import com.yutou.qqbot.QQBotManager;
import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.DownloadInterface;
import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.Model;
import com.yutou.qqbot.utlis.HttpTools; import com.yutou.qqbot.utlis.HttpTools;
import com.yutou.qqbot.utlis.StringUtils;
import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.event.events.MessageEvent;
import net.mamoe.mirai.message.data.MessageChainBuilder; import net.mamoe.mirai.message.data.MessageChainBuilder;
import java.io.File; import java.io.File;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
public class GetSeTu extends Model { public class GetSeTu extends Model {
@Override @Override
@ -29,8 +32,13 @@ 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 ("来点色图".equals(msg) || "来点涩图".equals(msg)) { if (msg.startsWith("来点")&&(msg.endsWith("色图")||msg.endsWith("涩图"))) {
String ret = HttpTools.get("https://api.lolicon.app/setu/v2?r18=2"); 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); JSONObject json = JSONObject.parseObject(ret);
HttpTools.download(json.getJSONArray("data").getJSONObject(0).getJSONObject("urls").getString("original"), HttpTools.download(json.getJSONArray("data").getJSONObject(0).getJSONObject("urls").getString("original"),
System.currentTimeMillis()+"_setu.jpg", System.currentTimeMillis()+"_setu.jpg",

View File

@ -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) { public synchronized static void download(final String url, final String saveName, final DownloadInterface downloadInterface) {
download(url,saveName,false,downloadInterface); download(url,saveName,false,downloadInterface);
@ -172,7 +172,7 @@ public class HttpTools {
public void run() { public void run() {
File jar = null; File jar = null;
try { try {
File savePath = new File(donwloadPath); File savePath = new File(downloadPath);
Proxy proxy=null; Proxy proxy=null;
if (!savePath.exists()) { if (!savePath.exists()) {
savePath.mkdirs(); savePath.mkdirs();
@ -200,7 +200,7 @@ public class HttpTools {
// Log.i(TAG,"获取到网络请求:"+connection.getResponseCode()); // Log.i(TAG,"获取到网络请求:"+connection.getResponseCode());
InputStream inputStream = connection.getInputStream(); InputStream inputStream = connection.getInputStream();
jar = new File(donwloadPath + saveName + "_tmp.tmp"); jar = new File(downloadPath + saveName + "_tmp.tmp");
jar.createNewFile(); jar.createNewFile();
Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath()); Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath());
OutputStream outputStream = new FileOutputStream(jar); OutputStream outputStream = new FileOutputStream(jar);
@ -217,7 +217,7 @@ public class HttpTools {
} }
outputStream.close(); outputStream.close();
inputStream.close(); inputStream.close();
File oldJar = new File(donwloadPath + saveName); File oldJar = new File(downloadPath + saveName);
if (oldJar.exists()) { if (oldJar.exists()) {
oldJar.delete(); oldJar.delete();
} }
@ -247,7 +247,7 @@ public class HttpTools {
} }
File jar = null; File jar = null;
try { try {
File savePath = new File(donwloadPath); File savePath = new File(downloadPath);
if (!savePath.exists()) { if (!savePath.exists()) {
savePath.mkdirs(); savePath.mkdirs();
} }
@ -258,7 +258,7 @@ public class HttpTools {
connection.addRequestProperty("Content-type","image/jpeg"); connection.addRequestProperty("Content-type","image/jpeg");
InputStream inputStream = connection.getInputStream(); InputStream inputStream = connection.getInputStream();
jar = new File(donwloadPath + saveName + "_tmp.tmp"); jar = new File(downloadPath + saveName + "_tmp.tmp");
jar.createNewFile(); jar.createNewFile();
Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath()); Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath());
OutputStream outputStream = new FileOutputStream(jar); OutputStream outputStream = new FileOutputStream(jar);
@ -271,7 +271,7 @@ public class HttpTools {
} }
outputStream.close(); outputStream.close();
inputStream.close(); inputStream.close();
File oldJar = new File(donwloadPath + saveName); File oldJar = new File(downloadPath + saveName);
if (oldJar.exists()) { if (oldJar.exists()) {
oldJar.delete(); oldJar.delete();
} }