From 34250d2bad3f0c7aa3449ce66806a1e3cfc21dde Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 22 Apr 2023 12:35:11 +0700 Subject: [PATCH] improve reconnect i guess --- .../land/chipmunk/chayapak/chomens_bot/Bot.java | 13 +++++++++++-- src/main/resources/default-config.yml | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java index 1ae964d..63397ec 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/Bot.java @@ -7,6 +7,7 @@ import com.github.steveice10.packetlib.event.session.*; import com.github.steveice10.packetlib.packet.Packet; import com.github.steveice10.packetlib.tcp.TcpClientSession; import land.chipmunk.chayapak.chomens_bot.plugins.*; +import land.chipmunk.chayapak.chomens_bot.util.ComponentUtilities; import lombok.Getter; import lombok.Setter; import org.apache.commons.lang3.RandomStringUtils; @@ -37,7 +38,7 @@ public class Bot { @Getter private boolean loggedIn = false; - @Getter private ScheduledExecutorService executor = Executors.newScheduledThreadPool(100); + @Getter private final ScheduledExecutorService executor = Executors.newScheduledThreadPool(100); @Getter @Setter private ConsolePlugin console; @Getter @Setter private LoggerPlugin logger; // in ConsolePlugin @@ -167,7 +168,15 @@ public class Bot { public void disconnected(DisconnectedEvent disconnectedEvent) { loggedIn = false; - final int reconnectDelay = config.reconnectDelay(); + int reconnectDelay = config.reconnectDelay(); + + final String stringMessage = ComponentUtilities.stringify(disconnectedEvent.getReason()); + + // this part is ported from chomens bot js + if ( + stringMessage.equals("Wait 5 seconds before connecting, thanks! :)") || + stringMessage.equals("You are logging in too fast, try again later.") + ) reconnectDelay = 1000 * 7; executor.schedule(() -> reconnect(), reconnectDelay, TimeUnit.MILLISECONDS); diff --git a/src/main/resources/default-config.yml b/src/main/resources/default-config.yml index ea0da9b..2f7be75 100644 --- a/src/main/resources/default-config.yml +++ b/src/main/resources/default-config.yml @@ -9,7 +9,7 @@ consolePrefixes: normalCommandsPrefix: '.' consoleServerPrefix: '/' -reconnectDelay: 7000 +reconnectDelay: 2000 discord: prefix: 'default!'