improve reconnect i guess

This commit is contained in:
Chayapak 2023-04-22 12:35:11 +07:00
parent 708654de67
commit 34250d2bad
2 changed files with 12 additions and 3 deletions

View file

@ -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);

View file

@ -9,7 +9,7 @@ consolePrefixes:
normalCommandsPrefix: '.'
consoleServerPrefix: '/'
reconnectDelay: 7000
reconnectDelay: 2000
discord:
prefix: 'default!'