Compare commits
8 Commits
632b11d242
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
| 237c9273ca | |||
| 607c05e028 | |||
| df0337b006 | |||
| ebe96127e5 | |||
| 120392be17 | |||
| 6ed42d3e80 | |||
| 9903056551 | |||
| 10c4459936 |
7
pom.xml
7
pom.xml
@@ -158,7 +158,12 @@
|
|||||||
<artifactId>retrofit</artifactId>
|
<artifactId>retrofit</artifactId>
|
||||||
<version>2.11.0</version>
|
<version>2.11.0</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<!-- jsoup HTML parser library @ https://jsoup.org/ -->
|
||||||
|
<groupId>org.jsoup</groupId>
|
||||||
|
<artifactId>jsoup</artifactId>
|
||||||
|
<version>1.17.2</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
@@ -70,9 +70,9 @@ public class MessageEvent {
|
|||||||
|
|
||||||
public static MessageEvent parseHandle(String jsonString) {
|
public static MessageEvent parseHandle(String jsonString) {
|
||||||
JSONObject json = JSONObject.parseObject(jsonString);
|
JSONObject json = JSONObject.parseObject(jsonString);
|
||||||
|
|
||||||
JSONArray array = json.getJSONArray("message");
|
JSONArray array = json.getJSONArray("message");
|
||||||
List<BaseHandle<?>> messageList = new ArrayList<>();
|
List<BaseHandle<?>> messageList = new ArrayList<>();
|
||||||
|
if (array != null) {
|
||||||
for (Object o : array) {
|
for (Object o : array) {
|
||||||
JSONObject _json = (JSONObject) o;
|
JSONObject _json = (JSONObject) o;
|
||||||
Type classType = null;
|
Type classType = null;
|
||||||
@@ -93,32 +93,40 @@ public class MessageEvent {
|
|||||||
}
|
}
|
||||||
messageList.add(handle);
|
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();
|
SourceFrom sender = new SourceFrom();
|
||||||
|
sender.setUserId(event.getUserId());
|
||||||
|
event.setSource(sender);
|
||||||
sender.setUserId(json.getJSONObject("sender").getLong("user_id"));
|
sender.setUserId(json.getJSONObject("sender").getLong("user_id"));
|
||||||
sender.setNickname(json.getJSONObject("sender").getString("nickname"));
|
sender.setNickname(json.getJSONObject("sender").getString("nickname"));
|
||||||
sender.setCard(json.getJSONObject("sender").getString("card"));
|
sender.setCard(json.getJSONObject("sender").getString("card"));
|
||||||
|
|
||||||
MessageEvent event = new MessageEvent();
|
|
||||||
event.setSelfId(json.getLong("self_id"));
|
|
||||||
event.setUserId(json.getLong("user_id"));
|
|
||||||
event.setTime(json.getLong("time"));
|
|
||||||
event.setMessageId(json.getInteger("message_id"));
|
event.setMessageId(json.getInteger("message_id"));
|
||||||
event.setRealId(json.getInteger("real_id"));
|
event.setRealId(json.getInteger("real_id"));
|
||||||
event.setMessageType(json.getString("message_type"));
|
event.setMessageType(json.getString("message_type"));
|
||||||
event.setSource(sender);
|
event.setSource(sender);
|
||||||
event.setRawMessage(json.getString("raw_message"));
|
event.setRawMessage(json.getString("raw_message"));
|
||||||
event.setFont(json.getInteger("font"));
|
event.setFont(json.getInteger("font"));
|
||||||
event.setSubType(json.getString("sub_type"));
|
|
||||||
event.setMessageFormat(json.getString("message_format"));
|
event.setMessageFormat(json.getString("message_format"));
|
||||||
event.setPostType(json.getString("post_type"));
|
|
||||||
event.setGroupId(json.getLong("group_id"));
|
|
||||||
event.setMessage(messageList);
|
event.setMessage(messageList);
|
||||||
return event;
|
return event;
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.err.println("jsonString:\n" + jsonString);
|
||||||
|
}
|
||||||
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasType(MessageEnum messageEnum) {
|
public boolean hasType(MessageEnum messageEnum) {
|
||||||
|
if(message==null||message.isEmpty()){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
for (BaseHandle<?> handle : message) {
|
for (BaseHandle<?> handle : message) {
|
||||||
if (MessageEnum.of(handle.getType()) == messageEnum) {
|
if (MessageEnum.of(handle.getType()) == messageEnum) {
|
||||||
return true;
|
return true;
|
||||||
@@ -129,6 +137,9 @@ public class MessageEvent {
|
|||||||
|
|
||||||
public <T extends BaseHandle> List<T> findAllType(Class<T> t) {
|
public <T extends BaseHandle> List<T> findAllType(Class<T> t) {
|
||||||
List<T> tmp = new ArrayList<>();
|
List<T> tmp = new ArrayList<>();
|
||||||
|
if (message == null || message.isEmpty()) {
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
T newed = t.getDeclaredConstructor().newInstance();
|
T newed = t.getDeclaredConstructor().newInstance();
|
||||||
for (BaseHandle<?> baseHandle : message) {
|
for (BaseHandle<?> baseHandle : message) {
|
||||||
|
|||||||
@@ -15,10 +15,10 @@ import java.util.List;
|
|||||||
public interface GroupApi {
|
public interface GroupApi {
|
||||||
/**
|
/**
|
||||||
* 禁言
|
* 禁言
|
||||||
|
*
|
||||||
* @param group 群号
|
* @param group 群号
|
||||||
* @param user 用户
|
* @param user 用户
|
||||||
* @param duration 禁言时长,单位秒
|
* @param duration 禁言时长,单位秒
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("/set_group_ban")
|
@POST("/set_group_ban")
|
||||||
@@ -30,6 +30,7 @@ public interface GroupApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 禁言群组全体成员
|
* 禁言群组全体成员
|
||||||
|
*
|
||||||
* @param group 群号
|
* @param group 群号
|
||||||
*/
|
*/
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@@ -61,11 +62,28 @@ public interface GroupApi {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取群组成员列表
|
* 获取群组成员列表
|
||||||
|
*
|
||||||
* @param group 群号
|
* @param group 群号
|
||||||
*/
|
*/
|
||||||
@FormUrlEncoded
|
@FormUrlEncoded
|
||||||
@POST("/get_group_member_list")
|
@POST("/get_group_member_list")
|
||||||
Call<HttpBody<GroupUserBean>> getGroupUserList(
|
Call<HttpBody<List<GroupUserBean>>> getGroupUserList(
|
||||||
@Field("group_id") long group
|
@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 );
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,5 +65,8 @@ public class GroupUserBean extends BaseBean {
|
|||||||
// 是否允许修改群名片
|
// 是否允许修改群名片
|
||||||
@JSONField(name = "card_changeable")
|
@JSONField(name = "card_changeable")
|
||||||
private boolean cardChangeable;
|
private boolean cardChangeable;
|
||||||
|
// 禁言剩余时间
|
||||||
|
@JSONField(name = "shut_up_timestamp")
|
||||||
|
private long shutUpTimestamp;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package com.yutou.qqbot.Controllers;
|
|||||||
|
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.yutou.napcat.QQDatabase;
|
import com.yutou.napcat.QQDatabase;
|
||||||
|
import com.yutou.napcat.handle.At;
|
||||||
import com.yutou.napcat.handle.BaseHandle;
|
import com.yutou.napcat.handle.BaseHandle;
|
||||||
import com.yutou.napcat.handle.Image;
|
import com.yutou.napcat.handle.Image;
|
||||||
import com.yutou.napcat.handle.Text;
|
import com.yutou.napcat.handle.Text;
|
||||||
@@ -22,6 +23,8 @@ import javax.servlet.http.HttpServletRequest;
|
|||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
public class AppController {
|
public class AppController {
|
||||||
@@ -71,10 +74,14 @@ public class AppController {
|
|||||||
if (json.getString("message").isEmpty()) {
|
if (json.getString("message").isEmpty()) {
|
||||||
return "not message";
|
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")),
|
SendMessageResponse sent = QQBotManager.getInstance().sendMessage(QQDatabase.checkFriend(json.getLong("qq")),
|
||||||
json.getLong("qq"),
|
json.getLong("qq"),
|
||||||
new Text(json.getString("message")),
|
list
|
||||||
new Image(json.getString("image"))
|
|
||||||
);
|
);
|
||||||
return sent == null ? "0" : sent.getId() + "";
|
return sent == null ? "0" : sent.getId() + "";
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class MiRouterDevices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private String getRemoteAddress(String ip) {
|
private String getRemoteAddress(String ip) {
|
||||||
JSONObject data = JSON.parseObject(HttpTools.get(XiaoMiRouter.getDeviceListUrl()));
|
JSONObject data = JSON.parseObject(HttpTools.get(XiaoMiRouter.getInstance().getDeviceListUrl()));
|
||||||
if (data.getInteger("code") == 0) {
|
if (data.getInteger("code") == 0) {
|
||||||
JSONArray array=data.getJSONArray("list");
|
JSONArray array=data.getJSONArray("list");
|
||||||
for (Object o : array) {
|
for (Object o : array) {
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class QQBotApplication {
|
public class QQBotApplication {
|
||||||
public static final String version = "QQBot v.1.7.3";
|
public static final String version = "QQBot v.1.7.8";
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("version = " + version);
|
System.out.println("version = " + version);
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import com.yutou.qqbot.MessageEvent.AdminMessage;
|
|||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
import com.yutou.qqbot.utlis.AppTools;
|
import com.yutou.qqbot.utlis.AppTools;
|
||||||
import com.yutou.qqbot.utlis.RedisTools;
|
import com.yutou.qqbot.utlis.RedisTools;
|
||||||
|
import com.yutou.qqbot.utlis.XiaoMiRouter;
|
||||||
import org.springframework.stereotype.Controller;
|
import org.springframework.stereotype.Controller;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
||||||
@@ -89,4 +90,15 @@ public class QQBotController {
|
|||||||
}
|
}
|
||||||
return "200";
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,22 +3,23 @@ package com.yutou.qqbot;
|
|||||||
import com.alibaba.fastjson2.JSON;
|
import com.alibaba.fastjson2.JSON;
|
||||||
import com.alibaba.fastjson2.JSONObject;
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.yutou.napcat.QQDatabase;
|
import com.yutou.napcat.QQDatabase;
|
||||||
import com.yutou.napcat.handle.BaseHandle;
|
import com.yutou.napcat.handle.*;
|
||||||
import com.yutou.napcat.handle.MessageHandleBuild;
|
|
||||||
import com.yutou.napcat.handle.Reply;
|
|
||||||
import com.yutou.napcat.handle.Text;
|
|
||||||
import com.yutou.napcat.http.NapCatApi;
|
import com.yutou.napcat.http.NapCatApi;
|
||||||
import com.yutou.napcat.model.FriendBean;
|
import com.yutou.napcat.model.FriendBean;
|
||||||
import com.yutou.napcat.model.GroupBean;
|
import com.yutou.napcat.model.GroupBean;
|
||||||
|
import com.yutou.napcat.model.GroupUserBean;
|
||||||
import com.yutou.napcat.model.SendMessageResponse;
|
import com.yutou.napcat.model.SendMessageResponse;
|
||||||
|
import com.yutou.okhttp.BaseBean;
|
||||||
import com.yutou.okhttp.HttpBody;
|
import com.yutou.okhttp.HttpBody;
|
||||||
import com.yutou.okhttp.HttpCallback;
|
import com.yutou.okhttp.HttpCallback;
|
||||||
import com.yutou.qqbot.data.MessageChainBuilder;
|
import com.yutou.qqbot.data.MessageChainBuilder;
|
||||||
|
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||||
import com.yutou.qqbot.utlis.*;
|
import com.yutou.qqbot.utlis.*;
|
||||||
import retrofit2.Response;
|
import retrofit2.Response;
|
||||||
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -163,7 +164,7 @@ public class QQBotManager {
|
|||||||
|
|
||||||
public String sendMessage(String text) {
|
public String sendMessage(String text) {
|
||||||
|
|
||||||
return getNotLoginQQ();
|
return sendMessage(false,defGroup,text).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public SendMessageResponse sendMessage(Long group, String text) {
|
public SendMessageResponse sendMessage(Long group, String text) {
|
||||||
@@ -183,16 +184,72 @@ public class QQBotManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(File imageFile, Long qq, String replyMessageId, String 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));
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendMessage(File imageFile, String text) {
|
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 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) {
|
public static void main(String[] args) {
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
@@ -206,10 +263,10 @@ public class QQBotManager {
|
|||||||
|
|
||||||
public void sendVersion() {
|
public void sendVersion() {
|
||||||
String localVersion = QQBotApplication.version;
|
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;
|
String msg = "本地版本:" + localVersion + "\n" + "服务器版本:" + serverVersion;
|
||||||
QQBotManager.getInstance().sendMessage(msg);
|
QQBotManager.getInstance().sendMessage(msg);
|
||||||
AppTools.sendServer("服务版本查询", msg);
|
// AppTools.sendServer("服务版本查询", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLogin() {
|
public boolean isLogin() {
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@UseModel
|
@UseModel
|
||||||
public class TurnipProphet extends Model {
|
public class TurnipProphet extends Model {
|
||||||
public static class TurnipData {
|
public static class TurnipData {
|
||||||
@@ -271,6 +272,11 @@ public class TurnipProphet extends Model {
|
|||||||
out.append("网页版:").append("\n").append(url).append("\n");
|
out.append("网页版:").append("\n").append(url).append("\n");
|
||||||
out.append("祝好运 :)");
|
out.append("祝好运 :)");
|
||||||
|
|
||||||
|
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);
|
Log.i("TurnipProphet", out.toString() + "\n 发送QQ:" + sendQQ);
|
||||||
QQBotManager.getInstance().sendMessage(sendQQ, getMessage(out.toString()));
|
QQBotManager.getInstance().sendMessage(sendQQ, getMessage(out.toString()));
|
||||||
return prArray.getJSONObject(0).getString(TurnipData.MODEL);
|
return prArray.getJSONObject(0).getString(TurnipData.MODEL);
|
||||||
@@ -304,7 +310,8 @@ public class TurnipProphet extends Model {
|
|||||||
|
|
||||||
|
|
||||||
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
public Map<String, String> openTurnip(String prices, String pattern) throws Exception {
|
||||||
String url = String.format("http://192.168.31.88:7000/?prices=%s%s",
|
String url = String.format("http://%s/?prices=%s%s",
|
||||||
|
ConfigTools.load(ConfigTools.CONFIG, ConfigTools.TURNIP_PROPHET_SERVER, String.class),
|
||||||
prices,
|
prices,
|
||||||
pattern == null ? "" : "&pattern=" + pattern
|
pattern == null ? "" : "&pattern=" + pattern
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ public class BiliBiliLive extends Model {
|
|||||||
@Override
|
@Override
|
||||||
public synchronized void onTime(Long qq, String time) {
|
public synchronized void onTime(Long qq, String time) {
|
||||||
super.onTime(qq, time);
|
super.onTime(qq, time);
|
||||||
if ("00:01:00".equals(time)) {
|
if ("07:01:00".equals(time)) {
|
||||||
if (!new BiliLogin(QQBotManager.defQQ).testLogin()) {
|
if (!new BiliLogin(QQBotManager.defQQ).testLogin()) {
|
||||||
new BiliLogin(QQBotManager.defQQ).loginAsQQ();
|
new BiliLogin(QQBotManager.defQQ).loginAsQQ();
|
||||||
System.out.println(BiliBiliUtils.getInstance(QQBotManager.defQQ).getLoginInfo());
|
System.out.println(BiliBiliUtils.getInstance(QQBotManager.defQQ).getLoginInfo());
|
||||||
|
|||||||
@@ -1,11 +1,16 @@
|
|||||||
package com.yutou.qqbot.models.Commands;
|
package com.yutou.qqbot.models.Commands;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
import com.yutou.qqbot.Annotations.UseModel;
|
import com.yutou.qqbot.Annotations.UseModel;
|
||||||
import com.yutou.qqbot.QQBotManager;
|
import com.yutou.qqbot.QQBotManager;
|
||||||
import com.yutou.qqbot.interfaces.ObjectInterface;
|
import com.yutou.qqbot.interfaces.ObjectInterface;
|
||||||
import com.yutou.qqbot.models.Model;
|
import com.yutou.qqbot.models.Model;
|
||||||
import com.yutou.qqbot.utlis.AppTools;
|
import com.yutou.qqbot.utlis.AppTools;
|
||||||
import com.yutou.napcat.event.MessageEvent;
|
import com.yutou.napcat.event.MessageEvent;
|
||||||
|
import com.yutou.qqbot.utlis.ConfigTools;
|
||||||
|
import com.yutou.qqbot.utlis.HttpTools;
|
||||||
|
|
||||||
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
@UseModel
|
@UseModel
|
||||||
public class BTDownload extends Model {
|
public class BTDownload extends Model {
|
||||||
@@ -33,18 +38,12 @@ public class BTDownload extends Model {
|
|||||||
super.onMessage(qq, event, isGroup);
|
super.onMessage(qq, event, isGroup);
|
||||||
if (msg.startsWith("magnet:?xt=")) {
|
if (msg.startsWith("magnet:?xt=")) {
|
||||||
String builder = "已添加下载磁链";
|
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);
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, builder);
|
||||||
String exec = String.format("qbittorrent-nox --save-path=%sdownload_tmp/%s \"%s\" "
|
|
||||||
, DownloadHomePath
|
|
||||||
, AppTools.getToDayTime()
|
|
||||||
, msg
|
|
||||||
);
|
|
||||||
AppTools.exec(exec, new ObjectInterface() {
|
|
||||||
@Override
|
|
||||||
public void out(String data) {
|
|
||||||
super.out(data);
|
|
||||||
}
|
|
||||||
}, true, false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package com.yutou.qqbot.models.Commands;
|
package com.yutou.qqbot.models.Commands;
|
||||||
|
|
||||||
import com.yutou.napcat.QQDatabase;
|
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.napcat.handle.Text;
|
||||||
import com.yutou.qqbot.Annotations.UseModel;
|
import com.yutou.qqbot.Annotations.UseModel;
|
||||||
import com.yutou.qqbot.QQBotManager;
|
import com.yutou.qqbot.QQBotManager;
|
||||||
@@ -14,6 +16,7 @@ import lombok.val;
|
|||||||
import org.apache.catalina.valves.JsonErrorReportValve;
|
import org.apache.catalina.valves.JsonErrorReportValve;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@UseModel
|
@UseModel
|
||||||
public class BaiduGPT extends Model {
|
public class BaiduGPT extends Model {
|
||||||
@@ -49,7 +52,6 @@ public class BaiduGPT extends Model {
|
|||||||
} else if ("4.0".equals(version)) {
|
} else if ("4.0".equals(version)) {
|
||||||
BaiduGPTManager.getManager().setModelFor40();
|
BaiduGPTManager.getManager().setModelFor40();
|
||||||
}
|
}
|
||||||
System.out.println("version = " + version);
|
|
||||||
if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) {
|
if (event.getTextMessage().equals(QQGroupCommands.GPT_CLEAR)) {
|
||||||
BaiduGPTManager.getManager().clear();
|
BaiduGPTManager.getManager().clear();
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏"));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Text("已经失忆捏"));
|
||||||
@@ -58,18 +60,36 @@ public class BaiduGPT extends Model {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ("GPT切换到4.0".equals(event.getTextMessage())) {
|
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().clear();
|
||||||
BaiduGPTManager.getManager().setModelFor40();
|
BaiduGPTManager.getManager().setModelFor40();
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "切换为4.0了");
|
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;
|
return;
|
||||||
} else if ("GPT切换到3.5".equals(event.getTextMessage())) {
|
} 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().clear();
|
||||||
BaiduGPTManager.getManager().setModelFor35();
|
BaiduGPTManager.getManager().setModelFor35();
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "切换为3.5了");
|
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;
|
return;
|
||||||
}
|
}
|
||||||
ResponseMessage message = BaiduGPTManager.getManager().sendMessage(
|
ResponseMessage message = BaiduGPTManager.getManager().sendMessage(
|
||||||
String.valueOf(user),
|
String.valueOf(qq),
|
||||||
event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim());
|
event.getTextMessage().replace("@" + QQDatabase.getMe().getUserId(), "").trim());
|
||||||
String sb = "调用版本:" +
|
String sb = "调用版本:" +
|
||||||
BaiduGPTManager.getManager().getGPTVersion() +
|
BaiduGPTManager.getManager().getGPTVersion() +
|
||||||
|
|||||||
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) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,7 +35,7 @@ public class WoodenFish extends Model {
|
|||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Record("muyu.mp3"));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Record("muyu.mp3"));
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "功德+1");
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, "功德+1");
|
||||||
} else if (msg.contains("遥遥领先")) {
|
} else if (msg.contains("遥遥领先")) {
|
||||||
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Record("遥遥领先.mp3"));
|
QQBotManager.getInstance().sendMessage(event.isUser(), qq, new Record("遥遥领先.silk"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -84,6 +84,9 @@ public abstract class Model implements ModelInterface {
|
|||||||
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
public void onMessage(Long qq, MessageEvent event, boolean isGroup) {
|
||||||
this.event = event;
|
this.event = event;
|
||||||
msg = event.getRawMessage();
|
msg = event.getRawMessage();
|
||||||
|
if(msg==null){
|
||||||
|
msg="";
|
||||||
|
}
|
||||||
msg = msg.replace("!", "!").trim();
|
msg = msg.replace("!", "!").trim();
|
||||||
this.isGroup = event.isGroup();
|
this.isGroup = event.isGroup();
|
||||||
if (isGroup) {
|
if (isGroup) {
|
||||||
@@ -92,6 +95,8 @@ public abstract class Model implements ModelInterface {
|
|||||||
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
|
if (QQNumberManager.getManager().isExistsPower(group, msg.split(" ")[0])) {
|
||||||
isGroupPower = true;
|
isGroupPower = true;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
user = qq;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -124,4 +129,8 @@ public abstract class Model implements ModelInterface {
|
|||||||
public boolean isAt() {
|
public boolean isAt() {
|
||||||
return msg.contains("@" + ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_NUMBER, String.class));
|
return msg.contains("@" + ConfigTools.load(ConfigTools.CONFIG, ConfigTools.QQ_NUMBER, String.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isAdmin() {
|
||||||
|
return user == 583819556L;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public class BiliBiliMangeSign extends Model {
|
|||||||
@Override
|
@Override
|
||||||
public void onTime(Long qq, String time) {
|
public void onTime(Long qq, String time) {
|
||||||
super.onTime(qq, time);
|
super.onTime(qq, time);
|
||||||
if ("00:01:00".equals(time)) {
|
if ("07:05:00".equals(time)) {
|
||||||
if (new BiliLogin(QQBotManager.defQQ).testLogin()) {
|
if (new BiliLogin(QQBotManager.defQQ).testLogin()) {
|
||||||
String msg;
|
String msg;
|
||||||
if (BiliBiliManga.sign() == null) {
|
if (BiliBiliManga.sign() == null) {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ public class MiRouter extends Model {
|
|||||||
isRunTime = false;
|
isRunTime = false;
|
||||||
}
|
}
|
||||||
private void run()throws Exception{
|
private void run()throws Exception{
|
||||||
String url = XiaoMiRouter.getDeviceListUrl();
|
String url = XiaoMiRouter.getInstance().getDeviceListUrl();
|
||||||
JSONObject json = JSON.parseObject(HttpTools.get(url));
|
JSONObject json = JSON.parseObject(HttpTools.get(url));
|
||||||
if (json.getInteger("code") == 0) {
|
if (json.getInteger("code") == 0) {
|
||||||
String _tmp = RedisTools.get(redis_key);
|
String _tmp = RedisTools.get(redis_key);
|
||||||
@@ -114,7 +114,7 @@ public class MiRouter extends Model {
|
|||||||
}
|
}
|
||||||
RedisTools.set(redis_key, devs.toString());
|
RedisTools.set(redis_key, devs.toString());
|
||||||
}else {
|
}else {
|
||||||
XiaoMiRouter.setNotToken();
|
XiaoMiRouter.getInstance().setNotToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
if (time.equals(oldTime)) {
|
if (time.equals(oldTime)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BaiduGPTManager.getManager().clear();
|
|
||||||
oldTime = time;
|
oldTime = time;
|
||||||
for (Class<?> model : Model.classList) {
|
for (Class<?> model : Model.classList) {
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
@@ -44,22 +43,39 @@ public class ApplicationInit implements ApplicationRunner {
|
|||||||
useModel.onTime(group.getGroupId(), time);
|
useModel.onTime(group.getGroupId(), time);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Bot bot = QQBotManager.getInstance().getBot();
|
|
||||||
if (bot == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Model useModel = (Model) model.getDeclaredConstructor().newInstance();
|
|
||||||
for (Group group : bot.getGroups()) {
|
|
||||||
if (QQNumberManager.getManager().isUseModel(group.getId(), model)) {
|
|
||||||
useModel.onTime(group.getId(), time);
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
//用switch判断time,case是整点
|
||||||
|
switch (time) {
|
||||||
|
case "00:00":
|
||||||
|
case "01:00":
|
||||||
|
case "02:00":
|
||||||
|
case "03:00":
|
||||||
|
case "04:00":
|
||||||
|
case "05:00":
|
||||||
|
case "06:00":
|
||||||
|
case "07:00":
|
||||||
|
case "08:00":
|
||||||
|
case "09:00":
|
||||||
|
case "10:00":
|
||||||
|
case "11:00":
|
||||||
|
case "12:00":
|
||||||
|
case "13:00":
|
||||||
|
case "14:00":
|
||||||
|
case "15:00":
|
||||||
|
case "16:00":
|
||||||
|
case "17:00":
|
||||||
|
case "18:00":
|
||||||
|
case "19:00":
|
||||||
|
case "20:00":
|
||||||
|
case "21:00":
|
||||||
|
case "22:00":
|
||||||
|
case "23:00":
|
||||||
|
BaiduGPTManager.getManager().clear();
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ public class BaiduGPTManager {
|
|||||||
private static final String AppID = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_APPID, String.class);
|
private static final String AppID = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_APPID, String.class);
|
||||||
private static final String ApiKey = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_API_KEY, String.class);
|
private static final String ApiKey = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_API_KEY, String.class);
|
||||||
private static final String SecretKey = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_SECRET_KEY, String.class);
|
private static final String SecretKey = ConfigTools.load(ConfigTools.CONFIG, ConfigTools.BAIDU_GPT_SECRET_KEY, String.class);
|
||||||
private final Map<String, List<Message>> msgMap;
|
private static Map<String, List<Message>> msgMap;
|
||||||
|
|
||||||
private BaiduGPTManager() {
|
private BaiduGPTManager() {
|
||||||
msgMap = new HashMap<>();
|
msgMap = new HashMap<>();
|
||||||
@@ -96,7 +96,9 @@ public class BaiduGPTManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "你是那个版本的大模型?");
|
ResponseMessage message = BaiduGPTManager.getManager().sendMessage("test", "现在假设小猪等于1,小猴等于2");
|
||||||
|
System.out.println(message.getResult());
|
||||||
|
message = BaiduGPTManager.getManager().sendMessage("test", "那么小猪加上小猴等于多少?");
|
||||||
System.out.println(message.getResult());
|
System.out.println(message.getResult());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,6 +31,8 @@ public class ConfigTools {
|
|||||||
public static final String BAIDU_GPT_APPID = "baidu.gpt.appid";
|
public static final String BAIDU_GPT_APPID = "baidu.gpt.appid";
|
||||||
public static final String BAIDU_GPT_API_KEY = "baidu.gpt.apikey";
|
public static final String BAIDU_GPT_API_KEY = "baidu.gpt.apikey";
|
||||||
public static final String BAIDU_GPT_SECRET_KEY = "baidu.gpt.SecretKey";
|
public static final String BAIDU_GPT_SECRET_KEY = "baidu.gpt.SecretKey";
|
||||||
|
public static final String TURNIP_PROPHET_SERVER = "turnip.server";
|
||||||
|
public static final String TURNIP_PROPHET_SEND_TMP_GROUP = "turnip.send.tmp.group";
|
||||||
|
|
||||||
|
|
||||||
static {
|
static {
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ public class RedisTools {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String get(String key, int dbIndex) {
|
public static String get(String key, int dbIndex) {
|
||||||
String value = "-999";
|
String value = null;
|
||||||
if (isNotInstallRedis) {
|
if (isNotInstallRedis) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,19 +7,30 @@ import org.apache.commons.codec.digest.DigestUtils;
|
|||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
|
||||||
public class XiaoMiRouter {
|
public class XiaoMiRouter {
|
||||||
|
private static XiaoMiRouter router;
|
||||||
private final static String key = "a2ffa5c9be07488bbb04a3a47d3c5f6a";
|
private final static String key = "a2ffa5c9be07488bbb04a3a47d3c5f6a";
|
||||||
private static String token = null;
|
private String token = null;
|
||||||
|
|
||||||
public static void setNotToken() {
|
private XiaoMiRouter() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static XiaoMiRouter getInstance() {
|
||||||
|
if (router == null) {
|
||||||
|
router = new XiaoMiRouter();
|
||||||
|
}
|
||||||
|
return router;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNotToken() {
|
||||||
token = null;
|
token = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getToken() {
|
private String getToken() {
|
||||||
if (token != null) {
|
if (token != null) {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
String nonce = nonceCreat();
|
String nonce = nonceCreat();
|
||||||
String oldPwd = DigestUtils.sha1Hex(nonce + DigestUtils.sha1Hex("34864394" + key));
|
String oldPwd = DigestUtils.sha256Hex(nonce + DigestUtils.sha256Hex("34864394" + key));
|
||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
json.put("username", "admin");
|
json.put("username", "admin");
|
||||||
json.put("password", oldPwd);
|
json.put("password", oldPwd);
|
||||||
@@ -33,17 +44,72 @@ public class XiaoMiRouter {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getDeviceListUrl() {
|
private String getHomeUrl() {
|
||||||
return "http://192.168.31.1/cgi-bin/luci/;stok=" + getToken() + "/api/misystem/devicelist";
|
return getHomeUrl(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String nonceCreat() {
|
private String getHomeUrl(boolean check) {
|
||||||
return String.format("%s_%s_%s_%s", 0, HttpTools.getLocalMacAddress(), (int) (System.currentTimeMillis() / 1000), (int) (Math.random() * 10000));
|
if (check && !checkToken()) {
|
||||||
|
token = null;
|
||||||
|
}
|
||||||
|
return "http://192.168.31.1/cgi-bin/luci/;stok=" + getToken();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceListUrl() {
|
||||||
|
return getHomeUrl() + "/api/misystem/devicelist";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String nonceCreat() {
|
||||||
|
return String.format("%s_%s_%s_%s", 0, "7c:83:34:bd:a3:9f", (int) (System.currentTimeMillis() / 1000), (int) (Math.random() * 10000));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getWan1StatusUrl() {
|
||||||
|
return getHomeUrl() + "/api/xqnetwork/get_wan_status";
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getWan2StatusUrl() {
|
||||||
|
return getHomeUrl() + "/api/xqnetwork/pppoe_status?wan_name=WAN2";
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkToken() {
|
||||||
|
String url = getHomeUrl(false) + "/api/misystem/messages";
|
||||||
|
JSONObject json = JSON.parseObject(HttpTools.get(url));
|
||||||
|
return json.getInteger("code") == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWan1IPAddress() {
|
||||||
|
String url = getWan1StatusUrl();
|
||||||
|
JSONObject json = JSON.parseObject(HttpTools.get(url));
|
||||||
|
try {
|
||||||
|
return json.getJSONObject("ipv4").getJSONObject("ip").getString("address");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return getIPv4();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getWan2IPAddress() {
|
||||||
|
String url = getWan2StatusUrl();
|
||||||
|
JSONObject json = JSON.parseObject(HttpTools.get(url));
|
||||||
|
try {
|
||||||
|
return json.getJSONObject("ip").getString("address");
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return getIPv4();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIPv4() {
|
||||||
|
return HttpTools.get("https://4.ipw.cn/");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
String url = XiaoMiRouter.getDeviceListUrl();
|
System.out.println(XiaoMiRouter.getInstance().getWan1IPAddress());
|
||||||
JSONObject json = JSON.parseObject(HttpTools.get(url));
|
XiaoMiRouter.getInstance().clear();
|
||||||
System.out.println("json = " + json);
|
System.out.println(XiaoMiRouter.getInstance().getWan2IPAddress());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void clear() {
|
||||||
|
token="";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user