新增代理
This commit is contained in:
parent
0819bc58aa
commit
a27d6c5a35
@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets;
|
|||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@UseModel
|
@UseModel
|
||||||
public class GetSeTu extends Model {
|
public class GetSeTu extends Model {
|
||||||
@Override
|
@Override
|
||||||
@ -64,7 +65,7 @@ public class GetSeTu extends Model {
|
|||||||
private void send(Long group) {
|
private void send(Long group) {
|
||||||
Jedis redis = RedisTools.getRedis();
|
Jedis redis = RedisTools.getRedis();
|
||||||
redis.select(RedisTools.QQBOT_USER);
|
redis.select(RedisTools.QQBOT_USER);
|
||||||
String ret = redis.get("Setu_"+group);
|
String ret = redis.get("Setu_" + group);
|
||||||
redis.close();
|
redis.close();
|
||||||
MessageChainBuilder builder = null;
|
MessageChainBuilder builder = null;
|
||||||
if (!StringUtils.isEmpty(ret)) {
|
if (!StringUtils.isEmpty(ret)) {
|
||||||
@ -96,8 +97,8 @@ public class GetSeTu extends Model {
|
|||||||
builder.append(new At(qq))
|
builder.append(new At(qq))
|
||||||
.append(":\n");
|
.append(":\n");
|
||||||
for (String tag : list) {
|
for (String tag : list) {
|
||||||
if(StringUtils.isEmpty(tag)){
|
if (StringUtils.isEmpty(tag)) {
|
||||||
tag="随机";
|
tag = "随机";
|
||||||
}
|
}
|
||||||
builder.append(tag).append("\n");
|
builder.append(tag).append("\n");
|
||||||
}
|
}
|
||||||
@ -157,11 +158,13 @@ public class GetSeTu extends Model {
|
|||||||
RedisTools.set("Setu_" + qq, array.toString());
|
RedisTools.set("Setu_" + qq, array.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event){
|
|
||||||
return getSeTu(model, key, r18, fuzzyR18, qq, event,3);
|
private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event) {
|
||||||
|
return getSeTu(model, key, r18, fuzzyR18, qq, event, 3);
|
||||||
}
|
}
|
||||||
private boolean getSeTu(String model,String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event,int reset) {
|
|
||||||
if(reset<=0){
|
private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event, int reset) {
|
||||||
|
if (reset <= 0) {
|
||||||
QQBotManager.getInstance().sendMessage(qq, "获取失败喵~");
|
QQBotManager.getInstance().sendMessage(qq, "获取失败喵~");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -169,7 +172,7 @@ public class GetSeTu extends Model {
|
|||||||
if (r18) {
|
if (r18) {
|
||||||
url = "https://api.lolicon.app/setu/v2?r18=1&size=regular";
|
url = "https://api.lolicon.app/setu/v2?r18=1&size=regular";
|
||||||
}
|
}
|
||||||
final String tmpKey=key;
|
final String tmpKey = key;
|
||||||
if (!StringUtils.isEmpty(key)) {
|
if (!StringUtils.isEmpty(key)) {
|
||||||
if ("tag".equals(model)) {
|
if ("tag".equals(model)) {
|
||||||
String[] keys = key.split(" ");
|
String[] keys = key.split(" ");
|
||||||
@ -192,7 +195,7 @@ public class GetSeTu extends Model {
|
|||||||
url = url.replace("&r18=0", "&r18=2").replace("&r18=1", "&r18=2");
|
url = url.replace("&r18=0", "&r18=2").replace("&r18=1", "&r18=2");
|
||||||
}
|
}
|
||||||
System.out.println("url = " + url);
|
System.out.println("url = " + url);
|
||||||
String ret = HttpTools.get(url);
|
String ret = HttpTools.http_get(url, null, true);
|
||||||
JSONObject json = JSON.parseObject(ret);
|
JSONObject json = JSON.parseObject(ret);
|
||||||
if (json.getJSONArray("data").size() == 0) {
|
if (json.getJSONArray("data").size() == 0) {
|
||||||
return false;
|
return false;
|
||||||
@ -227,15 +230,15 @@ public class GetSeTu extends Model {
|
|||||||
MessageChainBuilder chain = new MessageChainBuilder();
|
MessageChainBuilder chain = new MessageChainBuilder();
|
||||||
chain.append(new QuoteReply(event.getMessage()));
|
chain.append(new QuoteReply(event.getMessage()));
|
||||||
chain.append(builder.toString());
|
chain.append(builder.toString());
|
||||||
MessageReceipt<?> message=QQBotManager.getInstance().sendMessage(qq,chain);
|
MessageReceipt<?> message = QQBotManager.getInstance().sendMessage(qq, chain);
|
||||||
Log.i(getModelName(),message);
|
Log.i(getModelName(), message);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onError(Exception e) {
|
public void onError(Exception e) {
|
||||||
super.onError(e);
|
super.onError(e);
|
||||||
getSeTu(model, tmpKey, r18, fuzzyR18, qq, event, reset-1);
|
getSeTu(model, tmpKey, r18, fuzzyR18, qq, event, reset - 1);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -17,7 +17,7 @@ public class HttpTools {
|
|||||||
private static final int HttpRequestIndex = 3;
|
private static final int HttpRequestIndex = 3;
|
||||||
|
|
||||||
public static String get(String url) {
|
public static String get(String url) {
|
||||||
return http_get(url, null);
|
return http_get(url, null,false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String post(final String url, final byte[] body) {
|
public static String post(final String url, final byte[] body) {
|
||||||
@ -40,10 +40,19 @@ public class HttpTools {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String http_get(String url, Map<String, String> header) {
|
public static String http_get(String url, Map<String, String> header,boolean isProxy) {
|
||||||
try {
|
try {
|
||||||
HttpURLConnection connection;
|
HttpURLConnection connection;
|
||||||
connection = (HttpURLConnection) new URL(url).openConnection();
|
Proxy proxy = null;
|
||||||
|
if (isProxy) {
|
||||||
|
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
|
||||||
|
}
|
||||||
|
|
||||||
|
if(proxy==null) {
|
||||||
|
connection = (HttpURLConnection) new URL(url).openConnection();
|
||||||
|
}else{
|
||||||
|
connection = (HttpURLConnection) new URL(url).openConnection(proxy);
|
||||||
|
}
|
||||||
return urlConnection(header, connection);
|
return urlConnection(header, connection);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.err.println("error url = " + url);
|
System.err.println("error url = " + url);
|
||||||
|
Loading…
Reference in New Issue
Block a user