Only one ready event allowed
This commit is contained in:
parent
bc160a21b7
commit
27ddad537f
1 changed files with 6 additions and 0 deletions
|
@ -130,6 +130,7 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
.take(size) // Take only the first `size` GuildCreateEvent(s) to be received
|
||||||
.collectList()) // Take all received GuildCreateEvents and make it a List
|
.collectList()) // Take all received GuildCreateEvents and make it a List
|
||||||
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */
|
.subscribe(this::handleReady); /* All guilds have been received, client is fully connected */
|
||||||
|
//dc.getEventDispatcher().on(DisconnectEvent.class);
|
||||||
dc.login().subscribe();
|
dc.login().subscribe();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -141,6 +142,10 @@ public class DiscordPlugin extends ButtonPlugin {
|
||||||
|
|
||||||
private void handleReady(List<GuildCreateEvent> event) {
|
private void handleReady(List<GuildCreateEvent> event) {
|
||||||
try {
|
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
|
mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards
|
||||||
if (mainServer == null) {
|
if (mainServer == null) {
|
||||||
if (event.size() == 0) {
|
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
|
dc.updatePresence(Presence.idle(Activity.playing("Chromacraft"))).block(); //No longer using the same account for testing
|
||||||
timings.printElapsed("Logging out...");
|
timings.printElapsed("Logging out...");
|
||||||
dc.logout().block();
|
dc.logout().block();
|
||||||
|
mainServer = null; //Allow ReadyEvent again
|
||||||
//Configs are emptied so channels and servers are fetched again
|
//Configs are emptied so channels and servers are fetched again
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
TBMCCoreAPI.SendException("An error occured while disabling DiscordPlugin!", e);
|
||||||
|
|
Loading…
Reference in a new issue