package com.yutou.qqbot;

import com.yutou.qqbot.utlis.AppTools;
import com.yutou.qqbot.utlis.RedisTools;
import net.mamoe.mirai.Bot;
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 java.io.IOException;

@Controller
public class QQBotController {
    @ResponseBody
    @RequestMapping("/tools/openpc.do")
    public String open_pc(HttpServletRequest request, String type) {
        if ("nas".equals(type)) {
            try {
                Process process = Runtime.getRuntime().exec("wakeonlan 00:D8:61:6F:02:2F");
                RedisTools.processOut(process.getInputStream());
                RedisTools.processOut(process.getErrorStream());
                process.destroy();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "ok";
    }

    @ResponseBody
    @RequestMapping("/tools/server.do")
    public String sendServerManager(String title, String msg) {
        AppTools.sendServer(title, msg);
        return "ok";
    }
    @ResponseBody
    @RequestMapping("/bot/test.do")
    public String testLogin(){
        Bot bot = QQBotManager.getInstance().getBot();
        return bot.isOnline()+"";
    }
    @ResponseBody
    @RequestMapping("/bot/login.do")
    public String login(){
        QQBotManager.getInstance().reLogin();
        return "ok";
    }
}
