Edit Rules command #253

This commit is contained in:
GregTCLTK 2019-12-26 21:46:13 +01:00
parent 967985c80e
commit 8d3001adcf
No known key found for this signature in database
GPG key ID: A91BADE5C070FF67
3 changed files with 66 additions and 7 deletions

View file

@ -5,6 +5,7 @@ import com.bbn.hadder.commands.CommandEvent;
import com.bbn.hadder.core.Perm;
import com.bbn.hadder.core.Perms;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.entities.TextChannel;
/**
* @author Skidder / GregTCLTK
@ -19,8 +20,38 @@ public class EditRulesCommand implements Command {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.moderation.editrules.message.title",
"commands.moderation.editrules.message.description").build()).queue();
event.getEventWaiter().newOnMessageEventWaiter(event1 -> {
event.getEventWaiter().newOnMessageEventWaiter(event1 -> {
String rules = event1.getMessage().getContentRaw();
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.moderation.editrules.channel.title",
"commands.moderation.editrules.channel.description").build()).queue();
event.getEventWaiter().newOnMessageEventWaiter(event2 -> {
if (event2.getMessage().getMentionedChannels().size() == 1) {
try {
TextChannel channel = event2.getMessage().getMentionedChannels().get(0);
checkChannel(event, rules, channel);
} catch (Exception e) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.moderation.editrules.channel.error.title",
"commands.moderation.editrules.channel.error.description")
.build()).queue();
}
} else {
try {
TextChannel channel = event1.getGuild().getTextChannelsByName(event2.getMessage().getContentRaw(), true).get(0);
checkChannel(event, rules, channel);
} catch (Exception e) {
event.getTextChannel().sendMessage(
event.getMessageEditor().getMessage(
MessageEditor.MessageType.ERROR,
"commands.moderation.editrules.channel.error.title",
"commands.moderation.editrules.channel.error.description")
.build()).queue();
}
}
}, event);
}, event);
} else {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
@ -29,6 +60,27 @@ public class EditRulesCommand implements Command {
}
}
public void checkChannel(CommandEvent event, String rules, TextChannel channel) {
try {
channel.retrieveMessageById(event.getRethink().getRulesMID(event.getGuild().getId())).queue();
setRules(event, rules, channel);
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO,
"commands.moderation.editrules.success.title",
"commands.moderation.editrules.success.description").build()).queue();
} catch (Exception e) {
event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR,
"commands.moderation.editrules.channel.message.error.title",
"commands.moderation.editrules.channel.message.error.description").build()).queue();
}
}
public void setRules(CommandEvent event, String rules, TextChannel channel) {
channel.retrieveMessageById(event.getRethink().getRulesMID(event.getGuild().getId())).complete().editMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO)
.setTitle("Rules")
.setDescription(rules)
.build()).queue();
}
@Override
public String[] labels() {
return new String[]{"editrules", "rulesedit", "edit_rules", "rules_edit"};

View file

@ -29,7 +29,7 @@ public class RulesCommand implements Command {
"commands.moderation.rules.setup.title",
"commands.moderation.rules.setup.description")
.build()).queue();
new EventWaiter().newOnMessageEventWaiter(event1 -> {
event.getEventWaiter().newOnMessageEventWaiter(event1 -> {
if (event1.getMessage().getMentionedChannels().size() == 1) {
try {
TextChannel channel = event1.getMessage().getMentionedChannels().get(0);
@ -70,7 +70,7 @@ public class RulesCommand implements Command {
"commands.moderation.rules.rules.description",
channel.getName())
.build()).queue();
new EventWaiter().newOnMessageEventWaiter(event2 -> {
event.getEventWaiter().newOnMessageEventWaiter(event2 -> {
String message = event2.getMessage().getContentRaw();
event2.getChannel().sendMessage(
event.getMessageEditor().getMessage(
@ -120,7 +120,7 @@ public class RulesCommand implements Command {
"",
"commands.moderation.rules.emote.accept.description", role.getName())
.build()).queue();
new EventWaiter().newOnMessageEventWaiter(event4 -> {
event.getEventWaiter().newOnMessageEventWaiter(event4 -> {
if (event4.getMessage().getEmotes().size() == 1) {
Emote aemote = event4.getMessage().getEmotes().get(0);
event4.getChannel().sendMessage(
@ -129,7 +129,7 @@ public class RulesCommand implements Command {
"commands.moderation.rules.emote.decline.title", "",
"commands.moderation.rules.emote.decline.title", String.valueOf(aemote))
.build()).queue();
new EventWaiter().newOnMessageEventWaiter(event5 -> {
event.getEventWaiter().newOnMessageEventWaiter(event5 -> {
Emote demote = event5.getMessage().getEmotes().get(0);
if (!aemote.equals(demote)) {
Message rules = channel.sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO)
@ -174,7 +174,7 @@ public class RulesCommand implements Command {
"commands.moderation.rules.emote.decline.title",
"commands.moderation.rules.emoji.decline.description")
.build()).queue();
new EventWaiter().newOnMessageEventWaiter(event5 -> {
event.getEventWaiter().newOnMessageEventWaiter(event5 -> {
String demote = event5.getMessage().getContentRaw();
if (!aemote.equals(demote)) {
Message rules = channel.sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.INFO)

View file

@ -136,7 +136,6 @@ commands.moderation.rules.setup.title = Set up rules
commands.moderation.rules.setup.description = Welcome to the Hadder rules setup. Please mention the channel in which I should send the rules. Your message should look like\: \#rules or \#verify.
commands.moderation.rules.channel.error.title = Channel not found
commands.moderation.rules.channel.error.description = I can't find the specified channel. Please start the setup again.
commands.moderation.rules.rules.title = Rules
commands.moderation.rules.rules.description = The channel was successfully set to %extra%. Please send me the rules now.
commands.moderation.rules.role.title = Role to assign
commands.moderation.rules.role.description = The rules were successfully set. Please send me the name of the role which the user receives after he accepted the rules.
@ -159,10 +158,18 @@ commands.moderation.rules.error.message.title = Can't write messages
commands.moderation.rules.error.message.description = I can not write messages in the specified channel
commands.moderation.rules.help.description = Setup the rules on your Discord server
commands.moderation.starboard.success.title = Successfully set the Channel\!
commands.moderation.editrules.channel.title = Rules channel
commands.moderation.editrules.channel.description = Please send me the channel with the rules as mention
commands.moderation.editrules.channel.found.error.title = Channel not found
commands.moderation.editrules.channel.found.error.description = I can't find the specified channel. Please start the edit process again.
commands.moderation.editrules.channel.message.error.title = No rules message
commands.moderation.editrules.channel.message.error.description = I can not find the rules message in the specified channel.
commands.moderation.editrules.message.title = New message
commands.moderation.editrules.message.description = Please send me the new rules message now.
commands.moderation.editrules.error.title = No rules
commands.moderation.editrules.error.description = There is nor rules message in this server. Please setup the rules first with %extra%rules
commands.moderation.editrules.success.title = Successfully changed
commands.moderation.editrules.success.description = I successfully changed the rules
commands.moderation.editrules.help.description = Edits the rules message.
commands.music.join.success.title = Successfully connected