新增开门指令
This commit is contained in:
parent
aa935e8662
commit
8e98929622
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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;
|
||||
|
29
src/main/java/com/yutou/qqbot/models/Commands/OpenDoor.java
Normal file
29
src/main/java/com/yutou/qqbot/models/Commands/OpenDoor.java
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 = "开门";
|
||||
}
|
||||
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user