diff --git a/src/main/java/com/jagrosh/vortex/commands/owner/DebugCmd.java b/src/main/java/com/jagrosh/vortex/commands/owner/DebugCmd.java index 9eb3836..a5967ef 100644 --- a/src/main/java/com/jagrosh/vortex/commands/owner/DebugCmd.java +++ b/src/main/java/com/jagrosh/vortex/commands/owner/DebugCmd.java @@ -22,10 +22,8 @@ import com.jagrosh.vortex.Vortex; import com.jagrosh.vortex.utils.FormatUtil; import java.time.temporal.ChronoUnit; -import java.util.stream.Stream; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.User; -import net.dv8tion.jda.api.sharding.ShardManager; /** * @@ -52,12 +50,12 @@ long usedMb = (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory())/(1024*1024); StringBuilder sb = new StringBuilder("**"+event.getSelfUser().getName()+"** statistics:" + "\nLast Startup: "+FormatUtil.secondsToTime(Constants.STARTUP.until(OffsetDateTime.now(), ChronoUnit.SECONDS))+" ago" - + "\nMemory: **"+usedMb+"**Mb / **"+totalMb+"**Mb"); + + "\nMemory: **"+usedMb+"**Mb / **"+totalMb+"**Mb\n"); vortex.getShardManager().getShardManagers().forEach(bot -> //Stream.of(vortex.getShardManager()).forEach(bot -> { User self = bot.getShards().get(0).getSelfUser(); - sb.append("\n\n__**").append(self.getName()).append("** (").append(self.getId()).append(")__") + sb.append("\n__**").append(self.getName()).append("** (").append(self.getId()).append(")__") .append("\nGuilds: **").append(bot.getGuildCache().size()).append("**") .append("\nAverage Ping: **").append(bot.getAverageGatewayPing()).append("**ms") .append("\nShard Total: **").append(bot.getShardsTotal()).append("**") diff --git a/src/main/java/com/jagrosh/vortex/utils/ConditionalEventManager.java b/src/main/java/com/jagrosh/vortex/utils/ConditionalEventManager.java index 013549a..5101300 100644 --- a/src/main/java/com/jagrosh/vortex/utils/ConditionalEventManager.java +++ b/src/main/java/com/jagrosh/vortex/utils/ConditionalEventManager.java @@ -15,9 +15,10 @@ */ package com.jagrosh.vortex.utils; +import java.lang.reflect.InvocationTargetException; import java.util.List; +import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.events.GenericEvent; -import net.dv8tion.jda.api.events.guild.GenericGuildEvent; import net.dv8tion.jda.api.hooks.InterfacedEventManager; import net.dv8tion.jda.api.sharding.ShardManager; @@ -33,17 +34,43 @@ public void handle(GenericEvent ge) { // check if this guild is already loaded by some other shard - if(ge instanceof GenericGuildEvent) + long selfId; + try { - long selfId = ge.getJDA().getSelfUser().getIdLong(); - long gid = ((GenericGuildEvent) ge).getGuild().getIdLong(); - + selfId = ge.getJDA().getSelfUser().getIdLong(); + } + catch ( IllegalStateException ex) // selfid not ready yet + { + return; + } + Guild guild; + try + { + guild = (Guild) ge.getClass().getMethod("getGuild").invoke(ge); + } + catch (NoSuchMethodException | InvocationTargetException ex) // no getGuild method or not in guild + { + guild = null; + } + catch (IllegalAccessException ex) // something actually went wrong + { + guild = null; + ex.printStackTrace(); + } + long guildId = guild == null ? 0 : guild.getIdLong(); + + if(guildId != 0) + { for(ShardManager bot: getOrderedShardManagers()) { if(bot.getShards().get(0).getSelfUser().getIdLong() == selfId) + { break; - if(bot.getGuildById(gid) != null) + } + if(bot.getGuildById(guildId) != null) + { return; + } } } diff --git a/src/main/java/com/jagrosh/vortex/utils/MultiBotManager.java b/src/main/java/com/jagrosh/vortex/utils/MultiBotManager.java index f892b44..6f85706 100644 --- a/src/main/java/com/jagrosh/vortex/utils/MultiBotManager.java +++ b/src/main/java/com/jagrosh/vortex/utils/MultiBotManager.java @@ -38,16 +38,14 @@ */ public class MultiBotManager { - private final MultiBotEventManager mbem; private final List bots; protected MultiBotManager(List builders) throws LoginException, IllegalArgumentException { - this.mbem = new MultiBotEventManager(); this.bots = new ArrayList<>(); for(DefaultShardManagerBuilder b: builders) { - b.setEventManagerProvider(i -> mbem); + b.setEventManagerProvider(i -> new MultiBotEventManager()); b.setBulkDeleteSplittingEnabled(false); b.setRequestTimeoutRetry(true); bots.add(b.build());