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