diff --git a/src/main/java/com/yutou/qqbot/Listeners/QQMessageListener.java b/src/main/java/com/yutou/qqbot/Listeners/QQMessageListener.java index 86d0104..54fc18b 100644 --- a/src/main/java/com/yutou/qqbot/Listeners/QQMessageListener.java +++ b/src/main/java/com/yutou/qqbot/Listeners/QQMessageListener.java @@ -42,7 +42,6 @@ public class QQMessageListener extends SimpleListenerHost { Model useModel = (Model) model.getDeclaredConstructor().newInstance(); if (!useModel.isUserPublic()) { if (!QQNumberManager.getManager().isExistsPower(event.getSource().getFromId(), useModel.getUsePowers())) { - Log.i("用户没有权限",event.getSource().getFromId()+" > "+model.getSimpleName()); continue; } } diff --git a/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java b/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java index 6cf68a6..550915c 100644 --- a/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java +++ b/src/main/java/com/yutou/qqbot/MessageEvent/AdminMessage.java @@ -3,7 +3,10 @@ package com.yutou.qqbot.MessageEvent; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQNumberManager; import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.models.WebSign.BaiHeHui; +import com.yutou.qqbot.models.WebSign.Tsdm; import com.yutou.qqbot.utlis.AppTools; +import com.yutou.qqbot.utlis.Log; import com.yutou.qqbot.utlis.StringUtils; import java.util.List; @@ -24,6 +27,7 @@ public class AdminMessage extends Message { private static final String SHOW="!列表"; private static final String HELP="!help"; + private static final String SIGN="!签到"; } public AdminMessage(Long qq, String msg) { @@ -138,6 +142,27 @@ public class AdminMessage extends Message { System.out.println("结束进程"); AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false); } + case QQCommands.SIGN -> { + boolean sign=true; + Log.i("开始签到"); + try{ + new Tsdm().tsdmSign(); + }catch (Exception e){ + sign=false; + QQBotManager.getInstance().sendMessage(qq,"tsdm签到失败:"+AppTools.getExceptionString(e)); + e.printStackTrace(); + } + try { + new BaiHeHui().sign(); + }catch (Exception e){ + sign=false; + QQBotManager.getInstance().sendMessage(qq,"百合会签到失败:"+AppTools.getExceptionString(e)); + e.printStackTrace(); + } + if(sign){ + QQBotManager.getInstance().sendMessage(qq,"签到任务完成"); + } + } } } diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index ce00662..2bba941 100644 --- a/src/main/java/com/yutou/qqbot/QQBotApplication.java +++ b/src/main/java/com/yutou/qqbot/QQBotApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class QQBotApplication { - public static final String version="QQBot v.1.0.1"; + public static final String version="QQBot v.1.1.1"; public static void main(String[] args) { SpringApplication.run(QQBotApplication.class, args); RedisTools.initRedisPoolSub(); diff --git a/src/main/java/com/yutou/qqbot/models/Animal/TurnipProphet.java b/src/main/java/com/yutou/qqbot/models/Animal/TurnipProphet.java index 6c75185..4f38acf 100644 --- a/src/main/java/com/yutou/qqbot/models/Animal/TurnipProphet.java +++ b/src/main/java/com/yutou/qqbot/models/Animal/TurnipProphet.java @@ -4,10 +4,7 @@ import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.Model; -import com.yutou.qqbot.utlis.Log; -import com.yutou.qqbot.utlis.RedisTools; -import com.yutou.qqbot.utlis.StringUtils; -import com.yutou.qqbot.utlis.WebClient; +import com.yutou.qqbot.utlis.*; import net.mamoe.mirai.event.events.MessageEvent; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; @@ -43,7 +40,7 @@ public class TurnipProphet extends Model { } - static int nowTime; + static int nowTime=-1; @Override public boolean isUserPublic() { @@ -156,9 +153,7 @@ public class TurnipProphet extends Model { } } else { if (money >= 9 && money <= 660) { - System.out.println("array = " + array); - System.out.println("array.size() = " + array.size()); - if (nowTime < 12) { + if (getTime() < 12) { array.set(getDay() * 2 - 1, money); } else { array.set(getDay() * 2, money); @@ -189,7 +184,9 @@ public class TurnipProphet extends Model { QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势..."); Map map = openTurnip(prices, pattern); - + if(map==null){ + map=openTurnip(prices,pattern); + } String tmp_pattern = sendQQ(map, prices, pattern, qq); if (!StringUtils.isEmpty(tmp_pattern)) { json.put("pattern", tmp_pattern); @@ -197,21 +194,20 @@ public class TurnipProphet extends Model { RedisTools.set(redisKey, json.toJSONString()); } catch (Exception e) { - setData(money, qq); e.printStackTrace(); + setData(money, qq); } } private String sendQQ(Map map, String prices, String pattern, long qq) { - if (map == null) { String url = String.format("https://turnipprophet.io?prices=%s%s", prices, pattern == null ? "" : "&pattern=" + pattern ); - QQBotManager.getInstance().sendMessage(qq, "没有结果,请检查数据是否有误。 \n网页预览:" + url); + QQBotManager.getInstance().sendMessage(qq, "没有结果,请检查数据是否有误。 \n网页预览:\n" + url); return null; } @@ -221,7 +217,7 @@ public class TurnipProphet extends Model { out.append("预测结果如下:\n"); out.append(TurnipData.MODEL).append(prArray.getJSONObject(0).getString(TurnipData.MODEL)).append("\n"); out.append(TurnipData.PR).append(prArray.getJSONObject(0).getString(TurnipData.PR)).append("\n"); - + out.append("购入价:").append(prices.split("\\.")[0]).append("\n"); out.append(TurnipData.MIX).append(map.get(TurnipData.MIX)).append("\n") .append(TurnipData.MAX).append(map.get(TurnipData.MAX)).append("\n") .append(TurnipData.DAY).append(map.get(TurnipData.DAY)).append("\n") @@ -259,6 +255,12 @@ public class TurnipProphet extends Model { super.onTime(time); nowTime = Integer.parseInt(time.split(":")[0]); } + public int getTime(){ + if(nowTime==-1){ + nowTime=Integer.parseInt(AppTools.getHours()); + } + return nowTime; + } private int getDay() { return Calendar.getInstance().get(Calendar.DAY_OF_WEEK) - 1; @@ -266,7 +268,7 @@ public class TurnipProphet extends Model { public static void main(String[] args) throws Exception { TurnipProphet prophet = new TurnipProphet(); - prophet.setData(88, 583819556); + prophet.setData(68, 583819556); } @@ -284,10 +286,14 @@ public class TurnipProphet extends Model { driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); Thread.sleep(500); WebElement element = driver.findElement(By.id("output")); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); List list = element.findElements(By.tagName("tr")); + driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); JSONObject pr = new JSONObject(); JSONArray array = new JSONArray(); if (list.size() == 0) { + driver.close(); + driver.quit(); return null; } @@ -324,14 +330,24 @@ public class TurnipProphet extends Model { } } } + int maxMoney=0; + String maxDay=null; for (String key : map.keySet()) { - System.err.println("记录最高日:" + map.get(key) + " > " + key); - if (!key.equals(TurnipProphet.TurnipData.MAX) && - map.get(key).contains(map.get(TurnipProphet.TurnipData.MAX))) { - map.put(TurnipProphet.TurnipData.DAY, key); - break; + if(map.get(key).contains("~")){ + for (String s : map.get(key).split("~")) { + if(Integer.parseInt(s)>maxMoney){ + maxMoney=Integer.parseInt(s); + maxDay=key; + } + } + }else{ + if(Integer.parseInt(map.get(key))>maxMoney){ + maxMoney=Integer.parseInt(map.get(key)); + maxDay=key; + } } } + map.put(TurnipProphet.TurnipData.DAY, maxDay); pr.put(TurnipProphet.TurnipData.MODEL, array); map.put(TurnipProphet.TurnipData.MODEL, pr.toJSONString()); driver.close(); 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 4d89776..a8d9071 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java @@ -1,15 +1,19 @@ package com.yutou.qqbot.models.WebSign; import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.AppTools; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.StringUtils; import com.yutou.qqbot.utlis.WebClient; +import org.openqa.selenium.By; import org.openqa.selenium.Cookie; import org.openqa.selenium.WebDriver; +import org.openqa.selenium.WebElement; import java.io.File; +import java.util.concurrent.TimeUnit; public class BaiHeHui extends Model { @Override @@ -25,19 +29,27 @@ public class BaiHeHui extends Model { @Override public void onTime(String time) { super.onTime(time); - if("08:00".equals(time)){ - sign(); + if ("08:00".equals(time)) { + try { + sign(); + QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"百合会签到成功"); + } catch (Exception e) { + e.printStackTrace(); + QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"百合会签到失败:"+ AppTools.getExceptionString(e)); + } } } - private void sign(){ - String cookie= ConfigTools.readFile(new File("baihehui.json")); - if(StringUtils.isEmpty(cookie)){ + public void sign() { + String cookie = ConfigTools.readFile(new File("baihehui.json")); + if (StringUtils.isEmpty(cookie)) { return; } - WebDriver driver=WebClient.getInstance().getWebDriver(); - JSONArray array=JSONArray.parseArray(cookie); - driver.get("https://bbs.yamibo.com/plugin.php?id=study_daily_attendance:daily_attendance&fhash=425430f7"); + 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); } @@ -47,10 +59,17 @@ public class BaiHeHui extends Model { e.printStackTrace(); } driver.navigate().refresh(); - + for (WebElement element : driver.findElements(By.xpath("//a"))) { + if("打卡签到".equals(element.getText())){ + element.click(); + return; + } + } + driver.close(); + driver.quit(); } public static void main(String[] args) { - new BaiHeHui().sign(); + } } 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 e052651..09dfaae 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/Tsdm.java @@ -3,21 +3,16 @@ package com.yutou.qqbot.models.WebSign; import com.alibaba.fastjson.JSONArray; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.AppTools; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.StringUtils; import com.yutou.qqbot.utlis.WebClient; import net.mamoe.mirai.event.events.MessageEvent; -import org.openqa.selenium.By; -import org.openqa.selenium.Cookie; -import org.openqa.selenium.JavascriptExecutor; -import org.openqa.selenium.WebDriver; -import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.*; import java.io.File; import java.util.concurrent.TimeUnit; -import static com.yutou.qqbot.utlis.WebClient.getOptions; - public class Tsdm extends Model { @Override public boolean isUserPublic() { @@ -34,53 +29,74 @@ public class Tsdm extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if(msg.startsWith(QQFromCommands.TSDM_PAY)){ - String url=msg.replace(QQFromCommands.TSDM_PAY,"").trim(); - if(StringUtils.isEmpty(url)){ - QQBotManager.getInstance().sendMessage(qq,"使用说明:!tsdm [url]"); + if (msg.startsWith(QQFromCommands.TSDM_PAY)) { + String url = msg.replace(QQFromCommands.TSDM_PAY, "").trim(); + if (StringUtils.isEmpty(url)) { + QQBotManager.getInstance().sendMessage(qq, "使用说明:!tsdm [url]"); return; } - QQBotManager.getInstance().sendMessage(qq,"正在获取,请稍等..."); - QQBotManager.getInstance().sendMessage(qq,tsdm(url)); + QQBotManager.getInstance().sendMessage(qq, "正在获取,请稍等..."); + QQBotManager.getInstance().sendMessage(qq, tsdm(url)); } } @Override public void onTime(String time) { super.onTime(time); - if("08:00".equals(time)){ - tsdmSign(); - QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"已完成天使动漫的签到"); + if ("08:00".equals(time)) { + try { + tsdmSign(); + QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "已完成天使动漫的签到"); + } catch (Exception e) { + QQBotManager.getInstance().sendMessage(QQBotManager.defGroup, "天使动漫签到失败:" + AppTools.getExceptionString(e)); + e.printStackTrace(); + } } } - public void tsdmSign(){ + public void tsdmSign() { JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json"))); if (array == null) { System.err.println("array is null"); return; } - WebDriver driver =WebClient.getInstance().getWebDriver(); + 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; + } + } + if(!isSign){ + driver.close(); + driver.quit(); + return; + } try { ((JavascriptExecutor) driver).executeScript("showWindow('dsu_paulsign', 'plugin.php?id=dsu_paulsign:sign&9b5e8da2')"); - }catch (Exception ignored){ + } catch (Exception ignored) { } try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } - driver.findElement(By.id("wl")).click(); - driver.findElement(By.xpath("//input[@value='3']")).click(); - driver.findElement(By.id("qiandao")).submit(); + 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(); + } driver.close(); driver.quit(); } private void getTsdm(JSONArray array, WebDriver driver) { driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); + driver.manage().deleteAllCookies(); try { Thread.sleep(500); } catch (InterruptedException e) { @@ -103,7 +119,7 @@ public class Tsdm extends Model { System.err.println("array is null"); return null; } - WebDriver driver =WebClient.getInstance().getWebDriver(); + WebDriver driver = WebClient.getInstance().getWebDriver(); driver.get(url); getTsdm(array, driver); try { diff --git a/src/main/java/com/yutou/qqbot/utlis/AppTools.java b/src/main/java/com/yutou/qqbot/utlis/AppTools.java index 7a421c1..2b888d7 100644 --- a/src/main/java/com/yutou/qqbot/utlis/AppTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/AppTools.java @@ -31,6 +31,9 @@ public class AppTools { public static String getToDayTime() { return new SimpleDateFormat("yyyy-MM-dd").format(new Date()); } + public static String getHours(){ + return new SimpleDateFormat("HH").format(new Date()); + } /** * 异常输出 * diff --git a/src/main/java/com/yutou/qqbot/utlis/WebClient.java b/src/main/java/com/yutou/qqbot/utlis/WebClient.java index 4cc5eac..2ac29aa 100644 --- a/src/main/java/com/yutou/qqbot/utlis/WebClient.java +++ b/src/main/java/com/yutou/qqbot/utlis/WebClient.java @@ -21,9 +21,11 @@ public class WebClient { } return client; } - public WebDriver getWebDriver(){ + + public WebDriver getWebDriver() { return new ChromeDriver(getOptions()); } + private WebClient() { System.setProperty("webdriver.chrome.driver", ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class)); @@ -31,27 +33,22 @@ public class WebClient { } - - - - - - public static List loadCookie(JSONArray array){ - List list=new ArrayList<>(); + public static List loadCookie(JSONArray array) { + List list = new ArrayList<>(); for (Object o : array) { JSONObject json = (JSONObject) o; - boolean containsDate=json.containsKey("expirationDate"); - long t=0; - if(containsDate) { - t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000; + boolean containsDate = json.containsKey("expirationDate"); + long t = 0; + if (containsDate) { + t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000; } Cookie cookie = new Cookie(json.getString("name"), json.getString("value"), json.getString("domain"), json.getString("path"), - containsDate? new Date(t):null, + containsDate ? new Date(t) : new Date(), json.getBoolean("secure"), json.getBoolean("httpOnly") @@ -63,9 +60,9 @@ public class WebClient { public static ChromeOptions getOptions() { ChromeOptions options = new ChromeOptions(); - options.addArguments("disable-infobars"); - options.addArguments("blink-settings=imagesEnabled=false"); - options.addArguments("--headless"); + options.addArguments("--disable-gpu"); + // options.addArguments("blink-settings=imagesEnabled=false"); + options.addArguments("--headless"); options.addArguments("--no-sandbox"); return options;