Skip to content

Commit

Permalink
[BUG] Implement Stuck In Boot checker. Issue #139
Browse files Browse the repository at this point in the history
  • Loading branch information
hypherionmc committed Jan 12, 2025
1 parent b96963a commit ebba1ef
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@

import java.util.List;
import java.util.Optional;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
* @author HypherionSA
Expand All @@ -52,6 +54,8 @@
*/
public final class DiscordEventHandler extends ListenerAdapter {

private boolean isStuckInNotReady = false;

/**
* Discord yeeted the bot connection
*/
Expand Down Expand Up @@ -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");

Expand Down Expand Up @@ -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);
}
}
6 changes: 5 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -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**:

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
version_major=3
version_minor=2
version_patch=2
version_build=2
version_build=3

#Mod
mod_author=HypherionSA
Expand Down

0 comments on commit ebba1ef

Please sign in to comment.