diff --git a/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java b/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java index 91dd6d1..b5a0efc 100755 --- a/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java +++ b/src/main/java/buttondevteam/discordplugin/DiscordPlugin.java @@ -68,7 +68,7 @@ public class DiscordPlugin extends ButtonPlugin { private ConfigData> mainServer() { return getIConfig().getDataPrimDef("mainServer", 0L, id -> { - System.out.println("WTF ID: " + id); //TODO: It attempts to get the default as well + //It attempts to get the default as well if ((long) id == 0L) return Optional.empty(); //Hack? return dc.getGuildById(Snowflake.of((long) id)) @@ -81,6 +81,9 @@ public class DiscordPlugin extends ButtonPlugin { return DPUtils.snowflakeData(getIConfig(), "commandChannel", 239519012529111040L); } + /** + * If the role doesn't exist, then it will only allow for the owner. + */ public ConfigData> modRole() { return DPUtils.roleData(getIConfig(), "modRole", "Moderator"); } @@ -138,10 +141,7 @@ public class DiscordPlugin extends ButtonPlugin { private void handleReady(List event) { try { - System.out.println("w t f: " + mainServer); mainServer = mainServer().get().orElse(null); //Shouldn't change afterwards - System.out.println("Main server: " + mainServer); - System.out.println("wtf: " + mainServer().get()); if (mainServer == null) { if (event.size() == 0) { getLogger().severe("Main server not found! Invite the bot and do /discord reset"); @@ -153,7 +153,8 @@ public class DiscordPlugin extends ButtonPlugin { mainServer().set(Optional.of(mainServer)); //Save in config } SafeMode = false; - DPUtils.disableIfConfigError(null, commandChannel(), modRole()); //Won't disable, just prints the warning here + DPUtils.disableIfConfigErrorRes(null, commandChannel(), DPUtils.getMessageChannel(commandChannel())); + DPUtils.disableIfConfigError(null, modRole()); //Won't disable, just prints the warning here Component.registerComponent(this, new GeneralEventBroadcasterModule()); Component.registerComponent(this, new MinecraftChatModule()); diff --git a/src/main/java/buttondevteam/discordplugin/commands/DebugCommand.java b/src/main/java/buttondevteam/discordplugin/commands/DebugCommand.java index b8c6b64..e1c0686 100644 --- a/src/main/java/buttondevteam/discordplugin/commands/DebugCommand.java +++ b/src/main/java/buttondevteam/discordplugin/commands/DebugCommand.java @@ -17,7 +17,8 @@ public class DebugCommand extends ICommand2DC { .map(u -> u.asMember(DiscordPlugin.mainServer.getId())) .orElse(Mono.empty())) .flatMap(m -> DiscordPlugin.plugin.modRole().get() - .map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId())))) + .map(mr -> m.getRoleIds().stream().anyMatch(r -> r.equals(mr.getId()))) + .switchIfEmpty(Mono.fromSupplier(() -> DiscordPlugin.mainServer.getOwnerId().asLong() == m.getId().asLong()))) //Role not found .subscribe(success -> { if (success) sender.sendMessage("debug " + (CommonListeners.debug() ? "enabled" : "disabled")); diff --git a/src/main/java/buttondevteam/discordplugin/listeners/CommonListeners.java b/src/main/java/buttondevteam/discordplugin/listeners/CommonListeners.java index 08ed9ec..510e71a 100755 --- a/src/main/java/buttondevteam/discordplugin/listeners/CommonListeners.java +++ b/src/main/java/buttondevteam/discordplugin/listeners/CommonListeners.java @@ -47,20 +47,22 @@ public class CommonListeners { return commandCh.filterWhen(ch -> event.getMessage().getChannel().map(mch -> (commandChannel != null && mch.getId().asLong() == commandChannel.asLong()) //If mentioned, that's higher than chat || mch instanceof PrivateChannel - || event.getMessage().getContent().orElse("").contains("channelcon"))) //Only 'channelcon' is allowed in other channels - .filterWhen(ch -> { //Only continue if this doesn't handle the event + || event.getMessage().getContent().orElse("").contains("channelcon")) //Only 'channelcon' is allowed in other channels + .flatMap(shouldRun -> { //Only continue if this doesn't handle the event + if (!shouldRun) + return Mono.just(true); //The condition is only for the first command execution, not mcchat timings.printElapsed("Run command 1"); return CommandListener.runCommand(event.getMessage(), ch, true); //#bot is handled here - }).filterWhen(ch -> { - timings.printElapsed("mcchat"); - val mcchat = Component.getComponents().get(MinecraftChatModule.class); - if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again - return ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels - return Mono.empty(); //Wasn't handled, continue - }).filterWhen(ch -> { - timings.printElapsed("Run command 2"); - return CommandListener.runCommand(event.getMessage(), ch, false); - }); + })).filterWhen(ch -> { + timings.printElapsed("mcchat"); + val mcchat = Component.getComponents().get(MinecraftChatModule.class); + if (mcchat != null && mcchat.isEnabled()) //ComponentManager.isEnabled() searches the component again + return ((MinecraftChatModule) mcchat).getListener().handleDiscord(event); //Also runs Discord commands in chat channels + return Mono.empty(); //Wasn't handled, continue + }).filterWhen(ch -> { + timings.printElapsed("Run command 2"); + return CommandListener.runCommand(event.getMessage(), ch, false); + }); }).onErrorContinue((err, obj) -> TBMCCoreAPI.SendException("An error occured while handling a message!", err)) .subscribe(); dispatcher.on(PresenceUpdateEvent.class).subscribe(event -> {