diff --git a/Common/src/main/java/com/hypherionmc/sdlink/core/discord/events/DiscordEventHandler.java b/Common/src/main/java/com/hypherionmc/sdlink/core/discord/events/DiscordEventHandler.java index 4b5c267..ed76c46 100644 --- a/Common/src/main/java/com/hypherionmc/sdlink/core/discord/events/DiscordEventHandler.java +++ b/Common/src/main/java/com/hypherionmc/sdlink/core/discord/events/DiscordEventHandler.java @@ -43,6 +43,8 @@ import java.util.List; import java.util.Optional; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; /** * @author HypherionSA @@ -52,6 +54,8 @@ */ public final class DiscordEventHandler extends ListenerAdapter { + private boolean isStuckInNotReady = false; + /** * Discord yeeted the bot connection */ @@ -95,6 +99,11 @@ public void onMessageReceived(@NotNull MessageReceivedEvent event) { */ @Override public void onStatusChange(StatusChangeEvent event) { + if (event.getJDA().getStatus() == JDA.Status.LOADING_SUBSYSTEMS) { + isStuckInNotReady = true; + startReadyDetection(event.getJDA()); + } + if (event.getJDA().getStatus() == JDA.Status.CONNECTED) { BotController.INSTANCE.getLogger().info("Successfully connected to discord"); @@ -227,4 +236,13 @@ public void onGuildMemberRoleRemove(@NotNull GuildMemberRoleRemoveEvent event) { RoleSync.INSTANCE.roleRemovedFromMember(event.getMember(), role, event.getGuild(), null); }); } + + private void startReadyDetection(JDA jda) { + BotController.INSTANCE.updatesManager.scheduleAtFixedRate(() -> { + if (isStuckInNotReady && jda.getStatus() == JDA.Status.CONNECTED) { + onStatusChange(new StatusChangeEvent(jda, jda.getStatus(), JDA.Status.LOADING_SUBSYSTEMS)); + isStuckInNotReady = false; + } + }, 5, 5, TimeUnit.SECONDS); + } } diff --git a/changelog.md b/changelog.md index 24e681b..e4d4b0f 100644 --- a/changelog.md +++ b/changelog.md @@ -11,7 +11,11 @@ - Don't try to sync mentions to client when running on paper - Fix database engine not regenerating database files when they are deleted while the server is running - Fixed Forwarded messages not being relayed to discord -- Fixed bot getting stuck in not-ready state at random +- Added checker to prevent bot from getting stuck in NotReady state + +**New Features**: + +- Implemented a basic message spam detector **Technical Changes**: diff --git a/gradle.properties b/gradle.properties index 82beeeb..7830992 100644 --- a/gradle.properties +++ b/gradle.properties @@ -2,7 +2,7 @@ version_major=3 version_minor=2 version_patch=2 -version_build=2 +version_build=3 #Mod mod_author=HypherionSA