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());
} }
} }
} }
@ -259,16 +278,16 @@ public class AdminMessage extends Message {
} }
private void delModel(String qq, String model) { private void delModel(String qq, String model) {
boolean flag=false; boolean flag = false;
try { try {
if (model == null) { if (model == null) {
List<String> list = QQNumberManager.getManager().getUseModel(Long.parseLong(qq)); List<String> list = QQNumberManager.getManager().getUseModel(Long.parseLong(qq));
for (String power : list) { for (String power : list) {
flag=QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power)); flag = QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power));
} }
} else { } else {
for (String power : model.split("&")) { for (String power : model.split("&")) {
flag=QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power)); flag = QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power));
} }
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -29,47 +29,57 @@ public class BaiHeHui extends Model {
} }
@Override @Override
public void onTime(Long qq,String time) { public void onTime(Long qq, String time) {
super.onTime(qq,time); super.onTime(qq, time);
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));
} }
} }
} }
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();
JSONArray array = JSONArray.parseArray(cookie);
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get("https://bbs.yamibo.com/forum.php");
driver.manage().deleteAllCookies();
for (Cookie _cookie : WebClient.loadCookie(array)) {
driver.manage().addCookie(_cookie);
}
try { try {
Thread.sleep(500); JSONArray array = JSONArray.parseArray(cookie);
} catch (InterruptedException e) { driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
e.printStackTrace(); driver.get("https://bbs.yamibo.com/forum.php");
} driver.manage().deleteAllCookies();
driver.navigate().refresh(); for (Cookie _cookie : WebClient.loadCookie(array)) {
for (WebElement element : driver.findElements(By.xpath("//a"))) { driver.manage().addCookie(_cookie);
if("打卡签到".equals(element.getText())){
element.click();
break;
} }
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.navigate().refresh();
for (WebElement element : driver.findElements(By.xpath("//a"))) {
if ("打卡签到".equals(element.getText())) {
element.click();
break;
}
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
driver.close();
driver.quit();
} }
driver.close();
driver.quit();
} }
public static void main(String[] args) { public static void main(String[] args) {

View File

@ -27,13 +27,16 @@ public class NicePT extends Model {
} }
@Override @Override
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,31 +44,39 @@ 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();
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
driver.get(url);
for (Cookie _cookie : WebClient.loadCookie(array)) {
driver.manage().addCookie(_cookie);
}
try { try {
Thread.sleep(500); driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
} catch (InterruptedException e) { driver.get(url);
for (Cookie _cookie : WebClient.loadCookie(array)) {
driver.manage().addCookie(_cookie);
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.get(url);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
return true;
} catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false;
} finally {
driver.close();
driver.quit();
} }
driver.get(url);
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.close();
driver.quit();
} }
} }

View File

@ -43,13 +43,16 @@ public class Tsdm extends Model {
} }
@Override @Override
public void onTime(Long qq,String time) { public void onTime(Long qq, String time) {
super.onTime(qq,time); super.onTime(qq, time);
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,45 +60,52 @@ 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();
driver.get("https://www.tsdm39.net/forum.php"); try {
getTsdm(array, driver); driver.get("https://www.tsdm39.net/forum.php");
boolean isSign=false; getTsdm(array, driver);
for (WebElement element : driver.findElements(By.xpath("//a"))) { boolean isSign = false;
if(element.getText().contains("签到领奖!")){ for (WebElement element : driver.findElements(By.xpath("//a"))) {
isSign=true; if (element.getText().contains("签到领奖!")) {
break; isSign = true;
break;
}
} }
} if (!isSign) {
if(!isSign){ driver.close();
driver.close(); driver.quit();
driver.quit(); return true;
return; }
} 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')"); } catch (Exception ignored) {
} catch (Exception ignored) { }
} try {
try { Thread.sleep(500);
Thread.sleep(500); } catch (InterruptedException e) {
} catch (InterruptedException e) { e.printStackTrace();
e.printStackTrace(); }
} try {
try { driver.findElement(By.id("wl")).click();
driver.findElement(By.id("wl")).click(); driver.findElement(By.xpath("//input[@value='3']")).click();
driver.findElement(By.xpath("//input[@value='3']")).click(); driver.findElement(By.id("qiandao")).submit();
driver.findElement(By.id("qiandao")).submit(); } catch (Exception e) {
e.printStackTrace();
}
return true;
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
return false;
} finally {
driver.close();
driver.quit();
} }
driver.close();
driver.quit();
} }
private void getTsdm(JSONArray array, WebDriver driver) { private void getTsdm(JSONArray array, WebDriver driver) {