diff --git a/src/main/java/top/focess/qq/core/bot/mirai/MiraiBotManager.java b/src/main/java/top/focess/qq/core/bot/mirai/MiraiBotManager.java index 93b8e16..841224a 100644 --- a/src/main/java/top/focess/qq/core/bot/mirai/MiraiBotManager.java +++ b/src/main/java/top/focess/qq/core/bot/mirai/MiraiBotManager.java @@ -396,6 +396,13 @@ private void setup(final MiraiBot b, final net.mamoe.mirai.Bot bot) { FocessQQ.getLogger().thrLang("exception-submit-member-card-change-event", ex); } })); + listeners.add(bot.getEventChannel().subscribeAlways(BotOfflineEvent.class, event -> { + try { + bot.login(); + } catch (Exception e) { + FocessQQ.getLogger().thrLang("exception-bot-accidentally-offline", e); + } + })); BOT_LISTENER_MAP.put(b, listeners); } diff --git a/src/main/resources/lang.yml b/src/main/resources/lang.yml index f5c2b68..0aa78a6 100644 --- a/src/main/resources/lang.yml +++ b/src/main/resources/lang.yml @@ -81,6 +81,7 @@ exception-get-null-caller-class: Get null caller class exception exception-load-plugin-unexpected-exception: Load plugin with unexpected exception exception-enable-plugin: Enable plugin exception exception-disable-plugin: Disable plugin exception +exception-bot-accidentally-offline: Bot accidentally offline exception setup-uncaught-exception-handler: Setup uncaught exception handler setup-shutdown-hook: Setup shutdown hook start-console-input-thread: Start console input thread diff --git a/src/test/java/top/focess/qq/test/environment/TestBot.java b/src/test/java/top/focess/qq/test/environment/TestBot.java index e5a50d5..bbb27f2 100644 --- a/src/test/java/top/focess/qq/test/environment/TestBot.java +++ b/src/test/java/top/focess/qq/test/environment/TestBot.java @@ -6,7 +6,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; import org.jetbrains.annotations.UnmodifiableView; import top.focess.qq.FocessQQ; -import top.focess.qq.api.bot.BotLoginException; import top.focess.qq.api.bot.BotProtocol; import top.focess.qq.api.bot.contact.*; import top.focess.qq.api.bot.message.Audio; @@ -45,7 +44,7 @@ public TestBot(long id, String password, Plugin plugin, BotProtocol botProtocol, } @Override - public boolean relogin() throws BotLoginException { + public boolean relogin() { boolean ret = this.logout() && this.login(); try { EventManager.submit(new BotReloginEvent(this));