Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Commit

Permalink
Merge pull request #94 from BigBotNetwork/greg-dev
Browse files Browse the repository at this point in the history
Greg dev
  • Loading branch information
Skidder authored Nov 22, 2019
2 parents 99cf3a4 + f6e8b98 commit 9ab794d
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}

Expand Down
111 changes: 91 additions & 20 deletions src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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());
Expand All @@ -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 {
Expand All @@ -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
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/com/bbn/hadder/listener/RulesListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
}
}
}
}
Expand Down

0 comments on commit 9ab794d

Please sign in to comment.