1.14 support, better error handling #108

Merged
NorbiPeti merged 22 commits from dev into master 2019-10-30 18:43:31 +00:00
Showing only changes of commit 0e4a9ff7e0 - Show all commits

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,8 +142,8 @@ public class DiscordPlugin extends ButtonPlugin {
private void handleReady(List<GuildCreateEvent> event) {
try {
if(!SafeMode) {
getLogger().info("Ready again, already enabled."); //TODO: It should probably handle disconnections
if (mainServer != null) { //This is not the first ready event
getLogger().info("Ready event already handled"); //TODO: It should probably handle disconnections
return;
}
mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards
@ -272,6 +273,7 @@ public class DiscordPlugin extends ButtonPlugin {
//dc.updatePresence(Presence.idle(Activity.playing("logging out"))).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);