新作关键词

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.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",

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) {
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();
}