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 -> {
boolean sign = true;
boolean tsdmSign = false, baiheSign = false, nicePtSign = false;
Log.i("开始签到");
try {
new Tsdm().tsdmSign();
if (new Tsdm().tsdmSign()) {
tsdmSign = true;
}
} catch (Exception e) {
sign = false;
QQBotManager.getInstance().sendMessage(qq, "tsdm签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace();
}
try {
new BaiHeHui().sign();
if (new BaiHeHui().sign()) {
baiheSign = true;
}
} catch (Exception e) {
sign = false;
QQBotManager.getInstance().sendMessage(qq, "百合会签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace();
}
try {
new NicePT().sign();
if (new NicePT().sign()) {
nicePtSign = true;
}
} catch (Exception e) {
sign = false;
QQBotManager.getInstance().sendMessage(qq, "NicePT签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace();
}
if (sign) {
if (sign && tsdmSign && baiheSign && nicePtSign) {
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) {
boolean flag=false;
boolean flag = false;
try {
if (model == null) {
List<String> list = QQNumberManager.getManager().getUseModel(Long.parseLong(qq));
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 {
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) {

View File

@ -29,47 +29,57 @@ public class BaiHeHui extends Model {
}
@Override
public void onTime(Long qq,String time) {
super.onTime(qq,time);
public void onTime(Long qq, String time) {
super.onTime(qq, time);
if ("08:10:00".equals(time)) {
Log.i("开始百合会签到");
try {
sign();
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"百合会签到成功");
if (sign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到成功");
}else{
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "百合会签到失败");
}
} catch (Exception e) {
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"));
if (StringUtils.isEmpty(cookie)) {
return;
return false;
}
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 {
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;
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 {
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) {

View File

@ -27,13 +27,16 @@ public class NicePT extends Model {
}
@Override
public void onTime(Long qq,String time) {
super.onTime(qq,time);
public void onTime(Long qq, String time) {
super.onTime(qq, time);
if ("08:01:00".equals(time)) {
Log.i("开始天使动漫签到");
Log.i("开始NicePT签到");
try {
sign();
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成NicePT的签到");
if(sign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成NicePT的签到");
}else{
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "NicePT签到失败");
}
} catch (Exception e) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "NicePT签到失败:" + AppTools.getExceptionString(e));
e.printStackTrace();
@ -41,31 +44,39 @@ public class NicePT extends Model {
}
}
public void sign(){
String url="https://www.nicept.net/attendance.php";
public boolean sign() {
String url = "https://www.nicept.net/attendance.php";
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("nicept.json")));
if (array == null) {
System.err.println("array is null");
return;
return false;
}
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 {
Thread.sleep(500);
} catch (InterruptedException e) {
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
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();
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
public void onTime(Long qq,String time) {
super.onTime(qq,time);
public void onTime(Long qq, String time) {
super.onTime(qq, time);
if ("08:05:00".equals(time)) {
Log.i("开始天使动漫签到");
try {
tsdmSign();
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成天使动漫的签到");
if(tsdmSign()) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成天使动漫的签到");
}else{
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "天使动漫签到失败");
}
} catch (Exception e) {
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "天使动漫签到失败:" + AppTools.getExceptionString(e));
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")));
if (array == null) {
System.err.println("array is null");
return;
return false;
}
WebDriver driver = WebClient.getInstance().getWebDriver();
driver.get("https://www.tsdm39.net/forum.php");
getTsdm(array, driver);
boolean isSign=false;
for (WebElement element : driver.findElements(By.xpath("//a"))) {
if(element.getText().contains("签到领奖!")){
isSign=true;
break;
try {
driver.get("https://www.tsdm39.net/forum.php");
getTsdm(array, driver);
boolean isSign = false;
for (WebElement element : driver.findElements(By.xpath("//a"))) {
if (element.getText().contains("签到领奖!")) {
isSign = true;
break;
}
}
}
if(!isSign){
driver.close();
driver.quit();
return;
}
try {
((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')");
} catch (Exception ignored) {
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
driver.findElement(By.id("wl")).click();
driver.findElement(By.xpath("//input[@value='3']")).click();
driver.findElement(By.id("qiandao")).submit();
if (!isSign) {
driver.close();
driver.quit();
return true;
}
try {
((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')");
} catch (Exception ignored) {
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
try {
driver.findElement(By.id("wl")).click();
driver.findElement(By.xpath("//input[@value='3']")).click();
driver.findElement(By.id("qiandao")).submit();
} catch (Exception e) {
e.printStackTrace();
}
return true;
} catch (Exception e) {
e.printStackTrace();
return false;
} finally {
driver.close();
driver.quit();
}
driver.close();
driver.quit();
}
private void getTsdm(JSONArray array, WebDriver driver) {