diff --git a/README.md b/README.md index 63fd5bc..8b9fc8d 100644 --- a/README.md +++ b/README.md @@ -25,4 +25,5 @@ db.pass=password --- ### Todo -1. Password protect voice channels \ No newline at end of file +1. Password protect voice channels +2. Finish Wiki pages \ No newline at end of file diff --git a/src/main/java/com/jonteohr/discord/guardian/events/OnDirect.java b/src/main/java/com/jonteohr/discord/guardian/events/OnDirect.java index 80d8cbf..09ed153 100644 --- a/src/main/java/com/jonteohr/discord/guardian/events/OnDirect.java +++ b/src/main/java/com/jonteohr/discord/guardian/events/OnDirect.java @@ -43,14 +43,19 @@ public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) { } String guildName = ""; - for(int i = 1; i < args.length; i++) - guildName = guildName + args[i] + " "; + for(int i = 1; i < args.length; i++) { + if(i == (args.length - 1)) { + guildName = guildName + args[i]; + } else { + guildName = guildName + args[i] + " "; + } + } List guildNames = new ArrayList(); for(int i = 0; i < guilds.size(); i++) guildNames.add(e.getJDA().getGuildById(guilds.get(i)).getName().toLowerCase()); - if(!passwords.contains(password) || !guildNames.contains(args[1].toLowerCase())) { + if(!passwords.contains(password) || !guildNames.contains(guildName.toLowerCase())) { e.getChannel().sendMessage("The password or server name you entered is incorrect.").queue(); return; } @@ -60,7 +65,7 @@ public void onPrivateMessageReceived(PrivateMessageReceivedEvent e) { TextChannel channel = guild.getTextChannelById(channels.get(i)); String pw = passwords.get(i); Role role = guild.getRoleById(roles.get(i)); - + if(guild.getName().equalsIgnoreCase(guildName)) { if(!guild.getTextChannels().contains(channel)) // if the channel is not in this server continue; diff --git a/src/main/java/com/jonteohr/discord/guardian/sql/Channels.java b/src/main/java/com/jonteohr/discord/guardian/sql/Channels.java index 0bf5b9c..602542c 100644 --- a/src/main/java/com/jonteohr/discord/guardian/sql/Channels.java +++ b/src/main/java/com/jonteohr/discord/guardian/sql/Channels.java @@ -57,10 +57,13 @@ public boolean protectChannel(TextChannel channel, String password, Role role) { // Hides the channel for @everyone PermissionOverride permOverride = channel.getPermissionOverride(channel.getGuild().getPublicRole()); - permOverride.getManager().deny(Permission.VIEW_CHANNEL).queue(); + if(permOverride == null) + channel.putPermissionOverride(channel.getGuild().getPublicRole()).setDeny(Permission.VIEW_CHANNEL).queue(); + else + permOverride.getManager().deny(Permission.VIEW_CHANNEL).queue(); // Grants access to the channel for the new role - channel.createPermissionOverride(role) + channel.putPermissionOverride(role) .setAllow(Permission.VIEW_CHANNEL) .queue(); @@ -88,7 +91,10 @@ public boolean unProtectChannel(TextChannel channel, Role role) { // Un-hides the channel for @everyone PermissionOverride permOverride = channel.getPermissionOverride(channel.getGuild().getPublicRole()); - permOverride.getManager().clear(Permission.VIEW_CHANNEL).queue(); + if(permOverride == null) + channel.putPermissionOverride(channel.getGuild().getPublicRole()).clear(Permission.VIEW_CHANNEL).queue(); + else + permOverride.getManager().clear(Permission.VIEW_CHANNEL).queue(); return true; }