新增天使动漫下载以及自动签到
This commit is contained in:
parent
4c2f4abaa5
commit
90b9718471
@ -4,6 +4,7 @@ import com.yutou.qqbot.Listeners.QQMessageListener;
|
||||
import com.yutou.qqbot.models.Animal.TurnipProphet;
|
||||
import com.yutou.qqbot.models.Commands.Bangumi;
|
||||
import com.yutou.qqbot.models.Commands.System.*;
|
||||
import com.yutou.qqbot.models.Commands.Tsdm;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.models.setu.QQSetu;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
@ -38,6 +39,7 @@ public class QQBotManager {
|
||||
Model.classList.add(Bangumi.class);
|
||||
|
||||
Model.classList.add(TurnipProphet.class);
|
||||
Model.classList.add(Tsdm.class);
|
||||
}
|
||||
private static QQBotManager botManager = null;
|
||||
private Bot bot;
|
||||
|
44
src/main/java/com/yutou/qqbot/models/Commands/Tsdm.java
Normal file
44
src/main/java/com/yutou/qqbot/models/Commands/Tsdm.java
Normal file
@ -0,0 +1,44 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import com.yutou.qqbot.utlis.WebClient;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
|
||||
public class Tsdm extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[]{
|
||||
QQFromCommands.TSDM_PAY
|
||||
};
|
||||
}
|
||||
|
||||
@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]");
|
||||
return;
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在获取,请稍等...");
|
||||
QQBotManager.getInstance().sendMessage(qq,WebClient.getInstance().tsdm(url));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(String time) {
|
||||
super.onTime(time);
|
||||
if("08:00".equals(time)){
|
||||
WebClient.getInstance().tsdmSign();
|
||||
QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,"已完成天使动漫的签到");
|
||||
}
|
||||
}
|
||||
}
|
@ -36,6 +36,8 @@ public abstract class Model implements ModelInterface {
|
||||
|
||||
public static class QQFromCommands {
|
||||
public static final String TURNIP_PROPHET = "大头菜";
|
||||
public static final String TSDM_PAY = "!tsdm";
|
||||
public static final String TSDM_SIGN = "!tsdm签到";
|
||||
}
|
||||
|
||||
|
||||
|
@ -3,17 +3,16 @@ package com.yutou.qqbot.utlis;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.yutou.qqbot.models.Animal.TurnipProphet;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.*;
|
||||
import org.openqa.selenium.chrome.ChromeDriver;
|
||||
import org.openqa.selenium.chrome.ChromeOptions;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class WebClient {
|
||||
private static WebClient client;
|
||||
@ -28,12 +27,12 @@ public class WebClient {
|
||||
|
||||
private WebClient() {
|
||||
System.setProperty("webdriver.chrome.driver",
|
||||
ConfigTools.load(ConfigTools.CONFIG,"chrome",String.class));
|
||||
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
||||
ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class));
|
||||
// java.util.logging.Logger.getLogger("org.openqa.selenium").setLevel(Level.OFF);
|
||||
}
|
||||
|
||||
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
||||
String url=String.format("https://turnipprophet.io?prices=%s%s",
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
@ -48,7 +47,7 @@ public class WebClient {
|
||||
List<WebElement> list = element.findElements(By.tagName("tr"));
|
||||
JSONObject pr = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
if(list.size()==0){
|
||||
if (list.size() == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -86,7 +85,7 @@ public class WebClient {
|
||||
}
|
||||
}
|
||||
for (String key : map.keySet()) {
|
||||
System.err.println("记录最高日:"+map.get(key)+" > "+key);
|
||||
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);
|
||||
@ -96,20 +95,100 @@ public class WebClient {
|
||||
pr.put(TurnipProphet.TurnipData.MODEL, array);
|
||||
map.put(TurnipProphet.TurnipData.MODEL, pr.toJSONString());
|
||||
webDriver.close();
|
||||
webDriver.quit();
|
||||
return map;
|
||||
}
|
||||
|
||||
public String tsdm(String url) {
|
||||
JSONArray array = JSONArray.parseArray(ConfigTools.readFile(new File("cookie.json")));
|
||||
if (array == null) {
|
||||
System.err.println("array is null");
|
||||
return null;
|
||||
}
|
||||
WebDriver driver = new ChromeDriver(getOptions());
|
||||
driver.get(url);
|
||||
getTsdm(array, driver);
|
||||
try {
|
||||
((JavascriptExecutor) driver).executeScript("document.getElementsByClassName('y viewpay')[0].click()");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
driver.findElement(By.id("payform")).submit();
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
String body = driver.findElement(By.name("tsdmlz")).getText();
|
||||
driver.close();
|
||||
driver.quit();
|
||||
return body;
|
||||
}
|
||||
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 = new ChromeDriver(getOptions());
|
||||
driver.get("https://www.tsdm39.net/forum.php");
|
||||
getTsdm(array, driver);
|
||||
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();
|
||||
}
|
||||
driver.findElement(By.id("wl")).click();
|
||||
driver.findElement(By.xpath("//input[@value='3']")).click();
|
||||
driver.findElement(By.id("qiandao")).submit();
|
||||
driver.close();
|
||||
driver.quit();
|
||||
}
|
||||
|
||||
private void getTsdm(JSONArray array, WebDriver driver) {
|
||||
driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS);
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (Object o : array) {
|
||||
JSONObject json = (JSONObject) o;
|
||||
long t = Long.parseLong(json.getString("expirationDate").replace(".", "")) / 1000;
|
||||
Cookie cookie = new Cookie(json.getString("name"),
|
||||
json.getString("value"),
|
||||
json.getString("domain"),
|
||||
json.getString("path"),
|
||||
new Date(t),
|
||||
json.getBoolean("secure"),
|
||||
json.getBoolean("httpOnly")
|
||||
|
||||
);
|
||||
driver.manage().addCookie(cookie);
|
||||
}
|
||||
driver.navigate().refresh();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private ChromeOptions getOptions() {
|
||||
ChromeOptions options = new ChromeOptions();
|
||||
options.addArguments("disable-infobars");
|
||||
options.addArguments("blink-settings=imagesEnabled=false");
|
||||
options.addArguments("--headless");
|
||||
options.addArguments("disable-infobars");
|
||||
options.addArguments("blink-settings=imagesEnabled=false");
|
||||
options.addArguments("--headless");
|
||||
options.addArguments("--no-sandbox");
|
||||
|
||||
return options;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
WebClient.getInstance().tsdmSign();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user