From 399aade1302b6a561591a7bc1a44f4dd81b4a36e Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 23 Nov 2019 02:54:07 -0800 Subject: [PATCH 1/4] Better code --- src/main/java/com/bbn/hadder/Hadder.java | 2 +- .../java/com/bbn/hadder/commands/misc/GitHubCommand.java | 5 ++++- .../java/com/bbn/hadder/commands/misc/InviteCommand.java | 5 ++++- .../{ScreenshareCommand.java => ScreenShareCommand.java} | 3 ++- .../com/bbn/hadder/commands/moderation/ClearCommand.java | 4 ---- .../bbn/hadder/commands/moderation/GuildPrefixCommand.java | 2 -- .../com/bbn/hadder/commands/moderation/KickCommand.java | 2 -- .../com/bbn/hadder/commands/moderation/NickCommand.java | 4 ---- .../java/com/bbn/hadder/commands/owner/RebootCommand.java | 2 +- .../com/bbn/hadder/commands/settings/PrefixCommand.java | 2 -- src/main/java/com/bbn/hadder/core/LinkUtils.java | 6 ++---- 11 files changed, 14 insertions(+), 23 deletions(-) rename src/main/java/com/bbn/hadder/commands/misc/{ScreenshareCommand.java => ScreenShareCommand.java} (99%) diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index ce0ae2cb..cb7133c1 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -52,7 +52,7 @@ private static void startBot() { new GifCommand(), new ClearCommand(), new GitHubCommand(), - new ScreenshareCommand(), + new ScreenShareCommand(), new RebootCommand(), new EqualsCommand(), new InviteCommand(), diff --git a/src/main/java/com/bbn/hadder/commands/misc/GitHubCommand.java b/src/main/java/com/bbn/hadder/commands/misc/GitHubCommand.java index 2cc681bf..ed6b471e 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/GitHubCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/GitHubCommand.java @@ -68,7 +68,10 @@ public void executed(String[] args, CommandEvent event) { } } } else { - event.getTextChannel().sendMessage("SOON").queue(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, new EmbedBuilder() + .setTitle("Connect you GH account")) + .setDescription("[Please connect your GitHub account here](https://github.com/login/oauth/authorize?client_id=25321f690bb1b6952942)") + .build()).queue(); } } diff --git a/src/main/java/com/bbn/hadder/commands/misc/InviteCommand.java b/src/main/java/com/bbn/hadder/commands/misc/InviteCommand.java index 6357d0e0..f845fa22 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/InviteCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/InviteCommand.java @@ -15,7 +15,10 @@ public class InviteCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder).setTitle("Invite me!").setDescription("[Invite me here!](https://discordapp.com/oauth2/authorize?client_id=" + Hadder.shardManager.getGuilds().get(0).getSelfMember().getId() + "&scope=bot&permissions=470133879)").build()).queue(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder) + .setTitle("Invite me!") + .setDescription("[Invite me here!](https://discordapp.com/oauth2/authorize?client_id=" + Hadder.shardManager.getGuilds().get(0).getSelfMember().getId() + "&scope=bot&permissions=470133879)") + .build()).queue(); } @Override diff --git a/src/main/java/com/bbn/hadder/commands/misc/ScreenshareCommand.java b/src/main/java/com/bbn/hadder/commands/misc/ScreenShareCommand.java similarity index 99% rename from src/main/java/com/bbn/hadder/commands/misc/ScreenshareCommand.java rename to src/main/java/com/bbn/hadder/commands/misc/ScreenShareCommand.java index c9adbe0d..9a048a40 100644 --- a/src/main/java/com/bbn/hadder/commands/misc/ScreenshareCommand.java +++ b/src/main/java/com/bbn/hadder/commands/misc/ScreenShareCommand.java @@ -9,7 +9,8 @@ import java.util.List; -public class ScreenshareCommand implements Command { +public class ScreenShareCommand implements Command { + @Override public void executed(String[] args, CommandEvent event) { if (args.length>0) { diff --git a/src/main/java/com/bbn/hadder/commands/moderation/ClearCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/ClearCommand.java index 98ad5b57..0373508b 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/ClearCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/ClearCommand.java @@ -36,8 +36,6 @@ public void executed(String[] args, CommandEvent event) { EmbedBuilder builder = new EmbedBuilder(); event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder).setDescription("Successfully deleted " + nbToDelete + " messages.").build()).queue(); } catch (NumberFormatException e) { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You have to specify a number!").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } } else { @@ -49,8 +47,6 @@ public void executed(String[] args, CommandEvent event) { event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder).build()).queue(); } } else { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You have to specify a number!").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } } diff --git a/src/main/java/com/bbn/hadder/commands/moderation/GuildPrefixCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/GuildPrefixCommand.java index 5c4e493a..10f9a099 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/GuildPrefixCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/GuildPrefixCommand.java @@ -24,8 +24,6 @@ public void executed(String[] args, CommandEvent event) { event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("The prefix must not contain **\"**").build()).queue(); } } else { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You have to set a prefix.").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } } else { diff --git a/src/main/java/com/bbn/hadder/commands/moderation/KickCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/KickCommand.java index 7fc6f853..65877e6d 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/KickCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/KickCommand.java @@ -38,8 +38,6 @@ public void executed(String[] args, CommandEvent event) { event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You can't kick yourself.").build()).queue(); } } else if (event.getMessage().getMentionedMembers().size() == 0) { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You have to mention at least one user!").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } else if (event.getMessage().getMentionedMembers().size() > 1) { for (int i = 0; i < event.getMessage().getMentionedMembers().size(); i++) { diff --git a/src/main/java/com/bbn/hadder/commands/moderation/NickCommand.java b/src/main/java/com/bbn/hadder/commands/moderation/NickCommand.java index f8d44118..37cab596 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/NickCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/NickCommand.java @@ -31,8 +31,6 @@ public void executed(String[] args, CommandEvent event) { event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder).setTitle("✅ Successfully nicked ✅").setDescription("I successfully nicked " + event.getMessage().getMentionedMembers().get(0).getUser().getAsTag() + ".").build()).queue(); } } else { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setTitle("Missing arguments").setDescription("You have to specify a new nickname for the user(s).").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } } else { @@ -51,8 +49,6 @@ public void executed(String[] args, CommandEvent event) { } } } else if (event.getMessage().getMentionedMembers().size() == 0) { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You have to mention at least one user!").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } else { for (int i = 0; i < event.getMessage().getMentionedMembers().size(); i++) { diff --git a/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java b/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java index fceaa385..c5e3c5ef 100644 --- a/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java +++ b/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java @@ -16,7 +16,7 @@ public class RebootCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { if (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")) { - + System.exit(69); } else { EmbedBuilder builder = new EmbedBuilder(); event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder).build()).queue(); diff --git a/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java b/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java index 70ea455e..5c10d32b 100644 --- a/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java +++ b/src/main/java/com/bbn/hadder/commands/settings/PrefixCommand.java @@ -18,8 +18,6 @@ public void executed(String[] args, CommandEvent event) { EmbedBuilder builder = new EmbedBuilder(); event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder).setTitle("✅ Successfully set ✅").setDescription("I successfully set the new prefix for you to " + args[0]).build()).queue(); } else { - EmbedBuilder builder = new EmbedBuilder(); - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, builder).setDescription("You have to set a prefix.").build()).queue(); event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); } } diff --git a/src/main/java/com/bbn/hadder/core/LinkUtils.java b/src/main/java/com/bbn/hadder/core/LinkUtils.java index 1d5315a5..ea6bd6cf 100644 --- a/src/main/java/com/bbn/hadder/core/LinkUtils.java +++ b/src/main/java/com/bbn/hadder/core/LinkUtils.java @@ -25,7 +25,7 @@ public void sendAll(JSONArray jsonArray, JDA jda, Message message, User user, Li private void send(Message message, TextChannel channel, User user, List reactions, boolean usedmessagebuilder) { if (!channel.getGuild().getSelfMember().hasPermission(Permission.MANAGE_WEBHOOKS)) { - channel.sendMessage(new EmbedBuilder().setTitle("Wait a sec").setDescription("Please contact the owner of the server to give me the manage webhook permission").build()).queue(); + channel.sendMessage(new EmbedBuilder().setTitle("Wait a sec").setDescription("Please contact the owner of the server to give me the Manage Webhooks permission").build()).queue(); } else { channel.retrieveWebhooks().queue( webhooks -> { @@ -87,9 +87,7 @@ private void sendMessage(Webhook webhook, TextChannel channel, User user, Messag } } ); - } catch (InterruptedException e) { - e.printStackTrace(); - } catch (ExecutionException e) { + } catch (InterruptedException | ExecutionException e) { e.printStackTrace(); } } From 53ef9fb1ff530e48bc205e188e335f0158e570ae Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 23 Nov 2019 03:08:33 -0800 Subject: [PATCH 2/4] Introducing Eval Command --- src/main/java/com/bbn/hadder/Hadder.java | 1 + .../hadder/commands/owner/EvalCommand.java | 38 +++++++++++++++++++ .../hadder/commands/owner/RebootCommand.java | 2 +- .../commands/owner/ShutdownCommand.java | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java diff --git a/src/main/java/com/bbn/hadder/Hadder.java b/src/main/java/com/bbn/hadder/Hadder.java index cb7133c1..afcf18d3 100644 --- a/src/main/java/com/bbn/hadder/Hadder.java +++ b/src/main/java/com/bbn/hadder/Hadder.java @@ -71,6 +71,7 @@ private static void startBot() { new RulesCommand(), new FeedbackCommand(), new AvatarCommand(), + new EvalCommand(), new LinkCommand()), config, helpCommand); builder.addEventListeners( diff --git a/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java b/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java new file mode 100644 index 00000000..1e382b2c --- /dev/null +++ b/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java @@ -0,0 +1,38 @@ +package com.bbn.hadder.commands.owner; + +/* + * @author Skidder / GregTCLTK + */ + +import com.bbn.hadder.commands.Command; +import com.bbn.hadder.commands.CommandEvent; +import com.bbn.hadder.utils.MessageEditor; +import net.dv8tion.jda.api.EmbedBuilder; + +public class EvalCommand implements Command { + + @Override + public void executed(String[] args, CommandEvent event) { + if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) { + + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder).build()).queue(); + } + } + + @Override + public String[] labels() { + return new String[]{"eval"}; + } + + @Override + public String description() { + return "You know what a eval command is ;)"; + } + + @Override + public String usage() { + return ""; + } +} diff --git a/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java b/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java index c5e3c5ef..12781230 100644 --- a/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java +++ b/src/main/java/com/bbn/hadder/commands/owner/RebootCommand.java @@ -15,7 +15,7 @@ public class RebootCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { - if (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")) { + if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) { System.exit(69); } else { EmbedBuilder builder = new EmbedBuilder(); diff --git a/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java b/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java index 14c161bc..142c74f6 100644 --- a/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java +++ b/src/main/java/com/bbn/hadder/commands/owner/ShutdownCommand.java @@ -12,7 +12,7 @@ public class ShutdownCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { - if (event.getAuthor().getId().equals("477141528981012511") || event.getAuthor().getId().equals("261083609148948488")) { + if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) { EmbedBuilder builder = new EmbedBuilder(); event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder).setTitle("Shutdown").build()).queue(); event.getJDA().getShardManager().shutdown(); From aedf64d295b443d8b6db87c939c4597e06b5a57b Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 23 Nov 2019 03:21:41 -0800 Subject: [PATCH 3/4] Eval Command --- .../hadder/commands/owner/EvalCommand.java | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java b/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java index 1e382b2c..0d560c44 100644 --- a/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java +++ b/src/main/java/com/bbn/hadder/commands/owner/EvalCommand.java @@ -9,12 +9,71 @@ import com.bbn.hadder.utils.MessageEditor; import net.dv8tion.jda.api.EmbedBuilder; +import javax.script.ScriptEngine; +import javax.script.ScriptEngineManager; +import javax.script.ScriptException; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.ScheduledFuture; +import java.util.concurrent.TimeUnit; + public class EvalCommand implements Command { @Override public void executed(String[] args, CommandEvent event) { if (event.getConfig().getOwners().toString().contains(event.getAuthor().getId())) { - + if (args.length > 0) { + ScriptEngine engine = new ScriptEngineManager().getEngineByName("nashorn"); + + try { + engine.eval("var imports = new JavaImporter(java.io, java.lang, java.util);"); + } catch (ScriptException ex) { + ex.printStackTrace(); + } + + engine.put("event", event); + engine.put("jda", event.getJDA()); + engine.put("message", event.getMessage()); + engine.put("guild", event.getGuild()); + engine.put("channel", event.getChannel()); + engine.put("vc", event.getMember().getVoiceState().getChannel()); + engine.put("author", event.getAuthor()); + engine.put("member", event.getMember()); + engine.put("self", event.getGuild().getSelfMember()); + + ScheduledExecutorService service = Executors.newScheduledThreadPool(1); + + ScheduledFuture future = service.schedule(() -> { + + long startExec = System.currentTimeMillis(); + Object out = null; + EmbedBuilder builder = new EmbedBuilder(); + + try { + String script = ""; + for (int i = 0; i < args.length; i++) { + args[i] = args[i].replace("```java", "").replace("```", ""); + script += i == args.length-1 ? args[i]:args[i]+" "; + } + builder.addField("Input", "```java\n\n" + script + "```", false); + + out = engine.eval(script); + builder.addField("Output", "```java\n\n" + out.toString() + "```", false); + + } catch (Exception ex) { + builder.addField("Error", "```java\n\n" + ex.getMessage() + "```", false); + } + + builder.addField("Timing", System.currentTimeMillis()-startExec + " milliseconds", false); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.INFO, builder).setTitle("Eval Command").build()).queue(); + + service.shutdownNow(); + + }, 0, TimeUnit.MILLISECONDS); + + } else { + event.getHelpCommand().sendHelp(this, event.getRethink(), event.getAuthor(), event.getTextChannel()); + } } else { EmbedBuilder builder = new EmbedBuilder(); event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder).build()).queue(); From c0d25b7ae192837faa80b741e2eb4892f8a35279 Mon Sep 17 00:00:00 2001 From: GregTCLTK Date: Sat, 23 Nov 2019 03:49:53 -0800 Subject: [PATCH 4/4] Rules MESSAGE_WRITE check --- .../commands/moderation/RulesCommand.java | 206 +++++++++--------- 1 file changed, 109 insertions(+), 97 deletions(-) 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 e2e20cca..85ff9fc7 100644 --- a/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java +++ b/src/main/java/com/bbn/hadder/commands/moderation/RulesCommand.java @@ -28,118 +28,130 @@ public void executed(String[] args, CommandEvent event) { 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() - .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.") + if (event.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)) { + 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(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()); + 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 { - 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()); - }, 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(); + } } else { - event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.WARNING, new EmbedBuilder() - .setTitle("Wrong Guild") - .setDescription("The mentioned channel must be on this guid!")) + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder) .build()).queue(); } } else { 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.") + if (event.getGuild().getSelfMember().hasPermission(channel, Permission.MESSAGE_WRITE)) { + 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(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()); + 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 { - 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(); + } } - } 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()); - }, 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(); + } else { + EmbedBuilder builder = new EmbedBuilder(); + event.getTextChannel().sendMessage(new MessageEditor().setDefaultSettings(MessageEditor.MessageType.NO_PERMISSION, builder) + .build()).queue(); + } + } 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 { EmbedBuilder builder = new EmbedBuilder();