From 22416227d8db6fabdfbce15193196f44252973c6 Mon Sep 17 00:00:00 2001 From: Yutou <583819556@qq.com> Date: Sat, 20 Jan 2024 10:00:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0bot=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/yutou/qqbot/QQBotController.java | 13 +++++++++++++ src/main/java/com/yutou/qqbot/QQBotManager.java | 16 +++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/yutou/qqbot/QQBotController.java b/src/main/java/com/yutou/qqbot/QQBotController.java index f79a4e5..acdf39a 100644 --- a/src/main/java/com/yutou/qqbot/QQBotController.java +++ b/src/main/java/com/yutou/qqbot/QQBotController.java @@ -2,6 +2,7 @@ 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; @@ -33,4 +34,16 @@ public class QQBotController { 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"; + } } diff --git a/src/main/java/com/yutou/qqbot/QQBotManager.java b/src/main/java/com/yutou/qqbot/QQBotManager.java index 35da386..04c0060 100644 --- a/src/main/java/com/yutou/qqbot/QQBotManager.java +++ b/src/main/java/com/yutou/qqbot/QQBotManager.java @@ -6,7 +6,6 @@ import com.yutou.qqbot.Listeners.QQMessageListener; import com.yutou.qqbot.utlis.*; import net.mamoe.mirai.Bot; import net.mamoe.mirai.BotFactory; -import net.mamoe.mirai.auth.BotAuthorization; import net.mamoe.mirai.event.GlobalEventChannel; import net.mamoe.mirai.message.MessageReceipt; import net.mamoe.mirai.message.data.*; @@ -55,7 +54,11 @@ public class QQBotManager { @Override 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 { JSONObject json = JSONObject.parseObject(test); if (json.getInteger("code") != 0) { @@ -101,7 +104,6 @@ public class QQBotManager { } }).start(); bot.join(); - } }).start(); @@ -266,4 +268,12 @@ public class QQBotManager { public Bot getBot() { return bot; } + + public void reLogin() { + isInit=false; + if(bot.isOnline()){ + bot.close(); + } + init(); + } }