QQBot/src/main/java/com/yutou/qqbot/Controllers/AppController.java

88 lines
2.8 KiB
Java
Raw Normal View History

2021-12-18 17:33:14 +08:00
package com.yutou.qqbot.Controllers;
2022-01-09 03:32:30 +08:00
import com.alibaba.fastjson.JSONObject;
import com.yutou.qqbot.QQBotManager;
2021-12-18 17:33:14 +08:00
import com.yutou.qqbot.utlis.AppTools;
2022-01-09 03:32:30 +08:00
import com.yutou.qqbot.utlis.HttpTools;
2021-12-20 00:47:02 +08:00
import com.yutou.qqbot.utlis.RedisTools;
2022-01-28 20:06:15 +08:00
import com.yutou.qqbot.utlis.StringUtils;
2021-12-18 17:33:14 +08:00
import org.springframework.stereotype.Controller;
2022-01-16 12:31:39 +08:00
import org.springframework.web.bind.annotation.RequestBody;
2021-12-18 17:33:14 +08:00
import org.springframework.web.bind.annotation.RequestMapping;
2022-01-28 20:06:15 +08:00
import org.springframework.web.bind.annotation.RequestParam;
2021-12-18 17:33:14 +08:00
import org.springframework.web.bind.annotation.ResponseBody;
2022-01-28 20:06:15 +08:00
import org.springframework.web.multipart.MultipartFile;
2021-12-18 17:33:14 +08:00
2022-01-09 03:32:30 +08:00
import java.io.File;
2021-12-18 17:33:14 +08:00
@Controller
public class AppController {
@RequestMapping("/restart.do")
@ResponseBody
2021-12-20 00:47:02 +08:00
public String restart() {
AppTools.exec("cd /home/yutou/public/servier/qqbot && ./start.sh", null, true, false);
2021-12-18 17:33:14 +08:00
return "";
}
2021-12-20 00:47:02 +08:00
@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)) {
2021-12-20 17:34:23 +08:00
return "2";
2022-01-09 03:32:30 +08:00
} else if ("over".equals(status)) {
RedisTools.set("door", "ready");
2021-12-20 00:47:02 +08:00
return "1";
}
return "-1";
}
2022-01-09 03:32:30 +08:00
@ResponseBody
@RequestMapping("/qq/send.do")
2022-01-16 12:31:39 +08:00
public String sendQQ(@RequestBody JSONObject json) {
2022-01-09 03:32:30 +08:00
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;
}
2022-01-28 20:06:15 +08:00
@ResponseBody
@RequestMapping("/qq/file.do")
public String sendFile(@RequestParam("image") MultipartFile file) throws Exception {
2022-01-28 20:27:45 +08:00
String path=AppTools.createFile("tmp",file,AppTools.getToDayNowTimeToString()+".png");
2022-01-28 20:06:15 +08:00
if(StringUtils.isEmpty(path)){
return "not file";
}
File _file=new File(path);
QQBotManager.getInstance().sendMessage(_file,583819556L,"time = "+AppTools.getToDayNowTimeToString());
return "ok";
}
2021-12-18 17:33:14 +08:00
}