chromedrive新增代理支持

This commit is contained in:
Yutousama 2022-04-28 08:34:14 +08:00
parent ec6fce9a8d
commit 694b5fb2ae
4 changed files with 139 additions and 89 deletions

View File

@ -178,30 +178,49 @@ public class AdminMessage extends Message {
case QQCommands.SIGN -> { case QQCommands.SIGN -> {
boolean sign = true; boolean sign = true;
boolean tsdmSign = false, baiheSign = false, nicePtSign = false;
Log.i("开始签到"); Log.i("开始签到");
try { try {
new Tsdm().tsdmSign(); if (new Tsdm().tsdmSign()) {
tsdmSign = true;
}
} catch (Exception e) { } catch (Exception e) {
sign = false; sign = false;
QQBotManager.getInstance().sendMessage(qq, "tsdm签到失败:" + AppTools.getExceptionString(e)); QQBotManager.getInstance().sendMessage(qq, "tsdm签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace(); e.printStackTrace();
} }
try { try {
new BaiHeHui().sign(); if (new BaiHeHui().sign()) {
baiheSign = true;
}
} catch (Exception e) { } catch (Exception e) {
sign = false; sign = false;
QQBotManager.getInstance().sendMessage(qq, "百合会签到失败:" + AppTools.getExceptionString(e)); QQBotManager.getInstance().sendMessage(qq, "百合会签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace(); e.printStackTrace();
} }
try { try {
new NicePT().sign(); if (new NicePT().sign()) {
nicePtSign = true;
}
} catch (Exception e) { } catch (Exception e) {
sign = false; sign = false;
QQBotManager.getInstance().sendMessage(qq, "NicePT签到失败:" + AppTools.getExceptionString(e)); QQBotManager.getInstance().sendMessage(qq, "NicePT签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace(); e.printStackTrace();
} }
if (sign) { if (sign && tsdmSign && baiheSign && nicePtSign) {
QQBotManager.getInstance().sendMessage(qq, "签到任务完成"); QQBotManager.getInstance().sendMessage(qq, "签到任务完成");
}else{
StringBuilder builder=new StringBuilder();
if(!tsdmSign){
builder.append("天使动漫签到失败\n");
}
if(!baiheSign){
builder.append("百合会签到失败\n");
}
if(!nicePtSign){
builder.append("NicePT签到失败\n");
}
QQBotManager.getInstance().sendMessage(qq,builder.toString());
} }
} }
} }

View File

@ -34,8 +34,11 @@ public class BaiHeHui extends Model {
if ("08:10:00".equals(time)) { if ("08:10:00".equals(time)) {
Log.i("开始百合会签到"); Log.i("开始百合会签到");
try { try {
sign(); if (sign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到成功"); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到成功");
}else{
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到失败");
}
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到失败:" + AppTools.getExceptionString(e)); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到失败:" + AppTools.getExceptionString(e));
@ -43,12 +46,13 @@ public class BaiHeHui extends Model {
} }
} }
public void sign() { public boolean sign() {
String cookie = ConfigTools.readFile(new File("baihehui.json")); String cookie = ConfigTools.readFile(new File("baihehui.json"));
if (StringUtils.isEmpty(cookie)) { if (StringUtils.isEmpty(cookie)) {
return; return false;
} }
WebDriver driver = WebClient.getInstance().getWebDriver(); WebDriver driver = WebClient.getInstance().getWebDriver();
try {
JSONArray array = JSONArray.parseArray(cookie); JSONArray array = JSONArray.parseArray(cookie);
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get("https://bbs.yamibo.com/forum.php"); driver.get("https://bbs.yamibo.com/forum.php");
@ -68,9 +72,15 @@ public class BaiHeHui extends Model {
break; break;
} }
} }
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
driver.close(); driver.close();
driver.quit(); driver.quit();
} }
}
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -30,10 +30,13 @@ public class NicePT extends Model {
public void onTime(Long qq, String time) { public void onTime(Long qq, String time) {
super.onTime(qq, time); super.onTime(qq, time);
if ("08:01:00".equals(time)) { if ("08:01:00".equals(time)) {
Log.i("开始天使动漫签到"); Log.i("开始NicePT签到");
try { try {
sign(); if(sign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成NicePT的签到"); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成NicePT的签到");
}else{
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "NicePT签到失败");
}
} catch (Exception e) { } catch (Exception e) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "NicePT签到失败:" + AppTools.getExceptionString(e)); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "NicePT签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace(); e.printStackTrace();
@ -41,14 +44,15 @@ public class NicePT extends Model {
} }
} }
public void sign(){ public boolean sign() {
String url = "https://www.nicept.net/attendance.php"; String url = "https://www.nicept.net/attendance.php";
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("nicept.json"))); JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("nicept.json")));
if (array == null) { if (array == null) {
System.err.println("array is null"); System.err.println("array is null");
return; return false;
} }
WebDriver driver = WebClient.getInstance().getWebDriver(); WebDriver driver = WebClient.getInstance().getWebDriver();
try {
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get(url); driver.get(url);
for (Cookie _cookie : WebClient.loadCookie(array)) { for (Cookie _cookie : WebClient.loadCookie(array)) {
@ -65,7 +69,14 @@ public class NicePT extends Model {
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
} }
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
driver.close(); driver.close();
driver.quit(); driver.quit();
}
} }
} }

View File

@ -48,8 +48,11 @@ public class Tsdm extends Model {
if ("08:05:00".equals(time)) { if ("08:05:00".equals(time)) {
Log.i("开始天使动漫签到"); Log.i("开始天使动漫签到");
try { try {
tsdmSign(); if(tsdmSign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成天使动漫的签到"); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成天使动漫的签到");
}else{
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "天使动漫签到失败");
}
} catch (Exception e) { } catch (Exception e) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "天使动漫签到失败:" + AppTools.getExceptionString(e)); QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "天使动漫签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace(); e.printStackTrace();
@ -57,13 +60,14 @@ public class Tsdm extends Model {
} }
} }
public void tsdmSign() { public boolean tsdmSign() {
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json"))); JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json")));
if (array == null) { if (array == null) {
System.err.println("array is null"); System.err.println("array is null");
return; return false;
} }
WebDriver driver = WebClient.getInstance().getWebDriver(); WebDriver driver = WebClient.getInstance().getWebDriver();
try {
driver.get("https://www.tsdm39.net/forum.php"); driver.get("https://www.tsdm39.net/forum.php");
getTsdm(array, driver); getTsdm(array, driver);
boolean isSign = false; boolean isSign = false;
@ -76,7 +80,7 @@ public class Tsdm extends Model {
if (!isSign) { if (!isSign) {
driver.close(); driver.close();
driver.quit(); driver.quit();
return; return true;
} }
try { try {
((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')"); ((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')");
@ -94,9 +98,15 @@ public class Tsdm extends Model {
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
driver.close(); driver.close();
driver.quit(); driver.quit();
} }
}
private void getTsdm(JSONArray array, WebDriver driver) { private void getTsdm(JSONArray array, WebDriver driver) {
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);