From 694b5fb2ae5749d85f3b61560a18b8121755cda0 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 28 Apr 2022 08:34:14 +0800 Subject: [PATCH] =?UTF-8?q?chromedrive=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=90=86?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/MessageEvent/AdminMessage.java | 33 ++++++-- .../yutou/qqbot/models/WebSign/BaiHeHui.java | 60 ++++++++------ .../yutou/qqbot/models/WebSign/NicePT.java | 57 ++++++++------ .../com/yutou/qqbot/models/WebSign/Tsdm.java | 78 +++++++++++-------- 4 files changed, 139 insertions(+), 89 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java b/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java index fe7885e..ce875d7 100644 --- a/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java +++ b/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java @@ -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 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) { diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java b/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java index 2a8074e..403330b 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java @@ -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) { diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/NicePT.java b/src/main/java/com/yutou/qqbot/models/WebSign/NicePT.java index 21b041a..21dac43 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/NicePT.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/NicePT.java @@ -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(); } } diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java b/src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java index 5d6f4b1..762990b 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java @@ -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) {