diff --git a/pom.xml b/pom.xml index dbf03e6..835275f 100644 --- a/pom.xml +++ b/pom.xml @@ -19,7 +19,7 @@ net.dv8tion JDA - 4.1.0_81 + 4.1.0_84 org.json diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index 5626793..173d6f2 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -94,6 +94,7 @@ public class Hadder { new QueueCommand(), new InfoCommand(), new SkipCommand(), + new EditRulesCommand(), new StopCommand()), config, helpCommand); builder.addEventListeners( diff --git a/src/main/java/com/bbn/hadder/Rethink.java b/src/main/java/com/bbn/hadder/Rethink.java index f501971..cf63bf4 100644 --- a/src/main/java/com/bbn/hadder/Rethink.java +++ b/src/main/java/com/bbn/hadder/Rethink.java @@ -4,7 +4,6 @@ import com.bbn.hadder.core.Config; import com.rethinkdb.RethinkDB; import com.rethinkdb.gen.exc.ReqlOpFailedError; import com.rethinkdb.net.Connection; -import com.rethinkdb.net.Cursor; import org.json.JSONArray; import java.util.NoSuchElementException; @@ -56,33 +55,31 @@ public class Rethink { public Object get(String table, String where, String value, String column) { JSONArray array = this.getAsArray(table, where, value); - if (array.length()>0) + if (array.length() > 0) if (array.getJSONObject(0).has(column)) return array.getJSONObject(0).get(column); else return null; else return null; } - public String update(String table, String wherevalue, String what, String whatvalue) { - String out = ""; + public void update(String table, String value, String what, String whatvalue) { try { - Cursor cursor = r.table(table).get(wherevalue).update(r.hashMap(what, whatvalue)).run(conn); - out=cursor.toString(); - } catch (ClassCastException ignored) {} - return out; + r.table(table).get(value).update(r.hashMap(what, whatvalue)).run(conn); + } catch (ClassCastException e) { + e.printStackTrace(); + } } - public String insert(String table, Object object) { - String out = ""; + public void insert(String table, Object object) { try { - Cursor cursor = r.table(table).insert(object).run(conn); - out = cursor.next().toString(); - } catch (ClassCastException ignored) {} - return out; + r.table(table).insert(object).run(conn); + } catch (ClassCastException e) { + e.printStackTrace(); + } } - public void remove(String table, String where, String wherevalue) { - r.table(table).filter(row -> row.g(where.toLowerCase()).eq(wherevalue)).delete().run(conn); + public void remove(String table, String where, String value) { + r.table(table).filter(row -> row.g(where.toLowerCase()).eq(value)).delete().run(conn); } public void setup() { @@ -108,16 +105,16 @@ public class Rethink { } } - public void setUserPrefix(String prefix, String userid) { - this.update("user", userid, "prefix", prefix); + public void setUserPrefix(String prefix, String user_id) { + this.update("user", user_id, "prefix", prefix); } public String getUserPrefix(String id) { return (String) this.get("user", "id", id, "prefix"); } - public void setGuildPrefix(String prefix, String guildid) { - this.update("server", guildid, "prefix", prefix); + public void setGuildPrefix(String prefix, String guild_id) { + this.update("server", guild_id, "prefix", prefix); } public String getGuildPrefix(String id) { @@ -139,40 +136,40 @@ public class Rethink { this.insert("user", r.hashMap("id", id).with("prefix", "h.").with("language", "en")); } - public void setNeededstars(String stars, String guildid) { - this.update("server", guildid, "neededstars", stars); + public void setNeededstars(String stars, String guild_id) { + this.update("server", guild_id, "neededstars", stars); } - public String getNeededstars(String guildid) { - return (String) this.get("server", "id", guildid, "neededstars"); + public String getNeededstars(String guild_id) { + return (String) this.get("server", "id", guild_id, "neededstars"); } - public void setStarboardChannel(String guildid, String channelid) { - this.update("server", guildid, "starboard", channelid); + public void setStarboardChannel(String guild_id, String channel_id) { + this.update("server", guild_id, "starboard", channel_id); } - public String getStarboardChannel(String guildid) { - return (String) this.get("server", "id", guildid, "starboard"); + public String getStarboardChannel(String guild_id) { + return (String) this.get("server", "id", guild_id, "starboard"); } - public boolean hasStarboardChannel(String guildid) { - return !this.get("server", "id", guildid, "starboard").equals(""); + public boolean hasStarboardChannel(String guild_id) { + return !this.get("server", "id", guild_id, "starboard").equals(""); } - public void insertStarboardMessage(String messageid, String guildid, String starboardmessageid) { - this.insert("stars", r.hashMap("id", messageid).with("guild", guildid).with("starboardmsg", starboardmessageid)); + public void insertStarboardMessage(String message_id, String guild_id, String starboardmessageid) { + this.insert("stars", r.hashMap("id", message_id).with("guild", guild_id).with("starboardmsg", starboardmessageid)); } - public String getStarboardMessage(String messageid) { - return (String) this.get("stars", "id", messageid, "starboardmsg"); + public String getStarboardMessage(String message_id) { + return (String) this.get("stars", "id", message_id, "starboardmsg"); } - public void removeStarboardMessage(String messageid) { - this.remove("stars", "id", messageid); + public void removeStarboardMessage(String message_id) { + this.remove("stars", "id", message_id); } - public boolean hasStarboardMessage(String messageid) { - return this.get("stars", "id", messageid, "guild") != null; + public boolean hasStarboardMessage(String message_id) { + return this.get("stars", "id", message_id, "guild") != null; } public void updateRules(String guild_id, String message_id, String role_id, String accept_emote, String decline_emote) { diff --git a/src/main/java/com/bbn/hadder/commands/CommandEvent.java b/src/main/java/com/bbn/hadder/commands/CommandEvent.java index 7ea21a7..fb9d643 100644 --- a/src/main/java/com/bbn/hadder/commands/CommandEvent.java +++ b/src/main/java/com/bbn/hadder/commands/CommandEvent.java @@ -4,6 +4,7 @@ import com.bbn.hadder.Rethink; import com.bbn.hadder.commands.general.HelpCommand; import com.bbn.hadder.core.CommandHandler; import com.bbn.hadder.core.Config; +import com.bbn.hadder.utils.EventWaiter; import com.bbn.hadder.utils.MessageEditor; import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.entities.Message; @@ -18,14 +19,16 @@ public class CommandEvent extends MessageReceivedEvent { private CommandHandler commandHandler; private HelpCommand helpCommand; private MessageEditor messageEditor; + private EventWaiter eventWaiter; - public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor) { + public CommandEvent(@Nonnull JDA api, long responseNumber, @Nonnull Message message, Rethink rethink, Config config, CommandHandler commandHandler, HelpCommand helpCommand, MessageEditor messageEditor, EventWaiter eventWaiter) { super(api, responseNumber, message); this.rethink = rethink; this.config = config; this.commandHandler = commandHandler; this.helpCommand = helpCommand; this.messageEditor = messageEditor; + this.eventWaiter = eventWaiter; } public Rethink getRethink() { @@ -47,4 +50,8 @@ public class CommandEvent extends MessageReceivedEvent { public MessageEditor getMessageEditor() { return messageEditor; } + + public EventWaiter getEventWaiter() { + return eventWaiter; + } } diff --git a/src/main/java/com/bbn/hadder/commands/misc/FeedbackCommand.java b/src/main/java/com/bbn/hadder/commands/misc/FeedbackCommand.java index d081a46..a84d9f3 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/FeedbackCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/FeedbackCommand.java @@ -37,6 +37,7 @@ public class FeedbackCommand implements Command { GitHub connection = GitHub.connectUsingOAuth(event.getConfig().getGitHubToken()); GHRepository Hadder = connection.getOrganization("BigBotNetwork").getRepository("Hadder"); GHIssue issue = Hadder.createIssue(title).body("Feedback by " + event.getAuthor().getAsTag() + "
" + description).label("feedback").create(); + issue.addLabels("feedback"); event.getTextChannel().sendMessage( event.getMessageEditor().getMessage( MessageEditor.MessageType.INFO, diff --git a/src/main/java/com/bbn/hadder/commands/moderation/EditRulesCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/EditRulesCommand.java new file mode 100644 index 0000000..c8e9fd3 --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/moderation/EditRulesCommand.java @@ -0,0 +1,98 @@ +package com.bbn.hadder.commands.moderation; + +import com.bbn.hadder.commands.Command; +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 + */ + +@Perms(Perm.MANAGE_SERVER) +public class EditRulesCommand implements Command { + + @Override + public void executed(String[] args, CommandEvent event) { + if (event.getRethink().getRulesMID(event.getGuild().getId()).length() == 18) { + 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 -> { + 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.getJDA(), event.getAuthor()); + }, event.getJDA(), event.getAuthor()); + } else { + event.getTextChannel().sendMessage(event.getMessageEditor().getMessage(MessageEditor.MessageType.ERROR, + "commands.moderation.editrules.error.title", "", + "commands.moderation.editrules.error.description", event.getRethink().getGuildPrefix(event.getGuild().getId())).build()).queue(); + } + } + + 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"}; + } + + @Override + public String description() { + return "commands.moderation.editrules.help.description"; + } + + @Override + public String usage() { + return ""; + } +} 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 f05e1c2..99cc13e 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java @@ -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,16 +120,16 @@ 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( event.getMessageEditor().getMessage( MessageEditor.MessageType.INFO, "commands.moderation.rules.emote.decline.title", "", - "commands.moderation.rules.emote.decline.title", String.valueOf(aemote)) + "commands.moderation.rules.emote.decline.description", 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) diff --git a/src/main/java/com/bbn/hadder/core/CommandHandler.java b/src/main/java/com/bbn/hadder/core/CommandHandler.java index c8e8dd3..9d7469f 100644 --- a/src/main/java/com/bbn/hadder/core/CommandHandler.java +++ b/src/main/java/com/bbn/hadder/core/CommandHandler.java @@ -4,6 +4,7 @@ import com.bbn.hadder.Rethink; import com.bbn.hadder.commands.Command; import com.bbn.hadder.commands.CommandEvent; import com.bbn.hadder.commands.general.HelpCommand; +import com.bbn.hadder.utils.EventWaiter; import com.bbn.hadder.utils.MessageEditor; import net.dv8tion.jda.api.events.message.MessageReceivedEvent; @@ -34,7 +35,7 @@ public class CommandHandler { if (args.length > 0 && args[0].equals("")) args = new String[0]; CommandEvent commandEvent = new CommandEvent(event.getJDA(), event.getResponseNumber(), event.getMessage(), rethink, - config, this, helpCommand, new MessageEditor(rethink, event.getAuthor())); + config, this, helpCommand, new MessageEditor(rethink, event.getAuthor()), new EventWaiter()); if (cmd.getClass().getAnnotations().length > 0 && !Arrays.asList(cmd.getClass().getAnnotations()).contains(Perms.class)) { for (Perm perm : cmd.getClass().getAnnotation(Perms.class).value()) { if (!perm.check(commandEvent)) { diff --git a/src/main/resources/Translations/Translations_en.properties b/src/main/resources/Translations/Translations_en.properties index 219fc21..660e58c 100644 --- a/src/main/resources/Translations/Translations_en.properties +++ b/src/main/resources/Translations/Translations_en.properties @@ -136,7 +136,7 @@ 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.title = Rules message 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. @@ -148,17 +148,30 @@ commands.moderation.rules.emote.accept.title = Custom Accept Emote commands.moderation.rules.emote.accept.description = The role has been successfully set to %extra%. Now send me the emote on which your user should react to to get verified. commands.moderation.rules.emote.decline.title = Custom Decline Emote commands.moderation.rules.emote.decline.description = The first emote has been successfully set to %extra%. Please send me now the decline emote. -commands.moderation.rules.success.title = Successfully set the rules -commands.moderation.rules.success.description = I successfully send the rules in %extra%. commands.moderation.rules.emote.error.access.description = I can not access the custom emote(s). commands.moderation.rules.emote.error.equal.title = Emotes are equal commands.moderation.rules.emote.error.equal.description = The 1st and 2nd emote equals each other. commands.moderation.rules.emoji.decline.description = The first emote has been successfully set. Please send me now the decline emote. commands.moderation.rules.emoji.error.description = The given emote can't be used. +commands.moderation.rules.success.title = Successfully set the rules +commands.moderation.rules.success.description = I successfully send the rules in %extra%. 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 commands.music.join.success.description = I successfully connected to %extra%.