Compare commits
275 Commits
d35431a35d
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 237c9273ca | |||
| 607c05e028 | |||
| df0337b006 | |||
| ebe96127e5 | |||
| 120392be17 | |||
| 6ed42d3e80 | |||
| 9903056551 | |||
| 10c4459936 | |||
| 632b11d242 | |||
| b4230a4809 | |||
| 604d186cc2 | |||
| 2c37c19cc9 | |||
| 808ec3bd0a | |||
| 400f2df6ab | |||
| 7e9fa60f6a | |||
| d4b0a78fa9 | |||
| 4ccaa4b78e | |||
| c74033fed7 | |||
| 5a7382d02c | |||
| 3b52742ac1 | |||
| e40c19016a | |||
| 4dce74eaf8 | |||
| 68fd6efdf4 | |||
| 2000efdd55 | |||
| 9ea1450066 | |||
| 3437a5386f | |||
| 177c91c370 | |||
| 5af58336ec | |||
| b177561df4 | |||
| 126f25af81 | |||
| c48db62d00 | |||
| e595cff31d | |||
| 9b70685949 | |||
| a317767ae7 | |||
| 5846ef5016 | |||
| 91a18835c3 | |||
| 694239eac9 | |||
| af3f85618d | |||
| 6eedb9786e | |||
| d56d6edf19 | |||
| 084d8901e9 | |||
| 00816083b9 | |||
| 8da7c2f572 | |||
| e65eb62417 | |||
| 883f5bb820 | |||
| a34fafc39c | |||
| 9fdf670c26 | |||
| 00cdf7b96e | |||
| 2c456702d8 | |||
| 4aa0a53cc5 | |||
| 3d3046f1d7 | |||
| 8df36edd2d | |||
| 808798028f | |||
| 4f5bcc9df3 | |||
| 43a816066d | |||
| 9fc377f070 | |||
| 83e3b5adae | |||
| b14601ef2c | |||
| 48501b09ff | |||
| a27d6c5a35 | |||
| 0819bc58aa | |||
| 2e4e072201 | |||
| ff9ae9cc36 | |||
| eb4264628d | |||
| 211773a230 | |||
| ab941e97e3 | |||
| 943a2c9334 | |||
| 3bc4c164e0 | |||
| 938d3d532a | |||
| 5d15f24847 | |||
| fec901970a | |||
| 083218b1cb | |||
| ae72956f68 | |||
| 1456675446 | |||
| c2fc5c965a | |||
| cf098877c3 | |||
| c9eceaccf3 | |||
| ab1facc747 | |||
| 5ac0b45540 | |||
| c146eac9c5 | |||
| 85fbce9f4f | |||
| 0de499fb57 | |||
| 7623858866 | |||
| 6d9277ced5 | |||
| bcafd751e6 | |||
| 5d2d41f176 | |||
| 6de3f5d738 | |||
| 28167c7f49 | |||
| 22add886d5 | |||
| 47e4039127 | |||
| 3d730206b9 | |||
| 07361fb616 | |||
| 00985e7fb8 | |||
| 960c3e9c56 | |||
| 8207498f2c | |||
| fe48b030d9 | |||
| de1fe79b09 | |||
| 1908c905ac | |||
| f0d61ffbb6 | |||
| f46c09c6ed | |||
| 7885f2bbfb | |||
| f296d4c819 | |||
| 283deb3e4a | |||
| 0ffc076a71 | |||
| 6d2b1e9264 | |||
| 0ee1be5f04 | |||
| 204da16848 | |||
| 6857a1d5ea | |||
| e19d1cdeda | |||
| 39588831d4 | |||
| 8160d64867 | |||
| 4fabd514a7 | |||
| 03f8bc07ba | |||
| 61c9fc60a0 | |||
| 8f8fa41acf | |||
| d737730768 | |||
| 5209843e86 | |||
| 21dd8033d1 | |||
| af54377bb2 | |||
| 788bd24d92 | |||
| 08bbd247a4 | |||
| 75b43e40e5 | |||
| ef8d46aa64 | |||
| 886e3eae6f | |||
| 30fda14264 | |||
| c36044e6e4 | |||
| 8661d8f3e7 | |||
| c10abbe82e | |||
| 10675c373a | |||
| 67587d208b | |||
| e085690446 | |||
| b475e008a2 | |||
| b2610a02b2 | |||
| 05e8814b91 | |||
| d76090af75 | |||
| 299bc17758 | |||
| 8ddfc339dd | |||
| 7319944441 | |||
| c1fd29232e | |||
| a7baf2a236 | |||
| af9be86762 | |||
| 84c583ad38 | |||
| edfd663743 | |||
| 575df40591 | |||
| 50823587dd | |||
| 81929daebd | |||
| bfe7ec77ab | |||
| accead7817 | |||
| e0f81620a3 | |||
| 4031b07b0b | |||
| 7943606dc0 | |||
| f1ed4be143 | |||
| f116568261 | |||
| 694b5fb2ae | |||
| ec6fce9a8d | |||
| 7ac9d1b188 | |||
| 2db6d1fd39 | |||
| a90d493975 | |||
| e96bdefb67 | |||
| 61feb23f16 | |||
| 3dac0288f3 | |||
| fd5e32508f | |||
| 7e1a0d6b92 | |||
| 05a892a135 | |||
| 46322572c7 | |||
| 938591531d | |||
| 4d156ad861 | |||
| 7776fb3d01 | |||
| 4f3fea8615 | |||
| 15b0e14edd | |||
| dfd60919ad | |||
| 5d4717d7a3 | |||
| 149e64d85f | |||
| 731d7734d5 | |||
| b25a146e9a | |||
| 1f7376c020 | |||
| 19a9fb0d1b | |||
| 086d773ac0 | |||
| f908066602 | |||
| d5da784033 | |||
| 5d05f279e8 | |||
| 6c9bd5dc81 | |||
| c0b394c613 | |||
| fdc1d7c880 | |||
| 1b593106ab | |||
| ccdca908cf | |||
| 9d88fef157 | |||
| a1831163cc | |||
| 4dfbee6d08 | |||
| 10fd1d6863 | |||
| 4e56d31e43 | |||
| 973a51428b | |||
| 490ae1b9dc | |||
| e0e7195c57 | |||
| 479ae1dfba | |||
| 2558545ffe | |||
| f6c9748f48 | |||
| 2da36d7918 | |||
| a83e92b947 | |||
| f2acbd9dfb | |||
| 7405c2a288 | |||
| 62ad0a65fd | |||
| 409c12b76e | |||
| ac4466c374 | |||
| c9a5732721 | |||
| 00ebecb998 | |||
| 6bc4ff40d5 | |||
| 6b19fa8f2f | |||
| 3e709799d2 | |||
| 7fa6c22ef8 | |||
| bcba637ad5 | |||
| d56e237b62 | |||
| 606e2e1ef1 | |||
| b695e0ff08 | |||
| 4cbcba6b6e | |||
| d35b1bdc42 | |||
| 5adb68b2ad | |||
| 0ad33b328d | |||
| 82c130a506 | |||
| fe16be6693 | |||
| fab0cdf497 | |||
| 3fdd2cf5ec | |||
| d9b3e7f558 | |||
| 9ddd8059dd | |||
| fa2761dbe2 | |||
| d4b924f677 | |||
| 68cecf1e47 | |||
| 769f106fa3 | |||
| 2add54f3ad | |||
| 159426ed09 | |||
| 4cc5567568 | |||
| c04ada610f | |||
| 8145a1c313 | |||
| 61e35fb3c5 | |||
| abfe65a534 | |||
| d31534311f | |||
| 8e13a246ac | |||
| a8b6b34406 | |||
| bdb7d08622 | |||
| f825302b5f | |||
| 28d98e573d | |||
| e4ecde0db3 | |||
| 4503f2207f | |||
| b4484f1424 | |||
| 7cb003544b | |||
| 8d6fe31430 | |||
| e2083b1c47 | |||
| 48651c384f | |||
| bcae613e74 | |||
| 5fa740c58f | |||
| b5076323d7 | |||
| 8e98929622 | |||
| aa935e8662 | |||
| 7d1128cc1d | |||
| ba7b933bdb | |||
| 8f19448239 | |||
| 6e4fc0c3d3 | |||
| 6a68e95f45 | |||
| 75f3a68faf | |||
| 1bf0336b72 | |||
| 5b928afa82 | |||
| eedd304c43 | |||
| fb75b5206c | |||
| 55da787d66 | |||
| 33c7f0df56 | |||
| 66ae1c4e8b | |||
| e0751972a3 | |||
| 59477d518a | |||
| e7719b6cfe | |||
| b430143037 | |||
| edfddd7e17 | |||
| a73a5b34e2 | |||
| 618f91457f | |||
| e2432b5942 | |||
| 7b1050b4e3 |
17
KFCFactory.json
Normal file
17
KFCFactory.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"8.9.63": {
|
||||
"base_url": "http://192.168.31.88:7400",
|
||||
"type": "fuqiuluo/unidbg-fetch-qsign",
|
||||
"key": "114514"
|
||||
},
|
||||
"0.1.0": {
|
||||
"base_url": "http://127.0.0.1:8888",
|
||||
"type": "kiliokuara/magic-signer-guide",
|
||||
"server_identity_key": "vivo50",
|
||||
"authorization_key": "kfc"
|
||||
},
|
||||
"8.8.88": {
|
||||
"base_url": "http://127.0.0.1:80",
|
||||
"type": "TLV544Provider"
|
||||
}
|
||||
}
|
||||
BIN
libs/fix-protocol-version-1.9.9.mirai2.jar
Normal file
BIN
libs/fix-protocol-version-1.9.9.mirai2.jar
Normal file
Binary file not shown.
117
pom.xml
117
pom.xml
@@ -32,42 +32,30 @@
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.mamoe</groupId>
|
||||
<artifactId>mirai-core-jvm</artifactId>
|
||||
<version>2.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-jdk8</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlinx</groupId>
|
||||
<artifactId>kotlinx-coroutines-core-jvm</artifactId>
|
||||
<version>1.5.2</version>
|
||||
<version>1.6.4</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/redis.clients/jedis -->
|
||||
<dependency>
|
||||
<groupId>redis.clients</groupId>
|
||||
<artifactId>jedis</artifactId>
|
||||
<version>3.6.0-RC1</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.springframework.data/spring-data-redis -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.data</groupId>
|
||||
<artifactId>spring-data-redis</artifactId>
|
||||
<version>2.4.7</version>
|
||||
<version>4.3.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.alibaba/fastjson -->
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
<version>1.2.78</version>
|
||||
<groupId>com.alibaba.fastjson2</groupId>
|
||||
<artifactId>fastjson2</artifactId>
|
||||
<version>2.0.22</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -88,14 +76,94 @@
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-java</artifactId>
|
||||
<version>3.141.59</version>
|
||||
<version>4.7.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-chrome-driver</artifactId>
|
||||
<version>4.7.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-api -->
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-api</artifactId>
|
||||
<version>4.7.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-remote-driver -->
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-remote-driver</artifactId>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.seleniumhq.selenium</groupId>
|
||||
<artifactId>selenium-http-jdk-client</artifactId>
|
||||
<version>4.8.1</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
|
||||
<dependency>
|
||||
<groupId>commons-codec</groupId>
|
||||
<artifactId>commons-codec</artifactId>
|
||||
<version>1.15</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.zxing</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>3.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java</artifactId>
|
||||
<version>3.21.12</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.google.protobuf</groupId>
|
||||
<artifactId>protobuf-java-util</artifactId>
|
||||
<version>3.21.1</version>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.reflections/reflections
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>org.reflections</groupId>
|
||||
<artifactId>reflections</artifactId>
|
||||
<version>0.10.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/org.brotli/dec -->
|
||||
<dependency>
|
||||
<groupId>org.brotli</groupId>
|
||||
<artifactId>dec</artifactId>
|
||||
<version>0.1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.okhttp3</groupId>
|
||||
<artifactId>okhttp</artifactId>
|
||||
<version>4.12.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- https://mvnrepository.com/artifact/com.squareup.retrofit2/retrofit -->
|
||||
<dependency>
|
||||
<groupId>com.squareup.retrofit2</groupId>
|
||||
<artifactId>retrofit</artifactId>
|
||||
<version>2.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
|
||||
<groupId>org.jsoup</groupId>
|
||||
<artifactId>jsoup</artifactId>
|
||||
<version>1.17.2</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -114,7 +182,9 @@
|
||||
<configuration>
|
||||
<tasks>
|
||||
<echo>复制正式文件</echo>
|
||||
<copy file="src/main/resources/application.properties.release" tofile="${project.build.outputDirectory}/application.properties" overwrite="true"/>
|
||||
<copy file="src/main/resources/application.properties.release"
|
||||
tofile="${project.build.outputDirectory}/application.properties"
|
||||
overwrite="true"/>
|
||||
</tasks>
|
||||
</configuration>
|
||||
</execution>
|
||||
@@ -149,6 +219,7 @@
|
||||
<!--使用-Dloader.path需要在打包的时候增加<layout>ZIP</layou
|
||||
t>,不指定的话-Dloader.path不生效-->
|
||||
<layout>ZIP</layout>
|
||||
<includeSystemScope>true</includeSystemScope>
|
||||
<!-- 指定该jar包启动时的主类[建议] -->
|
||||
<mainClass>com.yutou.qqbot.QQBotApplication</mainClass>
|
||||
</configuration>
|
||||
@@ -159,12 +230,6 @@
|
||||
<goal>repackage</goal>
|
||||
</goals>
|
||||
|
||||
<configuration>
|
||||
<outputDirectory>
|
||||
X:\servier\qqbot\
|
||||
</outputDirectory>
|
||||
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
|
||||
8
src/main/java/com/yutou/bilibili/BaseAPI.java
Normal file
8
src/main/java/com/yutou/bilibili/BaseAPI.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.yutou.bilibili;
|
||||
|
||||
public class BaseAPI {
|
||||
public static final String BASE_URL = "https://api.bilibili.com/";
|
||||
|
||||
public static final String MCBBS_PNG = "https://www.mcbbs.net/template/mcbbs/image/special_photo_bg.png";
|
||||
public static final String ACCESS_TOKEN = "https://passport.bilibili.com/login/app/third";
|
||||
}
|
||||
9
src/main/java/com/yutou/bilibili/api/LiveAPI.java
Normal file
9
src/main/java/com/yutou/bilibili/api/LiveAPI.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.yutou.bilibili.api;
|
||||
|
||||
public class LiveAPI {
|
||||
public static final String LIVE_SEND_DANMU="https://api.live.bilibili.com/msg/send";
|
||||
|
||||
public static final String LIVE_ROOM_INFO = "https://api.live.bilibili.com/room/v1/Room/get_info";
|
||||
public static final String LIVE_TASK_PROGRESS = "https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/GetUserTaskProgress";
|
||||
public static final String LIVE_SET_TASK_PROGRESS = "https://api.live.bilibili.com/xlive/app-ucenter/v1/userTask/UserTaskReceiveRewards";
|
||||
}
|
||||
7
src/main/java/com/yutou/bilibili/api/LoginAPI.java
Normal file
7
src/main/java/com/yutou/bilibili/api/LoginAPI.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.yutou.bilibili.api;
|
||||
|
||||
public class LoginAPI {
|
||||
public static final String LOGIN_QRCODE = "https://passport.bilibili.com/x/passport-login/web/qrcode/generate";
|
||||
public static final String LOGIN_QRCODE_POLL="https://passport.bilibili.com/x/passport-login/web/qrcode/poll";
|
||||
|
||||
}
|
||||
9
src/main/java/com/yutou/bilibili/api/MangaApi.java
Normal file
9
src/main/java/com/yutou/bilibili/api/MangaApi.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.yutou.bilibili.api;
|
||||
|
||||
public class MangaApi {
|
||||
|
||||
public static final String SIGN = "https://manga.bilibili.com/twirp/activity.v1.Activity/ClockIn";
|
||||
public static final String LIST_PRODUCT_DATE = "https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/ListProduct";
|
||||
public static final String USER_POINT = "https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/GetUserPoint";
|
||||
public static final String PAY_MISSION = "https://manga.bilibili.com/twirp/pointshop.v1.Pointshop/Exchange";
|
||||
}
|
||||
7
src/main/java/com/yutou/bilibili/api/SignApi.java
Normal file
7
src/main/java/com/yutou/bilibili/api/SignApi.java
Normal file
@@ -0,0 +1,7 @@
|
||||
package com.yutou.bilibili.api;
|
||||
|
||||
public class SignApi {
|
||||
public static final String LIVE_SIGN_COIN = "https://api.live.bilibili.com/xlive/revenue/v1/wallet/silver2coin";
|
||||
public static final String LIVE_SIGN = "https://api.live.bilibili.com/xlive/web-ucenter/v1/sign/DoSign";
|
||||
public static final String VIP_SIGN = "https://api.bilibili.com/pgc/activity/score/task/sign";
|
||||
}
|
||||
10
src/main/java/com/yutou/bilibili/api/UserApi.java
Normal file
10
src/main/java/com/yutou/bilibili/api/UserApi.java
Normal file
@@ -0,0 +1,10 @@
|
||||
package com.yutou.bilibili.api;
|
||||
|
||||
public class UserApi {
|
||||
@Deprecated
|
||||
public static final String USER_INFO = "https://api.bilibili.com/x/space/acc/info";
|
||||
public static final String USER_INFO_V2="https://api.bilibili.com/x/space/wbi/acc/info";
|
||||
public static final String NAV = "https://api.bilibili.com/x/web-interface/nav";
|
||||
|
||||
|
||||
}
|
||||
6
src/main/java/com/yutou/bilibili/api/VideoApi.java
Normal file
6
src/main/java/com/yutou/bilibili/api/VideoApi.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.yutou.bilibili.api;
|
||||
|
||||
public class VideoApi {
|
||||
|
||||
public static final String VIDEO_AI = "https://api.bilibili.com/x/web-interface/view/conclusion/get";
|
||||
}
|
||||
64
src/main/java/com/yutou/napcat/NapCatQQ.java
Normal file
64
src/main/java/com/yutou/napcat/NapCatQQ.java
Normal file
@@ -0,0 +1,64 @@
|
||||
package com.yutou.napcat;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.enums.MessageEnum;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.napcat.handle.*;
|
||||
import com.yutou.napcat.model.*;
|
||||
import com.yutou.okhttp.HttpCallback;
|
||||
import com.yutou.napcat.http.NapCatApi;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.utlis.Base64Tools;
|
||||
import lombok.val;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class NapCatQQ {
|
||||
|
||||
|
||||
private NapCatQQ() {
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
/* List<BaseHandle<?>> list = new ArrayList<>();
|
||||
list.add(new Text("1", false));
|
||||
list.add(new Text("2", false));
|
||||
list.add(new Text("3"));
|
||||
list.add(new Text("4", false));
|
||||
list.add(new At(583819556L));
|
||||
list.add(new Text("5"));
|
||||
QQBotManager.getInstance().sendMessage(false, 891655174L, list);*/
|
||||
NapCatApi.setLog(false);
|
||||
File file = new File("C:\\Users\\58381\\Downloads\\0074TT8Yly1hp5mqidwqeg30g20f27wh.gif");
|
||||
NapCatApi.getMessageApi().sendPrivateMsg(
|
||||
MessageHandleBuild.create()
|
||||
.setQQNumber(583819556L)
|
||||
//.add(new Image(file))
|
||||
.add(new Text("abc"))
|
||||
.build()
|
||||
).enqueue(new HttpCallback<SendMessageResponse>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, SendMessageResponse response, String rawResponse) {
|
||||
System.out.println("code = " + code + ", status = " + status + ", response = " + response + ", rawResponse = " + rawResponse);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
throwable.printStackTrace();
|
||||
}
|
||||
});
|
||||
}
|
||||
/**
|
||||
* 私聊
|
||||
{"self_id":240828363,"user_id":583819556,"time":1714472684,"message_id":376,"real_id":376,"message_type":"private","sender":{"user_id":583819556,"nickname":"魔芋","card":""},"raw_message":"123","font":14,"sub_type":"friend","message":[{"data":{"text":"123"},"type":"text"}],"message_format":"array","post_type":"message"}
|
||||
*/
|
||||
|
||||
/**
|
||||
* 群聊
|
||||
* {"self_id":240828363,"user_id":583819556,"time":1714472695,"message_id":377,"real_id":377,"message_type":"group","sender":{"user_id":583819556,"nickname":"魔芋","card":"","role":"owner"},"raw_message":"222","font":14,"sub_type":"normal","message":[{"data":{"text":"222"},"type":"text"}],"message_format":"array","post_type":"message","group_id":891655174}
|
||||
*/
|
||||
}
|
||||
54
src/main/java/com/yutou/napcat/QQDatabase.java
Normal file
54
src/main/java/com/yutou/napcat/QQDatabase.java
Normal file
@@ -0,0 +1,54 @@
|
||||
package com.yutou.napcat;
|
||||
|
||||
import com.yutou.napcat.model.FriendBean;
|
||||
import com.yutou.napcat.model.GroupBean;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QQDatabase {
|
||||
private static Map<Long, Object> data = new HashMap<>();
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private static FriendBean me;
|
||||
|
||||
public static void addUser(Long qq, FriendBean bean) {
|
||||
data.put(qq, bean);
|
||||
}
|
||||
|
||||
public static void addGroup(Long qq, GroupBean bean) {
|
||||
data.put(qq, bean);
|
||||
}
|
||||
|
||||
public static boolean checkFriend(Long qq) {
|
||||
if (data.containsKey(qq)) {
|
||||
return data.get(qq) instanceof FriendBean;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkGroup(Long qq) {
|
||||
if (data.containsKey(qq)) {
|
||||
return data.get(qq) instanceof GroupBean;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static List<GroupBean> getGroups() {
|
||||
List<GroupBean> numbers = new ArrayList<>();
|
||||
for (Long qq : data.keySet()) {
|
||||
if (data.get(qq) instanceof GroupBean) {
|
||||
{
|
||||
numbers.add((GroupBean) data.get(qq));
|
||||
}
|
||||
}
|
||||
}
|
||||
return numbers;
|
||||
}
|
||||
|
||||
}
|
||||
29
src/main/java/com/yutou/napcat/enums/MessageEnum.java
Normal file
29
src/main/java/com/yutou/napcat/enums/MessageEnum.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.yutou.napcat.enums;
|
||||
|
||||
public enum MessageEnum {
|
||||
TEXT("text"),
|
||||
IMAGE("image"),
|
||||
AT("at"),
|
||||
REPLY("reply"),
|
||||
JSON("json");
|
||||
|
||||
String type;
|
||||
|
||||
MessageEnum(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public static MessageEnum of(String type) {
|
||||
for (MessageEnum messageEnum : MessageEnum.values()) {
|
||||
if (messageEnum.getType().equals(type)) {
|
||||
return messageEnum;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/yutou/napcat/enums/RecordFormatEnum.java
Normal file
28
src/main/java/com/yutou/napcat/enums/RecordFormatEnum.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.yutou.napcat.enums;
|
||||
|
||||
public enum RecordFormatEnum {
|
||||
MP3("mp3"),
|
||||
AMR("amr"),
|
||||
WMA("wma"),
|
||||
M4A("m4a"),
|
||||
SPX("spx"),
|
||||
OGG("ogg"),
|
||||
WAV("wav"),
|
||||
FLAC("flac");
|
||||
|
||||
|
||||
private final String format;
|
||||
|
||||
RecordFormatEnum(String format) {
|
||||
this.format = format;
|
||||
}
|
||||
|
||||
public String getFormat() {
|
||||
return format;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return format;
|
||||
}
|
||||
}
|
||||
13
src/main/java/com/yutou/napcat/event/GroupMessageEvent.java
Normal file
13
src/main/java/com/yutou/napcat/event/GroupMessageEvent.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.yutou.napcat.event;
|
||||
|
||||
import com.yutou.napcat.model.GroupFrom;
|
||||
import lombok.Data;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
public class GroupMessageEvent extends MessageEvent {
|
||||
private GroupFrom group;
|
||||
|
||||
}
|
||||
197
src/main/java/com/yutou/napcat/event/MessageEvent.java
Normal file
197
src/main/java/com/yutou/napcat/event/MessageEvent.java
Normal file
@@ -0,0 +1,197 @@
|
||||
package com.yutou.napcat.event;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.fasterxml.jackson.databind.deser.impl.BeanPropertyMap;
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.enums.MessageEnum;
|
||||
import com.yutou.napcat.handle.*;
|
||||
import com.yutou.napcat.model.AppShareBean;
|
||||
import com.yutou.napcat.model.Message;
|
||||
import com.yutou.napcat.model.SourceFrom;
|
||||
import lombok.Data;
|
||||
import lombok.val;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class MessageEvent {
|
||||
|
||||
@JSONField(name = "self_id")
|
||||
private Long selfId;
|
||||
|
||||
@JSONField(name = "user_id")
|
||||
private Long userId;
|
||||
|
||||
@JSONField(name = "time")
|
||||
private Long time;
|
||||
|
||||
@JSONField(name = "message_id")
|
||||
private Integer messageId;
|
||||
|
||||
@JSONField(name = "real_id")
|
||||
private Integer realId;
|
||||
|
||||
@JSONField(name = "message_type")
|
||||
private String messageType;
|
||||
|
||||
@JSONField(name = "sender")
|
||||
private SourceFrom source;
|
||||
|
||||
@JSONField(name = "raw_message")
|
||||
private String rawMessage;
|
||||
|
||||
@JSONField(name = "font")
|
||||
private Integer font;
|
||||
|
||||
@JSONField(name = "sub_type")
|
||||
private String subType;
|
||||
|
||||
@JSONField(name = "message")
|
||||
private List<BaseHandle<?>> message;
|
||||
|
||||
@JSONField(name = "message_format")
|
||||
private String messageFormat;
|
||||
|
||||
@JSONField(name = "post_type")
|
||||
private String postType;
|
||||
|
||||
@JSONField(name = "group_id")
|
||||
private Long groupId;
|
||||
|
||||
|
||||
public static MessageEvent parseHandleHttp(String jsonString) {
|
||||
return parseHandle(JSONObject.parseObject(jsonString).getJSONObject("data").toString());
|
||||
}
|
||||
|
||||
public static MessageEvent parseHandle(String jsonString) {
|
||||
JSONObject json = JSONObject.parseObject(jsonString);
|
||||
JSONArray array = json.getJSONArray("message");
|
||||
List<BaseHandle<?>> messageList = new ArrayList<>();
|
||||
if (array != null) {
|
||||
for (Object o : array) {
|
||||
JSONObject _json = (JSONObject) o;
|
||||
Type classType = null;
|
||||
MessageEnum _type = MessageEnum.of(_json.getString("type"));
|
||||
classType = switch (_type) {
|
||||
case TEXT -> Text.TextInfo.class;
|
||||
case IMAGE -> Image.ImageInfo.class;
|
||||
case AT -> At.AtData.class;
|
||||
case JSON -> OtherHandle.OtherInfo.class;
|
||||
case REPLY -> Reply.ReplyInfo.class;
|
||||
default -> classType;
|
||||
};
|
||||
BaseHandle<?> handle = new BaseHandle<>(_type.getType());
|
||||
if (_type == MessageEnum.JSON) {
|
||||
handle.setData(JSONObject.parseObject(((JSONObject) o).getJSONObject("data").getString("data"), classType));
|
||||
} else {
|
||||
handle.setData(JSONObject.parseObject(((JSONObject) o).getJSONObject("data").toString(), classType));
|
||||
}
|
||||
messageList.add(handle);
|
||||
}
|
||||
}
|
||||
MessageEvent event = new MessageEvent();
|
||||
event.setTime(json.getLong("time"));
|
||||
event.setSelfId(json.getLong("self_id"));
|
||||
event.setPostType(json.getString("post_type"));
|
||||
event.setGroupId(json.getLong("group_id"));
|
||||
event.setUserId(json.getLong("user_id"));
|
||||
event.setSubType(json.getString("sub_type"));
|
||||
try {
|
||||
SourceFrom sender = new SourceFrom();
|
||||
sender.setUserId(event.getUserId());
|
||||
event.setSource(sender);
|
||||
sender.setUserId(json.getJSONObject("sender").getLong("user_id"));
|
||||
sender.setNickname(json.getJSONObject("sender").getString("nickname"));
|
||||
sender.setCard(json.getJSONObject("sender").getString("card"));
|
||||
event.setMessageId(json.getInteger("message_id"));
|
||||
event.setRealId(json.getInteger("real_id"));
|
||||
event.setMessageType(json.getString("message_type"));
|
||||
event.setSource(sender);
|
||||
event.setRawMessage(json.getString("raw_message"));
|
||||
event.setFont(json.getInteger("font"));
|
||||
event.setMessageFormat(json.getString("message_format"));
|
||||
event.setMessage(messageList);
|
||||
return event;
|
||||
} catch (Exception e) {
|
||||
System.err.println("jsonString:\n" + jsonString);
|
||||
}
|
||||
return event;
|
||||
}
|
||||
|
||||
public boolean hasType(MessageEnum messageEnum) {
|
||||
if(message==null||message.isEmpty()){
|
||||
return false;
|
||||
}
|
||||
for (BaseHandle<?> handle : message) {
|
||||
if (MessageEnum.of(handle.getType()) == messageEnum) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public <T extends BaseHandle> List<T> findAllType(Class<T> t) {
|
||||
List<T> tmp = new ArrayList<>();
|
||||
if (message == null || message.isEmpty()) {
|
||||
return tmp;
|
||||
}
|
||||
try {
|
||||
T newed = t.getDeclaredConstructor().newInstance();
|
||||
for (BaseHandle<?> baseHandle : message) {
|
||||
if (baseHandle.getType().equals(newed.getType())) {
|
||||
newed.setData(baseHandle.getData());
|
||||
tmp.add(newed);
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return tmp;
|
||||
}
|
||||
|
||||
public <T extends BaseHandle> T findType(Class<T> tClass) {
|
||||
List<T> list = findAllType(tClass);
|
||||
if (list == null || list.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return list.get(0);
|
||||
}
|
||||
|
||||
|
||||
public boolean isAtMe() {
|
||||
if (!hasType(MessageEnum.AT)) {
|
||||
return false;
|
||||
}
|
||||
List<At> list = findAllType(At.class);
|
||||
for (At handle : list) {
|
||||
if (handle.getData().getQq() == QQDatabase.getMe().getUserId()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getTextMessage() {
|
||||
val texts = findAllType(Text.class);
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Text text : texts) {
|
||||
sb.append(text);
|
||||
}
|
||||
return sb.toString().trim();
|
||||
}
|
||||
|
||||
public boolean isUser() {
|
||||
return "private".equals(messageType);
|
||||
}
|
||||
|
||||
public boolean isGroup() {
|
||||
return "group".equals(messageType);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
32
src/main/java/com/yutou/napcat/handle/At.java
Normal file
32
src/main/java/com/yutou/napcat/handle/At.java
Normal file
@@ -0,0 +1,32 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
public class At extends BaseHandle<At.AtData> {
|
||||
public At() {
|
||||
super("at");
|
||||
}
|
||||
|
||||
public At(Long userId) {
|
||||
super("at");
|
||||
data = new AtData(userId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
if (data == null) {
|
||||
return null;
|
||||
}
|
||||
return String.format("[CQ:at,qq=%d]", data.qq);
|
||||
}
|
||||
|
||||
@Data
|
||||
public class AtData extends BaseBean {
|
||||
private Long qq;
|
||||
|
||||
public AtData(Long qq) {
|
||||
this.qq = qq;
|
||||
}
|
||||
}
|
||||
}
|
||||
28
src/main/java/com/yutou/napcat/handle/BaseHandle.java
Normal file
28
src/main/java/com/yutou/napcat/handle/BaseHandle.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.enums.MessageEnum;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class BaseHandle<T> extends BaseBean {
|
||||
protected String type;
|
||||
protected T data;
|
||||
protected String src;
|
||||
|
||||
public BaseHandle(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
||||
public BaseHandle(String type, Object obj) {
|
||||
super();
|
||||
this.type = type;
|
||||
this.data= (T) obj;
|
||||
}
|
||||
}
|
||||
35
src/main/java/com/yutou/napcat/handle/Image.java
Normal file
35
src/main/java/com/yutou/napcat/handle/Image.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.qqbot.utlis.Base64Tools;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class Image extends BaseHandle<Image.ImageInfo> {
|
||||
|
||||
public Image() {
|
||||
super("image");
|
||||
}
|
||||
|
||||
public Image(String imageUrl) {
|
||||
super("image");
|
||||
data = new ImageInfo(imageUrl);
|
||||
}
|
||||
public Image(File imageFile){
|
||||
super("image");
|
||||
data=new ImageInfo("base64://"+ Base64Tools.encode(imageFile));
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ImageInfo {
|
||||
String file;
|
||||
String url;
|
||||
@JSONField(name = "file_size")
|
||||
String fileSize;
|
||||
|
||||
public ImageInfo(String file) {
|
||||
this.file = file;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MessageHandleBuild {
|
||||
private List<BaseHandle<?>> msgList = new ArrayList<>();
|
||||
private long qq;
|
||||
private boolean autoEscape;
|
||||
private boolean isGroup;
|
||||
|
||||
public static MessageHandleBuild create() {
|
||||
return new MessageHandleBuild();
|
||||
}
|
||||
|
||||
private MessageHandleBuild() {
|
||||
msgList = new ArrayList<>();
|
||||
}
|
||||
|
||||
public MessageHandleBuild setQQNumber(long qq) {
|
||||
this.qq = qq;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHandleBuild setAutoEscape(boolean autoEscape) {
|
||||
this.autoEscape = autoEscape;
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHandleBuild add(BaseHandle<?> msg) {
|
||||
msgList.add(msg);
|
||||
return this;
|
||||
}
|
||||
|
||||
public MessageHandleBuild setGroup(boolean group) {
|
||||
isGroup = group;
|
||||
return this;
|
||||
}
|
||||
|
||||
public JSONObject build() {
|
||||
JSONObject json=new JSONObject();
|
||||
if(isGroup){
|
||||
json.put("group_id", qq);
|
||||
}else {
|
||||
json.put("user_id", qq);
|
||||
}
|
||||
json.put("auto_escape", autoEscape);
|
||||
json.put("message", msgList);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
20
src/main/java/com/yutou/napcat/handle/OtherHandle.java
Normal file
20
src/main/java/com/yutou/napcat/handle/OtherHandle.java
Normal file
@@ -0,0 +1,20 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.model.AppShareBean;
|
||||
import lombok.Data;
|
||||
|
||||
public class OtherHandle extends BaseHandle<OtherHandle.OtherInfo>{
|
||||
|
||||
public OtherHandle() {
|
||||
super("json");
|
||||
data= new OtherInfo();
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class OtherInfo extends AppShareBean{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/yutou/napcat/handle/QuoteReply.java
Normal file
14
src/main/java/com/yutou/napcat/handle/QuoteReply.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
public class QuoteReply {
|
||||
private final String messageId;
|
||||
|
||||
public QuoteReply(String messageId) {
|
||||
this.messageId = messageId;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[CQ:reply,id=%s]",messageId);
|
||||
}
|
||||
}
|
||||
38
src/main/java/com/yutou/napcat/handle/Record.java
Normal file
38
src/main/java/com/yutou/napcat/handle/Record.java
Normal file
@@ -0,0 +1,38 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import lombok.Data;
|
||||
|
||||
public class Record extends BaseHandle<Record.RecordInfo> {
|
||||
|
||||
public Record() {
|
||||
super("record");
|
||||
}
|
||||
|
||||
public Record(String file) {
|
||||
super("record");
|
||||
data = new RecordInfo(file);
|
||||
}
|
||||
|
||||
public Record(String file, boolean proxy) {
|
||||
super("record");
|
||||
data = new RecordInfo(file);
|
||||
data.proxy = proxy ? "1" : "0";
|
||||
}
|
||||
|
||||
|
||||
@Data
|
||||
public static class RecordInfo {
|
||||
String file;
|
||||
int magic;
|
||||
String url;
|
||||
String cache;
|
||||
String proxy;
|
||||
String timeout;
|
||||
|
||||
public RecordInfo(String file) {
|
||||
this.file = ConfigTools.getServerUrl()+file;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
24
src/main/java/com/yutou/napcat/handle/Reply.java
Normal file
24
src/main/java/com/yutou/napcat/handle/Reply.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
public class Reply extends BaseHandle<Reply.ReplyInfo> {
|
||||
|
||||
public Reply() {
|
||||
super("reply");
|
||||
}
|
||||
|
||||
public Reply(long id) {
|
||||
super("reply");
|
||||
data = new ReplyInfo(id);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class ReplyInfo {
|
||||
private long id;
|
||||
|
||||
public ReplyInfo(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
}
|
||||
}
|
||||
53
src/main/java/com/yutou/napcat/handle/Text.java
Normal file
53
src/main/java/com/yutou/napcat/handle/Text.java
Normal file
@@ -0,0 +1,53 @@
|
||||
package com.yutou.napcat.handle;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class Text extends BaseHandle<Text.TextInfo> {
|
||||
|
||||
public Text() {
|
||||
super("text");
|
||||
}
|
||||
|
||||
public Text(String text) {
|
||||
super("text");
|
||||
data = new TextInfo(text + "\n");
|
||||
}
|
||||
|
||||
public Text(String text, boolean isNewLine) {
|
||||
super("text");
|
||||
if (isNewLine) {
|
||||
data = new TextInfo(text + "\n");
|
||||
} else {
|
||||
data = new TextInfo(text);
|
||||
}
|
||||
}
|
||||
|
||||
public Text(boolean isNewLine, String... text) {
|
||||
super("text");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (String s : text) {
|
||||
sb.append(s);
|
||||
}
|
||||
if (isNewLine) {
|
||||
data = new TextInfo(sb + "\n");
|
||||
} else {
|
||||
data = new TextInfo(sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return data.text.trim();
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class TextInfo {
|
||||
String text;
|
||||
|
||||
public TextInfo(String text) {
|
||||
this.text = text.trim();
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/main/java/com/yutou/napcat/http/FriendApi.java
Normal file
17
src/main/java/com/yutou/napcat/http/FriendApi.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.napcat.model.FriendBean;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface FriendApi {
|
||||
@POST("/get_friend_list")
|
||||
Call<HttpBody<List<FriendBean>>> getFriendList(
|
||||
);
|
||||
}
|
||||
89
src/main/java/com/yutou/napcat/http/GroupApi.java
Normal file
89
src/main/java/com/yutou/napcat/http/GroupApi.java
Normal file
@@ -0,0 +1,89 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.napcat.model.FriendBean;
|
||||
import com.yutou.napcat.model.GroupBean;
|
||||
import com.yutou.napcat.model.GroupUserBean;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface GroupApi {
|
||||
/**
|
||||
* 禁言
|
||||
*
|
||||
* @param group 群号
|
||||
* @param user 用户
|
||||
* @param duration 禁言时长,单位秒
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/set_group_ban")
|
||||
Call<HttpBody<BaseBean>> groupBan(
|
||||
@Field("group_id") long group,
|
||||
@Field("user_id") long user,
|
||||
@Field("duration") long duration
|
||||
);
|
||||
|
||||
/**
|
||||
* 禁言群组全体成员
|
||||
*
|
||||
* @param group 群号
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/set_group_whole_ban")
|
||||
Call<HttpBody<BaseBean>> groupBanAll(
|
||||
@Field("group_id") long group
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组列表
|
||||
*/
|
||||
@POST("/get_group_list")
|
||||
Call<HttpBody<List<GroupBean>>> getGroupList(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组信息
|
||||
*/
|
||||
@POST("/get_group_info")
|
||||
Call<HttpBody<GroupBean>> getGroupInfo(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组成员信息
|
||||
*/
|
||||
@POST("/get_group_member_info")
|
||||
Call<HttpBody<GroupUserBean>> getGroupUserInfo(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取群组成员列表
|
||||
*
|
||||
* @param group 群号
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/get_group_member_list")
|
||||
Call<HttpBody<List<GroupUserBean>>> getGroupUserList(
|
||||
@Field("group_id") long group,
|
||||
@Field("no_cache")boolean noCache
|
||||
);
|
||||
|
||||
/**
|
||||
* 设置群组专属头衔
|
||||
* @param group 群号
|
||||
* @param user 用户
|
||||
* @param title 头衔
|
||||
* @param duration 持续时间,单位秒
|
||||
*/
|
||||
@POST("/set_group_special_title")
|
||||
@FormUrlEncoded
|
||||
Call<HttpBody<BaseBean>> setGroupSpecialTitle(
|
||||
@Field("group_id") long group,
|
||||
@Field("user_id") long user,
|
||||
@Field("special_title") String title,
|
||||
@Field("duration") long duration );
|
||||
}
|
||||
52
src/main/java/com/yutou/napcat/http/MessageAPI.java
Normal file
52
src/main/java/com/yutou/napcat/http/MessageAPI.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.napcat.model.MessageBean;
|
||||
import com.yutou.napcat.model.SendMessageResponse;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import kotlin.jvm.JvmSuppressWildcards;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MessageAPI {
|
||||
/**
|
||||
* 发送私聊消息
|
||||
* @param message {@link com.yutou.napcat.handle.MessageHandleBuild}
|
||||
* @return 消息id
|
||||
*/
|
||||
@POST("/send_private_msg")
|
||||
Call<HttpBody<SendMessageResponse>> sendPrivateMsg(
|
||||
@Body
|
||||
JSONObject message);
|
||||
/**
|
||||
* 发送群聊消息
|
||||
* @param message 消息内容
|
||||
* @return 消息id
|
||||
*/
|
||||
@POST("/send_group_msg")
|
||||
Call<HttpBody<SendMessageResponse>> sendGroupMsg(
|
||||
@Body
|
||||
JSONObject message
|
||||
);
|
||||
|
||||
/**
|
||||
* 撤回消息
|
||||
* @param messageId 消息id
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/delete_msg")
|
||||
Call<HttpBody<BaseBean>> delMsg(
|
||||
@Field("message_id") long messageId
|
||||
);
|
||||
|
||||
@FormUrlEncoded
|
||||
@POST("/get_msg")
|
||||
Call<HttpBody<MessageBean>> getMessage(
|
||||
@Field("message_id") long messageId
|
||||
);
|
||||
}
|
||||
29
src/main/java/com/yutou/napcat/http/NapCatApi.java
Normal file
29
src/main/java/com/yutou/napcat/http/NapCatApi.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.okhttp.api.BaseApi;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
|
||||
public class NapCatApi extends BaseApi {
|
||||
private static final String URL;
|
||||
static {
|
||||
URL= ConfigTools.load(ConfigTools.CONFIG,ConfigTools.NAPCAT_URL,String.class);
|
||||
}
|
||||
|
||||
public static void setLog(boolean log){
|
||||
HttpLoggingInterceptor.setLog(log);
|
||||
}
|
||||
|
||||
public static MessageAPI getMessageApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(MessageAPI.class);
|
||||
}
|
||||
public static UtilsApi getUtilsApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(UtilsApi.class);
|
||||
}
|
||||
public static GroupApi getGroupApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(GroupApi.class);
|
||||
}
|
||||
public static FriendApi getFriendApi(){
|
||||
return new NapCatApi().setURL(URL).createApi(FriendApi.class);
|
||||
}
|
||||
}
|
||||
80
src/main/java/com/yutou/napcat/http/UtilsApi.java
Normal file
80
src/main/java/com/yutou/napcat/http/UtilsApi.java
Normal file
@@ -0,0 +1,80 @@
|
||||
package com.yutou.napcat.http;
|
||||
|
||||
import com.yutou.napcat.model.*;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import retrofit2.Call;
|
||||
import retrofit2.http.Field;
|
||||
import retrofit2.http.FormUrlEncoded;
|
||||
import retrofit2.http.POST;
|
||||
|
||||
public interface UtilsApi {
|
||||
/**
|
||||
* 获取语音
|
||||
*
|
||||
* @param fileId 收到的语音文件名(消息段的 file 参数),如 0B38145AA44505000B38145AA4450500.silk
|
||||
* @param format 要转换到的格式,目前支持 mp3、amr、wma、m4a、spx、ogg、wav、flac {@link com.yutou.napcat.enums.RecordFormatEnum}
|
||||
* @return 转换后的语音文件路径
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/get_record")
|
||||
Call<HttpBody<String>> getMessageRecord(
|
||||
@Field("file") String fileId,
|
||||
@Field("out_format") String format
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取图片
|
||||
*
|
||||
* @param fileId 收到的图片文件名(消息段的 file 参数)
|
||||
* @return 下载后的图片文件路径
|
||||
*/
|
||||
@FormUrlEncoded
|
||||
@POST("/get_image")
|
||||
Call<HttpBody<String>> getMessageImage(
|
||||
@Field("file") String fileId
|
||||
);
|
||||
|
||||
/**
|
||||
* 检查是否可以发送图片
|
||||
*/
|
||||
@POST("/can_send_image")
|
||||
Call<HttpBody<CheckSendImageBean>> checkSendImage(
|
||||
);
|
||||
|
||||
/**
|
||||
* 检查是否可以发送语音
|
||||
*/
|
||||
@POST("/can_send_record")
|
||||
Call<HttpBody<CheckSendRecordBean>> checkSendRecord(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取机器人状态
|
||||
*/
|
||||
@POST("/get_status")
|
||||
Call<HttpBody<QQBotStatusBean>> checkQQBotStatus(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取机器人版本信息
|
||||
*/
|
||||
@POST("/get_version_info")
|
||||
Call<HttpBody<QQBotVersionBean>> checkQQBotVersion(
|
||||
);
|
||||
|
||||
/**
|
||||
* 清理缓存
|
||||
*/
|
||||
@POST("/clean_cache")
|
||||
Call<HttpBody<BaseBean>> cleanCache(
|
||||
);
|
||||
|
||||
/**
|
||||
* 获取登录信息
|
||||
*/
|
||||
@POST("/get_login_info")
|
||||
Call<HttpBody<FriendBean>> getLoginInfo(
|
||||
);
|
||||
|
||||
}
|
||||
139
src/main/java/com/yutou/napcat/model/AppShareBean.java
Normal file
139
src/main/java/com/yutou/napcat/model/AppShareBean.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Data
|
||||
|
||||
public class AppShareBean extends BaseBean {
|
||||
|
||||
@JSONField(name = "ver")
|
||||
private String version;
|
||||
|
||||
@JSONField(name = "prompt")
|
||||
private String prompt;
|
||||
|
||||
@JSONField(name = "config")
|
||||
private Config config;
|
||||
|
||||
@JSONField(name = "needShareCallBack")
|
||||
private boolean needShareCallBack;
|
||||
|
||||
@JSONField(name = "app")
|
||||
private String app;
|
||||
|
||||
@JSONField(name = "view")
|
||||
private String view;
|
||||
|
||||
@JSONField(name = "meta")
|
||||
private Meta meta;
|
||||
|
||||
// getters and setters...
|
||||
|
||||
// Inner classes
|
||||
|
||||
@Data
|
||||
public static class Config {
|
||||
@JSONField(name = "type")
|
||||
private String type;
|
||||
|
||||
@JSONField(name = "width")
|
||||
private int width;
|
||||
|
||||
@JSONField(name = "height")
|
||||
private int height;
|
||||
|
||||
@JSONField(name = "forward")
|
||||
private int forward;
|
||||
|
||||
@JSONField(name = "autoSize")
|
||||
private int autoSize;
|
||||
|
||||
@JSONField(name = "ctime")
|
||||
private long ctime;
|
||||
|
||||
@JSONField(name = "token")
|
||||
private String token;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Meta {
|
||||
@JSONField(name = "detail_1")
|
||||
private Detail detail1;
|
||||
|
||||
// If there can be multiple "detail_X" entries, you might need a Map
|
||||
// @JSONField(name = "detail_X")
|
||||
// private Map<String, Detail> details;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Detail {
|
||||
@JSONField(name = "appid")
|
||||
private String appid;
|
||||
|
||||
@JSONField(name = "appType")
|
||||
private int appType;
|
||||
|
||||
@JSONField(name = "title")
|
||||
private String title;
|
||||
|
||||
@JSONField(name = "desc")
|
||||
private String desc;
|
||||
|
||||
@JSONField(name = "icon")
|
||||
private String icon;
|
||||
|
||||
@JSONField(name = "preview")
|
||||
private String preview;
|
||||
|
||||
@JSONField(name = "url")
|
||||
private String url;
|
||||
|
||||
@JSONField(name = "scene")
|
||||
private int scene;
|
||||
|
||||
@JSONField(name = "host")
|
||||
private Host host;
|
||||
|
||||
@JSONField(name = "shareTemplateId")
|
||||
private String shareTemplateId;
|
||||
|
||||
// Since "shareTemplateData" is an empty object, it can be left as a Map or a specific class
|
||||
// if you know the structure of the data that might be there
|
||||
@JSONField(name = "shareTemplateData")
|
||||
private Map<String, Object> shareTemplateData;
|
||||
|
||||
@JSONField(name = "qqdocurl")
|
||||
private String qqdocurl;
|
||||
|
||||
@JSONField(name = "showLittleTail")
|
||||
private String showLittleTail;
|
||||
|
||||
@JSONField(name = "gamePoints")
|
||||
private String gamePoints;
|
||||
|
||||
@JSONField(name = "gamePointsUrl")
|
||||
private String gamePointsUrl;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Host {
|
||||
@JSONField(name = "uin")
|
||||
private long uin;
|
||||
|
||||
@JSONField(name = "nick")
|
||||
private String nick;
|
||||
|
||||
// getters and setters...
|
||||
}
|
||||
|
||||
}
|
||||
12
src/main/java/com/yutou/napcat/model/CheckSendImageBean.java
Normal file
12
src/main/java/com/yutou/napcat/model/CheckSendImageBean.java
Normal file
@@ -0,0 +1,12 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CheckSendImageBean extends BaseBean {
|
||||
@JSONField(name = "yes")
|
||||
private boolean yes;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class CheckSendRecordBean extends BaseBean {
|
||||
@JSONField(name = "yes")
|
||||
private boolean yes;
|
||||
|
||||
}
|
||||
15
src/main/java/com/yutou/napcat/model/FriendBean.java
Normal file
15
src/main/java/com/yutou/napcat/model/FriendBean.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class FriendBean extends BaseBean {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;//qq号
|
||||
@JSONField(name = "nickname")
|
||||
private String nickName;//昵称
|
||||
@JSONField(name = "remark")
|
||||
private String remark;//备注
|
||||
}
|
||||
18
src/main/java/com/yutou/napcat/model/GroupBean.java
Normal file
18
src/main/java/com/yutou/napcat/model/GroupBean.java
Normal file
@@ -0,0 +1,18 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupBean extends BaseBean {
|
||||
@JSONField(name = "group_id")
|
||||
private long groupId;
|
||||
@JSONField(name = "group_name")
|
||||
private String groupName;
|
||||
@JSONField(name = "member_count")
|
||||
private int userCount;
|
||||
@JSONField(name = "max_member_count")
|
||||
private int userMaxCount;
|
||||
|
||||
}
|
||||
8
src/main/java/com/yutou/napcat/model/GroupFrom.java
Normal file
8
src/main/java/com/yutou/napcat/model/GroupFrom.java
Normal file
@@ -0,0 +1,8 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupFrom {
|
||||
private long id;
|
||||
}
|
||||
72
src/main/java/com/yutou/napcat/model/GroupUserBean.java
Normal file
72
src/main/java/com/yutou/napcat/model/GroupUserBean.java
Normal file
@@ -0,0 +1,72 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GroupUserBean extends BaseBean {
|
||||
// 群号
|
||||
@JSONField(name = "group_id")
|
||||
private long groupId;
|
||||
|
||||
// QQ号
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
|
||||
// 昵称
|
||||
@JSONField(name = "nickname")
|
||||
private String nickname;
|
||||
|
||||
// 群名片/备注
|
||||
@JSONField(name = "card")
|
||||
private String card;
|
||||
|
||||
// 性别,male 或 female 或 unknown
|
||||
@JSONField(name = "sex")
|
||||
private String sex;
|
||||
|
||||
// 年龄
|
||||
@JSONField(name = "age")
|
||||
private int age;
|
||||
|
||||
// 地区
|
||||
@JSONField(name = "area")
|
||||
private String area;
|
||||
|
||||
// 加群时间戳
|
||||
@JSONField(name = "join_time")
|
||||
private int joinTime;
|
||||
|
||||
// 最后发言时间戳
|
||||
@JSONField(name = "last_sent_time")
|
||||
private int lastSentTime;
|
||||
|
||||
// 成员等级
|
||||
@JSONField(name = "level")
|
||||
private String level;
|
||||
|
||||
// 角色,owner 或 admin 或 member
|
||||
@JSONField(name = "role")
|
||||
private String role;
|
||||
|
||||
// 是否不良记录成员
|
||||
@JSONField(name = "unfriendly")
|
||||
private boolean unfriendly;
|
||||
|
||||
// 专属头衔
|
||||
@JSONField(name = "title")
|
||||
private String title;
|
||||
|
||||
// 专属头衔过期时间戳
|
||||
@JSONField(name = "title_expire_time")
|
||||
private int titleExpireTime;
|
||||
|
||||
// 是否允许修改群名片
|
||||
@JSONField(name = "card_changeable")
|
||||
private boolean cardChangeable;
|
||||
// 禁言剩余时间
|
||||
@JSONField(name = "shut_up_timestamp")
|
||||
private long shutUpTimestamp;
|
||||
|
||||
}
|
||||
23
src/main/java/com/yutou/napcat/model/Message.java
Normal file
23
src/main/java/com/yutou/napcat/model/Message.java
Normal file
@@ -0,0 +1,23 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Message {
|
||||
private String message;
|
||||
private String srcMessage;
|
||||
private String id;
|
||||
public Message(String message, String srcMessage) {
|
||||
this.message = message;
|
||||
this.srcMessage = srcMessage;
|
||||
}
|
||||
|
||||
public String serializeToMiraiCode(){
|
||||
return srcMessage;
|
||||
}
|
||||
|
||||
public String contentToString(){
|
||||
return message;
|
||||
}
|
||||
|
||||
}
|
||||
50
src/main/java/com/yutou/napcat/model/MessageBean.java
Normal file
50
src/main/java/com/yutou/napcat/model/MessageBean.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* 消息
|
||||
* @see <a href="https://github.com/botuniverse/onebot-11/blob/master/api/public.md#get_msg-%E8%8E%B7%E5%8F%96%E6%B6%88%E6%81%AF">文档</a>
|
||||
*/
|
||||
@Data
|
||||
public class MessageBean extends BaseBean {
|
||||
/**
|
||||
*发送时间
|
||||
*/
|
||||
@JSONField(name = "time")
|
||||
private long time;
|
||||
/**
|
||||
* 消息类型,同 <a href="https://github.com/botuniverse/onebot-11/blob/master/event/message.md">消息事件</a>
|
||||
*/
|
||||
@JSONField(name = "message_type")
|
||||
private String type;
|
||||
/**
|
||||
* 消息 ID
|
||||
*/
|
||||
@JSONField(name = "message_id")
|
||||
private int messageId;
|
||||
/**
|
||||
* 消息真实 ID
|
||||
*/
|
||||
@JSONField(name = "real_id")
|
||||
private int realId;
|
||||
/**
|
||||
* 发送人信息,同 <a href="https://github.com/botuniverse/onebot-11/blob/master/event/message.md">消息事件</a>
|
||||
*/
|
||||
@JSONField(name = "sender")
|
||||
private SenderBean sender;
|
||||
/**
|
||||
* 消息内容
|
||||
*/
|
||||
@JSONField(name = "message")
|
||||
private String message;
|
||||
|
||||
|
||||
}
|
||||
13
src/main/java/com/yutou/napcat/model/QQBotStatusBean.java
Normal file
13
src/main/java/com/yutou/napcat/model/QQBotStatusBean.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QQBotStatusBean extends BaseBean {
|
||||
@JSONField(name = "online")
|
||||
private String online;//当前 QQ 在线,null 表示无法查询到在线状态
|
||||
@JSONField(name = "good")
|
||||
private String good;//状态符合预期,意味着各模块正常运行、功能正常,且 QQ 在线
|
||||
}
|
||||
17
src/main/java/com/yutou/napcat/model/QQBotVersionBean.java
Normal file
17
src/main/java/com/yutou/napcat/model/QQBotVersionBean.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class QQBotVersionBean {
|
||||
@JSONField(name = "app_name")
|
||||
private String appName;//应用标识,如 mirai-native
|
||||
|
||||
@JSONField(name = "app_version")
|
||||
private String appVersion;//应用版本,如 1.2.3
|
||||
|
||||
@JSONField(name = "protocol_version")
|
||||
private String protocolVersion;//OneBot 标准版本,如 v11
|
||||
|
||||
}
|
||||
21
src/main/java/com/yutou/napcat/model/SendMessageRequest.java
Normal file
21
src/main/java/com/yutou/napcat/model/SendMessageRequest.java
Normal file
@@ -0,0 +1,21 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
import java.util.List;
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SendMessageRequest extends BaseBean {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
@JSONField
|
||||
List<BaseHandle<?>> message;
|
||||
@SerializedName("auto_escape")
|
||||
private boolean notCQCode;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@Data
|
||||
public class SendMessageResponse extends BaseBean {
|
||||
@JSONField( name = "message_id")
|
||||
private int id;
|
||||
|
||||
private String e;
|
||||
|
||||
}
|
||||
24
src/main/java/com/yutou/napcat/model/SenderBean.java
Normal file
24
src/main/java/com/yutou/napcat/model/SenderBean.java
Normal file
@@ -0,0 +1,24 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 发送人结构体
|
||||
*
|
||||
*/
|
||||
@Data
|
||||
public class SenderBean extends BaseBean {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
@JSONField(name = "nickname")
|
||||
private String nickName;
|
||||
/**
|
||||
* male 或 female 或 unknown
|
||||
*/
|
||||
@JSONField(name = "sex")
|
||||
private String sex;
|
||||
@JSONField(name = "age")
|
||||
private int age;
|
||||
}
|
||||
17
src/main/java/com/yutou/napcat/model/SourceFrom.java
Normal file
17
src/main/java/com/yutou/napcat/model/SourceFrom.java
Normal file
@@ -0,0 +1,17 @@
|
||||
package com.yutou.napcat.model;
|
||||
|
||||
import com.alibaba.fastjson2.annotation.JSONField;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class SourceFrom {
|
||||
@JSONField(name = "user_id")
|
||||
private long userId;
|
||||
private String nickname;
|
||||
private String card;
|
||||
private String role;
|
||||
|
||||
public Long getFromId() {
|
||||
return userId;
|
||||
}
|
||||
}
|
||||
6
src/main/java/com/yutou/okhttp/BaseBean.java
Normal file
6
src/main/java/com/yutou/okhttp/BaseBean.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class BaseBean implements Serializable {
|
||||
}
|
||||
25
src/main/java/com/yutou/okhttp/GetRequestParams.java
Normal file
25
src/main/java/com/yutou/okhttp/GetRequestParams.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
|
||||
import okhttp3.HttpUrl;
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GetRequestParams implements IRequestParam {
|
||||
/**
|
||||
* 构建Request
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
public Request getRequest(HashMap<String, String> map, Request request) {
|
||||
//添加公共参数
|
||||
HttpUrl.Builder builder = request.url().newBuilder();
|
||||
for (String key : map.keySet()) {
|
||||
builder.addQueryParameter(key, String.valueOf(map.get(key)));
|
||||
}
|
||||
return request.newBuilder().url(builder.build()).build();
|
||||
}
|
||||
}
|
||||
14
src/main/java/com/yutou/okhttp/HttpBody.java
Normal file
14
src/main/java/com/yutou/okhttp/HttpBody.java
Normal file
@@ -0,0 +1,14 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HttpBody<T> {
|
||||
private String msg;
|
||||
private String status;
|
||||
private int code;
|
||||
private int retcode;
|
||||
private T data;
|
||||
private String src;
|
||||
|
||||
}
|
||||
31
src/main/java/com/yutou/okhttp/HttpCallback.java
Normal file
31
src/main/java/com/yutou/okhttp/HttpCallback.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
import retrofit2.Call;
|
||||
import retrofit2.Callback;
|
||||
import retrofit2.Response;
|
||||
|
||||
public abstract class HttpCallback<T> implements Callback<HttpBody<T>> {
|
||||
|
||||
public abstract void onResponse(int code, String status, T response, String rawResponse);
|
||||
|
||||
public abstract void onFailure(Throwable throwable);
|
||||
|
||||
@Override
|
||||
public void onResponse(Call<HttpBody<T>> call, Response<HttpBody<T>> response) {
|
||||
if (response.body() != null) {
|
||||
onResponse(
|
||||
response.body().getRetcode(),
|
||||
response.body().getStatus(),
|
||||
response.body().getData(),
|
||||
response.body().getSrc()
|
||||
);
|
||||
} else {
|
||||
onFailure(new NullPointerException("response body is null"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<HttpBody<T>> call, Throwable throwable) {
|
||||
onFailure(throwable);
|
||||
}
|
||||
}
|
||||
221
src/main/java/com/yutou/okhttp/HttpLoggingInterceptor.java
Normal file
221
src/main/java/com/yutou/okhttp/HttpLoggingInterceptor.java
Normal file
@@ -0,0 +1,221 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import okhttp3.Connection;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.Protocol;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
import okhttp3.ResponseBody;
|
||||
import okhttp3.internal.http.HttpHeaders;
|
||||
import okio.Buffer;
|
||||
import okio.BufferedSource;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class HttpLoggingInterceptor implements Interceptor {
|
||||
private static final String TAG = "HttpLogging";
|
||||
|
||||
private static final Charset UTF8 = Charset.forName("UTF-8");
|
||||
|
||||
private volatile Level printLevel = Level.NONE;
|
||||
private java.util.logging.Level colorLevel;
|
||||
private Logger logger;
|
||||
|
||||
private static boolean prLog;
|
||||
|
||||
public static void setLog(boolean log) {
|
||||
prLog = log;
|
||||
}
|
||||
|
||||
public enum Level {
|
||||
NONE, //不打印log
|
||||
BASIC, //只打印 请求首行 和 响应首行
|
||||
HEADERS, //打印请求和响应的所有 Header
|
||||
BODY //所有数据全部打印
|
||||
}
|
||||
|
||||
public HttpLoggingInterceptor(String tag) {
|
||||
logger = Logger.getLogger(tag);
|
||||
colorLevel = java.util.logging.Level.INFO;
|
||||
}
|
||||
|
||||
public void setPrintLevel(Level level) {
|
||||
if (printLevel == null)
|
||||
throw new NullPointerException("printLevel == null. Use Level.NONE instead.");
|
||||
printLevel = level;
|
||||
}
|
||||
|
||||
public void setColorLevel(java.util.logging.Level level) {
|
||||
colorLevel = level;
|
||||
}
|
||||
|
||||
private void log(String message) {
|
||||
//logger.log(colorLevel, message);
|
||||
if (prLog) {
|
||||
Log.i(TAG, message);
|
||||
}
|
||||
//Log.e(TAG,message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
if (request.body().contentLength() == 0) {
|
||||
request = chain.call().request();
|
||||
}
|
||||
if (printLevel == Level.NONE) {
|
||||
return chain.proceed(request);
|
||||
}
|
||||
|
||||
//请求日志拦截
|
||||
logForRequest(request, chain.connection());
|
||||
|
||||
//执行请求,计算请求时间
|
||||
long startNs = System.nanoTime();
|
||||
Response response;
|
||||
try {
|
||||
response = chain.proceed(request);
|
||||
} catch (Exception e) {
|
||||
log("<-- HTTP FAILED: " + e);
|
||||
throw e;
|
||||
}
|
||||
long tookMs = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startNs);
|
||||
|
||||
//响应日志拦截
|
||||
return logForResponse(response, tookMs);
|
||||
}
|
||||
|
||||
private void logForRequest(Request request, Connection connection) throws IOException {
|
||||
boolean logBody = (printLevel == Level.BODY);
|
||||
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
|
||||
RequestBody requestBody = request.body();
|
||||
boolean hasRequestBody = requestBody != null;
|
||||
Protocol protocol = connection != null ? connection.protocol() : Protocol.HTTP_1_1;
|
||||
|
||||
try {
|
||||
String requestStartMessage = "--> " + request.method() + ' ' + request.url() + ' ' + protocol;
|
||||
log(requestStartMessage);
|
||||
|
||||
if (logHeaders) {
|
||||
if (hasRequestBody) {
|
||||
// Request body headers are only present when installed as a network interceptor. Force
|
||||
// them to be included (when available) so there values are known.
|
||||
if (requestBody.contentType() != null) {
|
||||
log("\tContent-Type: " + requestBody.contentType());
|
||||
}
|
||||
if (requestBody.contentLength() != -1) {
|
||||
log("\tContent-Length: " + requestBody.contentLength());
|
||||
}
|
||||
}
|
||||
Headers headers = request.headers();
|
||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||
String name = headers.name(i);
|
||||
// Skip headers from the request body as they are explicitly logged above.
|
||||
if (!"Content-Type".equalsIgnoreCase(name) && !"Content-Length".equalsIgnoreCase(name)) {
|
||||
log("\t" + name + ": " + headers.value(i));
|
||||
}
|
||||
}
|
||||
|
||||
log(" ");
|
||||
if (logBody && hasRequestBody) {
|
||||
if (isPlaintext(requestBody.contentType())) {
|
||||
bodyToString(request);
|
||||
} else {
|
||||
log("\tbody: maybe [binary body], omitted!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(java.util.logging.Level.WARNING, e.getMessage(), e);
|
||||
} finally {
|
||||
log("--> END " + request.method());
|
||||
}
|
||||
}
|
||||
|
||||
private Response logForResponse(Response response, long tookMs) {
|
||||
Response.Builder builder = response.newBuilder();
|
||||
Response clone = builder.build();
|
||||
ResponseBody responseBody = clone.body();
|
||||
boolean logBody = (printLevel == Level.BODY);
|
||||
boolean logHeaders = (printLevel == Level.BODY || printLevel == Level.HEADERS);
|
||||
|
||||
try {
|
||||
log("<-- " + clone.code() + ' ' + clone.message() + ' ' + clone.request().url() + " (" + tookMs + "ms)");
|
||||
if (logHeaders) {
|
||||
Headers headers = clone.headers();
|
||||
for (int i = 0, count = headers.size(); i < count; i++) {
|
||||
log("\t" + headers.name(i) + ": " + headers.value(i));
|
||||
}
|
||||
log(" ");
|
||||
if (logBody && HttpHeaders.hasBody(clone)) {
|
||||
if (responseBody == null) return response;
|
||||
|
||||
if (isPlaintext(responseBody.contentType())) {
|
||||
byte[] bytes = responseBody.byteStream().readAllBytes();
|
||||
MediaType contentType = responseBody.contentType();
|
||||
String body = new String(bytes, getCharset(contentType));
|
||||
log("\tbody:" + body);
|
||||
responseBody = ResponseBody.create(responseBody.contentType(), bytes);
|
||||
return response.newBuilder().body(responseBody).build();
|
||||
} else {
|
||||
log("\tbody: maybe [binary body], omitted!");
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(java.util.logging.Level.WARNING, e.getMessage(), e);
|
||||
} finally {
|
||||
log("<-- END HTTP");
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
private static Charset getCharset(MediaType contentType) {
|
||||
Charset charset = contentType != null ? contentType.charset(UTF8) : UTF8;
|
||||
if (charset == null) charset = UTF8;
|
||||
return charset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if the body in question probably contains human readable text. Uses a small sample
|
||||
* of code points to detect unicode control characters commonly used in binary file signatures.
|
||||
*/
|
||||
private static boolean isPlaintext(MediaType mediaType) {
|
||||
if (mediaType == null) return false;
|
||||
if (mediaType.type() != null && mediaType.type().equals("text")) {
|
||||
return true;
|
||||
}
|
||||
String subtype = mediaType.subtype();
|
||||
if (subtype != null) {
|
||||
subtype = subtype.toLowerCase();
|
||||
if (subtype.contains("x-www-form-urlencoded") || subtype.contains("json") || subtype.contains("xml") || subtype.contains("html")) //
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void bodyToString(Request request) {
|
||||
try {
|
||||
Request copy = request.newBuilder().build();
|
||||
RequestBody body = copy.body();
|
||||
if (body == null) return;
|
||||
Buffer buffer = new Buffer();
|
||||
body.writeTo(buffer);
|
||||
Charset charset = getCharset(body.contentType());
|
||||
log("\tbody:" + buffer.readString(charset));
|
||||
} catch (Exception e) {
|
||||
logger.log(java.util.logging.Level.WARNING, e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/main/java/com/yutou/okhttp/IRequestParam.java
Normal file
9
src/main/java/com/yutou/okhttp/IRequestParam.java
Normal file
@@ -0,0 +1,9 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public interface IRequestParam {
|
||||
Request getRequest(HashMap<String,String> map, Request request);
|
||||
}
|
||||
31
src/main/java/com/yutou/okhttp/ParamsContext.java
Normal file
31
src/main/java/com/yutou/okhttp/ParamsContext.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
import okhttp3.Request;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ParamsContext {
|
||||
private IRequestParam iRequestParam;
|
||||
private Request request;
|
||||
private HashMap<String,String> map;
|
||||
|
||||
public ParamsContext(HashMap<String,String> map,Request request) {
|
||||
if(map==null){
|
||||
map=new HashMap<>();
|
||||
}
|
||||
this.map=map;
|
||||
this.request = request;
|
||||
}
|
||||
|
||||
public Request getInRequest() {
|
||||
switch (request.method()) {
|
||||
case "GET":
|
||||
iRequestParam = new GetRequestParams();
|
||||
break;
|
||||
case "POST":
|
||||
iRequestParam = new PostRequestParams();
|
||||
break;
|
||||
}
|
||||
return iRequestParam.getRequest(map,request);
|
||||
}
|
||||
}
|
||||
68
src/main/java/com/yutou/okhttp/PostRequestParams.java
Normal file
68
src/main/java/com/yutou/okhttp/PostRequestParams.java
Normal file
@@ -0,0 +1,68 @@
|
||||
package com.yutou.okhttp;
|
||||
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import okhttp3.*;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
public class PostRequestParams implements IRequestParam {
|
||||
@Override
|
||||
public Request getRequest(HashMap<String, String> map, Request request) {
|
||||
if (request.body() instanceof FormBody) {
|
||||
FormBody.Builder bodyBuilder = new FormBody.Builder();
|
||||
FormBody formBody = (FormBody) request.body();
|
||||
|
||||
for (int i = 0; i < formBody.size(); i++) {
|
||||
bodyBuilder.addEncoded(formBody.encodedName(i), formBody.encodedValue(i));
|
||||
}
|
||||
for (String key : map.keySet()) {
|
||||
bodyBuilder.addEncoded(key, String.valueOf(map.get(key)));
|
||||
}
|
||||
formBody = bodyBuilder.build();
|
||||
request = request.newBuilder().post(formBody).build();
|
||||
} else if (request.body() != null) {
|
||||
RequestBody requestBody = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),toUrlParams(map));
|
||||
request = request.newBuilder().post(request.body())
|
||||
.post(requestBody).build();
|
||||
}
|
||||
return request;
|
||||
}
|
||||
|
||||
public static String toUrlParams(JSONObject json) {
|
||||
StringBuilder string = new StringBuilder();
|
||||
Set<String> keys = json.keySet();
|
||||
for (String key : keys) {
|
||||
try {
|
||||
string.append("&").append(key).append("=").append(URLEncoder.encode(json.getString(key), "UTF-8"));
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
try {
|
||||
string.append("&").append(URLEncoder.encode(key,"UTF-8")).append("=");
|
||||
// string += "&" + key + "=";
|
||||
} catch (Exception e1) {
|
||||
string.append("&").append(key).append("=");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string = new StringBuilder(string.substring(1, string.length()).replaceAll(" ", ""));
|
||||
return string.toString();
|
||||
}
|
||||
|
||||
public static String toUrlParams(Map<String, String> map) {
|
||||
if(map.isEmpty()){
|
||||
return "";
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
98
src/main/java/com/yutou/okhttp/api/BaseApi.java
Normal file
98
src/main/java/com/yutou/okhttp/api/BaseApi.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.yutou.okhttp.api;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.internal.bind.DateTypeAdapter;
|
||||
import com.yutou.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.okhttp.ParamsContext;
|
||||
import com.yutou.okhttp.converter.JsonCallAdapter;
|
||||
import com.yutou.okhttp.converter.JsonConverterFactory;
|
||||
import okhttp3.Interceptor;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Converter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.logging.Level;
|
||||
|
||||
public class BaseApi {
|
||||
private String URL;
|
||||
private HashMap<String, String> params;
|
||||
|
||||
public BaseApi setURL(String URL) {
|
||||
this.URL = URL;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BaseApi setParams(HashMap<String, String> params) {
|
||||
this.params = params;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建一个接口方法
|
||||
*
|
||||
* @param okHttpClient okhttp客户端
|
||||
* @param converterFactory 处理工厂类
|
||||
* @param callAdapterFactory 请求适配器工厂
|
||||
* @param baseUrl 基础地质
|
||||
* @param service 接口
|
||||
* @param <T> 接口泛型
|
||||
* @return 接口
|
||||
*/
|
||||
public <T> T create(OkHttpClient okHttpClient, Converter.Factory converterFactory, CallAdapter.Factory callAdapterFactory, String baseUrl, Class<T> service) {
|
||||
Retrofit.Builder builder = new Retrofit.Builder()
|
||||
//基础url
|
||||
.baseUrl(baseUrl)
|
||||
//客户端OKHttp
|
||||
.client(okHttpClient);
|
||||
//添加转换工厂
|
||||
if (null != converterFactory) {
|
||||
builder.addConverterFactory(converterFactory);
|
||||
}
|
||||
//添加请求工厂
|
||||
if (null != callAdapterFactory) {
|
||||
builder.addCallAdapterFactory(callAdapterFactory);
|
||||
}
|
||||
//创建retrofit对象
|
||||
Retrofit retrofit = builder.build();
|
||||
|
||||
//返回创建的api
|
||||
return retrofit.create(service);
|
||||
}
|
||||
|
||||
public <T> T createApi(Class<T> apiClass) {
|
||||
Gson gson = new GsonBuilder()
|
||||
.registerTypeAdapter(Date.class, new DateTypeAdapter())
|
||||
.create();
|
||||
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor("http");
|
||||
loggingInterceptor.setPrintLevel(HttpLoggingInterceptor.Level.BODY);
|
||||
OkHttpClient.Builder builder = new OkHttpClient()
|
||||
.newBuilder()
|
||||
|
||||
.addInterceptor(initQuery())
|
||||
.addInterceptor(loggingInterceptor);
|
||||
return create(builder.build(),
|
||||
JsonConverterFactory.create(gson),
|
||||
JsonCallAdapter.create(),
|
||||
URL,
|
||||
apiClass);
|
||||
}
|
||||
public Interceptor initQuery() {
|
||||
Interceptor addQueryParameterInterceptor = new Interceptor() {
|
||||
@Override
|
||||
public Response intercept(Chain chain) throws IOException {
|
||||
Request request = chain.request();
|
||||
//配置公共参数
|
||||
request = new ParamsContext(params,request).getInRequest();
|
||||
return chain.proceed(request);
|
||||
}
|
||||
};
|
||||
return addQueryParameterInterceptor;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yutou.okhttp.converter;
|
||||
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.CallAdapter;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonCallAdapter extends CallAdapter.Factory{
|
||||
public static JsonCallAdapter create(){
|
||||
return new JsonCallAdapter();
|
||||
}
|
||||
@Nullable
|
||||
@Override
|
||||
public CallAdapter<?, ?> get(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package com.yutou.okhttp.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import retrofit2.Converter;
|
||||
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.Retrofit;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonConverterFactory extends Converter.Factory {
|
||||
Gson gson;
|
||||
public static JsonConverterFactory create(Gson gson) {
|
||||
return new JsonConverterFactory(gson);
|
||||
}
|
||||
|
||||
private JsonConverterFactory(Gson gson) {
|
||||
this.gson = gson;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Converter<?, RequestBody> requestBodyConverter(Type type, Annotation[] parameterAnnotations, Annotation[] methodAnnotations, Retrofit retrofit) {
|
||||
// return super.requestBodyConverter(type, parameterAnnotations, methodAnnotations, retrofit);
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new JsonRequestBodyConverter<>(gson,adapter);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Converter<ResponseBody, ?> responseBodyConverter(Type type, Annotation[] annotations, Retrofit retrofit) {
|
||||
// return super.responseBodyConverter(type, annotations, retrofit);
|
||||
TypeAdapter<?> adapter = gson.getAdapter(TypeToken.get(type));
|
||||
return new JsonResponseBodyConverter<>(gson,adapter,type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.yutou.okhttp.converter;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.RequestBody;
|
||||
import okio.Buffer;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.Converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStreamWriter;
|
||||
import java.io.Writer;
|
||||
import java.nio.charset.Charset;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
public class JsonRequestBodyConverter<T> implements Converter<T, RequestBody> {
|
||||
Gson gson;
|
||||
TypeAdapter<T> adapter;
|
||||
public JsonRequestBodyConverter(Gson gson, TypeAdapter<T> adapter) {
|
||||
this.gson=gson;
|
||||
this.adapter=adapter;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public RequestBody convert(T value) throws IOException {
|
||||
Buffer buffer = new Buffer();
|
||||
Writer writer = new OutputStreamWriter(buffer.outputStream(), StandardCharsets.UTF_8);
|
||||
JsonWriter jsonWriter = gson.newJsonWriter(writer);
|
||||
adapter.write(jsonWriter, value);
|
||||
jsonWriter.close();
|
||||
byte[] bytes = buffer.readByteArray();
|
||||
return RequestBody.create(MediaType.parse("application/json; charset=UTF-8"),bytes );
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
package com.yutou.okhttp.converter;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.TypeAdapter;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import okhttp3.ResponseBody;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import retrofit2.Converter;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
public class JsonResponseBodyConverter<T> implements Converter<ResponseBody, T> {
|
||||
Gson gson;
|
||||
TypeAdapter<?> adapter;
|
||||
Type type;
|
||||
|
||||
public JsonResponseBodyConverter(Gson gson, TypeAdapter<?> adapter, Type type) {
|
||||
this.gson = gson;
|
||||
this.adapter = adapter;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public T convert(ResponseBody responseBody) throws IOException {
|
||||
String string = new String(responseBody.bytes());
|
||||
responseBody.close();
|
||||
HttpBody<T> body;
|
||||
try {
|
||||
body = JSONObject.parseObject(string, type);
|
||||
body.setSrc(string);
|
||||
return (T) body;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
body = new HttpBody();
|
||||
body.setSrc(string);
|
||||
}
|
||||
return (T) body;
|
||||
|
||||
}
|
||||
}
|
||||
122
src/main/java/com/yutou/qqbot/Controllers/AppController.java
Normal file
122
src/main/java/com/yutou/qqbot/Controllers/AppController.java
Normal file
@@ -0,0 +1,122 @@
|
||||
package com.yutou.qqbot.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.handle.At;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.napcat.handle.Image;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.napcat.model.SendMessageResponse;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
public class AppController {
|
||||
@RequestMapping("/restart.do")
|
||||
@ResponseBody
|
||||
public String restart() {
|
||||
AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh", null, true, false);
|
||||
return "";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/door/set.do")
|
||||
public String openDoor(String status) {
|
||||
RedisTools.set("door", status);
|
||||
return "1";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/door/get.do")
|
||||
public String getDoor() {
|
||||
if ("open".equals(RedisTools.get("door"))) {
|
||||
RedisTools.set("door", "on");
|
||||
return "1";
|
||||
}
|
||||
return "0";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/door/status.do")
|
||||
public String getStatus() {
|
||||
String status = RedisTools.get("door");
|
||||
if ("open".equals(status)) {
|
||||
return "0";
|
||||
} else if ("on".equals(status)) {
|
||||
return "2";
|
||||
} else if ("over".equals(status)) {
|
||||
RedisTools.set("door", "ready");
|
||||
return "1";
|
||||
}
|
||||
return "-1";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/qq/send.do")
|
||||
public String sendQQ(@RequestBody JSONObject json) {
|
||||
File image = null;
|
||||
if (json.getString("message").isEmpty()) {
|
||||
return "not message";
|
||||
}
|
||||
List<BaseHandle<?>> list=new ArrayList<>();
|
||||
list.add(new Text(json.getString("message")));
|
||||
if(json.getString("image")!=null&&!json.getString("image").isEmpty()){
|
||||
list.add(new Image(json.getString("image")));
|
||||
}
|
||||
SendMessageResponse sent = QQBotManager.getInstance().sendMessage(QQDatabase.checkFriend(json.getLong("qq")),
|
||||
json.getLong("qq"),
|
||||
list
|
||||
);
|
||||
return sent == null ? "0" : sent.getId() + "";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/qq/file.do")
|
||||
public String sendFile(@RequestParam("image") MultipartFile file) throws Exception {
|
||||
String path = AppTools.createFile("tmp", file, System.currentTimeMillis() + ".png");
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
return "not file";
|
||||
}
|
||||
File _file = new File(path);
|
||||
QQBotManager.getInstance().sendMessage(_file, 583819556L, "time = " + AppTools.getToDayNowTimeToString());
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@RequestMapping("/test.do")
|
||||
@ResponseBody
|
||||
public String test(HttpServletResponse response) {
|
||||
System.out.println("NAS自动关机");
|
||||
/* try {
|
||||
response.sendRedirect("http://192.168.31.88:9999/live/index.m3u8");
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}*/
|
||||
// return HttpTools.http_get("http://192.168.31.88:9999/live/index.m3u8",null);
|
||||
return "1";
|
||||
}
|
||||
|
||||
@RequestMapping("*.ts")
|
||||
public void test2(HttpServletResponse response, HttpServletRequest request) {
|
||||
try {
|
||||
response.sendRedirect("http://192.168.31.88:9999/live" + request.getRequestURI());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
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;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
public class BiliBiliController {
|
||||
@RequestMapping("/bilibili/down.do")
|
||||
@ResponseBody
|
||||
public JSONObject downloadBili(String data) {
|
||||
new Thread(() -> {
|
||||
JSONObject json = JSONObject.parseObject(data);
|
||||
System.out.println("json = " + json);
|
||||
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(QQBotManager.defQQ);
|
||||
video.downVideo(url, downDanmu, merge);
|
||||
}
|
||||
).start();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("msg", "ok");
|
||||
json.put("code", 0);
|
||||
return json;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,240 @@
|
||||
package com.yutou.qqbot.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.data.jianr.AndroidDevice;
|
||||
import com.yutou.qqbot.data.jianr.JianRScriptV2Data;
|
||||
import com.yutou.qqbot.utlis.JianRTaskManager;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@Controller
|
||||
public class JianRScriptController {
|
||||
@RequestMapping("/jianr/run.do")
|
||||
@ResponseBody
|
||||
public JSONObject runScript(String task, String device, String modelName) {
|
||||
JSONObject json = new JSONObject();
|
||||
String data = RedisTools.getHashMap(JianRTaskManager.Redis_Script, task);
|
||||
String deviceJsonString = RedisTools.getHashMap(JianRTaskManager.Redis_Device, 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(modelName)) {
|
||||
manager.setModelId(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
manager.setTask(script, androidDevice);
|
||||
manager.start();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务创建成功");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/stop.do")
|
||||
@ResponseBody
|
||||
public JSONObject stop() {
|
||||
JianRTaskManager.getInstance().stop();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务已停止");
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/status.do")
|
||||
@ResponseBody
|
||||
public JSONObject status() {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject data = new JSONObject();
|
||||
JianRTaskManager manager = JianRTaskManager.getInstance();
|
||||
data.put("status", manager.isRunning());
|
||||
data.put("runIndex", manager.getRunIndex());
|
||||
data.put("taskName", manager.getTaskName());
|
||||
data.put("log", manager.getLog());
|
||||
json.put("code", 0);
|
||||
json.put("data", data);
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/task/list.do")
|
||||
@ResponseBody
|
||||
public JSONObject tasks() {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
Map<String, String> map = RedisTools.getHashMap(JianRTaskManager.Redis_Script);
|
||||
array.addAll(map.keySet());
|
||||
json.put("code", 0);
|
||||
json.put("data", array);
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/task/add.do")
|
||||
@ResponseBody
|
||||
public JSONObject addTask(String task) {
|
||||
JSONObject json = new JSONObject();
|
||||
JSONObject data = JSON.parseObject(task);
|
||||
if (data == null) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
String taskName = data.getString("title");
|
||||
if (RedisTools.getHashMap(JianRTaskManager.Redis_Script).containsKey(taskName)) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "该任务名称已存在");
|
||||
} else {
|
||||
RedisTools.setHashMap(JianRTaskManager.Redis_Script, taskName, task);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务创建成功");
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/task/get.do")
|
||||
@ResponseBody
|
||||
public JSONObject getTask(String task) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("data", RedisTools.getHashMap(JianRTaskManager.Redis_Script, task));
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/task/remove.do")
|
||||
@ResponseBody
|
||||
public JSONObject removeTask(String task) {
|
||||
RedisTools.removeHashMap(JianRTaskManager.Redis_Script, task);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务删除成功");
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/connect.do")
|
||||
@ResponseBody
|
||||
public JSONObject connectDevice(String device) {
|
||||
JSONObject json = new JSONObject();
|
||||
JianRTaskManager.getInstance().connect(device);
|
||||
json.put("code", 0);
|
||||
json.put("msg", "成功");
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/add.do")
|
||||
@ResponseBody
|
||||
public JSONObject addDevice(String device) {
|
||||
Map<String, String> hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device);
|
||||
JSONObject deviceJson = JSON.parseObject(device);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (deviceJson == null) {
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
if (hashMap.containsKey(device)) {
|
||||
json.put("msg", "设备已存在");
|
||||
} else {
|
||||
json.put("msg", RedisTools.setHashMap(JianRTaskManager.Redis_Device,
|
||||
deviceJson.getString("title"), device) ?
|
||||
"设备添加成功" : "设备添加失败");
|
||||
}
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/edit.do")
|
||||
@ResponseBody
|
||||
public JSONObject editDevice(String device, String oldDevice) {
|
||||
JSONObject deviceJson = JSON.parseObject(device);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (deviceJson == null) {
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
RedisTools.removeHashMap(JianRTaskManager.Redis_Device, oldDevice);
|
||||
json.put("msg", RedisTools.setHashMap(JianRTaskManager.Redis_Device,
|
||||
deviceJson.getString("title"), device) ?
|
||||
"设备修改成功" : "设备修改失败");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/del.do")
|
||||
@ResponseBody
|
||||
public JSONObject delDevice(String device) {
|
||||
JSONObject deviceJson = JSON.parseObject(device);
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("code", 0);
|
||||
if (deviceJson == null) {
|
||||
json.put("msg", "JSON格式错误");
|
||||
} else {
|
||||
json.put("msg", RedisTools.removeHashMap(JianRTaskManager.Redis_Device) ?
|
||||
"设备修改成功" : "设备修改失败");
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@RequestMapping("/jianr/device/list.do")
|
||||
@ResponseBody
|
||||
public JSONObject getDeviceList() {
|
||||
Map<String, String> hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device);
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
json.put("code", 0);
|
||||
hashMap.keySet().forEach(key -> {
|
||||
JSONObject device = JSONObject.parseObject(hashMap.get(key));
|
||||
JSONArray child = new JSONArray();
|
||||
JSONObject item = new JSONObject();
|
||||
JSONObject del = new JSONObject();
|
||||
JSONObject edit = new JSONObject();
|
||||
JSONObject select = new JSONObject();
|
||||
JSONObject connect = new JSONObject();
|
||||
item.put("title", key);
|
||||
del.put("title", "删除");
|
||||
del.put("data", "del");
|
||||
del.put("device", device);
|
||||
edit.put("title", "编辑");
|
||||
edit.put("data", "edit");
|
||||
edit.put("device", device);
|
||||
select.put("title", "选择");
|
||||
select.put("data", "select");
|
||||
select.put("device", device);
|
||||
connect.put("title", "连接设备");
|
||||
connect.put("data", "connect");
|
||||
connect.put("device", device);
|
||||
child.add(connect);
|
||||
child.add(select);
|
||||
child.add(del);
|
||||
child.add(edit);
|
||||
item.put("child", child);
|
||||
array.add(item);
|
||||
});
|
||||
json.put("data", array);
|
||||
return json;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Map<String, String> hashMap = RedisTools.getHashMap(JianRTaskManager.Redis_Device);
|
||||
JSONObject json = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
json.put("code", 0);
|
||||
hashMap.keySet().forEach(key -> {
|
||||
JSONObject item = JSONObject.parseObject(hashMap.get(key));
|
||||
array.add(item);
|
||||
});
|
||||
json.put("data", array);
|
||||
System.out.println(json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,79 @@
|
||||
package com.yutou.qqbot.Controllers;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.models.XiaoMi.MiRouter;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.qqbot.utlis.XiaoMiRouter;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/router/")
|
||||
public class MiRouterDevices {
|
||||
@RequestMapping("device/add.do")
|
||||
@ResponseBody
|
||||
public String addDevice(HttpServletRequest request,String qq) {
|
||||
String data = RedisTools.get(MiRouter.redis_key);
|
||||
JSONArray array;
|
||||
if (data == null) {
|
||||
array = new JSONArray();
|
||||
} else {
|
||||
array = JSON.parseArray(data);
|
||||
}
|
||||
for (Object o : array) {
|
||||
JSONObject item = (JSONObject) o;
|
||||
if (item.getString("mac").equals(getRemoteAddress(request.getRemoteAddr()))) {
|
||||
return "已经添加过了";
|
||||
}
|
||||
}
|
||||
JSONObject item=new JSONObject();
|
||||
item.put("qq",qq);
|
||||
item.put("mac",getRemoteAddress(request.getRemoteAddr()));
|
||||
item.put("online",false);
|
||||
array.add(item);
|
||||
RedisTools.set(MiRouter.redis_key,array.toString());
|
||||
return "添加成功,关闭当前页面即可";
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("device/del.do")
|
||||
public String delDevice(HttpServletRequest request,String qq){
|
||||
String data = RedisTools.get(MiRouter.redis_key);
|
||||
JSONArray array;
|
||||
if (data == null) {
|
||||
array = new JSONArray();
|
||||
} else {
|
||||
array = JSON.parseArray(data);
|
||||
}
|
||||
JSONArray _array= JSON.parseArray(array.toString());
|
||||
for (Object o : array) {
|
||||
JSONObject item = (JSONObject) o;
|
||||
if (item.getString("mac").equals(getRemoteAddress(request.getRemoteAddr()))) {
|
||||
_array.remove(item);
|
||||
RedisTools.set(MiRouter.redis_key,_array.toString());
|
||||
return "已成功删除";
|
||||
}
|
||||
}
|
||||
return "未找到该设备";
|
||||
}
|
||||
|
||||
private String getRemoteAddress(String ip) {
|
||||
JSONObject data = JSON.parseObject(HttpTools.get(XiaoMiRouter.getInstance().getDeviceListUrl()));
|
||||
if (data.getInteger("code") == 0) {
|
||||
JSONArray array=data.getJSONArray("list");
|
||||
for (Object o : array) {
|
||||
JSONObject item= (JSONObject) o;
|
||||
if(item.getJSONArray("ip").getJSONObject(0).getString("ip").equals(ip)){
|
||||
return item.getString("mac");
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,27 +3,20 @@ package com.yutou.qqbot.Listeners;
|
||||
import com.yutou.qqbot.MessageEvent.AdminMessage;
|
||||
import com.yutou.qqbot.QQNumberManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import kotlin.coroutines.CoroutineContext;
|
||||
import net.mamoe.mirai.event.EventHandler;
|
||||
import net.mamoe.mirai.event.ListeningStatus;
|
||||
import net.mamoe.mirai.event.SimpleListenerHost;
|
||||
import net.mamoe.mirai.event.events.GroupMessageEvent;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class QQMessageListener extends SimpleListenerHost {
|
||||
public class QQMessageListener {
|
||||
|
||||
|
||||
@Override
|
||||
public void handleException(@NotNull CoroutineContext context, @NotNull Throwable exception) {
|
||||
// super.handleException(context, exception);
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public ListeningStatus onMessage(MessageEvent event) {
|
||||
long qqNumber;
|
||||
public void onMessage() {
|
||||
/* long qqNumber;
|
||||
boolean isGroup;
|
||||
if (event instanceof GroupMessageEvent) {
|
||||
qqNumber = ((GroupMessageEvent) event).getGroup().getId();
|
||||
@@ -52,7 +45,7 @@ public class QQMessageListener extends SimpleListenerHost {
|
||||
}
|
||||
}
|
||||
|
||||
return ListeningStatus.LISTENING; // 表示继续监听事件
|
||||
return ListeningStatus.LISTENING; // 表示继续监听事件*/
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,15 @@ import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.QQNumberManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.models.WebSign.BaiHeHui;
|
||||
import com.yutou.qqbot.models.WebSign.NicePT;
|
||||
import com.yutou.qqbot.models.WebSign.Tsdm;
|
||||
import com.yutou.qqbot.models.WebSign.ZhuZhu;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import com.yutou.qqbot.utlis.WebClient;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.List;
|
||||
|
||||
public class AdminMessage extends Message {
|
||||
@@ -21,13 +25,16 @@ public class AdminMessage extends Message {
|
||||
private static final String MODEL_SHOW = "!查看模块";
|
||||
private static final String MODEL_DEL = "!删除模块";
|
||||
|
||||
public static final String SYSTEM_RESTART_QQ="!重启qq";
|
||||
public static final String SYSTEM_RESTART_TOOLS="!重启服务";
|
||||
public static final String SYSTEM_RESTART_QQ = "!重启qq";
|
||||
public static final String SYSTEM_RESTART_TOOLS = "!重启服务";
|
||||
|
||||
public static final String SYSTEM_UPDATE_QQ = "!更新qq";
|
||||
public static final String SYSTEM_UPDATE_NAS = "!更新服务";
|
||||
|
||||
|
||||
private static final String SHOW="!列表";
|
||||
private static final String HELP="!help";
|
||||
private static final String SIGN="!签到";
|
||||
private static final String SHOW = "!列表";
|
||||
private static final String HELP = "!help";
|
||||
private static final String SIGN = "!签到";
|
||||
}
|
||||
|
||||
public AdminMessage(Long qq, String msg) {
|
||||
@@ -35,7 +42,7 @@ public class AdminMessage extends Message {
|
||||
String[] msgGroup = msg.replace("!", "!").split(" ");
|
||||
|
||||
switch (msgGroup[0]) {
|
||||
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq,Model.getCommands(QQCommands.class).toString());
|
||||
case QQCommands.HELP -> QQBotManager.getInstance().sendMessage(qq, Model.getCommands(QQCommands.class).toString());
|
||||
case QQCommands.POWER_ADD -> {
|
||||
if (msgGroup.length == 1) {
|
||||
StringBuilder builder = Model.getCommands(Model.QQGroupCommands.class);
|
||||
@@ -78,6 +85,12 @@ public class AdminMessage extends Message {
|
||||
if (msgGroup.length == 1) {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Class<?> aClass : Model.classList) {
|
||||
try {
|
||||
Model model = (Model) aClass.getDeclaredConstructor().newInstance();
|
||||
builder.append("[").append(model.getModelName()).append("]");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
builder.append(aClass.getName()).append("\n");
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "使用方法:" + QQCommands.MODEL_ADD + " [qqnumber] 模块" + "\n" + "可设置以下模块,用&分割");
|
||||
@@ -86,7 +99,11 @@ public class AdminMessage extends Message {
|
||||
if (msgGroup.length <= 2) {
|
||||
addModel(msgGroup[1], null);
|
||||
} else {
|
||||
addModel(msgGroup[1], msgGroup[2]);
|
||||
if ("this".equals(msgGroup[1])) {
|
||||
addModel(sendQQ + "", msgGroup[2]);
|
||||
} else {
|
||||
addModel(msgGroup[1], msgGroup[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,74 +111,132 @@ public class AdminMessage extends Message {
|
||||
if (msgGroup.length == 1) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "使用方法:" + QQCommands.MODEL_SHOW + " [qqnumber]");
|
||||
} else {
|
||||
List<String> list = QQNumberManager.getManager().getUseModel(Long.parseLong(msgGroup[1]));
|
||||
String qqGroup = msgGroup[1];
|
||||
if ("this".equals(qqGroup)) {
|
||||
qqGroup = sendQQ + "";
|
||||
}
|
||||
List<String> list = QQNumberManager.getManager().getUseModel(Long.parseLong(qqGroup));
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (String power : list) {
|
||||
builder.append(power).append("\n");
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, Long.parseLong(msgGroup[1]) + " 拥有以下模块:" + builder);
|
||||
QQBotManager.getInstance().sendMessage(qq, Long.parseLong(qqGroup) + " 拥有以下模块:" + builder);
|
||||
}
|
||||
}
|
||||
case QQCommands.MODEL_DEL -> {
|
||||
if (msgGroup.length == 1) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "使用方法:" + QQCommands.MODEL_DEL + " [qqnumber] 模块 用&分割");
|
||||
} else {
|
||||
String qqGroup = msgGroup[1];
|
||||
if ("this".equals(qqGroup)) {
|
||||
qqGroup = sendQQ + "";
|
||||
}
|
||||
if (msgGroup.length <= 2) {
|
||||
delModel(msgGroup[1], null);
|
||||
delModel(qqGroup, null);
|
||||
} else {
|
||||
delModel(msgGroup[1], msgGroup[2]);
|
||||
delModel(qqGroup, msgGroup[2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
case QQCommands.SHOW -> {
|
||||
List<Long> users=QQNumberManager.getManager().getNumber();
|
||||
StringBuilder builder=new StringBuilder();
|
||||
List<Long> users = QQNumberManager.getManager().getNumber();
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (Long user : users) {
|
||||
builder.append(user).append(":\n");
|
||||
List<String> modelPower=QQNumberManager.getManager().getUseModel(user);
|
||||
List<String> modelPower = QQNumberManager.getManager().getUseModel(user);
|
||||
builder.append("模块(").append(modelPower.size()).append("):\n");
|
||||
for (String model : modelPower) {
|
||||
builder.append(model).append("\n");
|
||||
}
|
||||
List<String> list=QQNumberManager.getManager().getPower(user);
|
||||
List<String> list = QQNumberManager.getManager().getPower(user);
|
||||
builder.append("权限(").append(list.size()).append("):\n");
|
||||
for (String power : list) {
|
||||
builder.append(power).append("\n");
|
||||
}
|
||||
builder.append("\n");
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq,builder.toString());
|
||||
QQBotManager.getInstance().sendMessage(qq, builder.toString());
|
||||
}
|
||||
case QQCommands.SYSTEM_RESTART_QQ -> {
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在重启机器人");
|
||||
QQBotManager.getInstance().sendMessage(qq, "正在重启机器人");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh",null,true,false);
|
||||
AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh", null, true, false);
|
||||
}
|
||||
case QQCommands.SYSTEM_RESTART_TOOLS ->{
|
||||
QQBotManager.getInstance().sendMessage(qq,"正在重启服务");
|
||||
case QQCommands.SYSTEM_RESTART_TOOLS -> {
|
||||
QQBotManager.getInstance().sendMessage(qq, "正在重启服务");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh",null,true,false);
|
||||
AppTools.exec("cd /home/yutou/public/servier/tools && ./start.sh", null, true, false);
|
||||
}
|
||||
case QQCommands.SYSTEM_UPDATE_QQ -> {
|
||||
QQBotManager.getInstance().sendMessage(qq, "正在更新qq");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/git/QQBot && ./update.sh", null, true, false);
|
||||
}
|
||||
case QQCommands.SYSTEM_UPDATE_NAS -> {
|
||||
QQBotManager.getInstance().sendMessage(qq, "正在更新NAS服务");
|
||||
System.out.println("结束进程");
|
||||
AppTools.exec("cd /home/yutou/git/nas-service && ./update.sh", null, true, false);
|
||||
}
|
||||
|
||||
case QQCommands.SIGN -> {
|
||||
boolean sign=true;
|
||||
boolean sign = true;
|
||||
boolean tsdmSign = false, baiheSign = false, nicePtSign = false, zhuzhuSign=false;
|
||||
Log.i("开始签到");
|
||||
try{
|
||||
new Tsdm().tsdmSign();
|
||||
}catch (Exception e){
|
||||
sign=false;
|
||||
QQBotManager.getInstance().sendMessage(qq,"tsdm签到失败:"+AppTools.getExceptionString(e));
|
||||
try {
|
||||
if (new Tsdm().tsdmSign()) {
|
||||
tsdmSign = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sign = false;
|
||||
QQBotManager.getInstance().sendMessage(qq, "tsdm签到失败:" + AppTools.getExceptionString(e));
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
new BaiHeHui().sign();
|
||||
}catch (Exception e){
|
||||
sign=false;
|
||||
QQBotManager.getInstance().sendMessage(qq,"百合会签到失败:"+AppTools.getExceptionString(e));
|
||||
if (new BaiHeHui().sign()) {
|
||||
baiheSign = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sign = false;
|
||||
QQBotManager.getInstance().sendMessage(qq, "百合会签到失败:" + AppTools.getExceptionString(e));
|
||||
e.printStackTrace();
|
||||
}
|
||||
if(sign){
|
||||
QQBotManager.getInstance().sendMessage(qq,"签到任务完成");
|
||||
try {
|
||||
if (new NicePT().sign()) {
|
||||
nicePtSign = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sign = false;
|
||||
QQBotManager.getInstance().sendMessage(qq, "NicePT签到失败:" + AppTools.getExceptionString(e));
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
if (new ZhuZhu().sign()) {
|
||||
zhuzhuSign = true;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
sign = false;
|
||||
QQBotManager.getInstance().sendMessage(qq, "HiRes花园签到失败:" + AppTools.getExceptionString(e));
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (sign && tsdmSign && baiheSign && nicePtSign) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "签到任务完成");
|
||||
}else{
|
||||
StringBuilder builder=new StringBuilder();
|
||||
if(!tsdmSign){
|
||||
builder.append("天使动漫签到失败\n");
|
||||
}
|
||||
if(!baiheSign){
|
||||
builder.append("百合会签到失败\n");
|
||||
}
|
||||
if(!nicePtSign){
|
||||
builder.append("NicePT签到失败\n");
|
||||
}
|
||||
if(!zhuzhuSign){
|
||||
builder.append("HiRes花园签到失败\n");
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq,builder.toString());
|
||||
}
|
||||
WebClient.getInstance().quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,20 +293,22 @@ public class AdminMessage extends Message {
|
||||
}
|
||||
|
||||
private void delModel(String qq, String model) {
|
||||
boolean flag = false;
|
||||
try {
|
||||
if (model == null) {
|
||||
List<String> list = QQNumberManager.getManager().getUseModel(Long.parseLong(qq));
|
||||
for (String power : list) {
|
||||
QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power));
|
||||
flag = QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power));
|
||||
}
|
||||
} else {
|
||||
for (String power : model.split("&")) {
|
||||
QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power));
|
||||
flag = QQNumberManager.getManager().delUseModel(Long.parseLong(qq), Class.forName(power));
|
||||
}
|
||||
}
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, flag ? "删除成功" : "删除失败");
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,26 @@
|
||||
package com.yutou.qqbot;
|
||||
|
||||
import com.yutou.napcat.http.NapCatApi;
|
||||
import com.yutou.okhttp.HttpLoggingInterceptor;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import lombok.val;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class QQBotApplication {
|
||||
public static final String version="QQBot v.1.1.2";
|
||||
public static final String version = "QQBot v.1.7.8";
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println("version = " + version);
|
||||
SpringApplication.run(QQBotApplication.class, args);
|
||||
NapCatApi.setLog(true);
|
||||
RedisTools.initRedisPoolSub();
|
||||
QQBotManager.getInstance();
|
||||
val log = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_LOG, Boolean.class);
|
||||
NapCatApi.setLog(log);
|
||||
//1
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,27 @@
|
||||
package com.yutou.qqbot;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.enums.MessageEnum;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.napcat.handle.OtherHandle;
|
||||
import com.yutou.qqbot.MessageEvent.AdminMessage;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.qqbot.utlis.XiaoMiRouter;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Set;
|
||||
|
||||
@Controller
|
||||
public class QQBotController {
|
||||
@@ -33,4 +47,58 @@ public class QQBotController {
|
||||
AppTools.sendServer(title, msg);
|
||||
return "ok";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/napcat/qq/bot.do")
|
||||
public String qq_bot(HttpServletRequest request, HttpServletResponse response) {
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
try {
|
||||
BufferedInputStream stream = new BufferedInputStream(request.getInputStream());
|
||||
byte[] bytes = new byte[1024];
|
||||
int len = 0, size;
|
||||
while ((len = stream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
outputStream.flush();
|
||||
}
|
||||
String str = outputStream.toString(StandardCharsets.UTF_8);
|
||||
MessageEvent event = MessageEvent.parseHandle(str);
|
||||
|
||||
long qqNumber = event.isGroup() ? event.getGroupId() : event.getUserId();
|
||||
boolean isGroup = event.isGroup();
|
||||
|
||||
if ((event.isGroup() && event.getSource().getUserId() == 583819556L) || (!event.isGroup() && event.getUserId() == 583819556L)) {
|
||||
new AdminMessage(qqNumber, event.getRawMessage());
|
||||
}
|
||||
for (Class<?> model : Model.classList) {
|
||||
if (QQNumberManager.getManager().isUseModel(qqNumber, model) || !isGroup) {
|
||||
try {
|
||||
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
|
||||
if (!useModel.isUserPublic()) {
|
||||
if (!QQNumberManager.getManager().isExistsPower(event.getSource().getFromId(), useModel.getUsePowers())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
useModel.onMessage(qqNumber, event, isGroup);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "200";
|
||||
}
|
||||
|
||||
@ResponseBody
|
||||
@RequestMapping("/router/wan1ip.do")
|
||||
public String getWan1IP(){
|
||||
return XiaoMiRouter.getInstance().getWan1IPAddress();
|
||||
}
|
||||
@ResponseBody
|
||||
@RequestMapping("/router/wan2ip.do")
|
||||
public String getWan2IP(){
|
||||
return XiaoMiRouter.getInstance().getWan2IPAddress();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,35 @@
|
||||
package com.yutou.qqbot;
|
||||
|
||||
import com.yutou.qqbot.Listeners.QQMessageListener;
|
||||
import com.yutou.qqbot.models.Animal.TurnipProphet;
|
||||
import com.yutou.qqbot.models.Commands.BaiduDown;
|
||||
import com.yutou.qqbot.models.Commands.Bangumi;
|
||||
import com.yutou.qqbot.models.Commands.System.*;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.models.WebSign.Tsdm;
|
||||
import com.yutou.qqbot.models.setu.QQSetu;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.handle.*;
|
||||
import com.yutou.napcat.http.NapCatApi;
|
||||
import com.yutou.napcat.model.FriendBean;
|
||||
import com.yutou.napcat.model.GroupBean;
|
||||
import com.yutou.napcat.model.GroupUserBean;
|
||||
import com.yutou.napcat.model.SendMessageResponse;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
import com.yutou.okhttp.HttpCallback;
|
||||
import com.yutou.qqbot.data.MessageChainBuilder;
|
||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
import net.mamoe.mirai.Bot;
|
||||
import net.mamoe.mirai.BotFactory;
|
||||
import net.mamoe.mirai.event.GlobalEventChannel;
|
||||
import net.mamoe.mirai.message.data.Image;
|
||||
import net.mamoe.mirai.message.data.MessageChainBuilder;
|
||||
import net.mamoe.mirai.utils.BotConfiguration;
|
||||
import net.mamoe.mirai.utils.ExternalResource;
|
||||
import retrofit2.Response;
|
||||
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class QQBotManager {
|
||||
|
||||
public static Long defGroup=891655174L;
|
||||
public static Long defGroup = 891655174L;
|
||||
public static Long defQQ = 583819556L;
|
||||
|
||||
static {
|
||||
Model.classList.add(QQSetu.class);
|
||||
Model.classList.add(Audio.class);
|
||||
Model.classList.add(BtFlash.class);
|
||||
Model.classList.add(Cmd.class);
|
||||
Model.classList.add(Help.class);
|
||||
Model.classList.add(IP.class);
|
||||
Model.classList.add(OpenPC.class);
|
||||
Model.classList.add(Restart.class);
|
||||
Model.classList.add(ToolsIdea.class);
|
||||
Model.classList.add(UpdateIP.class);
|
||||
Model.classList.add(Version.class);
|
||||
Model.classList.add(Bangumi.class);
|
||||
|
||||
Model.classList.add(TurnipProphet.class);
|
||||
Model.classList.add(Tsdm.class);
|
||||
Model.classList.add(BaiduDown.class);
|
||||
}
|
||||
private static QQBotManager botManager = null;
|
||||
private Bot bot;
|
||||
private static final long qqGroup = 891655174L;
|
||||
private boolean isLogin = false;
|
||||
private static boolean isInit = false;
|
||||
@@ -54,169 +39,239 @@ public class QQBotManager {
|
||||
Object isRun = ConfigTools.load(ConfigTools.CONFIG, "qq_bot");
|
||||
if (isRun != null && (boolean) isRun) {
|
||||
isLogin = true;
|
||||
isInit = true;
|
||||
init();
|
||||
}
|
||||
}
|
||||
|
||||
private void init() {
|
||||
new Thread(new Runnable() {
|
||||
sendMessage(true, 583819556L, "姬妻酱上线拉~☆Daze~ 当前版本:" + QQBotApplication.version);
|
||||
NapCatApi.getGroupApi().getGroupList().enqueue(new HttpCallback<List<GroupBean>>() {
|
||||
@Override
|
||||
public void run() {
|
||||
long qq = ConfigTools.load(ConfigTools.CONFIG,"qq_number",Long.class);
|
||||
String password = ConfigTools.load(ConfigTools.CONFIG,"qq_password",String.class);
|
||||
bot = BotFactory.INSTANCE.newBot(qq, password, new BotConfiguration() {
|
||||
{
|
||||
setProtocol(MiraiProtocol.ANDROID_PAD);
|
||||
fileBasedDeviceInfo("qq_bot_devices_info.json");
|
||||
if ("nas".equals(ConfigTools.load(ConfigTools.CONFIG, "model"))) {
|
||||
noBotLog();
|
||||
noNetworkLog();
|
||||
}
|
||||
}
|
||||
});
|
||||
//Events.registerEvents(bot, new MessageListener());
|
||||
GlobalEventChannel.INSTANCE.registerListenerHost(new QQMessageListener());
|
||||
// GlobalEventChannel.INSTANCE.subscribeAlways(GroupMessageEvent.class, new MessageListener());
|
||||
bot.login();
|
||||
new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String str = sendMessage("姬妻酱上线拉~☆Daze~ 当前版本:"+QQBotApplication.version);
|
||||
Log.i(str);
|
||||
public void onResponse(int code, String status, List<GroupBean> response, String rawResponse) {
|
||||
for (GroupBean groupBean : response) {
|
||||
QQDatabase.addGroup(groupBean.getGroupId(), groupBean);
|
||||
QQNumberManager.getManager().addNumber(groupBean.getGroupId(), true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}).start();
|
||||
bot.join();
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
|
||||
}
|
||||
}).start();
|
||||
});
|
||||
NapCatApi.getFriendApi().getFriendList().enqueue(new HttpCallback<List<FriendBean>>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, List<FriendBean> response, String rawResponse) {
|
||||
for (FriendBean friendBean : response) {
|
||||
QQDatabase.addUser(friendBean.getUserId(), friendBean);
|
||||
QQNumberManager.getManager().addNumber(friendBean.getUserId(), false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
|
||||
}
|
||||
});
|
||||
NapCatApi.getUtilsApi().getLoginInfo().enqueue(new HttpCallback<FriendBean>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, FriendBean response, String rawResponse) {
|
||||
QQDatabase.setMe(response);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
|
||||
}
|
||||
});
|
||||
isInit = true;
|
||||
}
|
||||
|
||||
public static QQBotManager getInstance() {
|
||||
public synchronized static QQBotManager getInstance() {
|
||||
if (botManager == null && !isInit) {
|
||||
botManager = new QQBotManager();
|
||||
}
|
||||
return botManager;
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return isLogin;
|
||||
}
|
||||
|
||||
private Image getImage(File file,Long qq) {
|
||||
if (bot != null) {
|
||||
if(QQNumberManager.getManager().isGroup(qq)) {
|
||||
return Objects.requireNonNull(bot.getGroup(qq)).uploadImage(ExternalResource.create(file));
|
||||
}else{
|
||||
return Objects.requireNonNull(bot.getFriend(qq)).uploadImage(ExternalResource.create(file));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getNotLoginQQ() {
|
||||
return "没有登录QQ";
|
||||
}
|
||||
|
||||
|
||||
public String sendMessage(String text) {
|
||||
if (bot != null&&!StringUtils.isEmpty(text)) {
|
||||
try {
|
||||
return Objects.requireNonNull(bot.getGroup(qqGroup)).sendMessage(text).toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return getNotLoginQQ();
|
||||
public SendMessageResponse sendPrivateMessage(Long qq, BaseHandle<?>... items) {
|
||||
return sendMessage(true, qq, items);
|
||||
}
|
||||
|
||||
public String sendMessage(Long group, String text) {
|
||||
if (bot != null) {
|
||||
try {
|
||||
if(QQNumberManager.getManager().isGroup(group)) {
|
||||
return Objects.requireNonNull(bot.getGroup(group)).sendMessage(text).toString();
|
||||
}else{
|
||||
return Objects.requireNonNull(bot.getFriend(group)).sendMessage(text).toString();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return getNotLoginQQ();
|
||||
private SendMessageResponse sendGroupMessage(Long group, BaseHandle<?>... items) {
|
||||
return sendMessage(false, group, items);
|
||||
}
|
||||
|
||||
public void sendMessage(Long group, MessageChainBuilder builder) {
|
||||
if (bot != null) {
|
||||
if(QQNumberManager.getManager().isGroup(group)) {
|
||||
Objects.requireNonNull(bot.getGroup(group)).sendMessage(builder.asMessageChain());
|
||||
}else{
|
||||
Objects.requireNonNull(bot.getFriend(group)).sendMessage(builder.asMessageChain());
|
||||
}
|
||||
}
|
||||
public SendMessageResponse sendMessage(boolean user, Long qq, String msg) {
|
||||
return sendMessage(user, qq, new Text(msg));
|
||||
}
|
||||
|
||||
public String sendMessage(File imageFile,Long qq,String text){
|
||||
public SendMessageResponse sendMessage(Long qq, BaseHandle<?>... items) {
|
||||
return sendMessage(QQDatabase.checkFriend(qq), qq, Arrays.asList(items));
|
||||
}
|
||||
|
||||
public SendMessageResponse sendMessage(boolean isUser, Long qq, BaseHandle<?>... items) {
|
||||
return sendMessage(isUser, qq, Arrays.asList(items));
|
||||
}
|
||||
|
||||
public SendMessageResponse sendMessage(boolean isUser, Long qq, List<BaseHandle<?>> items) {
|
||||
try {
|
||||
if (bot != null) {
|
||||
Image image = getImage(imageFile,qq);
|
||||
MessageChainBuilder builder = new MessageChainBuilder();
|
||||
if (image != null) {
|
||||
builder.append(image);
|
||||
if (!ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ, Boolean.class)) {
|
||||
return null;
|
||||
}
|
||||
MessageHandleBuild handleBuild = MessageHandleBuild
|
||||
.create()
|
||||
.setGroup(!isUser)
|
||||
.setQQNumber(qq);
|
||||
for (BaseHandle<?> item : items) {
|
||||
if (item.getData() == null) {
|
||||
continue;
|
||||
}
|
||||
builder.append(text);
|
||||
if(QQNumberManager.getManager().isGroup(qq)) {
|
||||
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()).toString();
|
||||
}else{
|
||||
return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()).toString();
|
||||
if (item instanceof Reply) {
|
||||
if (((Reply) item).getData().getId() == -1) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
handleBuild.add(item);
|
||||
}
|
||||
Response<HttpBody<SendMessageResponse>> response;
|
||||
if (isUser) {
|
||||
response = NapCatApi.getMessageApi().sendPrivateMsg(
|
||||
handleBuild.build()
|
||||
).execute();
|
||||
} else {
|
||||
response = NapCatApi.getMessageApi().sendGroupMsg(
|
||||
handleBuild.build()
|
||||
).execute();
|
||||
}
|
||||
if (response.body() != null) {
|
||||
return response.body().getData();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
SendMessageResponse response = new SendMessageResponse();
|
||||
response.setId(-1);
|
||||
response.setE(e.getMessage());
|
||||
return response;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String sendMessage(String text) {
|
||||
|
||||
return sendMessage(false,defGroup,text).toString();
|
||||
}
|
||||
|
||||
public SendMessageResponse sendMessage(Long group, String text) {
|
||||
return sendMessage(QQDatabase.checkFriend(group), group, new Text(text));
|
||||
}
|
||||
|
||||
public void sendMessage(Long group, MessageChainBuilder builder) {
|
||||
if (QQNumberManager.getManager().isGroup(group)) {
|
||||
System.out.println("发群");
|
||||
} else {
|
||||
System.out.println("发个人");
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessage(File imageFile, Long qq, String text) {
|
||||
sendMessage(imageFile, qq, null, text);
|
||||
}
|
||||
|
||||
public void sendMessage(File imageFile, Long qq, String replyMessageId, String text) {
|
||||
List<BaseHandle<?>> items = new ArrayList<>();
|
||||
|
||||
if (imageFile != null) {
|
||||
items.add(new Image(imageFile));
|
||||
}
|
||||
|
||||
return getNotLoginQQ();
|
||||
}
|
||||
public String sendMessage(File imageFile, String text) {
|
||||
return sendMessage(imageFile,qqGroup,text);
|
||||
}
|
||||
|
||||
public String sendMessage(List<File> imgs,Long qq, String text) {
|
||||
if (bot != null) {
|
||||
MessageChainBuilder builder = new MessageChainBuilder();
|
||||
for (File img : imgs) {
|
||||
builder.append(Objects.requireNonNull(getImage(img,qq)));
|
||||
}
|
||||
builder.append(text);
|
||||
if(QQNumberManager.getManager().isGroup(qq)) {
|
||||
return Objects.requireNonNull(bot.getGroup(qq)).sendMessage(builder.asMessageChain()).toString();
|
||||
}else{
|
||||
return Objects.requireNonNull(bot.getFriend(qq)).sendMessage(builder.asMessageChain()).toString();
|
||||
}
|
||||
if (replyMessageId != null && !replyMessageId.isEmpty()) {
|
||||
items.add(new Reply(Long.parseLong(replyMessageId)));
|
||||
}
|
||||
|
||||
if (text != null && !text.isEmpty()) {
|
||||
items.add(new Text(text));
|
||||
}
|
||||
|
||||
if (!items.isEmpty()) {
|
||||
sendMessage(QQDatabase.checkFriend(qq),qq, items);
|
||||
}
|
||||
return getNotLoginQQ();
|
||||
}
|
||||
|
||||
public void sendMessage(File imageFile, String text) {
|
||||
sendMessage(true,defQQ,new Image(imageFile),new Text(text));
|
||||
}
|
||||
|
||||
public void sendMessage(List<File> imgs, Long qq, String text) {
|
||||
|
||||
}
|
||||
|
||||
public void groupBan(long qqGroup, long user, int timer, ObjectInterface objectInterface) {
|
||||
NapCatApi.getGroupApi().groupBan(qqGroup, user, timer).enqueue(new HttpCallback<BaseBean>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, BaseBean response, String rawResponse) {
|
||||
if (objectInterface != null) {
|
||||
objectInterface.out("1");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
if (objectInterface != null) {
|
||||
objectInterface.out(null);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void getShutUpList(long qqGroup, HttpCallback<List<GroupUserBean>> callback) {
|
||||
NapCatApi.getGroupApi().getGroupUserList(qqGroup,true).enqueue(callback);
|
||||
}
|
||||
|
||||
public void setGroupSpecialTitle(long group,
|
||||
long user,
|
||||
String title,
|
||||
long duration) {
|
||||
NapCatApi.getGroupApi().setGroupSpecialTitle(group, user, title, duration).enqueue(new HttpCallback<BaseBean>() {
|
||||
|
||||
@Override
|
||||
public void onResponse(int code, String status, BaseBean response, String rawResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
getInstance();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("t1", 3234567890L);
|
||||
System.out.println("json = " + json);
|
||||
|
||||
String tmp = json.toString();
|
||||
JSONObject json2 = JSON.parseObject(tmp);
|
||||
System.out.println("json2 = " + json2);
|
||||
}
|
||||
|
||||
public void sendVersion() {
|
||||
String localVersion = QQBotApplication.version;
|
||||
String serverVersion = HttpTools.get("http://tools.yutou233.cn:8000/public/version.do?token=zIrsh9TUZP2lfRW753PannG49E7VJvor");
|
||||
String serverVersion = HttpTools.get("https://tools.yutou233.cn/public/version.do?token=zIrsh9TUZP2lfRW753PannG49E7VJvor");
|
||||
String msg = "本地版本:" + localVersion + "\n" + "服务器版本:" + serverVersion;
|
||||
QQBotManager.getInstance().sendMessage(msg);
|
||||
AppTools.sendServer("服务版本查询", msg);
|
||||
// AppTools.sendServer("服务版本查询", msg);
|
||||
}
|
||||
|
||||
public boolean isLogin() {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package com.yutou.qqbot;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import redis.clients.jedis.Jedis;
|
||||
@@ -49,7 +50,7 @@ public class QQNumberManager {
|
||||
}
|
||||
public boolean addPower(Long qq, String power){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
array.add(power);
|
||||
json.put("power",array);
|
||||
@@ -60,7 +61,7 @@ public class QQNumberManager {
|
||||
public List<String> getPower(Long qq){
|
||||
List<String> list=new ArrayList<>();
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
for (Object power : array) {
|
||||
list.add((String) power);
|
||||
@@ -72,7 +73,7 @@ public class QQNumberManager {
|
||||
public List<String> getUseModel(long qq) {
|
||||
List<String> list=new ArrayList<>();
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
for (Object power : array) {
|
||||
list.add((String) power);
|
||||
@@ -83,7 +84,7 @@ public class QQNumberManager {
|
||||
}
|
||||
public boolean delPower(Long qq, String power){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
array.remove(power);
|
||||
json.put("power",array);
|
||||
@@ -93,7 +94,7 @@ public class QQNumberManager {
|
||||
}
|
||||
public boolean addUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
array.add(modelClass.getName());
|
||||
json.put("model",array);
|
||||
@@ -103,7 +104,7 @@ public class QQNumberManager {
|
||||
}
|
||||
public boolean delUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
array.remove(modelClass.getName());
|
||||
json.put("model",array);
|
||||
@@ -112,8 +113,9 @@ public class QQNumberManager {
|
||||
return false;
|
||||
}
|
||||
public boolean isExistsPower(Long qq, String... power){
|
||||
//1
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("power");
|
||||
for (String key : power) {
|
||||
if(!array.contains(key)){
|
||||
@@ -126,14 +128,14 @@ public class QQNumberManager {
|
||||
}
|
||||
public boolean isGroup(Long qq){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
return json.getBoolean("group");
|
||||
JSONObject json= JSON.parseObject(RedisTools.get(qq));
|
||||
return json.getBooleanValue("group");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isUseModel(Long qq,Class<?> modelClass){
|
||||
if(RedisTools.exists(qq,null)){
|
||||
JSONObject json=JSONObject.parseObject(RedisTools.get(qq));
|
||||
JSONObject json=JSON.parseObject(RedisTools.get(qq));
|
||||
JSONArray array=json.getJSONArray("model");
|
||||
return array.contains(modelClass.getName());
|
||||
}
|
||||
|
||||
98
src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java
Normal file
98
src/main/java/com/yutou/qqbot/bilibili/AppUserTask.java
Normal file
@@ -0,0 +1,98 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
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> weekTask = new ArrayList<>();
|
||||
private long weekTotal;
|
||||
private long weekGroup;
|
||||
private DayTask dayTask;
|
||||
|
||||
public List<WeekTask> 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",
|
||||
(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");
|
||||
if (newTask.weekTask != null && !newTask.getWeekTask().isEmpty()) {
|
||||
newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n"));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
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 1 -> "进行中,需要发送弹幕数:" + 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;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
170
src/main/java/com/yutou/qqbot/bilibili/AssTools.java
Normal file
170
src/main/java/com/yutou/qqbot/bilibili/AssTools.java
Normal file
@@ -0,0 +1,170 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class AssTools {
|
||||
private final StringBuilder builder;
|
||||
private String title;
|
||||
private int y = 0;
|
||||
private List<String> filters = new ArrayList<>();
|
||||
private String alpha="80";
|
||||
|
||||
/**
|
||||
* 弹幕转换ass
|
||||
* @param title 标题
|
||||
*/
|
||||
public AssTools(String title) {
|
||||
builder = new StringBuilder();
|
||||
this.title=title;
|
||||
initAssHeader();
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹幕过滤器
|
||||
* @param filter 过滤词
|
||||
*/
|
||||
public void addFilter(String... filter) {
|
||||
filters.addAll(Arrays.asList(filter));
|
||||
}
|
||||
|
||||
/**
|
||||
* 弹幕透明度
|
||||
* @param alpha 0 完全不透明 255 完全透明
|
||||
*/
|
||||
public void setAlpha(int alpha){
|
||||
this.alpha=Integer.toHexString(alpha);
|
||||
}
|
||||
private void addBuilder(String txt) {
|
||||
builder.append(txt).append("\n");
|
||||
}
|
||||
|
||||
private void initAssHeader() {
|
||||
addBuilder("[Script Info]");
|
||||
addBuilder("Title: " + title);
|
||||
addBuilder("Original Script: 本字幕由@yutou生成");
|
||||
addBuilder("ScriptType: v4.00+");
|
||||
addBuilder("Collisions: Normal");
|
||||
addBuilder("PlayResX: 1920");
|
||||
addBuilder("PlayResY: 1080");
|
||||
addBuilder("Timer: 10.0000");
|
||||
addBuilder("");
|
||||
addBuilder("[V4+ Styles]");
|
||||
addBuilder("Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, ");
|
||||
addBuilder("MarginL, MarginR, MarginV, Encoding");
|
||||
addBuilder("Style: Fix,Microsoft YaHei UI,45,&H66FFFFFF,&H66FFFFFF,&H66000000,&H66000000,1,0,0,0,100,100,0,0,1,2,0,2,20,20,2,0");
|
||||
addBuilder("Style: R2L,Microsoft YaHei UI,45,&H00FFFFFF,&H000000FF,&H00161616,&H00000000,0,0,0,0,100,100,0,0,1,2,0,2,20,20,20,1");
|
||||
addBuilder("");
|
||||
addBuilder("[Events]");
|
||||
addBuilder("Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text");
|
||||
}
|
||||
|
||||
/**
|
||||
* 保存弹幕文件
|
||||
* @param savePath 存储路径
|
||||
* @return 存储结果
|
||||
*/
|
||||
public boolean saveDanmu(String savePath) {
|
||||
System.out.println("savePath = " + savePath);
|
||||
File file = new File(savePath+File.separator+title+".ass");
|
||||
FileWriter writer;
|
||||
try {
|
||||
if (file.exists()) {
|
||||
if (!file.delete()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
boolean mkdirs = file.mkdirs();
|
||||
boolean delete = file.delete();
|
||||
if (!mkdirs || !delete) {
|
||||
return false;
|
||||
}
|
||||
if (!file.createNewFile()) {
|
||||
return false;
|
||||
}
|
||||
writer = new FileWriter(file);
|
||||
writer.write(builder.toString());
|
||||
writer.flush();
|
||||
writer.close();
|
||||
return true;
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}finally {
|
||||
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 添加弹幕
|
||||
* @param list 弹幕
|
||||
*/
|
||||
public void addDanmu(List<DanmuData> list) {
|
||||
list.sort((o1, o2) -> {
|
||||
if (o1.getTime() == o2.getTime()) {
|
||||
return 0;
|
||||
}
|
||||
return o1.getTime() < o2.getTime() ? -1 : 1;
|
||||
});
|
||||
for (DanmuData danmuData : list) {
|
||||
addDanmu(danmuData);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 添加弹幕
|
||||
* @param danmuData 弹幕
|
||||
*/
|
||||
public void addDanmu(DanmuData danmuData) {
|
||||
if (filters.contains(danmuData.getDanmu())) {
|
||||
return;
|
||||
}
|
||||
addY();
|
||||
long _time = danmuData.getTime();
|
||||
long h = TimeUnit.MILLISECONDS.toHours(_time);
|
||||
long m = TimeUnit.MILLISECONDS.toMinutes(_time) % 60;
|
||||
long s = TimeUnit.MILLISECONDS.toSeconds(_time) % 60;
|
||||
String sTime = String.format("%s:%s:%s.0",
|
||||
new DecimalFormat("00").format(h),
|
||||
new DecimalFormat("00").format(m),
|
||||
new DecimalFormat("00").format(s));
|
||||
if (s >= 52) {
|
||||
s = (s + 8) - 60;
|
||||
m++;
|
||||
} else {
|
||||
s += 8;
|
||||
}
|
||||
String eTime = String.format("%s:%s:%s.0",
|
||||
new DecimalFormat("00").format(h),
|
||||
new DecimalFormat("00").format(m),
|
||||
new DecimalFormat("00").format(s));
|
||||
float x1, x2;
|
||||
x1 = 1920 + (danmuData.getDanmu().length() * 12.5f);
|
||||
x2 = 0 - (danmuData.getDanmu().length() * 12.5f);
|
||||
|
||||
String ass = String.format("Dialogue: 0,%s,%s,R2L,,20,20,2,,{\\move(%.1f,%d,%.1f,%d)\\c&%s\\alpha&H%s}%s",
|
||||
sTime,
|
||||
eTime,
|
||||
x1,
|
||||
y,
|
||||
x2,
|
||||
y,
|
||||
danmuData.getFontColorHex(),
|
||||
alpha,
|
||||
danmuData.getDanmu()
|
||||
);
|
||||
addBuilder(ass);
|
||||
}
|
||||
|
||||
|
||||
private void addY() {
|
||||
y += 40;
|
||||
if (y >= 1080) {
|
||||
y = 40;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
191
src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java
Normal file
191
src/main/java/com/yutou/qqbot/bilibili/BiliBiliAppUtils.java
Normal file
@@ -0,0 +1,191 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.bilibili.BaseAPI;
|
||||
import com.yutou.bilibili.api.LiveAPI;
|
||||
import com.yutou.bilibili.api.VideoApi;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.models.BiliBili.BiliVideo;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.BiliBiliWbiSign;
|
||||
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 = BaseAPI.MCBBS_PNG;
|
||||
String sign = AppTools.getMD5("api=" + tmpUrl + AppSec);
|
||||
JSONObject get = biliUtils.http_get(BaseAPI.ACCESS_TOKEN+"?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<String, String> params = HttpTools.getUrlParams(connection.getURL().toString());
|
||||
return params.get("access_key");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Map<String, String> sign(Map<String, String> map) {
|
||||
map.putAll(getDefaultBody());
|
||||
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<String, String> getDefaultBody() {
|
||||
Map<String, String> 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<String, String> sort(Map<String, String> map) {
|
||||
return new LinkedHashMap<>(new TreeMap<>(map));
|
||||
}
|
||||
|
||||
private Map<String, String> 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<String, String> 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(LiveAPI.LIVE_TASK_PROGRESS);
|
||||
System.out.println("task = " + task);
|
||||
assert task != null;
|
||||
return task.getObject("data", AppUserTask.class);
|
||||
}
|
||||
|
||||
private void setUserTaskProgress(int index) {
|
||||
Map<String, String> map = new TreeMap<>();
|
||||
map.put("target_id", "33989");
|
||||
map.put("reward_index", index + "");
|
||||
|
||||
JSONObject httpGet = biliUtils.http(
|
||||
LiveAPI.LIVE_SET_TASK_PROGRESS,
|
||||
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<AppUserTask.WeekTask> taskList = task.getWeekTask();
|
||||
taskList.forEach(weekTask -> {
|
||||
if (weekTask.getStatus() == 2) {
|
||||
setUserTaskProgress(weekTask.getId());
|
||||
}
|
||||
});
|
||||
return task;
|
||||
}
|
||||
public static String getVideoAI(String url){
|
||||
if(url.startsWith("https://b23.tv")){
|
||||
url=b23ToUrl(url);
|
||||
}
|
||||
JSONObject videoInfo = new BiliVideo().getVideoInfo(url);
|
||||
if(videoInfo==null){
|
||||
return null;
|
||||
}
|
||||
String cid = videoInfo.getJSONObject("data").getString("cid");
|
||||
TreeMap<String,String> body=new TreeMap<>();
|
||||
body.put("cid",cid);
|
||||
body.put("up_mid",videoInfo.getJSONObject("data").getJSONObject("owner").getString("mid"));
|
||||
body.put("bvid",videoInfo.getJSONObject("data").getString("bvid"));
|
||||
BiliBiliWbiSign.getWbiSign(body);
|
||||
JSONObject object = BiliBiliUtils.getInstance(QQBotManager.defQQ)
|
||||
.http_get(VideoApi.VIDEO_AI +"?"+HttpTools.toUrlParams(body));
|
||||
if(object.getInteger("code")==0){
|
||||
if(object.getJSONObject("data").getInteger("code")==0) {
|
||||
return object.getJSONObject("data").getJSONObject("model_result").getString("summary");
|
||||
}else{
|
||||
return "没得省流";
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public static String b23ToUrl(String url){
|
||||
try {
|
||||
HttpsURLConnection connection = BiliBiliUtils.getInstance(QQBotManager.defQQ).getBiliHttpGet(url, BiliBiliUtils.getInstance(QQBotManager.defQQ).getCookie());
|
||||
connection.setInstanceFollowRedirects(false);
|
||||
connection.connect();
|
||||
if(connection.getResponseCode()==302){
|
||||
connection.setConnectTimeout(5000);
|
||||
return connection.getHeaderField("Location");
|
||||
}
|
||||
return connection.getURL().toString();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
BiliBiliWbiSign.updateRawWbiKey();
|
||||
String url="https://b23.tv/NtqDorB?share_medium=android&share_source=qq&bbid=XUDCA4BDD60B5853ACDC17794BFAEF91F874A&ts=1705470976484";
|
||||
// url="https://www.bilibili.com/video/BV1fw411E75p/?buvid=XUDCA4BDD60B5853ACDC17794BFAEF91F874A&from_spmid=tm.recommend.0.0&is_story_h5=false&mid=7G8S%2B4e7nx6XSaU3oMQKXA%3D%3D&p=1&plat_id=116&share_from=ugc&share_medium=android&share_plat=android&share_session_id=ab27db6e-47a5-43b5-b0ec-b027bcfdeccc&share_source=QQ&share_tag=s_i&spmid=main.ugc-video-detail.0.0×tamp=1705470976&unique_k=NtqDorB&up_id=1156809979";
|
||||
String ai = getVideoAI(url);
|
||||
System.out.println("ai = " + ai);
|
||||
}
|
||||
}
|
||||
182
src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java
Normal file
182
src/main/java/com/yutou/qqbot/bilibili/BiliBiliManga.java
Normal file
@@ -0,0 +1,182 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.bilibili.api.MangaApi;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
public class BiliBiliManga {
|
||||
public BiliBiliManga(long qq) {
|
||||
biliUtils = BiliBiliUtils.getInstance(qq);
|
||||
}
|
||||
|
||||
public static JSONObject sign() {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("platform", "android");
|
||||
return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post(MangaApi.SIGN, HttpTools.toUrlParams(body));
|
||||
}
|
||||
|
||||
private static JSONObject getListProductDate() {
|
||||
return BiliBiliUtils.getInstance(QQBotManager.defQQ).http_post(MangaApi.LIST_PRODUCT_DATE, "");
|
||||
}
|
||||
|
||||
private static boolean isPayMission = false;
|
||||
private static Product missionProduct = new Product();
|
||||
private static Timer mission = null;
|
||||
private static BiliBiliUtils biliUtils = null;
|
||||
private ObjectInterface anInterface = null;
|
||||
|
||||
public void addInterface(ObjectInterface objectInterface) {
|
||||
anInterface = objectInterface;
|
||||
}
|
||||
|
||||
public static boolean isPayMission() {
|
||||
return isPayMission;
|
||||
}
|
||||
|
||||
public static String getMission() {
|
||||
return missionProduct + " 兑换数量:" + missionProduct.getPayAmount();
|
||||
}
|
||||
|
||||
public static List<Product> getListProduct() {
|
||||
List<Product> list = new ArrayList<>();
|
||||
JSONObject product = getListProductDate();
|
||||
if (product.getInteger("code") == 0) {
|
||||
JSONArray array = product.getJSONArray("data");
|
||||
for (Object o : array) {
|
||||
JSONObject data = (JSONObject) o;
|
||||
Product item = new Product();
|
||||
item.setId(data.getInteger("id"));
|
||||
item.setTitle(data.getString("title"));
|
||||
item.setAmount(data.getInteger("amount"));
|
||||
item.setRemain_amount(data.getInteger("remain_amount"));
|
||||
item.setReal_cost(data.getInteger("real_cost"));
|
||||
list.add(item);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
public static int getMyPoint() {
|
||||
JSONObject user = biliUtils.http_post(MangaApi.USER_POINT, "");
|
||||
if (user != null && user.getInteger("code") == 0) {
|
||||
return user.getJSONObject("data").getInteger("point");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public JSONObject startPayMission(int id, int num) {
|
||||
JSONObject json = new JSONObject();
|
||||
if (isPayMission) {
|
||||
json.put("code", 2);
|
||||
json.put("msg", "任务正在进行:" + getMission());
|
||||
return json;
|
||||
}
|
||||
if (biliUtils == null) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "B站未登录");
|
||||
return json;
|
||||
}
|
||||
int userPoint = getMyPoint();
|
||||
List<Product> list = getListProduct();
|
||||
missionProduct = null;
|
||||
for (Product product : list) {
|
||||
if (product.getId() == id) {
|
||||
missionProduct = product;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (missionProduct == null) {
|
||||
json.put("code", -1);
|
||||
json.put("msg", "未找到商品,可能id有误 id:" + id);
|
||||
return json;
|
||||
}
|
||||
if (num == -1) {
|
||||
num = 99999;
|
||||
}
|
||||
int userPointNum = userPoint / missionProduct.getReal_cost();
|
||||
num = Math.min(num, userPointNum);
|
||||
if (num < missionProduct.getRemain_amount()) {
|
||||
num = missionProduct.getRemain_amount();
|
||||
}
|
||||
|
||||
missionProduct.setPayAmount(num);
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("product_id", id);
|
||||
data.put("product_num", num);
|
||||
data.put("point", num * missionProduct.getReal_cost());
|
||||
startPayMission(data);
|
||||
isPayMission = true;
|
||||
|
||||
if (num == 0) {
|
||||
json.put("code", 3);
|
||||
json.put("msg", "商品无货,正在抢购");
|
||||
} else {
|
||||
json.put("code", 0);
|
||||
json.put("msg", "任务创建成功:" + missionProduct + " 兑换数量:" + num);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
private void startPayMission(JSONObject data) {
|
||||
if (mission != null) {
|
||||
mission.cancel();
|
||||
}
|
||||
mission = new Timer();
|
||||
mission.schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
JSONObject post = biliUtils.http_post(MangaApi.PAY_MISSION, HttpTools.toUrlParams(data));
|
||||
if (post == null) {
|
||||
anInterface.out("网络请求失败,请查看日志");
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
if (post.getInteger("code") == 0) {
|
||||
anInterface.out("兑换成功,任务已取消");
|
||||
isPayMission = false;
|
||||
cancel();
|
||||
} else {
|
||||
anInterface.out("[" + post.getInteger("code") + "]" + post.getString("msg"));
|
||||
}
|
||||
}
|
||||
}, 0, 1000);
|
||||
}
|
||||
|
||||
public void stopPayMission() {
|
||||
if (isPayMission) {
|
||||
isPayMission = false;
|
||||
if (mission != null) {
|
||||
mission.cancel();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
// System.out.println(BiliBiliManga.sign());
|
||||
BiliBiliUtils.getInstance(583819556L).sendLiveDanmu(33989,"学学这个");
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Product {
|
||||
String title;
|
||||
int id;
|
||||
int remain_amount;
|
||||
int real_cost;
|
||||
int amount;
|
||||
int payAmount;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[ " + id + " ] " + title + " (" + remain_amount + "/" + amount + ") $" + real_cost;
|
||||
}
|
||||
}
|
||||
}
|
||||
444
src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java
Normal file
444
src/main/java/com/yutou/qqbot/bilibili/BiliBiliUtils.java
Normal file
@@ -0,0 +1,444 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.bilibili.api.LiveAPI;
|
||||
import com.yutou.bilibili.api.LoginAPI;
|
||||
import com.yutou.bilibili.api.SignApi;
|
||||
import com.yutou.bilibili.api.UserApi;
|
||||
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.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.Proxy;
|
||||
import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
public class BiliBiliUtils {
|
||||
private long qq;
|
||||
private long oldBiliBiliHttpTime = 0;
|
||||
|
||||
public enum HTTP {
|
||||
POST, GET
|
||||
}
|
||||
|
||||
public enum RET_MODEL {
|
||||
BYTE, JSON
|
||||
}
|
||||
|
||||
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;
|
||||
while ((len = stream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
outputStream.flush();
|
||||
}
|
||||
String str = outputStream.toString(StandardCharsets.UTF_8);
|
||||
outputStream.close();
|
||||
try {
|
||||
return JSON.parseObject(str);
|
||||
} catch (Exception e) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("html", str);
|
||||
return json;
|
||||
} finally {
|
||||
|
||||
stream.close();
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
//com.yutou.bilibili.Tools.Log.e(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JSONObject http_login_getSid(String url) {
|
||||
try {
|
||||
Log.i("调用url = " + url);
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
setConnection(null, connection);
|
||||
connection.setRequestMethod("GET");
|
||||
connection.connect();
|
||||
BufferedInputStream stream = new BufferedInputStream(connection.getInputStream());
|
||||
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
||||
byte[] bytes = new byte[1024];
|
||||
int len;
|
||||
while ((len = stream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
outputStream.flush();
|
||||
}
|
||||
List<String> cookie = null;
|
||||
if (connection.getHeaderFields().containsKey("Set-Cookie")) {
|
||||
cookie = connection.getHeaderFields().get("Set-Cookie");
|
||||
}
|
||||
String str = outputStream.toString(StandardCharsets.UTF_8);
|
||||
outputStream.close();
|
||||
try {
|
||||
JSONObject json = JSON.parseObject(str);
|
||||
if (cookie != null) {
|
||||
StringBuilder ck = new StringBuilder();
|
||||
for (String key : cookie) {
|
||||
ck.append(";").append(key);
|
||||
}
|
||||
json.put("cookie", ck.toString());
|
||||
}
|
||||
return json;
|
||||
} catch (Exception e) {
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("html", str);
|
||||
return json;
|
||||
} finally {
|
||||
|
||||
stream.close();
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
//com.yutou.bilibili.Tools.Log.e(e);
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public JSONObject http_post(String url, String body) {
|
||||
return http(url, HTTP.POST, body, RET_MODEL.JSON);
|
||||
}
|
||||
|
||||
public <T> T http(String url, HTTP model, String body, RET_MODEL ret_model) {
|
||||
return http(url, model, body, null, ret_model);
|
||||
}
|
||||
|
||||
public <T> T http(String url, HTTP model, String body, Map<String, String> headers, RET_MODEL ret_model) {
|
||||
JSONObject json = null;
|
||||
BufferedInputStream stream = null;
|
||||
ByteArrayOutputStream outputStream = null;
|
||||
OutputStream connectionOutputStream = null;
|
||||
HttpURLConnection connection = null;
|
||||
try {
|
||||
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||
}
|
||||
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));
|
||||
}
|
||||
} else {
|
||||
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
|
||||
}
|
||||
|
||||
if (!StringUtils.isEmpty(body)) {
|
||||
connectionOutputStream = connection.getOutputStream();
|
||||
connectionOutputStream.write(body.getBytes(StandardCharsets.UTF_8));
|
||||
connectionOutputStream.flush();
|
||||
}
|
||||
connection.connect();
|
||||
if (connection.getResponseCode() == 400) {
|
||||
return null;
|
||||
}
|
||||
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;
|
||||
while ((len = stream.read(bytes)) != -1) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
outputStream.flush();
|
||||
}
|
||||
if (ret_model == RET_MODEL.BYTE) {
|
||||
return (T) outputStream.toByteArray();
|
||||
}
|
||||
String str = outputStream.toString(StandardCharsets.UTF_8);
|
||||
|
||||
try {
|
||||
json = JSON.parseObject(str);
|
||||
json.put("cookie", connection.getHeaderField("Set-Cookie"));
|
||||
return (T) json;
|
||||
} catch (Exception e) {
|
||||
json = new JSONObject();
|
||||
json.put("html", str);
|
||||
json.put("cookie", connection.getHeaderField("Set-Cookie"));
|
||||
return (T) json;
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
try {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
if (outputStream != null) {
|
||||
outputStream.close();
|
||||
}
|
||||
if (connectionOutputStream != null) {
|
||||
connectionOutputStream.close();
|
||||
}
|
||||
if (connection != null) {
|
||||
connection.disconnect();
|
||||
}
|
||||
|
||||
} catch (Exception ignored) {
|
||||
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getCookie() {
|
||||
if (StringUtils.isEmpty(ConfigTools.readFile(new File(qq + "_bilibili.cookie")))) {
|
||||
return "";
|
||||
}
|
||||
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(";");
|
||||
|
||||
}
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
public HttpURLConnection getBiliHttpPost(String url, String cookie) throws Exception {
|
||||
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setDoInput(true);
|
||||
setConnection(cookie, connection);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public HttpsURLConnection getBiliHttpGet(String url, String cookie) throws IOException {
|
||||
if (System.currentTimeMillis() - oldBiliBiliHttpTime < 1000) {
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
oldBiliBiliHttpTime = System.currentTimeMillis();
|
||||
}
|
||||
HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
if (cookie != null) {
|
||||
setConnection(cookie, connection);
|
||||
}
|
||||
connection.setReadTimeout(5000);
|
||||
connection.setConnectTimeout(5000);
|
||||
return connection;
|
||||
}
|
||||
|
||||
public File download(final String url, final String saveName, boolean isProxy) {
|
||||
File jar = null;
|
||||
try {
|
||||
File savePath = new File(HttpTools.downloadPath + saveName);
|
||||
Proxy proxy = null;
|
||||
if (!savePath.exists()) {
|
||||
savePath.mkdirs();
|
||||
}
|
||||
savePath.delete();
|
||||
Log.i("DOWNLOAD", "下载文件:" + url + " 保存文件:" + saveName);
|
||||
if (isProxy) {
|
||||
proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 7890));
|
||||
}
|
||||
HttpsURLConnection connection;
|
||||
if (isProxy) {
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection(proxy);
|
||||
} else {
|
||||
connection = (HttpsURLConnection) new URL(url).openConnection();
|
||||
}
|
||||
setConnection(getCookie(), connection);
|
||||
|
||||
InputStream inputStream = connection.getInputStream();
|
||||
jar = new File(HttpTools.downloadPath + saveName + "_tmp.tmp");
|
||||
jar.createNewFile();
|
||||
Log.i("DOWNLOAD", "临时保存文件:" + jar.getAbsolutePath());
|
||||
OutputStream outputStream = new FileOutputStream(jar);
|
||||
byte[] bytes = new byte[1024];
|
||||
double size = connection.getContentLength();
|
||||
double downSize = 0;
|
||||
int len;
|
||||
while ((len = inputStream.read(bytes)) > 0) {
|
||||
outputStream.write(bytes, 0, len);
|
||||
downSize += len;
|
||||
}
|
||||
outputStream.close();
|
||||
inputStream.close();
|
||||
File oldJar = new File(HttpTools.downloadPath + saveName);
|
||||
if (oldJar.exists()) {
|
||||
oldJar.delete();
|
||||
}
|
||||
jar.renameTo(oldJar);
|
||||
Log.i("DOWNLOAD", "实际保存:" + oldJar.getAbsolutePath() + " " + oldJar.getName());
|
||||
return oldJar;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
if (jar != null) {
|
||||
jar.delete();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void download_ffmpeg(final List<String> url, final String saveName) {
|
||||
new Thread(() -> {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(ConfigTools.load(ConfigTools.CONFIG, ConfigTools.FFMPEG, String.class)).append(" ");
|
||||
/* builder.append("-user_agent").append(" ");
|
||||
builder.append("\"").append("User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36 Referer:https://live.bilibili.com").append("\"").append(" ");
|
||||
builder.append("-cookies").append(" ");
|
||||
builder.append("\"").append(getCookie()).append("\"").append(" ");
|
||||
builder.append("-headers").append(" ");
|
||||
builder.append("\"").append("Referer:https://live.bilibili.com").append("\"").append(" ");*/
|
||||
for (String _url : url) {
|
||||
builder.append("-i").append(" ");
|
||||
builder.append("\"").append(_url).append("\"").append(" ");
|
||||
}
|
||||
builder.append("-vcodec").append(" ");
|
||||
builder.append("copy").append(" ");
|
||||
builder.append("-acodec").append(" ");
|
||||
builder.append("copy").append(" ");
|
||||
builder.append("-threads").append(" ");
|
||||
builder.append("8").append(" ");
|
||||
// builder.append("-y").append(" ");
|
||||
builder.append(new File(HttpTools.downloadPath + saveName + ".mp4").getAbsolutePath()).append(" ");
|
||||
System.out.println(builder);
|
||||
AppTools.exec(builder.toString(), new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
System.out.println("data = " + data);
|
||||
}
|
||||
}, false, false);
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
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");
|
||||
connection.setRequestProperty("Referer", "https://www.bilibili.com");
|
||||
connection.addRequestProperty("Connection", "keep-alive");
|
||||
connection.addRequestProperty("Upgrade-Insecure-Requests", "1");
|
||||
if (!StringUtils.isEmpty(cookie)) {
|
||||
connection.addRequestProperty("Cookie", cookie);
|
||||
}
|
||||
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 JSONObject getLoginInfo() {
|
||||
JSONObject jsonObject = http_get(UserApi.NAV);
|
||||
if (jsonObject == null) {
|
||||
jsonObject = new JSONObject();
|
||||
jsonObject.put("code", "-1");
|
||||
jsonObject.put("data", new JSONObject());
|
||||
}
|
||||
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=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));*/
|
||||
JSONObject sign = new BiliBiliUtils(583819556).getUserInfo(96300);
|
||||
System.out.println("sign = " + sign);
|
||||
}
|
||||
|
||||
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(qq));
|
||||
body.put("csrf_token", BiliLogin.getCookieToken(qq));
|
||||
JSONObject post = http_post(LiveAPI.LIVE_SEND_DANMU, HttpTools.toUrlParams(body));
|
||||
return post.getInteger("code") == 0;
|
||||
}
|
||||
|
||||
public String liveSignIn() {
|
||||
//{"code":0,"data":{"coin":1,"gold":19500,"silver":106394,"tid":"Silver2Coin22101413201169763005873"},"message":"兑换成功"}
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("csrf", BiliLogin.getCookieToken(qq));
|
||||
body.put("csrf_token", BiliLogin.getCookieToken(qq));
|
||||
JSONObject toCoin = http_post(SignApi.LIVE_SIGN_COIN, HttpTools.toUrlParams(body));
|
||||
JSONObject liveSign = http_get(SignApi.LIVE_SIGN);
|
||||
JSONObject vipSign = http_post(SignApi.VIP_SIGN, null);
|
||||
return "银瓜子兑换硬币:" + toCoin.getString("message") + "|" + "直播签到:" + liveSign.getString("message") + "|大会员中心签到:" + vipSign.getString("message");
|
||||
}
|
||||
|
||||
public JSONObject getLiveRoom(int roomId) {
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("room_id", roomId);
|
||||
body.put("csrf", BiliLogin.getCookieToken(qq));
|
||||
body.put("csrf_token", BiliLogin.getCookieToken(qq));
|
||||
return http_post(LiveAPI.LIVE_ROOM_INFO, HttpTools.toUrlParams(body));
|
||||
}
|
||||
|
||||
public JSONObject getUserInfo(int mid) {
|
||||
TreeMap<String, String> body = new TreeMap<>();
|
||||
body.put("mid", mid + "");
|
||||
BiliBiliWbiSign.getWbiSign(body);
|
||||
return http_get(UserApi.USER_INFO_V2 + "?" + HttpTools.toUrlParams(body));
|
||||
}
|
||||
|
||||
public boolean checkLiveRoom(int roomId) {
|
||||
JSONObject post = getLiveRoom(roomId);
|
||||
return post.getInteger("code") == 0;
|
||||
}
|
||||
}
|
||||
110
src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java
Normal file
110
src/main/java/com/yutou/qqbot/bilibili/BiliLogin.java
Normal file
@@ -0,0 +1,110 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.bilibili.api.LoginAPI;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.text.ParseException;
|
||||
import java.text.ParsePosition;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
public class BiliLogin {
|
||||
|
||||
BiliBiliUtils biliUtils;
|
||||
private long qq;
|
||||
|
||||
|
||||
public BiliLogin(Long qq) {
|
||||
biliUtils = BiliBiliUtils.getInstance(qq);
|
||||
this.qq = qq;
|
||||
}
|
||||
|
||||
public JSONObject login() {
|
||||
JSONObject login = JSON.parseObject(HttpTools.get(LoginAPI.LOGIN_QRCODE));
|
||||
JSONObject json = new JSONObject();
|
||||
System.out.println("login = " + login);
|
||||
json.put("code", login.getInteger("code"));
|
||||
json.put("url", login.getJSONObject("data").getString("url"));
|
||||
new Thread(() -> waitLogin(login.getJSONObject("data").getString("qrcode_key"))).start();
|
||||
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();
|
||||
new Timer().schedule(new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
String bd = "gourl=https%3A%2F%2Fpassport.bilibili.com%2Fajax%2FminiLogin%2Fredirect&oauthKey=" + oauthKey;
|
||||
if ((System.currentTimeMillis() - time) > 5 * 60 * 1000) {
|
||||
cancel();
|
||||
return;
|
||||
}
|
||||
JSONObject json = biliUtils.http_login_getSid(LoginAPI.LOGIN_QRCODE_POLL + "?qrcode_key=" + oauthKey);
|
||||
Log.i("B站登陆", json.toJSONString());
|
||||
if (json.getInteger("code") == 0 && json.getJSONObject("data").getInteger("code") == 0) {
|
||||
|
||||
String[] split = json.getString("cookie").split(";");
|
||||
JSONObject ck = new JSONObject();
|
||||
for (String string : split) {
|
||||
if (!ck.containsKey(string) && !StringUtils.isEmpty(string) && string.contains("=")) {
|
||||
String key = string.split("=")[0].trim();
|
||||
String value = string.split("=")[1].trim();
|
||||
if (key.contains("Expires")) {
|
||||
SimpleDateFormat sdf = new SimpleDateFormat("EEE, dd MMMM yyyy HH:mm:ss z", Locale.ENGLISH);
|
||||
sdf.setTimeZone(TimeZone.getDefault());
|
||||
Date date = sdf.parse(value, new ParsePosition(0));
|
||||
value = String.valueOf(date.getTime() / 1000);
|
||||
}
|
||||
ck.put(key, value);
|
||||
}
|
||||
}
|
||||
ck.put("gourl", bd);
|
||||
ConfigTools.saveFile(new File(qq + "_bilibili.cookie"), ck.toJSONString());
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
}, 1000, 3000);
|
||||
|
||||
}
|
||||
|
||||
public boolean testLogin() {
|
||||
if (biliUtils == null) {
|
||||
return false;
|
||||
}
|
||||
JSONObject jsonObject = biliUtils.getLoginInfo();
|
||||
return jsonObject.getInteger("code") == 0;
|
||||
}
|
||||
|
||||
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(qq + "_bilibili.cookie")));
|
||||
return json.getString("bili_jct");
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args) throws ParseException {
|
||||
String http = "{\"code\":0,\"message\":\"0\",\"ttl\":1,\"data\":{\"url\":\"https://passport.biligame.com/x/passport-login/web/crossDomain?DedeUserID=96300&DedeUserID__ckMd5=c506a12068157a3a&Expires=1720252437&SESSDATA=c383a8e0,1720252437,9ba5c*11CjCBp3_j-6zYtK27tzUVrmFZNgjyeDW6pcdfmRBJU5cVfz4OhVmujjKCZsGAkXL6ll8SVnplZ2JONlBleHdFOGgzUzNJYUxIbzJwRVhTYVM2LWVuQnJyQVQxQnRWTUFZbUYybV95Y1RELTdGeF9mNlpXV3RDTjdsMVBaYkhxZGZyblRkTUJCMGV3IIEC&bili_jct=e786885293c24eb7198dc0538b56d6d8&gourl=https%3A%2F%2Fwww.bilibili.com\",\"refresh_token\":\"347b83e7c4a1e24f4681f06f28f71b11\",\"timestamp\":1704700437058,\"code\":0,\"message\":\"\"},\"cookie\":\";SESSDATA=c383a8e0%2C1720252437%2C9ba5c%2A11CjCBp3_j-6zYtK27tzUVrmFZNgjyeDW6pcdfmRBJU5cVfz4OhVmujjKCZsGAkXL6ll8SVnplZ2JONlBleHdFOGgzUzNJYUxIbzJwRVhTYVM2LWVuQnJyQVQxQnRWTUFZbUYybV95Y1RELTdGeF9mNlpXV3RDTjdsMVBaYkhxZGZyblRkTUJCMGV3IIEC; Path=/; Domain=bilibili.com; Expires=Sat, 06 Jul 2024 07:53:57 GMT; HttpOnly; Secure;bili_jct=e786885293c24eb7198dc0538b56d6d8; Path=/; Domain=bilibili.com; Expires=Sat, 06 Jul 2024 07:53:57 GMT;DedeUserID=96300; Path=/; Domain=bilibili.com; Expires=Sat, 06 Jul 2024 07:53:57 GMT;DedeUserID__ckMd5=c506a12068157a3a; Path=/; Domain=bilibili.com; Expires=Sat, 06 Jul 2024 07:53:57 GMT;sid=ger7871m; Path=/; Domain=bilibili.com; Expires=Sat, 06 Jul 2024 07:53:57 GMT\"}";
|
||||
JSONObject body = JSON.parseObject(http);
|
||||
BiliLogin login = new BiliLogin(583819556L);
|
||||
boolean testLogin = login.testLogin();
|
||||
System.out.println("testLogin = " + testLogin);
|
||||
System.out.println(BiliBiliUtils.getInstance(583819556L).getLoginInfo());
|
||||
//JSONObject json = login.login();
|
||||
//System.out.println("json = " + json);
|
||||
// QRCodeUtils.createQRCode("bili_login", json.getString("url"));
|
||||
}
|
||||
}
|
||||
26
src/main/java/com/yutou/qqbot/bilibili/DanmuData.java
Normal file
26
src/main/java/com/yutou/qqbot/bilibili/DanmuData.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package com.yutou.qqbot.bilibili;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Data
|
||||
public class DanmuData {
|
||||
private int id;
|
||||
private int model;//1~3 滚动弹幕 4 底端弹幕 5 顶端弹幕 6 逆向弹幕 7 精准定位 8 高级弹幕
|
||||
private int fontSize;
|
||||
private int fontColor;
|
||||
private long time;
|
||||
private String uCode;
|
||||
private String danmu;
|
||||
private long uid;
|
||||
private String uname;
|
||||
|
||||
public Date getTimeDate() {
|
||||
return new Date(time);
|
||||
}
|
||||
|
||||
public String getFontColorHex() {
|
||||
return Integer.toHexString(fontColor);
|
||||
}
|
||||
}
|
||||
57620
src/main/java/com/yutou/qqbot/bilibili/VideoDanMu.java
Normal file
57620
src/main/java/com/yutou/qqbot/bilibili/VideoDanMu.java
Normal file
File diff suppressed because it is too large
Load Diff
16
src/main/java/com/yutou/qqbot/data/MessageChainBuilder.java
Normal file
16
src/main/java/com/yutou/qqbot/data/MessageChainBuilder.java
Normal file
@@ -0,0 +1,16 @@
|
||||
package com.yutou.qqbot.data;
|
||||
|
||||
public class MessageChainBuilder {
|
||||
StringBuilder sb;
|
||||
public MessageChainBuilder() {
|
||||
sb=new StringBuilder();
|
||||
}
|
||||
public MessageChainBuilder append(String s){
|
||||
sb.append(s);
|
||||
return this;
|
||||
}
|
||||
public MessageChainBuilder append(Object o){
|
||||
sb.append(o.toString());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
30
src/main/java/com/yutou/qqbot/data/baidu/Message.java
Normal file
30
src/main/java/com/yutou/qqbot/data/baidu/Message.java
Normal file
@@ -0,0 +1,30 @@
|
||||
package com.yutou.qqbot.data.baidu;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Message {
|
||||
private String role = "user";
|
||||
private String content;
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
|
||||
public boolean checkIsUser() {
|
||||
return "user".equals(role);
|
||||
}
|
||||
|
||||
public static Message create(String message) {
|
||||
return create(message, false);
|
||||
}
|
||||
|
||||
public static Message create(String message, boolean isGTP) {
|
||||
Message msg = new Message();
|
||||
msg.content = message;
|
||||
if (isGTP) {
|
||||
msg.role = "assistant";
|
||||
}
|
||||
return msg;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package com.yutou.qqbot.data.baidu;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class ResponseMessage {
|
||||
private String id;
|
||||
private String object;
|
||||
private long created;
|
||||
private String result;
|
||||
private boolean isTruncated;
|
||||
private boolean needClearHistory;
|
||||
private Message usage;
|
||||
|
||||
public ResponseMessage() {
|
||||
}
|
||||
}
|
||||
50
src/main/java/com/yutou/qqbot/data/bili/EPInfo.java
Normal file
50
src/main/java/com/yutou/qqbot/data/bili/EPInfo.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package com.yutou.qqbot.data.bili;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class EPInfo {
|
||||
private int code;
|
||||
private String message;
|
||||
private MediaResult result;
|
||||
|
||||
@Data
|
||||
public static class MediaResult {
|
||||
private Media media;
|
||||
|
||||
// getters and setters
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Media {
|
||||
private String cover;
|
||||
private String horizontal_picture;
|
||||
private int media_id;
|
||||
private NewEp new_ep;
|
||||
private Rating rating;
|
||||
private int season_id;
|
||||
private String share_url;
|
||||
private String title;
|
||||
private int type;
|
||||
private String type_name;
|
||||
|
||||
// getters and setters
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class NewEp {
|
||||
private int id;
|
||||
private String index;
|
||||
private String index_show;
|
||||
|
||||
// getters and setters
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Rating {
|
||||
private int count;
|
||||
private double score;
|
||||
|
||||
// getters and setters
|
||||
}
|
||||
}
|
||||
49
src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java
Normal file
49
src/main/java/com/yutou/qqbot/data/jianr/AndroidDevice.java
Normal file
@@ -0,0 +1,49 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class AndroidDevice {
|
||||
String title;
|
||||
String deviceId;
|
||||
DeviceDisplay androidDevice;
|
||||
List<GameDisplay> deviceDisplay;
|
||||
|
||||
|
||||
@Data
|
||||
public static class DeviceDisplay {
|
||||
int width, height;
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class GameDisplay {
|
||||
String title;
|
||||
double width, height;
|
||||
Vector2D start, end;
|
||||
|
||||
public double getWidth() {
|
||||
return end.getX() - start.getX();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class JianRScriptData {
|
||||
private String name;
|
||||
private String device;
|
||||
private List<Script> run;
|
||||
|
||||
public void addRun(Script script) {
|
||||
if(run==null){
|
||||
run=new ArrayList<>();
|
||||
}
|
||||
run.add(script);
|
||||
}
|
||||
|
||||
@Data
|
||||
public static class Script {
|
||||
private String name;
|
||||
private int nextWaitTime;
|
||||
private int randomNextWaitTime;
|
||||
private String model;
|
||||
private int x;
|
||||
private int y;
|
||||
private int rx;
|
||||
private int ry;
|
||||
public static class ScriptModel {
|
||||
public static final String CLICK = "click";
|
||||
public static final String WAIT = "wait";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Data
|
||||
public class JianRScriptV2Data {
|
||||
private String title;
|
||||
private List<Script> script;
|
||||
|
||||
@Data
|
||||
public static class Script {
|
||||
private String title;
|
||||
private String activity;
|
||||
private int nextWaitTime;
|
||||
private int randomNextWaitTime;
|
||||
}
|
||||
public static class ScriptModel {
|
||||
public static final String MAP = "map";
|
||||
public static final String attack = "attack";
|
||||
public static final String formationType = "formationType";
|
||||
public static final String dialog_go = "dialog_go";
|
||||
public static final String dialog_back = "dialog_back";
|
||||
public static final String dialog_assets = "dialog_assets";
|
||||
public static final String none = "none";
|
||||
}
|
||||
}
|
||||
45
src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java
Normal file
45
src/main/java/com/yutou/qqbot/data/jianr/Vector2D.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.yutou.qqbot.data.jianr;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
@Data
|
||||
public class Vector2D {
|
||||
double x, y;
|
||||
boolean enableRandomX, enableRandomY;
|
||||
boolean absRandomX, absRandomY;
|
||||
int randomNumX, randomNumY;
|
||||
|
||||
|
||||
public double getX() {
|
||||
if (isEnableRandomX()) {
|
||||
double tmp = new Random().nextDouble(-randomNumX, randomNumX);
|
||||
if (isAbsRandomX()) {
|
||||
return Math.abs(tmp) + x;
|
||||
} else {
|
||||
return tmp + x;
|
||||
}
|
||||
}
|
||||
return x;
|
||||
}
|
||||
public double getNotRandomY() {
|
||||
return y;
|
||||
}
|
||||
public double getNotRandomX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
|
||||
public double getY() {
|
||||
if(isEnableRandomY()){
|
||||
double tmp = new Random().nextDouble(-randomNumY, randomNumY);
|
||||
if (isAbsRandomY()) {
|
||||
return Math.abs(tmp) + y;
|
||||
} else {
|
||||
return tmp + y;
|
||||
}
|
||||
}
|
||||
return y;
|
||||
}
|
||||
}
|
||||
@@ -3,4 +3,5 @@ package com.yutou.qqbot.interfaces;
|
||||
public interface ModelInterface {
|
||||
boolean isUserPublic();
|
||||
String[] getUsePowers();
|
||||
String getModelName();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package com.yutou.qqbot.models.Animal;
|
||||
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.*;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.WebElement;
|
||||
@@ -16,6 +18,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@UseModel
|
||||
public class TurnipProphet extends Model {
|
||||
public static class TurnipData {
|
||||
public static final String MODEL = "趋势:";
|
||||
@@ -40,7 +43,7 @@ public class TurnipProphet extends Model {
|
||||
|
||||
}
|
||||
|
||||
static int nowTime=-1;
|
||||
static int nowTime = -1;
|
||||
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
@@ -54,32 +57,47 @@ public class TurnipProphet extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "大头菜";
|
||||
}
|
||||
|
||||
Long user, sendQQ;
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
user = qq;
|
||||
sendQQ = qq;
|
||||
if (isGroup) {
|
||||
return;
|
||||
if (!event.isAtMe()) {
|
||||
return;
|
||||
}
|
||||
user = event.getSource().getFromId();
|
||||
}
|
||||
int money = -1;
|
||||
try {
|
||||
if (isGroup) {
|
||||
msg = msg.replace("@2476945931", "").trim();
|
||||
}
|
||||
money = Integer.parseInt(msg.trim());
|
||||
} catch (Exception e) {
|
||||
if (msg.equals(QQFromCommands.TURNIP_PROPHET)) {
|
||||
showData(event.getSource().getFromId());
|
||||
showData();
|
||||
}
|
||||
return;
|
||||
}
|
||||
setData(money, event.getSource().getFromId());
|
||||
setData(money);
|
||||
}
|
||||
|
||||
private void showData(long qq) {
|
||||
String redisKey = qq + "_turnip";
|
||||
private void showData() {
|
||||
String redisKey = user + "_turnip";
|
||||
String data = RedisTools.get(redisKey);
|
||||
if (StringUtils.isEmpty(data)) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有本周数据,无法预测");
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有本周数据,无法预测"));
|
||||
return;
|
||||
}
|
||||
JSONObject json = JSONObject.parseObject(data);
|
||||
JSONObject json = JSON.parseObject(data);
|
||||
String prices = json.getString("prices");
|
||||
String pattern = null;
|
||||
if (json.containsKey("old_pattern")) {
|
||||
@@ -99,23 +117,26 @@ public class TurnipProphet extends Model {
|
||||
Map<String, String> map = null;
|
||||
try {
|
||||
map = openTurnip(prices, pattern);
|
||||
sendQQ(map, prices, pattern, qq);
|
||||
sendQQ(map, prices, pattern);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
showData(qq);
|
||||
showData();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void setData(int money, long qq) {
|
||||
String redisKey = qq + "_turnip";
|
||||
private void setData(int money) {
|
||||
String redisKey = user + "_turnip";
|
||||
String data = RedisTools.get(redisKey);
|
||||
String pattern = null;
|
||||
JSONObject json;
|
||||
JSONArray array;
|
||||
if (StringUtils.isEmpty(data)||getDay()==0) {
|
||||
if (StringUtils.isEmpty(data) || getDay() == 0) {
|
||||
array = new JSONArray();
|
||||
json = new JSONObject();
|
||||
if (getDay() == 0 && !StringUtils.isEmpty(data)) {
|
||||
json = JSON.parseObject(data);
|
||||
}
|
||||
array.add(-1);
|
||||
array.add(-1);
|
||||
array.add(-1);
|
||||
@@ -130,11 +151,11 @@ public class TurnipProphet extends Model {
|
||||
array.add(-1);
|
||||
array.add(-1);
|
||||
} else {
|
||||
json = JSONObject.parseObject(data);
|
||||
json = JSON.parseObject(data);
|
||||
array = json.getJSONArray("turnip");
|
||||
}
|
||||
if (array.getInteger(0) == -1 && getDay() != 0) {
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有周日买入信息,本周不收录 :(");
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有周日买入信息,本周不收录 :("));
|
||||
return;
|
||||
}
|
||||
if (json.containsKey("old_pattern")) {
|
||||
@@ -145,19 +166,21 @@ public class TurnipProphet extends Model {
|
||||
}
|
||||
if (getDay() == 0) {
|
||||
if (json.containsKey("pattern")) {
|
||||
json.put("old_pattern", json.getString("pattern"));
|
||||
pattern = json.getString("pattern");
|
||||
}
|
||||
if (money >= 90 && money <= 110) {
|
||||
array.set(0, money);
|
||||
}
|
||||
} else {
|
||||
if (money >= 9 && money <= 660) {
|
||||
if (getTime() < 12) {
|
||||
array.set(getDay() * 2 - 1, money);
|
||||
if (!json.containsKey("tmp_pattern")) {
|
||||
json.put("old_pattern", json.getString("pattern"));
|
||||
pattern = json.getString("pattern");
|
||||
} else {
|
||||
array.set(getDay() * 2, money);
|
||||
pattern = json.getString("old_pattern");
|
||||
}
|
||||
json.put("tmp_pattern", json.getString("pattern"));
|
||||
}
|
||||
array.set(0, money);
|
||||
} else {
|
||||
json.remove("tmp_pattern");
|
||||
if (getTime() < 12) {
|
||||
array.set(getDay() * 2 - 1, money);
|
||||
} else {
|
||||
array.set(getDay() * 2, money);
|
||||
}
|
||||
}
|
||||
json.put("turnip", array);
|
||||
@@ -181,13 +204,13 @@ public class TurnipProphet extends Model {
|
||||
case "小幅上涨(四期型)" -> pattern = "3";
|
||||
}
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "已记录,正在预测本周走势...");
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("已记录,正在预测本周走势..."));
|
||||
|
||||
Map<String, String> map = openTurnip(prices, pattern);
|
||||
if(map==null){
|
||||
map=openTurnip(prices,pattern);
|
||||
if (map == null) {
|
||||
map = openTurnip(prices, pattern);
|
||||
}
|
||||
String tmp_pattern = sendQQ(map, prices, pattern, qq);
|
||||
String tmp_pattern = sendQQ(map, prices, pattern);
|
||||
if (!StringUtils.isEmpty(tmp_pattern)) {
|
||||
json.put("pattern", tmp_pattern);
|
||||
}
|
||||
@@ -195,29 +218,32 @@ public class TurnipProphet extends Model {
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
setData(money, qq);
|
||||
setData(money);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private String sendQQ(Map<String, String> map, String prices, String pattern, long qq) {
|
||||
private String sendQQ(Map<String, String> map, String prices, String pattern) {
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
if (map == null) {
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
QQBotManager.getInstance().sendMessage(qq, "没有结果,请检查数据是否有误。 \n网页预览:\n" + url);
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage("没有结果,请检查数据是否有误。 \n网页预览:\n" + url));
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject pr = JSONObject.parseObject(map.get(TurnipData.MODEL));
|
||||
JSONObject pr = JSON.parseObject(map.get(TurnipData.MODEL));
|
||||
JSONArray prArray = pr.getJSONArray(TurnipData.MODEL);
|
||||
StringBuilder out = new StringBuilder();
|
||||
out.append("预测结果如下:\n");
|
||||
out.append(TurnipData.MODEL).append(prArray.getJSONObject(0).getString(TurnipData.MODEL)).append("\n");
|
||||
out.append(TurnipData.PR).append(prArray.getJSONObject(0).getString(TurnipData.PR)).append("\n");
|
||||
out.append("购入价:").append(prices.split("\\.")[0]).append("\n");
|
||||
if (getDay() == 0) {
|
||||
out.append("满背包(4行)购入价:").append(4000 * Integer.parseInt(prices.split("\\.")[0])).append("\n");
|
||||
}
|
||||
out.append(TurnipData.MIX).append(map.get(TurnipData.MIX)).append("\n")
|
||||
.append(TurnipData.MAX).append(map.get(TurnipData.MAX)).append("\n")
|
||||
.append(TurnipData.DAY).append(map.get(TurnipData.DAY)).append("\n")
|
||||
@@ -243,21 +269,28 @@ public class TurnipProphet extends Model {
|
||||
out.append(tmp.getString(TurnipData.MODEL)).append(":").append(tmp.getString(TurnipData.PR)).append("\n");
|
||||
}
|
||||
out.append("------------").append("\n");
|
||||
out.append("网页版:").append("\n").append(url).append("\n");
|
||||
out.append("祝好运 :)");
|
||||
|
||||
Log.i("TurnipProphet", out.toString());
|
||||
QQBotManager.getInstance().sendMessage(qq, out.toString());
|
||||
if (ConfigTools.load(ConfigTools.CONFIG, ConfigTools.TURNIP_PROPHET_SEND_TMP_GROUP, Boolean.class)) {
|
||||
out.append("\n使用者:").append(sendQQ);
|
||||
sendQQ = 891655174L;
|
||||
}
|
||||
|
||||
Log.i("TurnipProphet", out.toString() + "\n 发送QQ:" + sendQQ);
|
||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage(out.toString()));
|
||||
return prArray.getJSONObject(0).getString(TurnipData.MODEL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(String time) {
|
||||
super.onTime(time);
|
||||
public void onTime(Long qq, String time) {
|
||||
super.onTime(qq, time);
|
||||
nowTime = Integer.parseInt(time.split(":")[0]);
|
||||
}
|
||||
public int getTime(){
|
||||
if(nowTime==-1){
|
||||
nowTime=Integer.parseInt(AppTools.getHours());
|
||||
|
||||
public int getTime() {
|
||||
if (nowTime == -1) {
|
||||
nowTime = Integer.parseInt(AppTools.getHours());
|
||||
}
|
||||
return nowTime;
|
||||
}
|
||||
@@ -268,19 +301,23 @@ public class TurnipProphet extends Model {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
TurnipProphet prophet = new TurnipProphet();
|
||||
prophet.setData(68, 583819556);
|
||||
String prices = "108.93.89.84.79........";
|
||||
String pattern = "0";
|
||||
Map<String, String> map = prophet.openTurnip(prices, pattern);
|
||||
prophet.sendQQ(map, prices, pattern);
|
||||
|
||||
}
|
||||
|
||||
|
||||
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
||||
String url = String.format("https://turnipprophet.io?prices=%s%s",
|
||||
String url = String.format("http://%s/?prices=%s%s",
|
||||
ConfigTools.load(ConfigTools.CONFIG, ConfigTools.TURNIP_PROPHET_SERVER, String.class),
|
||||
prices,
|
||||
pattern == null ? "" : "&pattern=" + pattern
|
||||
);
|
||||
System.out.println("url = " + url);
|
||||
LinkedHashMap<String, String> map = new LinkedHashMap<>();
|
||||
WebDriver driver =WebClient.getInstance().getWebDriver();
|
||||
WebDriver driver = WebClient.getInstance().getWebDriver();
|
||||
|
||||
driver.get(url);
|
||||
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
|
||||
@@ -292,8 +329,7 @@ public class TurnipProphet extends Model {
|
||||
JSONObject pr = new JSONObject();
|
||||
JSONArray array = new JSONArray();
|
||||
if (list.size() == 0) {
|
||||
driver.close();
|
||||
driver.quit();
|
||||
WebClient.getInstance().quit();
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -330,28 +366,27 @@ public class TurnipProphet extends Model {
|
||||
}
|
||||
}
|
||||
}
|
||||
int maxMoney=0;
|
||||
String maxDay=null;
|
||||
int maxMoney = 0;
|
||||
String maxDay = null;
|
||||
for (String key : map.keySet()) {
|
||||
if(map.get(key).contains("~")){
|
||||
if (map.get(key).contains("~")) {
|
||||
for (String s : map.get(key).split("~")) {
|
||||
if(Integer.parseInt(s)>maxMoney){
|
||||
maxMoney=Integer.parseInt(s);
|
||||
maxDay=key;
|
||||
if (Integer.parseInt(s) > maxMoney) {
|
||||
maxMoney = Integer.parseInt(s);
|
||||
maxDay = key;
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(Integer.parseInt(map.get(key))>maxMoney){
|
||||
maxMoney=Integer.parseInt(map.get(key));
|
||||
maxDay=key;
|
||||
} else {
|
||||
if (Integer.parseInt(map.get(key)) > maxMoney) {
|
||||
maxMoney = Integer.parseInt(map.get(key));
|
||||
maxDay = key;
|
||||
}
|
||||
}
|
||||
}
|
||||
map.put(TurnipProphet.TurnipData.DAY, maxDay);
|
||||
pr.put(TurnipProphet.TurnipData.MODEL, array);
|
||||
map.put(TurnipProphet.TurnipData.MODEL, pr.toJSONString());
|
||||
driver.close();
|
||||
driver.quit();
|
||||
WebClient.getInstance().quit();
|
||||
return map;
|
||||
}
|
||||
}
|
||||
|
||||
139
src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java
Normal file
139
src/main/java/com/yutou/qqbot/models/BiliBili/BiliBiliLive.java
Normal file
@@ -0,0 +1,139 @@
|
||||
package com.yutou.qqbot.models.BiliBili;
|
||||
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.bilibili.BiliBiliUtils;
|
||||
import com.yutou.qqbot.bilibili.BiliLogin;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
@UseModel
|
||||
public class BiliBiliLive extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[]{
|
||||
Model.QQGroupCommands.BILI_LIVE_DANMU_LIST,
|
||||
Model.QQGroupCommands.BILI_LIVE_DANMU_SEND,
|
||||
QQGroupCommands.BILI_LIVE_DANMU_DEL
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "BiliBili Live Sign in";
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onTime(Long qq, String time) {
|
||||
super.onTime(qq, time);
|
||||
if ("07:01:00".equals(time)) {
|
||||
if (!new BiliLogin(QQBotManager.defQQ).testLogin()) {
|
||||
new BiliLogin(QQBotManager.defQQ).loginAsQQ();
|
||||
System.out.println(BiliBiliUtils.getInstance(QQBotManager.defQQ).getLoginInfo());
|
||||
return;
|
||||
}
|
||||
signLive(QQBotManager.defQQ, qq);
|
||||
}
|
||||
}
|
||||
|
||||
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<String> 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());
|
||||
/* BiliBiliAppUtils appUtils = new BiliBiliAppUtils(QQBotManager.defQQ);
|
||||
AppUserTask oldTask = appUtils.startAppTask();
|
||||
AppUserTask newTask = appUtils.getTaskProgress();
|
||||
builder = new StringBuilder();
|
||||
builder.append("执行APP任务").append("\n").append(AppUserTask.toMessageFormat(oldTask, newTask));
|
||||
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) &&
|
||||
!msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_LIST)) {
|
||||
return;
|
||||
}
|
||||
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 {
|
||||
boolean isDel = false;
|
||||
if (msg.startsWith(QQGroupCommands.BILI_LIVE_DANMU_DEL)) {
|
||||
isDel = true;
|
||||
msg = msg.replace(QQGroupCommands.BILI_LIVE_DANMU_DEL, "").trim();
|
||||
} 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 (!new BiliLogin(qq).testLogin()) {
|
||||
new BiliLogin(qq).loginAsQQ();
|
||||
return;
|
||||
}
|
||||
if (biliUtils.checkLiveRoom(roomId) && roomId != 0) {
|
||||
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 if (roomId != 0) {
|
||||
message.append("直播签到操作失败\n");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
message = new StringBuilder("直播签到添加失败\n");
|
||||
}
|
||||
message.append("-----直播签到房间号-----\n");
|
||||
Set<String> biliLive = RedisTools.list_get("bili_live");
|
||||
for (String id : biliLive) {
|
||||
message.append(id)
|
||||
.append(":")
|
||||
.append(biliUtils.getUserInfo(
|
||||
biliUtils.getLiveRoom(Integer.parseInt(id))
|
||||
.getJSONObject("data")
|
||||
.getInteger("uid"))
|
||||
.getJSONObject("data")
|
||||
.getString("name"))
|
||||
.append("\n");
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, message.toString());
|
||||
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
new BiliBiliLive().signLive(QQBotManager.defQQ, 0);
|
||||
}
|
||||
}
|
||||
435
src/main/java/com/yutou/qqbot/models/BiliBili/BiliVideo.java
Normal file
435
src/main/java/com/yutou/qqbot/models/BiliBili/BiliVideo.java
Normal file
@@ -0,0 +1,435 @@
|
||||
package com.yutou.qqbot.models.BiliBili;
|
||||
|
||||
import com.alibaba.fastjson2.JSONArray;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.enums.MessageEnum;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.napcat.handle.OtherHandle;
|
||||
import com.yutou.napcat.handle.Reply;
|
||||
import com.yutou.napcat.http.NapCatApi;
|
||||
import com.yutou.napcat.model.MessageBean;
|
||||
import com.yutou.okhttp.HttpBody;
|
||||
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;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import retrofit2.Response;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@UseModel
|
||||
public class BiliVideo extends Model {
|
||||
public String downloadPath = "tmp";
|
||||
List<DanmuData> 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() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "B站视频下载";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if (event.isAtMe() && event.hasType(MessageEnum.REPLY)) {
|
||||
Reply reply = event.findType(Reply.class);
|
||||
long id = reply.getData().getId();
|
||||
if (msg.contains("省流") || msg.contains("总结")) {
|
||||
String value = onAIVideo(id);
|
||||
if (!StringUtils.isEmpty(value)) {
|
||||
QQBotManager.getInstance().sendMessage(qq, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String onAIVideo(long id) {
|
||||
try {
|
||||
Response<HttpBody<MessageBean>> execute = NapCatApi.getMessageApi().getMessage(id).execute();
|
||||
if(execute.body()==null){
|
||||
return "省流失败";
|
||||
}
|
||||
MessageEvent handle = MessageEvent.parseHandleHttp(execute.body().getSrc());
|
||||
if (handle.hasType(MessageEnum.JSON)) {
|
||||
OtherHandle type = handle.findType(OtherHandle.class);
|
||||
String url = type.getData().getMeta().getDetail1().getQqdocurl();
|
||||
if (StringUtils.isEmpty(url)) {
|
||||
return "地址不正确";
|
||||
}
|
||||
if (url.startsWith("BV")) {
|
||||
url = "https://www.bilibili.com/video/" + url.trim();
|
||||
}
|
||||
if (!url.startsWith("https://www.bilibili.com/video/") && !url.startsWith("https://b23.tv")) {
|
||||
return "这是B站吗?";
|
||||
}
|
||||
String ai = BiliBiliAppUtils.getVideoAI(url.trim());
|
||||
if (!StringUtils.isEmpty(ai)) {
|
||||
return ai;
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
return "省流失败";
|
||||
}
|
||||
|
||||
public void downVideo(String url) {
|
||||
downVideo(url, true, false);
|
||||
}
|
||||
|
||||
public void downVideo(String url, boolean downDanmu, boolean merge) {
|
||||
if (biliUtils == null || !new BiliLogin(qq).testLogin()) {
|
||||
System.err.println("未登录");
|
||||
return;
|
||||
}
|
||||
if (!url.contains("?")) {
|
||||
url += "?";
|
||||
}
|
||||
danmuDatas.clear();
|
||||
JSONObject info = getVideoInfo(url);
|
||||
if (info.getInteger("code") == 0) {
|
||||
JSONObject infoData = info.getJSONObject("data");
|
||||
JSONObject eps = new JSONObject();
|
||||
if (infoData.containsKey("ugc_season")) {
|
||||
JSONObject ugc = infoData.getJSONObject("ugc_season");
|
||||
eps.put("title", ugc.getString("title"));
|
||||
JSONArray ep = new JSONArray();
|
||||
for (Object o : ugc.getJSONArray("sections")) {
|
||||
JSONObject season = (JSONObject) o;
|
||||
for (Object episodes : season.getJSONArray("episodes")) {
|
||||
JSONObject _epi = (JSONObject) episodes;
|
||||
JSONObject _item = new JSONObject();
|
||||
_item.put("title", season.getString("title") + "-" + _epi.getString("title"));
|
||||
_item.put("cid", _epi.getLong("cid"));
|
||||
_item.put("aid", _epi.getLong("aid"));
|
||||
ep.add(_item);
|
||||
}
|
||||
}
|
||||
eps.put("eps", ep);
|
||||
} else if (infoData.getInteger("videos") != 1) {
|
||||
JSONArray pages = infoData.getJSONArray("pages");
|
||||
JSONArray ep = new JSONArray();
|
||||
for (Object o : pages) {
|
||||
JSONObject page = (JSONObject) o;
|
||||
JSONObject _item = new JSONObject();
|
||||
_item.put("title", infoData.getString("title") + "-" + page.getString("part"));
|
||||
_item.put("cid", page.getLong("cid"));
|
||||
_item.put("aid", infoData.getLong("aid"));
|
||||
ep.add(_item);
|
||||
}
|
||||
eps.put("title", infoData.getString("title"));
|
||||
eps.put("eps", ep);
|
||||
} else {
|
||||
eps.put("title", infoData.getString("title"));
|
||||
eps.put("cid", infoData.getLong("cid"));
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("danmu", downDanmu);
|
||||
json.put("merge", merge);
|
||||
json.put("avid", infoData.getLong("aid"));
|
||||
if (eps.containsKey("cid")) {
|
||||
json.put("cid", eps.getLong("cid"));
|
||||
json.put("qn", 127);
|
||||
json.put("fnval", 80);
|
||||
json.put("fourk", 1);
|
||||
downVideo(json, eps);
|
||||
} else {
|
||||
System.out.println("json = " + json);
|
||||
System.out.println("eps = " + eps);
|
||||
List<File> list = new ArrayList<>();
|
||||
|
||||
String root = new File("tmp").getAbsolutePath() + File.separator;
|
||||
for (Object o : eps.getJSONArray("eps")) {
|
||||
JSONObject item = (JSONObject) o;
|
||||
json.put("avid", item.getLong("aid"));
|
||||
json.put("cid", item.getLong("cid"));
|
||||
json.put("qn", 127);
|
||||
json.put("fnval", 80);
|
||||
json.put("fourk", 1);
|
||||
item.put("title", eps.getString("title") + "$(File.separator)" + item.getString("title"));
|
||||
list.add(new File(root + StringUtils.toSaveFileName(item.getString("title") + ".mp4")));
|
||||
downVideo(json, item);
|
||||
if (downDanmu && merge) {
|
||||
long tmp = 0;
|
||||
for (VideoDanMu.DanmakuElem elem : buildDanmuHttp(json.getLong("cid"), json.getLong("avid"), 1)) {
|
||||
DanmuData danmuData = new DanmuData();
|
||||
danmuData.setDanmu(elem.getContent());
|
||||
danmuData.setFontSize(elem.getFontsize());
|
||||
danmuData.setTime(elem.getProgress() + danmuNextTime);
|
||||
danmuData.setFontColor(elem.getColor());
|
||||
danmuData.setModel(elem.getMode());
|
||||
if (elem.getProgress() > tmp) {
|
||||
tmp = elem.getProgress();
|
||||
}
|
||||
danmuDatas.add(danmuData);
|
||||
}
|
||||
danmuNextTime = tmp;
|
||||
}
|
||||
}
|
||||
if (merge) {
|
||||
merge(root, StringUtils.toSaveFileName(eps.getString("title")), list);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void merge(String root, String name, List<File> files) {
|
||||
String saveName = root + name;
|
||||
File fileList = new File(saveName + File.separator + "tmp.txt");
|
||||
System.out.println("fileList.getAbsolutePath() = " + fileList.getAbsolutePath());
|
||||
StringBuilder builder = new StringBuilder();
|
||||
int i = 0;
|
||||
List<File> tmp = new ArrayList<>();
|
||||
for (File file : files) {
|
||||
System.out.println("file.getName() = " + file.getName());
|
||||
file.renameTo(new File(file.getParentFile(), i + ".mp4"));
|
||||
tmp.add(new File(file.getParentFile(), i + ".mp4"));
|
||||
builder.append("file '").append(i++).append(".mp4'");
|
||||
builder.append("\n");
|
||||
}
|
||||
try {
|
||||
// boolean b = fileList.createNewFile();
|
||||
// System.out.println("b = " + b);
|
||||
FileWriter fw = new FileWriter(fileList);
|
||||
fw.write(builder.toString());
|
||||
fw.flush();
|
||||
fw.close();
|
||||
|
||||
String exec = String.format("cd \"%s\" && ffmpeg -f concat -i \"%s\" -c copy %s.mp4", saveName, "tmp.txt", name);
|
||||
System.out.println("exec = " + exec);
|
||||
AppTools.exec(exec, new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
// System.out.println(data);
|
||||
System.out.println("over");
|
||||
fileList.delete();
|
||||
for (File file : tmp) {
|
||||
file.delete();
|
||||
}
|
||||
AssTools tools = new AssTools(name);
|
||||
tools.addDanmu(danmuDatas);
|
||||
boolean saveDanmu = tools.saveDanmu(saveName);
|
||||
System.out.println("弹幕保存:" + saveDanmu);
|
||||
}
|
||||
}, false, false);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void downVideo(JSONObject json, JSONObject eps) {
|
||||
eps.put("title", StringUtils.toSaveFileName(eps.getString("title")));
|
||||
File tmp = new File(HttpTools.downloadPath + eps.getString("title") + ".mp4");
|
||||
if (json.getBooleanValue("danmu") && !json.getBooleanValue("merge")) {
|
||||
List<VideoDanMu.DanmakuElem> elems = buildDanmuHttp(json.getLong("cid"), json.getLong("avid"), 1);
|
||||
downDanmu("tmp", eps.getString("title"), elems);
|
||||
}
|
||||
if (tmp.exists()) {
|
||||
return;
|
||||
}
|
||||
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 = biliUtils.download(video.getString("baseUrl"), eps.getString("title") + "_video.mp4", false);
|
||||
if (videoFile == null) {
|
||||
downVideo(json, eps);
|
||||
return;
|
||||
}
|
||||
File audioFile = biliUtils.download(audio.getString("baseUrl"), eps.getString("title") + "_audio.mp3", false);
|
||||
if (audioFile == null) {
|
||||
videoFile.delete();
|
||||
downVideo(json, eps);
|
||||
return;
|
||||
}
|
||||
save(eps.getString("title"), videoFile, audioFile);
|
||||
}
|
||||
}
|
||||
|
||||
private void downDanmu(String savePath, String title, List<VideoDanMu.DanmakuElem> danmuList) {
|
||||
try {
|
||||
AssTools tools = new AssTools(title);
|
||||
List<DanmuData> list = new ArrayList<>();
|
||||
for (VideoDanMu.DanmakuElem elem : danmuList) {
|
||||
DanmuData danmuData = new DanmuData();
|
||||
danmuData.setDanmu(elem.getContent());
|
||||
danmuData.setFontSize(elem.getFontsize());
|
||||
danmuData.setTime(elem.getProgress());
|
||||
danmuData.setFontColor(elem.getColor());
|
||||
danmuData.setModel(elem.getMode());
|
||||
list.add(danmuData);
|
||||
}
|
||||
tools.addDanmu(list);
|
||||
boolean saveDanmu = tools.saveDanmu(savePath);
|
||||
System.out.println("弹幕保存:" + saveDanmu);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private List<VideoDanMu.DanmakuElem> buildDanmuHttp(long cid, long avid, int segment_index) {
|
||||
List<VideoDanMu.DanmakuElem> tmp, danmuList = new ArrayList<>();
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("type", 1);
|
||||
json.put("oid", cid);
|
||||
json.put("avid", avid);
|
||||
json.put("segment_index", segment_index);
|
||||
while (!(tmp = getDanmu(json)).isEmpty()) {
|
||||
danmuList.addAll(tmp);
|
||||
json.put("segment_index", ++segment_index);
|
||||
}
|
||||
return danmuList;
|
||||
}
|
||||
|
||||
private List<VideoDanMu.DanmakuElem> getDanmu(JSONObject json) {
|
||||
try {
|
||||
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) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return new ArrayList<>();
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void save(String name, File videoFile, File audioFile) {
|
||||
List<String> urls = new ArrayList<>();
|
||||
urls.add(videoFile.getAbsolutePath());
|
||||
urls.add(audioFile.getAbsolutePath());
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(ConfigTools.load(ConfigTools.CONFIG, "ffmpeg", String.class)).append(" ");
|
||||
for (String _url : urls) {
|
||||
builder.append("-i").append(" ");
|
||||
builder.append("\"").append(_url).append("\"").append(" ");
|
||||
}
|
||||
builder.append("-vcodec").append(" ");
|
||||
builder.append("copy").append(" ");
|
||||
builder.append("-acodec").append(" ");
|
||||
builder.append("copy").append(" ");
|
||||
builder.append("-threads").append(" ");
|
||||
builder.append("8").append(" ");
|
||||
// builder.append("-y").append(" ");
|
||||
builder.append("\"").append(new File(HttpTools.downloadPath + name + ".mp4").getAbsolutePath()).append("\"").append(" ");
|
||||
System.out.println(builder);
|
||||
AppTools.exec(builder.toString(), new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
videoFile.delete();
|
||||
audioFile.delete();
|
||||
}
|
||||
|
||||
}, false, false);
|
||||
}
|
||||
|
||||
public JSONObject getVideoInfo(String url) {
|
||||
if (!new BiliLogin(qq).testLogin()) {
|
||||
System.err.println("未登录");
|
||||
return null;
|
||||
}
|
||||
JSONObject json = buildJSON(url);
|
||||
if (json != null) {
|
||||
return biliUtils.http("https://api.bilibili.com/x/web-interface/view?" + HttpTools.toUrlParams(json), BiliBiliUtils.HTTP.GET, null, BiliBiliUtils.RET_MODEL.JSON);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private JSONObject buildJSON(String url) {
|
||||
if (!url.contains("?")) {
|
||||
url += "?";
|
||||
}
|
||||
Pattern pattern = Pattern.compile("(?<=video/).*?(?=\\?)");
|
||||
Matcher matcher = pattern.matcher(url);
|
||||
String id = null;
|
||||
if (matcher.find()) {
|
||||
id = matcher.group();
|
||||
}
|
||||
if (id == null) {
|
||||
return null;
|
||||
}
|
||||
if (id.contains("/")) {
|
||||
id = id.replace("/", "");
|
||||
}
|
||||
JSONObject json = new JSONObject();
|
||||
if (id.startsWith("BV")) {
|
||||
json.put("bvid", id);
|
||||
} else {
|
||||
json.put("avid", id.toLowerCase().replace("av", ""));
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
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");
|
||||
//唐诱 合集
|
||||
//video.downVideo("https://www.bilibili.com/video/BV1Vv4y1K7ox?spm_id_from=444.41.top_right_bar_window_default_collection.content.click");
|
||||
//邦邦 长视频
|
||||
// video.downVideo("https://www.bilibili.com/video/BV1w5411271A?spm_id_from=444.41.list.card_archive.click");
|
||||
//LK 超清4k hdr
|
||||
//video.downVideo("https://www.bilibili.com/video/BV1uZ4y1U7h8/?spm_id_from=333.788.recommend_more_video.-1");
|
||||
// hdr
|
||||
// video.downVideo("https://www.bilibili.com/video/BV1rp4y1e745/?spm_id_from=333.788.recommend_more_video.-1");
|
||||
// 1080+ 60fps
|
||||
//video.downVideo("https://www.bilibili.com/video/BV1qF411T7Vf?spm_id_from=444.41.list.card_archive.click");
|
||||
//唐诱正片
|
||||
//video.downVideo("https://www.bilibili.com/video/BV1L44y147zR?spm_id_from=333.999.0.0");// ep1
|
||||
//video.downVideo("https://www.bilibili`.com/video/BV1Zu4y1B7DU/?spm_id_from=333.337.search-card.all.click", true, false);// ep5
|
||||
// video.downVideo("https://www.bilibili.com/video/BV1SL411g7FS/?spm_id_from=333.788.recommend_more_video.0"); //all ig 1\5
|
||||
|
||||
// video.downVideo("https://www.bilibili.com/video/BV18L4y1H7rz?spm_id_from=333.999.0.0");
|
||||
// video.downVideo("https://www.bilibili.com/video/BV1Pe4y1Q7MX?spm_id_from=444.41.top_right_bar_window_history.content.click");
|
||||
// int a=16|2048;
|
||||
// System.out.println("a = " + a);
|
||||
//video.downDanmu(428855000L,976216102L,"【都市_情感】《唐可可的诱惑》第一集",1);
|
||||
video.downVideo("https://www.bilibili.com/bangumi/play/ep776259", false, false);// ep5
|
||||
System.out.println("事件结束");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
@UseModel
|
||||
public class BTDownload extends Model {
|
||||
private static final String DownloadHomePath = "/media/yutou/disk_lvm/public/download/";
|
||||
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[]{
|
||||
QQFromCommands.BT_DOWNLOAD
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "添加BT下载";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if (msg.startsWith("magnet:?xt=")) {
|
||||
String builder = "已添加下载磁链";
|
||||
JSONObject json = new JSONObject();
|
||||
json.put("url", msg.trim());
|
||||
json.put("title", "qqbot/" + System.currentTimeMillis() + ".torrent");
|
||||
String post = HttpTools.post(ConfigTools.getServerUrl()+"qq/bt/download.do", json.toString().getBytes(StandardCharsets.UTF_8));
|
||||
builder += "\n" + post;
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, builder);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,17 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@UseModel
|
||||
public class BaiduDown extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
@@ -22,19 +25,24 @@ public class BaiduDown extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "同步百度云";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if(msg.startsWith(QQFromCommands.BAIDU_DOWN)){
|
||||
QQBotManager.getInstance().sendMessage(qq,"开始同步百度云");
|
||||
AppTools.exec("cd "+new File("baidupan").getAbsolutePath()+" && bypy downdir -v", new ObjectInterface() {
|
||||
if (msg.startsWith(QQFromCommands.BAIDU_DOWN)) {
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("开始同步百度云"));
|
||||
AppTools.exec("cd " + new File("baidupan").getAbsolutePath() + " && bypy downdir -v", new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
Log.i(data);
|
||||
QQBotManager.getInstance().sendMessage(qq,"任务完成");
|
||||
QQBotManager.getInstance().sendMessage(qq, "任务完成");
|
||||
}
|
||||
},true,true);
|
||||
}, true, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
115
src/main/java/com/yutou/qqbot/models/Commands/BaiduGPT.java
Normal file
115
src/main/java/com/yutou/qqbot/models/Commands/BaiduGPT.java
Normal file
@@ -0,0 +1,115 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.handle.At;
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.data.baidu.ResponseMessage;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.BaiduGPTManager;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.qqbot.utlis.ConfigTools;
|
||||
import com.yutou.qqbot.utlis.StringUtils;
|
||||
import lombok.val;
|
||||
import org.apache.catalina.valves.JsonErrorReportValve;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@UseModel
|
||||
public class BaiduGPT extends Model {
|
||||
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[]{
|
||||
QQGroupCommands.GPT,
|
||||
QQGroupCommands.GPT_CLEAR
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "百度文言一心GPT";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
String version = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_VERSION, String.class);
|
||||
if (StringUtils.isEmpty(version)) {
|
||||
version = "3.5";
|
||||
BaiduGPTManager.getManager().setModelFor35();
|
||||
}
|
||||
if ("3.5".equals(version)) {
|
||||
BaiduGPTManager.getManager().setModelFor35();
|
||||
} else if ("4.0".equals(version)) {
|
||||
BaiduGPTManager.getManager().setModelFor40();
|
||||
}
|
||||
if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) {
|
||||
BaiduGPTManager.getManager().clear();
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏"));
|
||||
} else if (event.isAtMe()) {
|
||||
if (event.getTextMessage().contains("省流") || event.getTextMessage().contains("总结")) {
|
||||
return;
|
||||
}
|
||||
if ("GPT切换到4.0".equals(event.getTextMessage())) {
|
||||
List<BaseHandle<?>> list = new ArrayList<>();
|
||||
if (isAdmin()) {
|
||||
list.add(new At(user));
|
||||
list.add(new Text("切换为4.0了"));
|
||||
BaiduGPTManager.getManager().clear();
|
||||
BaiduGPTManager.getManager().setModelFor40();
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||
} else {
|
||||
list.add(new At(user));
|
||||
list.add(new Text("你没有权限"));
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||
}
|
||||
return;
|
||||
} else if ("GPT切换到3.5".equals(event.getTextMessage())) {
|
||||
List<BaseHandle<?>> list = new ArrayList<>();
|
||||
if (isAdmin()) {
|
||||
list.add(new At(user));
|
||||
list.add(new Text("切换为3.5了"));
|
||||
BaiduGPTManager.getManager().clear();
|
||||
BaiduGPTManager.getManager().setModelFor35();
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||
}else {
|
||||
list.add(new At(user));
|
||||
list.add(new Text("你没有权限"));
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||
}
|
||||
return;
|
||||
}
|
||||
ResponseMessage message = BaiduGPTManager.getManager().sendMessage(
|
||||
String.valueOf(qq),
|
||||
event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim());
|
||||
String sb = "调用版本:" +
|
||||
BaiduGPTManager.getManager().getGPTVersion() +
|
||||
"\n" +
|
||||
message.getResult();
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text(sb));
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
System.out.println(ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_VERSION));
|
||||
val messageEvent = new MessageEvent();
|
||||
messageEvent.setMessage(new ArrayList<>());
|
||||
messageEvent.setRawMessage("");
|
||||
new BaiduGPT().onMessage(123456789L, messageEvent, false);
|
||||
BaiduGPTManager.getManager().clear();
|
||||
BaiduGPTManager.getManager().setModelFor40();
|
||||
new BaiduGPT().onMessage(123456789L, messageEvent, false);
|
||||
/* BaiduGPTManager.getManager().clear();
|
||||
BaiduGPTManager.getManager().setModelFor35();
|
||||
new BaiduGPT().onMessage(123456789L, messageEvent, false);*/
|
||||
}
|
||||
}
|
||||
@@ -1,20 +1,21 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.napcat.handle.BaseHandle;
|
||||
import com.yutou.napcat.handle.Image;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.DownloadInterface;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.BangumiTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@UseModel
|
||||
public class Bangumi extends Model {
|
||||
|
||||
|
||||
@@ -22,27 +23,28 @@ public class Bangumi extends Model {
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
|
||||
if(!isGroupPower){
|
||||
return;
|
||||
}
|
||||
switch (msg){
|
||||
switch (msg) {
|
||||
case QQGroupCommands.QQ_BANGUMI_TODAY -> {
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "获取中...");
|
||||
RedisTools.remove("reportToDayBangumi");
|
||||
QQBotManager.getInstance().sendMessage(qq, BangumiTools.reportToDayBangumi());
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text(BangumiTools.reportToDayBangumi()));
|
||||
}
|
||||
case QQGroupCommands.QQ_BANGUMI_LIST -> {
|
||||
QQBotManager.getInstance().sendMessage(qq,"获取中...");
|
||||
QQBotManager.getInstance().sendMessage(qq,BangumiTools.reportBangumiList());
|
||||
}default -> {
|
||||
if(msg.startsWith(QQGroupCommands.QQ_BANGUMI_SUB)){
|
||||
subBanGumi(qq,msg);
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "获取中...");
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, BangumiTools.reportBangumiList());
|
||||
}
|
||||
default -> {
|
||||
if (msg.startsWith(QQGroupCommands.QQ_BANGUMI_SUB)) {
|
||||
subBanGumi(qq, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
private void subBanGumi(long qq,String msg){
|
||||
|
||||
private void subBanGumi(long qq, String msg) {
|
||||
List<String> infos = null;
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "获取中...");
|
||||
try {
|
||||
int id = Integer.parseInt(msg.replace(QQGroupCommands.QQ_BANGUMI_SUB, "").trim());
|
||||
infos = BangumiTools.reportBangumiInfo(id);
|
||||
@@ -58,9 +60,10 @@ public class Bangumi extends Model {
|
||||
info = info.replace("<img " + img + " /img>", "");
|
||||
}
|
||||
}
|
||||
sendImagesMsg(imgs,qq, info);
|
||||
sendImagesMsg(imgs, qq, info, msg.replace(QQGroupCommands.QQ_BANGUMI_SUB, "").trim());
|
||||
}
|
||||
}
|
||||
|
||||
public static List<String> getImages(String str) {
|
||||
List<String> list = new ArrayList<>();
|
||||
String regex = "<img(.*?)/img>";
|
||||
@@ -73,40 +76,21 @@ public class Bangumi extends Model {
|
||||
}
|
||||
return list;
|
||||
}
|
||||
private List<File> files;
|
||||
|
||||
private int index = 0;
|
||||
|
||||
private void sendImagesMsg(List<String> imgs,Long qq, String text) {
|
||||
files = new ArrayList<>();
|
||||
private void sendImagesMsg(List<String> imgs, Long qq, String text, String key) {
|
||||
index = 0;
|
||||
if (imgs.size() == 0) {
|
||||
QQBotManager.getInstance().sendMessage(qq,text);
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, text);
|
||||
return;
|
||||
}
|
||||
List<BaseHandle<?>> list = new ArrayList<>();
|
||||
for (String img : imgs) {
|
||||
HttpTools.download(img,null, new DownloadInterface() {
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
files.add(file);
|
||||
send(imgs.size(),qq, text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
index++;
|
||||
send(imgs.size(),qq, text);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void send(int size,Long qq, String text) {
|
||||
if ((files.size() + index) == size) {
|
||||
String str = QQBotManager.getInstance().sendMessage(files,qq, text);
|
||||
Log.i("str = " + str);
|
||||
list.add(new Image(img.replace("http://", "https://")));
|
||||
}
|
||||
list.add(new Text(text));
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, list);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -124,10 +108,16 @@ public class Bangumi extends Model {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(String time) {
|
||||
super.onTime(time);
|
||||
public String getModelName() {
|
||||
return "新番列表";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTime(Long qq, String time) {
|
||||
super.onTime(qq, time);
|
||||
switch (time) {
|
||||
case "08:00", "20:00" -> QQBotManager.getInstance().sendMessage(QQBotManager.defGroup,BangumiTools.reportToDayBangumi());
|
||||
case "08:00:00", "20:00:00" ->
|
||||
QQBotManager.getInstance().sendMessage(qq, BangumiTools.reportToDayBangumi());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.napcat.handle.QuoteReply;
|
||||
import com.yutou.napcat.handle.Reply;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.data.MessageChainBuilder;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
|
||||
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"))) {
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq,
|
||||
new Reply(user),
|
||||
new Text("别水了,快去打工,没钱氪老婆了")
|
||||
);
|
||||
RedisTools.set("maomao_work_" + AppTools.getToDayTime(), "true", 20 * 60 * 60);
|
||||
}
|
||||
}
|
||||
}
|
||||
94
src/main/java/com/yutou/qqbot/models/Commands/Moyu.java
Normal file
94
src/main/java/com/yutou/qqbot/models/Commands/Moyu.java
Normal file
@@ -0,0 +1,94 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.alibaba.fastjson2.JSON;
|
||||
import com.alibaba.fastjson2.JSONObject;
|
||||
import com.yutou.napcat.QQDatabase;
|
||||
import com.yutou.napcat.handle.Image;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.DownloadInterface;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import com.yutou.qqbot.utlis.Log;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@UseModel
|
||||
public class Moyu extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "摸鱼提醒";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if (msg.equals(QQGroupCommands.QQ_MOYU)) {
|
||||
send(qq);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public synchronized void onTime(Long qq, String time) {
|
||||
super.onTime(qq, time);
|
||||
if ("09:50:00".equals(time)) {
|
||||
// downloadImage(false, qq);
|
||||
}
|
||||
if ("10:00:00".equals(time)) {
|
||||
send(qq);
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadImage(boolean isSend, Long qq) {
|
||||
Log.i(this, "下载图片");
|
||||
String ret = HttpTools.get("https://api.vvhan.com/api/moyu?type=json");
|
||||
JSONObject json = JSON.parseObject(ret);
|
||||
HttpTools.download(json.getString("url"), AppTools.getToDayTime() + "_moyu.jpg", new DownloadInterface() {
|
||||
int count = 3;
|
||||
|
||||
@Override
|
||||
public void onDownload(File file) {
|
||||
super.onDownload(file);
|
||||
if (isSend) {
|
||||
send(qq);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception e) {
|
||||
super.onError(e);
|
||||
e.printStackTrace();
|
||||
if (count == 0) {
|
||||
return;
|
||||
}
|
||||
downloadImage(isSend, qq);
|
||||
count--;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void send(Long qq) {
|
||||
|
||||
String ret = HttpTools.get("https://api.vvhan.com/api/moyu?type=json");
|
||||
JSONObject json = JSON.parseObject(ret);
|
||||
QQBotManager.getInstance().sendMessage(QQDatabase.checkFriend(qq), qq,
|
||||
new Image(json.getString("url"))
|
||||
);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.napcat.handle.QuoteReply;
|
||||
import com.yutou.napcat.handle.Reply;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.data.MessageChainBuilder;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.AppTools;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
|
||||
import static com.yutou.qqbot.models.Model.QQGroupCommands.QQ_TIMEOUT;
|
||||
|
||||
@UseModel
|
||||
public class PaoPaoSleepWaring 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())>=22 && event.getSource().getFromId() == 914520754
|
||||
&& "false".equals(RedisTools.get("paopao_sleep_"+AppTools.getToDayTime(),"false"))){
|
||||
// builder.append(new QuoteReply(event.getMessage().getId()));
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(),qq,
|
||||
new Reply(user),
|
||||
new Text("别水了,该睡了~")
|
||||
);
|
||||
RedisTools.set("paopao_sleep_"+AppTools.getToDayTime(),"true",1*60*60);
|
||||
}
|
||||
/*if(event.getSource().getFromId() == 914520754 && msg.contains("#体力")){
|
||||
MessageChainBuilder builder=new MessageChainBuilder();
|
||||
builder.append(new At(369224573L));
|
||||
builder.append("惠城! 体力! ");
|
||||
QQBotManager.getInstance().sendMessage(qq,builder);
|
||||
}*/
|
||||
}
|
||||
}
|
||||
148
src/main/java/com/yutou/qqbot/models/Commands/QQBean.java
Normal file
148
src/main/java/com/yutou/qqbot/models/Commands/QQBean.java
Normal file
@@ -0,0 +1,148 @@
|
||||
package com.yutou.qqbot.models.Commands;
|
||||
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
import com.yutou.napcat.handle.At;
|
||||
import com.yutou.napcat.handle.Text;
|
||||
import com.yutou.napcat.http.NapCatApi;
|
||||
import com.yutou.napcat.model.GroupUserBean;
|
||||
import com.yutou.okhttp.BaseBean;
|
||||
import com.yutou.okhttp.HttpCallback;
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
@UseModel
|
||||
public class QQBean extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getUsePowers() {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "QQ禁言";
|
||||
}
|
||||
|
||||
Random random = new Random();
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
if (!isGroup) return;
|
||||
if ("抽奖".equals(msg)) {
|
||||
int hour = 60;
|
||||
int day = 1440;
|
||||
int max = 30 * day;
|
||||
int time = 1;
|
||||
if (random.nextInt(100) == 23) {
|
||||
releaseAll(qq, true);
|
||||
} else if (random.nextInt(10) > 2) {
|
||||
time = random.nextInt(hour);
|
||||
} else if (random.nextInt(10) > 4) {
|
||||
time = random.nextInt(day);
|
||||
} else if (random.nextInt(10) > 5) {
|
||||
time = random.nextInt(day, 3 * day);
|
||||
} else {
|
||||
time = random.nextInt(max);
|
||||
|
||||
}
|
||||
int sendTime = time;
|
||||
QQBotManager.getInstance().groupBan(qq, user, sendTime * 60, new ObjectInterface() {
|
||||
@Override
|
||||
public void out(String data) {
|
||||
super.out(data);
|
||||
if (data != null) {
|
||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq,
|
||||
new Text("恭喜"),
|
||||
new At(user),
|
||||
new Text("获得了" + sendTime + "分钟的禁言," + sendAchievement(qq, user, sendTime))
|
||||
);
|
||||
if (sendTime > day && random.nextInt(10) >= 3) {
|
||||
int tmp = random.nextInt(sendTime / 2, sendTime);
|
||||
QQBotManager.getInstance().groupBan(qq, user, (sendTime - tmp) * 60, null);
|
||||
QQBotManager.getInstance().sendMessage(qq, "触发减伤:-" + tmp);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
} else if ("大赦天下".equals(msg) && isAdmin()) {
|
||||
releaseAll(qq, true);
|
||||
} else if ("查看禁言列表".equals(msg) && isAdmin()) {
|
||||
releaseAll(qq, false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
String sendAchievement(long qq, long user, int timer) {
|
||||
Calendar data1 = Calendar.getInstance();
|
||||
Calendar data2 = Calendar.getInstance();
|
||||
data1.setTime(new Date());
|
||||
data2.set(Calendar.HOUR_OF_DAY, 23);
|
||||
data2.set(Calendar.MINUTE, 59);
|
||||
data2.set(Calendar.SECOND, 59);
|
||||
long time = data2.getTimeInMillis() - data1.getTimeInMillis();
|
||||
String achievement = RedisTools.get("shut_" + qq + "_" + user);
|
||||
int achievementTimer = timer;
|
||||
if (achievement != null) {
|
||||
achievementTimer += Integer.parseInt(achievement);
|
||||
}
|
||||
RedisTools.set("shut_" + qq + "_" + user, achievementTimer + "", time / 1000);
|
||||
return "今日累计" + achievementTimer + "分钟禁言";
|
||||
}
|
||||
|
||||
void releaseAll(long qq, boolean isRelease) {
|
||||
QQBotManager.getInstance().getShutUpList(qq, new HttpCallback<List<GroupUserBean>>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, List<GroupUserBean> response, String rawResponse) {
|
||||
List<GroupUserBean> shutList = new ArrayList<>();
|
||||
for (GroupUserBean bean : response) {
|
||||
if (bean.getShutUpTimestamp() > 60) {
|
||||
shutList.add(bean);
|
||||
}
|
||||
}
|
||||
if (!shutList.isEmpty()) {
|
||||
|
||||
if (!isRelease) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (GroupUserBean bean : shutList) {
|
||||
sb.append(bean.getNickname()).append(":").append(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss",Locale.CHINA).format(new Date(bean.getShutUpTimestamp()))).append("\n");
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "当前塞了:" + shutList.size() + "人" + "\n" + sb);
|
||||
return;
|
||||
}
|
||||
QQBotManager.getInstance().sendMessage(qq, "触发自动解禁,解禁人数:" + shutList.size() + "人");
|
||||
for (GroupUserBean bean : shutList) {
|
||||
NapCatApi.getGroupApi().groupBan(qq, bean.getUserId(), 0).enqueue(new HttpCallback<BaseBean>() {
|
||||
@Override
|
||||
public void onResponse(int code, String status, BaseBean response, String rawResponse) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
QQBotManager.getInstance().sendMessage(qq, "阿巴阿巴");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Throwable throwable) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.yutou.qqbot.models.Commands.System;
|
||||
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.models.audio.QQAudio;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
@UseModel
|
||||
public class Audio extends Model {
|
||||
|
||||
@Override
|
||||
@@ -20,6 +21,11 @@ public class Audio extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "音频播放";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
package com.yutou.qqbot.models.Commands.System;
|
||||
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.QQBotManager;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.HttpTools;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
@UseModel
|
||||
public class BtFlash extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
@@ -18,6 +19,11 @@ public class BtFlash extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "刷新bt";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package com.yutou.qqbot.models.Commands.System;
|
||||
|
||||
import com.yutou.qqbot.Annotations.UseModel;
|
||||
import com.yutou.qqbot.models.Model;
|
||||
import com.yutou.qqbot.utlis.RedisTools;
|
||||
import net.mamoe.mirai.event.events.MessageEvent;
|
||||
|
||||
import com.yutou.napcat.event.MessageEvent;
|
||||
@UseModel
|
||||
public class Cmd extends Model {
|
||||
@Override
|
||||
public boolean isUserPublic() {
|
||||
@@ -18,6 +19,11 @@ public class Cmd extends Model {
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getModelName() {
|
||||
return "cmd指令";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||
super.onMessage(qq, event, isGroup);
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user