更新bot测试接口

This commit is contained in:
Yutou 2024-01-20 10:00:07 +08:00
parent 1705f4d752
commit 22416227d8
2 changed files with 26 additions and 3 deletions

View File

@ -2,6 +2,7 @@ package com.yutou.qqbot;
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 net.mamoe.mirai.Bot;
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;
@ -33,4 +34,16 @@ public class QQBotController {
AppTools.sendServer(title, msg); AppTools.sendServer(title, msg);
return "ok"; 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";
}
} }

View File

@ -6,7 +6,6 @@ import com.yutou.qqbot.Listeners.QQMessageListener;
import com.yutou.qqbot.utlis.*; import com.yutou.qqbot.utlis.*;
import net.mamoe.mirai.Bot; import net.mamoe.mirai.Bot;
import net.mamoe.mirai.BotFactory; import net.mamoe.mirai.BotFactory;
import net.mamoe.mirai.auth.BotAuthorization;
import net.mamoe.mirai.event.GlobalEventChannel; import net.mamoe.mirai.event.GlobalEventChannel;
import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.MessageReceipt;
import net.mamoe.mirai.message.data.*; import net.mamoe.mirai.message.data.*;
@ -55,7 +54,11 @@ public class QQBotManager {
@Override @Override
public void run() { public void run() {
String test = HttpTools.get("http://192.168.31.88:7400/"); String url=ConfigTools.load(ConfigTools.CONFIG,"sign_url",String.class);
if(StringUtils.isEmpty(url)){
url="http://192.168.31.88:7400/";
}
String test = HttpTools.get(url);
try { try {
JSONObject json = JSONObject.parseObject(test); JSONObject json = JSONObject.parseObject(test);
if (json.getInteger("code") != 0) { if (json.getInteger("code") != 0) {
@ -101,7 +104,6 @@ public class QQBotManager {
} }
}).start(); }).start();
bot.join(); bot.join();
} }
}).start(); }).start();
@ -266,4 +268,12 @@ public class QQBotManager {
public Bot getBot() { public Bot getBot() {
return bot; return bot;
} }
public void reLogin() {
isInit=false;
if(bot.isOnline()){
bot.close();
}
init();
}
} }