diff --git a/src/main/java/com/yutou/qqbot/Controllers/AppController.java b/src/main/java/com/yutou/qqbot/Controllers/AppController.java index 541c382..9e0a905 100644 --- a/src/main/java/com/yutou/qqbot/Controllers/AppController.java +++ b/src/main/java/com/yutou/qqbot/Controllers/AppController.java @@ -1,11 +1,16 @@ package com.yutou.qqbot.Controllers; +import com.alibaba.fastjson.JSONObject; +import com.yutou.qqbot.QQBotManager; import com.yutou.qqbot.utlis.AppTools; +import com.yutou.qqbot.utlis.HttpTools; 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.io.File; + @Controller public class AppController { @RequestMapping("/restart.do") @@ -40,10 +45,27 @@ public class AppController { return "0"; } else if ("on".equals(status)) { return "2"; - }else if("over".equals(status)){ - RedisTools.set("door","ready"); + } else if ("over".equals(status)) { + RedisTools.set("door", "ready"); return "1"; } return "-1"; } + + @ResponseBody + @RequestMapping("/qq/send.do") + public String sendQQ(JSONObject json) { + File image = null; + String ret; + if (json.containsKey("image")) { + image = HttpTools.syncDownload(json.getString("image"), System.currentTimeMillis() + ".png"); + } + if (image != null) { + ret = QQBotManager.getInstance().sendMessage(image, json.getLong("qq"), json.getString("message")); + + } else { + ret = QQBotManager.getInstance().sendMessage(json.getLong("qq"), json.getString("message")); + } + return ret; + } } diff --git a/src/main/java/com/yutou/qqbot/QQBotApplication.java b/src/main/java/com/yutou/qqbot/QQBotApplication.java index 969ffb0..9b17d0b 100644 --- a/src/main/java/com/yutou/qqbot/QQBotApplication.java +++ b/src/main/java/com/yutou/qqbot/QQBotApplication.java @@ -6,7 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication public class QQBotApplication { - public static final String version="QQBot v.1.2.6.1"; + public static final String version="QQBot v.1.2.7"; public static void main(String[] args) { System.out.println("version = " + version); SpringApplication.run(QQBotApplication.class, args); diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 880961a..31b1b60 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -4,6 +4,7 @@ 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.OpenDoor; import com.yutou.qqbot.models.Commands.System.*; import com.yutou.qqbot.models.Model; import com.yutou.qqbot.models.WebSign.Tsdm; @@ -47,6 +48,7 @@ public class QQBotManager { Model.classList.add(BaiduDown.class); Model.classList.add(MiRouter.class); Model.classList.add(GetSeTu.class); + Model.classList.add(OpenDoor.class); } private static QQBotManager botManager = null; private Bot bot; diff --git a/src/main/java/com/yutou/qqbot/models/Commands/OpenDoor.java b/src/main/java/com/yutou/qqbot/models/Commands/OpenDoor.java new file mode 100644 index 0000000..6c2dae6 --- /dev/null +++ b/src/main/java/com/yutou/qqbot/models/Commands/OpenDoor.java @@ -0,0 +1,29 @@ +package com.yutou.qqbot.models.Commands; + +import com.yutou.qqbot.QQBotManager; +import com.yutou.qqbot.models.Model; +import net.mamoe.mirai.event.events.MessageEvent; + +public class OpenDoor extends Model { + @Override + public boolean isUserPublic() { + return false; + } + + @Override + public String[] getUsePowers() { + return new String[]{ + QQFromCommands.DOOR_OPEN + }; + } + + @Override + public void onMessage(Long qq, MessageEvent event, boolean isGroup) { + super.onMessage(qq, event, isGroup); + if(msg.equals(QQFromCommands.DOOR_OPEN)){ + String builder = "点击该链接开门:" + "\n" + + "http://192.168.31.88:802/openDoor.html"; + QQBotManager.getInstance().sendMessage(qq, builder); + } + } +} diff --git a/src/main/java/com/yutou/qqbot/models/Model.java b/src/main/java/com/yutou/qqbot/models/Model.java index 137861a..4d50cfc 100644 --- a/src/main/java/com/yutou/qqbot/models/Model.java +++ b/src/main/java/com/yutou/qqbot/models/Model.java @@ -43,6 +43,7 @@ public abstract class Model implements ModelInterface { public static final String BAIDU_DOWN = "!bd"; public static final String ROUTER_ADD = "!添加设备"; public static final String ROUTER_DEL = "!删除设备"; + public static final String DOOR_OPEN = "开门"; } diff --git a/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java b/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java index bce3741..93e3916 100644 --- a/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java +++ b/src/main/java/com/yutou/qqbot/models/XiaoMi/MiRouter.java @@ -49,6 +49,14 @@ public class MiRouter extends Model { return; } isRunTime = true; + try { + run(); + } catch (Exception e) { + e.printStackTrace(); + } + isRunTime = false; + } + private void run()throws Exception{ String url = XiaoMiRouter.getDeviceListUrl(); JSONObject json = JSONObject.parseObject(HttpTools.get(url)); if (json.getInteger("code") == 0) { @@ -99,7 +107,6 @@ public class MiRouter extends Model { } RedisTools.set(redis_key, devs.toJSONString()); } - isRunTime = false; } private String getOnLineTime(String online) {