Skip to content

Commit

Permalink
modify: add relogin when bot offline
Browse files Browse the repository at this point in the history
  • Loading branch information
MidCoard committed Jan 8, 2024
1 parent 9d14561 commit 118c7bf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/top/focess/qq/test/environment/TestBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down

0 comments on commit 118c7bf

Please sign in to comment.