diff --git a/src/main/java/com/bbn/hadder/commands/moderation/RoleCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/RoleCommand.java index 9b69706b..b0a92be3 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/RoleCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/RoleCommand.java @@ -75,7 +75,7 @@ public void executed(String[] args, CommandEvent event) { event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder).build()).queue(); } } else { - event.getTextChannel().sendMessage("Missing args").queue(); + event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } } diff --git a/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java index 67d4622a..53f263b0 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java @@ -25,7 +25,7 @@ public void executed(String[] args, CommandEvent event) { .setDescription("Please specify the channel on which I should send the rules. Your message should look like: #rules.")) .build()).queue(); new EventWaiter().newOnMessageEventWaiter(event1 -> { - if (event1.getMessage().getMentionedChannels().size() > 0) { + if (event1.getMessage().getMentionedChannels().size() == 1) { TextChannel channel = event1.getMessage().getMentionedChannels().get(0); if (channel.getGuild().getId().equals(event1.getGuild().getId())) { event1.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() @@ -39,21 +39,40 @@ public void executed(String[] args, CommandEvent event) { .setDescription("The rules were successfully set. Please send me the name of the role which the user receives after he accepted the rules.") .build()).queue(); new EventWaiter().newOnMessageEventWaiter(event3 -> { - Role role = event3.getGuild().getRolesByName(event3.getMessage().getContentRaw(), true).get(0); - if (event3.getGuild().getSelfMember().canInteract(role)) { - event3.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() - .setTitle("The role has been successfully set to " + role.getName() + ".")) - .build()).queue(); - Message rules = channel.sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() - .setTitle("Rules")) - .setDescription(message) - .build()).complete(); - rules.addReaction("✅").queue(); - rules.addReaction("❌").queue(); - event.getRethink().updateRules(event.getGuild().getId(), rules.getId(), role.getId()); + if(event.getMessage().getMentionedRoles().size() == 1) { + Role role = event.getMessage().getMentionedRoles().get(0); + if (event3.getGuild().getSelfMember().canInteract(role)) { + event3.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("The role has been successfully set to " + role.getName() + ".")) + .build()).queue(); + Message rules = channel.sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Rules")) + .setDescription(message) + .build()).complete(); + rules.addReaction("✅").queue(); + rules.addReaction("❌").queue(); + event.getRethink().updateRules(event.getGuild().getId(), rules.getId(), role.getId()); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_SELF_PERMISSION, builder).build()).queue(); + } } else { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_SELF_PERMISSION, builder).build()).queue(); + Role role = event3.getGuild().getRolesByName(event3.getMessage().getContentRaw(), true).get(0); + if (event3.getGuild().getSelfMember().canInteract(role)) { + event3.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("The role has been successfully set to " + role.getName() + ".")) + .build()).queue(); + Message rules = channel.sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Rules")) + .setDescription(message) + .build()).complete(); + rules.addReaction("✅").queue(); + rules.addReaction("❌").queue(); + event.getRethink().updateRules(event.getGuild().getId(), rules.getId(), role.getId()); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_SELF_PERMISSION, builder).build()).queue(); + } } }, event.getJDA(), event.getAuthor()); }, event.getJDA(), event.getAuthor()); @@ -64,10 +83,62 @@ public void executed(String[] args, CommandEvent event) { .build()).queue(); } } else { - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, new EmbedBuilder() - .setTitle("No Channel mentioned")) - .setDescription("Please mention a channel. This should look like #rules") - .build()).queue(); + TextChannel channel = event1.getGuild().getTextChannelsByName(event1.getMessage().getContentRaw(), true).get(0); + if (channel.getGuild().getId().equals(event1.getGuild().getId())) { + event1.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Rules") + .setDescription("The channel was successfully set to " + channel.getName() + ". Please send me the rules now.")) + .build()).queue(); + new EventWaiter().newOnMessageEventWaiter(event2 -> { + String message = event2.getMessage().getContentDisplay(); + event2.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Role to assign")) + .setDescription("The rules were successfully set. Please send me the name of the role which the user receives after he accepted the rules.") + .build()).queue(); + new EventWaiter().newOnMessageEventWaiter(event3 -> { + if(event.getMessage().getMentionedRoles().size() == 1) { + Role role = event.getMessage().getMentionedRoles().get(0); + if (event3.getGuild().getSelfMember().canInteract(role)) { + event3.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("The role has been successfully set to " + role.getName() + ".")) + .build()).queue(); + Message rules = channel.sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Rules")) + .setDescription(message) + .build()).complete(); + rules.addReaction("✅").queue(); + rules.addReaction("❌").queue(); + event.getRethink().updateRules(event.getGuild().getId(), rules.getId(), role.getId()); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_SELF_PERMISSION, builder).build()).queue(); + } + } else { + Role role = event3.getGuild().getRolesByName(event3.getMessage().getContentRaw(), true).get(0); + if (event3.getGuild().getSelfMember().canInteract(role)) { + event3.getChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("The role has been successfully set to " + role.getName() + ".")) + .build()).queue(); + Message rules = channel.sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Rules")) + .setDescription(message) + .build()).complete(); + rules.addReaction("✅").queue(); + rules.addReaction("❌").queue(); + event.getRethink().updateRules(event.getGuild().getId(), rules.getId(), role.getId()); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_SELF_PERMISSION, builder).build()).queue(); + } + } + }, event.getJDA(), event.getAuthor()); + }, event.getJDA(), event.getAuthor()); + } else { + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, new EmbedBuilder() + .setTitle("Wrong Guild") + .setDescription("The mentioned channel must be on this guid!")) + .build()).queue(); + } } }, event.getJDA(), event.getAuthor()); } else { @@ -82,7 +153,7 @@ public void executed(String[] args, CommandEvent event) { @Override public String[] labels() { - return new String[]{"rules"}; + return new String[]{"rules", "rule"}; } @Override diff --git a/src/main/java/com/bbn/hadder/listener/RulesListener.java b/src/main/java/com/bbn/hadder/listener/RulesListener.java index b56c47ca..5c225e68 100644 --- a/src/main/java/com/bbn/hadder/listener/RulesListener.java +++ b/src/main/java/com/bbn/hadder/listener/RulesListener.java @@ -6,6 +6,7 @@ import com.bbn.hadder.Rethink; import net.dv8tion.jda.api.events.message.react.MessageReactionAddEvent; +import net.dv8tion.jda.api.events.message.react.MessageReactionRemoveEvent; import net.dv8tion.jda.api.hooks.ListenerAdapter; public class RulesListener extends ListenerAdapter { @@ -20,9 +21,25 @@ public RulesListener(Rethink rethink) { public void onMessageReactionAdd(MessageReactionAddEvent event) { if (event.getMessageId().equals(rethink.getRulesMID(event.getGuild().getId()))) { if (!event.getMember().getUser().isBot()) { + if (event.getReactionEmote().getEmoji().equals("✅")) { + event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).reason("Accepted rules").queue(); + } else if (event.getReactionEmote().getEmoji().equals("❌")) { + if (event.getGuild().getSelfMember().canInteract(event.getMember())) { + event.getReaction().removeReaction().queue(); + event.getMember().kick().reason("Declined the rules"); + } + } + } + } + } - event.getGuild().addRoleToMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).queue(); - + @Override + public void onMessageReactionRemove(MessageReactionRemoveEvent event) { + if (event.getMessageId().equals(rethink.getRulesMID(event.getGuild().getId()))) { + if (!event.getMember().getUser().isBot()) { + if (event.getReactionEmote().getEmoji().equals("✅")) { + event.getGuild().removeRoleFromMember(event.getMember(), event.getGuild().getRoleById(rethink.getRulesRID(event.getGuild().getId()))).reason("Withdrawal of the acceptance of the rules").queue(); + } } } }