Only one ready event allowed

This commit is contained in:
Norbi Peti 2019-06-08 22:44:03 +02:00
parent bc160a21b7
commit 27ddad537f
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56

View file

@ -130,6 +130,7 @@ public class DiscordPlugin extends ButtonPlugin {
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
.collectList()) // Take all received GuildCreateEvents and make it a List
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */
//dc.getEventDispatcher().on(DisconnectEvent.class);
dc.login().subscribe();
} catch (Exception e) {
e.printStackTrace();
@ -141,6 +142,10 @@ public class DiscordPlugin extends ButtonPlugin {
private void handleReady(List<GuildCreateEvent> event) {
try {
if (mainServer != null) { //This is not the first ready event
getLogger().info("Ready event already handled");
return;
}
mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards
if (mainServer == null) {
if (event.size() == 0) {
@ -265,6 +270,7 @@ public class DiscordPlugin extends ButtonPlugin {
dc.updatePresence(Presence.idle(Activity.playing("Chromacraft"))).block(); //No longer using the same account for testing
timings.printElapsed("Logging out...");
dc.logout().block();
mainServer = null; //Allow ReadyEvent again
//Configs are emptied so channels and servers are fetched again
} catch (Exception e) {
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);