From 0ee1be5f047f940edaf8167a29adb52ed778f207 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 22 Aug 2022 21:39:06 +0800 Subject: [PATCH 01/54] tmp --- .../qqbot/Controllers/CalendarController.java | 26 ++ .../yutou/qqbot/bilibili/BiliBiliUtils.java | 6 + .../yutou/qqbot/data/jianr/AndroidDevice.java | 14 ++ .../com/yutou/qqbot/data/jianr/Vector2D.java | 7 + .../com/yutou/qqbot/utlis/CalendarTools.java | 61 +++++ .../yutou/qqbot/utlis/JianRTaskManager.java | 229 ++++++++++++++---- .../com/yutou/qqbot/utlis/RedisTools.java | 4 +- web/calendar.html | 122 ++++++++++ 8 files changed, 418 insertions(+), 51 deletions(-) create mode 100644 src/main/java/com/yutou/qqbot/Controllers/CalendarController.java create mode 100644 src/main/java/com/yutou/qqbot/utlis/CalendarTools.java create mode 100644 web/calendar.html diff --git a/src/main/java/com/yutou/qqbot/Controllers/CalendarController.java b/src/main/java/com/yutou/qqbot/Controllers/CalendarController.java new file mode 100644 index 0000000..4e803ed --- /dev/null +++ b/src/main/java/com/yutou/qqbot/Controllers/CalendarController.java @@ -0,0 +1,26 @@ +package com.yutou.qqbot.Controllers; + +import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.utlis.CalendarTools; +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.ResponseBody; + +@Controller +public class CalendarController { + @ResponseBody + @RequestMapping("/calendar/all.do") + public JSONObject getCalendar(){ + JSONObject json = new JSONObject(); + JSONObject holiday= CalendarTools.getHoliday(); + json.put("data",holiday); + return json; + } + @ResponseBody + @RequestMapping("/calendar/set.do") + public JSONObject setCalendar(String startDate,String interval){ + JSONObject json = new JSONObject(); + + return json; + } +} diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index b062569..ca1fe89 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -294,4 +294,10 @@ public class BiliBiliUtils { } return jsonObject; } + + public static void main(String[] args) { + String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; + File file=BiliBiliUtils.download(url,"16.mp4",false); + System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath()); + } } diff --git a/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java b/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java index 48b9043..95e39a7 100644 --- a/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java +++ b/src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java @@ -30,6 +30,20 @@ public class AndroidDevice { public double getHeight() { return end.getY() - start.getY(); } + + public void setEnabledRandom(boolean enabled) { + if(enabled){ + start.setEnableRandomY(true); + start.setEnableRandomX(true); + end.setEnableRandomX(true); + end.setEnableRandomY(true); + }else{ + start.setEnableRandomX(false); + start.setEnableRandomY(false); + end.setEnableRandomY(false); + end.setEnableRandomX(false); + } + } } } diff --git a/src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java b/src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java index e703492..0ff531b 100644 --- a/src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java +++ b/src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java @@ -23,6 +23,13 @@ public class Vector2D { } return x; } + public double getNotRandomY() { + return y; + } + public double getNotRandomX() { + return x; + } + public double getY() { if(isEnableRandomY()){ diff --git a/src/main/java/com/yutou/qqbot/utlis/CalendarTools.java b/src/main/java/com/yutou/qqbot/utlis/CalendarTools.java new file mode 100644 index 0000000..b060e4c --- /dev/null +++ b/src/main/java/com/yutou/qqbot/utlis/CalendarTools.java @@ -0,0 +1,61 @@ +package com.yutou.qqbot.utlis; + +import com.alibaba.fastjson2.JSONObject; + +import java.text.DateFormat; +import java.util.Calendar; +import java.util.Locale; +import java.util.Set; + +public class CalendarTools { + private static final String REDIS_TAG="Calendar"; + public static JSONObject getHoliday() { + int month = Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA).get(Calendar.MONTH) + 1; + int year = Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA).get(Calendar.YEAR); + return getHoliday(year + "", null); + } + + public static JSONObject getHoliday(String year, String month) { + String get = HttpTools.get(String.format("https://timor.tech/api/holiday/year/%s", year)); + JSONObject json = JSONObject.parseObject(get); + JSONObject date = new JSONObject(); + JSONObject dateHoliday = new JSONObject(); + JSONObject holiday = json.getJSONObject("holiday"); + for (String key : holiday.keySet()) { + JSONObject _tmp = holiday.getJSONObject(key); + date.put(year + "-" + key, _tmp.getString("name")); + dateHoliday.put(year + "-" + key, _tmp.getBooleanValue("holiday")); + } + JSONObject tmp = new JSONObject(); + tmp.put("date", date); + tmp.put("holiday", dateHoliday); + return tmp; + } + public static boolean isHoliday() { + Calendar calendar=Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA); + Calendar calendar2=Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA); + Set list = RedisTools.list_get(REDIS_TAG); + for (String s : list) { + + } + return false; + } + + public static void main(String[] args) { + Calendar calendar=Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA); + Calendar calendar2=Calendar.getInstance(DateFormat.getDateInstance().getTimeZone(), Locale.CHINA); + int start = 6; + int in = 14; + calendar.set(Calendar.MONTH,7); + calendar.set(Calendar.DATE,start); + calendar2.set(Calendar.DATE,13); + long t2=calendar2.getTime().getTime(); + long t1=calendar.getTime().getTime(); + long l = calendar2.getTime().getTime() - calendar.getTime().getTime(); + long interval=l/1000/60/60/24; + System.out.println(interval); + System.out.println("t1 = " + t1); + System.out.println("t2 = " + t2); + System.out.println("interval = " + interval%in); + } +} diff --git a/src/main/java/com/yutou/qqbot/utlis/JianRTaskManager.java b/src/main/java/com/yutou/qqbot/utlis/JianRTaskManager.java index a218c35..5356958 100644 --- a/src/main/java/com/yutou/qqbot/utlis/JianRTaskManager.java +++ b/src/main/java/com/yutou/qqbot/utlis/JianRTaskManager.java @@ -1,14 +1,19 @@ package com.yutou.qqbot.utlis; import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import com.yutou.qqbot.data.jianr.AndroidDevice; import com.yutou.qqbot.data.jianr.JianRScriptData; import com.yutou.qqbot.data.jianr.JianRScriptV2Data; import com.yutou.qqbot.data.jianr.Vector2D; +import com.yutou.qqbot.interfaces.ObjectInterface; +import lombok.SneakyThrows; -import java.util.ArrayList; -import java.util.List; +import javax.imageio.ImageIO; +import java.awt.image.BufferedImage; +import java.io.File; import java.util.Random; +import java.util.TreeMap; public class JianRTaskManager { public static final String Redis_Script = "jianrScript_Script"; @@ -49,10 +54,10 @@ public class JianRTaskManager { } public void start() { - if (running||runStatus) { + if (running || runStatus) { return; } - runStatus=true; + runStatus = true; running = true; new Thread(new Runnable() { @@ -68,10 +73,16 @@ public class JianRTaskManager { } log(script.getTitle()); JianRTaskManager.this.run(device, modelId, script); - try { + /* try { Thread.sleep((long) getRandom(0, script.getRandomNextWaitTime() * 1000, script.getNextWaitTime() * 1000)); } catch (Exception e) { throw new RuntimeException(e); + }*/ + while (true){ + if(waitGame(device,modelId,script)){ + System.out.println("next"); + break; + } } } runIndex++; @@ -82,43 +93,87 @@ public class JianRTaskManager { } } - runStatus=false; + runStatus = false; log("终止任务"); } }).start(); } + Vector2D nowVector2D = null; + private void run(AndroidDevice device, int modelId, JianRScriptV2Data.Script script) { AndroidDevice.GameDisplay gameDisplay = device.getDeviceDisplay().get(modelId); - Vector2D vector2D = null; switch (script.getActivity()) { case JianRScriptV2Data.ScriptModel.MAP: - vector2D = getMapCoords(device, gameDisplay); + nowVector2D = getMapCoords(device, gameDisplay); break; case JianRScriptV2Data.ScriptModel.attack: - vector2D = getAttackCoords(device, gameDisplay); + nowVector2D = getAttackCoords(device, gameDisplay); break; case JianRScriptV2Data.ScriptModel.dialog_go: - vector2D = getDialogCoords(device, gameDisplay, false); + nowVector2D = getDialogCoords(device, gameDisplay, false); break; case JianRScriptV2Data.ScriptModel.dialog_back: - vector2D = getDialogCoords(device, gameDisplay, true); + nowVector2D = getDialogCoords(device, gameDisplay, true); break; case JianRScriptV2Data.ScriptModel.dialog_assets: - vector2D = getDialogAssetsCoords(device, gameDisplay); + nowVector2D = getDialogAssetsCoords(device, gameDisplay); break; case JianRScriptV2Data.ScriptModel.none: - vector2D=getNoneCoords(device, gameDisplay); + nowVector2D = getNoneCoords(device, gameDisplay); break; default: if (script.getActivity().startsWith(JianRScriptV2Data.ScriptModel.formationType)) { - vector2D = getNextFormationCoords(device, gameDisplay, Integer.parseInt(script.getActivity().split("#")[1])); + nowVector2D = getNextFormationCoords(device, gameDisplay, Integer.parseInt(script.getActivity().split("#")[1])); } } - if (vector2D != null) { - adb(device, vector2D); + if (nowVector2D != null) { + adb(device, nowVector2D); } } + private boolean isAttack=false; + private boolean isFormation=false; + private boolean waitGame(AndroidDevice device, int modelId,JianRScriptV2Data.Script script) { + AndroidDevice.GameDisplay gameDisplay = device.getDeviceDisplay().get(modelId); + String ocr; + switch (script.getActivity()) { + case JianRScriptV2Data.ScriptModel.MAP: + ocr=screen(gameDisplay,getAttackCoords(device,gameDisplay)); + System.out.println("ocr = " + ocr); + if(ocr.trim().contains("开始出征")){ + return true; + } + break; + case JianRScriptV2Data.ScriptModel.attack: + ocr=screen(gameDisplay,getAttackCoords(device,gameDisplay)); + System.out.println("ocr = " + ocr); + if(ocr.trim().contains("开始战斗")){ + isAttack=true; + } + if(isAttack){ + run(device, modelId, script); + isFormation= true; + } + if(isFormation){ + ocr=screen(gameDisplay,getDialogCoords(device,gameDisplay,true)); + String tmp=screen(gameDisplay,getContinueCoords(device,gameDisplay)); + if(ocr.contains("放弃")||tmp.contains("继续")){ + + } + } + break; + case JianRScriptV2Data.ScriptModel.dialog_go: + break; + case JianRScriptV2Data.ScriptModel.dialog_back: + break; + case JianRScriptV2Data.ScriptModel.dialog_assets: + break; + case JianRScriptV2Data.ScriptModel.none: + break; + default: + } + return false; + } public void stop() { task = null; @@ -194,6 +249,13 @@ public class JianRTaskManager { return v2d; } + private Vector2D getContinueCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay) { + Vector2D v2d = new Vector2D(); + v2d.setX(gameDisplay.getWidth() * 0.8725 + gameDisplay.getStart().getX()); + v2d.setY(gameDisplay.getHeight() * 0.9 + gameDisplay.getStart().getY()); + return v2d; + } + /** * 获取地图点击坐标 * @@ -225,6 +287,13 @@ public class JianRTaskManager { return v2d; } + public Vector2D getBottomLeft(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay) { + Vector2D v2d = new Vector2D(); + v2d.setX(gameDisplay.getStart().getX()); + v2d.setY(gameDisplay.getEnd().getY()); + return v2d; + } + /** * 获取出击坐标 * @@ -253,47 +322,109 @@ public class JianRTaskManager { v2d.setY(gameDisplay.getHeight() * 0.5433 + gameDisplay.getStart().getY()); return v2d; } - private Vector2D getNoneCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay){ + + private Vector2D getNoneCoords(AndroidDevice device, AndroidDevice.GameDisplay gameDisplay) { Vector2D v2d = new Vector2D(); v2d.setX(gameDisplay.getWidth() * 0.1 + gameDisplay.getStart().getX()); v2d.setY(gameDisplay.getHeight() * 0.1 + gameDisplay.getStart().getY()); return v2d; } + @SneakyThrows public static void main(String[] args) { - AndroidDevice device = new AndroidDevice(); - AndroidDevice.DeviceDisplay deviceDisplay = new AndroidDevice.DeviceDisplay(); - AndroidDevice.GameDisplay gameDisplay = new AndroidDevice.GameDisplay(); - deviceDisplay.setHeight(1800); - deviceDisplay.setWidth(2800); - Vector2D start = new Vector2D(); - Vector2D end = new Vector2D(); - start.setX(2000); - start.setY(57); - end.setX(2800); - end.setY(581); - gameDisplay.setStart(start); - gameDisplay.setEnd(end); - List displays = new ArrayList<>(); - displays.add(gameDisplay); - device.setDeviceDisplay(displays); - device.setAndroidDevice(deviceDisplay); - device.setDeviceId("192.168.31.142:6666"); - device.setTitle("SAMSUNG-TAB-S7+"); + JSONObject json = new JSONObject(); + String data = RedisTools.getHashMap(JianRTaskManager.Redis_Script, "7-1刷A点"); + String deviceJsonString = RedisTools.getHashMap(JianRTaskManager.Redis_Device, "三星平板"); + if (data == null || deviceJsonString == null) { + json.put("code", -1); + json.put("msg", "没有找到该方案或设备错误,请配置"); + } else { + JianRScriptV2Data script = JSON.parseObject(data, JianRScriptV2Data.class); + AndroidDevice androidDevice = JSON.parseObject(deviceJsonString, AndroidDevice.class); + JianRTaskManager manager = JianRTaskManager.getInstance(); + if (manager.isRunning()) { + manager.stop(); + } + for (int i = 0; i < androidDevice.getDeviceDisplay().size(); i++) { + if (androidDevice.getDeviceDisplay().get(i).getTitle().equals("全屏模式")) { + manager.setModelId(i); + break; + } + } + manager.setTask(script, androidDevice); + manager.start(); + } + } - JianRTaskManager manager = new JianRTaskManager(); - Vector2D mapCoords; - // mapCoords = manager.getMapCoords(device,device.getGameDisplay().get(0)); - // mapCoords = manager.getAttackCoords(device,device.getGameDisplay().get(0)); - // mapCoords = manager.getNextFormationCoords(device,device.getGameDisplay().get(0), 0); - mapCoords = manager.getDialogCoords(device, device.getDeviceDisplay().get(0), true); - // adb(device, mapCoords); - System.out.println("device = " + device); - String jsonString = "{\"name\":\"1-1Test\",\"script\":[{\"name\":\"点击地图\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"出击\",\"activity\":\"attack\",\"nextWaitTime\":12,\"randomNextWaitTime\":2},{\"name\":\"战斗\",\"activity\":\"attack\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"选择单纵\",\"activity\":\"formationType#0\",\"nextWaitTime\":20,\"randomNextWaitTime\":5},{\"name\":\"结算1\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"结算2\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"获取舰娘\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"前进\",\"activity\":\"dialog_go\",\"nextWaitTime\":12,\"randomNextWaitTime\":3},{\"name\":\"战斗\",\"activity\":\"attack\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"选择梯形\",\"activity\":\"formationType#3\",\"nextWaitTime\":20,\"randomNextWaitTime\":5},{\"name\":\"结算1\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"结算2\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3},{\"name\":\"获取舰娘\",\"activity\":\"map\",\"nextWaitTime\":2,\"randomNextWaitTime\":3}]}"; - JianRScriptV2Data script = JSON.parseObject(jsonString, JianRScriptV2Data.class); - manager.setTask(script, device); - manager.setModelId(0); - manager.start(); + public File cut(Vector2D v2d) { + try { + System.out.println("v2d = " + v2d); + int x = (int) v2d.getNotRandomX() - 150; + int y = (int) v2d.getNotRandomY() - 50; + if (y + 150 > device.getAndroidDevice().getHeight()) { + y -= 100; + } + if (y < 0) { + y = 0; + } + if (x + 450 > device.getAndroidDevice().getWidth()) { + x -= 300; + } + if (x < 0) { + x = 0; + } + System.out.println("x = " + x); + System.out.println("y = " + y); + BufferedImage bufImage = ImageIO.read(new File("1.png")); + BufferedImage bufferedImage = bufImage.getSubimage(x, y, 400, 100); + File imgCutFile = new File("tmp.png"); + ImageIO.write(bufferedImage, "PNG", imgCutFile); + return imgCutFile; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private static String ocr(File file) { + String exec = "\"C:\\Program Files\\Tesseract-OCR\\tesseract.exe\" " + file.getAbsolutePath() + " - -l chi_sim --psm 6"; + return AppTools.exec(exec, null, false, true).replace("\r", "").replace("\n", ""); + } + + private String screen(AndroidDevice.GameDisplay gameDisplay, Vector2D v2d) { + AppTools.exec("adb exec-out screencap -p > 1.png", null, false, false); + gameDisplay.setEnabledRandom(false); + File file = cut(v2d); + return ocr(file); + } + + public void test() { + String data = RedisTools.getHashMap(JianRTaskManager.Redis_Script, "7-1刷A点"); + String deviceJsonString = RedisTools.getHashMap(JianRTaskManager.Redis_Device, "三星平板"); + JianRScriptV2Data script = JSON.parseObject(data, JianRScriptV2Data.class); + AndroidDevice androidDevice = JSON.parseObject(deviceJsonString, AndroidDevice.class); + this.device = androidDevice; + this.task = script; + this.modelId = 1; + System.out.println("download image"); + AppTools.exec("adb exec-out screencap -p > 1.png", new ObjectInterface() { + @Override + public void out(String data) { + super.out(data); + AndroidDevice dev = device; + AndroidDevice.GameDisplay gameDisplay = device.getDeviceDisplay().get(modelId); + gameDisplay.setEnabledRandom(false); + Vector2D v2d; + v2d = getBottomLeft(device, gameDisplay); + v2d = getNextFormationCoords(device, gameDisplay, 4); + v2d = getAttackCoords(device, gameDisplay); + v2d = getDialogCoords(device, device.getDeviceDisplay().get(modelId), true); + v2d = getContinueCoords(device, gameDisplay); + File file = cut(v2d); + String ocr = ocr(file); + System.out.println(ocr.trim()); + } + }, false, true); } private void adb(AndroidDevice device, Vector2D v2d) { diff --git a/src/main/java/com/yutou/qqbot/utlis/RedisTools.java b/src/main/java/com/yutou/qqbot/utlis/RedisTools.java index 0c8284d..0cc9ea8 100644 --- a/src/main/java/com/yutou/qqbot/utlis/RedisTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/RedisTools.java @@ -204,9 +204,9 @@ public class RedisTools { public static boolean setHashMap(String hashKey, String key, String value) { Jedis jedis = getRedis(); - long l = jedis.hsetnx(hashKey, key, value); + long l = jedis.hset(hashKey, key, value); jedis.close(); - return l > 0; + return l == 0; } public static boolean removeHashMap(String hashKey, String key) { diff --git a/web/calendar.html b/web/calendar.html new file mode 100644 index 0000000..a667078 --- /dev/null +++ b/web/calendar.html @@ -0,0 +1,122 @@ + + + + + + BiliBili下载器 + + + + + + + +
+
日历管理 +
+ +


+ +
+ +
+
+ +
+
+
+
+
+
+
+
+ +
+ +
+
+
日期选择 +
+
+ +
+ +
+
+
+ +
+ + +
+
+ + + + + + + + \ No newline at end of file -- 2.43.0 From f296d4c819b217d221cb7497d65ee35a62d0e90e Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 1 Sep 2022 21:27:07 +0800 Subject: [PATCH 02/54] =?UTF-8?q?=E6=9B=B4=E6=96=B0layui=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- web/calendar.html | 45 ++++++++++--------- web/layui/css/layui.css | 2 +- web/layui/css/modules/code.css | 2 +- .../css/modules/laydate/default/laydate.css | 2 +- web/layui/css/modules/layer/default/layer.css | 2 +- web/layui/layui.js | 6 +-- 6 files changed, 28 insertions(+), 31 deletions(-) diff --git a/web/calendar.html b/web/calendar.html index a667078..73db49f 100644 --- a/web/calendar.html +++ b/web/calendar.html @@ -63,40 +63,41 @@ - - \ No newline at end of file -- 2.43.0 From f0d61ffbb60928b9047568ed79c1ac8b0a96fad7 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 9 Oct 2022 00:03:34 +0800 Subject: [PATCH 05/54] =?UTF-8?q?=E6=9B=BF=E6=8D=A2BT=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/QQBotApplication.java | 2 +- src/main/java/com/yutou/qqbot/models/Commands/BTDownload.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index 3cebb3a..1408e3a 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.3.5.1"; + public static final String version="QQBot v.1.3.5.2"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/models/Commands/BTDownload.java b/src/main/java/com/yutou/qqbot/models/Commands/BTDownload.java index bf5aae7..0fc326b 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/BTDownload.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/BTDownload.java @@ -32,7 +32,7 @@ public class BTDownload extends Model { if(msg.startsWith("magnet:?xt=")){ String builder = "已添加下载磁链" ; QQBotManager.getInstance().sendMessage(qq, builder); - String exec = String.format("transmission-remote -n yutou:34864394 -w %sdownload_tmp/%s -a \"%s\" " + String exec = String.format("qbittorrent-nox --save-path=%sdownload_tmp/%s \"%s\" " ,DownloadHomePath , AppTools.getToDayTime() , msg -- 2.43.0 From 1908c905acfaa1ec9c687c0cfa31acfd04153965 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 13 Oct 2022 23:28:04 +0800 Subject: [PATCH 06/54] =?UTF-8?q?=E4=B8=8B=E8=BD=BD=E5=99=A8=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/Controllers/AppController.java | 2 +- .../yutou/qqbot/models/Commands/Bangumi.java | 2 +- .../java/com/yutou/qqbot/utlis/HttpTools.java | 20 ++++++++++++++----- .../java/com/yutou/qqbot/utlis/IdeaTools.java | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/Controllers/AppController.java b/src/main/java/com/yutou/qqbot/Controllers/AppController.java index c733677..7ce89b4 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/AppController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/AppController.java @@ -69,7 +69,7 @@ public class AppController { return "not message"; } if (json.containsKey("image")) { - image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png"); + image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png",true); } if (image != null) { ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); diff --git a/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java b/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java index 55a2c03..807964f 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/Bangumi.java @@ -88,7 +88,7 @@ public class Bangumi extends Model { return; } for (String img : imgs) { - File file = HttpTools.syncDownload(img.replace("http://", "https://"), key + ".jpg"); + File file = HttpTools.syncDownload(img.replace("http://", "https://"), key + ".jpg",false); files.add(file); send(imgs.size(), qq, text); } diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index 87b329c..4e57641 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -24,8 +24,8 @@ public class HttpTools { return http_post(url, body, 0, null); } - public static File syncDownload(final String url, final String saveName) { - return new HttpTools().http_syncDownload(url, saveName); + public static File syncDownload(final String url, final String saveName,boolean isProxy) { + return new HttpTools().http_syncDownload(url, saveName,isProxy); } public static String https_get(String url, Map header) { @@ -158,7 +158,7 @@ public class HttpTools { } public static void main(String[] args) { - File file = syncDownload("https://lain.bgm.tv/pic/cover/l/6c/2a/302128_qQIjG.jpg", "12345.jpg"); + File file = syncDownload("https://lain.bgm.tv/pic/cover/l/6c/2a/302128_qQIjG.jpg", "12345.jpg",false); System.out.println("file.length() = " + file.length()); } @@ -249,7 +249,7 @@ public class HttpTools { }).start(); } - public synchronized File http_syncDownload(final String url, final String saveName) { + public synchronized File http_syncDownload(final String url, final String saveName,boolean isProxy) { if (StringUtils.isEmpty(url)) { return null; } @@ -259,8 +259,18 @@ public class HttpTools { if (!savePath.exists()) { savePath.mkdirs(); } + Proxy proxy = null; + if (isProxy) { + proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890)); + } + Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName); - HttpURLConnection connection = (HttpURLConnection) new URL(url).openConnection(); + HttpURLConnection connection; + if(proxy==null) { + connection = (HttpURLConnection) new URL(url).openConnection(); + }else{ + connection = (HttpURLConnection) new URL(url).openConnection(proxy); + } connection.addRequestProperty("User-Agent", getExtUa()); // Log.i(TAG,"获取到网络请求:"+connection.getResponseCode()); diff --git a/src/main/java/com/yutou/qqbot/utlis/IdeaTools.java b/src/main/java/com/yutou/qqbot/utlis/IdeaTools.java index 0037af9..49eb013 100644 --- a/src/main/java/com/yutou/qqbot/utlis/IdeaTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/IdeaTools.java @@ -30,7 +30,7 @@ public class IdeaTools { } public static List getIdeaList(String url) { - File file = HttpTools.syncDownload(url, "idea.zip"); + File file = HttpTools.syncDownload(url, "idea.zip",false); List list = new ArrayList<>(); try { ZipFile zip = new ZipFile(file, Charset.forName("gbk")); -- 2.43.0 From de1fe79b093923d277f4958faf541057fafb387e Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 13 Oct 2022 23:50:37 +0800 Subject: [PATCH 07/54] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=A9=E5=9B=BE?= =?UTF-8?q?=E7=BA=BF=E4=B8=8A=E8=A7=82=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index 08ef889..a3e77eb 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -215,6 +215,7 @@ public class GetSeTu extends Model { @Override public void onDownload(File file) { super.onDownload(file); + builder.append("看不到图?点这里:http://setu.cnmglz.com/setu/").append(file.getName()); QQBotManager.getInstance().sendMessage(file, qq, event.getMessage(), ""); MessageChainBuilder chain = new MessageChainBuilder(); chain.append(new QuoteReply(event.getMessage())); -- 2.43.0 From fe48b030d91e455d1b2ea71820f634f783ec29c7 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 13 Oct 2022 23:51:52 +0800 Subject: [PATCH 08/54] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=B6=A9=E5=9B=BE?= =?UTF-8?q?=E7=BA=BF=E4=B8=8A=E8=A7=82=E7=9C=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index a3e77eb..a891e00 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -215,7 +215,7 @@ public class GetSeTu extends Model { @Override public void onDownload(File file) { super.onDownload(file); - builder.append("看不到图?点这里:http://setu.cnmglz.com/setu/").append(file.getName()); + builder.append("\n看不到图?点这里:http://setu.cnmglz.com/setu/").append(file.getName()); QQBotManager.getInstance().sendMessage(file, qq, event.getMessage(), ""); MessageChainBuilder chain = new MessageChainBuilder(); chain.append(new QuoteReply(event.getMessage())); -- 2.43.0 From 8207498f2c0e9409a6b9f9b45fd1829d45dd9752 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 13:49:43 +0800 Subject: [PATCH 09/54] add bilibili live signIn add bilibili live room sign --- .../com/yutou/qqbot/QQBotApplication.java | 2 +- .../yutou/qqbot/bilibili/BiliBiliUtils.java | 29 ++++++++ .../com/yutou/qqbot/bilibili/BiliLogin.java | 8 +++ .../qqbot/models/BiliBili/BiliBiliLive.java | 68 +++++++++++++++++++ .../java/com/yutou/qqbot/models/Model.java | 2 + 5 files changed, 108 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index 1408e3a..c5f1c65 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.3.5.2"; + public static final String version="QQBot v.1.3.6"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index ca1fe89..32b406f 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -300,4 +300,33 @@ public class BiliBiliUtils { File file=BiliBiliUtils.download(url,"16.mp4",false); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath()); } + + public static boolean sendLiveDanmu(long roomId,String msg){ + JSONObject body=new JSONObject(); + body.put("msg",msg); + body.put("roomid",roomId); + body.put("color",16777215); + body.put("fontsize",25); + body.put("rnd",System.currentTimeMillis()/1000); + body.put("csrf",BiliLogin.getCookieToken()); + body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body)); + return post.getInteger("code")==0; + } + public static String liveSignIn(){ + //{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"} + JSONObject body=new JSONObject(); + body.put("csrf",BiliLogin.getCookieToken()); + body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); + return post.getString("message"); + } + public static boolean checkLiveRoom(int roomId){ + JSONObject body=new JSONObject(); + body.put("room_id",roomId); + body.put("csrf",BiliLogin.getCookieToken()); + body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); + return post.getInteger("code")==0; + } } diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java index 44aac46..153b2f4 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java @@ -5,6 +5,7 @@ import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.HttpTools; +import com.yutou.qqbot.utlis.StringUtils; import java.io.File; import java.nio.charset.StandardCharsets; @@ -69,6 +70,13 @@ public class BiliLogin { JSONObject jsonObject = BiliBiliUtils.getLoginInfo(); return jsonObject.getInteger("code")==0; } + public static String getCookieToken(){ + if (StringUtils.isEmpty(ConfigTools.readFile(new File("bilibili.cookie")))) { + return null; + } + JSONObject json = JSON.parseObject(ConfigTools.readFile(new File("bilibili.cookie"))); + return json.getString("bili_jct"); + } public static void main(String[] args) { diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java new file mode 100644 index 0000000..bfbf257 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -0,0 +1,68 @@ +package com.yutou.qqbot.models.BiliBili; + +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.bilibili.BiliBiliManga; +import com.yutou.qqbot.bilibili.BiliBiliUtils; +import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.RedisTools; +import net.mamoe.mirai.event.events.MessageEvent; + +import java.util.Set; + +public class BiliBiliLive extends Model { + @Override + public boolean isUserPublic() { + return false; + } + + @Override + public String[] getUsePowers() { + return new String[]{ + Model.QQGroupCommands.BILI_LIVE_DANMU_SEND + }; + } + + @Override + public String getModelName() { + return "BiliBili Live Sign in"; + } + + @Override + public synchronized void onTime(Long qq, String time) { + super.onTime(qq, time); + if("00:01:00".equals(time)){ + QQBotManager.getInstance().sendMessage(qq, BiliBiliUtils.liveSignIn()); + Set biliLive = RedisTools.list_get("bili_live"); + StringBuilder builder=new StringBuilder(); + for (String id : biliLive) { + boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.getInteger(id), "打卡"); + builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n"); + } + QQBotManager.getInstance().sendMessage(qq,builder.toString()); + } + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + try { + Integer roomId = Integer.getInteger(msg); + StringBuilder message; + if(BiliBiliUtils.checkLiveRoom(roomId)&&!RedisTools.list_isExist("bili_live",roomId+"")){ + RedisTools.list_add("bili_live",roomId+""); + message = new StringBuilder("live sign Add Success"); + }else{ + message = new StringBuilder("live sign Add Error\n"); + message.append("-----live sign roomId-----\n"); + Set biliLive = RedisTools.list_get("bili_live"); + for (String id : biliLive) { + message.append(id).append("\n"); + } + } + QQBotManager.getInstance().sendMessage(qq,message.toString()); + }catch (Exception e){ + e.printStackTrace(); + } + + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index f871a88..c6e2e5d 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -35,6 +35,8 @@ public abstract class Model implements ModelInterface { public final static String QQ_BANGUMI_INFO = "!保存动画信息>"; public final static String QQ_MOYU = "!摸鱼"; + public final static String BILI_LIVE_DANMU_SEND="!b站签到"; + } public static class QQFromCommands { -- 2.43.0 From 960c3e9c56d455adeb90ee047f49081d8dc39e6d Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 13:52:59 +0800 Subject: [PATCH 10/54] add bilibili live signIn add bilibili live room sign --- src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index bfbf257..f9d9085 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -1,5 +1,6 @@ package com.yutou.qqbot.models.BiliBili; +import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.bilibili.BiliBiliManga; import com.yutou.qqbot.bilibili.BiliBiliUtils; @@ -9,6 +10,7 @@ import net.mamoe.mirai.event.events.MessageEvent; import java.util.Set; +@UseModel public class BiliBiliLive extends Model { @Override public boolean isUserPublic() { -- 2.43.0 From 00985e7fb8ef33da77f528149ede438ccd8eefcb Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 14:12:09 +0800 Subject: [PATCH 11/54] fix bili live sign bugs --- .../qqbot/models/BiliBili/BiliBiliLive.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index f9d9085..bf64b9a 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -20,7 +20,7 @@ public class BiliBiliLive extends Model { @Override public String[] getUsePowers() { return new String[]{ - Model.QQGroupCommands.BILI_LIVE_DANMU_SEND + Model.QQGroupCommands.BILI_LIVE_DANMU_SEND }; } @@ -32,28 +32,31 @@ public class BiliBiliLive extends Model { @Override public synchronized void onTime(Long qq, String time) { super.onTime(qq, time); - if("00:01:00".equals(time)){ + if ("00:01:00".equals(time)) { QQBotManager.getInstance().sendMessage(qq, BiliBiliUtils.liveSignIn()); Set biliLive = RedisTools.list_get("bili_live"); - StringBuilder builder=new StringBuilder(); + StringBuilder builder = new StringBuilder(); for (String id : biliLive) { boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.getInteger(id), "打卡"); builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n"); } - QQBotManager.getInstance().sendMessage(qq,builder.toString()); + QQBotManager.getInstance().sendMessage(qq, builder.toString()); } } @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); + if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND)) { + return; + } + StringBuilder message; try { Integer roomId = Integer.getInteger(msg); - StringBuilder message; - if(BiliBiliUtils.checkLiveRoom(roomId)&&!RedisTools.list_isExist("bili_live",roomId+"")){ - RedisTools.list_add("bili_live",roomId+""); + if (BiliBiliUtils.checkLiveRoom(roomId) && !RedisTools.list_isExist("bili_live", roomId + "")) { + RedisTools.list_add("bili_live", roomId + ""); message = new StringBuilder("live sign Add Success"); - }else{ + } else { message = new StringBuilder("live sign Add Error\n"); message.append("-----live sign roomId-----\n"); Set biliLive = RedisTools.list_get("bili_live"); @@ -61,10 +64,15 @@ public class BiliBiliLive extends Model { message.append(id).append("\n"); } } - QQBotManager.getInstance().sendMessage(qq,message.toString()); - }catch (Exception e){ - e.printStackTrace(); + } catch (Exception e) { + message = new StringBuilder("live sign Add Error\n"); + message.append("-----live sign roomId-----\n"); + Set biliLive = RedisTools.list_get("bili_live"); + for (String id : biliLive) { + message.append(id).append("\n"); + } } + QQBotManager.getInstance().sendMessage(qq, message.toString()); } } -- 2.43.0 From 07361fb616cd0d2f0fca3a030164915bf223fdc6 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 21:11:31 +0800 Subject: [PATCH 12/54] =?UTF-8?q?fix=20B=E7=AB=99=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../qqbot/models/BiliBili/BiliBiliLive.java | 34 +++++++++++++------ .../java/com/yutou/qqbot/models/Model.java | 1 + 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index bf64b9a..2545d59 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -20,7 +20,8 @@ public class BiliBiliLive extends Model { @Override public String[] getUsePowers() { return new String[]{ - Model.QQGroupCommands.BILI_LIVE_DANMU_SEND + Model.QQGroupCommands.BILI_LIVE_DANMU_SEND, + QQGroupCommands.BILI_LIVE_DANMU_DEL }; } @@ -47,26 +48,39 @@ public class BiliBiliLive extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND)) { + if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND) && !msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { return; } StringBuilder message; + message = new StringBuilder(); try { - Integer roomId = Integer.getInteger(msg); - if (BiliBiliUtils.checkLiveRoom(roomId) && !RedisTools.list_isExist("bili_live", roomId + "")) { - RedisTools.list_add("bili_live", roomId + ""); - message = new StringBuilder("live sign Add Success"); + boolean isDel = false; + if (msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { + isDel = true; + msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_DEL, "").trim(); } else { - message = new StringBuilder("live sign Add Error\n"); - message.append("-----live sign roomId-----\n"); + msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_SEND, "").trim(); + } + Integer roomId = Integer.getInteger(msg); + if (BiliBiliUtils.checkLiveRoom(roomId)) { + if (isDel && RedisTools.list_isExist("bili_live", roomId + "")) { + RedisTools.list_remove("bili_live", roomId + ""); + message.append("直播签到删除成功").append("\n"); + } else if (!RedisTools.list_isExist("bili_live", roomId + "")) { + RedisTools.list_add("bili_live", roomId + ""); + message.append("直播签到添加成功").append("\n"); + } + } else { + message.append("直播签到操作失败\n"); + message.append("-----直播签到房间号----\n"); Set biliLive = RedisTools.list_get("bili_live"); for (String id : biliLive) { message.append(id).append("\n"); } } } catch (Exception e) { - message = new StringBuilder("live sign Add Error\n"); - message.append("-----live sign roomId-----\n"); + message = new StringBuilder("直播签到添加失败\n"); + message.append("-----直播签到房间号-----\n"); Set biliLive = RedisTools.list_get("bili_live"); for (String id : biliLive) { message.append(id).append("\n"); diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index c6e2e5d..6a90381 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -36,6 +36,7 @@ public abstract class Model implements ModelInterface { public final static String QQ_MOYU = "!摸鱼"; public final static String BILI_LIVE_DANMU_SEND="!b站签到"; + public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; } -- 2.43.0 From 3d730206b9584fb7401d8c1a1b6a3d43e81a7db3 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 21:14:11 +0800 Subject: [PATCH 13/54] =?UTF-8?q?fix=20B=E7=AB=99=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E7=9B=B4=E6=92=AD=E9=97=B4=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 2545d59..455d816 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -61,7 +61,7 @@ public class BiliBiliLive extends Model { } else { msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_SEND, "").trim(); } - Integer roomId = Integer.getInteger(msg); + Integer roomId = Integer.parseInt(msg); if (BiliBiliUtils.checkLiveRoom(roomId)) { if (isDel && RedisTools.list_isExist("bili_live", roomId + "")) { RedisTools.list_remove("bili_live", roomId + ""); -- 2.43.0 From 47e4039127a1669829d500df796ab477daf34efd Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 21:27:24 +0800 Subject: [PATCH 14/54] add user info --- .../yutou/qqbot/bilibili/BiliBiliUtils.java | 19 +++++++++++++---- .../qqbot/models/BiliBili/BiliBiliLive.java | 21 ++++++++++--------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index 32b406f..091cea6 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -296,9 +296,12 @@ public class BiliBiliUtils { } public static void main(String[] args) { - String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; + /* String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; File file=BiliBiliUtils.download(url,"16.mp4",false); - System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath()); + System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());*/ + System.out.println(getLiveRoom(42062)); + System.out.println("--------------------------------------------"); + System.out.println(getUserInfo(730732)); } public static boolean sendLiveDanmu(long roomId,String msg){ @@ -321,12 +324,20 @@ public class BiliBiliUtils { JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); return post.getString("message"); } - public static boolean checkLiveRoom(int roomId){ + public static JSONObject getLiveRoom(int roomId){ JSONObject body=new JSONObject(); body.put("room_id",roomId); body.put("csrf",BiliLogin.getCookieToken()); body.put("csrf_token",BiliLogin.getCookieToken()); - JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); + return BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); + } + public static JSONObject getUserInfo(int mid){ + JSONObject body=new JSONObject(); + body.put("mid",mid); + return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?"+ HttpTools.toUrlParams(body)); + } + public static boolean checkLiveRoom(int roomId){ + JSONObject post=getLiveRoom(roomId); return post.getInteger("code")==0; } } diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 455d816..13b96ab 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -72,19 +72,20 @@ public class BiliBiliLive extends Model { } } else { message.append("直播签到操作失败\n"); - message.append("-----直播签到房间号----\n"); - Set biliLive = RedisTools.list_get("bili_live"); - for (String id : biliLive) { - message.append(id).append("\n"); - } } } catch (Exception e) { message = new StringBuilder("直播签到添加失败\n"); - message.append("-----直播签到房间号-----\n"); - Set biliLive = RedisTools.list_get("bili_live"); - for (String id : biliLive) { - message.append(id).append("\n"); - } + } + message.append("-----直播签到房间号-----\n"); + Set biliLive = RedisTools.list_get("bili_live"); + for (String id : biliLive) { + message.append(id) + .append(":") + .append(BiliBiliUtils.getUserInfo( + BiliBiliUtils.getLiveRoom(Integer.parseInt(id)) + .getJSONObject("data") + .getInteger("mid"))) + .append("\n"); } QQBotManager.getInstance().sendMessage(qq, message.toString()); -- 2.43.0 From 22add886d535f6001f057fd980ffefdc8a6fdb76 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 21:30:25 +0800 Subject: [PATCH 15/54] add user info --- src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 13b96ab..911c9ae 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -84,7 +84,7 @@ public class BiliBiliLive extends Model { .append(BiliBiliUtils.getUserInfo( BiliBiliUtils.getLiveRoom(Integer.parseInt(id)) .getJSONObject("data") - .getInteger("mid"))) + .getInteger("uid"))) .append("\n"); } QQBotManager.getInstance().sendMessage(qq, message.toString()); -- 2.43.0 From 28167c7f4916a2e218ba0d2347b1c772fa3231f4 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 14 Oct 2022 21:31:57 +0800 Subject: [PATCH 16/54] add user info --- .../com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 911c9ae..3749cb5 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -82,9 +82,11 @@ public class BiliBiliLive extends Model { message.append(id) .append(":") .append(BiliBiliUtils.getUserInfo( - BiliBiliUtils.getLiveRoom(Integer.parseInt(id)) - .getJSONObject("data") - .getInteger("uid"))) + BiliBiliUtils.getLiveRoom(Integer.parseInt(id)) + .getJSONObject("data") + .getInteger("uid")) + .getJSONObject("data") + .getString("name")) .append("\n"); } QQBotManager.getInstance().sendMessage(qq, message.toString()); -- 2.43.0 From 6de3f5d738da9fc3255d7e2d946e8670aeccc2d7 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 15 Oct 2022 11:10:46 +0800 Subject: [PATCH 17/54] fix int.parseInt --- .../java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 3749cb5..f902914 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -38,7 +38,7 @@ public class BiliBiliLive extends Model { Set biliLive = RedisTools.list_get("bili_live"); StringBuilder builder = new StringBuilder(); for (String id : biliLive) { - boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.getInteger(id), "打卡"); + boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.parseInt(id), "打卡"); builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n"); } QQBotManager.getInstance().sendMessage(qq, builder.toString()); @@ -51,6 +51,10 @@ public class BiliBiliLive extends Model { if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND) && !msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { return; } + if(msg.equals(QQGroupCommands.BILI_LIVE_DANMU_SEND+"debug")){ + onTime(qq,"00:01:00"); + return; + } StringBuilder message; message = new StringBuilder(); try { -- 2.43.0 From 5d2d41f176f39ee6804bfffa678885dc072f6f35 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 15 Oct 2022 11:16:31 +0800 Subject: [PATCH 18/54] fix bili live sign time sleep --- .../java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index f902914..b60f98e 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -38,6 +38,11 @@ public class BiliBiliLive extends Model { Set biliLive = RedisTools.list_get("bili_live"); StringBuilder builder = new StringBuilder(); for (String id : biliLive) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.parseInt(id), "打卡"); builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n"); } -- 2.43.0 From bcafd751e62402107cca0b28f224ba734f6d0781 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 15 Oct 2022 11:31:12 +0800 Subject: [PATCH 19/54] fix bili live sign bugs --- .../java/com/yutou/qqbot/bilibili/BiliBiliUtils.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index 091cea6..c51d8c0 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -299,9 +299,11 @@ public class BiliBiliUtils { /* String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; File file=BiliBiliUtils.download(url,"16.mp4",false); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());*/ - System.out.println(getLiveRoom(42062)); + /* System.out.println(getLiveRoom(42062)); System.out.println("--------------------------------------------"); - System.out.println(getUserInfo(730732)); + System.out.println(getUserInfo(730732));*/ + String sign = liveSignIn(); + System.out.println("sign = " + sign); } public static boolean sendLiveDanmu(long roomId,String msg){ @@ -322,7 +324,8 @@ public class BiliBiliUtils { body.put("csrf",BiliLogin.getCookieToken()); body.put("csrf_token",BiliLogin.getCookieToken()); JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); - return post.getString("message"); + JSONObject post_ = BiliBiliUtils.http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); + return post.getString("message")+"|"+post_.getString("message"); } public static JSONObject getLiveRoom(int roomId){ JSONObject body=new JSONObject(); -- 2.43.0 From 6d9277ced52dfa2ebb10889ea712eaa979acd55f Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 17 Oct 2022 09:50:42 +0800 Subject: [PATCH 20/54] update pom.xml --- pom.xml | 10 +++++----- .../java/com/yutou/qqbot/models/WebSign/BaiHeHui.java | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 19ff167..4e3739c 100644 --- a/pom.xml +++ b/pom.xml @@ -60,7 +60,7 @@ com.alibaba.fastjson2 fastjson2 - 2.0.12 + 2.0.14 @@ -81,24 +81,24 @@ org.seleniumhq.selenium selenium-java - 4.2.1 + 4.5.0 org.seleniumhq.selenium selenium-chrome-driver - 4.2.1 + 4.5.0 org.seleniumhq.selenium selenium-api - 4.2.1 + 4.5.0 org.seleniumhq.selenium selenium-remote-driver - 4.2.1 + 4.5.0 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 8636eb4..e59ec6f 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java @@ -51,7 +51,7 @@ public class BaiHeHui extends Model { public boolean sign() { String cookie = ConfigTools.readFile(new File("baihehui.json")); - if (StringUtils.isEmpty(cookie)) { + if (StringUtils.isEmpty(cookie)||true) { return false; } WebDriver driver = WebClient.getInstance().getWebDriver(); -- 2.43.0 From 762385886664b33454e51ae34a8f650e8e42d891 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 22 Oct 2022 13:46:55 +0800 Subject: [PATCH 21/54] test1 --- src/main/java/com/yutou/qqbot/QQNumberManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/com/yutou/qqbot/QQNumberManager.java b/src/main/java/com/yutou/qqbot/QQNumberManager.java index fea40e6..612925e 100644 --- a/src/main/java/com/yutou/qqbot/QQNumberManager.java +++ b/src/main/java/com/yutou/qqbot/QQNumberManager.java @@ -113,6 +113,7 @@ public class QQNumberManager { return false; } public boolean isExistsPower(Long qq, String... power){ + //1 if(RedisTools.exists(qq,null)){ JSONObject json=JSON.parseObject(RedisTools.get(qq)); JSONArray array=json.getJSONArray("power"); -- 2.43.0 From 0de499fb5711ab215d35bef3ec00b5a9b3092ac5 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 28 Oct 2022 09:41:48 +0800 Subject: [PATCH 22/54] fix BaiHeHui.java --- .../java/com/yutou/qqbot/models/WebSign/BaiHeHui.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) 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 e59ec6f..ebe4c9d 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BaiHeHui.java @@ -11,6 +11,7 @@ import org.openqa.selenium.WebDriver; import org.openqa.selenium.WebElement; import java.io.File; +import java.time.Duration; import java.util.concurrent.TimeUnit; @UseModel public class BaiHeHui extends Model { @@ -50,14 +51,9 @@ public class BaiHeHui extends Model { } public boolean sign() { - String cookie = ConfigTools.readFile(new File("baihehui.json")); - if (StringUtils.isEmpty(cookie)||true) { - return false; - } WebDriver driver = WebClient.getInstance().getWebDriver(); try { - JSONArray array = JSON.parseArray(cookie); - driver.manage().timeouts().implicitlyWait(10000, TimeUnit.SECONDS); + driver.manage().timeouts().implicitlyWait( Duration.ofSeconds(5)); driver.get("https://bbs.yamibo.com/forum.php"); login(driver); // driver.manage().deleteAllCookies(); -- 2.43.0 From 85fbce9f4ffe3f57c8c4ca7ff42e7d483689e2b0 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 4 Nov 2022 10:25:17 +0800 Subject: [PATCH 23/54] add WoodenFish.java --- .../qqbot/models/Commands/WoodenFish.java | 34 +++++++++++++++++++ .../java/com/yutou/qqbot/models/Model.java | 4 ++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java diff --git a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java new file mode 100644 index 0000000..6a2d58a --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java @@ -0,0 +1,34 @@ +package com.yutou.qqbot.models.Commands; + +import com.yutou.qqbot.Annotations.UseModel; +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.models.Model; +import net.mamoe.mirai.event.events.MessageEvent; + +import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_WOODEN; + +@UseModel +public class WoodenFish extends Model { + @Override + public boolean isUserPublic() { + return false; + } + + @Override + public String[] getUsePowers() { + return new String[]{QQ_WOODEN}; + } + + @Override + public String getModelName() { + return "电子木鱼"; + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + if("地狱笑话".equals(msg)){ + QQBotManager.getInstance().sendMessage(qq,"功德+1"); + } + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index 6a90381..07c24bf 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -38,9 +38,11 @@ public abstract class Model implements ModelInterface { public final static String BILI_LIVE_DANMU_SEND="!b站签到"; public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; + public final static String QQ_WOODEN="!电子木鱼"; + } - public static class QQFromCommands { + public static class QQFromCommands { public static final String TURNIP_PROPHET = "大头菜"; public static final String TSDM_PAY = "!tsdm"; public static final String BAIDU_DOWN = "!bd"; -- 2.43.0 From c146eac9c58a28a65e95783b059d0dbccbd71c59 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 4 Nov 2022 10:28:58 +0800 Subject: [PATCH 24/54] add WoodenFish.java --- src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java index 6a2d58a..8784220 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java @@ -11,12 +11,12 @@ import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_WOODEN; public class WoodenFish extends Model { @Override public boolean isUserPublic() { - return false; + return true; } @Override public String[] getUsePowers() { - return new String[]{QQ_WOODEN}; + return new String[0]; } @Override -- 2.43.0 From 5ac0b45540aa70482e1331f3dd2b2c13869bc223 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 7 Nov 2022 09:41:45 +0800 Subject: [PATCH 25/54] fix WoodenFish.java --- src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java index 8784220..92c0cd1 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java @@ -27,7 +27,7 @@ public class WoodenFish extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if("地狱笑话".equals(msg)){ + if(msg.contains("地狱笑话")){ QQBotManager.getInstance().sendMessage(qq,"功德+1"); } } -- 2.43.0 From ab1facc747c6cf0ed515417aae02f0579c60fc4e Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 10 Nov 2022 14:18:12 +0800 Subject: [PATCH 26/54] add PaoPaoSleepWaring --- .../qqbot/Controllers/AppController.java | 7 +--- .../java/com/yutou/qqbot/QQBotManager.java | 17 ++++++-- .../models/Commands/PaoPaoSleepWaring.java | 40 +++++++++++++++++++ .../java/com/yutou/qqbot/models/Model.java | 1 + .../com/yutou/qqbot/utlis/PatternTools.java | 25 ++++++++++++ 5 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java create mode 100644 src/main/java/com/yutou/qqbot/utlis/PatternTools.java diff --git a/src/main/java/com/yutou/qqbot/Controllers/AppController.java b/src/main/java/com/yutou/qqbot/Controllers/AppController.java index 7ce89b4..b487ffd 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/AppController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/AppController.java @@ -71,12 +71,7 @@ public class AppController { if (json.containsKey("image")) { image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png",true); } - if (image != null) { - ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); - - } else { - ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message")); - } + ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); return ret==null?"message send fail":"message send success"; } diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 33f49ab..468d2e3 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -9,10 +9,7 @@ import net.mamoe.mirai.BotFactory; import net.mamoe.mirai.contact.Group; import net.mamoe.mirai.event.GlobalEventChannel; import net.mamoe.mirai.message.MessageReceipt; -import net.mamoe.mirai.message.data.Image; -import net.mamoe.mirai.message.data.MessageChain; -import net.mamoe.mirai.message.data.MessageChainBuilder; -import net.mamoe.mirai.message.data.QuoteReply; +import net.mamoe.mirai.message.data.*; import net.mamoe.mirai.utils.BotConfiguration; import net.mamoe.mirai.utils.ExternalResource; @@ -95,6 +92,9 @@ public class QQBotManager { } private Image getImage(File file, Long qq) { + if(file==null){ + return null; + } if (bot != null) { ExternalResource resource = ExternalResource.create(file); Image image; @@ -170,6 +170,15 @@ public class QQBotManager { if (image != null) { builder.append(image); } + List list=PatternTools.getQQ(text); + if (!list.isEmpty()) { + for (String _qq : list) { + String[] tmp = text.split(_qq); + builder.append(tmp[0]); + builder.append(new At(Long.parseLong(_qq.replace("@", "")))); + text = text.replace(tmp[0] + _qq, ""); + } + } builder.append(text); if (QQNumberManager.getManager().isGroup(qq)) { return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()); diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java new file mode 100644 index 0000000..1e221ec --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -0,0 +1,40 @@ +package com.yutou.qqbot.models.Commands; + +import com.yutou.qqbot.Annotations.UseModel; +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.AppTools; +import net.mamoe.mirai.event.events.MessageEvent; +import net.mamoe.mirai.message.data.MessageChainBuilder; +import net.mamoe.mirai.message.data.QuoteReply; + +import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_TIMEOUT; + +@UseModel +public class PaoPaoSleepWaring extends Model { + @Override + public boolean isUserPublic() { + return false; + } + + @Override + public String[] getUsePowers() { + return new String[]{QQ_TIMEOUT}; + } + + @Override + public String getModelName() { + return "paopao"; + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + if(Integer.parseInt(AppTools.getHours())>22 && event.getSource().getFromId() == 914520754){ + MessageChainBuilder builder=new MessageChainBuilder(); + builder.append(new QuoteReply(event.getMessage())); + builder.append("别水了,该睡了~"); + QQBotManager.getInstance().sendMessage(qq,builder); + } + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index 07c24bf..c7023ad 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -39,6 +39,7 @@ public abstract class Model implements ModelInterface { public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; public final static String QQ_WOODEN="!电子木鱼"; + public final static String QQ_TIMEOUT="!timer"; } diff --git a/src/main/java/com/yutou/qqbot/utlis/PatternTools.java b/src/main/java/com/yutou/qqbot/utlis/PatternTools.java new file mode 100644 index 0000000..6db6326 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/utlis/PatternTools.java @@ -0,0 +1,25 @@ +package com.yutou.qqbot.utlis; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +public class PatternTools { + private static List exec(String regex, String input){ + List list=new ArrayList<>(); + Pattern pattern=Pattern.compile(regex); + Matcher matcher = pattern.matcher(input); + while(matcher.find()){ + list.add(matcher.group()); + } + return list; + } + public static List pattern(String text,String start,String end){ + return exec(String.format(".(?<=%s).*(?=%s)", start,end), text); + } + public static List getQQ(String text){ + return exec("(@[0-9]\\d*)",text); + } +} -- 2.43.0 From c9eceaccf38fb90d45a30791af1e8e75a00b7649 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 10 Nov 2022 20:29:49 +0800 Subject: [PATCH 27/54] =?UTF-8?q?update=20=E6=9C=A8=E9=B1=BC=E9=9F=B3?= =?UTF-8?q?=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yutou/qqbot/bilibili/BiliBiliUtils.java | 86 ++++++++++++------- .../qqbot/models/Commands/WoodenFish.java | 15 ++++ .../java/com/yutou/qqbot/utlis/AppTools.java | 5 ++ .../java/com/yutou/qqbot/utlis/HttpTools.java | 7 ++ 4 files changed, 83 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index c51d8c0..3a7ce38 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -12,7 +12,9 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import java.nio.charset.StandardCharsets; +import java.util.LinkedHashMap; import java.util.List; +import java.util.Map; public class BiliBiliUtils { private static long oldBiliBiliHttpTime = 0; @@ -64,6 +66,10 @@ public class BiliBiliUtils { } public static T http(String url, HTTP model, String body, RET_MODEL ret_model) { + return http(url, model, body, null, ret_model); + } + + public static T http(String url, HTTP model, String body, Map headers, RET_MODEL ret_model) { JSONObject json = null; BufferedInputStream stream = null; ByteArrayOutputStream outputStream = null; @@ -81,8 +87,22 @@ public class BiliBiliUtils { if (model == HTTP.POST) { connection = getBiliHttpPost(url, getCookie()); } else { + if (body != null) { + if (url.contains("?")) { + url += "&" + body; + } else { + url += "?" + body; + } + body = null; + } connection = getBiliHttpGet(url, getCookie()); } + if (headers != null) { + for (String key : headers.keySet()) { + connection.setRequestProperty(key, headers.get(key)); + } + } + System.out.println("url = " + url); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); if (!StringUtils.isEmpty(body)) { @@ -182,7 +202,9 @@ public class BiliBiliUtils { oldBiliBiliHttpTime = System.currentTimeMillis(); } HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection(); - setConnection(cookie, connection); + if (cookie != null) { + setConnection(cookie, connection); + } connection.setReadTimeout(5000); connection.setConnectTimeout(5000); return connection; @@ -191,7 +213,7 @@ public class BiliBiliUtils { public static File download(final String url, final String saveName, boolean isProxy) { File jar = null; try { - File savePath = new File(HttpTools.downloadPath+saveName); + File savePath = new File(HttpTools.downloadPath + saveName); Proxy proxy = null; if (!savePath.exists()) { savePath.mkdirs(); @@ -230,7 +252,7 @@ public class BiliBiliUtils { } jar.renameTo(oldJar); Log.i("DOWNLOAD", "实际保存:" + oldJar.getAbsolutePath() + " " + oldJar.getName()); - return oldJar; + return oldJar; } catch (Exception e) { e.printStackTrace(); if (jar != null) { @@ -306,41 +328,45 @@ public class BiliBiliUtils { System.out.println("sign = " + sign); } - public static boolean sendLiveDanmu(long roomId,String msg){ - JSONObject body=new JSONObject(); - body.put("msg",msg); - body.put("roomid",roomId); - body.put("color",16777215); - body.put("fontsize",25); - body.put("rnd",System.currentTimeMillis()/1000); - body.put("csrf",BiliLogin.getCookieToken()); - body.put("csrf_token",BiliLogin.getCookieToken()); + public static boolean sendLiveDanmu(long roomId, String msg) { + JSONObject body = new JSONObject(); + body.put("msg", msg); + body.put("roomid", roomId); + body.put("color", 16777215); + body.put("fontsize", 25); + body.put("rnd", System.currentTimeMillis() / 1000); + body.put("csrf", BiliLogin.getCookieToken()); + body.put("csrf_token", BiliLogin.getCookieToken()); JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body)); - return post.getInteger("code")==0; + return post.getInteger("code") == 0; } - public static String liveSignIn(){ + + public static String liveSignIn() { //{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"} - JSONObject body=new JSONObject(); - body.put("csrf",BiliLogin.getCookieToken()); - body.put("csrf_token",BiliLogin.getCookieToken()); + JSONObject body = new JSONObject(); + body.put("csrf", BiliLogin.getCookieToken()); + body.put("csrf_token", BiliLogin.getCookieToken()); JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); JSONObject post_ = BiliBiliUtils.http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); - return post.getString("message")+"|"+post_.getString("message"); + return post.getString("message") + "|" + post_.getString("message"); } - public static JSONObject getLiveRoom(int roomId){ - JSONObject body=new JSONObject(); - body.put("room_id",roomId); - body.put("csrf",BiliLogin.getCookieToken()); - body.put("csrf_token",BiliLogin.getCookieToken()); + + public static JSONObject getLiveRoom(int roomId) { + JSONObject body = new JSONObject(); + body.put("room_id", roomId); + body.put("csrf", BiliLogin.getCookieToken()); + body.put("csrf_token", BiliLogin.getCookieToken()); return BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); } - public static JSONObject getUserInfo(int mid){ - JSONObject body=new JSONObject(); - body.put("mid",mid); - return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?"+ HttpTools.toUrlParams(body)); + + public static JSONObject getUserInfo(int mid) { + JSONObject body = new JSONObject(); + body.put("mid", mid); + return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?" + HttpTools.toUrlParams(body)); } - public static boolean checkLiveRoom(int roomId){ - JSONObject post=getLiveRoom(roomId); - return post.getInteger("code")==0; + + public static boolean checkLiveRoom(int roomId) { + JSONObject post = getLiveRoom(roomId); + return post.getInteger("code") == 0; } } diff --git a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java index 92c0cd1..a600c48 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java @@ -3,7 +3,15 @@ package com.yutou.qqbot.models.Commands; import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.Model; +import net.mamoe.mirai.contact.AudioSupported; import net.mamoe.mirai.event.events.MessageEvent; +import net.mamoe.mirai.message.data.Audio; +import net.mamoe.mirai.message.data.MessageChainBuilder; +import net.mamoe.mirai.message.data.OfflineAudio; +import net.mamoe.mirai.utils.ExternalResource; + +import java.io.File; +import java.util.Objects; import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_WOODEN; @@ -28,6 +36,13 @@ public class WoodenFish extends Model { public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); if(msg.contains("地狱笑话")){ + File file=new File("muyu.wav"); + if(file.exists()) { + OfflineAudio audio = Objects.requireNonNull(event.getBot().getGroup(qq)).uploadAudio(ExternalResource.create(file)); + MessageChainBuilder builder = new MessageChainBuilder(); + builder.append(audio); + QQBotManager.getInstance().sendMessage(qq,builder); + } QQBotManager.getInstance().sendMessage(qq,"功德+1"); } } diff --git a/src/main/java/com/yutou/qqbot/utlis/AppTools.java b/src/main/java/com/yutou/qqbot/utlis/AppTools.java index 5638e74..1831d90 100644 --- a/src/main/java/com/yutou/qqbot/utlis/AppTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/AppTools.java @@ -4,6 +4,7 @@ import com.alibaba.fastjson2.JSON; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.interfaces.DownloadInterface; import com.yutou.qqbot.interfaces.ObjectInterface; +import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.ClassPathScanningCandidateComponentProvider; @@ -231,4 +232,8 @@ public class AppTools { return null; } } + + public static String getMD5(String str){ + return DigestUtils.md5Hex(str); + } } diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index 4e57641..5aca45c 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -144,6 +144,13 @@ public class HttpTools { string = new StringBuilder(string.substring(1, string.length()).replaceAll(" ", "")); return string.toString(); } + public static String toUrlParams(Map map) { + StringBuilder builder=new StringBuilder(); + for (String key : map.keySet()) { + builder.append(key).append("=").append(map.get(key)).append("&"); + } + return builder.substring(0, builder.length() - 1); + } public static Map getUrlParams(String url) { Map map = new HashMap<>(); -- 2.43.0 From cf098877c3332302259c66e85e0188ee0c65a544 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 10 Nov 2022 20:36:37 +0800 Subject: [PATCH 28/54] =?UTF-8?q?update=20=E6=9C=A8=E9=B1=BC=E9=9F=B3?= =?UTF-8?q?=E9=A2=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java index a600c48..8115891 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/WoodenFish.java @@ -36,7 +36,7 @@ public class WoodenFish extends Model { public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); if(msg.contains("地狱笑话")){ - File file=new File("muyu.wav"); + File file=new File("muyu.mp3"); if(file.exists()) { OfflineAudio audio = Objects.requireNonNull(event.getBot().getGroup(qq)).uploadAudio(ExternalResource.create(file)); MessageChainBuilder builder = new MessageChainBuilder(); -- 2.43.0 From c2fc5c965af9b45d9a24f2cfaea6dd1d640c174d Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 11 Nov 2022 22:43:46 +0800 Subject: [PATCH 29/54] add PaoPaoSleepWaring --- .../com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index 1e221ec..89b659d 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -14,7 +14,7 @@ import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_TIMEOUT; public class PaoPaoSleepWaring extends Model { @Override public boolean isUserPublic() { - return false; + return true; } @Override @@ -30,7 +30,7 @@ public class PaoPaoSleepWaring extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if(Integer.parseInt(AppTools.getHours())>22 && event.getSource().getFromId() == 914520754){ + if(Integer.parseInt(AppTools.getHours())>=22 && event.getSource().getFromId() == 914520754){ MessageChainBuilder builder=new MessageChainBuilder(); builder.append(new QuoteReply(event.getMessage())); builder.append("别水了,该睡了~"); -- 2.43.0 From 1456675446156767cf2cb8c7db1b4eb9fc6ff699 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 11 Nov 2022 22:54:15 +0800 Subject: [PATCH 30/54] update PaoPaoSleepWaring --- .../com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index 89b659d..aeaffc3 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -4,6 +4,7 @@ import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.Model; import com.yutou.qqbot.utlis.AppTools; +import com.yutou.qqbot.utlis.RedisTools; import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.message.data.MessageChainBuilder; import net.mamoe.mirai.message.data.QuoteReply; @@ -30,11 +31,13 @@ public class PaoPaoSleepWaring extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if(Integer.parseInt(AppTools.getHours())>=22 && event.getSource().getFromId() == 914520754){ + if(Integer.parseInt(AppTools.getHours())>=22 && event.getSource().getFromId() == 914520754 + && "true".equals(RedisTools.get("paopao_sleep_"+AppTools.getToDayTime(),"false"))){ MessageChainBuilder builder=new MessageChainBuilder(); builder.append(new QuoteReply(event.getMessage())); builder.append("别水了,该睡了~"); QQBotManager.getInstance().sendMessage(qq,builder); + RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",2*60*60); } } } -- 2.43.0 From ae72956f6814230463b15ed3a9fa508f4336ba1e Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 11 Nov 2022 22:55:03 +0800 Subject: [PATCH 31/54] update PaoPaoSleepWaring --- .../java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index aeaffc3..0b1f690 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -32,7 +32,7 @@ public class PaoPaoSleepWaring extends Model { public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); if(Integer.parseInt(AppTools.getHours())>=22 && event.getSource().getFromId() == 914520754 - && "true".equals(RedisTools.get("paopao_sleep_"+AppTools.getToDayTime(),"false"))){ + && "false".equals(RedisTools.get("paopao_sleep_"+AppTools.getToDayTime(),"false"))){ MessageChainBuilder builder=new MessageChainBuilder(); builder.append(new QuoteReply(event.getMessage())); builder.append("别水了,该睡了~"); -- 2.43.0 From 083218b1cb132e29feceda13c80f432eaeec9067 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sun, 20 Nov 2022 19:07:56 +0800 Subject: [PATCH 32/54] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E6=AF=9B=E6=AF=9B?= =?UTF-8?q?=E6=8F=90=E9=86=92=EF=BC=8C=E4=BF=AE=E6=94=B9=E6=B3=A1=E6=B3=A1?= =?UTF-8?q?=E6=8F=90=E9=86=92=E4=B8=BA=E4=B8=80=E5=B0=8F=E6=97=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../models/Commands/MaoMaoWorkWaring.java | 43 +++++++++++++++++++ .../models/Commands/PaoPaoSleepWaring.java | 4 +- 2 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/yutou/qqbot/models/Commands/MaoMaoWorkWaring.java diff --git a/src/main/java/com/yutou/qqbot/models/Commands/MaoMaoWorkWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/MaoMaoWorkWaring.java new file mode 100644 index 0000000..12c4e88 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/Commands/MaoMaoWorkWaring.java @@ -0,0 +1,43 @@ +package com.yutou.qqbot.models.Commands; + +import com.yutou.qqbot.Annotations.UseModel; +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.AppTools; +import com.yutou.qqbot.utlis.RedisTools; +import net.mamoe.mirai.event.events.MessageEvent; +import net.mamoe.mirai.message.data.MessageChainBuilder; +import net.mamoe.mirai.message.data.QuoteReply; + +import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_TIMEOUT; + +@UseModel +public class MaoMaoWorkWaring extends Model { + @Override + public boolean isUserPublic() { + return true; + } + + @Override + public String[] getUsePowers() { + return new String[]{QQ_TIMEOUT}; + } + + @Override + public String getModelName() { + return "毛毛工作提醒"; + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + if(Integer.parseInt(AppTools.getHours())>=6 && event.getSource().getFromId() == 526306604 + && "false".equals(RedisTools.get("maomao_work_"+AppTools.getToDayTime(),"false"))){ + MessageChainBuilder builder=new MessageChainBuilder(); + builder.append(new QuoteReply(event.getMessage())); + builder.append("别水了,快去打工,没钱氪老婆了"); + QQBotManager.getInstance().sendMessage(qq,builder); + RedisTools.set("maomao_work_"+AppTools.getToDayTime(),"true",20*60*60); + } + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index 0b1f690..d21288a 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -25,7 +25,7 @@ public class PaoPaoSleepWaring extends Model { @Override public String getModelName() { - return "paopao"; + return "泡泡提醒"; } @Override @@ -37,7 +37,7 @@ public class PaoPaoSleepWaring extends Model { builder.append(new QuoteReply(event.getMessage())); builder.append("别水了,该睡了~"); QQBotManager.getInstance().sendMessage(qq,builder); - RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",2*60*60); + RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",1*60*60); } } } -- 2.43.0 From fec901970a61ab6610af4dd57d3fa103b7d7e419 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 5 Jan 2023 14:36:42 +0800 Subject: [PATCH 33/54] =?UTF-8?q?=E6=96=B0=E5=A2=9EB=E7=AB=99=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E9=A2=86=E7=94=B5=E6=B1=A0=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=20=E6=96=B0=E5=A2=9EB=E7=AB=99APP=E6=93=8D=E4=BD=9C=E7=9B=B8?= =?UTF-8?q?=E5=85=B3API=20=E4=BC=98=E5=8C=96B=E7=AB=99=E7=99=BB=E9=99=86?= =?UTF-8?q?=E6=A0=B9=E6=8D=AEQQ=E5=8F=B7=E5=88=86=E8=B4=A6=E5=8F=B7?= =?UTF-8?q?=E5=AD=98=E5=82=A8=20=E4=BF=AE=E5=A4=8DRedis=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=97=B6=E4=B8=BA=E7=A9=BA=E6=8A=A5=E9=94=99?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 23 ++- .../qqbot/Controllers/BiliBiliController.java | 3 +- .../com/yutou/qqbot/QQBotApplication.java | 2 +- .../java/com/yutou/qqbot/QQBotManager.java | 1 + .../com/yutou/qqbot/bilibili/AppUserTask.java | 76 ++++++++++ .../qqbot/bilibili/BiliBiliAppUtils.java | 141 ++++++++++++++++++ .../yutou/qqbot/bilibili/BiliBiliManga.java | 43 +++--- .../yutou/qqbot/bilibili/BiliBiliUtils.java | 97 +++++++----- .../com/yutou/qqbot/bilibili/BiliLogin.java | 83 +++++++---- .../qqbot/models/BiliBili/BiliBiliLive.java | 61 +++++--- .../qqbot/models/BiliBili/BiliVideo.java | 31 ++-- .../java/com/yutou/qqbot/models/Model.java | 23 +-- .../models/WebSign/BiliBiliMangeSign.java | 6 +- .../java/com/yutou/qqbot/utlis/RSAUtils.java | 136 +++++++++++++++++ .../com/yutou/qqbot/utlis/RedisTools.java | 42 ++++-- 15 files changed, 611 insertions(+), 157 deletions(-) create mode 100644 src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java create mode 100644 src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java create mode 100644 src/main/java/com/yutou/qqbot/utlis/RSAUtils.java diff --git a/pom.xml b/pom.xml index 4e3739c..7dcee9d 100644 --- a/pom.xml +++ b/pom.xml @@ -52,7 +52,7 @@ redis.clients jedis - 4.2.3 + 4.3.1 @@ -60,7 +60,7 @@ com.alibaba.fastjson2 fastjson2 - 2.0.14 + 2.0.22 @@ -81,24 +81,24 @@ org.seleniumhq.selenium selenium-java - 4.5.0 + 4.7.1 org.seleniumhq.selenium selenium-chrome-driver - 4.5.0 + 4.7.1 org.seleniumhq.selenium selenium-api - 4.5.0 + 4.7.1 org.seleniumhq.selenium selenium-remote-driver - 4.5.0 + 4.7.1 @@ -117,13 +117,13 @@ com.google.zxing core - 3.5.0 + 3.5.1 com.google.protobuf protobuf-java - 3.21.1 + 3.21.12 com.google.protobuf @@ -138,6 +138,13 @@ 0.10.2 + + + org.brotli + dec + 0.1.2 + + diff --git a/src/main/java/com/yutou/qqbot/Controllers/BiliBiliController.java b/src/main/java/com/yutou/qqbot/Controllers/BiliBiliController.java index 2cad996..ba003ab 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/BiliBiliController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/BiliBiliController.java @@ -1,6 +1,7 @@ package com.yutou.qqbot.Controllers; import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.models.BiliBili.BiliVideo; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @@ -17,7 +18,7 @@ public class BiliBiliController { String url = json.getString("url"); boolean downDanmu = json.containsKey("danmu") && "on".equals(json.getString("danmu")); boolean merge = json.containsKey("merge") && "on".equals(json.getString("merge")); - BiliVideo video = new BiliVideo(); + BiliVideo video = new BiliVideo(QQBotManager.defQQ); video.downVideo(url, downDanmu, merge); } ).start(); diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index c5f1c65..a2e6f89 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.3.6"; + public static final String version="QQBot v.1.4b"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 468d2e3..b70931b 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -21,6 +21,7 @@ import java.util.Objects; public class QQBotManager { public static Long defGroup = 891655174L; + public static Long defQQ = 583819556L; private static QQBotManager botManager = null; diff --git a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java new file mode 100644 index 0000000..8f8217a --- /dev/null +++ b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java @@ -0,0 +1,76 @@ +package com.yutou.qqbot.bilibili; + + +import lombok.Data; + +import java.util.List; + +@Data +public class AppUserTask { + private long isSurplus; + private long status; + private long progress; + private long target; + private Wallet wallet; + private List weekTask; + private long weekTotal; + private long weekGroup; + private DayTask dayTask; + + + public String toMessageFormat() { + StringBuilder sb = new StringBuilder(); + sb.append("当前电池数量:").append(String.format("%.2f", (double) wallet.gold / 100)).append("\n"); + sb.append("当前银瓜子数量:").append(wallet.silver).append("\n"); + sb.append("每日领取电池:").append(dayTask.toMessageFormat()).append("\n"); + weekTask.forEach(task -> sb.append(task.toMessageFormat(weekTotal)).append("\n")); + return sb.toString(); + } + + @Data + public static class DayTask { + private int status; + private long progress; + private long target; + + public String toMessageFormat() { + return switch (getStatus()) { + case 0 -> "不可领取,需要发送弹幕:" + getTarget() + ",进度:" + getProgress(); + case 2 -> "未领取"; + case 3 -> "已领取"; + default -> "未知状态:" + this; + }; + } + + } + + @Data + public static class Wallet { + private long gold; + private long silver; + } + +// WeekTask.java + + + @Data + public static class WeekTask { + private long rewardNum; + private long minimalDay; + private int status; + private int id; + + public String toMessageFormat(long totalNum) { + return switch (getStatus()) { + case 0 -> + "任务id:" + id + ",不可领取, 进度天数:" + totalNum + ",需要天数:" + minimalDay + ",任务奖励电池:" + rewardNum; + case 2 -> "任务id:" + id + ":未领取" + ",任务奖励电池:" + rewardNum; + case 3 -> "任务id:" + id + ":已领取" + ",任务奖励电池:" + rewardNum; + default -> "未知状态:" + this; + }; + } + } + +} + + diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java new file mode 100644 index 0000000..0070530 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java @@ -0,0 +1,141 @@ +package com.yutou.qqbot.bilibili; + +import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.utlis.AppTools; +import com.yutou.qqbot.utlis.HttpTools; + +import javax.net.ssl.HttpsURLConnection; +import java.net.URLEncoder; +import java.nio.charset.Charset; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +public class BiliBiliAppUtils { + private static final String AppKey = "1d8b6e7d45233436"; + private static final String AppSec = "560c52ccd288fed045859ed18bffd973"; + + private BiliBiliUtils biliUtils; + + public BiliBiliAppUtils(Long qq) { + biliUtils = BiliBiliUtils.getInstance(qq); + } + + public String getAccessToken() { + try { + String tmpUrl = "https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png"; + String sign = AppTools.getMD5("api=" + tmpUrl + AppSec); + JSONObject get = biliUtils.http_get(" https://passport.bilibili.com/login/app/third?appkey=" + AppKey + "&api=" + tmpUrl + "&sign=" + sign); + assert get != null; + String uri = get.getJSONObject("data").getString("confirm_uri"); + HttpsURLConnection connection = biliUtils.getBiliHttpGet(uri, biliUtils.getCookie()); + connection.connect(); + if (connection.getResponseCode() == 200) { + Map params = HttpTools.getUrlParams(connection.getURL().toString()); + return params.get("access_key"); + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + private Map sign(Map map) { + map.putAll(getDefaultHeader()); + map = sort(map); + StringBuilder builder = new StringBuilder(); + for (String key : map.keySet()) { + builder.append(key).append("=").append(map.get(key)).append("&"); + } + String param = builder.substring(0, builder.length() - 1); + map.put("sign", AppTools.getMD5(param + AppSec)); + return map; + } + + private Map getDefaultHeader() { + Map map = new TreeMap<>(); + map.put("access_key", getAccessToken()); + map.put("actionKey", "appkey"); + map.put("appkey", AppKey); + map.put("build", "7120200"); + map.put("c_locale", "zh_CN"); + map.put("channel", "xiaomi_cn_tv.danmaku.bili_20210930"); + map.put("device", "android"); + map.put("disable_rcmd", "0"); + map.put("mobi_app", "android"); + map.put("platform", "android"); + map.put("s_locale", "zh_CN"); + map.put("statistics", URLEncoder.encode("{\"appId\":1,\"platform\":3,\"version\":\"7.12.0\",\"abtest\":\"\"}", Charset.defaultCharset())); + map.put("ts", (System.currentTimeMillis() / 1000) + ""); + return map; + } + + private LinkedHashMap sort(Map map) { + return new LinkedHashMap<>(new TreeMap<>(map)); + } + + private Map getHeaderMap() { + String md5_1 = AppTools.getMD5(System.currentTimeMillis() + ""); + String md5_2 = AppTools.getMD5(System.currentTimeMillis() + ""); + String trace_id = md5_1 + ":" + md5_2.substring(0, 16) + ":0:0"; + Map map = new TreeMap<>(); + map.put("x-bili-mid", "96300"); + map.put("x-bili-trace-id", trace_id); + map.put("x-bili-aurora-zone", ""); + map.put("x-bili-aurora-eid", "WFICRlE="); + map.put("APP-KEY", "android64"); + map.put("bili-http-engine", "cronet"); + map.put("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); + map.put("session_id", md5_1.substring(0, 8)); + map.put("Host", "api.live.bilibili.com"); + map.put("Connection", "keep-alive"); + map.put("fp_local", md5_1 + md5_2); + map.put("fp_remote", md5_1 + md5_2); + map.put("env", "prod"); + map.put("buvid", "XUF43FCF17D1747514C79C6D3D43B64C8D1B2"); + map.put("Accept-Encoding", "gzip, deflate, br"); + map.put("User-Agent", "Mozilla/5.0 BiliDroid/7.4.0 (bbcallen@gmail.com) os/android model/22061218C mobi_app/android build/7040300 channel/xiaomi_cn_tv.danmaku.bili_20210930 innerVer/7040310 osVer/12 network/2"); + return map; + } + + public AppUserTask getTaskProgress() { + JSONObject task = biliUtils.http_get("https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/GetUserTaskProgress"); + assert task != null; + return task.getObject("data", AppUserTask.class); + } + + private void setUserTaskProgress(int index) { + Map map = new TreeMap<>(); + map.put("target_id", "33989"); + map.put("reward_index", index + ""); + + JSONObject httpGet = biliUtils.http( + "https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/UserTaskReceiveRewards", + BiliBiliUtils.HTTP.POST, + HttpTools.toUrlParams(sign(map)), + getHeaderMap(), + BiliBiliUtils.RET_MODEL.JSON + ); + System.out.println("任务 " + index + " :" + httpGet); + } + + public AppUserTask startAppTask() { + AppUserTask task = getTaskProgress(); + if (task.getDayTask().getStatus() == 2) { + setUserTaskProgress(0); + } + List taskList = task.getWeekTask(); + taskList.forEach(weekTask -> { + if (weekTask.getStatus() == 2) { + setUserTaskProgress(weekTask.getId()); + } + }); + return task; + } + + public static void main(String[] args) throws Exception { + System.out.println(new BiliBiliAppUtils(QQBotManager.defQQ).startAppTask().toMessageFormat()); + } +} diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java index 9bcd1f7..95f191c 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java @@ -2,6 +2,7 @@ package com.yutou.qqbot.bilibili; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.utlis.HttpTools; import lombok.Data; @@ -12,23 +13,28 @@ import java.util.Timer; import java.util.TimerTask; public class BiliBiliManga { + public BiliBiliManga() { + biliUtils = BiliBiliUtils.getInstance(QQBotManager.defQQ); + } + public static JSONObject sign() { JSONObject body = new JSONObject(); body.put("platform", "android"); - return BiliBiliUtils.http_post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn", HttpTools.toUrlParams(body)); + return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post("https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn", HttpTools.toUrlParams(body)); } private static JSONObject getListProductDate() { - return BiliBiliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/ListProduct", ""); + return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/ListProduct", ""); } private static boolean isPayMission = false; private static Product missionProduct = new Product(); private static Timer mission = null; - private final List anInterface = new ArrayList<>(); + private static BiliBiliUtils biliUtils = null; + private ObjectInterface anInterface = null; public void addInterface(ObjectInterface objectInterface) { - anInterface.add(objectInterface); + anInterface = objectInterface; } public static boolean isPayMission() { @@ -36,7 +42,7 @@ public class BiliBiliManga { } public static String getMission() { - return missionProduct+" 兑换数量:"+missionProduct.getPayAmount(); + return missionProduct + " 兑换数量:" + missionProduct.getPayAmount(); } public static List getListProduct() { @@ -59,7 +65,7 @@ public class BiliBiliManga { } public static int getMyPoint() { - JSONObject user = BiliBiliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/GetUserPoint", ""); + JSONObject user = biliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/GetUserPoint", ""); if (user != null && user.getInteger("code") == 0) { return user.getJSONObject("data").getInteger("point"); } @@ -70,7 +76,12 @@ public class BiliBiliManga { JSONObject json = new JSONObject(); if (isPayMission) { json.put("code", 2); - json.put("msg", "任务正在进行:" +getMission()); + json.put("msg", "任务正在进行:" + getMission()); + return json; + } + if (biliUtils == null) { + json.put("code", -1); + json.put("msg", "B站未登录"); return json; } int userPoint = getMyPoint(); @@ -107,9 +118,9 @@ public class BiliBiliManga { if (num == 0) { json.put("code", 3); json.put("msg", "商品无货,正在抢购"); - }else { + } else { json.put("code", 0); - json.put("msg", "任务创建成功:"+missionProduct+" 兑换数量:"+num); + json.put("msg", "任务创建成功:" + missionProduct + " 兑换数量:" + num); } return json; } @@ -122,24 +133,18 @@ public class BiliBiliManga { mission.schedule(new TimerTask() { @Override public void run() { - JSONObject post = BiliBiliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/Exchange", HttpTools.toUrlParams(data)); + JSONObject post = biliUtils.http_post("https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/Exchange", HttpTools.toUrlParams(data)); if (post == null) { - for (ObjectInterface objectInterface : anInterface) { - objectInterface.out("网络请求失败,请查看日志"); - } + anInterface.out("网络请求失败,请查看日志"); cancel(); return; } if (post.getInteger("code") == 0) { - for (ObjectInterface mInt : anInterface) { - mInt.out("兑换成功,任务已取消"); - } + anInterface.out("兑换成功,任务已取消"); isPayMission = false; cancel(); } else { - for (ObjectInterface objectInterface : anInterface) { - objectInterface.out("[" + post.getInteger("code") + "]" + post.getString("msg")); - } + anInterface.out("[" + post.getInteger("code") + "]" + post.getString("msg")); } } }, 0, 1000); diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index 3a7ce38..6b4b23a 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -2,8 +2,10 @@ package com.yutou.qqbot.bilibili; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.utlis.*; +import org.brotli.dec.BrotliInputStream; import javax.net.ssl.HttpsURLConnection; import java.io.*; @@ -12,12 +14,13 @@ import java.net.InetSocketAddress; import java.net.Proxy; import java.net.URL; import java.nio.charset.StandardCharsets; -import java.util.LinkedHashMap; import java.util.List; import java.util.Map; +import java.util.zip.GZIPInputStream; public class BiliBiliUtils { - private static long oldBiliBiliHttpTime = 0; + private long qq; + private long oldBiliBiliHttpTime = 0; public enum HTTP { POST, GET @@ -27,14 +30,22 @@ public class BiliBiliUtils { BYTE, JSON } - public synchronized static JSONObject http_get(String url) { + public BiliBiliUtils(long qq) { + this.qq = qq; + } + + public static BiliBiliUtils getInstance(long qq) { + return new BiliBiliUtils(qq); + } + + public synchronized JSONObject http_get(String url) { try { // Log.i("调用url = "+url); HttpsURLConnection connection = getBiliHttpGet(url, getCookie()); BufferedInputStream stream = new BufferedInputStream(connection.getInputStream()); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; - int len = 0, size; + int len; while ((len = stream.read(bytes)) != -1) { outputStream.write(bytes, 0, len); outputStream.flush(); @@ -42,8 +53,7 @@ public class BiliBiliUtils { String str = outputStream.toString(StandardCharsets.UTF_8); outputStream.close(); try { - JSONObject json = JSON.parseObject(str); - return json; + return JSON.parseObject(str); } catch (Exception e) { JSONObject json = new JSONObject(); json.put("html", str); @@ -61,15 +71,15 @@ public class BiliBiliUtils { return null; } - public static JSONObject http_post(String url, String body) { + public JSONObject http_post(String url, String body) { return http(url, HTTP.POST, body, RET_MODEL.JSON); } - public static T http(String url, HTTP model, String body, RET_MODEL ret_model) { + public T http(String url, HTTP model, String body, RET_MODEL ret_model) { return http(url, model, body, null, ret_model); } - public static T http(String url, HTTP model, String body, Map headers, RET_MODEL ret_model) { + public T http(String url, HTTP model, String body, Map headers, RET_MODEL ret_model) { JSONObject json = null; BufferedInputStream stream = null; ByteArrayOutputStream outputStream = null; @@ -101,9 +111,9 @@ public class BiliBiliUtils { for (String key : headers.keySet()) { connection.setRequestProperty(key, headers.get(key)); } + } else { + connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); } - System.out.println("url = " + url); - connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); if (!StringUtils.isEmpty(body)) { connectionOutputStream = connection.getOutputStream(); @@ -114,7 +124,13 @@ public class BiliBiliUtils { if (connection.getResponseCode() == 400) { return null; } - stream = new BufferedInputStream(connection.getInputStream()); + if (connection.getContentEncoding() != null && connection.getContentEncoding().contains("gzip")) { + stream = new BufferedInputStream(new GZIPInputStream(connection.getInputStream())); + } else if (connection.getContentEncoding() != null && connection.getContentEncoding().contains("br")) { + stream = new BufferedInputStream(new BrotliInputStream(connection.getInputStream())); + } else { + stream = new BufferedInputStream(connection.getInputStream()); + } outputStream = new ByteArrayOutputStream(); byte[] bytes = new byte[1024]; int len = 0, size; @@ -162,12 +178,11 @@ public class BiliBiliUtils { return null; } - public static String getCookie() { - if (StringUtils.isEmpty(ConfigTools.readFile(new File("bilibili.cookie")))) { - + public String getCookie() { + if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq + "_bilibili.cookie")))) { return ""; } - JSONObject json = JSON.parseObject(ConfigTools.readFile(new File("bilibili.cookie"))); + JSONObject json = JSON.parseObject(ConfigTools.readFile(new File(qq + "_bilibili.cookie"))); StringBuilder builder = new StringBuilder(); for (String s : json.keySet()) { builder.append(s).append("=").append(json.getString(s)).append(";"); @@ -176,7 +191,7 @@ public class BiliBiliUtils { return builder.toString(); } - public static HttpURLConnection getBiliHttpPost(String url, String cookie) throws Exception { + public HttpURLConnection getBiliHttpPost(String url, String cookie) throws Exception { if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) { try { Thread.sleep(500); @@ -193,7 +208,7 @@ public class BiliBiliUtils { return connection; } - public static HttpsURLConnection getBiliHttpGet(String url, String cookie) throws IOException { + public HttpsURLConnection getBiliHttpGet(String url, String cookie) throws IOException { if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) { try { Thread.sleep(500); @@ -210,7 +225,7 @@ public class BiliBiliUtils { return connection; } - public static File download(final String url, final String saveName, boolean isProxy) { + public File download(final String url, final String saveName, boolean isProxy) { File jar = null; try { File savePath = new File(HttpTools.downloadPath + saveName); @@ -262,7 +277,7 @@ public class BiliBiliUtils { return null; } - public static void download_ffmpeg(final List url, final String saveName) { + public void download_ffmpeg(final List url, final String saveName) { new Thread(() -> { StringBuilder builder = new StringBuilder(); builder.append(ConfigTools.load(ConfigTools.CONFIG, "ffmpeg", String.class)).append(" "); @@ -296,7 +311,7 @@ public class BiliBiliUtils { } - private static void setConnection(String cookie, HttpURLConnection connection) { + private void setConnection(String cookie, HttpURLConnection connection) { connection.addRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8"); connection.addRequestProperty("Accept-Language", "zh-CN,zh;q=0.8"); connection.addRequestProperty("Cache-Control", "max-age=0"); @@ -307,8 +322,8 @@ public class BiliBiliUtils { connection.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.157 Safari/537.36"); } - public static JSONObject getLoginInfo() { - JSONObject jsonObject = BiliBiliUtils.http_get("https://api.bilibili.com/x/web-interface/nav"); + public JSONObject getLoginInfo() { + JSONObject jsonObject = http_get("https://api.bilibili.com/x/web-interface/nav"); if (jsonObject == null) { jsonObject = new JSONObject(); jsonObject.put("code", "-1"); @@ -317,9 +332,9 @@ public class BiliBiliUtils { return jsonObject; } - public static void main(String[] args) { + public void main(String[] args) { /* String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; - File file=BiliBiliUtils.download(url,"16.mp4",false); + File file=download(url,"16.mp4",false); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());*/ /* System.out.println(getLiveRoom(42062)); System.out.println("--------------------------------------------"); @@ -328,44 +343,44 @@ public class BiliBiliUtils { System.out.println("sign = " + sign); } - public static boolean sendLiveDanmu(long roomId, String msg) { + public boolean sendLiveDanmu(long roomId, String msg) { JSONObject body = new JSONObject(); body.put("msg", msg); body.put("roomid", roomId); body.put("color", 16777215); body.put("fontsize", 25); body.put("rnd", System.currentTimeMillis() / 1000); - body.put("csrf", BiliLogin.getCookieToken()); - body.put("csrf_token", BiliLogin.getCookieToken()); - JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body)); + body.put("csrf", BiliLogin.getCookieToken(qq)); + body.put("csrf_token", BiliLogin.getCookieToken(qq)); + JSONObject post = http_post("https://api.live.bilibili.com/msg/send", HttpTools.toUrlParams(body)); return post.getInteger("code") == 0; } - public static String liveSignIn() { + public String liveSignIn() { //{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"} JSONObject body = new JSONObject(); - body.put("csrf", BiliLogin.getCookieToken()); - body.put("csrf_token", BiliLogin.getCookieToken()); - JSONObject post = BiliBiliUtils.http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); - JSONObject post_ = BiliBiliUtils.http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); + body.put("csrf", BiliLogin.getCookieToken(qq)); + body.put("csrf_token", BiliLogin.getCookieToken(qq)); + JSONObject post = http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); + JSONObject post_ = http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); return post.getString("message") + "|" + post_.getString("message"); } - public static JSONObject getLiveRoom(int roomId) { + public JSONObject getLiveRoom(int roomId) { JSONObject body = new JSONObject(); body.put("room_id", roomId); - body.put("csrf", BiliLogin.getCookieToken()); - body.put("csrf_token", BiliLogin.getCookieToken()); - return BiliBiliUtils.http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); + body.put("csrf", BiliLogin.getCookieToken(qq)); + body.put("csrf_token", BiliLogin.getCookieToken(qq)); + return http_post("https://api.live.bilibili.com/room/v1/Room/get_info", HttpTools.toUrlParams(body)); } - public static JSONObject getUserInfo(int mid) { + public JSONObject getUserInfo(int mid) { JSONObject body = new JSONObject(); body.put("mid", mid); - return BiliBiliUtils.http_get("https://api.bilibili.com/x/space/acc/info?" + HttpTools.toUrlParams(body)); + return http_get("https://api.bilibili.com/x/space/acc/info?" + HttpTools.toUrlParams(body)); } - public static boolean checkLiveRoom(int roomId) { + public boolean checkLiveRoom(int roomId) { JSONObject post = getLiveRoom(roomId); return post.getInteger("code") == 0; } diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java index 153b2f4..6005db6 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java @@ -15,73 +15,92 @@ import java.util.TimerTask; public class BiliLogin { + BiliBiliUtils biliUtils; + private long qq; - public JSONObject login(){ - JSONObject login= JSON.parseObject(HttpTools.get("https://passport.bilibili.com/qrcode/getLoginUrl")); - JSONObject json=new JSONObject(); - json.put("code",login.getInteger("code")); - json.put("url",login.getJSONObject("data").getString("url")); + + public BiliLogin(Long qq) { + biliUtils = BiliBiliUtils.getInstance(qq); + this.qq=qq; + } + + public JSONObject login() { + JSONObject login = JSON.parseObject(HttpTools.get("https://passport.bilibili.com/qrcode/getLoginUrl")); + JSONObject json = new JSONObject(); + json.put("code", login.getInteger("code")); + json.put("url", login.getJSONObject("data").getString("url")); new Thread(() -> waitLogin(login.getJSONObject("data").getString("oauthKey"))).start(); return json; } - public void waitLogin(String oauthKey){ - long time=System.currentTimeMillis(); - String bd="gourl=https%3A%2F%2Fpassport.bilibili.com%2Fajax%2FminiLogin%2Fredirect&oauthKey="+oauthKey; + public void waitLogin(String oauthKey) { + long time = System.currentTimeMillis(); + String bd = "gourl=https%3A%2F%2Fpassport.bilibili.com%2Fajax%2FminiLogin%2Fredirect&oauthKey=" + oauthKey; new Timer().schedule(new TimerTask() { @Override public void run() { - if((System.currentTimeMillis()-time)>5*60*1000){ + if ((System.currentTimeMillis() - time) > 5 * 60 * 1000) { cancel(); return; } - JSONObject json=JSON.parseObject(HttpTools.post("https://passport.bilibili.com/qrcode/getLoginInfo",bd.getBytes(StandardCharsets.UTF_8))); - if(json.containsKey("code")&&json.getInteger("code")==0){ + JSONObject json = JSON.parseObject(HttpTools.post("https://passport.bilibili.com/qrcode/getLoginInfo", bd.getBytes(StandardCharsets.UTF_8))); + if (json.containsKey("code") && json.getInteger("code") == 0) { System.out.println("json = " + json); - String _url=json.getJSONObject("data").getString("url"); - Map map=HttpTools.getUrlParams(_url); + String _url = json.getJSONObject("data").getString("url"); + Map map = HttpTools.getUrlParams(_url); - JSONObject cookie=new JSONObject(); - JSONArray array=new JSONArray(); + JSONObject cookie = new JSONObject(); + JSONArray array = new JSONArray(); for (String key : map.keySet()) { - cookie.put(key,map.get(key)); + cookie.put(key, map.get(key)); } System.out.println(array); + if (biliUtils == null) { + biliUtils = BiliBiliUtils.getInstance(qq); + } + assert biliUtils != null; - JSONObject tmp=BiliBiliUtils.http_post(_url,""); + JSONObject tmp = biliUtils.http_post(_url, ""); System.out.println("tmp = " + tmp); - if(tmp==null){ + if (tmp == null) { cancel(); return; } - String sid=tmp.getString("cookie"); - sid=sid.split("sid=")[1]; - sid=sid.split(";")[0]; - cookie.put("sid",sid); - cookie.put("Domain",".bilibili.com"); - ConfigTools.saveFile(new File("bilibili.cookie"),cookie.toJSONString()); + String sid = tmp.getString("cookie"); + sid = sid.split("sid=")[1]; + sid = sid.split(";")[0]; + cookie.put("sid", sid); + cookie.put("Domain", ".bilibili.com"); + ConfigTools.saveFile(new File(qq + "_bilibili.cookie"), cookie.toJSONString()); cancel(); } } - },0,3000); + }, 0, 3000); } - public boolean testLogin(){ - JSONObject jsonObject = BiliBiliUtils.getLoginInfo(); - return jsonObject.getInteger("code")==0; + + public boolean testLogin() { + if (biliUtils == null) { + return false; + } + JSONObject jsonObject = biliUtils.getLoginInfo(); + return jsonObject.getInteger("code") == 0; } - public static String getCookieToken(){ - if (StringUtils.isEmpty(ConfigTools.readFile(new File("bilibili.cookie")))) { + + public static String getCookieToken(Long qq) { + if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq+"_bilibili.cookie")))) { return null; } - JSONObject json = JSON.parseObject(ConfigTools.readFile(new File("bilibili.cookie"))); + JSONObject json = JSON.parseObject(ConfigTools.readFile(new File(qq+"_bilibili.cookie"))); return json.getString("bili_jct"); } public static void main(String[] args) { - BiliLogin login = new BiliLogin(); + BiliLogin login = new BiliLogin(583819556L); boolean testLogin = login.testLogin(); System.out.println("testLogin = " + testLogin); + // JSONObject json = login.login(); + // QRCodeUtils.createQRCode("bili_login", json.getString("url")); } } diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index b60f98e..5bf875d 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -2,7 +2,8 @@ package com.yutou.qqbot.models.BiliBili; import com.yutou.qqbot.Annotations.UseModel; import com.yutou.qqbot.QQBotManager; -import com.yutou.qqbot.bilibili.BiliBiliManga; +import com.yutou.qqbot.bilibili.AppUserTask; +import com.yutou.qqbot.bilibili.BiliBiliAppUtils; import com.yutou.qqbot.bilibili.BiliBiliUtils; import com.yutou.qqbot.models.Model; import com.yutou.qqbot.utlis.RedisTools; @@ -20,6 +21,7 @@ public class BiliBiliLive extends Model { @Override public String[] getUsePowers() { return new String[]{ + Model.QQGroupCommands.BILI_LIVE_DANMU_LIST, Model.QQGroupCommands.BILI_LIVE_DANMU_SEND, QQGroupCommands.BILI_LIVE_DANMU_DEL }; @@ -34,32 +36,45 @@ public class BiliBiliLive extends Model { public synchronized void onTime(Long qq, String time) { super.onTime(qq, time); if ("00:01:00".equals(time)) { - QQBotManager.getInstance().sendMessage(qq, BiliBiliUtils.liveSignIn()); - Set biliLive = RedisTools.list_get("bili_live"); - StringBuilder builder = new StringBuilder(); - for (String id : biliLive) { - try { - Thread.sleep(1000); - } catch (InterruptedException e) { - throw new RuntimeException(e); - } - boolean sign = BiliBiliUtils.sendLiveDanmu(Integer.parseInt(id), "打卡"); - builder.append("BiliLiveSign ").append(id).append(":").append(sign).append("\n"); - } - QQBotManager.getInstance().sendMessage(qq, builder.toString()); + signLive(QQBotManager.defQQ, qq); } } + private void signLive(long qq, long sendQQ) { + BiliBiliUtils biliUtils = BiliBiliUtils.getInstance(qq); + QQBotManager.getInstance().sendMessage(sendQQ, biliUtils.liveSignIn()); + Set biliLive = RedisTools.list_get("bili_live"); + StringBuilder builder = new StringBuilder(); + for (String id : biliLive) { + try { + Thread.sleep(1000); + } catch (InterruptedException e) { + throw new RuntimeException(e); + } + boolean sign = biliUtils.sendLiveDanmu(Integer.parseInt(id), "打卡"); + builder.append("BiliLiveSign").append(id).append(":").append(sign).append("\n"); + } + QQBotManager.getInstance().sendMessage(sendQQ, builder.toString()); + AppUserTask task = new BiliBiliAppUtils(QQBotManager.defQQ).startAppTask(); + builder = new StringBuilder(); + builder.append("执行APP任务").append("\n").append(task.toMessageFormat()); + QQBotManager.getInstance().sendMessage(sendQQ, builder.toString()); + } + @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); - if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND) && !msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { + if (!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND) && + !msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL) && + !msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_LIST)) { return; } - if(msg.equals(QQGroupCommands.BILI_LIVE_DANMU_SEND+"debug")){ - onTime(qq,"00:01:00"); + if (msg.equals(QQGroupCommands.BILI_LIVE_DANMU_SEND)) { + signLive(user, qq); return; } + + BiliBiliUtils biliUtils = BiliBiliUtils.getInstance(isGroup ? event.getSource().getFromId() : qq); StringBuilder message; message = new StringBuilder(); try { @@ -67,11 +82,13 @@ public class BiliBiliLive extends Model { if (msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) { isDel = true; msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_DEL, "").trim(); - } else { + } else if (msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_SEND)) { msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_SEND, "").trim(); + } else { + msg = "0"; } Integer roomId = Integer.parseInt(msg); - if (BiliBiliUtils.checkLiveRoom(roomId)) { + if (biliUtils.checkLiveRoom(roomId) && roomId != 0) { if (isDel && RedisTools.list_isExist("bili_live", roomId + "")) { RedisTools.list_remove("bili_live", roomId + ""); message.append("直播签到删除成功").append("\n"); @@ -79,7 +96,7 @@ public class BiliBiliLive extends Model { RedisTools.list_add("bili_live", roomId + ""); message.append("直播签到添加成功").append("\n"); } - } else { + } else if (roomId != 0) { message.append("直播签到操作失败\n"); } } catch (Exception e) { @@ -90,8 +107,8 @@ public class BiliBiliLive extends Model { for (String id : biliLive) { message.append(id) .append(":") - .append(BiliBiliUtils.getUserInfo( - BiliBiliUtils.getLiveRoom(Integer.parseInt(id)) + .append(biliUtils.getUserInfo( + biliUtils.getLiveRoom(Integer.parseInt(id)) .getJSONObject("data") .getInteger("uid")) .getJSONObject("data") diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliVideo.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliVideo.java index e23313b..2dd41ff 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliVideo.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliVideo.java @@ -3,6 +3,7 @@ package com.yutou.qqbot.models.BiliBili; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; import com.yutou.qqbot.Annotations.UseModel; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.bilibili.*; import com.yutou.qqbot.interfaces.ObjectInterface; import com.yutou.qqbot.models.Model; @@ -23,6 +24,18 @@ public class BiliVideo extends Model { public String downloadPath = "tmp"; List danmuDatas = new ArrayList<>(); long danmuNextTime = 0; + private BiliBiliUtils biliUtils; + private long qq; + + public BiliVideo(long qq) { + this.qq = qq; + biliUtils = BiliBiliUtils.getInstance(qq); + } + + public BiliVideo() { + this.qq = QQBotManager.defQQ; + biliUtils = BiliBiliUtils.getInstance(qq); + } @Override public boolean isUserPublic() { @@ -44,7 +57,7 @@ public class BiliVideo extends Model { } public void downVideo(String url, boolean downDanmu, boolean merge) { - if (!new BiliLogin().testLogin()) { + if (biliUtils == null || !new BiliLogin(qq).testLogin()) { System.err.println("未登录"); return; } @@ -196,19 +209,19 @@ public class BiliVideo extends Model { if (tmp.exists()) { return; } - JSONObject http = BiliBiliUtils.http("https://api.bilibili.com/x/player/playurl?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON); + JSONObject http = biliUtils.http("https://api.bilibili.com/x/player/playurl?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON); if (http.getInteger("code") == 0) { JSONObject data = http.getJSONObject("data"); JSONObject dash = data.getJSONObject("dash"); JSONObject video = dash.getJSONArray("video").getJSONObject(0); JSONObject audio = dash.getJSONArray("audio").getJSONObject(0); - File videoFile = BiliBiliUtils.download(video.getString("baseUrl"), eps.getString("title") + "_video.mp4", false); + File videoFile = biliUtils.download(video.getString("baseUrl"), eps.getString("title") + "_video.mp4", false); if (videoFile == null) { downVideo(json, eps); return; } - File audioFile = BiliBiliUtils.download(audio.getString("baseUrl"), eps.getString("title") + "_audio.mp3", false); + File audioFile = biliUtils.download(audio.getString("baseUrl"), eps.getString("title") + "_audio.mp3", false); if (audioFile == null) { videoFile.delete(); downVideo(json, eps); @@ -255,7 +268,7 @@ public class BiliVideo extends Model { private List getDanmu(JSONObject json) { try { - byte[] http = BiliBiliUtils.http("https://api.bilibili.com/x/v2/dm/web/seg.so?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.BYTE); + byte[] http = biliUtils.http("https://api.bilibili.com/x/v2/dm/web/seg.so?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.BYTE); VideoDanMu.DmSegMobileReply parse = VideoDanMu.DmSegMobileReply.parseFrom(http); return parse.getElemsList(); } catch (Exception e) { @@ -298,13 +311,13 @@ public class BiliVideo extends Model { } public JSONObject getVideoInfo(String url) { - if (!new BiliLogin().testLogin()) { + if (!new BiliLogin(qq).testLogin()) { System.err.println("未登录"); return null; } JSONObject json = buildJSON(url); if (json != null) { - return BiliBiliUtils.http("https://api.bilibili.com/x/web-interface/view?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON); + return biliUtils.http("https://api.bilibili.com/x/web-interface/view?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON); } return null; } @@ -336,8 +349,8 @@ public class BiliVideo extends Model { public static void main(String[] args) { - BiliVideo video = new BiliVideo(); - JSONObject login = new BiliLogin().login(); + BiliVideo video = new BiliVideo(QQBotManager.defQQ); + JSONObject login = new BiliLogin(QQBotManager.defQQ).login(); System.out.println(login); //岚少 480 //video.downVideo("https://www.bilibili.com/video/BV1Ps411m7pt?spm_id_from=333.999.0.0"); diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index c7023ad..e0ef13f 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -1,7 +1,9 @@ package com.yutou.qqbot.models; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.QQNumberManager; import com.yutou.qqbot.interfaces.ModelInterface; +import net.mamoe.mirai.Bot; import net.mamoe.mirai.event.events.GroupMessageEvent; import net.mamoe.mirai.event.events.MessageEvent; import net.mamoe.mirai.message.data.At; @@ -35,15 +37,16 @@ public abstract class Model implements ModelInterface { public final static String QQ_BANGUMI_INFO = "!保存动画信息>"; public final static String QQ_MOYU = "!摸鱼"; - public final static String BILI_LIVE_DANMU_SEND="!b站签到"; - public final static String BILI_LIVE_DANMU_DEL="!b站签到删除"; + public final static String BILI_LIVE_DANMU_SEND = "!b站签到"; + public final static String BILI_LIVE_DANMU_LIST = "!b站列表"; + public final static String BILI_LIVE_DANMU_DEL = "!b站签到删除"; - public final static String QQ_WOODEN="!电子木鱼"; - public final static String QQ_TIMEOUT="!timer"; + public final static String QQ_WOODEN = "!电子木鱼"; + public final static String QQ_TIMEOUT = "!timer"; } - public static class QQFromCommands { + public static class QQFromCommands { public static final String TURNIP_PROPHET = "大头菜"; public static final String TSDM_PAY = "!tsdm"; public static final String BAIDU_DOWN = "!bd"; @@ -58,9 +61,11 @@ public abstract class Model implements ModelInterface { public static List> classList; long group; + static { - classList=new ArrayList<>(); + classList = new ArrayList<>(); } + public Model() { if (!classList.contains(getClass())) { classList.add(getClass()); @@ -71,14 +76,14 @@ public abstract class Model implements ModelInterface { public String msg; protected boolean isGroupPower = false; private boolean isGroup; - private Long user; + public Long user; public void onMessage(Long qq, MessageEvent event, boolean isGroup) { msg = event.getMessage().contentToString(); msg = msg.replace("!", "!").trim(); this.isGroup = isGroup; if (isGroup) { - user=event.getSource().getFromId(); + user = event.getSource().getFromId(); GroupMessageEvent groupEvent = (GroupMessageEvent) event; group = groupEvent.getGroup().getId(); if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) { @@ -87,7 +92,7 @@ public abstract class Model implements ModelInterface { } } - public synchronized void onTime(Long qq,String time) { + public synchronized void onTime(Long qq, String time) { } public static StringBuilder getCommands(Class commands) { diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java index 110872a..fb431c8 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java @@ -36,7 +36,7 @@ public class BiliBiliMangeSign extends Model { super.onMessage(qq, event, isGroup); if (msg.equals(QQFromCommands.BILI_MANGA_SIGN)) { String msg; - if (new BiliLogin().testLogin()) { + if (new BiliLogin(user).testLogin()) { if (BiliBiliManga.sign() == null) { msg = "B站漫画已经签到过了"; } else { @@ -44,7 +44,7 @@ public class BiliBiliMangeSign extends Model { } QQBotManager.getInstance().sendMessage(qq, msg); } else { - String url = new BiliLogin().login().getString("url"); + String url = new BiliLogin(user).login().getString("url"); File code = QRCodeUtils.createQRCode("bili_login", url); QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); } @@ -118,7 +118,7 @@ public class BiliBiliMangeSign extends Model { public void onTime(Long qq,String time) { super.onTime(qq,time); if ("00:01:00".equals(time)) { - if (new BiliLogin().testLogin()) { + if (new BiliLogin(QQBotManager.defQQ).testLogin()) { String msg; if (BiliBiliManga.sign() == null) { msg = "B站漫画已经签到过了"; diff --git a/src/main/java/com/yutou/qqbot/utlis/RSAUtils.java b/src/main/java/com/yutou/qqbot/utlis/RSAUtils.java new file mode 100644 index 0000000..64d8adb --- /dev/null +++ b/src/main/java/com/yutou/qqbot/utlis/RSAUtils.java @@ -0,0 +1,136 @@ +package com.yutou.qqbot.utlis; + +import org.apache.commons.codec.binary.Base64; + +import javax.crypto.Cipher; +import java.io.ByteArrayOutputStream; +import java.security.*; +import java.security.spec.PKCS8EncodedKeySpec; +import java.security.spec.X509EncodedKeySpec; +import java.util.HashMap; +import java.util.Map; + +public class RSAUtils { + /** + * 加密算法RSA + */ + public static final String KEY_ALGORITHM = "RSA"; + + /** + * 签名算法 + */ + public static final String SIGNATURE_ALGORITHM = "MD5withRSA"; + + /** + * 获取公钥的key + */ + private static final String PUBLIC_KEY = "RSAPublicKey"; + + /** + * 获取私钥的key + */ + private static final String PRIVATE_KEY = "RSAPrivateKey"; + + /** + * RSA 密钥位数 + */ + private static final int KEY_SIZE = 1024; + + /** + * RSA最大解密密文大小 + */ + private static final int MAX_DECRYPT_BLOCK = KEY_SIZE / 8; + + /** + * RSA最大加密明文大小 + */ + private static final int MAX_ENCRYPT_BLOCK = MAX_DECRYPT_BLOCK - 11; + private static Map keyMap=new HashMap<>(); + + /** + * 随机生成密钥对 + * @throws NoSuchAlgorithmException + */ + public static void getKeyPair() throws Exception { + //KeyPairGenerator类用于生成公钥和密钥对,基于RSA算法生成对象 + KeyPairGenerator keyPairGen = KeyPairGenerator.getInstance("RSA"); + //初始化密钥对生成器,密钥大小为96-1024位 + keyPairGen.initialize(1024,new SecureRandom()); + //生成一个密钥对,保存在keyPair中 + KeyPair keyPair = keyPairGen.generateKeyPair(); + PrivateKey privateKey = keyPair.getPrivate();//得到私钥 + PublicKey publicKey = keyPair.getPublic();//得到公钥 + //得到公钥字符串 + String publicKeyString=new String(Base64.encodeBase64(publicKey.getEncoded())); + //得到私钥字符串 + String privateKeyString=new String(Base64.encodeBase64(privateKey.getEncoded())); + //将公钥和私钥保存到Map + keyMap.put(0,publicKeyString);//0表示公钥 + keyMap.put(1,privateKeyString);//1表示私钥 + } + /** + *

+ * 公钥加密 + *

+ * + * @param str 源数据 + * @param publicKey 公钥(BASE64编码) + * @return + * @throws Exception + */ + public static String encryptByPublicKey(String str, String publicKey) throws Exception { + publicKey=publicKey.replace("-----BEGIN PUBLIC KEY-----","").replace("-----END PUBLIC KEY-----",""); + byte[] data=Base64.decodeBase64(str); + byte[] keyBytes = Base64.decodeBase64(publicKey); + X509EncodedKeySpec x509KeySpec = new X509EncodedKeySpec(keyBytes); + KeyFactory keyFactory = KeyFactory.getInstance(KEY_ALGORITHM); + Key publicK = keyFactory.generatePublic(x509KeySpec); + // 对数据加密 + Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm()); + cipher.init(Cipher.ENCRYPT_MODE, publicK); + int inputLen = data.length; + ByteArrayOutputStream out = new ByteArrayOutputStream(); + int offSet = 0; + byte[] cache; + int i = 0; + // 对数据分段加密 + while (inputLen - offSet > 0) { + if (inputLen - offSet > MAX_ENCRYPT_BLOCK) { + cache = cipher.doFinal(data, offSet, MAX_ENCRYPT_BLOCK); + } else { + cache = cipher.doFinal(data, offSet, inputLen - offSet); + } + out.write(cache, 0, cache.length); + i++; + offSet = i * MAX_ENCRYPT_BLOCK; + } + byte[] encryptedData = out.toByteArray(); + out.close(); + return new String(Base64.encodeBase64(encryptedData)); + } + + /** + * RSA私钥解密 + * + * @param str + * 加密字符串 + * @param privateKey + * 私钥 + * @return 铭文 + * @throws Exception + * 解密过程中的异常信息 + */ + public static String decrypt(String str,String privateKey) throws Exception { + //Base64解码加密后的字符串 + byte[] inputByte = Base64.decodeBase64(str.getBytes("UTF-8")); + //Base64编码的私钥 + byte[] decoded = Base64.decodeBase64(privateKey); + PrivateKey priKey = KeyFactory.getInstance("RSA").generatePrivate(new PKCS8EncodedKeySpec(decoded)); + //RSA解密 + Cipher cipher = Cipher.getInstance("RSA"); + cipher.init(Cipher.DECRYPT_MODE,priKey); + String outStr=new String(cipher.doFinal(inputByte)); + return outStr; + + } +} diff --git a/src/main/java/com/yutou/qqbot/utlis/RedisTools.java b/src/main/java/com/yutou/qqbot/utlis/RedisTools.java index 0cc9ea8..924a58a 100644 --- a/src/main/java/com/yutou/qqbot/utlis/RedisTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/RedisTools.java @@ -168,28 +168,46 @@ public class RedisTools { } public static Set list_get(String listName) { - Jedis jedis = getRedis(); - jedis.select(QQBOT_USER); - Set set = jedis.smembers(listName); - jedis.close(); - if (set == null) { + Set set; + try { + Jedis jedis = getRedis(); + jedis.select(QQBOT_USER); + set = jedis.smembers(listName); + jedis.close(); + if (set == null) { + set = new HashSet<>(); + } + } catch (Exception e) { + e.printStackTrace(); set = new HashSet<>(); } + return set; } public static boolean list_remove(String listName, String... value) { - Jedis jedis = getRedis(); - jedis.select(QQBOT_USER); - long index = jedis.srem(listName, value); - jedis.close(); + long index = 0; + try { + Jedis jedis = getRedis(); + jedis.select(QQBOT_USER); + index = jedis.srem(listName, value); + jedis.close(); + } catch (Exception e) { + e.printStackTrace(); + } + return index != 0; } public static boolean list_isExist(String listName, String value) { - Jedis jedis = getRedis(); - boolean flag = jedis.sismember(listName, value); - jedis.close(); + boolean flag = false; + try { + Jedis jedis = getRedis(); + flag = jedis.sismember(listName, value); + jedis.close(); + } catch (Exception e) { + e.printStackTrace(); + } return flag; } -- 2.43.0 From 5d15f24847231a8ba69307d2214e81d35f478429 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 5 Jan 2023 15:18:53 +0800 Subject: [PATCH 34/54] =?UTF-8?q?=E6=96=B0=E5=A2=9EB=E7=AB=99=E5=A4=A7?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=A7=AF=E5=88=86=E7=AD=BE=E5=88=B0=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DB=E7=AB=99=E6=93=8D=E4=BD=9C=E5=89=8D?= =?UTF-8?q?=E6=B2=A1=E5=81=9A=E7=99=BB=E9=99=86=E6=A0=A1=E9=AA=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/qqbot/QQBotApplication.java | 2 +- .../yutou/qqbot/bilibili/BiliBiliAppUtils.java | 4 ++-- .../com/yutou/qqbot/bilibili/BiliBiliUtils.java | 11 ++++++----- .../yutou/qqbot/models/BiliBili/BiliBiliLive.java | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index a2e6f89..f27ab4a 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.4b"; + public static final String version="QQBot v.1.4b.1"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java index 0070530..4bbb6b9 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java @@ -43,7 +43,7 @@ public class BiliBiliAppUtils { } private Map sign(Map map) { - map.putAll(getDefaultHeader()); + map.putAll(getDefaultBody()); map = sort(map); StringBuilder builder = new StringBuilder(); for (String key : map.keySet()) { @@ -54,7 +54,7 @@ public class BiliBiliAppUtils { return map; } - private Map getDefaultHeader() { + private Map getDefaultBody() { Map map = new TreeMap<>(); map.put("access_key", getAccessToken()); map.put("actionKey", "appkey"); diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index 6b4b23a..81b1ccc 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -332,14 +332,14 @@ public class BiliBiliUtils { return jsonObject; } - public void main(String[] args) { + public static void main(String[] args) { /* String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; File file=download(url,"16.mp4",false); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());*/ /* System.out.println(getLiveRoom(42062)); System.out.println("--------------------------------------------"); System.out.println(getUserInfo(730732));*/ - String sign = liveSignIn(); + String sign = new BiliBiliUtils(583819556).liveSignIn(); System.out.println("sign = " + sign); } @@ -361,9 +361,10 @@ public class BiliBiliUtils { JSONObject body = new JSONObject(); body.put("csrf", BiliLogin.getCookieToken(qq)); body.put("csrf_token", BiliLogin.getCookieToken(qq)); - JSONObject post = http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); - JSONObject post_ = http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); - return post.getString("message") + "|" + post_.getString("message"); + JSONObject toCoin = http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); + JSONObject liveSign = http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); + JSONObject vipSign = http_post("https://api.bilibili.com/pgc/activity/score/task/sign", null); + return "银瓜子兑换硬币:"+toCoin.getString("message") + "|" +"直播签到:"+ liveSign.getString("message")+"|大会员中心签到:"+vipSign.getString("message"); } public JSONObject getLiveRoom(int roomId) { diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 5bf875d..053c18c 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -5,10 +5,13 @@ import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.bilibili.AppUserTask; import com.yutou.qqbot.bilibili.BiliBiliAppUtils; import com.yutou.qqbot.bilibili.BiliBiliUtils; +import com.yutou.qqbot.bilibili.BiliLogin; import com.yutou.qqbot.models.Model; +import com.yutou.qqbot.utlis.QRCodeUtils; import com.yutou.qqbot.utlis.RedisTools; import net.mamoe.mirai.event.events.MessageEvent; +import java.io.File; import java.util.Set; @UseModel @@ -36,6 +39,12 @@ public class BiliBiliLive extends Model { public synchronized void onTime(Long qq, String time) { super.onTime(qq, time); if ("00:01:00".equals(time)) { + if(!new BiliLogin(qq).testLogin()){ + String url = new BiliLogin(QQBotManager.defQQ).login().getString("url"); + File code = QRCodeUtils.createQRCode("bili_login", url); + QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + return; + } signLive(QQBotManager.defQQ, qq); } } @@ -88,6 +97,12 @@ public class BiliBiliLive extends Model { msg = "0"; } Integer roomId = Integer.parseInt(msg); + if(!new BiliLogin(qq).testLogin()){ + String url = new BiliLogin(user).login().getString("url"); + File code = QRCodeUtils.createQRCode("bili_login", url); + QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + return; + } if (biliUtils.checkLiveRoom(roomId) && roomId != 0) { if (isDel && RedisTools.list_isExist("bili_live", roomId + "")) { RedisTools.list_remove("bili_live", roomId + ""); -- 2.43.0 From 938d3d532ab3963f18d53471531a4b96fb9611e7 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 6 Jan 2023 01:23:34 +0800 Subject: [PATCH 35/54] =?UTF-8?q?=E6=96=B0=E5=A2=9EB=E7=AB=99=E5=A4=A7?= =?UTF-8?q?=E4=BC=9A=E5=91=98=E7=A7=AF=E5=88=86=E7=AD=BE=E5=88=B0=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8DB=E7=AB=99=E6=93=8D=E4=BD=9C=E5=89=8D?= =?UTF-8?q?=E6=B2=A1=E5=81=9A=E7=99=BB=E9=99=86=E6=A0=A1=E9=AA=8C=E7=9A=84?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/qqbot/bilibili/AppUserTask.java | 10 ++++++---- .../com/yutou/qqbot/bilibili/BiliBiliAppUtils.java | 1 + .../java/com/yutou/qqbot/bilibili/BiliBiliUtils.java | 4 ++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java index 8f8217a..b5c2970 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java +++ b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java @@ -3,6 +3,7 @@ package com.yutou.qqbot.bilibili; import lombok.Data; +import java.util.ArrayList; import java.util.List; @Data @@ -12,7 +13,7 @@ public class AppUserTask { private long progress; private long target; private Wallet wallet; - private List weekTask; + private List weekTask = new ArrayList<>(); private long weekTotal; private long weekGroup; private DayTask dayTask; @@ -35,8 +36,9 @@ public class AppUserTask { public String toMessageFormat() { return switch (getStatus()) { - case 0 -> "不可领取,需要发送弹幕:" + getTarget() + ",进度:" + getProgress(); - case 2 -> "未领取"; + case 0 -> "不可领取,需要发送弹幕数:" + getTarget() + ",进度:" + getProgress(); + case 1 -> "进行中,需要发送弹幕数:" + getTarget() + ",进度:" + getProgress(); + case 2 -> "可领取"; case 3 -> "已领取"; default -> "未知状态:" + this; }; @@ -64,7 +66,7 @@ public class AppUserTask { return switch (getStatus()) { case 0 -> "任务id:" + id + ",不可领取, 进度天数:" + totalNum + ",需要天数:" + minimalDay + ",任务奖励电池:" + rewardNum; - case 2 -> "任务id:" + id + ":未领取" + ",任务奖励电池:" + rewardNum; + case 2 -> "任务id:" + id + ":可领取" + ",任务奖励电池:" + rewardNum; case 3 -> "任务id:" + id + ":已领取" + ",任务奖励电池:" + rewardNum; default -> "未知状态:" + this; }; diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java index 4bbb6b9..eed2770 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java @@ -102,6 +102,7 @@ public class BiliBiliAppUtils { public AppUserTask getTaskProgress() { JSONObject task = biliUtils.http_get("https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/GetUserTaskProgress"); + System.out.println("task = " + task); assert task != null; return task.getObject("data", AppUserTask.class); } diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java index 81b1ccc..5b61484 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java @@ -332,7 +332,7 @@ public class BiliBiliUtils { return jsonObject; } - public static void main(String[] args) { + public static void main(String[] args) { /* String url="https://xy218x85x123x8xy.mcdn.bilivideo.cn:4483/upgcxcode/12/12/17281212/17281212-16-80.flv?e=ig8euxZM2rNcNbNBhbdVhwdlhbUghwdVhoNvNC8BqJIzNbfqXBvEqxTEto8BTrNvN0GvT90W5JZMkX_YN0MvXg8gNEV4NC8xNEV4N03eN0B5tZlqNxTEto8BTrNvNeZVuJ10Kj_g2UB02J0mN0B5tZlqNCNEto8BTrNvNC7MTX502C8f2jmMQJ6mqF2fka1mqx6gqj0eN0B599M=&uipk=5&nbs=1&deadline=1660538573&gen=playurlv2&os=mcdn&oi=2936701972&trid=00006f9623cac1514d8ea18fba3a15a756cau&mid=96300&platform=pc&upsig=25ddd1da610960e8e1d2e80dc97c2361&uparams=e,uipk,nbs,deadline,gen,os,oi,trid,mid,platform&mcdnid=11000101&bvc=vod&nettype=0&orderid=0,2&agrr=1&bw=253116&logo=A0000400&requestFrom=BILIBILI_HELPER_2.5.8"; File file=download(url,"16.mp4",false); System.out.println("file.getAbsolutePath() = " + file.getAbsolutePath());*/ @@ -364,7 +364,7 @@ public class BiliBiliUtils { JSONObject toCoin = http_post("https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin", HttpTools.toUrlParams(body)); JSONObject liveSign = http_get("https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign"); JSONObject vipSign = http_post("https://api.bilibili.com/pgc/activity/score/task/sign", null); - return "银瓜子兑换硬币:"+toCoin.getString("message") + "|" +"直播签到:"+ liveSign.getString("message")+"|大会员中心签到:"+vipSign.getString("message"); + return "银瓜子兑换硬币:" + toCoin.getString("message") + "|" + "直播签到:" + liveSign.getString("message") + "|大会员中心签到:" + vipSign.getString("message"); } public JSONObject getLiveRoom(int roomId) { -- 2.43.0 From 3bc4c164e0ff569ccd9533f20ac6e8aa52bd455b Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 6 Jan 2023 01:31:01 +0800 Subject: [PATCH 36/54] =?UTF-8?q?=E4=BF=AE=E5=A4=8DB=E7=AB=99=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E6=9C=AA=E7=99=BB=E5=BD=95=E6=97=B6=E7=9A=84=E7=8A=B6?= =?UTF-8?q?=E6=80=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/bilibili/BiliLogin.java | 18 +++++++++++++----- .../qqbot/models/BiliBili/BiliBiliLive.java | 12 ++++++------ .../models/WebSign/BiliBiliMangeSign.java | 4 +--- 3 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java index 6005db6..c8dbf72 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java @@ -3,8 +3,10 @@ package com.yutou.qqbot.bilibili; import com.alibaba.fastjson2.JSON; import com.alibaba.fastjson2.JSONArray; import com.alibaba.fastjson2.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.utlis.ConfigTools; import com.yutou.qqbot.utlis.HttpTools; +import com.yutou.qqbot.utlis.QRCodeUtils; import com.yutou.qqbot.utlis.StringUtils; import java.io.File; @@ -21,7 +23,7 @@ public class BiliLogin { public BiliLogin(Long qq) { biliUtils = BiliBiliUtils.getInstance(qq); - this.qq=qq; + this.qq = qq; } public JSONObject login() { @@ -33,6 +35,12 @@ public class BiliLogin { return json; } + public void loginAsQQ() { + String url = login().getString("url"); + File code = QRCodeUtils.createQRCode("bili_login", url); + QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + } + public void waitLogin(String oauthKey) { long time = System.currentTimeMillis(); String bd = "gourl=https%3A%2F%2Fpassport.bilibili.com%2Fajax%2FminiLogin%2Fredirect&oauthKey=" + oauthKey; @@ -88,10 +96,10 @@ public class BiliLogin { } public static String getCookieToken(Long qq) { - if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq+"_bilibili.cookie")))) { + if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq + "_bilibili.cookie")))) { return null; } - JSONObject json = JSON.parseObject(ConfigTools.readFile(new File(qq+"_bilibili.cookie"))); + JSONObject json = JSON.parseObject(ConfigTools.readFile(new File(qq + "_bilibili.cookie"))); return json.getString("bili_jct"); } @@ -100,7 +108,7 @@ public class BiliLogin { BiliLogin login = new BiliLogin(583819556L); boolean testLogin = login.testLogin(); System.out.println("testLogin = " + testLogin); - // JSONObject json = login.login(); - // QRCodeUtils.createQRCode("bili_login", json.getString("url")); + // JSONObject json = login.login(); + // QRCodeUtils.createQRCode("bili_login", json.getString("url")); } } diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 053c18c..2a8c200 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -40,9 +40,7 @@ public class BiliBiliLive extends Model { super.onTime(qq, time); if ("00:01:00".equals(time)) { if(!new BiliLogin(qq).testLogin()){ - String url = new BiliLogin(QQBotManager.defQQ).login().getString("url"); - File code = QRCodeUtils.createQRCode("bili_login", url); - QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + new BiliLogin(QQBotManager.defQQ).loginAsQQ(); return; } signLive(QQBotManager.defQQ, qq); @@ -50,6 +48,10 @@ public class BiliBiliLive extends Model { } private void signLive(long qq, long sendQQ) { + if(!new BiliLogin(qq).testLogin()){ + new BiliLogin(qq).loginAsQQ(); + return; + } BiliBiliUtils biliUtils = BiliBiliUtils.getInstance(qq); QQBotManager.getInstance().sendMessage(sendQQ, biliUtils.liveSignIn()); Set biliLive = RedisTools.list_get("bili_live"); @@ -98,9 +100,7 @@ public class BiliBiliLive extends Model { } Integer roomId = Integer.parseInt(msg); if(!new BiliLogin(qq).testLogin()){ - String url = new BiliLogin(user).login().getString("url"); - File code = QRCodeUtils.createQRCode("bili_login", url); - QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + new BiliLogin(qq).loginAsQQ(); return; } if (biliUtils.checkLiveRoom(roomId) && roomId != 0) { diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java index fb431c8..bfde21e 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java @@ -44,9 +44,7 @@ public class BiliBiliMangeSign extends Model { } QQBotManager.getInstance().sendMessage(qq, msg); } else { - String url = new BiliLogin(user).login().getString("url"); - File code = QRCodeUtils.createQRCode("bili_login", url); - QQBotManager.getInstance().sendMessage(code, qq, "B站未登录,请扫码登陆后再试"); + new BiliLogin(user).loginAsQQ(); } } else if (msg.equals(QQFromCommands.BILI_MANGA_PAY)) { StringBuilder builder = new StringBuilder(); -- 2.43.0 From 943a2c933421703370ed4f93d36e9ad7b51c5521 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 7 Jan 2023 10:22:57 +0800 Subject: [PATCH 37/54] =?UTF-8?q?=E4=BC=98=E5=8C=96B=E7=AB=99=E7=9B=B4?= =?UTF-8?q?=E6=92=AD=E9=97=B4=E6=AF=8F=E6=97=A5=E7=AD=BE=E5=88=B0=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E6=96=87=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/qqbot/bilibili/AppUserTask.java | 11 +++++++++++ .../java/com/yutou/qqbot/bilibili/BiliBiliManga.java | 4 ++-- .../yutou/qqbot/models/BiliBili/BiliBiliLive.java | 12 +++++++----- .../qqbot/models/WebSign/BiliBiliMangeSign.java | 12 +++++++----- 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java index b5c2970..5d4f832 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java +++ b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java @@ -18,6 +18,17 @@ public class AppUserTask { private long weekGroup; private DayTask dayTask; + public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) { + StringBuilder sb = new StringBuilder(); + sb.append("当前电池数量:").append(String.format("%.2f → %.2f", + (double) oldTask.wallet.gold / 100, + (double) newTask.wallet.gold / 100) + ).append("\n"); + sb.append("当前银瓜子数量:").append(newTask.wallet.silver).append("\n"); + sb.append("每日领取电池:").append(newTask.dayTask.toMessageFormat()).append("\n"); + newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n")); + return sb.toString(); + } public String toMessageFormat() { StringBuilder sb = new StringBuilder(); diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java index 95f191c..130116d 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java @@ -13,8 +13,8 @@ import java.util.Timer; import java.util.TimerTask; public class BiliBiliManga { - public BiliBiliManga() { - biliUtils = BiliBiliUtils.getInstance(QQBotManager.defQQ); + public BiliBiliManga(long qq) { + biliUtils = BiliBiliUtils.getInstance(qq); } public static JSONObject sign() { diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 2a8c200..4c18894 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -39,7 +39,7 @@ public class BiliBiliLive extends Model { public synchronized void onTime(Long qq, String time) { super.onTime(qq, time); if ("00:01:00".equals(time)) { - if(!new BiliLogin(qq).testLogin()){ + if (!new BiliLogin(qq).testLogin()) { new BiliLogin(QQBotManager.defQQ).loginAsQQ(); return; } @@ -48,7 +48,7 @@ public class BiliBiliLive extends Model { } private void signLive(long qq, long sendQQ) { - if(!new BiliLogin(qq).testLogin()){ + if (!new BiliLogin(qq).testLogin()) { new BiliLogin(qq).loginAsQQ(); return; } @@ -66,9 +66,11 @@ public class BiliBiliLive extends Model { builder.append("BiliLiveSign").append(id).append(":").append(sign).append("\n"); } QQBotManager.getInstance().sendMessage(sendQQ, builder.toString()); - AppUserTask task = new BiliBiliAppUtils(QQBotManager.defQQ).startAppTask(); + BiliBiliAppUtils appUtils = new BiliBiliAppUtils(QQBotManager.defQQ); + AppUserTask oldTask = appUtils.startAppTask(); + AppUserTask newTask = appUtils.getTaskProgress(); builder = new StringBuilder(); - builder.append("执行APP任务").append("\n").append(task.toMessageFormat()); + builder.append("执行APP任务").append("\n").append(AppUserTask.toMessageFormat(oldTask, newTask)); QQBotManager.getInstance().sendMessage(sendQQ, builder.toString()); } @@ -99,7 +101,7 @@ public class BiliBiliLive extends Model { msg = "0"; } Integer roomId = Integer.parseInt(msg); - if(!new BiliLogin(qq).testLogin()){ + if (!new BiliLogin(qq).testLogin()) { new BiliLogin(qq).loginAsQQ(); return; } diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java index bfde21e..a71b94c 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java @@ -10,6 +10,7 @@ import com.yutou.qqbot.utlis.QRCodeUtils; import net.mamoe.mirai.event.events.MessageEvent; import java.io.File; + @UseModel public class BiliBiliMangeSign extends Model { @Override @@ -34,6 +35,7 @@ public class BiliBiliMangeSign extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); + BiliBiliManga manga = new BiliBiliManga(user); if (msg.equals(QQFromCommands.BILI_MANGA_SIGN)) { String msg; if (new BiliLogin(user).testLogin()) { @@ -70,8 +72,8 @@ public class BiliBiliMangeSign extends Model { } QQBotManager.getInstance().sendMessage(qq, builder.toString()); } else if (msg.equals(QQFromCommands.BILI_MANGA_PAY_STOP)) { - new BiliBiliManga().stopPayMission(); - QQBotManager.getInstance().sendMessage(qq, "当前任务已取消:"+BiliBiliManga.getMission()); + manga.stopPayMission(); + QQBotManager.getInstance().sendMessage(qq, "当前任务已取消:" + BiliBiliManga.getMission()); } else if (msg.startsWith(QQFromCommands.BILI_MANGA_PAY)) { msg = msg.replace(QQFromCommands.BILI_MANGA_PAY, ""); String[] message = msg.split(" "); @@ -97,7 +99,7 @@ public class BiliBiliMangeSign extends Model { QQBotManager.getInstance().sendMessage(qq, "商城id错误"); return; } - BiliBiliManga manga = new BiliBiliManga(); + manga.addInterface(new ObjectInterface() { @Override public void out(String data) { @@ -113,8 +115,8 @@ public class BiliBiliMangeSign 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 ("00:01:00".equals(time)) { if (new BiliLogin(QQBotManager.defQQ).testLogin()) { String msg; -- 2.43.0 From 211773a2304348d624a985f762827c7933203021 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Tue, 14 Feb 2023 16:43:21 +0800 Subject: [PATCH 38/54] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'src/main/java/com/y?= =?UTF-8?q?utou/qqbot/models/setu/GetSeTu.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 优化输出中文冒号. --- src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index a891e00..b712286 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -75,7 +75,7 @@ public class GetSeTu extends Model { builder.append("本群今日共查询:"); builder.append(String.valueOf(array.size())); builder.append("次!\n"); - builder.append("接下来公布大伙的XP系统:"); + builder.append("接下来公布大伙的XP系统:"); builder.append("\n"); Map> map = new HashMap<>(); for (Object o : array) { -- 2.43.0 From eb4264628d36243705bd29485b16133562c4a048 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 23 Feb 2023 17:21:57 +0800 Subject: [PATCH 39/54] update --- pom.xml | 2 +- .../qqbot/models/Commands/PaoPaoSleepWaring.java | 3 +++ .../java/com/yutou/qqbot/models/setu/GetSeTu.java | 13 ++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 7dcee9d..58dab18 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ net.mamoe mirai-core-jvm - 2.12.0 + 2.14.0 org.jetbrains.kotlinx diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index d21288a..9f271c3 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -39,5 +39,8 @@ public class PaoPaoSleepWaring extends Model { QQBotManager.getInstance().sendMessage(qq,builder); RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",1*60*60); } + if(event.getSource().getFromId() == 914520754 && msg.contains("#\u4f53\u529b")){ + QQBotManager.getInstance().sendMessage(qq, "\u60e0\u57ce\uff01"); + } } } diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index b712286..115fb6f 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -157,12 +157,19 @@ public class GetSeTu extends Model { RedisTools.set("Setu_" + qq, array.toString()); } } - - private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event) { + private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event){ + return getSeTu(model, key, r18, fuzzyR18, qq, event,3); + } + private boolean getSeTu(String model,String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event,int reset) { + if(reset<=0){ + QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); + return false; + } String url = "https://api.lolicon.app/setu/v2?r18=0&size=regular"; if (r18) { url = "https://api.lolicon.app/setu/v2?r18=1&size=regular"; } + final String tmpKey=key; if (!StringUtils.isEmpty(key)) { if ("tag".equals(model)) { String[] keys = key.split(" "); @@ -228,7 +235,7 @@ public class GetSeTu extends Model { @Override public void onError(Exception e) { super.onError(e); - QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); + getSeTu(model, tmpKey, r18, fuzzyR18, qq, event, reset-1); e.printStackTrace(); } }); -- 2.43.0 From ff9ae9cc36428eca4b1a6ca21734c20073d8a206 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Thu, 23 Feb 2023 17:23:08 +0800 Subject: [PATCH 40/54] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'src/main/java/com/y?= =?UTF-8?q?utou/qqbot/models/Commands/PaoPaoSleepWaring.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index 9f271c3..db36f1d 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -39,8 +39,8 @@ public class PaoPaoSleepWaring extends Model { QQBotManager.getInstance().sendMessage(qq,builder); RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",1*60*60); } - if(event.getSource().getFromId() == 914520754 && msg.contains("#\u4f53\u529b")){ - QQBotManager.getInstance().sendMessage(qq, "\u60e0\u57ce\uff01"); + if(event.getSource().getFromId() == 914520754 && msg.contains("#体力")){ + QQBotManager.getInstance().sendMessage(qq, "惠城! 体力! "); } } } -- 2.43.0 From 2e4e0722017b91c800fa6706d045ab43d066cc9b Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 23 Feb 2023 17:27:44 +0800 Subject: [PATCH 41/54] update --- .../com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index db36f1d..ecddf1f 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -6,6 +6,7 @@ import com.yutou.qqbot.models.Model; import com.yutou.qqbot.utlis.AppTools; import com.yutou.qqbot.utlis.RedisTools; import net.mamoe.mirai.event.events.MessageEvent; +import net.mamoe.mirai.message.data.At; import net.mamoe.mirai.message.data.MessageChainBuilder; import net.mamoe.mirai.message.data.QuoteReply; @@ -40,7 +41,10 @@ public class PaoPaoSleepWaring extends Model { RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",1*60*60); } if(event.getSource().getFromId() == 914520754 && msg.contains("#体力")){ - QQBotManager.getInstance().sendMessage(qq, "惠城! 体力! "); + MessageChainBuilder builder=new MessageChainBuilder(); + builder.append(new At(369224573L)); + builder.append("惠城! 体力! "); + QQBotManager.getInstance().sendMessage(qq,builder); } } } -- 2.43.0 From 0819bc58aa04f2df9d94d5be9e46724f10a04d5e Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Thu, 23 Feb 2023 22:40:49 +0800 Subject: [PATCH 42/54] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20'src/main/java/com/y?= =?UTF-8?q?utou/qqbot/models/Commands/PaoPaoSleepWaring.java'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java index ecddf1f..690513b 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/PaoPaoSleepWaring.java @@ -40,11 +40,11 @@ public class PaoPaoSleepWaring extends Model { QQBotManager.getInstance().sendMessage(qq,builder); RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",1*60*60); } - if(event.getSource().getFromId() == 914520754 && msg.contains("#体力")){ + /*if(event.getSource().getFromId() == 914520754 && msg.contains("#体力")){ MessageChainBuilder builder=new MessageChainBuilder(); builder.append(new At(369224573L)); builder.append("惠城! 体力! "); QQBotManager.getInstance().sendMessage(qq,builder); - } + }*/ } } -- 2.43.0 From a27d6c5a35a115c3cb7358592c2b74af81592682 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Mon, 27 Feb 2023 20:48:09 +0800 Subject: [PATCH 43/54] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BB=A3=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/models/setu/GetSeTu.java | 27 ++++++++++--------- .../java/com/yutou/qqbot/utlis/HttpTools.java | 15 ++++++++--- 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java index 115fb6f..40e0584 100644 --- a/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java +++ b/src/main/java/com/yutou/qqbot/models/setu/GetSeTu.java @@ -24,6 +24,7 @@ import java.nio.charset.StandardCharsets; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; + @UseModel public class GetSeTu extends Model { @Override @@ -64,7 +65,7 @@ public class GetSeTu extends Model { private void send(Long group) { Jedis redis = RedisTools.getRedis(); redis.select(RedisTools.QQBOT_USER); - String ret = redis.get("Setu_"+group); + String ret = redis.get("Setu_" + group); redis.close(); MessageChainBuilder builder = null; if (!StringUtils.isEmpty(ret)) { @@ -96,8 +97,8 @@ public class GetSeTu extends Model { builder.append(new At(qq)) .append(":\n"); for (String tag : list) { - if(StringUtils.isEmpty(tag)){ - tag="随机"; + if (StringUtils.isEmpty(tag)) { + tag = "随机"; } builder.append(tag).append("\n"); } @@ -157,11 +158,13 @@ public class GetSeTu extends Model { RedisTools.set("Setu_" + qq, array.toString()); } } - private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event){ - return getSeTu(model, key, r18, fuzzyR18, qq, event,3); + + private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event) { + return getSeTu(model, key, r18, fuzzyR18, qq, event, 3); } - private boolean getSeTu(String model,String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event,int reset) { - if(reset<=0){ + + private boolean getSeTu(String model, String key, boolean r18, boolean fuzzyR18, Long qq, MessageEvent event, int reset) { + if (reset <= 0) { QQBotManager.getInstance().sendMessage(qq, "获取失败喵~"); return false; } @@ -169,7 +172,7 @@ public class GetSeTu extends Model { if (r18) { url = "https://api.lolicon.app/setu/v2?r18=1&size=regular"; } - final String tmpKey=key; + final String tmpKey = key; if (!StringUtils.isEmpty(key)) { if ("tag".equals(model)) { String[] keys = key.split(" "); @@ -192,7 +195,7 @@ public class GetSeTu extends Model { url = url.replace("&r18=0", "&r18=2").replace("&r18=1", "&r18=2"); } System.out.println("url = " + url); - String ret = HttpTools.get(url); + String ret = HttpTools.http_get(url, null, true); JSONObject json = JSON.parseObject(ret); if (json.getJSONArray("data").size() == 0) { return false; @@ -227,15 +230,15 @@ public class GetSeTu extends Model { MessageChainBuilder chain = new MessageChainBuilder(); chain.append(new QuoteReply(event.getMessage())); chain.append(builder.toString()); - MessageReceipt message=QQBotManager.getInstance().sendMessage(qq,chain); - Log.i(getModelName(),message); + MessageReceipt message = QQBotManager.getInstance().sendMessage(qq, chain); + Log.i(getModelName(), message); } @Override public void onError(Exception e) { super.onError(e); - getSeTu(model, tmpKey, r18, fuzzyR18, qq, event, reset-1); + getSeTu(model, tmpKey, r18, fuzzyR18, qq, event, reset - 1); e.printStackTrace(); } }); diff --git a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java index 5aca45c..2f1e67b 100644 --- a/src/main/java/com/yutou/qqbot/utlis/HttpTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/HttpTools.java @@ -17,7 +17,7 @@ public class HttpTools { private static final int HttpRequestIndex = 3; public static String get(String url) { - return http_get(url, null); + return http_get(url, null,false); } public static String post(final String url, final byte[] body) { @@ -40,10 +40,19 @@ public class HttpTools { return null; } - public static String http_get(String url, Map header) { + public static String http_get(String url, Map header,boolean isProxy) { try { HttpURLConnection connection; - connection = (HttpURLConnection) new URL(url).openConnection(); + Proxy proxy = null; + if (isProxy) { + proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890)); + } + + if(proxy==null) { + connection = (HttpURLConnection) new URL(url).openConnection(); + }else{ + connection = (HttpURLConnection) new URL(url).openConnection(proxy); + } return urlConnection(header, connection); } catch (Exception e) { System.err.println("error url = " + url); -- 2.43.0 From 48501b09ff0bc8a921fde9bd265c39affd63f5ac Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Thu, 2 Mar 2023 09:57:16 +0800 Subject: [PATCH 44/54] =?UTF-8?q?=E4=BF=AE=E5=A4=8DB=E7=AB=99=E6=AF=8F?= =?UTF-8?q?=E6=97=A5=E7=AD=BE=E5=88=B0=E6=B2=A1=E6=9C=89=E5=91=A8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E6=97=B6=E7=9A=84=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java index 5d4f832..c5d43de 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java +++ b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java @@ -18,6 +18,13 @@ public class AppUserTask { private long weekGroup; private DayTask dayTask; + public List getWeekTask() { + if(weekTask == null){ + weekTask=new ArrayList<>(); + } + return weekTask; + } + public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) { StringBuilder sb = new StringBuilder(); sb.append("当前电池数量:").append(String.format("%.2f → %.2f", -- 2.43.0 From b14601ef2c4e3ce4de35a43436b1b13585ea3684 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 17 Mar 2023 17:39:14 +0800 Subject: [PATCH 45/54] add:FixQQVersion --- mvnw | 0 .../java/com/yutou/qqbot/QQBotManager.java | 2 +- .../qqbot/models/BiliBili/BiliBiliLive.java | 4 ++ .../yutou/qqbot/utlis/FixProtocolVersion.java | 68 +++++++++++++++++++ 4 files changed, 73 insertions(+), 1 deletion(-) mode change 100644 => 100755 mvnw create mode 100644 src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java diff --git a/mvnw b/mvnw old mode 100644 new mode 100755 diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index b70931b..11e7bbb 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -6,7 +6,6 @@ import com.yutou.qqbot.Listeners.QQMessageListener; import com.yutou.qqbot.utlis.*; import net.mamoe.mirai.Bot; import net.mamoe.mirai.BotFactory; -import net.mamoe.mirai.contact.Group; import net.mamoe.mirai.event.GlobalEventChannel; import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.*; @@ -47,6 +46,7 @@ public class QQBotManager { String password = ConfigTools.load(ConfigTools.CONFIG, "qq_password", String.class); System.out.println("qq = " + qq); System.out.println("password = " + password); + FixProtocolVersion.fix(); bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() { { setProtocol(MiraiProtocol.ANDROID_PAD); diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 4c18894..870db6d 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -135,4 +135,8 @@ public class BiliBiliLive extends Model { QQBotManager.getInstance().sendMessage(qq, message.toString()); } + + public static void main(String[] args) { + new BiliBiliLive().signLive(QQBotManager.defQQ, 0); + } } diff --git a/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java b/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java new file mode 100644 index 0000000..d32b853 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java @@ -0,0 +1,68 @@ +package com.yutou.qqbot.utlis; + +import net.mamoe.mirai.utils.BotConfiguration; + +import java.lang.reflect.Field; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.Map; + +public class FixProtocolVersion { + public static void fix(){ + try { + + Class MiraiProtocolInternal = Class.forName("net.mamoe.mirai.internal.utils.MiraiProtocolInternal"); + Field field = MiraiProtocolInternal.getFields()[0]; + Object companion = field.get(Object.class); + + EnumMap protocols = (EnumMap)companion.getClass().getMethod("getProtocols$mirai_core").invoke(companion); + Object pad = protocols.get(BotConfiguration.MiraiProtocol.ANDROID_PAD); + /* + * apkId: String, + id: Long, + ver: String, + sdkVer: String, + miscBitMap: Int, + subSigMap: Int, + mainSigMap: Int, + sign: String, + buildTime: Long, + ssoVersion: Int, + canDoQRCodeLogin: Boolean = false, + * */ + Class padClass = pad.getClass(); + Map padData = new HashMap(){{ + put("id", 537151218); + put("ver", "8.9.33.10335"); + put("sdkVer", "6.0.0.2534"); + put("buildTime", 1673599898L); + }}; + for (Field f : padClass.getFields()) { + f.setAccessible(true); + if(padData.containsKey(f.getName())){ + f.set(pad, padData.get(f.getName())); + } + f.setAccessible(false); + } + + Object phone = protocols.get(BotConfiguration.MiraiProtocol.ANDROID_PHONE); + Map phoneData = new HashMap(){{ + put("id", 537151682); + put("ver", "8.9.33.10335"); + put("sdkVer", "6.0.0.2534"); + put("buildTime", 1673599898L); + }}; + for (Field f : padClass.getFields()) { + f.setAccessible(true); + if(padData.containsKey(f.getName())){ + f.set(phone, phoneData.get(f.getName())); + } + f.setAccessible(false); + } + + } catch (Exception e) { + e.printStackTrace(); + } + } +} + -- 2.43.0 From 83e3b5adaefd2503b946db739cd5b6087b3e2775 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Fri, 17 Mar 2023 17:43:12 +0800 Subject: [PATCH 46/54] remove:MiRouter --- src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java b/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java index afa849c..47e8ff8 100644 --- a/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java +++ b/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java @@ -47,7 +47,7 @@ public class MiRouter extends Model { } } - private static boolean isRunTime = false; + private static boolean isRunTime = true; @Override public void onTime(Long qq,String time) { -- 2.43.0 From 9fc377f070c1c7478ded711331ad0d60bbb95c58 Mon Sep 17 00:00:00 2001 From: Yutousama <583819556@qq.com> Date: Sat, 18 Mar 2023 13:41:47 +0800 Subject: [PATCH 47/54] =?UTF-8?q?update=20=E6=9B=B4=E6=96=B0selenium?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++++++- src/main/java/com/yutou/qqbot/utlis/WebClient.java | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 58dab18..aecc6ec 100644 --- a/pom.xml +++ b/pom.xml @@ -98,7 +98,12 @@ org.seleniumhq.selenium selenium-remote-driver - 4.7.1 + 4.8.1 + + + org.seleniumhq.selenium + selenium-http-jdk-client + 4.8.1 diff --git a/src/main/java/com/yutou/qqbot/utlis/WebClient.java b/src/main/java/com/yutou/qqbot/utlis/WebClient.java index efb68fc..9fa27ff 100644 --- a/src/main/java/com/yutou/qqbot/utlis/WebClient.java +++ b/src/main/java/com/yutou/qqbot/utlis/WebClient.java @@ -37,6 +37,7 @@ public class WebClient { } private WebClient() { + //System.setProperty("webdriver.http.factory", "jdk-http-client"); System.setProperty("webdriver.chrome.driver", ConfigTools.load(ConfigTools.CONFIG, "chrome", String.class)); // System.setProperty("webdriver.chrome.whitelistedIps", ""); @@ -84,6 +85,7 @@ public class WebClient { public ChromeOptions getOptions() { ChromeOptions options = new ChromeOptions(); + options.addArguments("--remote-allow-origins=*"); // options.addArguments("--disable-gpu"); // options.addArguments("blink-settings=imagesEnabled=false"); String headless = RedisTools.get("chromedrive_headless"); -- 2.43.0 From 43a816066d7c6009c2602a61be09d1d4d190021e Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Tue, 18 Apr 2023 07:48:19 +0800 Subject: [PATCH 48/54] fix version --- .../yutou/qqbot/utlis/FixProtocolVersion.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java b/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java index d32b853..c5cd31b 100644 --- a/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java +++ b/src/main/java/com/yutou/qqbot/utlis/FixProtocolVersion.java @@ -32,10 +32,10 @@ public class FixProtocolVersion { * */ Class padClass = pad.getClass(); Map padData = new HashMap(){{ - put("id", 537151218); - put("ver", "8.9.33.10335"); - put("sdkVer", "6.0.0.2534"); - put("buildTime", 1673599898L); + put("id", 537152242); + put("ver", "8.9.35.10440"); + put("sdkVer", "6.0.0.2535"); + put("buildTime", 1676531414L); }}; for (Field f : padClass.getFields()) { f.setAccessible(true); @@ -47,10 +47,10 @@ public class FixProtocolVersion { Object phone = protocols.get(BotConfiguration.MiraiProtocol.ANDROID_PHONE); Map phoneData = new HashMap(){{ - put("id", 537151682); - put("ver", "8.9.33.10335"); - put("sdkVer", "6.0.0.2534"); - put("buildTime", 1673599898L); + put("id", 537153294); + put("ver", "8.9.35.10440"); + put("sdkVer", "6.0.0.2535"); + put("buildTime", 1676531414L); }}; for (Field f : padClass.getFields()) { f.setAccessible(true); -- 2.43.0 From 4f5bcc9df3015a55251e9e97d6bbd11a746c0506 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Tue, 20 Jun 2023 09:40:27 +0800 Subject: [PATCH 49/54] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=B8=8B=E8=BD=BD?= =?UTF-8?q?=E6=91=B8=E9=B1=BC=E5=9B=BE=E7=89=87=E4=BC=9A=E6=AD=BB=E5=BE=AA?= =?UTF-8?q?=E7=8E=AF=E9=97=AE=E9=A2=98=20=E4=BF=AE=E5=A4=8D=E7=94=B5?= =?UTF-8?q?=E6=B1=A0=E7=AD=BE=E5=88=B0=E4=BB=BB=E5=8A=A1=E5=91=A8=E4=BB=BB?= =?UTF-8?q?=E5=8A=A1=E4=B8=BA=E7=A9=BA=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/yutou/qqbot/bilibili/AppUserTask.java | 14 ++++++----- .../yutou/qqbot/bilibili/BiliBiliManga.java | 1 + .../com/yutou/qqbot/models/Commands/Moyu.java | 25 ++++++++++++------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java index c5d43de..77efaed 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java +++ b/src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java @@ -19,8 +19,8 @@ public class AppUserTask { private DayTask dayTask; public List getWeekTask() { - if(weekTask == null){ - weekTask=new ArrayList<>(); + if (weekTask == null) { + weekTask = new ArrayList<>(); } return weekTask; } @@ -28,12 +28,14 @@ public class AppUserTask { public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) { StringBuilder sb = new StringBuilder(); sb.append("当前电池数量:").append(String.format("%.2f → %.2f", - (double) oldTask.wallet.gold / 100, - (double) newTask.wallet.gold / 100) - ).append("\n"); + (double) oldTask.wallet.gold / 100, + (double) newTask.wallet.gold / 100) + ).append("\n"); sb.append("当前银瓜子数量:").append(newTask.wallet.silver).append("\n"); sb.append("每日领取电池:").append(newTask.dayTask.toMessageFormat()).append("\n"); - newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n")); + if (newTask.weekTask != null && !newTask.getWeekTask().isEmpty()) { + newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n")); + } return sb.toString(); } diff --git a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java index 130116d..0ed25cb 100644 --- a/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java +++ b/src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java @@ -160,6 +160,7 @@ public class BiliBiliManga { } public static void main(String[] args) { + System.out.println(BiliBiliManga.sign()); } @Data diff --git a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java index 0ae1468..e936f1c 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java @@ -12,6 +12,7 @@ import com.yutou.qqbot.utlis.Log; import net.mamoe.mirai.event.events.MessageEvent; import java.io.File; + @UseModel public class Moyu extends Model { @Override @@ -38,25 +39,27 @@ public class Moyu extends Model { } @Override - public synchronized void onTime(Long qq, String time) { + public synchronized void onTime(Long qq, String time) { super.onTime(qq, time); if ("07:00:00".equals(time)) { - downloadImage(false,qq); + downloadImage(false, qq); } if ("10:00:00".equals(time)) { send(qq); } } - private void downloadImage(boolean isSend,Long qq) { - Log.i(this,"下载图片"); + private void downloadImage(boolean isSend, Long qq) { + Log.i(this, "下载图片"); String ret = HttpTools.get("https://api.j4u.ink/v1/store/other/proxy/remote/moyu.json"); JSONObject json = JSON.parseObject(ret); HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() { + int count = 3; + @Override public void onDownload(File file) { super.onDownload(file); - if(isSend){ + if (isSend) { send(qq); } } @@ -65,18 +68,22 @@ public class Moyu extends Model { public void onError(Exception e) { super.onError(e); e.printStackTrace(); - downloadImage(isSend,qq); + if (count == 0) { + return; + } + downloadImage(isSend, qq); + count--; } }); } private void send(Long qq) { File file = new File(HttpTools.downloadPath + AppTools.getToDayTime() + "_moyu.jpg"); - Log.i(this,"发送图片 : file.exists = "+file.exists()+" qq = "+qq); + Log.i(this, "发送图片 : file.exists = " + file.exists() + " qq = " + qq); if (file.exists()) { QQBotManager.getInstance().sendMessage(file, qq, ""); - }else{ - downloadImage(true,qq); + } else { + downloadImage(true, qq); } } } -- 2.43.0 From 808798028f58565937f696764860fe9e22d135cc Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Tue, 20 Jun 2023 17:48:04 +0800 Subject: [PATCH 50/54] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=91=B8=E9=B1=BC?= =?UTF-8?q?=E6=97=A5=E5=8E=86API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/models/Commands/Moyu.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java index e936f1c..ca65cb1 100644 --- a/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java +++ b/src/main/java/com/yutou/qqbot/models/Commands/Moyu.java @@ -51,9 +51,9 @@ public class Moyu extends Model { private void downloadImage(boolean isSend, Long qq) { Log.i(this, "下载图片"); - String ret = HttpTools.get("https://api.j4u.ink/v1/store/other/proxy/remote/moyu.json"); + String ret = HttpTools.get("https://api.vvhan.com/api/moyu?type=json"); JSONObject json = JSON.parseObject(ret); - HttpTools.download(json.getJSONObject("data").getString("moyu_url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() { + HttpTools.download(json.getString("url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() { int count = 3; @Override @@ -86,4 +86,8 @@ public class Moyu extends Model { downloadImage(true, qq); } } + + public static void main(String[] args) { + + } } -- 2.43.0 From 8df36edd2d8fc329885067ae1ead7781575f9985 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Tue, 20 Jun 2023 17:48:22 +0800 Subject: [PATCH 51/54] =?UTF-8?q?=E8=B0=83=E6=95=B4=E6=91=B8=E9=B1=BC?= =?UTF-8?q?=E6=97=A5=E5=8E=86API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/QQBotApplication.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index f27ab4a..e396ebd 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.4b.1"; + public static final String version="QQBot v.1.4b.2"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); -- 2.43.0 From 3d3046f1d70cbdfd614f3c9df03a9ec3fadec8d6 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Sun, 25 Jun 2023 08:40:24 +0800 Subject: [PATCH 52/54] =?UTF-8?q?=E4=BF=AE=E5=A4=8DB=E7=AB=99=E6=BC=AB?= =?UTF-8?q?=E7=94=BB=E7=AD=BE=E5=88=B0=E7=9A=84=E7=A9=BA=E6=8C=87=E9=92=88?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yutou/qqbot/models/WebSign/BiliBiliMangeSign.java | 3 +++ src/main/java/com/yutou/qqbot/utlis/BangumiTools.java | 9 ++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java index a71b94c..564e563 100644 --- a/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java +++ b/src/main/java/com/yutou/qqbot/models/WebSign/BiliBiliMangeSign.java @@ -35,6 +35,9 @@ public class BiliBiliMangeSign extends Model { @Override public void onMessage(Long qq, MessageEvent event, boolean isGroup) { super.onMessage(qq, event, isGroup); + if(user==null){ + return; + } BiliBiliManga manga = new BiliBiliManga(user); if (msg.equals(QQFromCommands.BILI_MANGA_SIGN)) { String msg; diff --git a/src/main/java/com/yutou/qqbot/utlis/BangumiTools.java b/src/main/java/com/yutou/qqbot/utlis/BangumiTools.java index 2d99961..02e2b74 100644 --- a/src/main/java/com/yutou/qqbot/utlis/BangumiTools.java +++ b/src/main/java/com/yutou/qqbot/utlis/BangumiTools.java @@ -345,12 +345,7 @@ public class BangumiTools { } public static void main(String[] args) { - List list = BangumiTools.reportSearchBangumi("处刑少女的生存之道"); - /*for (String s : list) { - System.out.println(s); - }*/ - JSONObject test=new JSONObject(); - test.put("data",JSON.toJSON(list)); - System.out.println(test); + + System.out.println(BangumiTools.reportToDayBangumi()); } } -- 2.43.0 From 4aa0a53cc5e074a52931ac03dbfd7a4f8e3160a4 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Sun, 25 Jun 2023 10:26:13 +0800 Subject: [PATCH 53/54] =?UTF-8?q?=E6=9B=B4=E6=96=B0QQ=E6=9C=BA=E5=99=A8?= =?UTF-8?q?=E4=BA=BA=E7=89=88=E6=9C=AC=20=E6=96=B0=E5=A2=9E=E6=89=AB?= =?UTF-8?q?=E7=A0=81=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- src/main/java/com/yutou/qqbot/QQBotManager.java | 9 +++++++-- .../com/yutou/qqbot/models/Animal/TurnipProphet.java | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index aecc6ec..f4c8522 100644 --- a/pom.xml +++ b/pom.xml @@ -35,7 +35,7 @@ net.mamoe mirai-core-jvm - 2.14.0 + 2.15.0-RC org.jetbrains.kotlinx diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 11e7bbb..0de12d0 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -6,6 +6,7 @@ import com.yutou.qqbot.Listeners.QQMessageListener; import com.yutou.qqbot.utlis.*; import net.mamoe.mirai.Bot; import net.mamoe.mirai.BotFactory; +import net.mamoe.mirai.auth.BotAuthorization; import net.mamoe.mirai.event.GlobalEventChannel; import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.*; @@ -47,9 +48,11 @@ public class QQBotManager { System.out.println("qq = " + qq); System.out.println("password = " + password); FixProtocolVersion.fix(); - bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() { + + bot = BotFactory.INSTANCE.newBot(qq, BotAuthorization.byQRCode(),new BotConfiguration() { { - setProtocol(MiraiProtocol.ANDROID_PAD); + + setProtocol(MiraiProtocol.ANDROID_WATCH); fileBasedDeviceInfo("qq_bot_devices_info.json"); if ("nas".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) { noBotLog(); @@ -148,8 +151,10 @@ public class QQBotManager { public MessageReceipt sendMessage(Long group, MessageChainBuilder builder) { if (bot != null) { if (QQNumberManager.getManager().isGroup(group)) { + System.out.println("发群"); return Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain()); } else { + System.out.println("发个人"); return Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain()); } } 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 2ca1368..35961fc 100644 --- a/src/main/java/com/yutou/qqbot/models/Animal/TurnipProphet.java +++ b/src/main/java/com/yutou/qqbot/models/Animal/TurnipProphet.java @@ -271,7 +271,7 @@ public class TurnipProphet extends Model { out.append("网页版:").append("\n").append(url).append("\n"); out.append("祝好运 :)"); - Log.i("TurnipProphet", out.toString()); + Log.i("TurnipProphet", out.toString()+"\n 发送QQ:"+sendQQ); QQBotManager.getInstance().sendMessage(sendQQ, getMessage(out.toString())); return prArray.getJSONObject(0).getString(TurnipData.MODEL); } -- 2.43.0 From 2c456702d822a1033b4877d7fc1ba62a2aca3281 Mon Sep 17 00:00:00 2001 From: yutou <583819556@qq.com> Date: Thu, 20 Jul 2023 13:32:30 +0800 Subject: [PATCH 54/54] =?UTF-8?q?=E8=B0=83=E6=95=B4B=E7=AB=99=E7=AD=BE?= =?UTF-8?q?=E5=88=B0=E5=87=BA=E9=94=99=E6=97=B6=E8=BE=93=E5=87=BA=E6=97=A5?= =?UTF-8?q?=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/yutou/qqbot/QQBotApplication.java | 2 +- src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index e396ebd..0fe4efa 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.4b.2"; + public static final String version="QQBot v.1.4b.3"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java index 870db6d..4b2e47d 100644 --- a/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java +++ b/src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java @@ -41,6 +41,7 @@ public class BiliBiliLive extends Model { if ("00:01:00".equals(time)) { if (!new BiliLogin(qq).testLogin()) { new BiliLogin(QQBotManager.defQQ).loginAsQQ(); + System.out.println(BiliBiliUtils.getInstance(QQBotManager.defQQ).getLoginInfo()); return; } signLive(QQBotManager.defQQ, qq); -- 2.43.0