From 0ce0c778b64b890fbb783342ad95714fb92bc075 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 16:15:06 +0100 Subject: [PATCH 001/182] added ban and kick command --- .../togetherjava/tjbot/commands/Commands.java | 4 +- .../tjbot/commands/moderation/BanCommand.java | 70 +++++++++++++++++++ .../commands/moderation/KickCommand.java | 63 +++++++++++++++++ .../commands/moderation/package-info.java | 4 ++ 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index 88d6f4dd6e..ee5e4e7fae 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -3,6 +3,7 @@ import org.jetbrains.annotations.NotNull; import org.togetherjava.tjbot.commands.basic.DatabaseCommand; import org.togetherjava.tjbot.commands.basic.PingCommand; +import org.togetherjava.tjbot.commands.moderation.*; import org.togetherjava.tjbot.db.Database; import java.util.Collection; @@ -33,6 +34,7 @@ public enum Commands { // NOTE The command system can add special system relevant commands also by itself, // hence this list may not necessarily represent the full list of all commands actually // available. - return List.of(new PingCommand(), new DatabaseCommand(database)); + return List.of(new PingCommand(), new DatabaseCommand(database), new KickCommand(), new BanCommand()); + } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java new file mode 100644 index 0000000000..1b5c39c513 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -0,0 +1,70 @@ +package org.togetherjava.tjbot.commands.moderation; + +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.InteractionHook; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import org.jetbrains.annotations.NotNull; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; +import org.togetherjava.tjbot.commands.SlashCommandVisibility; + +/** + * @author RealYusufIsmail + */ +public class BanCommand extends SlashCommandAdapter { + public BanCommand() { + super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); + + getData().addOption(OptionType.USER, "ban", "The user which you want to ban", true) + .addOption(OptionType.INTEGER, "del_days", "The delete message histroy", false); + + } + @Override + public void onSlashCommand(@NotNull SlashCommandEvent event) { + // Used to get the member + final Member member = event.getOption("user").getAsMember(); + + event.deferReply(true).queue(); // Let the user know we received the command before doing + // anything else + InteractionHook hook = event.getHook(); // This is a special webhook that allows you to send + // messages without having permissions in the + // channel and also allows ephemeral messages + hook.setEphemeral(true); // All messages here will now be ephemeral implicitly + + // Checks if the author has perms + if (!event.getMember().hasPermission(Permission.BAN_MEMBERS)) + { + hook.sendMessage("You do not have the required permissions to ban users from this server.").queue(); + return; + } + + // Checks if the bot has perms + Member selfMember = event.getGuild().getSelfMember(); + if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) + { + hook.sendMessage("I don't have the required permissions to ban users from this server.").queue(); + return; + } + + + // Check if the user can be banned + if (member != null && !selfMember.canInteract(member)) + { + hook.sendMessage("This user is too powerful for me to ban.").queue(); + return; + } + + //Used to delete message history + int delDays = 0; + OptionMapping option = event.getOption("del_days"); + if (option != null) // null = not provided + delDays = (int) Math.max(0, Math.min(7, option.getAsLong())); + // Ban the user and send a success response + event.getGuild().ban(member, delDays) + .flatMap(v -> hook.sendMessage("Banned user " + member.getUser())) + .queue(); + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java new file mode 100644 index 0000000000..0c648f5496 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -0,0 +1,63 @@ +package org.togetherjava.tjbot.commands.moderation; + +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.InteractionHook; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import org.jetbrains.annotations.NotNull; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; +import org.togetherjava.tjbot.commands.SlashCommandVisibility; + +/** + * @author RealYusufIsmail + */ +public class KickCommand extends SlashCommandAdapter { + public KickCommand() { + super("Kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); + + getData().addOption(OptionType.USER, "user", "The user which you want to kick", true); + } + + @Override + public void onSlashCommand(@NotNull SlashCommandEvent event) { + // Used to get the member + final Member member = event.getOption("user").getAsMember(); + + event.deferReply(true).queue(); // Let the user know we received the command before doing + // anything else + InteractionHook hook = event.getHook(); // This is a special webhook that allows you to send + // messages without having permissions in the + // channel and also allows ephemeral messages + hook.setEphemeral(true); // All messages here will now be ephemeral implicitly + + // Checks if the author has perms + if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) { + hook.sendMessage( + "You do not have the required permissions to kick users from this server.") + .queue(); + return; + } + + // Checks if the bot has perms + Member selfMember = event.getGuild().getSelfMember(); + if (!selfMember.hasPermission(Permission.KICK_MEMBERS)) { + hook.sendMessage( + "I don't have the required permissions to kick users from this server.") + .queue(); + return; + } + + // Check if the user can be kicked + if (member != null && !selfMember.canInteract(member)) { + hook.sendMessage("This user is too powerful for me to kick.").queue(); + return; + } + + // Kicks the user and send a success response + event.getGuild() + .kick(member) + .flatMap(v -> hook.sendMessage("kicked user " + member.getUser())) + .queue(); + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java new file mode 100644 index 0000000000..7971cce2ff --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java @@ -0,0 +1,4 @@ +/** + * This package offers all the moderation commands in the application. + */ +package org.togetherjava.tjbot.commands.moderation; From bc393fc2e4b35b839d1b4b3117ddf306dd7125be Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 16:17:49 +0100 Subject: [PATCH 002/182] Update Commands.java --- .../main/java/org/togetherjava/tjbot/commands/Commands.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index ee5e4e7fae..f6d6d8d70c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -34,7 +34,8 @@ public enum Commands { // NOTE The command system can add special system relevant commands also by itself, // hence this list may not necessarily represent the full list of all commands actually // available. - return List.of(new PingCommand(), new DatabaseCommand(database), new KickCommand(), new BanCommand()); + return List.of(new PingCommand(), new DatabaseCommand(database), new KickCommand(), + new BanCommand()); } } From aa83502dafc218acc5d44adbbc4c827a5e876243 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 16:50:09 +0100 Subject: [PATCH 003/182] fixed typos --- .../tjbot/commands/moderation/BanCommand.java | 28 ++++++++++--------- .../commands/moderation/KickCommand.java | 4 +-- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 1b5c39c513..b68ef701f0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -19,9 +19,10 @@ public BanCommand() { super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, "ban", "The user which you want to ban", true) - .addOption(OptionType.INTEGER, "del_days", "The delete message histroy", false); + .addOption(OptionType.INTEGER, "del_days", "The delete message history", false); } + @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member @@ -35,36 +36,37 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { hook.setEphemeral(true); // All messages here will now be ephemeral implicitly // Checks if the author has perms - if (!event.getMember().hasPermission(Permission.BAN_MEMBERS)) - { - hook.sendMessage("You do not have the required permissions to ban users from this server.").queue(); + if (!event.getMember().hasPermission(Permission.BAN_MEMBERS)) { + hook.sendMessage( + "You do not have the required permissions to ban users from this server.") + .queue(); return; } // Checks if the bot has perms Member selfMember = event.getGuild().getSelfMember(); - if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) - { - hook.sendMessage("I don't have the required permissions to ban users from this server.").queue(); + if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) { + hook.sendMessage("I don't have the required permissions to ban users from this server.") + .queue(); return; } // Check if the user can be banned - if (member != null && !selfMember.canInteract(member)) - { + if (member != null && !selfMember.canInteract(member)) { hook.sendMessage("This user is too powerful for me to ban.").queue(); return; } - //Used to delete message history + // Used to delete message history int delDays = 0; OptionMapping option = event.getOption("del_days"); if (option != null) // null = not provided delDays = (int) Math.max(0, Math.min(7, option.getAsLong())); // Ban the user and send a success response - event.getGuild().ban(member, delDays) - .flatMap(v -> hook.sendMessage("Banned user " + member.getUser())) - .queue(); + event.getGuild() + .ban(member, delDays) + .flatMap(v -> hook.sendMessage("Banned user " + member.getUser())) + .queue(); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 0c648f5496..92ca1517d8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -25,7 +25,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { final Member member = event.getOption("user").getAsMember(); event.deferReply(true).queue(); // Let the user know we received the command before doing - // anything else + // anything else InteractionHook hook = event.getHook(); // This is a special webhook that allows you to send // messages without having permissions in the // channel and also allows ephemeral messages @@ -57,7 +57,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Kicks the user and send a success response event.getGuild() .kick(member) - .flatMap(v -> hook.sendMessage("kicked user " + member.getUser())) + .flatMap(v -> hook.sendMessage("Kicked the user" + member.getUser())) .queue(); } } From 246733552c8c6c4d9cf6549eaf846a96e577ce01 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 17:15:15 +0100 Subject: [PATCH 004/182] Update KickCommand.java --- .../commands/moderation/KickCommand.java | 43 +++++++++++++------ 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 92ca1517d8..edad380d10 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -9,27 +9,44 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -/** - * @author RealYusufIsmail - */ + public class KickCommand extends SlashCommandAdapter { + /** + * Creates an instance of the kick command. + */ public KickCommand() { super("Kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, "user", "The user which you want to kick", true); + getData().addOption(OptionType.USER, "user", "The user which you want to kick", true) + .addOption(OptionType.STRING, "reason", "The reason of the kick", true); } + /** + * When triggered with {@code /kick @user reason}, the bot will respond will check if the user + * has perms. Then it will check if itself has perms to kick. If it does it will check if the user is the user + * is too powerful or not. If the user is not then bot will kick the user. + * + * @param event the corresponding event + */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member - final Member member = event.getOption("user").getAsMember(); + Member member = event.getOption("user").getAsMember(); + + //Used for the reason + String reason = event.getOption("reason").getAsString(); + + // Let the user know we received the command before doing anything else + event.deferReply(true).queue(); + + // This is a special webhook that allows you to send + // messages without having permissions in the + // channel and also allows ephemeral messages + InteractionHook hook = event.getHook(); + + // All messages here will now be ephemeral implicitly + hook.setEphemeral(true); - event.deferReply(true).queue(); // Let the user know we received the command before doing - // anything else - InteractionHook hook = event.getHook(); // This is a special webhook that allows you to send - // messages without having permissions in the - // channel and also allows ephemeral messages - hook.setEphemeral(true); // All messages here will now be ephemeral implicitly // Checks if the author has perms if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) { @@ -56,8 +73,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Kicks the user and send a success response event.getGuild() - .kick(member) - .flatMap(v -> hook.sendMessage("Kicked the user" + member.getUser())) + .kick(member, reason) + .flatMap(v -> event.reply("Kicked the user" + member.getUser().getAsTag())) .queue(); } } From 551ec7659db6d0a35a50dc569bde8f78357f0ac0 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 17:18:29 +0100 Subject: [PATCH 005/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 49 ++++++++++++++----- 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index b68ef701f0..dc48ec6392 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -11,29 +11,46 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -/** - * @author RealYusufIsmail - */ + public class BanCommand extends SlashCommandAdapter { + /** + * Creates an instance of the ban command. + */ public BanCommand() { super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, "ban", "The user which you want to ban", true) - .addOption(OptionType.INTEGER, "del_days", "The delete message history", false); + getData().addOption(OptionType.USER, "user", "The user which you want to ban", true) + .addOption(OptionType.INTEGER, "del_days", "The delete message history", true) + .addOption(OptionType.STRING, "reason", "The reason of the ban", true); + } + /** + * When triggered with {@code /ban del_days @user reason}, the bot will respond will check if the user + * has perms. Then it will check if itself has perms to ban. If it does it will check if the user is the user + * is too powerful or not. If the user is not then bot will ban the user. + * + * @param event the corresponding event + */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member - final Member member = event.getOption("user").getAsMember(); + Member member = event.getOption("user").getAsMember(); + + //Used for the reason of the ban + String reason = event.getOption("reason").getAsString(); - event.deferReply(true).queue(); // Let the user know we received the command before doing - // anything else - InteractionHook hook = event.getHook(); // This is a special webhook that allows you to send + // Let the user know we received the command before doing anything else + event.deferReply(true).queue(); + + // This is a special webhook that allows you to send // messages without having permissions in the // channel and also allows ephemeral messages - hook.setEphemeral(true); // All messages here will now be ephemeral implicitly + InteractionHook hook = event.getHook(); + + // All messages here will now be ephemeral implicitly + hook.setEphemeral(true); // Checks if the author has perms if (!event.getMember().hasPermission(Permission.BAN_MEMBERS)) { @@ -60,13 +77,19 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to delete message history int delDays = 0; + OptionMapping option = event.getOption("del_days"); - if (option != null) // null = not provided + + // null = not provided + if (option != null) { + hook.sendMessage("You have not provided a number"); delDays = (int) Math.max(0, Math.min(7, option.getAsLong())); + } + // Ban the user and send a success response event.getGuild() - .ban(member, delDays) - .flatMap(v -> hook.sendMessage("Banned user " + member.getUser())) + .ban(member, delDays, reason) + .flatMap(v -> event.reply("Banned the user " + member.getUser().getAsTag())) .queue(); } } From f8d59ac4a55fce2fffad75bb6394b0774bc1659c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 17:19:15 +0100 Subject: [PATCH 006/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index dc48ec6392..38b6f221ee 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -2,7 +2,6 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.commands.OptionMapping; From a7e19c1b32c45abce36353d5cbef621c33473e92 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:15:46 +0100 Subject: [PATCH 007/182] Update KickCommand.java --- .../commands/moderation/KickCommand.java | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index edad380d10..c82ef3ac69 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -31,35 +31,23 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member - Member member = event.getOption("user").getAsMember(); + final Member member = event.getOption("user").getAsMember(); //Used for the reason - String reason = event.getOption("reason").getAsString(); - - // Let the user know we received the command before doing anything else - event.deferReply(true).queue(); - - // This is a special webhook that allows you to send - // messages without having permissions in the - // channel and also allows ephemeral messages - InteractionHook hook = event.getHook(); - - // All messages here will now be ephemeral implicitly - hook.setEphemeral(true); - + final String reason = event.getOption("reason").getAsString(); // Checks if the author has perms if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) { - hook.sendMessage( + event.reply( "You do not have the required permissions to kick users from this server.") .queue(); return; } // Checks if the bot has perms - Member selfMember = event.getGuild().getSelfMember(); + final Member selfMember = event.getGuild().getSelfMember(); if (!selfMember.hasPermission(Permission.KICK_MEMBERS)) { - hook.sendMessage( + event.reply( "I don't have the required permissions to kick users from this server.") .queue(); return; @@ -67,7 +55,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Check if the user can be kicked if (member != null && !selfMember.canInteract(member)) { - hook.sendMessage("This user is too powerful for me to kick.").queue(); + event.reply("This user is too powerful for me to kick.").queue(); return; } From c0b796f93c4b90b8e7a4eb6aba2539b0f0e6f35d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:17:42 +0100 Subject: [PATCH 008/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index c82ef3ac69..9d2e546a04 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -24,7 +24,7 @@ public KickCommand() { /** * When triggered with {@code /kick @user reason}, the bot will respond will check if the user * has perms. Then it will check if itself has perms to kick. If it does it will check if the user is the user - * is too powerful or not. If the user is not then bot will kick the user. + * is too powerful or not. If the user is not then bot will kick the user and reply with {@code Kicked User!}. * * @param event the corresponding event */ From 73e251712d780413985c6eee38db1d51614c9894 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:19:26 +0100 Subject: [PATCH 009/182] Update KickCommand.java --- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 9d2e546a04..3e96d47e39 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -6,11 +6,15 @@ import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; public class KickCommand extends SlashCommandAdapter { + //the logger + private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); /** * Creates an instance of the kick command. */ From 605a6809f1a9ef24b88b41bcec4e7627e6c758ad Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:22:23 +0100 Subject: [PATCH 010/182] Update KickCommand.java --- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 3e96d47e39..b138a75358 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -3,7 +3,6 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.InteractionHook; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -12,6 +11,10 @@ import org.togetherjava.tjbot.commands.SlashCommandVisibility; +/** + *

+ * The implemented command is {@code /kick @user reason}, upon which the bot will kick the user. + */ public class KickCommand extends SlashCommandAdapter { //the logger private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); From 7910cce334cdb55bb4935c138deefafb06106271 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:24:14 +0100 Subject: [PATCH 011/182] Update KickCommand.java --- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 5 ----- 1 file changed, 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index b138a75358..f7d3cde42e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -37,13 +37,10 @@ public KickCommand() { */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - // Used to get the member final Member member = event.getOption("user").getAsMember(); - //Used for the reason final String reason = event.getOption("reason").getAsString(); - // Checks if the author has perms if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) { event.reply( "You do not have the required permissions to kick users from this server.") @@ -51,7 +48,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - // Checks if the bot has perms final Member selfMember = event.getGuild().getSelfMember(); if (!selfMember.hasPermission(Permission.KICK_MEMBERS)) { event.reply( @@ -60,7 +56,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - // Check if the user can be kicked if (member != null && !selfMember.canInteract(member)) { event.reply("This user is too powerful for me to kick.").queue(); return; From 44ed0bd3a4c57f19bc671bc442125fe60702ad8b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:24:52 +0100 Subject: [PATCH 012/182] Update KickCommand.java --- .../tjbot/commands/moderation/KickCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index f7d3cde42e..17250df00c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -10,6 +10,8 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; +import java.util.Objects; + /** *

@@ -37,18 +39,18 @@ public KickCommand() { */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - final Member member = event.getOption("user").getAsMember(); + final Member member = Objects.requireNonNull(event.getOption("user")).getAsMember(); - final String reason = event.getOption("reason").getAsString(); + final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); - if (!event.getMember().hasPermission(Permission.KICK_MEMBERS)) { + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { event.reply( "You do not have the required permissions to kick users from this server.") .queue(); return; } - final Member selfMember = event.getGuild().getSelfMember(); + final Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!selfMember.hasPermission(Permission.KICK_MEMBERS)) { event.reply( "I don't have the required permissions to kick users from this server.") From 32260430d4d61b1bef40248a23c10ae526cd7d40 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:26:50 +0100 Subject: [PATCH 013/182] Fix the rest tomorrow --- .../tjbot/commands/moderation/BanCommand.java | 47 ++++++++----------- 1 file changed, 20 insertions(+), 27 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 38b6f221ee..f310dff090 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -7,11 +7,21 @@ import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; +import java.util.Objects; + +/** + *

+ * The implemented command is {@code @user /ban delete-message-history-days reason}, upon which the bot will ban the user. + */ public class BanCommand extends SlashCommandAdapter { + //the logger + private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); /** * Creates an instance of the ban command. */ @@ -19,7 +29,7 @@ public BanCommand() { super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, "user", "The user which you want to ban", true) - .addOption(OptionType.INTEGER, "del_days", "The delete message history", true) + .addOption(OptionType.INTEGER, "delete-message-history-days", "The delete message history", true) .addOption(OptionType.STRING, "reason", "The reason of the ban", true); @@ -35,55 +45,38 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member - Member member = event.getOption("user").getAsMember(); + final Member member = Objects.requireNonNull(event.getOption("user")).getAsMember(); //Used for the reason of the ban - String reason = event.getOption("reason").getAsString(); - - // Let the user know we received the command before doing anything else - event.deferReply(true).queue(); - - // This is a special webhook that allows you to send - // messages without having permissions in the - // channel and also allows ephemeral messages - InteractionHook hook = event.getHook(); + final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); - // All messages here will now be ephemeral implicitly - hook.setEphemeral(true); - - // Checks if the author has perms - if (!event.getMember().hasPermission(Permission.BAN_MEMBERS)) { - hook.sendMessage( + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { + event.reply( "You do not have the required permissions to ban users from this server.") .queue(); return; } - // Checks if the bot has perms - Member selfMember = event.getGuild().getSelfMember(); + Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) { - hook.sendMessage("I don't have the required permissions to ban users from this server.") + event.reply("I don't have the required permissions to ban users from this server.") .queue(); return; } - - // Check if the user can be banned if (member != null && !selfMember.canInteract(member)) { - hook.sendMessage("This user is too powerful for me to ban.").queue(); + event.reply("This user is too powerful for me to ban.").queue(); return; } // Used to delete message history int delDays = 0; - OptionMapping option = event.getOption("del_days"); + OptionMapping option = event.getOption("delete-message-history-days"); // null = not provided - if (option != null) { - hook.sendMessage("You have not provided a number"); + if (option != null) delDays = (int) Math.max(0, Math.min(7, option.getAsLong())); - } // Ban the user and send a success response event.getGuild() From b6288111ac5f5c411727c628339e6e6f31fa7c44 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:38:35 +0100 Subject: [PATCH 014/182] Update KickCommand.java --- .../tjbot/commands/moderation/KickCommand.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 17250df00c..5a779eb9eb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -39,7 +39,7 @@ public KickCommand() { */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - final Member member = Objects.requireNonNull(event.getOption("user")).getAsMember(); + final Member user = Objects.requireNonNull(event.getOption("user")).getAsMember(); final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); @@ -58,15 +58,19 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (member != null && !selfMember.canInteract(member)) { + if (user != null && !selfMember.canInteract(user)) { event.reply("This user is too powerful for me to kick.").queue(); return; } + + assert user != null; + logger.error("The user is not provided"); + // Kicks the user and send a success response event.getGuild() - .kick(member, reason) - .flatMap(v -> event.reply("Kicked the user" + member.getUser().getAsTag())) + .kick(user, reason) + .flatMap(v -> event.reply("Kicked the user" + user.getUser().getAsTag())) .queue(); } } From f1a4aa5a855d89a449a7985ee5af094d7c449b41 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:40:11 +0100 Subject: [PATCH 015/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 5a779eb9eb..e9e7e4f43e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -24,7 +24,7 @@ public class KickCommand extends SlashCommandAdapter { * Creates an instance of the kick command. */ public KickCommand() { - super("Kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); + super("kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, "user", "The user which you want to kick", true) .addOption(OptionType.STRING, "reason", "The reason of the kick", true); From a46b4c2f7656f86fbebba37bd3f7c48add3298cd Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 19:46:28 +0100 Subject: [PATCH 016/182] Update KickCommand.java --- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index e9e7e4f43e..bdf795aa1c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -67,6 +67,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { assert user != null; logger.error("The user is not provided"); + //Add this to audit log + logger.info("User '{}' Kicked user '{}' Reason was '{}'", + selfMember, user, reason); + // Kicks the user and send a success response event.getGuild() .kick(user, reason) From e3dc6dedf06f8a67f4e0411481062200f3b07520 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 20:10:53 +0100 Subject: [PATCH 017/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 33 ++++++++++++------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index f310dff090..fb9460e244 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -3,8 +3,6 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.InteractionHook; -import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -45,7 +43,7 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member - final Member member = Objects.requireNonNull(event.getOption("user")).getAsMember(); + final Member user = Objects.requireNonNull(event.getOption("user")).getAsMember(); //Used for the reason of the ban final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); @@ -64,24 +62,37 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (member != null && !selfMember.canInteract(member)) { + if (user != null && !selfMember.canInteract(user)) { event.reply("This user is too powerful for me to ban.").queue(); return; } // Used to delete message history - int delDays = 0; + long option = Objects.requireNonNull(event.getOption("delete-message-history-days")).getAsLong(); + int delDays = (int) option; - OptionMapping option = event.getOption("delete-message-history-days"); + if(delDays < 1) { + event.reply("The deletion days of the messages must be between 1 and 7 days"); + } else if(delDays > 7) { + event.reply("The deletion days of the messages must be between 1 and 7 days"); - // null = not provided - if (option != null) - delDays = (int) Math.max(0, Math.min(7, option.getAsLong())); + } else { + delDays = Math.toIntExact(option); + } + + + + assert user != null; + logger.error("The user is not provided"); + + //Add this to audit log + logger.info("User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + selfMember, user, delDays, reason); // Ban the user and send a success response event.getGuild() - .ban(member, delDays, reason) - .flatMap(v -> event.reply("Banned the user " + member.getUser().getAsTag())) + .ban(user, delDays, reason) + .flatMap(v -> event.reply("Banned the user " + user.getUser().getAsTag())) .queue(); } } From 2aba8c23c071d9e7acaf63f51a2a5479bdfb9051 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 20:17:32 +0100 Subject: [PATCH 018/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index fb9460e244..646a12040d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -15,11 +15,13 @@ /** *

- * The implemented command is {@code @user /ban delete-message-history-days reason}, upon which the bot will ban the user. + * The implemented command is {@code @user /ban delete-message-history-days reason}, upon which the + * bot will ban the user. */ public class BanCommand extends SlashCommandAdapter { - //the logger + // the logger private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + /** * Creates an instance of the ban command. */ @@ -27,16 +29,18 @@ public BanCommand() { super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, "user", "The user which you want to ban", true) - .addOption(OptionType.INTEGER, "delete-message-history-days", "The delete message history", true) - .addOption(OptionType.STRING, "reason", "The reason of the ban", true); + .addOption(OptionType.INTEGER, "delete-message-history-days", + "The delete message history", true) + .addOption(OptionType.STRING, "reason", "The reason of the ban", true); } /** - * When triggered with {@code /ban del_days @user reason}, the bot will respond will check if the user - * has perms. Then it will check if itself has perms to ban. If it does it will check if the user is the user - * is too powerful or not. If the user is not then bot will ban the user. + * When triggered with {@code /ban del_days @user reason}, the bot will respond will check if + * the user has perms. Then it will check if itself has perms to ban. If it does it will check + * if the user is the user is too powerful or not. If the user is not then bot will ban the + * user. * * @param event the corresponding event */ @@ -45,12 +49,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Used to get the member final Member user = Objects.requireNonNull(event.getOption("user")).getAsMember(); - //Used for the reason of the ban + // Used for the reason of the ban final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { - event.reply( - "You do not have the required permissions to ban users from this server.") + event.reply("You do not have the required permissions to ban users from this server.") .queue(); return; } @@ -68,12 +71,13 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } // Used to delete message history - long option = Objects.requireNonNull(event.getOption("delete-message-history-days")).getAsLong(); + long option = + Objects.requireNonNull(event.getOption("delete-message-history-days")).getAsLong(); int delDays = (int) option; - if(delDays < 1) { + if (delDays < 1) { event.reply("The deletion days of the messages must be between 1 and 7 days"); - } else if(delDays > 7) { + } else if (delDays > 7) { event.reply("The deletion days of the messages must be between 1 and 7 days"); } else { @@ -85,8 +89,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { assert user != null; logger.error("The user is not provided"); - //Add this to audit log - logger.info("User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + // Add this to audit log + logger.info( + "User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", selfMember, user, delDays, reason); // Ban the user and send a success response From 111eec4a454902ee57dabd42b4fd153d70007bd8 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 20:17:41 +0100 Subject: [PATCH 019/182] Update KickCommand.java --- .../commands/moderation/KickCommand.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index bdf795aa1c..dfe3e04987 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -18,8 +18,9 @@ * The implemented command is {@code /kick @user reason}, upon which the bot will kick the user. */ public class KickCommand extends SlashCommandAdapter { - //the logger + // the logger private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); + /** * Creates an instance of the kick command. */ @@ -27,13 +28,14 @@ public KickCommand() { super("kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, "user", "The user which you want to kick", true) - .addOption(OptionType.STRING, "reason", "The reason of the kick", true); + .addOption(OptionType.STRING, "reason", "The reason of the kick", true); } /** * When triggered with {@code /kick @user reason}, the bot will respond will check if the user - * has perms. Then it will check if itself has perms to kick. If it does it will check if the user is the user - * is too powerful or not. If the user is not then bot will kick the user and reply with {@code Kicked User!}. + * has perms. Then it will check if itself has perms to kick. If it does it will check if the + * user is the user is too powerful or not. If the user is not then bot will kick the user and + * reply with {@code Kicked User!}. * * @param event the corresponding event */ @@ -44,16 +46,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { - event.reply( - "You do not have the required permissions to kick users from this server.") + event.reply("You do not have the required permissions to kick users from this server.") .queue(); return; } final Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!selfMember.hasPermission(Permission.KICK_MEMBERS)) { - event.reply( - "I don't have the required permissions to kick users from this server.") + event.reply("I don't have the required permissions to kick users from this server.") .queue(); return; } @@ -67,9 +67,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { assert user != null; logger.error("The user is not provided"); - //Add this to audit log - logger.info("User '{}' Kicked user '{}' Reason was '{}'", - selfMember, user, reason); + // Add this to audit log + logger.info("User '{}' Kicked user '{}' Reason was '{}'", selfMember, user, reason); // Kicks the user and send a success response event.getGuild() From 05694be5d2c0918bc1402179425753680222180b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 21:48:01 +0100 Subject: [PATCH 020/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 646a12040d..25a89f6820 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -15,7 +15,7 @@ /** *

- * The implemented command is {@code @user /ban delete-message-history-days reason}, upon which the + * The implemented command is {@code /ban @user delete-message-history-days reason}, upon which the * bot will ban the user. */ public class BanCommand extends SlashCommandAdapter { From b9663042980cc30a93991c91765e156499e92d09 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 21:52:20 +0100 Subject: [PATCH 021/182] added UnBan Command --- .../togetherjava/tjbot/commands/Commands.java | 2 +- .../tjbot/commands/moderation/BanCommand.java | 8 +-- .../commands/moderation/KickCommand.java | 8 +-- .../commands/moderation/UnBanCommand.java | 68 +++++++++++++++++++ 4 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index f6d6d8d70c..1c0e9e55e0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -35,7 +35,7 @@ public enum Commands { // hence this list may not necessarily represent the full list of all commands actually // available. return List.of(new PingCommand(), new DatabaseCommand(database), new KickCommand(), - new BanCommand()); + new BanCommand(), new UnBanCommand()); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 25a89f6820..8fcbc03533 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -58,14 +58,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!selfMember.hasPermission(Permission.BAN_MEMBERS)) { + Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to ban users from this server.") .queue(); return; } - if (user != null && !selfMember.canInteract(user)) { + if (user != null && !author.canInteract(user)) { event.reply("This user is too powerful for me to ban.").queue(); return; } @@ -92,7 +92,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Add this to audit log logger.info( "User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - selfMember, user, delDays, reason); + author, user, delDays, reason); // Ban the user and send a success response event.getGuild() diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index dfe3e04987..8bce55a1af 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -51,14 +51,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - final Member selfMember = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!selfMember.hasPermission(Permission.KICK_MEMBERS)) { + final Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the required permissions to kick users from this server.") .queue(); return; } - if (user != null && !selfMember.canInteract(user)) { + if (user != null && !author.canInteract(user)) { event.reply("This user is too powerful for me to kick.").queue(); return; } @@ -68,7 +68,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { logger.error("The user is not provided"); // Add this to audit log - logger.info("User '{}' Kicked user '{}' Reason was '{}'", selfMember, user, reason); + logger.info("User '{}' Kicked user '{}' Reason was '{}'", author, user, reason); // Kicks the user and send a success response event.getGuild() diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java new file mode 100644 index 0000000000..5ab8b4e4f1 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -0,0 +1,68 @@ +package org.togetherjava.tjbot.commands.moderation; + +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.commands.OptionType; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.togetherjava.tjbot.commands.SlashCommandAdapter; +import org.togetherjava.tjbot.commands.SlashCommandVisibility; + +import java.util.Objects; + +/** + *

+ * The implemented command is {@code /unban user_id}, upon which the + * bot will unban the user. + */ +public class UnBanCommand extends SlashCommandAdapter { + // the logger + private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + + /** + * Creates an instance of the ban command. + */ + public UnBanCommand() { + super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); + + getData().addOption(OptionType.STRING, "user_id", "The user if of the user which you want to unban", + true); + + } + + /** + * When triggered with {@code /unban user_id}}, the bot will respond will check if + * the user has perms. Then it will check if itself has perms to unban. If it does it will check + * if the user is the user is too powerful or not. If the user is not then unban will ban the + * user. + * + * @param event the corresponding event + */ + @Override + public void onSlashCommand(@NotNull SlashCommandEvent event) { + final String userId = Objects.requireNonNull(event.getOption("user_id")).getAsString(); + + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) + { + event.reply("You do not have the required permissions to ban users from this server.").queue(); + return; + } + + Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!author.hasPermission(Permission.BAN_MEMBERS)) + { + event.reply("I don't have the required permissions to unban the user from this server.").queue(); + return; + } + + // Add this to audit log + logger.info("User '{}' unbanned user id '{}'", author, userId); + + //Unbans the user + event.getGuild().unban(userId) + .flatMap(v -> event.reply("Unbanned the user")) + .queue(); + } +} From 0c92c3e962eb023d9b65aa5a9f6b3538fc941339 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 16 Oct 2021 21:55:56 +0100 Subject: [PATCH 022/182] Update UnBanCommand.java --- .../commands/moderation/UnBanCommand.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java index 5ab8b4e4f1..4ca6e2cf82 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -14,8 +14,7 @@ /** *

- * The implemented command is {@code /unban user_id}, upon which the - * bot will unban the user. + * The implemented command is {@code /unban user_id}, upon which the bot will unban the user. */ public class UnBanCommand extends SlashCommandAdapter { // the logger @@ -27,16 +26,15 @@ public class UnBanCommand extends SlashCommandAdapter { public UnBanCommand() { super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.STRING, "user_id", "The user if of the user which you want to unban", - true); + getData().addOption(OptionType.STRING, "user_id", + "The user if of the user which you want to unban", true); } /** - * When triggered with {@code /unban user_id}}, the bot will respond will check if - * the user has perms. Then it will check if itself has perms to unban. If it does it will check - * if the user is the user is too powerful or not. If the user is not then unban will ban the - * user. + * When triggered with {@code /unban user_id}}, the bot will respond will check if the user has + * perms. Then it will check if itself has perms to unban. If it does it will check if the user + * is the user is too powerful or not. If the user is not then unban will ban the user. * * @param event the corresponding event */ @@ -44,25 +42,23 @@ public UnBanCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { final String userId = Objects.requireNonNull(event.getOption("user_id")).getAsString(); - if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) - { - event.reply("You do not have the required permissions to ban users from this server.").queue(); + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { + event.reply("You do not have the required permissions to ban users from this server.") + .queue(); return; } Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) - { - event.reply("I don't have the required permissions to unban the user from this server.").queue(); + if (!author.hasPermission(Permission.BAN_MEMBERS)) { + event.reply("I don't have the required permissions to unban the user from this server.") + .queue(); return; } // Add this to audit log logger.info("User '{}' unbanned user id '{}'", author, userId); - //Unbans the user - event.getGuild().unban(userId) - .flatMap(v -> event.reply("Unbanned the user")) - .queue(); + // Unbans the user + event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); } } From 9f7dc06f4d4766835f6f0b8c19d5e432b4913f6a Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sun, 17 Oct 2021 09:11:59 +0100 Subject: [PATCH 023/182] Apply suggestions from code review Co-authored-by: java-coding-prodigy <85149944+java-coding-prodigy@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnBanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java index 4ca6e2cf82..b741c530cc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -27,7 +27,7 @@ public UnBanCommand() { super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.STRING, "user_id", - "The user if of the user which you want to unban", true); + "The id of the user which you want to unban", true); } From dbe0a35ce25f0f769ad2f8ccf3e7a85d906e1c0d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 09:14:01 +0100 Subject: [PATCH 024/182] Update UnBanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnBanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java index 4ca6e2cf82..66d55e4cd4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -27,7 +27,7 @@ public UnBanCommand() { super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.STRING, "user_id", - "The user if of the user which you want to unban", true); + "The user id of the user which you want to unban", true); } From 01d8069a12fe31925b48b5852aeec7e744a839c3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 09:47:50 +0100 Subject: [PATCH 025/182] fixed all commands --- .../tjbot/commands/moderation/BanCommand.java | 80 ++++++++----------- .../commands/moderation/KickCommand.java | 37 ++++----- .../commands/moderation/UnBanCommand.java | 17 ++-- 3 files changed, 62 insertions(+), 72 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 8fcbc03533..2eccc20d22 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -14,13 +14,18 @@ /** - *

- * The implemented command is {@code /ban @user delete-message-history-days reason}, upon which the - * bot will ban the user. + * When triggered with {@code /ban del_days @user rea son}, the bot will respond then will check if + * the user has perms. Then it will check if itself has perms to ban. If it does it will check + * if the user is too powerful or not. If the user is not then bot will ban the + * user abd reply with {@code Banned User!}. + * */ -public class BanCommand extends SlashCommandAdapter { +public final class BanCommand extends SlashCommandAdapter { // the logger private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + private static final String USER_OPTION = "user"; + private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; + private static final String REASON_OPTION = "reason"; /** * Creates an instance of the ban command. @@ -28,76 +33,59 @@ public class BanCommand extends SlashCommandAdapter { public BanCommand() { super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, "user", "The user which you want to ban", true) - .addOption(OptionType.INTEGER, "delete-message-history-days", - "The delete message history", true) - .addOption(OptionType.STRING, "reason", "The reason of the ban", true); + getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) + .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, + "The delete message history. Between 1 to 7 days", true) + .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); } - /** - * When triggered with {@code /ban del_days @user reason}, the bot will respond will check if - * the user has perms. Then it will check if itself has perms to ban. If it does it will check - * if the user is the user is too powerful or not. If the user is not then bot will ban the - * user. - * - * @param event the corresponding event - */ + @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - // Used to get the member - final Member user = Objects.requireNonNull(event.getOption("user")).getAsMember(); + Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); - // Used for the reason of the ban - final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") - .queue(); + .setEphemeral(true).queue(); return; } Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to ban users from this server.") - .queue(); + .setEphemeral(true).queue(); return; } - - if (user != null && !author.canInteract(user)) { - event.reply("This user is too powerful for me to ban.").queue(); + + if (!author.canInteract(Objects.requireNonNull(user))) { + event.reply("This user is too powerful for me to ban.") + .setEphemeral(true).queue(); return; } - // Used to delete message history - long option = - Objects.requireNonNull(event.getOption("delete-message-history-days")).getAsLong(); - int delDays = (int) option; - if (delDays < 1) { - event.reply("The deletion days of the messages must be between 1 and 7 days"); - } else if (delDays > 7) { - event.reply("The deletion days of the messages must be between 1 and 7 days"); + int deleteMessageHistoryDays = (int)Objects.requireNonNull( + event.getOption("delete-message-history-days")).getAsLong(); - } else { - delDays = Math.toIntExact(option); + if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + event.reply("The deletion days of the messages must be between 1 and 7 days") + .setEphemeral(true).queue(); + return; } - - - assert user != null; - logger.error("The user is not provided"); - - // Add this to audit log - logger.info( - "User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - author, user, delDays, reason); - // Ban the user and send a success response event.getGuild() - .ban(user, delDays, reason) + .ban(user, deleteMessageHistoryDays, reason) .flatMap(v -> event.reply("Banned the user " + user.getUser().getAsTag())) .queue(); + + // Add this to audit log + logger.info( + "User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + author, user, deleteMessageHistoryDays, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 8bce55a1af..b0a9e2f455 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -17,9 +17,12 @@ *

* The implemented command is {@code /kick @user reason}, upon which the bot will kick the user. */ -public class KickCommand extends SlashCommandAdapter { +public final class KickCommand extends SlashCommandAdapter { // the logger private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); + private static final String USER_OPTION = "user"; + private static final String REASON_OPTION = "reason"; + /** * Creates an instance of the kick command. @@ -27,53 +30,51 @@ public class KickCommand extends SlashCommandAdapter { public KickCommand() { super("kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, "user", "The user which you want to kick", true) - .addOption(OptionType.STRING, "reason", "The reason of the kick", true); + getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to kick", true) + .addOption(OptionType.STRING, REASON_OPTION, "The reason of the kick", true); } /** - * When triggered with {@code /kick @user reason}, the bot will respond will check if the user + * When triggered with {@code /kick @user reason}, the bot will respond then it will check if the user * has perms. Then it will check if itself has perms to kick. If it does it will check if the - * user is the user is too powerful or not. If the user is not then bot will kick the user and + * user is too powerful or not. If the user is not then bot will kick the user and * reply with {@code Kicked User!}. * * @param event the corresponding event */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - final Member user = Objects.requireNonNull(event.getOption("user")).getAsMember(); + Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); - final String reason = Objects.requireNonNull(event.getOption("reason")).getAsString(); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { event.reply("You do not have the required permissions to kick users from this server.") - .queue(); + .setEphemeral(true).queue(); return; } - final Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); + Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the required permissions to kick users from this server.") - .queue(); + .setEphemeral(true).queue(); return; } - if (user != null && !author.canInteract(user)) { - event.reply("This user is too powerful for me to kick.").queue(); + if (!author.canInteract(Objects.requireNonNull(user))) { + event.reply("This user is too powerful for me to kick.") + .setEphemeral(true).queue(); return; } - assert user != null; - logger.error("The user is not provided"); - - // Add this to audit log - logger.info("User '{}' Kicked user '{}' Reason was '{}'", author, user, reason); - // Kicks the user and send a success response event.getGuild() .kick(user, reason) .flatMap(v -> event.reply("Kicked the user" + user.getUser().getAsTag())) .queue(); + + // Add this to audit log + logger.info("User '{}' Kicked user '{}' Reason was '{}'", author, user, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java index 66d55e4cd4..4cedaaf85c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -16,9 +16,10 @@ *

* The implemented command is {@code /unban user_id}, upon which the bot will unban the user. */ -public class UnBanCommand extends SlashCommandAdapter { +public final class UnBanCommand extends SlashCommandAdapter { // the logger private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + private static final String USER_ID = "user_id"; /** * Creates an instance of the ban command. @@ -26,7 +27,7 @@ public class UnBanCommand extends SlashCommandAdapter { public UnBanCommand() { super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.STRING, "user_id", + getData().addOption(OptionType.STRING, USER_ID, "The user id of the user which you want to unban", true); } @@ -40,25 +41,25 @@ public UnBanCommand() { */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - final String userId = Objects.requireNonNull(event.getOption("user_id")).getAsString(); + final String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") - .queue(); + .setEphemeral(true).queue(); return; } Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to unban the user from this server.") - .queue(); + .setEphemeral(true).queue(); return; } - // Add this to audit log - logger.info("User '{}' unbanned user id '{}'", author, userId); - // Unbans the user event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); + + // Add this to audit log + logger.info("User '{}' unbanned user id '{}'", author, userId); } } From a55ecc01b9ec0edf7d76f21f4d940db9b2b17eaa Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 09:52:53 +0100 Subject: [PATCH 026/182] spotlessApply --- .../tjbot/commands/moderation/BanCommand.java | 27 ++++++++++--------- .../commands/moderation/KickCommand.java | 17 ++++++------ .../commands/moderation/UnBanCommand.java | 6 +++-- 3 files changed, 28 insertions(+), 22 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 2eccc20d22..c2f83afa53 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -14,10 +14,10 @@ /** - * When triggered with {@code /ban del_days @user rea son}, the bot will respond then will check if - * the user has perms. Then it will check if itself has perms to ban. If it does it will check - * if the user is too powerful or not. If the user is not then bot will ban the - * user abd reply with {@code Banned User!}. + * When triggered with {@code /ban del_days @user rea son}, the bot will respond then will check + * if the user has perms. Then it will check if itself has perms to ban. If it does it will check if + * the user is too powerful or not. If the user is not then bot will ban the user abd reply with + * {@code Banned User!}. * */ public final class BanCommand extends SlashCommandAdapter { @@ -50,30 +50,33 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to ban users from this server.") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } - + if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for me to ban.") - .setEphemeral(true).queue(); + event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); return; } - int deleteMessageHistoryDays = (int)Objects.requireNonNull( - event.getOption("delete-message-history-days")).getAsLong(); + int deleteMessageHistoryDays = + (int) Objects.requireNonNull(event.getOption("delete-message-history-days")) + .getAsLong(); if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { event.reply("The deletion days of the messages must be between 1 and 7 days") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index b0a9e2f455..7633954a88 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -35,10 +35,10 @@ public KickCommand() { } /** - * When triggered with {@code /kick @user reason}, the bot will respond then it will check if the user - * has perms. Then it will check if itself has perms to kick. If it does it will check if the - * user is too powerful or not. If the user is not then bot will kick the user and - * reply with {@code Kicked User!}. + * When triggered with {@code /kick @user reason}, the bot will respond then it will check if + * the user has perms. Then it will check if itself has perms to kick. If it does it will check + * if the user is too powerful or not. If the user is not then bot will kick the user and reply + * with {@code Kicked User!}. * * @param event the corresponding event */ @@ -50,20 +50,21 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { event.reply("You do not have the required permissions to kick users from this server.") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the required permissions to kick users from this server.") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for me to kick.") - .setEphemeral(true).queue(); + event.reply("This user is too powerful for me to kick.").setEphemeral(true).queue(); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java index 4cedaaf85c..06b379485a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -45,14 +45,16 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to unban the user from this server.") - .setEphemeral(true).queue(); + .setEphemeral(true) + .queue(); return; } From 0daad10413a241afdb641521540538b83540303f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 10:04:16 +0100 Subject: [PATCH 027/182] The bot will dm the user now. The bot will send a message to the user saying you have been banned for this reason : --- .../tjbot/commands/moderation/BanCommand.java | 10 ++++++++++ .../tjbot/commands/moderation/KickCommand.java | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c2f83afa53..737778b0ec 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -1,5 +1,6 @@ package org.togetherjava.tjbot.commands.moderation; +import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -44,10 +45,14 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { + JDA jda = event.getJDA(); + Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); + String userId = Objects.requireNonNull(user).getUser().getId(); + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") .setEphemeral(true) @@ -80,6 +85,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + //tells ths user he has been banned + jda.openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage("You have been banned for this reason " + reason)) + .queue(); + // Ban the user and send a success response event.getGuild() .ban(user, deleteMessageHistoryDays, reason) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 7633954a88..48c3cea9fc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -1,7 +1,9 @@ package org.togetherjava.tjbot.commands.moderation; +import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; @@ -44,10 +46,14 @@ public KickCommand() { */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { + JDA jda = event.getJDA(); + Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); + String userId = Objects.requireNonNull(user).getUser().getId(); + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { event.reply("You do not have the required permissions to kick users from this server.") .setEphemeral(true) @@ -68,6 +74,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + //tells ths user he has been kicked + jda.openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage("You have been kicked for this reason " + reason)) + .queue(); // Kicks the user and send a success response event.getGuild() From 12fc55afbfe425b3db9d9ffdce478833bba8fc39 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 10:05:13 +0100 Subject: [PATCH 028/182] spotlessApply --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 7 ++++--- .../tjbot/commands/moderation/KickCommand.java | 7 ++++--- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 737778b0ec..dfd185ece6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -85,10 +85,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - //tells ths user he has been banned + // tells ths user he has been banned jda.openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage("You have been banned for this reason " + reason)) - .queue(); + .flatMap(channel -> channel + .sendMessage("You have been banned for this reason " + reason)) + .queue(); // Ban the user and send a success response event.getGuild() diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 48c3cea9fc..76f7a0da2d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -74,10 +74,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - //tells ths user he has been kicked + // tells ths user he has been kicked jda.openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage("You have been kicked for this reason " + reason)) - .queue(); + .flatMap(channel -> channel + .sendMessage("You have been kicked for this reason " + reason)) + .queue(); // Kicks the user and send a success response event.getGuild() From fe594254ef64cec13cc6cc813e6c68f3ff6a2368 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 10:12:32 +0100 Subject: [PATCH 029/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index dfd185ece6..aec23cbc78 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -36,7 +36,7 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "The delete message history. Between 1 to 7 days", true) + "The delete message history. Between 1 to as many days as you want", true) .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); From 867147f9c273039c2ce928e81c8ceb7988e05625 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 10:20:12 +0100 Subject: [PATCH 030/182] changed user id from string to long --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index aec23cbc78..53f3ea5ea8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -51,7 +51,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - String userId = Objects.requireNonNull(user).getUser().getId(); + long userId = Objects.requireNonNull(user).getUser().getIdLong(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 76f7a0da2d..7aea19fe6e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -52,7 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - String userId = Objects.requireNonNull(user).getUser().getId(); + long userId = Objects.requireNonNull(user).getUser().getIdLong(); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { event.reply("You do not have the required permissions to kick users from this server.") From 365ff7ea1627b7d9479650cdeb43d5c0c7c245f4 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 10:28:42 +0100 Subject: [PATCH 031/182] it will log the author. Who use the kick/ban command --- .../tjbot/commands/moderation/BanCommand.java | 14 ++++++++------ .../tjbot/commands/moderation/KickCommand.java | 12 +++++++----- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 53f3ea5ea8..17ca25fb7f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -49,26 +49,28 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); + Member author = Objects.requireNonNull(event.getMember()); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); long userId = Objects.requireNonNull(user).getUser().getIdLong(); - if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { + if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") .setEphemeral(true) .queue(); return; } - Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to ban users from this server.") .setEphemeral(true) .queue(); return; } - if (!author.canInteract(Objects.requireNonNull(user))) { + if (!bot.canInteract(Objects.requireNonNull(user))) { event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); return; } @@ -99,7 +101,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // Add this to audit log logger.info( - "User '{}' banned user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - author, user, deleteMessageHistoryDays, reason); + "Bot '{}' was made to banned the user '{}' by '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + bot, user, author, deleteMessageHistoryDays, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 7aea19fe6e..2720f380bf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -50,26 +50,28 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); + Member author = Objects.requireNonNull(event.getMember()); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); long userId = Objects.requireNonNull(user).getUser().getIdLong(); - if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.KICK_MEMBERS)) { + if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply("You do not have the required permissions to kick users from this server.") .setEphemeral(true) .queue(); return; } - Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!author.hasPermission(Permission.KICK_MEMBERS)) { + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the required permissions to kick users from this server.") .setEphemeral(true) .queue(); return; } - if (!author.canInteract(Objects.requireNonNull(user))) { + if (!bot.canInteract(Objects.requireNonNull(user))) { event.reply("This user is too powerful for me to kick.").setEphemeral(true).queue(); return; } @@ -87,6 +89,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); // Add this to audit log - logger.info("User '{}' Kicked user '{}' Reason was '{}'", author, user, reason); + logger.info("User '{}' was made to kick the user '{}' by '{}' due to reason being '{}'", bot, user, author, reason); } } From 606793bda732779a8f878f5d20a9330a98c60766 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 10:29:47 +0100 Subject: [PATCH 032/182] Update UnBanCommand.java --- .../tjbot/commands/moderation/UnBanCommand.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java index 06b379485a..3a15d85a80 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java @@ -43,6 +43,8 @@ public UnBanCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { final String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); + Member author = Objects.requireNonNull(event.getMember()); + if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the required permissions to ban users from this server.") .setEphemeral(true) @@ -50,8 +52,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Member author = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to unban the user from this server.") .setEphemeral(true) .queue(); @@ -62,6 +64,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); // Add this to audit log - logger.info("User '{}' unbanned user id '{}'", author, userId); + logger.info("Bot was forced to '{}' unban user id '{}' by '{}'", bot, userId, author); } } From 019bec37ad79d3c6603e61b28b91479d392cb0dd Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 11:50:30 +0100 Subject: [PATCH 033/182] Update BanCommand.java --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 17ca25fb7f..f654bc89e2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -15,9 +15,9 @@ /** - * When triggered with {@code /ban del_days @user rea son}, the bot will respond then will check + * When triggered with {@code /ban del_days @user reason}, the bot will check * if the user has perms. Then it will check if itself has perms to ban. If it does it will check if - * the user is too powerful or not. If the user is not then bot will ban the user abd reply with + * the user is too powerful or not. If the user is not then bot will ban the user and reply with * {@code Banned User!}. * */ From 516ffcf1e12aaefc686446bdc9f38be13d209fa4 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 11:51:00 +0100 Subject: [PATCH 034/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 2720f380bf..882268adfa 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -37,7 +37,7 @@ public KickCommand() { } /** - * When triggered with {@code /kick @user reason}, the bot will respond then it will check if + * When triggered with {@code /kick @user reason}, the bot will check if * the user has perms. Then it will check if itself has perms to kick. If it does it will check * if the user is too powerful or not. If the user is not then bot will kick the user and reply * with {@code Kicked User!}. From 23a6c2e5e8c9852ccc13b09397139cbe44e8b420 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 12:22:56 +0100 Subject: [PATCH 035/182] changed from UnBanCommand to UnbanCommand. Allowed to delete messages for more than 7 days --- .../main/java/org/togetherjava/tjbot/commands/Commands.java | 2 +- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- .../moderation/{UnBanCommand.java => UnbanCommand.java} | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) rename application/src/main/java/org/togetherjava/tjbot/commands/moderation/{UnBanCommand.java => UnbanCommand.java} (96%) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index 1c0e9e55e0..b91cfc23dd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -35,7 +35,7 @@ public enum Commands { // hence this list may not necessarily represent the full list of all commands actually // available. return List.of(new PingCommand(), new DatabaseCommand(database), new KickCommand(), - new BanCommand(), new UnBanCommand()); + new BanCommand(), new UnbanCommand()); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index f654bc89e2..6d933d6130 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -80,7 +80,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { (int) Objects.requireNonNull(event.getOption("delete-message-history-days")) .getAsLong(); - if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + if (deleteMessageHistoryDays < 1) { event.reply("The deletion days of the messages must be between 1 and 7 days") .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java similarity index 96% rename from application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java rename to application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 3a15d85a80..718e4d8d51 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnBanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -16,7 +16,7 @@ *

* The implemented command is {@code /unban user_id}, upon which the bot will unban the user. */ -public final class UnBanCommand extends SlashCommandAdapter { +public final class UnbanCommand extends SlashCommandAdapter { // the logger private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); private static final String USER_ID = "user_id"; @@ -24,7 +24,7 @@ public final class UnBanCommand extends SlashCommandAdapter { /** * Creates an instance of the ban command. */ - public UnBanCommand() { + public UnbanCommand() { super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.STRING, USER_ID, From fd0802d48e089e752f43e69e0734b6254d406e41 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 12:23:05 +0100 Subject: [PATCH 036/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 6d933d6130..4626662700 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -38,8 +38,6 @@ public BanCommand() { .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "The delete message history. Between 1 to as many days as you want", true) .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); - - } From 48f98634af703c890ec447ee0e2d7a935caf6c5b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 12:37:13 +0100 Subject: [PATCH 037/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 4626662700..4aab6346b4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -36,7 +36,8 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "The delete message history. Between 1 to as many days as you want", true) + "The messages in these day will be deleted. 1 to as many days as you want", + true) .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); } From 8b96b3ab4fffd9b518f797f9c75a388bfd08b2dd Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 17 Oct 2021 12:49:55 +0100 Subject: [PATCH 038/182] I checked the jda guild and its says it has to be between one and 7 days --- .../tjbot/commands/moderation/BanCommand.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 4aab6346b4..ca9339bbc9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -36,7 +36,7 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "The messages in these day will be deleted. 1 to as many days as you want", + "The messages in these days will be deleted. 0 to 7 days. 0 means no messages deleted", true) .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); } @@ -77,10 +77,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { int deleteMessageHistoryDays = (int) Objects.requireNonNull(event.getOption("delete-message-history-days")) - .getAsLong(); + .getAsLong(); - if (deleteMessageHistoryDays < 1) { - event.reply("The deletion days of the messages must be between 1 and 7 days") + if (deleteMessageHistoryDays < 0 || deleteMessageHistoryDays > 7) { + event.reply("The deletion days of the messages must be between 0 and 7 days.") .setEphemeral(true) .queue(); return; From 7dae25c77a204166d6689bad398f6ab830b9d8e1 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 18 Oct 2021 16:33:34 +0100 Subject: [PATCH 039/182] Update .gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 0ce9cdb2ce..f24a747936 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,4 @@ logviewer/types.d.ts logviewer/pnpm-lock.yaml logviewer/webpack.config.js logviewer/webpack.generated.js +.DS_Store From 9d6c4be26bcf193a98138c57be9a8ad7f50d3849 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 18 Oct 2021 16:50:12 +0100 Subject: [PATCH 040/182] fixed everything --- .../tjbot/commands/moderation/BanCommand.java | 40 ++++++++++--------- .../commands/moderation/KickCommand.java | 28 ++++++------- .../commands/moderation/UnbanCommand.java | 6 +-- 3 files changed, 37 insertions(+), 37 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index ca9339bbc9..efc9c9a93b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -1,6 +1,5 @@ package org.togetherjava.tjbot.commands.moderation; -import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -15,14 +14,15 @@ /** - * When triggered with {@code /ban del_days @user reason}, the bot will check - * if the user has perms. Then it will check if itself has perms to ban. If it does it will check if - * the user is too powerful or not. If the user is not then bot will ban the user and reply with - * {@code Banned User!}. + * This command can ban users and optionally remove their messages from the past days. Banning can + * also be paired with a ban reason. The command will also try to DM the user to inform him about + * the action and the reason. + *

+ * The command fails if the user triggering it is lacking permissions to either ban other users or + * to ban the specific given user (for example a moderator attempting to ban an admin). * */ public final class BanCommand extends SlashCommandAdapter { - // the logger private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; @@ -37,15 +37,13 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "The messages in these days will be deleted. 0 to 7 days. 0 means no messages deleted", - true) + false) .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); } @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - JDA jda = event.getJDA(); - Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); Member author = Objects.requireNonNull(event.getMember()); @@ -61,6 +59,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + if (!author.canInteract(Objects.requireNonNull(user))) { + event.reply("This user is too powerful for you to ban.").setEphemeral(true).queue(); + return; + } + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the required permissions to ban users from this server.") @@ -74,33 +77,32 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - int deleteMessageHistoryDays = (int) Objects.requireNonNull(event.getOption("delete-message-history-days")) - .getAsLong(); + .getAsLong(); - if (deleteMessageHistoryDays < 0 || deleteMessageHistoryDays > 7) { - event.reply("The deletion days of the messages must be between 0 and 7 days.") + if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + event.reply("The deletion days of the messages must be between 1 and 7 days.") .setEphemeral(true) .queue(); return; } - // tells ths user he has been banned - jda.openPrivateChannelById(userId) + event.getJDA() + .openPrivateChannelById(userId) .flatMap(channel -> channel .sendMessage("You have been banned for this reason " + reason)) .queue(); - // Ban the user and send a success response event.getGuild() .ban(user, deleteMessageHistoryDays, reason) .flatMap(v -> event.reply("Banned the user " + user.getUser().getAsTag())) .queue(); - // Add this to audit log + String userName = user.getId(); + String authorName = author.getId(); logger.info( - "Bot '{}' was made to banned the user '{}' by '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - bot, user, author, deleteMessageHistoryDays, reason); + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorName, userName, deleteMessageHistoryDays, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 882268adfa..413944c70e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -1,9 +1,7 @@ package org.togetherjava.tjbot.commands.moderation; -import net.dv8tion.jda.api.JDA; import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; @@ -20,7 +18,6 @@ * The implemented command is {@code /kick @user reason}, upon which the bot will kick the user. */ public final class KickCommand extends SlashCommandAdapter { - // the logger private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); private static final String USER_OPTION = "user"; private static final String REASON_OPTION = "reason"; @@ -37,17 +34,15 @@ public KickCommand() { } /** - * When triggered with {@code /kick @user reason}, the bot will check if - * the user has perms. Then it will check if itself has perms to kick. If it does it will check - * if the user is too powerful or not. If the user is not then bot will kick the user and reply - * with {@code Kicked User!}. + * When triggered with {@code /kick @user reason}, the bot will check if the user has perms. + * Then it will check if itself has perms to kick. If it does it will check if the user is too + * powerful or not. If the user is not then bot will kick the user and reply with + * {@code Kicked User!}. * * @param event the corresponding event */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - JDA jda = event.getJDA(); - Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); Member author = Objects.requireNonNull(event.getMember()); @@ -63,6 +58,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + if (!author.canInteract(Objects.requireNonNull(user))) { + event.reply("This user is too powerful for you to ban.").setEphemeral(true).queue(); + return; + } + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the required permissions to kick users from this server.") @@ -76,19 +76,19 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - // tells ths user he has been kicked - jda.openPrivateChannelById(userId) + event.getJDA() + .openPrivateChannelById(userId) .flatMap(channel -> channel .sendMessage("You have been kicked for this reason " + reason)) .queue(); - // Kicks the user and send a success response event.getGuild() .kick(user, reason) .flatMap(v -> event.reply("Kicked the user" + user.getUser().getAsTag())) .queue(); - // Add this to audit log - logger.info("User '{}' was made to kick the user '{}' by '{}' due to reason being '{}'", bot, user, author, reason); + String userName = user.getId(); + String authorName = author.getId(); + logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorName, userName, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 718e4d8d51..abdf57df36 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -17,7 +17,6 @@ * The implemented command is {@code /unban user_id}, upon which the bot will unban the user. */ public final class UnbanCommand extends SlashCommandAdapter { - // the logger private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); private static final String USER_ID = "user_id"; @@ -60,10 +59,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - // Unbans the user event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); - // Add this to audit log - logger.info("Bot was forced to '{}' unban user id '{}' by '{}'", bot, userId, author); + String authorName = author.getId(); + logger.info(" '{}' unbanned user id '{}' ", authorName, userId); } } From 336d567cf0ede2be911309b38ac07ebac295da76 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 18 Oct 2021 18:00:19 +0100 Subject: [PATCH 041/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index efc9c9a93b..347ecd415b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -36,7 +36,7 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "The messages in these days will be deleted. 0 to 7 days. 0 means no messages deleted", + "The messages in these days will be deleted. 1 to 7 days.", false) .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); } From 64d7c661668b2af9f1dde746c86f6fa04ac44265 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 19 Oct 2021 13:14:12 +0100 Subject: [PATCH 042/182] Fixed everything apart from https://github.com/Together-Java/TJ-Bot/pull/196/files#r731556495 --- .../tjbot/commands/moderation/BanCommand.java | 37 ++++++++++++------- .../commands/moderation/KickCommand.java | 17 ++++++--- .../commands/moderation/UnbanCommand.java | 4 +- 3 files changed, 37 insertions(+), 21 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 347ecd415b..d3a103c9c5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -32,16 +32,15 @@ public final class BanCommand extends SlashCommandAdapter { * Creates an instance of the ban command. */ public BanCommand() { - super("ban", "Use this command to ban a user", SlashCommandVisibility.GUILD); + super("ban", "Use this command to ban a given user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to ban", true) + getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "The messages in these days will be deleted. 1 to 7 days.", + "the amount of days of the message history to delete, otherwise no messages are deleted. 1 to 7 days.", false) - .addOption(OptionType.STRING, REASON_OPTION, "The reason of the ban", true); + .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true); } - @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); @@ -50,30 +49,36 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - long userId = Objects.requireNonNull(user).getUser().getIdLong(); + long userId = user.getUser().getIdLong(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("You do not have the required permissions to ban users from this server.") + event.reply("You do not have the BAN_MEMBERS permission to ban users from this server.") .setEphemeral(true) .queue(); return; } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for you to ban.").setEphemeral(true).queue(); + event.reply( + "This user is too powerful for you to ban because he has more permissions than uou.") + .setEphemeral(true) + .queue(); return; } Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("I don't have the required permissions to ban users from this server.") + event.reply("I don't have the BAN_MEMBERS permission to ban users from this server.") .setEphemeral(true) .queue(); return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); + event.reply( + "This user is too powerful for me to ban because he has more permissions than me.") + .setEphemeral(true) + .queue(); return; } @@ -82,7 +87,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .getAsLong(); if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { - event.reply("The deletion days of the messages must be between 1 and 7 days.") + event.reply( + "The amount of days of the message history to delete must be between 1 and 7, but was " + + deleteMessageHistoryDays + ".") .setEphemeral(true) .queue(); return; @@ -90,13 +97,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) - .flatMap(channel -> channel - .sendMessage("You have been banned for this reason " + reason)) + .flatMap(channel -> channel.sendMessage( + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Togherer Java'. If you think this was a mistake, please contact a moderator or adming of the guild. The ban reason is: " + + reason)) .queue(); event.getGuild() .ban(user, deleteMessageHistoryDays, reason) - .flatMap(v -> event.reply("Banned the user " + user.getUser().getAsTag())) + .flatMap(v -> event.reply(user.getUser().getAsTag() + "was banned by " + + author.getEffectiveName() + "for: " + reason)) .queue(); String userName = user.getId(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 413944c70e..743d9bd9db 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -27,10 +27,10 @@ public final class KickCommand extends SlashCommandAdapter { * Creates an instance of the kick command. */ public KickCommand() { - super("kick", "Use this command to kick a user", SlashCommandVisibility.GUILD); + super("kick", "Use this command to kick a given user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to kick", true) - .addOption(OptionType.STRING, REASON_OPTION, "The reason of the kick", true); + .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); } /** @@ -59,7 +59,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for you to ban.").setEphemeral(true).queue(); + event.reply( + "This user is too powerful for you to kick because he has more permissions than uou.") + .setEphemeral(true) + .queue(); return; } @@ -72,7 +75,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for me to kick.").setEphemeral(true).queue(); + event.reply( + "This user is too powerful for me to kick because he has more permissions than me.") + .setEphemeral(true) + .queue(); return; } @@ -89,6 +95,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String userName = user.getId(); String authorName = author.getId(); - logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorName, userName, reason); + logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorName, userName, + reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index abdf57df36..d726f1c6d2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -45,7 +45,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member author = Objects.requireNonNull(event.getMember()); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { - event.reply("You do not have the required permissions to ban users from this server.") + event.reply("You do not have the BAN_MEMBERS permission to urban users from this server.") .setEphemeral(true) .queue(); return; @@ -53,7 +53,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("I don't have the required permissions to unban the user from this server.") + event.reply("I don't have the BAN_MEMBERS permission to unban the user from this server.") .setEphemeral(true) .queue(); return; From 9ae34779cc1567041d655e40ee8d323a1f6ce6d7 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 19 Oct 2021 13:16:25 +0100 Subject: [PATCH 043/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index d3a103c9c5..3507084cc1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -98,7 +98,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Togherer Java'. If you think this was a mistake, please contact a moderator or adming of the guild. The ban reason is: " + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. If you think this was a mistake, please contact a moderator or admin of the guild. The ban reason is: " + reason)) .queue(); From d31f7c456ca8c72921a50f57484f8533d087171e Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 19 Oct 2021 13:17:45 +0100 Subject: [PATCH 044/182] Update UnbanCommand.java --- .../tjbot/commands/moderation/UnbanCommand.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index d726f1c6d2..bd9beb414b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -45,7 +45,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member author = Objects.requireNonNull(event.getMember()); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { - event.reply("You do not have the BAN_MEMBERS permission to urban users from this server.") + event.reply( + "You do not have the BAN_MEMBERS permission to urban users from this server.") .setEphemeral(true) .queue(); return; @@ -53,7 +54,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("I don't have the BAN_MEMBERS permission to unban the user from this server.") + event.reply( + "I don't have the BAN_MEMBERS permission to unban the user from this server.") .setEphemeral(true) .queue(); return; From 30eb8aed7f8a53d84dcc1a07f958a55dcb3fb7f1 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 19 Oct 2021 13:17:48 +0100 Subject: [PATCH 045/182] Update KickCommand.java --- .../tjbot/commands/moderation/KickCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 743d9bd9db..fcba1d63ee 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -52,7 +52,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { long userId = Objects.requireNonNull(user).getUser().getIdLong(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { - event.reply("You do not have the required permissions to kick users from this server.") + event.reply( + "You do not have the KICK_MEMBERS permission to kick users from this server.") .setEphemeral(true) .queue(); return; @@ -68,7 +69,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.KICK_MEMBERS)) { - event.reply("I don't have the required permissions to kick users from this server.") + event.reply("I don't have the KICK_MEMBERS permission to kick users from this server.") .setEphemeral(true) .queue(); return; @@ -84,8 +85,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) - .flatMap(channel -> channel - .sendMessage("You have been kicked for this reason " + reason)) + .flatMap(channel -> channel.sendMessage( + "Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. If you think this was a mistake, please contact a moderator or admin of the guild. The kick reason is: " + + reason)) .queue(); event.getGuild() From d9bf30b073c87fea1e7b81976068d6570ebdb964 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 19 Oct 2021 13:53:10 +0100 Subject: [PATCH 046/182] I think i have solved the problem --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 3507084cc1..a1d2bad66e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -83,9 +83,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } int deleteMessageHistoryDays = - (int) Objects.requireNonNull(event.getOption("delete-message-history-days")) - .getAsLong(); - + Math.toIntExact(Objects.requireNonNull(event.getOption("delete-message-history-days")) + .getAsLong()); + if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { event.reply( "The amount of days of the message history to delete must be between 1 and 7, but was " From abfb6248277c6f80f75ea9167dc49a7862b1a71b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 19 Oct 2021 22:28:17 +0100 Subject: [PATCH 047/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index a1d2bad66e..d2ab9b23a0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -83,7 +83,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } int deleteMessageHistoryDays = - Math.toIntExact(Objects.requireNonNull(event.getOption("delete-message-history-days")) + Math.toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { From 84a5b24c1e00d39fe322248d04b2ceea6b8f652c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 19 Oct 2021 22:33:19 +0100 Subject: [PATCH 048/182] Cleaned the code --- .../java/org/togetherjava/tjbot/commands/Commands.java | 2 +- .../tjbot/commands/moderation/BanCommand.java | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index 8a47e7bf2f..b8dc8374ae 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -37,6 +37,6 @@ public enum Commands { // hence this list may not necessarily represent the full list of all commands actually // available. return List.of(new PingCommand(), new DatabaseCommand(database), new KickCommand(), - new BanCommand(), new UnbanCommand(), new TeXCommand()); + new BanCommand(), new UnbanCommand(), new TeXCommand()); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index d2ab9b23a0..b1e4add31c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -82,10 +82,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - int deleteMessageHistoryDays = - Math.toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); - + int deleteMessageHistoryDays = Math + .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) + .getAsLong()); + if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { event.reply( "The amount of days of the message history to delete must be between 1 and 7, but was " From a8a1ecff810a14a7357e78ad4607471d2c6fcdfc Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 20 Oct 2021 20:13:58 +0100 Subject: [PATCH 049/182] continue later --- .../tjbot/commands/moderation/BanCommand.java | 44 ++++++++++--------- .../commands/moderation/KickCommand.java | 7 +-- .../commands/moderation/UnbanCommand.java | 2 +- 3 files changed, 29 insertions(+), 24 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index b1e4add31c..7ce516b92b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -3,6 +3,7 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -27,26 +28,26 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; + //private static final Integer DELETE_HISTORY_MIN_DAYS = 1; + //private static final Integer DELETE_HISTORY_MAX_DAYS = 7; /** * Creates an instance of the ban command. */ public BanCommand() { - super("ban", "Use this command to ban a given user", SlashCommandVisibility.GUILD); + super("ban", "Bans a given user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) + .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "the amount of days of the message history to delete, otherwise no messages are deleted. 1 to 7 days.", - false) - .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true); + "the amount(1-7) of days of the message history to delete, otherwise no messages are deleted.", + false); } @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); - Member author = Objects.requireNonNull(event.getMember()); - String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); long userId = user.getUser().getIdLong(); @@ -60,7 +61,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.canInteract(Objects.requireNonNull(user))) { event.reply( - "This user is too powerful for you to ban because he has more permissions than uou.") + "This user is too powerful for you to ban because he has more permissions than you.") .setEphemeral(true) .queue(); return; @@ -82,30 +83,33 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - int deleteMessageHistoryDays = Math - .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); + OptionMapping deleteMessageHistoryDaysOption = + event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); - if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { - event.reply( - "The amount of days of the message history to delete must be between 1 and 7, but was " - + deleteMessageHistoryDays + ".") - .setEphemeral(true) - .queue(); + int deleteMessageHistoryDays = (int) event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION).getAsLong(); + + if (deleteMessageHistoryDaysOption != null) { + deleteMessageHistoryDays = 0; + } else if(deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + event.reply("The deletion days of the messages must be between 1 and 7 days.") + .setEphemeral(true) + .queue(); return; } + event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. If you think this was a mistake, please contact a moderator or admin of the guild. The ban reason is: " - + reason)) + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " + + "If you think this was a mistake, please contact a moderator or admin of the guild. " + + "The ban reason is: " + reason)) .queue(); event.getGuild() .ban(user, deleteMessageHistoryDays, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + "was banned by " - + author.getEffectiveName() + "for: " + reason)) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) .queue(); String userName = user.getId(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index fcba1d63ee..8ca7375d01 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -27,7 +27,7 @@ public final class KickCommand extends SlashCommandAdapter { * Creates an instance of the kick command. */ public KickCommand() { - super("kick", "Use this command to kick a given user", SlashCommandVisibility.GUILD); + super("kick", "Kicks a given user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to kick", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); @@ -61,7 +61,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.canInteract(Objects.requireNonNull(user))) { event.reply( - "This user is too powerful for you to kick because he has more permissions than uou.") + "This user is too powerful for you to kick because he has more permissions than you.") .setEphemeral(true) .queue(); return; @@ -92,7 +92,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getGuild() .kick(user, reason) - .flatMap(v -> event.reply("Kicked the user" + user.getUser().getAsTag())) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " + + author.getUser().getAsTag() + " for: " + reason)) .queue(); String userName = user.getId(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index bd9beb414b..a9cc389d16 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -24,7 +24,7 @@ public final class UnbanCommand extends SlashCommandAdapter { * Creates an instance of the ban command. */ public UnbanCommand() { - super("unban", "Use this command to unban a user", SlashCommandVisibility.GUILD); + super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.STRING, USER_ID, "The user id of the user which you want to unban", true); From b17ef9821ea2e873623e86dfc22762480bc6d207 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 20 Oct 2021 20:17:27 +0100 Subject: [PATCH 050/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 7ce516b92b..2ac0d6ab61 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -28,8 +28,8 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; - //private static final Integer DELETE_HISTORY_MIN_DAYS = 1; - //private static final Integer DELETE_HISTORY_MAX_DAYS = 7; + // private static final Integer DELETE_HISTORY_MIN_DAYS = 1; + // private static final Integer DELETE_HISTORY_MAX_DAYS = 7; /** * Creates an instance of the ban command. @@ -86,14 +86,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping deleteMessageHistoryDaysOption = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); - int deleteMessageHistoryDays = (int) event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION).getAsLong(); + int deleteMessageHistoryDays = + (int) event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION).getAsLong(); if (deleteMessageHistoryDaysOption != null) { deleteMessageHistoryDays = 0; - } else if(deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + } else if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { event.reply("The deletion days of the messages must be between 1 and 7 days.") - .setEphemeral(true) - .queue(); + .setEphemeral(true) + .queue(); return; } From c825f78cc01d094d650ff3100b0242d7dd8edcbc Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 20 Oct 2021 20:27:42 +0100 Subject: [PATCH 051/182] Fixed everything + spotlessApply --- application/build.gradle | 2 +- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/application/build.gradle b/application/build.gradle index ab2815d6fb..29b5e2fa36 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -45,7 +45,7 @@ shadowJar { dependencies { implementation project(':database') - implementation 'net.dv8tion:JDA:4.3.0_334' + implementation 'net.dv8tion:JDA:4.3.0_335' implementation 'org.apache.logging.log4j:log4j-api:2.14.1' implementation 'org.apache.logging.log4j:log4j-core:2.14.1' diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 2ac0d6ab61..24ea41435e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -28,8 +28,6 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; - // private static final Integer DELETE_HISTORY_MIN_DAYS = 1; - // private static final Integer DELETE_HISTORY_MAX_DAYS = 7; /** * Creates an instance of the ban command. @@ -98,7 +96,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( From 59b7dff361cc676002a8330df76c0fda971c8e0e Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 20 Oct 2021 20:47:56 +0100 Subject: [PATCH 052/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 24ea41435e..55733c7d04 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -11,6 +11,7 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; +import java.awt.*; import java.util.Objects; @@ -81,6 +82,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + + /* OptionMapping deleteMessageHistoryDaysOption = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); @@ -95,6 +98,19 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); return; } + + */ + + Choice days = new Choice(); + days.add("0"); + days.add("1"); + days.add("2"); + days.add("3"); + days.add("5"); + days.add("6"); + days.add("7"); + + event.getJDA() .openPrivateChannelById(userId) From 72268008cd8b572d71da341296b28d4527149494 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 20 Oct 2021 20:56:37 +0100 Subject: [PATCH 053/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 55733c7d04..ab712b250f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -84,25 +84,21 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { /* - OptionMapping deleteMessageHistoryDaysOption = - event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); + int deleteMessageHistoryDays = Math + .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) + .getAsLong()); - int deleteMessageHistoryDays = - (int) event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION).getAsLong(); - - if (deleteMessageHistoryDaysOption != null) { - deleteMessageHistoryDays = 0; - } else if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { - event.reply("The deletion days of the messages must be between 1 and 7 days.") + if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + event.reply( + "The amount of days of the message history to delete must be between 1 and 7, but was " + + deleteMessageHistoryDays + ".") .setEphemeral(true) .queue(); return; } - */ Choice days = new Choice(); - days.add("0"); days.add("1"); days.add("2"); days.add("3"); @@ -112,6 +108,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { + + event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( From 7687186044240cd26ffa9be55271062aef7949fa Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 06:39:23 +0100 Subject: [PATCH 054/182] Fixed it I have put it in a if statement. If it is not null then use deldays if there is no deldays then set to 0 --- .../tjbot/commands/moderation/BanCommand.java | 93 +++++++++++-------- 1 file changed, 52 insertions(+), 41 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index ab712b250f..3bc9feda67 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -11,7 +11,6 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -import java.awt.*; import java.util.Objects; @@ -83,51 +82,63 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } - /* - int deleteMessageHistoryDays = Math - .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); - - if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { - event.reply( - "The amount of days of the message history to delete must be between 1 and 7, but was " - + deleteMessageHistoryDays + ".") - .setEphemeral(true) + OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); + + if (option != null) { + int deleteMessageHistoryDays = Math.toIntExact( + Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) + .getAsLong()); + + if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { + event.reply( + "The amount of days of the message history to delete must be between 1 and 7, but was " + + deleteMessageHistoryDays + ".") + .setEphemeral(true) + .queue(); + return; + } + + event.getJDA() + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " + + "If you think this was a mistake, please contact a moderator or admin of the guild. " + + "The ban reason is: " + reason)) .queue(); - return; - } - */ - - Choice days = new Choice(); - days.add("1"); - days.add("2"); - days.add("3"); - days.add("5"); - days.add("6"); - days.add("7"); - - + event.getGuild() + .ban(user, deleteMessageHistoryDays, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); + String userName = user.getId(); + String authorName = author.getId(); + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorName, userName, deleteMessageHistoryDays, reason); + + } else { + event.getJDA() + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " + + "If you think this was a mistake, please contact a moderator or admin of the guild. " + + "The ban reason is: " + reason)) + .queue(); - event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " - + "If you think this was a mistake, please contact a moderator or admin of the guild. " - + "The ban reason is: " + reason)) - .queue(); + event.getGuild() + .ban(user, 0, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); - event.getGuild() - .ban(user, deleteMessageHistoryDays, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); + String userName = user.getId(); + String authorName = author.getId(); + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last 0 days. Reason was '{}'", + authorName, userName, reason); - String userName = user.getId(); - String authorName = author.getId(); - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorName, userName, deleteMessageHistoryDays, reason); + } } } From 8775730c353a97a3af8c24af731b896ec33ae7d2 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 06:55:26 +0100 Subject: [PATCH 055/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 3bc9feda67..1f0d78c40a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -81,7 +81,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); if (option != null) { From 7aee2878ee089592903e13780889eded8ed91d99 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Thu, 21 Oct 2021 15:06:39 +0100 Subject: [PATCH 056/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: java-coding-prodigy <85149944+java-coding-prodigy@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index a9cc389d16..2720ee8a9d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -17,7 +17,7 @@ * The implemented command is {@code /unban user_id}, upon which the bot will unban the user. */ public final class UnbanCommand extends SlashCommandAdapter { - private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); private static final String USER_ID = "user_id"; /** From 5550872822309b7dd200691496d96e2ab71bb92c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 19:57:45 +0100 Subject: [PATCH 057/182] changed some things --- application/build.gradle | 2 +- .../tjbot/commands/moderation/BanCommand.java | 85 ++++++++++--------- .../commands/moderation/KickCommand.java | 2 +- 3 files changed, 45 insertions(+), 44 deletions(-) diff --git a/application/build.gradle b/application/build.gradle index 29b5e2fa36..ab2815d6fb 100644 --- a/application/build.gradle +++ b/application/build.gradle @@ -45,7 +45,7 @@ shadowJar { dependencies { implementation project(':database') - implementation 'net.dv8tion:JDA:4.3.0_335' + implementation 'net.dv8tion:JDA:4.3.0_334' implementation 'org.apache.logging.log4j:log4j-api:2.14.1' implementation 'org.apache.logging.log4j:log4j-core:2.14.1' diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 1f0d78c40a..0530a56020 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -11,6 +11,7 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; +import java.awt.*; import java.util.Objects; @@ -28,6 +29,8 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; + private static final Integer DELETE_HISTORY_MIN_DAYS = 1; + private static final Integer DELETE_HISTORY_MAX_DAYS = 7; /** * Creates an instance of the ban command. @@ -35,11 +38,16 @@ public final class BanCommand extends SlashCommandAdapter { public BanCommand() { super("ban", "Bans a given user", SlashCommandVisibility.GUILD); + //TODO add choices + Choice days = new Choice(); + days.add("1"); + getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "the amount(1-7) of days of the message history to delete, otherwise no messages are deleted.", false); + } @Override @@ -59,7 +67,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.canInteract(Objects.requireNonNull(user))) { event.reply( - "This user is too powerful for you to ban because he has more permissions than you.") + "This user is too powerful for you to ban.") .setEphemeral(true) .queue(); return; @@ -84,60 +92,53 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); if (option != null) { - int deleteMessageHistoryDays = Math.toIntExact( + int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); - - if (deleteMessageHistoryDays < 1 || deleteMessageHistoryDays > 7) { - event.reply( - "The amount of days of the message history to delete must be between 1 and 7, but was " - + deleteMessageHistoryDays + ".") + .getAsLong()); + deleteMessageHistory(days, event); + banGuild(user, reason, days, event); + String userName = user.getId(); + String authorName = author.getId(); + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorName, userName, days, reason); + } else { + openPrivateChannel(userId, reason, event); + banGuild(user, reason, 0, event); + String userName = user.getId(); + String authorName = author.getId(); + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorName, userName, 0, reason); + } + } + public static void deleteMessageHistory(int days , @NotNull SlashCommandEvent event) { + if (days < DELETE_HISTORY_MIN_DAYS || days > DELETE_HISTORY_MAX_DAYS) { + event.reply( + "The amount of days of the message history to delete must be between " + + DELETE_HISTORY_MIN_DAYS + " and " + DELETE_HISTORY_MAX_DAYS + " , but was " + + days + ".") .setEphemeral(true) .queue(); - return; - } - - event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " - + "If you think this was a mistake, please contact a moderator or admin of the guild. " - + "The ban reason is: " + reason)) - .queue(); + } + } - event.getGuild() - .ban(user, deleteMessageHistoryDays, reason) + public static void banGuild(Member user, String reason, int days, @NotNull SlashCommandEvent event) { + Member author = Objects.requireNonNull(event.getMember()); + event.getGuild() + .ban(user, days, reason) .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); + } - String userName = user.getId(); - String authorName = author.getId(); - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorName, userName, deleteMessageHistoryDays, reason); - - } else { - event.getJDA() + public static void openPrivateChannel(long userId, String reason, @NotNull SlashCommandEvent event) { + event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " + "If you think this was a mistake, please contact a moderator or admin of the guild. " + "The ban reason is: " + reason)) .queue(); - - event.getGuild() - .ban(user, 0, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); - - String userName = user.getId(); - String authorName = author.getId(); - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last 0 days. Reason was '{}'", - authorName, userName, reason); - - } } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 8ca7375d01..307796b62b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -61,7 +61,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.canInteract(Objects.requireNonNull(user))) { event.reply( - "This user is too powerful for you to kick because he has more permissions than you.") + "\"This user is too powerful for you to kick.") .setEphemeral(true) .queue(); return; From 73f30e686936e9db95a73fe52f17cac0fd2ad71a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:01:55 +0100 Subject: [PATCH 058/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 0530a56020..e8842d8c2a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -41,7 +41,7 @@ public BanCommand() { //TODO add choices Choice days = new Choice(); days.add("1"); - + getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, @@ -91,25 +91,22 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); + String userName = user.getId(); + String authorName = author.getId(); if (option != null) { int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); deleteMessageHistory(days, event); banGuild(user, reason, days, event); - String userName = user.getId(); - String authorName = author.getId(); + logger.info( " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", authorName, userName, days, reason); } else { openPrivateChannel(userId, reason, event); banGuild(user, reason, 0, event); - String userName = user.getId(); - String authorName = author.getId(); - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorName, userName, 0, reason); + logger(authorName, userName, 0, reason); } } public static void deleteMessageHistory(int days , @NotNull SlashCommandEvent event) { @@ -141,4 +138,9 @@ public static void openPrivateChannel(long userId, String reason, @NotNull Slash + "The ban reason is: " + reason)) .queue(); } + public static void logger(String authorNameId, String userNameId, int days, String reason) { + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorNameId, userNameId, days, reason); + } } From 81e3f17dc0c2ee4c5fb88bf032c614eb3a75f99c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:05:12 +0100 Subject: [PATCH 059/182] a bit cleaner --- .../tjbot/commands/moderation/BanCommand.java | 46 ++--------------- .../commands/moderation/BanHelperMethods.java | 50 +++++++++++++++++++ 2 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index e8842d8c2a..2eebb9f269 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -29,8 +29,6 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; - private static final Integer DELETE_HISTORY_MIN_DAYS = 1; - private static final Integer DELETE_HISTORY_MAX_DAYS = 7; /** * Creates an instance of the ban command. @@ -97,50 +95,16 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); - deleteMessageHistory(days, event); - banGuild(user, reason, days, event); + BanHelperMethods.deleteMessageHistory(days, event); + BanHelperMethods.banGuild(user, reason, days, event); logger.info( " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", authorName, userName, days, reason); } else { - openPrivateChannel(userId, reason, event); - banGuild(user, reason, 0, event); - logger(authorName, userName, 0, reason); + BanHelperMethods.openPrivateChannel(userId, reason, event); + BanHelperMethods.banGuild(user, reason, 0, event); + BanHelperMethods.logger(authorName, userName, 0, reason); } } - public static void deleteMessageHistory(int days , @NotNull SlashCommandEvent event) { - if (days < DELETE_HISTORY_MIN_DAYS || days > DELETE_HISTORY_MAX_DAYS) { - event.reply( - "The amount of days of the message history to delete must be between " + - DELETE_HISTORY_MIN_DAYS + " and " + DELETE_HISTORY_MAX_DAYS + " , but was " - + days + ".") - .setEphemeral(true) - .queue(); - } - } - - public static void banGuild(Member user, String reason, int days, @NotNull SlashCommandEvent event) { - Member author = Objects.requireNonNull(event.getMember()); - event.getGuild() - .ban(user, days, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); - } - - public static void openPrivateChannel(long userId, String reason, @NotNull SlashCommandEvent event) { - event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " - + "If you think this was a mistake, please contact a moderator or admin of the guild. " - + "The ban reason is: " + reason)) - .queue(); - } - public static void logger(String authorNameId, String userNameId, int days, String reason) { - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorNameId, userNameId, days, reason); - } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java new file mode 100644 index 0000000000..0b34e57810 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -0,0 +1,50 @@ +package org.togetherjava.tjbot.commands.moderation; + +import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.Objects; + +public class BanHelperMethods { + private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + private static final Integer DELETE_HISTORY_MIN_DAYS = 1; + private static final Integer DELETE_HISTORY_MAX_DAYS = 7; + + public static void deleteMessageHistory(int days , @NotNull SlashCommandEvent event) { + if (days < DELETE_HISTORY_MIN_DAYS || days > DELETE_HISTORY_MAX_DAYS) { + event.reply( + "The amount of days of the message history to delete must be between " + + DELETE_HISTORY_MIN_DAYS + " and " + DELETE_HISTORY_MAX_DAYS + " , but was " + + days + ".") + .setEphemeral(true) + .queue(); + } + } + + public static void banGuild(Member user, String reason, int days, @NotNull SlashCommandEvent event) { + Member author = Objects.requireNonNull(event.getMember()); + event.getGuild() + .ban(user, days, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); + } + + public static void openPrivateChannel(long userId, String reason, @NotNull SlashCommandEvent event) { + event.getJDA() + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " + + "If you think this was a mistake, please contact a moderator or admin of the guild. " + + "The ban reason is: " + reason)) + .queue(); + } + public static void logger(String authorNameId, String userNameId, int days, String reason) { + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorNameId, userNameId, days, reason); + } +} From c6722dacc931c4c4af54aba97caba8a08a6eead6 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:39:32 +0100 Subject: [PATCH 060/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 2eebb9f269..8e3f1c60dc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -5,6 +5,7 @@ import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -36,16 +37,19 @@ public final class BanCommand extends SlashCommandAdapter { public BanCommand() { super("ban", "Bans a given user", SlashCommandVisibility.GUILD); - //TODO add choices - Choice days = new Choice(); - days.add("1"); - getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) - .addOption(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "the amount(1-7) of days of the message history to delete, otherwise no messages are deleted.", - false); - + .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, + "the amount of days of the message history to delete, otherwise no messages are deleted.", + true) + .addChoice("1",1) + .addChoice("2",2) + .addChoice("3",3) + .addChoice("4",4) + .addChoice("5",5) + .addChoice("6",6) + .addChoice("7",7) + ); } @Override From 166311381bd037ecce4f95129a91274d9b9fde81 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:40:26 +0100 Subject: [PATCH 061/182] added choices --- .../tjbot/commands/moderation/BanCommand.java | 24 ++++------- .../commands/moderation/BanHelperMethods.java | 41 ++++++++++--------- .../commands/moderation/KickCommand.java | 5 +-- 3 files changed, 32 insertions(+), 38 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 8e3f1c60dc..2ef210d7cb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -12,7 +12,6 @@ import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; -import java.awt.*; import java.util.Objects; @@ -41,15 +40,13 @@ public BanCommand() { .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "the amount of days of the message history to delete, otherwise no messages are deleted.", - true) - .addChoice("1",1) - .addChoice("2",2) - .addChoice("3",3) - .addChoice("4",4) - .addChoice("5",5) - .addChoice("6",6) - .addChoice("7",7) - ); + true).addChoice("1", 1) + .addChoice("2", 2) + .addChoice("3", 3) + .addChoice("4", 4) + .addChoice("5", 5) + .addChoice("6", 6) + .addChoice("7", 7)); } @Override @@ -68,10 +65,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply( - "This user is too powerful for you to ban.") - .setEphemeral(true) - .queue(); + event.reply("This user is too powerful for you to ban.").setEphemeral(true).queue(); return; } @@ -98,7 +92,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (option != null) { int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); + .getAsLong()); BanHelperMethods.deleteMessageHistory(days, event); BanHelperMethods.banGuild(user, reason, days, event); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index 0b34e57810..7812ad3cbc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -13,35 +13,38 @@ public class BanHelperMethods { private static final Integer DELETE_HISTORY_MIN_DAYS = 1; private static final Integer DELETE_HISTORY_MAX_DAYS = 7; - public static void deleteMessageHistory(int days , @NotNull SlashCommandEvent event) { + public static void deleteMessageHistory(int days, @NotNull SlashCommandEvent event) { if (days < DELETE_HISTORY_MIN_DAYS || days > DELETE_HISTORY_MAX_DAYS) { - event.reply( - "The amount of days of the message history to delete must be between " + - DELETE_HISTORY_MIN_DAYS + " and " + DELETE_HISTORY_MAX_DAYS + " , but was " - + days + ".") - .setEphemeral(true) - .queue(); + event + .reply("The amount of days of the message history to delete must be between " + + DELETE_HISTORY_MIN_DAYS + " and " + DELETE_HISTORY_MAX_DAYS + + " , but was " + days + ".") + .setEphemeral(true) + .queue(); } } - public static void banGuild(Member user, String reason, int days, @NotNull SlashCommandEvent event) { + public static void banGuild(Member user, String reason, int days, + @NotNull SlashCommandEvent event) { Member author = Objects.requireNonNull(event.getMember()); event.getGuild() - .ban(user, days, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); + .ban(user, days, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); } - public static void openPrivateChannel(long userId, String reason, @NotNull SlashCommandEvent event) { + public static void openPrivateChannel(long userId, String reason, + @NotNull SlashCommandEvent event) { event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " - + "If you think this was a mistake, please contact a moderator or admin of the guild. " - + "The ban reason is: " + reason)) - .queue(); + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " + + "If you think this was a mistake, please contact a moderator or admin of the guild. " + + "The ban reason is: " + reason)) + .queue(); } + public static void logger(String authorNameId, String userNameId, int days, String reason) { logger.info( " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 307796b62b..b5b790ee2c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -60,10 +60,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply( - "\"This user is too powerful for you to kick.") - .setEphemeral(true) - .queue(); + event.reply("\"This user is too powerful for you to kick.").setEphemeral(true).queue(); return; } From fe7f1d391051f63e9063ba2c7dd962bdc0468577 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:43:02 +0100 Subject: [PATCH 062/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 1 + 1 file changed, 1 insertion(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 2ef210d7cb..b2c497bf64 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -90,6 +90,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String userName = user.getId(); String authorName = author.getId(); if (option != null) { + //TODO Implement the same delete message structure for the purge message. int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); From edc42ed3f12c96739dc67e37687d645e17d8380d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:45:07 +0100 Subject: [PATCH 063/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index b2c497bf64..856efb60e4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -40,7 +40,7 @@ public BanCommand() { .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "the amount of days of the message history to delete, otherwise no messages are deleted.", - true).addChoice("1", 1) + false).addChoice("1", 1) .addChoice("2", 2) .addChoice("3", 3) .addChoice("4", 4) From 2fb352ef62df997a0019d67313fb6210202d3f8d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 20:45:48 +0100 Subject: [PATCH 064/182] Update BanCommand.java --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 856efb60e4..cd2019935b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -40,13 +40,16 @@ public BanCommand() { .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "the amount of days of the message history to delete, otherwise no messages are deleted.", - false).addChoice("1", 1) + false) + .addChoice("0", 0) + .addChoice("1", 1) .addChoice("2", 2) .addChoice("3", 3) .addChoice("4", 4) .addChoice("5", 5) .addChoice("6", 6) - .addChoice("7", 7)); + .addChoice("7", 7) + ); } @Override From bd27130160fb2e96b6254023da1ff0ced64ff584 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Thu, 21 Oct 2021 21:07:14 +0100 Subject: [PATCH 065/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index b5b790ee2c..69b0a232f9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -93,9 +93,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { + author.getUser().getAsTag() + " for: " + reason)) .queue(); - String userName = user.getId(); - String authorName = author.getId(); - logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorName, userName, + String userId = user.getId(); + String authorId= author.getId(); + logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorId, userId , reason); } } From 46c2ecbdcf32c73fa6add2f972e4cc83d843e1b9 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Thu, 21 Oct 2021 21:07:27 +0100 Subject: [PATCH 066/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 2720ee8a9d..a39f1478de 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -63,7 +63,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); - String authorName = author.getId(); - logger.info(" '{}' unbanned user id '{}' ", authorName, userId); + String authorId = author.getId(); + logger.info(" '{}' unbanned user id '{}' ", authorId, userId); } } From 3a328ffa2c596f9c25e0eb82bdb419333d79598f Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Thu, 21 Oct 2021 21:08:24 +0100 Subject: [PATCH 067/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index cd2019935b..e6e22293d1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -90,8 +90,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); - String userName = user.getId(); - String authorName = author.getId(); + long userName = user.getIdLong(); + long authorName = author.getIdLong(); if (option != null) { //TODO Implement the same delete message structure for the purge message. int days = Math.toIntExact( From 107e536fb9a646e5612fc0dad3a288d2b7f5a3cf Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 21:09:38 +0100 Subject: [PATCH 068/182] Update BanHelperMethods.java --- .../tjbot/commands/moderation/BanHelperMethods.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index 7812ad3cbc..5272680bec 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -45,7 +45,7 @@ public static void openPrivateChannel(long userId, String reason, .queue(); } - public static void logger(String authorNameId, String userNameId, int days, String reason) { + public static void logger(long authorNameId, long userNameId, int days, String reason) { logger.info( " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", authorNameId, userNameId, days, reason); From de1b36e01a791fb915e7b47ff473332e56c11dfe Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Thu, 21 Oct 2021 21:10:00 +0100 Subject: [PATCH 069/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../tjbot/commands/moderation/BanHelperMethods.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index 5272680bec..5ebad3ec1d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -39,9 +39,11 @@ public static void openPrivateChannel(long userId, String reason, event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. " - + "If you think this was a mistake, please contact a moderator or admin of the guild. " - + "The ban reason is: " + reason)) + """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. + If you think this was a mistake, please contact a moderator or admin of the guild. + The ban reason is: %s + """.formatted(reason);)) .queue(); } From 90b88fe6f3d1ec476620db77634e1640741f9cac Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 21:12:58 +0100 Subject: [PATCH 070/182] Update BanHelperMethods.java --- .../tjbot/commands/moderation/BanHelperMethods.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index 5ebad3ec1d..e987915615 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -43,7 +43,7 @@ public static void openPrivateChannel(long userId, String reason, Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. If you think this was a mistake, please contact a moderator or admin of the guild. The ban reason is: %s - """.formatted(reason);)) + """.formatted(reason))) .queue(); } From 198c720b08b19a73660532dc5837d01f21fc52ac Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 21:13:18 +0100 Subject: [PATCH 071/182] Update BanHelperMethods.java --- .../tjbot/commands/moderation/BanHelperMethods.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index e987915615..ce583dd62a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -40,7 +40,7 @@ public static void openPrivateChannel(long userId, String reason, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'. + Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'.\040 If you think this was a mistake, please contact a moderator or admin of the guild. The ban reason is: %s """.formatted(reason))) From fa89b6426f0e86fe7755bf9db13605698ff480b3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 21 Oct 2021 21:17:05 +0100 Subject: [PATCH 072/182] spotlessApply --- .../tjbot/commands/moderation/BanCommand.java | 8 +++----- .../tjbot/commands/moderation/BanHelperMethods.java | 9 +++++---- .../tjbot/commands/moderation/KickCommand.java | 4 ++-- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index e6e22293d1..f35a9da4a9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -40,16 +40,14 @@ public BanCommand() { .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "the amount of days of the message history to delete, otherwise no messages are deleted.", - false) - .addChoice("0", 0) + false).addChoice("0", 0) .addChoice("1", 1) .addChoice("2", 2) .addChoice("3", 3) .addChoice("4", 4) .addChoice("5", 5) .addChoice("6", 6) - .addChoice("7", 7) - ); + .addChoice("7", 7)); } @Override @@ -93,7 +91,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { long userName = user.getIdLong(); long authorName = author.getIdLong(); if (option != null) { - //TODO Implement the same delete message structure for the purge message. + // TODO Implement the same delete message structure for the purge message. int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index ce583dd62a..1f84d2f27d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -40,10 +40,11 @@ public static void openPrivateChannel(long userId, String reason, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'.\040 - If you think this was a mistake, please contact a moderator or admin of the guild. - The ban reason is: %s - """.formatted(reason))) + Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'.\040 + If you think this was a mistake, please contact a moderator or admin of the guild. + The ban reason is: %s + """ + .formatted(reason))) .queue(); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 69b0a232f9..71eb24116f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -94,8 +94,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); String userId = user.getId(); - String authorId= author.getId(); - logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorId, userId , + String authorId = author.getId(); + logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorId, userId, reason); } } From 97a4aacc3f8a9ea0e23111778f3d3c9205a2c8c3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 07:16:33 +0100 Subject: [PATCH 073/182] tweaked the ban command. Removed unneeded string in kick command --- .../tjbot/commands/moderation/BanCommand.java | 21 ++++++++----------- .../commands/moderation/BanHelperMethods.java | 14 ++++++------- .../commands/moderation/KickCommand.java | 1 - 3 files changed, 15 insertions(+), 21 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index f35a9da4a9..9dd3d97578 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -25,10 +25,11 @@ * */ public final class BanCommand extends SlashCommandAdapter { - private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; + private static final Integer DELETE_HISTORY_MIN_DAYS = 0; + private static final Integer DELETE_HISTORY_MAX_DAYS = 7; /** * Creates an instance of the ban command. @@ -88,23 +89,19 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); - long userName = user.getIdLong(); - long authorName = author.getIdLong(); + long authorId = author.getIdLong(); if (option != null) { // TODO Implement the same delete message structure for the purge message. int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); - BanHelperMethods.deleteMessageHistory(days, event); - BanHelperMethods.banGuild(user, reason, days, event); - - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorName, userName, days, reason); + BanHelperMethods.getDeleteMessageHistory(days, DELETE_HISTORY_MIN_DAYS, DELETE_HISTORY_MAX_DAYS, event); + BanHelperMethods.getBanGuild(user, reason, days, event); + BanHelperMethods.getLogger(authorId, userId, days, reason); } else { - BanHelperMethods.openPrivateChannel(userId, reason, event); - BanHelperMethods.banGuild(user, reason, 0, event); - BanHelperMethods.logger(authorName, userName, 0, reason); + BanHelperMethods.getOpenPrivateChannel(userId, reason, event); + BanHelperMethods.getBanGuild(user, reason, 0, event); + BanHelperMethods.getLogger(authorId, userId, 0, reason); } } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index 1f84d2f27d..274cfac5b7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -10,21 +10,19 @@ public class BanHelperMethods { private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); - private static final Integer DELETE_HISTORY_MIN_DAYS = 1; - private static final Integer DELETE_HISTORY_MAX_DAYS = 7; - public static void deleteMessageHistory(int days, @NotNull SlashCommandEvent event) { - if (days < DELETE_HISTORY_MIN_DAYS || days > DELETE_HISTORY_MAX_DAYS) { + public static void getDeleteMessageHistory(int days, int minDays, int maxDays, @NotNull SlashCommandEvent event) { + if (days < minDays || days > maxDays) { event .reply("The amount of days of the message history to delete must be between " - + DELETE_HISTORY_MIN_DAYS + " and " + DELETE_HISTORY_MAX_DAYS + + minDays + " and " + maxDays + " , but was " + days + ".") .setEphemeral(true) .queue(); } } - public static void banGuild(Member user, String reason, int days, + public static void getBanGuild(Member user, String reason, int days, @NotNull SlashCommandEvent event) { Member author = Objects.requireNonNull(event.getMember()); event.getGuild() @@ -34,7 +32,7 @@ public static void banGuild(Member user, String reason, int days, .queue(); } - public static void openPrivateChannel(long userId, String reason, + public static void getOpenPrivateChannel(long userId, String reason, @NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) @@ -48,7 +46,7 @@ public static void openPrivateChannel(long userId, String reason, .queue(); } - public static void logger(long authorNameId, long userNameId, int days, String reason) { + public static void getLogger(long authorNameId, long userNameId, int days, String reason) { logger.info( " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", authorNameId, userNameId, days, reason); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 71eb24116f..4cf01f8ddb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -93,7 +93,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { + author.getUser().getAsTag() + " for: " + reason)) .queue(); - String userId = user.getId(); String authorId = author.getId(); logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorId, userId, reason); From 7e165f9d7aee951f307d2fda6350fcf363591282 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 07:17:16 +0100 Subject: [PATCH 074/182] spotlessJavaApply --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 3 ++- .../tjbot/commands/moderation/BanHelperMethods.java | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 9dd3d97578..1a287a2b1c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -95,7 +95,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { int days = Math.toIntExact( Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); - BanHelperMethods.getDeleteMessageHistory(days, DELETE_HISTORY_MIN_DAYS, DELETE_HISTORY_MAX_DAYS, event); + BanHelperMethods.getDeleteMessageHistory(days, DELETE_HISTORY_MIN_DAYS, + DELETE_HISTORY_MAX_DAYS, event); BanHelperMethods.getBanGuild(user, reason, days, event); BanHelperMethods.getLogger(authorId, userId, days, reason); } else { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java index 274cfac5b7..8e8805f03b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java @@ -11,12 +11,12 @@ public class BanHelperMethods { private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); - public static void getDeleteMessageHistory(int days, int minDays, int maxDays, @NotNull SlashCommandEvent event) { + public static void getDeleteMessageHistory(int days, int minDays, int maxDays, + @NotNull SlashCommandEvent event) { if (days < minDays || days > maxDays) { event .reply("The amount of days of the message history to delete must be between " - + minDays + " and " + maxDays - + " , but was " + days + ".") + + minDays + " and " + maxDays + " , but was " + days + ".") .setEphemeral(true) .queue(); } From 35b9939c7b85c8bc46ded172ad345354801a85ad Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 07:21:52 +0100 Subject: [PATCH 075/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 1a287a2b1c..c1c955ecf8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -7,8 +7,6 @@ import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; From af1fe466843c18f706386b822beef32085045d7d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 13:16:58 +0100 Subject: [PATCH 076/182] I have fixed what you told me to fix --- .../tjbot/commands/moderation/BanCommand.java | 61 +++++++++++-------- .../commands/moderation/BanHelperMethods.java | 54 ---------------- 2 files changed, 37 insertions(+), 78 deletions(-) delete mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c1c955ecf8..585aa5f109 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -3,10 +3,11 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; @@ -26,8 +27,7 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; - private static final Integer DELETE_HISTORY_MIN_DAYS = 0; - private static final Integer DELETE_HISTORY_MAX_DAYS = 7; + private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); /** * Creates an instance of the ban command. @@ -39,7 +39,7 @@ public BanCommand() { .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, "the amount of days of the message history to delete, otherwise no messages are deleted.", - false).addChoice("0", 0) + true).addChoice("none", 0) .addChoice("1", 1) .addChoice("2", 2) .addChoice("3", 3) @@ -78,29 +78,42 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply( - "This user is too powerful for me to ban because he has more permissions than me.") - .setEphemeral(true) - .queue(); + event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); return; } - OptionMapping option = event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION); - long authorId = author.getIdLong(); - if (option != null) { - // TODO Implement the same delete message structure for the purge message. - int days = Math.toIntExact( - Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); - BanHelperMethods.getDeleteMessageHistory(days, DELETE_HISTORY_MIN_DAYS, - DELETE_HISTORY_MAX_DAYS, event); - BanHelperMethods.getBanGuild(user, reason, days, event); - BanHelperMethods.getLogger(authorId, userId, days, reason); - } else { - BanHelperMethods.getOpenPrivateChannel(userId, reason, event); - BanHelperMethods.getBanGuild(user, reason, 0, event); - BanHelperMethods.getLogger(authorId, userId, 0, reason); - } + // TODO Implement the same delete message structure for the purge message. + int days = Math + .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) + .getAsLong()); + + banUser(userId, authorId, user, reason, days, event); + } + + private static void banUser(long userId, long authorNameId, Member user, String reason, + int days, @NotNull SlashCommandEvent event) { + event.getJDA() + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'.\040 + If you think this was a mistake, please contact a moderator or admin of the guild. + The ban reason is: %s + """ + .formatted(reason))) + .queue(); + + Member author = Objects.requireNonNull(event.getMember()); + + event.getGuild() + .ban(user, days, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); + + logger.info( + " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + authorNameId, userId, days, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java deleted file mode 100644 index 8e8805f03b..0000000000 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanHelperMethods.java +++ /dev/null @@ -1,54 +0,0 @@ -package org.togetherjava.tjbot.commands.moderation; - -import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import java.util.Objects; - -public class BanHelperMethods { - private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); - - public static void getDeleteMessageHistory(int days, int minDays, int maxDays, - @NotNull SlashCommandEvent event) { - if (days < minDays || days > maxDays) { - event - .reply("The amount of days of the message history to delete must be between " - + minDays + " and " + maxDays + " , but was " + days + ".") - .setEphemeral(true) - .queue(); - } - } - - public static void getBanGuild(Member user, String reason, int days, - @NotNull SlashCommandEvent event) { - Member author = Objects.requireNonNull(event.getMember()); - event.getGuild() - .ban(user, days, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); - } - - public static void getOpenPrivateChannel(long userId, String reason, - @NotNull SlashCommandEvent event) { - event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'.\040 - If you think this was a mistake, please contact a moderator or admin of the guild. - The ban reason is: %s - """ - .formatted(reason))) - .queue(); - } - - public static void getLogger(long authorNameId, long userNameId, int days, String reason) { - logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorNameId, userNameId, days, reason); - } -} From 563998a16c273f73d3734f60862ec51f3c33ae0a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 13:21:22 +0100 Subject: [PATCH 077/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 585aa5f109..bbc0be1ddf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -38,7 +38,7 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "the amount of days of the message history to delete, otherwise no messages are deleted.", + "the amount of days of the message history to delete, none means no messages are deleted.", true).addChoice("none", 0) .addChoice("1", 1) .addChoice("2", 2) From c6dd085fc5b3e4ae1010409744e3e62f511576d9 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 16:14:38 +0100 Subject: [PATCH 078/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index bbc0be1ddf..833724ea93 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -13,7 +13,6 @@ import java.util.Objects; - /** * This command can ban users and optionally remove their messages from the past days. Banning can * also be paired with a ban reason. The command will also try to DM the user to inform him about @@ -28,7 +27,6 @@ public final class BanCommand extends SlashCommandAdapter { private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); - /** * Creates an instance of the ban command. */ @@ -37,16 +35,13 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) - .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "the amount of days of the message history to delete, none means no messages are deleted.", - true).addChoice("none", 0) - .addChoice("1", 1) - .addChoice("2", 2) - .addChoice("3", 3) - .addChoice("4", 4) - .addChoice("5", 5) - .addChoice("6", 6) - .addChoice("7", 7)); + .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, + "the amount of days of the message history to delete, none means no messages are deleted.", + true) + .addChoice("none", 0) + .addChoice("recent", 1) + .addChoice("all", 7) + ); } @Override @@ -82,12 +77,13 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - long authorId = author.getIdLong(); + + // TODO Implement the same delete message structure for the purge message. int days = Math - .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); - + .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) + .getAsLong()); + long authorId = author.getIdLong(); banUser(userId, authorId, user, reason, days, event); } From 57e89f946ea3ac72785feb1d488a928470e52266 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 16:19:11 +0100 Subject: [PATCH 079/182] Update BanCommand.java --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 833724ea93..27f3b00d20 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -84,11 +84,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); long authorId = author.getIdLong(); - banUser(userId, authorId, user, reason, days, event); + banUser(user, reason, days, userId, authorId, event); } - private static void banUser(long userId, long authorNameId, Member user, String reason, - int days, @NotNull SlashCommandEvent event) { + private static void banUser(Member user, String reason, + int days, long userId, long authorNameId, @NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( From 6a4f39a2f805cd986aa519718d7359d5d564f094 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 16:25:53 +0100 Subject: [PATCH 080/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 27f3b00d20..0da8882c08 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -26,6 +26,7 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; private static final String REASON_OPTION = "reason"; + private static final Integer REASON_MAX_LENGTH = 512; private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); /** * Creates an instance of the ban command. @@ -89,6 +90,13 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { private static void banUser(Member user, String reason, int days, long userId, long authorNameId, @NotNull SlashCommandEvent event) { + + if(reason.length() > BanCommand.REASON_MAX_LENGTH) { + event.reply("The reason can not be over 512 characters") + .setEphemeral(true) + .queue(); + } + event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( From 21059894323c748d52216d2f7a646f3928e3f242 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 16:26:17 +0100 Subject: [PATCH 081/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 0da8882c08..a9fa279d70 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -28,6 +28,7 @@ public final class BanCommand extends SlashCommandAdapter { private static final String REASON_OPTION = "reason"; private static final Integer REASON_MAX_LENGTH = 512; private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); + /** * Creates an instance of the ban command. */ @@ -36,13 +37,9 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) - .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, - "the amount of days of the message history to delete, none means no messages are deleted.", - true) - .addChoice("none", 0) - .addChoice("recent", 1) - .addChoice("all", 7) - ); + .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, + "the amount of days of the message history to delete, none means no messages are deleted.", + true).addChoice("none", 0).addChoice("recent", 1).addChoice("all", 7)); } @Override @@ -82,19 +79,17 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { // TODO Implement the same delete message structure for the purge message. int days = Math - .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); + .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) + .getAsLong()); long authorId = author.getIdLong(); banUser(user, reason, days, userId, authorId, event); } - private static void banUser(Member user, String reason, - int days, long userId, long authorNameId, @NotNull SlashCommandEvent event) { + private static void banUser(Member user, String reason, int days, long userId, + long authorNameId, @NotNull SlashCommandEvent event) { - if(reason.length() > BanCommand.REASON_MAX_LENGTH) { - event.reply("The reason can not be over 512 characters") - .setEphemeral(true) - .queue(); + if (reason.length() > BanCommand.REASON_MAX_LENGTH) { + event.reply("The reason can not be over 512 characters").setEphemeral(true).queue(); } event.getJDA() From 1532d75b3a6c0b87cc20a6f8c27bd6d2bff42138 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 16:40:50 +0100 Subject: [PATCH 082/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index a9fa279d70..c4ec3ebc55 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -85,7 +85,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { banUser(user, reason, days, userId, authorId, event); } - private static void banUser(Member user, String reason, int days, long userId, + private static void banUser(@NotNull Member user, @NotNull String reason, int days, long userId, long authorNameId, @NotNull SlashCommandEvent event) { if (reason.length() > BanCommand.REASON_MAX_LENGTH) { From bc90bd41dd88cb6f062da85de5b03d721183e151 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 16:41:16 +0100 Subject: [PATCH 083/182] Update BanCommand.java --- .../tjbot/commands/moderation/BanCommand.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c4ec3ebc55..07b421ea87 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -81,6 +81,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { int days = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) .getAsLong()); + + if (reason.length() > BanCommand.REASON_MAX_LENGTH) { + event.reply("The reason can not be over 512 characters").setEphemeral(true).queue(); + } + long authorId = author.getIdLong(); banUser(user, reason, days, userId, authorId, event); } @@ -88,10 +93,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { private static void banUser(@NotNull Member user, @NotNull String reason, int days, long userId, long authorNameId, @NotNull SlashCommandEvent event) { - if (reason.length() > BanCommand.REASON_MAX_LENGTH) { - event.reply("The reason can not be over 512 characters").setEphemeral(true).queue(); - } - event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( From f7aac63caea0db659a75147c2ef17214bddb2be6 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 19:46:23 +0100 Subject: [PATCH 084/182] Fixed everything --- .gitignore | 1 - .../tjbot/commands/moderation/BanCommand.java | 29 ++++++++++--------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/.gitignore b/.gitignore index f24a747936..0ce9cdb2ce 100644 --- a/.gitignore +++ b/.gitignore @@ -158,4 +158,3 @@ logviewer/types.d.ts logviewer/pnpm-lock.yaml logviewer/webpack.config.js logviewer/webpack.generated.js -.DS_Store diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 07b421ea87..3931621660 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -1,9 +1,12 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -24,8 +27,11 @@ */ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; - private static final String DELETE_MESSAGE_HISTORY_DAYS_OPTION = "delete-message-history-days"; + private static final String DELETE_HISTORY_OPTION = "delete-history"; private static final String REASON_OPTION = "reason"; + /** + * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. + */ private static final Integer REASON_MAX_LENGTH = 512; private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); @@ -37,7 +43,7 @@ public BanCommand() { getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) - .addOptions(new OptionData(OptionType.INTEGER, DELETE_MESSAGE_HISTORY_DAYS_OPTION, + .addOptions(new OptionData(OptionType.INTEGER, DELETE_HISTORY_OPTION, "the amount of days of the message history to delete, none means no messages are deleted.", true).addChoice("none", 0).addChoice("recent", 1).addChoice("all", 7)); } @@ -48,8 +54,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member author = Objects.requireNonNull(event.getMember()); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - long userId = user.getUser().getIdLong(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the BAN_MEMBERS permission to ban users from this server.") .setEphemeral(true) @@ -70,24 +74,22 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + logger.error("The Bot does not have BAN_MEMBERS permissions so it cant ban users"); + if (!bot.canInteract(Objects.requireNonNull(user))) { event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); return; } - - // TODO Implement the same delete message structure for the purge message. int days = Math - .toIntExact(Objects.requireNonNull(event.getOption(DELETE_MESSAGE_HISTORY_DAYS_OPTION)) - .getAsLong()); + .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); if (reason.length() > BanCommand.REASON_MAX_LENGTH) { event.reply("The reason can not be over 512 characters").setEphemeral(true).queue(); } - long authorId = author.getIdLong(); - banUser(user, reason, days, userId, authorId, event); + banUser(user, reason, days, user.getUser().getIdLong(), author.getIdLong(), event); } private static void banUser(@NotNull Member user, @NotNull String reason, int days, long userId, @@ -102,14 +104,15 @@ private static void banUser(@NotNull Member user, @NotNull String reason, int da The ban reason is: %s """ .formatted(reason))) - .queue(); + .queue(null, throwable -> { + }); - Member author = Objects.requireNonNull(event.getMember()); + logger.error("I could not send a personal message to '{}' ", userId); event.getGuild() .ban(user, days, reason) .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + author.getUser().getAsTag() + " for: " + reason)) + + user.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info( From 08be6987ad19370a256d3ddd879788bb8ecc627f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 19:58:23 +0100 Subject: [PATCH 085/182] Fixed the loggers --- .../tjbot/commands/moderation/BanCommand.java | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 3931621660..5aed087e22 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -71,17 +71,17 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("I don't have the BAN_MEMBERS permission to ban users from this server.") .setEphemeral(true) .queue(); + + logger.error("The Bot does not have BAN_MEMBERS permissions so it cant ban users"); + return; } - logger.error("The Bot does not have BAN_MEMBERS permissions so it cant ban users"); - if (!bot.canInteract(Objects.requireNonNull(user))) { event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); return; } - int days = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); @@ -105,10 +105,9 @@ private static void banUser(@NotNull Member user, @NotNull String reason, int da """ .formatted(reason))) .queue(null, throwable -> { + logger.error("I could not send a personal message to '{}' ", userId); }); - logger.error("I could not send a personal message to '{}' ", userId); - event.getGuild() .ban(user, days, reason) .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " From cdc838931618e74dec43f96578832ad2afc9f790 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 19:59:06 +0100 Subject: [PATCH 086/182] Update .gitignore --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index 0ce9cdb2ce..563dbf8375 100644 --- a/.gitignore +++ b/.gitignore @@ -158,3 +158,6 @@ logviewer/types.d.ts logviewer/pnpm-lock.yaml logviewer/webpack.config.js logviewer/webpack.generated.js + +### Mac Patch ### +.DS_Store From 12f6a40e1632e8873e4765a419d2dbfe41578a80 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 22 Oct 2021 20:40:58 +0100 Subject: [PATCH 087/182] fixed kick and unban command --- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 6 +++--- .../tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 4cf01f8ddb..672fcf660e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -93,8 +93,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { + author.getUser().getAsTag() + " for: " + reason)) .queue(); - String authorId = author.getId(); - logger.info(" '{}' kicked the user '{}' due to reason being '{}'", authorId, userId, - reason); + logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", + author.getUser().getAsTag(), author.getIdLong(), author.getUser().getAsTag(), + userId, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index a39f1478de..d25ef1973b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -61,9 +61,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } + logger.error("The user '{}' does not exist", userId); event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); - String authorId = author.getId(); - logger.info(" '{}' unbanned user id '{}' ", authorId, userId); + logger.info(" '{}' unbanned user id '{}' ", author.getIdLong(), userId); } } From 4d3f4c10223f3478059e6d81cc8a55970bdecc68 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 11:30:10 +0100 Subject: [PATCH 088/182] Update KickCommand.java --- .../commands/moderation/KickCommand.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 672fcf660e..bec942dbaf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -9,7 +9,6 @@ import org.slf4j.LoggerFactory; import org.togetherjava.tjbot.commands.SlashCommandAdapter; import org.togetherjava.tjbot.commands.SlashCommandVisibility; - import java.util.Objects; @@ -30,7 +29,7 @@ public KickCommand() { super("kick", "Kicks a given user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to kick", true) - .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); + .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); } /** @@ -44,18 +43,15 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); - Member author = Objects.requireNonNull(event.getMember()); - String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - long userId = Objects.requireNonNull(user).getUser().getIdLong(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( - "You do not have the KICK_MEMBERS permission to kick users from this server.") - .setEphemeral(true) - .queue(); + "You do not have the KICK_MEMBERS permission to kick users from this server.") + .setEphemeral(true) + .queue(); return; } @@ -67,31 +63,35 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the KICK_MEMBERS permission to kick users from this server.") - .setEphemeral(true) - .queue(); + .setEphemeral(true) + .queue(); return; } if (!bot.canInteract(Objects.requireNonNull(user))) { event.reply( - "This user is too powerful for me to kick because he has more permissions than me.") - .setEphemeral(true) - .queue(); + "This user is too powerful for me to kick because he has more permissions than me.") + .setEphemeral(true) + .queue(); return; } event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - "Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. If you think this was a mistake, please contact a moderator or admin of the guild. The kick reason is: " - + reason)) - .queue(); + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. + If you think this was a mistake, please contact a moderator or admin of the guild. + The kick reason is: + """ + + reason)) + .queue(); event.getGuild() - .kick(user, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); + .kick(user, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", author.getUser().getAsTag(), author.getIdLong(), author.getUser().getAsTag(), From 19e7b5708a6f80791c53b3b821dbd4c87e03e8d0 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 11:31:28 +0100 Subject: [PATCH 089/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index d25ef1973b..bf848b70c7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -41,7 +41,6 @@ public UnbanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { final String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); - Member author = Objects.requireNonNull(event.getMember()); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { @@ -63,7 +62,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { logger.error("The user '{}' does not exist", userId); event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); - logger.info(" '{}' unbanned user id '{}' ", author.getIdLong(), userId); } } From 18e05880eb350410668f90a062eabbe6c022f416 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 12:11:14 +0100 Subject: [PATCH 090/182] Update UnbanCommand.java --- .../commands/moderation/UnbanCommand.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index bf848b70c7..355f07a905 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -3,7 +3,9 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.OptionType; +import net.dv8tion.jda.api.requests.ErrorResponse; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -45,23 +47,35 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "You do not have the BAN_MEMBERS permission to urban users from this server.") - .setEphemeral(true) - .queue(); + "You do not have the BAN_MEMBERS permission to urban users from this server.") + .setEphemeral(true) + .queue(); return; } Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "I don't have the BAN_MEMBERS permission to unban the user from this server.") - .setEphemeral(true) - .queue(); + "I don't have the BAN_MEMBERS permission to unban the user from this server.") + .setEphemeral(true) + .queue(); return; } - logger.error("The user '{}' does not exist", userId); - event.getGuild().unban(userId).flatMap(v -> event.reply("Unbanned the user")).queue(); - logger.info(" '{}' unbanned user id '{}' ", author.getIdLong(), userId); + + event.getGuild().unban(userId).queue(v -> { + event.reply("Unbanned the user"); + logger.info(" '{}' unbanned user id '{}' ", author.getIdLong(), userId); + }, throwable -> { + if (throwable instanceof ErrorResponseException errorResponseException && + errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { + + event.reply("the specified user doesn't exist").queue(); + logger.debug("The user '{}' does not exist", userId); + } else { + event.reply("Something went wrong, check the logs or contact a helper/moderator").queue(); + logger.error("Something went wrong in the unban command: " + throwable); + } + }); } } From 39c8c127a2b9712cbeebef3cef49d8c6108bc9ee Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 15:32:40 +0100 Subject: [PATCH 091/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 1 - 1 file changed, 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 5aed087e22..7157f59af7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -73,7 +73,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The Bot does not have BAN_MEMBERS permissions so it cant ban users"); - return; } From 7f2389fee018b587860b2e3bd77071eada79f86a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 15:50:11 +0100 Subject: [PATCH 092/182] Update BanCommand.java --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 7157f59af7..83fddd0765 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -5,9 +5,11 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.OptionData; +import net.dv8tion.jda.api.requests.ErrorResponse; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -72,10 +74,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .setEphemeral(true) .queue(); - logger.error("The Bot does not have BAN_MEMBERS permissions so it cant ban users"); + logger.error("The bot does not have BAN_MEMBERS permissions"); return; } - if (!bot.canInteract(Objects.requireNonNull(user))) { event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); return; From 431d4881fb078932e87efb5dfebc809a70a01cac Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 15:58:11 +0100 Subject: [PATCH 093/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 83fddd0765..bc543da76b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -5,11 +5,8 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.OptionType; -import net.dv8tion.jda.api.interactions.commands.build.CommandData; import net.dv8tion.jda.api.interactions.commands.build.OptionData; -import net.dv8tion.jda.api.requests.ErrorResponse; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; From 47f9f289e7a3f0d69317ebc230e52c25c9ddec28 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 15:59:59 +0100 Subject: [PATCH 094/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index bc543da76b..86a2ee094f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -52,6 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); Member author = Objects.requireNonNull(event.getMember()); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply("You do not have the BAN_MEMBERS permission to ban users from this server.") @@ -65,7 +66,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply("I don't have the BAN_MEMBERS permission to ban users from this server.") .setEphemeral(true) From e3d2a5e0d628ec3ad4ac1dfd8554327b18ba531a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:00:20 +0100 Subject: [PATCH 095/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index bec942dbaf..216b14ea6f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -45,6 +45,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); Member author = Objects.requireNonNull(event.getMember()); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); long userId = Objects.requireNonNull(user).getUser().getIdLong(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { @@ -60,7 +61,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply("I don't have the KICK_MEMBERS permission to kick users from this server.") .setEphemeral(true) From 5cef333bdf0e5b75d4f37d13cfa6d856ac335c46 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:01:24 +0100 Subject: [PATCH 096/182] Update UnbanCommand.java --- .../tjbot/commands/moderation/UnbanCommand.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 355f07a905..d548e4c04c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -43,7 +43,6 @@ public UnbanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { final String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); - Member author = Objects.requireNonNull(event.getMember()); if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply( @@ -53,19 +52,17 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); - if (!bot.hasPermission(Permission.BAN_MEMBERS)) { + if (!(event.getGuild()).getSelfMember().hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I don't have the BAN_MEMBERS permission to unban the user from this server.") .setEphemeral(true) .queue(); return; } - - + event.getGuild().unban(userId).queue(v -> { event.reply("Unbanned the user"); - logger.info(" '{}' unbanned user id '{}' ", author.getIdLong(), userId); + logger.info(" '{}' unbanned user id '{}' ", event.getMember().getIdLong(), userId); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { From 7bfb2885e0856510e5068da993095c18e6811195 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:26:25 +0100 Subject: [PATCH 097/182] fixed everything that i was told to fix --- .../tjbot/commands/moderation/BanCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 86a2ee094f..f54e1a347e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -71,7 +71,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .setEphemeral(true) .queue(); - logger.error("The bot does not have BAN_MEMBERS permissions"); + logger.error("The bot does not have BAN_MEMBERS permissions on the server '{}' ", + event.getGuild().getId()); return; } if (!bot.canInteract(Objects.requireNonNull(user))) { @@ -84,13 +85,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (reason.length() > BanCommand.REASON_MAX_LENGTH) { event.reply("The reason can not be over 512 characters").setEphemeral(true).queue(); + return; } banUser(user, reason, days, user.getUser().getIdLong(), author.getIdLong(), event); } private static void banUser(@NotNull Member user, @NotNull String reason, int days, long userId, - long authorNameId, @NotNull SlashCommandEvent event) { + long authorId, @NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) @@ -102,7 +104,7 @@ private static void banUser(@NotNull Member user, @NotNull String reason, int da """ .formatted(reason))) .queue(null, throwable -> { - logger.error("I could not send a personal message to '{}' ", userId); + logger.error("I could not dm the user '{}' to inform them they were banned.", userId); }); event.getGuild() @@ -113,6 +115,6 @@ private static void banUser(@NotNull Member user, @NotNull String reason, int da logger.info( " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", - authorNameId, userId, days, reason); + authorId, userId, days, reason); } } From 547536f7176e578b39787350d7899a7aaa05b17a Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:28:01 +0100 Subject: [PATCH 098/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index d548e4c04c..f329847d0c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -52,7 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!(event.getGuild()).getSelfMember().hasPermission(Permission.BAN_MEMBERS)) { + if (!(Objects.requireNonNull(event.getGuild())).getSelfMember().hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I don't have the BAN_MEMBERS permission to unban the user from this server.") .setEphemeral(true) From 08c42dcb3ec9ac1143c820283879c28ad02c2934 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:28:18 +0100 Subject: [PATCH 099/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index f329847d0c..cdebcc7994 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -1,7 +1,6 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -61,7 +60,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } event.getGuild().unban(userId).queue(v -> { - event.reply("Unbanned the user"); + event.reply("Unbanned the user") + .queue(); logger.info(" '{}' unbanned user id '{}' ", event.getMember().getIdLong(), userId); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && From b44f3af86d0c17582d97c48058ad9e75d91059bb Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:29:52 +0100 Subject: [PATCH 100/182] Tweaking the commands --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index f54e1a347e..3b113f2ab4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -62,7 +62,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for you to ban.").setEphemeral(true).queue(); + event.reply("The user" + user + " is too powerful for you to ban.").setEphemeral(true).queue(); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 216b14ea6f..ea05286f33 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -57,7 +57,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("\"This user is too powerful for you to kick.").setEphemeral(true).queue(); + event.reply("The user" + user + "is too powerful for you to kick.").setEphemeral(true).queue(); return; } @@ -65,6 +65,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("I don't have the KICK_MEMBERS permission to kick users from this server.") .setEphemeral(true) .queue(); + + logger.error("The bot does not have KICK_MEMBERS permissions on the server '{}' ", + event.getGuild().getId()); return; } From 6c4f3ed5190f89637dc976ab52e9c16cf603d6a3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:32:57 +0100 Subject: [PATCH 101/182] improving the sentecences --- .../tjbot/commands/moderation/BanCommand.java | 4 ++-- .../tjbot/commands/moderation/KickCommand.java | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 3b113f2ab4..9cdc7aa6c9 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -55,7 +55,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("You do not have the BAN_MEMBERS permission to ban users from this server.") + event.reply("You do not have the BAN_MEMBERS permission which means you can't unable to ban users in this server.") .setEphemeral(true) .queue(); return; @@ -67,7 +67,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("I don't have the BAN_MEMBERS permission to ban users from this server.") + event.reply("I don't have the BAN_MEMBERS permission which means I am unable to ban users in this server.") .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index ea05286f33..9e33ae6ced 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -50,7 +50,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( - "You do not have the KICK_MEMBERS permission to kick users from this server.") + "You do not have the KICK_MEMBERS permission which means you can't unable to kick users in this server.") .setEphemeral(true) .queue(); return; @@ -62,7 +62,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.hasPermission(Permission.KICK_MEMBERS)) { - event.reply("I don't have the KICK_MEMBERS permission to kick users from this server.") + event.reply("I don't have the KICK_MEMBERS permission which means I am unable to kick users in this server.") .setEphemeral(true) .queue(); @@ -83,9 +83,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. - If you think this was a mistake, please contact a moderator or admin of the guild. - The kick reason is: + Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. + If you think this was a mistake, please contact a moderator or admin of the guild. + The kick reason is: """ + reason)) .queue(); From ec26837d9ab7da36983eeefa434a92eb525af316 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 16:50:16 +0100 Subject: [PATCH 102/182] added some loggers --- .../tjbot/commands/moderation/BanCommand.java | 5 ++++- .../tjbot/commands/moderation/KickCommand.java | 8 ++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 9cdc7aa6c9..7d61dbfb23 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -76,7 +76,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("This user is too powerful for me to ban.").setEphemeral(true).queue(); + event.reply("The user" + user + "is too powerful for me to ban.").setEphemeral(true).queue(); + + logger.error("The bot does not have enough permissions to ban '{}'", + user.getUser().getIdLong()); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 9e33ae6ced..7a02fb7f68 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -72,10 +72,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply( - "This user is too powerful for me to kick because he has more permissions than me.") - .setEphemeral(true) - .queue(); + event.reply("The user" + user + "is too powerful for me to kick.").setEphemeral(true).queue(); + + logger.error("The bot does not have enough permissions to kick '{}'", + user.getUser().getIdLong()); return; } From 9d199d95a970e1f2a8ce116d2d9171d6eb66cf20 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 17:43:59 +0100 Subject: [PATCH 103/182] spotlessApply --- .../tjbot/commands/moderation/BanCommand.java | 17 +++++-- .../commands/moderation/KickCommand.java | 49 ++++++++++--------- .../commands/moderation/UnbanCommand.java | 29 ++++++----- 3 files changed, 55 insertions(+), 40 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 7d61dbfb23..f482f40d6d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -55,19 +55,23 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("You do not have the BAN_MEMBERS permission which means you can't unable to ban users in this server.") + event.reply( + "You do not have the BAN_MEMBERS permission which means you can't unable to ban users in this server.") .setEphemeral(true) .queue(); return; } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user + " is too powerful for you to ban.").setEphemeral(true).queue(); + event.reply("The user" + user + " is too powerful for you to ban.") + .setEphemeral(true) + .queue(); return; } if (!bot.hasPermission(Permission.BAN_MEMBERS)) { - event.reply("I don't have the BAN_MEMBERS permission which means I am unable to ban users in this server.") + event.reply( + "I don't have the BAN_MEMBERS permission which means I am unable to ban users in this server.") .setEphemeral(true) .queue(); @@ -76,7 +80,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user + "is too powerful for me to ban.").setEphemeral(true).queue(); + event.reply("The user" + user.getUser().getIdLong() + "is too powerful for me to ban.") + .setEphemeral(true) + .queue(); logger.error("The bot does not have enough permissions to ban '{}'", user.getUser().getIdLong()); @@ -107,7 +113,8 @@ private static void banUser(@NotNull Member user, @NotNull String reason, int da """ .formatted(reason))) .queue(null, throwable -> { - logger.error("I could not dm the user '{}' to inform them they were banned.", userId); + logger.error("I could not dm the user '{}' to inform them they were banned.", + userId); }); event.getGuild() diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 7a02fb7f68..a3d51ac6fc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -29,7 +29,7 @@ public KickCommand() { super("kick", "Kicks a given user", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to kick", true) - .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); + .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); } /** @@ -50,21 +50,24 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( - "You do not have the KICK_MEMBERS permission which means you can't unable to kick users in this server.") - .setEphemeral(true) - .queue(); + "You do not have the KICK_MEMBERS permission which means you can't unable to kick users in this server.") + .setEphemeral(true) + .queue(); return; } if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user + "is too powerful for you to kick.").setEphemeral(true).queue(); + event.reply("The user" + user + "is too powerful for you to kick.") + .setEphemeral(true) + .queue(); return; } if (!bot.hasPermission(Permission.KICK_MEMBERS)) { - event.reply("I don't have the KICK_MEMBERS permission which means I am unable to kick users in this server.") - .setEphemeral(true) - .queue(); + event.reply( + "I don't have the KICK_MEMBERS permission which means I am unable to kick users in this server.") + .setEphemeral(true) + .queue(); logger.error("The bot does not have KICK_MEMBERS permissions on the server '{}' ", event.getGuild().getId()); @@ -72,7 +75,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user + "is too powerful for me to kick.").setEphemeral(true).queue(); + event.reply("The user" + user.getUser().getIdLong() + "is too powerful for me to kick.") + .setEphemeral(true) + .queue(); logger.error("The bot does not have enough permissions to kick '{}'", user.getUser().getIdLong()); @@ -80,21 +85,21 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. - If you think this was a mistake, please contact a moderator or admin of the guild. - The kick reason is: - """ - + reason)) - .queue(); + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. + If you think this was a mistake, please contact a moderator or admin of the guild. + The kick reason is: + """ + + reason)) + .queue(); event.getGuild() - .kick(user, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " - + author.getUser().getAsTag() + " for: " + reason)) - .queue(); + .kick(user, reason) + .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " + + author.getUser().getAsTag() + " for: " + reason)) + .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", author.getUser().getAsTag(), author.getIdLong(), author.getUser().getAsTag(), diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index cdebcc7994..f8724980ab 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -45,32 +45,35 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "You do not have the BAN_MEMBERS permission to urban users from this server.") - .setEphemeral(true) - .queue(); + "You do not have the BAN_MEMBERS permission to urban users from this server.") + .setEphemeral(true) + .queue(); return; } - if (!(Objects.requireNonNull(event.getGuild())).getSelfMember().hasPermission(Permission.BAN_MEMBERS)) { + if (!(Objects.requireNonNull(event.getGuild())).getSelfMember() + .hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "I don't have the BAN_MEMBERS permission to unban the user from this server.") - .setEphemeral(true) - .queue(); + "I don't have the BAN_MEMBERS permission which means I am unable to unban users in this server.") + .setEphemeral(true) + .queue(); + + logger.error("The bot does not have enough permissions to unban '{}'", userId); return; } - + event.getGuild().unban(userId).queue(v -> { - event.reply("Unbanned the user") - .queue(); + event.reply("Unbanned the user").queue(); logger.info(" '{}' unbanned user id '{}' ", event.getMember().getIdLong(), userId); }, throwable -> { - if (throwable instanceof ErrorResponseException errorResponseException && - errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { + if (throwable instanceof ErrorResponseException errorResponseException + && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { event.reply("the specified user doesn't exist").queue(); logger.debug("The user '{}' does not exist", userId); } else { - event.reply("Something went wrong, check the logs or contact a helper/moderator").queue(); + event.reply("Something went wrong, check the logs or contact a helper/moderator") + .queue(); logger.error("Something went wrong in the unban command: " + throwable); } }); From 9edd2a5bd8113f470c751c02c464a98bf47fbadb Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 17:51:59 +0100 Subject: [PATCH 104/182] fixed a gramatical mistake --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index f482f40d6d..4aa5645db0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -75,7 +75,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .setEphemeral(true) .queue(); - logger.error("The bot does not have BAN_MEMBERS permissions on the server '{}' ", + logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", event.getGuild().getId()); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index a3d51ac6fc..982bf4a4b2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -69,7 +69,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .setEphemeral(true) .queue(); - logger.error("The bot does not have KICK_MEMBERS permissions on the server '{}' ", + logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", event.getGuild().getId()); return; } From fb6b4f842b2eb018b0fb1b3b786e70352967bacf Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 17:52:33 +0100 Subject: [PATCH 105/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index f8724980ab..7a93194b67 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -58,7 +58,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .setEphemeral(true) .queue(); - logger.error("The bot does not have enough permissions to unban '{}'", userId); + logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", + event.getGuild().getId()); return; } From e2aee23ab5cc06e232fffa09ef6a5fb06fb7a0ad Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 19:03:31 +0100 Subject: [PATCH 106/182] Update V1__Database_Listener.sql --- application/src/main/resources/db/V1__Database_Listener.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/resources/db/V1__Database_Listener.sql b/application/src/main/resources/db/V1__Database_Listener.sql index f1956f216e..8f16bf2dc6 100644 --- a/application/src/main/resources/db/V1__Database_Listener.sql +++ b/application/src/main/resources/db/V1__Database_Listener.sql @@ -2,4 +2,4 @@ CREATE TABLE storage ( key TEXT NOT NULL PRIMARY KEY, value TEXT NOT NULL -) +) \ No newline at end of file From d8f4bee7c48be73718d0fe1d4a435b6f9c5878df Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 19:04:54 +0100 Subject: [PATCH 107/182] Update V1__Database_Listener.sql --- application/src/main/resources/db/V1__Database_Listener.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/resources/db/V1__Database_Listener.sql b/application/src/main/resources/db/V1__Database_Listener.sql index 8f16bf2dc6..f1956f216e 100644 --- a/application/src/main/resources/db/V1__Database_Listener.sql +++ b/application/src/main/resources/db/V1__Database_Listener.sql @@ -2,4 +2,4 @@ CREATE TABLE storage ( key TEXT NOT NULL PRIMARY KEY, value TEXT NOT NULL -) \ No newline at end of file +) From caa53a572b5dcdfb52983f0fd0ed515c9e0042d9 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 23 Oct 2021 19:51:42 +0100 Subject: [PATCH 108/182] Fixed everything i was told to fix --- .../tjbot/commands/moderation/BanCommand.java | 23 ++++---- .../commands/moderation/KickCommand.java | 55 +++++++++---------- .../commands/moderation/UnbanCommand.java | 4 +- 3 files changed, 38 insertions(+), 44 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 4aa5645db0..426f4e2274 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -38,10 +38,10 @@ public final class BanCommand extends SlashCommandAdapter { * Creates an instance of the ban command. */ public BanCommand() { - super("ban", "Bans a given user", SlashCommandVisibility.GUILD); + super("ban", "Bans the given user from the server", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to ban", true) - .addOption(OptionType.STRING, REASON_OPTION, "why the user should be banned", true) + .addOption(OptionType.STRING, REASON_OPTION, "Why the user should be banned", true) .addOptions(new OptionData(OptionType.INTEGER, DELETE_HISTORY_OPTION, "the amount of days of the message history to delete, none means no messages are deleted.", true).addChoice("none", 0).addChoice("recent", 1).addChoice("all", 7)); @@ -56,7 +56,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "You do not have the BAN_MEMBERS permission which means you can't unable to ban users in this server.") + "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") .setEphemeral(true) .queue(); return; @@ -71,7 +71,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "I don't have the BAN_MEMBERS permission which means I am unable to ban users in this server.") + "I can not ban users in this guild since I do not have the BAN_MEMBERS permission.") .setEphemeral(true) .queue(); @@ -83,9 +83,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("The user" + user.getUser().getIdLong() + "is too powerful for me to ban.") .setEphemeral(true) .queue(); - - logger.error("The bot does not have enough permissions to ban '{}'", - user.getUser().getIdLong()); return; } @@ -107,11 +104,13 @@ private static void banUser(@NotNull Member user, @NotNull String reason, int da .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild 'Together Java'.\040 - If you think this was a mistake, please contact a moderator or admin of the guild. - The ban reason is: %s - """ - .formatted(reason))) + Hey there, sorry to tell you but unfortunately you have been banned from the guild""" + + event.getGuild().getName() + + """ + If you think this was a mistake, please contact a moderator or admin of the guild. + The ban reason is: %s + """ + .formatted(reason))) .queue(null, throwable -> { logger.error("I could not dm the user '{}' to inform them they were banned.", userId); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 982bf4a4b2..e3d57934fd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -13,44 +13,35 @@ /** - *

- * The implemented command is {@code /kick @user reason}, upon which the bot will kick the user. + * When triggered with {@code /kick @user reason}, the bot will check if the user has perms. Then it + * will check if itself has perms to kick. If it does it will check if the user is too powerful or + * not. If the user is not then bot will kick the user and reply with {@code Kicked User!}. */ public final class KickCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); private static final String USER_OPTION = "user"; private static final String REASON_OPTION = "reason"; - /** * Creates an instance of the kick command. */ public KickCommand() { - super("kick", "Kicks a given user", SlashCommandVisibility.GUILD); + super("kick", "Kicks the given user from the user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, USER_OPTION, "The user which you want to kick", true) - .addOption(OptionType.STRING, REASON_OPTION, "why the user should be kicked", true); + getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to kick", true) + .addOption(OptionType.STRING, REASON_OPTION, "Why the user should be kicked", true); } - /** - * When triggered with {@code /kick @user reason}, the bot will check if the user has perms. - * Then it will check if itself has perms to kick. If it does it will check if the user is too - * powerful or not. If the user is not then bot will kick the user and reply with - * {@code Kicked User!}. - * - * @param event the corresponding event - */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); Member author = Objects.requireNonNull(event.getMember()); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); - long userId = Objects.requireNonNull(user).getUser().getIdLong(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( - "You do not have the KICK_MEMBERS permission which means you can't unable to kick users in this server.") + "You can not kick users in this guild since you do not have the KICK_MEMBERS permission.") .setEphemeral(true) .queue(); return; @@ -65,44 +56,48 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply( - "I don't have the KICK_MEMBERS permission which means I am unable to kick users in this server.") + "I can not kick users in this guild since I do not have the KICK_MEMBERS permission.") .setEphemeral(true) .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - event.getGuild().getId()); + Objects.requireNonNull(event.getGuild().getId())); return; } - if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user.getUser().getIdLong() + "is too powerful for me to kick.") + if (!bot.canInteract(user)) { + event.reply("The user" + user + "is too powerful for me to kick.") .setEphemeral(true) .queue(); - - logger.error("The bot does not have enough permissions to kick '{}'", - user.getUser().getIdLong()); return; } + kickUser(user, reason, user.getUser().getIdLong(), event); + } + + public static void kickUser(@NotNull Member user, @NotNull String reason, long userId, + @NotNull SlashCommandEvent event) { event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild 'Together Java'. - If you think this was a mistake, please contact a moderator or admin of the guild. - The kick reason is: - """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild""" + + event.getGuild().getName() + + """ + If you think this was a mistake, please contact a moderator or admin of the guild. + The kick reason is: + """ + reason)) .queue(); event.getGuild() .kick(user, reason) .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " - + author.getUser().getAsTag() + " for: " + reason)) + + user.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", - author.getUser().getAsTag(), author.getIdLong(), author.getUser().getAsTag(), - userId, reason); + user.getUser().getAsTag(), user.getIdLong(), user.getUser().getAsTag(), userId, + reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 7a93194b67..f0221371aa 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -45,7 +45,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "You do not have the BAN_MEMBERS permission to urban users from this server.") + "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") .setEphemeral(true) .queue(); return; @@ -54,7 +54,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!(Objects.requireNonNull(event.getGuild())).getSelfMember() .hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "I don't have the BAN_MEMBERS permission which means I am unable to unban users in this server.") + "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") .setEphemeral(true) .queue(); From 7626460ad73950c8a5361a77f8cbf579f091551f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 11:13:34 +0100 Subject: [PATCH 109/182] changed logger.error to logger.info --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 5 ++++- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 426f4e2274..9460c3d671 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -80,9 +80,12 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user.getUser().getIdLong() + "is too powerful for me to ban.") + event.reply("The user" + user.getUser().getAsTag() + "is too powerful for me to ban.") .setEphemeral(true) .queue(); + + logger.info("The bot does not have enough permissions to ban '{}'", + user.getUser().getAsTag()); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index e3d57934fd..5e168d749d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -69,6 +69,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("The user" + user + "is too powerful for me to kick.") .setEphemeral(true) .queue(); + + logger.info("The bot does not have enough permissions to kick '{}'", + user.getUser().getAsTag()); return; } From 6a28671a3a709479eac1699c41ae1f6f917c07b3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 12:09:54 +0100 Subject: [PATCH 110/182] Removed TODO since codefactor said so --- .../java/org/togetherjava/tjbot/commands/tags/TagCommand.java | 1 - .../org/togetherjava/tjbot/commands/tags/TagManageCommand.java | 1 - .../java/org/togetherjava/tjbot/commands/tags/TagSystem.java | 1 - .../java/org/togetherjava/tjbot/commands/tags/TagsCommand.java | 1 - 4 files changed, 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index e82b1ad827..d92afcff2d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -31,7 +31,6 @@ public TagCommand(TagSystem tagSystem) { this.tagSystem = tagSystem; - // TODO Thing about adding an ephemeral selection menu with pagination support // if the user calls this without id or similar getData().addOption(OptionType.STRING, ID_OPTION, "the id of the tag to display", true); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index cff16854ef..16cb909128 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -56,7 +56,6 @@ public TagManageCommand(TagSystem tagSystem) { this.tagSystem = tagSystem; - // TODO Think about adding a "Are you sure"-dialog to 'edit', 'edit-with-message' and // 'delete' getData().addSubcommands(new SubcommandData(Subcommand.RAW.name, "View the raw content of a tag, without Discord interpreting any of its content") diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java index b2698ea52a..1fd9a6ba00 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java @@ -61,7 +61,6 @@ boolean isUnknownTagAndHandle(@NotNull String id, @NotNull Interaction event) { if (hasTag(id)) { return false; } - // TODO Add fuzzy string matching suggestions (Levenshtein edit distance) event.reply("Could not find any tag with id '%s'.".formatted(id)) .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java index 82baa36a94..848383bb63 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java @@ -41,7 +41,6 @@ public TagsCommand(TagSystem tagSystem) { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - // TODO A list might be better than comma separated, which is hard to read event.replyEmbeds(MessageUtils.generateEmbed("All available tags", String.join(", ", tagSystem.getAllIds()), event.getUser(), TagSystem.AMBIENT_COLOR)) .addActionRow( From 69ea546b1e75c0bcc012ee705911cb56a9d0c7c2 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 12:35:20 +0100 Subject: [PATCH 111/182] undo --- .../java/org/togetherjava/tjbot/commands/tags/TagCommand.java | 1 + .../org/togetherjava/tjbot/commands/tags/TagManageCommand.java | 1 + .../java/org/togetherjava/tjbot/commands/tags/TagSystem.java | 1 + .../java/org/togetherjava/tjbot/commands/tags/TagsCommand.java | 1 + 4 files changed, 4 insertions(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java index d92afcff2d..e82b1ad827 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagCommand.java @@ -31,6 +31,7 @@ public TagCommand(TagSystem tagSystem) { this.tagSystem = tagSystem; + // TODO Thing about adding an ephemeral selection menu with pagination support // if the user calls this without id or similar getData().addOption(OptionType.STRING, ID_OPTION, "the id of the tag to display", true); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java index 16cb909128..cff16854ef 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagManageCommand.java @@ -56,6 +56,7 @@ public TagManageCommand(TagSystem tagSystem) { this.tagSystem = tagSystem; + // TODO Think about adding a "Are you sure"-dialog to 'edit', 'edit-with-message' and // 'delete' getData().addSubcommands(new SubcommandData(Subcommand.RAW.name, "View the raw content of a tag, without Discord interpreting any of its content") diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java index 1fd9a6ba00..b2698ea52a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagSystem.java @@ -61,6 +61,7 @@ boolean isUnknownTagAndHandle(@NotNull String id, @NotNull Interaction event) { if (hasTag(id)) { return false; } + // TODO Add fuzzy string matching suggestions (Levenshtein edit distance) event.reply("Could not find any tag with id '%s'.".formatted(id)) .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java index 848383bb63..82baa36a94 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/tags/TagsCommand.java @@ -41,6 +41,7 @@ public TagsCommand(TagSystem tagSystem) { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { + // TODO A list might be better than comma separated, which is hard to read event.replyEmbeds(MessageUtils.generateEmbed("All available tags", String.join(", ", tagSystem.getAllIds()), event.getUser(), TagSystem.AMBIENT_COLOR)) .addActionRow( From f4783bb0394b6a817f6bf03a7932d3d6fadc8616 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sun, 24 Oct 2021 12:50:45 +0100 Subject: [PATCH 112/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index f0221371aa..5ae611f20a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -65,7 +65,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getGuild().unban(userId).queue(v -> { event.reply("Unbanned the user").queue(); - logger.info(" '{}' unbanned user id '{}' ", event.getMember().getIdLong(), userId); + User user = event.getUser(); + logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag, user.getIdLong(), userId); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { From b7bbd22b93e7bb8002d32a04258301123f2ded9b Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sun, 24 Oct 2021 12:51:54 +0100 Subject: [PATCH 113/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../tjbot/commands/moderation/KickCommand.java | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 5e168d749d..2445a7b270 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -80,17 +80,16 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { public static void kickUser(@NotNull Member user, @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { + String guildName = event.getGuild().getName(); + event.getJDA() .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild""" - + event.getGuild().getName() - + """ - If you think this was a mistake, please contact a moderator or admin of the guild. - The kick reason is: - """ - + reason)) + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The kick reason is: %s + """.formatted(guildName , reason)) .queue(); event.getGuild() From ddda8492f7a00011f85e712f4cdc2e1f9514cd8b Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sun, 24 Oct 2021 13:28:39 +0100 Subject: [PATCH 114/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 2445a7b270..db9b602cb3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -78,7 +78,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { kickUser(user, reason, user.getUser().getIdLong(), event); } - public static void kickUser(@NotNull Member user, @NotNull String reason, long userId, + public static void kickUser(@NotNull Member member, @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); From 681ee0942bd2273875fcc87154bbd7028770cdbb Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 14:27:29 +0100 Subject: [PATCH 115/182] fixed most of the code --- .../tjbot/commands/moderation/BanCommand.java | 38 +++++++++---------- .../commands/moderation/KickCommand.java | 29 +++++++------- .../commands/moderation/UnbanCommand.java | 8 ++-- 3 files changed, 35 insertions(+), 40 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 9460c3d671..bb49c09c14 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -62,8 +62,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user + " is too powerful for you to ban.") + long userid = user.getIdLong(); + if (!author.canInteract(user)) { + event.reply("The user" + userid + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return; @@ -83,9 +84,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("The user" + user.getUser().getAsTag() + "is too powerful for me to ban.") .setEphemeral(true) .queue(); - - logger.info("The bot does not have enough permissions to ban '{}'", - user.getUser().getAsTag()); return; } @@ -97,36 +95,34 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(user, reason, days, user.getUser().getIdLong(), author.getIdLong(), event); + banUser(user, author, reason, days, userid, author.getIdLong(), event); } - private static void banUser(@NotNull Member user, @NotNull String reason, int days, long userId, + private static void banUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, int days, long userId, long authorId, @NotNull SlashCommandEvent event) { + String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild""" - + event.getGuild().getName() - + """ - If you think this was a mistake, please contact a moderator or admin of the guild. - The ban reason is: %s - """ - .formatted(reason))) + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the ban is: %s + """.formatted(guildName, reason))) .queue(null, throwable -> { - logger.error("I could not dm the user '{}' to inform them they were banned.", + logger.error("I could not dm the user '{}' to inform them that they were banned.", userId); }); event.getGuild() - .ban(user, days, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was banned by " - + user.getUser().getAsTag() + " for: " + reason)) + .ban(member, days, reason) + .flatMap(v -> event.reply(member.getUser().getAsTag() + " was banned by " + + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info( - " '{}' banned the user '{}' and deleted the message history of the last '{}' days. Reason was '{}'", + " '{}' banned the user '{}' and deleted their message history of the last '{}' days. Reason was '{}'", authorId, userId, days, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 2445a7b270..bfa1680a61 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -47,8 +47,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!author.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user + "is too powerful for you to kick.") + long userid = user.getIdLong(); + if (!author.canInteract(user)) { + event.reply("The user" + userid + "is too powerful for you to kick.") .setEphemeral(true) .queue(); return; @@ -66,31 +67,27 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } if (!bot.canInteract(user)) { - event.reply("The user" + user + "is too powerful for me to kick.") + event.reply("The user " + user + " is too powerful for me to kick.") .setEphemeral(true) .queue(); - - logger.info("The bot does not have enough permissions to kick '{}'", - user.getUser().getAsTag()); return; } - kickUser(user, reason, user.getUser().getIdLong(), event); + kickUser(user, reason, userid, event); } public static void kickUser(@NotNull Member user, @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); - event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The kick reason is: %s - """.formatted(guildName , reason)) - .queue(); + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the kick is: %s + """.formatted(guildName , reason))) + .queue(); event.getGuild() .kick(user, reason) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5ae611f20a..dc3b93c88d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; import net.dv8tion.jda.api.interactions.commands.OptionType; @@ -66,7 +67,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getGuild().unban(userId).queue(v -> { event.reply("Unbanned the user").queue(); User user = event.getUser(); - logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag, user.getIdLong(), userId); + logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag(), user.getIdLong(), userId); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { @@ -74,9 +75,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("the specified user doesn't exist").queue(); logger.debug("The user '{}' does not exist", userId); } else { - event.reply("Something went wrong, check the logs or contact a helper/moderator") + event.reply("Something went wrong, check the logs or contact a staff/moderator") .queue(); - logger.error("Something went wrong in the unban command: " + throwable); + + logger.error("Something went wrong in the unban command: '{}'", throwable); } }); } From 8ac9bc64ffff76af939aa456a742f599ce677681 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 14:32:05 +0100 Subject: [PATCH 116/182] Update KickCommand.java --- .../tjbot/commands/moderation/KickCommand.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index bf94a9ae11..7da1ed94c6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -73,10 +73,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - kickUser(user, reason, userid, event); + kickUser(user, author, reason, userid, event); } - public static void kickUser(@NotNull Member member, @NotNull String reason, long userId, + public static void kickUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() @@ -87,16 +87,19 @@ public static void kickUser(@NotNull Member member, @NotNull String reason, long If you think this was a mistake, please contact a moderator or admin of the guild. The reason for the kick is: %s """.formatted(guildName , reason))) - .queue(); + .queue(null, throwable -> { + logger.error("I could not dm the user '{}' to inform them that they were kicked.", + userId); + }); event.getGuild() - .kick(user, reason) - .flatMap(v -> event.reply(user.getUser().getAsTag() + " was kicked by " - + user.getUser().getAsTag() + " for: " + reason)) + .kick(member, reason) + .flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by " + + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", - user.getUser().getAsTag(), user.getIdLong(), user.getUser().getAsTag(), userId, + author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), userId, reason); } } From 7801677be11f7c52dd9c5640b14a0d84e730dc45 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 15:58:41 +0100 Subject: [PATCH 117/182] All checks should pass --- .../tjbot/commands/moderation/BanCommand.java | 26 ++++++------ .../commands/moderation/KickCommand.java | 42 ++++++++++--------- .../commands/moderation/UnbanCommand.java | 5 ++- 3 files changed, 40 insertions(+), 33 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index bb49c09c14..c5e814f06d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -98,22 +98,24 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { banUser(user, author, reason, days, userid, author.getIdLong(), event); } - private static void banUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, int days, long userId, - long authorId, @NotNull SlashCommandEvent event) { + private static void banUser(@NotNull Member member, @NotNull Member author, + @NotNull String reason, int days, long userId, long authorId, + @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the ban is: %s - """.formatted(guildName, reason))) - .queue(null, throwable -> { - logger.error("I could not dm the user '{}' to inform them that they were banned.", - userId); - }); + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the ban is: %s + """ + .formatted(guildName, reason))) + .queue(null, + throwable -> logger.error( + "I could not dm the user '{}' to inform them that they were banned.", + userId)); event.getGuild() .ban(member, days, reason) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 7da1ed94c6..fe166f111b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -13,9 +13,12 @@ /** - * When triggered with {@code /kick @user reason}, the bot will check if the user has perms. Then it - * will check if itself has perms to kick. If it does it will check if the user is too powerful or - * not. If the user is not then bot will kick the user and reply with {@code Kicked User!}. + * This command can kicks users. Kicking can also be paired with a kick reason. The command will + * also try to DM the user to inform him about the action and the reason. + *

+ * The command fails if the user triggering it is lacking permissions to either kick other users or + * to kick the specific given user (for example a moderator attempting to kick an admin). + * */ public final class KickCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); @@ -62,7 +65,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild().getId())); + event.getGuild().getId()); return; } @@ -76,21 +79,22 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { kickUser(user, author, reason, userid, event); } - public static void kickUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, long userId, - @NotNull SlashCommandEvent event) { + public static void kickUser(@NotNull Member member, @NotNull Member author, + @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() - .openPrivateChannelById(userId) - .flatMap(channel -> channel.sendMessage( - """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the kick is: %s - """.formatted(guildName , reason))) - .queue(null, throwable -> { - logger.error("I could not dm the user '{}' to inform them that they were kicked.", - userId); - }); + .openPrivateChannelById(userId) + .flatMap(channel -> channel.sendMessage( + """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the kick is: %s + """ + .formatted(guildName, reason))) + .queue(null, + throwable -> logger.error( + "I could not dm the user '{}' to inform them that they were kicked.", + userId)); event.getGuild() .kick(member, reason) @@ -99,7 +103,7 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, @Not .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", - author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), userId, - reason); + author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), + userId, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index dc3b93c88d..483f80deff 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -67,7 +67,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.getGuild().unban(userId).queue(v -> { event.reply("Unbanned the user").queue(); User user = event.getUser(); - logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag(), user.getIdLong(), userId); + logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag(), user.getIdLong(), + userId); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { @@ -78,7 +79,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("Something went wrong, check the logs or contact a staff/moderator") .queue(); - logger.error("Something went wrong in the unban command: '{}'", throwable); + logger.error("Something went wrong in the unban command: %d", throwable); } }); } From f04077d4e91ebac923db19872d1c9c4fdac9c1c0 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sun, 24 Oct 2021 16:38:24 +0100 Subject: [PATCH 118/182] Update UnbanCommand.java --- .../tjbot/commands/moderation/UnbanCommand.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 483f80deff..5b2d45841d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -15,8 +15,9 @@ import java.util.Objects; /** + * This command can unban users. *

- * The implemented command is {@code /unban user_id}, upon which the bot will unban the user. + * The command fails if the user triggering it is lacking permissions to either unban other users. */ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); @@ -35,8 +36,8 @@ public UnbanCommand() { /** * When triggered with {@code /unban user_id}}, the bot will respond will check if the user has - * perms. Then it will check if itself has perms to unban. If it does it will check if the user - * is the user is too powerful or not. If the user is not then unban will ban the user. + * perms. Then it will check if itself has perms to unban. If it does then it will check if the + * user is on the ban list. If the user is on the ban list it will unban the user. * * @param event the corresponding event */ @@ -79,7 +80,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("Something went wrong, check the logs or contact a staff/moderator") .queue(); - logger.error("Something went wrong in the unban command: %d", throwable); + logger.error("Something went wrong during the process of unbanning the user ", + throwable); } }); } From 9bdee00277af1740dd0bc2b4afdca58b44599114 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 25 Oct 2021 13:33:25 +0100 Subject: [PATCH 119/182] FIxed my sentences --- .../tjbot/commands/moderation/BanCommand.java | 12 ++++++------ .../tjbot/commands/moderation/KickCommand.java | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c5e814f06d..e71801edc8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -17,7 +17,7 @@ /** * This command can ban users and optionally remove their messages from the past days. Banning can - * also be paired with a ban reason. The command will also try to DM the user to inform him about + * also be paired with a ban reason. The command will also try to DM the user to inform them about * the action and the reason. *

* The command fails if the user triggering it is lacking permissions to either ban other users or @@ -107,13 +107,13 @@ private static void banUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the ban is: %s - """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the ban is: %s + """ .formatted(guildName, reason))) .queue(null, - throwable -> logger.error( + throwable -> logger.info( "I could not dm the user '{}' to inform them that they were banned.", userId)); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index fe166f111b..528f0e397e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -14,7 +14,7 @@ /** * This command can kicks users. Kicking can also be paired with a kick reason. The command will - * also try to DM the user to inform him about the action and the reason. + * also try to DM the user to inform them about the action and the reason. *

* The command fails if the user triggering it is lacking permissions to either kick other users or * to kick the specific given user (for example a moderator attempting to kick an admin). @@ -29,7 +29,7 @@ public final class KickCommand extends SlashCommandAdapter { * Creates an instance of the kick command. */ public KickCommand() { - super("kick", "Kicks the given user from the user", SlashCommandVisibility.GUILD); + super("kick", "Kicks the given user from the server", SlashCommandVisibility.GUILD); getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to kick", true) .addOption(OptionType.STRING, REASON_OPTION, "Why the user should be kicked", true); @@ -86,13 +86,13 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the kick is: %s - """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + he reason for the kick is: %s + """ .formatted(guildName, reason))) .queue(null, - throwable -> logger.error( + throwable -> logger.info( "I could not dm the user '{}' to inform them that they were kicked.", userId)); From dbed14b4b5accc484d3441576db173d8f460c208 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 25 Oct 2021 14:40:13 +0100 Subject: [PATCH 120/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index e71801edc8..c7ae32023a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -77,7 +77,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - event.getGuild().getId()); + Objects.requireNonNull(event.getGuild())); return; } if (!bot.canInteract(Objects.requireNonNull(user))) { From 0c9deec7373420f760f818d8b0574cf83a7ac74c Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Mon, 25 Oct 2021 16:41:20 +0100 Subject: [PATCH 121/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5b2d45841d..1d366a1a25 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -47,7 +47,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") + "You can not unban users in this guild since you do not have the BAN_MEMBERS permission.") .setEphemeral(true) .queue(); return; From 0281c36f11a98f26ee509a97d1a7b3ab65a5064d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 25 Oct 2021 17:07:43 +0100 Subject: [PATCH 122/182] Fixed everything --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 528f0e397e..02015d2659 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -65,7 +65,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - event.getGuild().getId()); + Objects.requireNonNull(event.getGuild())); return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5b2d45841d..fdca213868 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -77,7 +77,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { event.reply("the specified user doesn't exist").queue(); logger.debug("The user '{}' does not exist", userId); } else { - event.reply("Something went wrong, check the logs or contact a staff/moderator") + event.reply("Something went wrong, check the logs or contact a staff member") .queue(); logger.error("Something went wrong during the process of unbanning the user ", From 8ae535489fd92300c7e5e8a65309531ad988877e Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 25 Oct 2021 18:21:50 +0100 Subject: [PATCH 123/182] spotlessApply --- .../tjbot/commands/moderation/BanCommand.java | 8 ++++---- .../tjbot/commands/moderation/KickCommand.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c7ae32023a..5d2b045f69 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -107,10 +107,10 @@ private static void banUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the ban is: %s - """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the ban is: %s + """ .formatted(guildName, reason))) .queue(null, throwable -> logger.info( diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 02015d2659..94b74a7b22 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -86,10 +86,10 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - he reason for the kick is: %s - """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + he reason for the kick is: %s + """ .formatted(guildName, reason))) .queue(null, throwable -> logger.info( From 8bcd8825a487564b2100c26ec8246976c9401002 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 25 Oct 2021 20:45:03 +0100 Subject: [PATCH 124/182] please fix spotlessApply --- .../tjbot/commands/moderation/BanCommand.java | 8 ++++---- .../tjbot/commands/moderation/KickCommand.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 5d2b045f69..c7ae32023a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -107,10 +107,10 @@ private static void banUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the ban is: %s - """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the ban is: %s + """ .formatted(guildName, reason))) .queue(null, throwable -> logger.info( diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 94b74a7b22..02015d2659 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -86,10 +86,10 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - he reason for the kick is: %s - """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + he reason for the kick is: %s + """ .formatted(guildName, reason))) .queue(null, throwable -> logger.info( From a35e1aa28d229a9c309a93de72e365b3bc1dbf19 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Mon, 25 Oct 2021 20:46:34 +0100 Subject: [PATCH 125/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c7ae32023a..ded7375ee5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -64,7 +64,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { long userid = user.getIdLong(); if (!author.canInteract(user)) { - event.reply("The user" + userid + " is too powerful for you to ban.") + event.reply("The user " + userid + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return; From 57a190cd32cbf9f9178e7130d8dba17d34346691 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 25 Oct 2021 20:48:32 +0100 Subject: [PATCH 126/182] spotlessApply --- .../tjbot/commands/moderation/BanCommand.java | 8 ++++---- .../tjbot/commands/moderation/KickCommand.java | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index c7ae32023a..5d2b045f69 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -107,10 +107,10 @@ private static void banUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - The reason for the ban is: %s - """ + Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + The reason for the ban is: %s + """ .formatted(guildName, reason))) .queue(null, throwable -> logger.info( diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 02015d2659..94b74a7b22 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -86,10 +86,10 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. - he reason for the kick is: %s - """ + Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. + If you think this was a mistake, please contact a moderator or admin of the guild. + he reason for the kick is: %s + """ .formatted(guildName, reason))) .queue(null, throwable -> logger.info( From 202eb61fe28943e5f2c160c7af0d6aef138bbb09 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Mon, 25 Oct 2021 21:06:33 +0100 Subject: [PATCH 127/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Jonas --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 4f9c52b761..a1581b1a76 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -62,7 +62,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - long userid = user.getIdLong(); + long userId = user.getIdLong(); if (!author.canInteract(user)) { event.reply("The user " + userid + " is too powerful for you to ban.") .setEphemeral(true) From 06a792354e8d17a54478ef6f002e08ae1a9df231 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Mon, 25 Oct 2021 21:06:43 +0100 Subject: [PATCH 128/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Jonas --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index a1581b1a76..5df11fce61 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -95,7 +95,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(user, author, reason, days, userid, author.getIdLong(), event); + banUser(user, author, reason, days, userId, author.getIdLong(), event); } private static void banUser(@NotNull Member member, @NotNull Member author, From cf415ba5cd890be11e483bf0b3170d9043ff0be7 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Mon, 25 Oct 2021 21:07:21 +0100 Subject: [PATCH 129/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Jonas --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 5df11fce61..0537a9c303 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -64,7 +64,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { long userId = user.getIdLong(); if (!author.canInteract(user)) { - event.reply("The user " + userid + " is too powerful for you to ban.") + event.reply("The user " + userId + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return; From fe03facb766f43349d433337f350d651e1c2fa7b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 14:42:02 +0100 Subject: [PATCH 130/182] fixed the dm bug --- .../tjbot/commands/moderation/BanCommand.java | 13 ++++--------- .../tjbot/commands/moderation/KickCommand.java | 13 ++++--------- 2 files changed, 8 insertions(+), 18 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 0537a9c303..ed5f101350 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -107,18 +107,13 @@ private static void banUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been banned from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. + Hey there, sorry to tell you but unfortunately you have been banned from the server %s. + If you think this was a mistake, please contact a moderator or admin of the server. The reason for the ban is: %s """ .formatted(guildName, reason))) - .queue(null, - throwable -> logger.info( - "I could not dm the user '{}' to inform them that they were banned.", - userId)); - - event.getGuild() - .ban(member, days, reason) + .mapToResult() + .flatMap(result -> event.getGuild().ban(member, days, reason)) .flatMap(v -> event.reply(member.getUser().getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 94b74a7b22..956b2ee93f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -86,18 +86,13 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, .openPrivateChannelById(userId) .flatMap(channel -> channel.sendMessage( """ - Hey there, sorry to tell you but unfortunately you have been kicked from the guild %s. - If you think this was a mistake, please contact a moderator or admin of the guild. + Hey there, sorry to tell you but unfortunately you have been kicked from the server %s. + If you think this was a mistake, please contact a moderator or admin of the server. he reason for the kick is: %s """ .formatted(guildName, reason))) - .queue(null, - throwable -> logger.info( - "I could not dm the user '{}' to inform them that they were kicked.", - userId)); - - event.getGuild() - .kick(member, reason) + .mapToResult() + .flatMap(result -> event.getGuild().kick(member, reason)) .flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); From 6c02458f6f3768615d181a7e3ec97e29e094dce5 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 14:56:52 +0100 Subject: [PATCH 131/182] fixed some more issues --- .../tjbot/commands/moderation/BanCommand.java | 8 ++++---- .../tjbot/commands/moderation/KickCommand.java | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index ed5f101350..6827da3444 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -62,9 +62,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - long userId = user.getIdLong(); + String userTag = user.getUser().getAsTag(); if (!author.canInteract(user)) { - event.reply("The user " + userId + " is too powerful for you to ban.") + event.reply("The user " + userTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return; @@ -81,7 +81,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + user.getUser().getAsTag() + "is too powerful for me to ban.") + event.reply("The user" + userTag + "is too powerful for me to ban.") .setEphemeral(true) .queue(); return; @@ -95,7 +95,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(user, author, reason, days, userId, author.getIdLong(), event); + banUser(user, author, reason, days, user.getIdLong(), author.getIdLong(), event); } private static void banUser(@NotNull Member member, @NotNull Member author, diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 956b2ee93f..9cb74be413 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -50,9 +50,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - long userid = user.getIdLong(); + String userTag = user.getUser().getAsTag(); if (!author.canInteract(user)) { - event.reply("The user" + userid + "is too powerful for you to kick.") + event.reply("The user" + userTag + "is too powerful for you to kick.") .setEphemeral(true) .queue(); return; @@ -65,18 +65,18 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild())); + Objects.requireNonNull(event.getGuild().getId())); return; } if (!bot.canInteract(user)) { - event.reply("The user " + user + " is too powerful for me to kick.") + event.reply("The user " + userTag + " is too powerful for me to kick.") .setEphemeral(true) .queue(); return; } - kickUser(user, author, reason, userid, event); + kickUser(user, author, reason, user.getIdLong(), event); } public static void kickUser(@NotNull Member member, @NotNull Member author, From bf2e6510ed68bc32099b62f092ae7d548b54fb79 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 14:57:40 +0100 Subject: [PATCH 132/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 6827da3444..0608a22d90 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -81,7 +81,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user" + userTag + "is too powerful for me to ban.") + event.reply("The user " + userTag + "is too powerful for me to ban.") .setEphemeral(true) .queue(); return; From dd842ad2e3fb7d1841dd30cb064a56b32302efca Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 14:57:52 +0100 Subject: [PATCH 133/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 9cb74be413..4137f9d610 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -52,7 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String userTag = user.getUser().getAsTag(); if (!author.canInteract(user)) { - event.reply("The user" + userTag + "is too powerful for you to kick.") + event.reply("The user " + userTag + "is too powerful for you to kick.") .setEphemeral(true) .queue(); return; From 71cb4474523b31b1c26c21bcfd3ca380885bfc67 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 14:57:59 +0100 Subject: [PATCH 134/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 4137f9d610..3c5ed1a5dd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -52,7 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String userTag = user.getUser().getAsTag(); if (!author.canInteract(user)) { - event.reply("The user " + userTag + "is too powerful for you to kick.") + event.reply("The user " + userTag + " is too powerful for you to kick.") .setEphemeral(true) .queue(); return; From 08bbc23d1eb8df49ebdf15006fd30700d13af45f Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 14:58:07 +0100 Subject: [PATCH 135/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 0608a22d90..92388f5164 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -81,7 +81,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } if (!bot.canInteract(Objects.requireNonNull(user))) { - event.reply("The user " + userTag + "is too powerful for me to ban.") + event.reply("The user " + userTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); return; From ec722c470623ec5dbd8c7299b065df6ed9fc0bff Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 17:49:40 +0100 Subject: [PATCH 136/182] fixed an issue which cause gradle build to fail --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 92388f5164..b974914f5a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -77,7 +77,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild())); + Objects.requireNonNull(event.getGuild()).getName()); return; } if (!bot.canInteract(Objects.requireNonNull(user))) { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 3c5ed1a5dd..b9d321fb5d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -65,7 +65,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild().getId())); + Objects.requireNonNull(event.getGuild()).getName()); return; } From 0399339184482ed16547a91cb1c3fe6885e4c8ad Mon Sep 17 00:00:00 2001 From: Yusuf Date: Tue, 26 Oct 2021 19:44:04 +0100 Subject: [PATCH 137/182] hopefully fixed everything. --- .../tjbot/commands/moderation/BanCommand.java | 7 +-- .../commands/moderation/KickCommand.java | 4 +- .../commands/moderation/UnbanCommand.java | 43 ++++++++++--------- .../commands/moderation/package-info.java | 3 +- 4 files changed, 30 insertions(+), 27 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index b974914f5a..899452aca5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -90,8 +90,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { int days = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); - if (reason.length() > BanCommand.REASON_MAX_LENGTH) { - event.reply("The reason can not be over 512 characters").setEphemeral(true).queue(); + if (reason.length() > REASON_MAX_LENGTH) { + event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") + .setEphemeral(true) + .queue(); return; } @@ -101,7 +103,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { private static void banUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, int days, long userId, long authorId, @NotNull SlashCommandEvent event) { - String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index b9d321fb5d..e4a25577e4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -79,7 +79,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { kickUser(user, author, reason, user.getIdLong(), event); } - public static void kickUser(@NotNull Member member, @NotNull Member author, + private static void kickUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() @@ -88,7 +88,7 @@ public static void kickUser(@NotNull Member member, @NotNull Member author, """ Hey there, sorry to tell you but unfortunately you have been kicked from the server %s. If you think this was a mistake, please contact a moderator or admin of the server. - he reason for the kick is: %s + The reason for the kick is: %s """ .formatted(guildName, reason))) .mapToResult() diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 35ec755e32..2dd3e8a65c 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.exceptions.ErrorResponseException; @@ -15,37 +16,32 @@ import java.util.Objects; /** - * This command can unban users. + * This command can unban users. This command requires the user to input the id of the user they + * want to unban. *

- * The command fails if the user triggering it is lacking permissions to either unban other users. + * The command fails if the user is not banned or the incorrect id was inputted. */ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); private static final String USER_ID = "user_id"; /** - * Creates an instance of the ban command. + * Creates an instance of the unban command. */ public UnbanCommand() { super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.STRING, USER_ID, - "The user id of the user which you want to unban", true); + getData().addOption(OptionType.STRING, USER_ID, "The id of the user who you want to unban", + true); } - /** - * When triggered with {@code /unban user_id}}, the bot will respond will check if the user has - * perms. Then it will check if itself has perms to unban. If it does then it will check if the - * user is on the ban list. If the user is on the ban list it will unban the user. - * - * @param event the corresponding event - */ @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - final String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); + String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); + Member author = Objects.requireNonNull(event.getMember()); - if (!Objects.requireNonNull(event.getMember()).hasPermission(Permission.BAN_MEMBERS)) { + if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "You can not unban users in this guild since you do not have the BAN_MEMBERS permission.") .setEphemeral(true) @@ -53,8 +49,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!(Objects.requireNonNull(event.getGuild())).getSelfMember() - .hasPermission(Permission.BAN_MEMBERS)) { + Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") .setEphemeral(true) @@ -66,21 +62,26 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } event.getGuild().unban(userId).queue(v -> { - event.reply("Unbanned the user").queue(); User user = event.getUser(); + event + .reply("The user " + author.getUser().getAsTag() + " unbanned the user " + + user.getAsTag()) + .queue(); logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag(), user.getIdLong(), userId); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { - event.reply("the specified user doesn't exist").queue(); - logger.debug("The user '{}' does not exist", userId); + event.reply("The specified user doesn't exist").queue(); + logger.debug("I could not unban the user '{}' because they do not exist", userId); } else { - event.reply("Something went wrong, check the logs or contact a staff member") + event.reply( + "Sorry, but something went wrong, please check the logs or contact a staff member") + .setEphemeral(true) .queue(); - logger.error("Something went wrong during the process of unbanning the user ", + logger.warn("Something went wrong during the process of unbanning the user ", throwable); } }); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java index 7971cce2ff..399fc1fa1f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/package-info.java @@ -1,4 +1,5 @@ /** - * This package offers all the moderation commands in the application. + * This package offers all the moderation commands from the application such as banning and kicking + * users. */ package org.togetherjava.tjbot.commands.moderation; From 78de5451b78c75a3550abf748f3e0f83a45709e2 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 11:53:12 +0100 Subject: [PATCH 138/182] Improved Unban And Ban Command --- .../tjbot/commands/moderation/BanCommand.java | 30 ++++++------ .../commands/moderation/KickCommand.java | 23 +++++---- .../commands/moderation/UnbanCommand.java | 47 +++++++++---------- 3 files changed, 53 insertions(+), 47 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 899452aca5..adc00a48b1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -49,12 +49,13 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); - Member author = Objects.requireNonNull(event.getMember()); - String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + Member member = event.getOption(USER_OPTION).getAsMember(); + Member author = event.getMember(); + String reason = event.getOption(REASON_OPTION).getAsString(); + Member bot = event.getGuild().getSelfMember(); + User user = event.getOption(USER_OPTION).getAsUser(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { + if (author != null && !author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") .setEphemeral(true) @@ -62,8 +63,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = user.getUser().getAsTag(); - if (!author.canInteract(user)) { + String userTag = user.getAsTag(); + if (member != null && author != null && !author.canInteract(member)) { event.reply("The user " + userTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); @@ -80,7 +81,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Objects.requireNonNull(event.getGuild()).getName()); return; } - if (!bot.canInteract(Objects.requireNonNull(user))) { + if (member != null && !bot.canInteract(member)) { event.reply("The user " + userTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); @@ -97,12 +98,13 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(user, author, reason, days, user.getIdLong(), author.getIdLong(), event); + if (author != null) { + banUser(user, author, reason, days, user.getIdLong(), author.getIdLong(), event); + } } - private static void banUser(@NotNull Member member, @NotNull Member author, - @NotNull String reason, int days, long userId, long authorId, - @NotNull SlashCommandEvent event) { + private static void banUser(User user, Member author, @NotNull String reason, int days, + long userId, long authorId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) @@ -114,8 +116,8 @@ private static void banUser(@NotNull Member member, @NotNull Member author, """ .formatted(guildName, reason))) .mapToResult() - .flatMap(result -> event.getGuild().ban(member, days, reason)) - .flatMap(v -> event.reply(member.getUser().getAsTag() + " was banned by " + .flatMap(result -> event.getGuild().ban(user, days, reason)) + .flatMap(v -> event.reply(user.getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index e4a25577e4..73bb231205 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -37,12 +37,12 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member user = Objects.requireNonNull(event.getOption(USER_OPTION)).getAsMember(); - Member author = Objects.requireNonNull(event.getMember()); - String reason = Objects.requireNonNull(event.getOption(REASON_OPTION)).getAsString(); - Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + Member user = event.getOption(USER_OPTION).getAsMember(); + Member author = event.getMember(); + String reason = event.getOption(REASON_OPTION).getAsString(); + Member bot = event.getGuild().getSelfMember(); - if (!author.hasPermission(Permission.KICK_MEMBERS)) { + if (author != null && !author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( "You can not kick users in this guild since you do not have the KICK_MEMBERS permission.") .setEphemeral(true) @@ -50,8 +50,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = user.getUser().getAsTag(); - if (!author.canInteract(user)) { + String userTag = null; + if (user != null) { + userTag = user.getUser().getAsTag(); + } + if (user != null && author != null && !author.canInteract(user)) { event.reply("The user " + userTag + " is too powerful for you to kick.") .setEphemeral(true) .queue(); @@ -69,14 +72,16 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!bot.canInteract(user)) { + if (user != null && !bot.canInteract(user)) { event.reply("The user " + userTag + " is too powerful for me to kick.") .setEphemeral(true) .queue(); return; } - kickUser(user, author, reason, user.getIdLong(), event); + if (author != null && user != null) { + kickUser(user, author, reason, user.getIdLong(), event); + } } private static void kickUser(@NotNull Member member, @NotNull Member author, diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 2dd3e8a65c..83e0d0bcbc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -19,11 +19,12 @@ * This command can unban users. This command requires the user to input the id of the user they * want to unban. *

- * The command fails if the user is not banned or the incorrect id was inputted. + * The command fails if the user is not banned or the incorrect id was input. */ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); - private static final String USER_ID = "user_id"; + private static final String USER = "user"; + private static final String REASON = "reason"; /** * Creates an instance of the unban command. @@ -31,25 +32,24 @@ public final class UnbanCommand extends SlashCommandAdapter { public UnbanCommand() { super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.STRING, USER_ID, "The id of the user who you want to unban", - true); - + getData().addOption(OptionType.USER, USER, "The user who you want to unban", true) + .addOption(OptionType.STRING, REASON, "Why the user should be unbanned", true); } @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - String userId = Objects.requireNonNull(event.getOption(USER_ID)).getAsString(); - Member author = Objects.requireNonNull(event.getMember()); + User user = event.getOption(USER).getAsUser(); + Member author = event.getMember(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { + if (author != null && !author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "You can not unban users in this guild since you do not have the BAN_MEMBERS permission.") - .setEphemeral(true) - .queue(); + "You can not unban users in this guild since you do not have the BAN_MEMBERS permission.") + .setEphemeral(true) + .queue(); return; } - Member bot = Objects.requireNonNull(event.getGuild()).getSelfMember(); + Member bot = event.getGuild().getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") @@ -57,29 +57,28 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - event.getGuild().getId()); + Objects.requireNonNull(event.getGuild()).getName()); return; } - event.getGuild().unban(userId).queue(v -> { - User user = event.getUser(); + String reason = event.getOption(REASON).getAsString(); + event.getGuild().unban(user).queue(v -> { event .reply("The user " + author.getUser().getAsTag() + " unbanned the user " - + user.getAsTag()) + + user.getAsTag() + " for: " + reason) .queue(); - logger.info(" {} ({}) unbanned user id '{}' ", user.getAsTag(), user.getIdLong(), - userId); + logger.info(" {} ({}) unbanned the user '{}' for: '{}'", author.getUser().getAsTag(), + author.getIdLong(), user.getAsTag(), reason); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { - event.reply("The specified user doesn't exist").queue(); - logger.debug("I could not unban the user '{}' because they do not exist", userId); + event.reply("The specified user doesn't exist").setEphemeral(true).queue(); + + logger.debug("I could not unban the user '{}' because they do not exist", + user.getAsTag()); } else { - event.reply( - "Sorry, but something went wrong, please check the logs or contact a staff member") - .setEphemeral(true) - .queue(); + event.reply("Sorry, but something went wrong.").setEphemeral(true).queue(); logger.warn("Something went wrong during the process of unbanning the user ", throwable); From 79cbca197c3d1309370732208e11595328afe604 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Wed, 27 Oct 2021 14:17:04 +0100 Subject: [PATCH 139/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index adc00a48b1..7da1e18a70 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -50,7 +50,7 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member member = event.getOption(USER_OPTION).getAsMember(); - Member author = event.getMember(); + Member author = Objects.requireNonNull(event.getMember(), "Member is null); String reason = event.getOption(REASON_OPTION).getAsString(); Member bot = event.getGuild().getSelfMember(); User user = event.getOption(USER_OPTION).getAsUser(); From 6076a0fc08146cd759140a3fe6ead0e1dd19397d Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Wed, 27 Oct 2021 14:17:16 +0100 Subject: [PATCH 140/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 73bb231205..7b3d389d9e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -38,7 +38,7 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member user = event.getOption(USER_OPTION).getAsMember(); - Member author = event.getMember(); + Member author = Objects.requireNonNull(event.getMember(), "Member is null); String reason = event.getOption(REASON_OPTION).getAsString(); Member bot = event.getGuild().getSelfMember(); From aba48bbd94b0748e01eac80a86c41478b999a555 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Wed, 27 Oct 2021 14:17:25 +0100 Subject: [PATCH 141/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 83e0d0bcbc..969d4a51bf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -39,7 +39,7 @@ public UnbanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { User user = event.getOption(USER).getAsUser(); - Member author = event.getMember(); + Member author = Objects.requireNonNull(event.getMember(), "Member is null); if (author != null && !author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( From 3a4fdff485ebbd693a2eca4cd5c519ddf145d18b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 14:39:55 +0100 Subject: [PATCH 142/182] Fixed everything and I fixed the Objects.requireNonNull --- .../tjbot/commands/moderation/BanCommand.java | 27 +++++++++-------- .../commands/moderation/KickCommand.java | 27 ++++++++--------- .../commands/moderation/UnbanCommand.java | 30 ++++++++++--------- 3 files changed, 43 insertions(+), 41 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 7da1e18a70..17a54dbf50 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -49,13 +49,16 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member member = event.getOption(USER_OPTION).getAsMember(); - Member author = Objects.requireNonNull(event.getMember(), "Member is null); - String reason = event.getOption(REASON_OPTION).getAsString(); - Member bot = event.getGuild().getSelfMember(); - User user = event.getOption(USER_OPTION).getAsUser(); + Member member = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + .getAsMember(); + Member author = Objects.requireNonNull(event.getMember(), "Author is null"); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") + .getAsString(); + Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); + User user = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") + .getAsUser(); - if (author != null && !author.hasPermission(Permission.BAN_MEMBERS)) { + if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") .setEphemeral(true) @@ -64,7 +67,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } String userTag = user.getAsTag(); - if (member != null && author != null && !author.canInteract(member)) { + if (!author.canInteract(member)) { event.reply("The user " + userTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); @@ -81,7 +84,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Objects.requireNonNull(event.getGuild()).getName()); return; } - if (member != null && !bot.canInteract(member)) { + if (!bot.canInteract(member)) { event.reply("The user " + userTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); @@ -98,13 +101,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (author != null) { - banUser(user, author, reason, days, user.getIdLong(), author.getIdLong(), event); - } + banUser(user, author, reason, days, user.getIdLong(), author.getIdLong(), event); } - private static void banUser(User user, Member author, @NotNull String reason, int days, - long userId, long authorId, @NotNull SlashCommandEvent event) { + private static void banUser(@NotNull User user, @NotNull Member author, @NotNull String reason, + int days, long userId, long authorId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 7b3d389d9e..b607d58170 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -2,6 +2,7 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Member; +import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; @@ -37,12 +38,15 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member user = event.getOption(USER_OPTION).getAsMember(); - Member author = Objects.requireNonNull(event.getMember(), "Member is null); - String reason = event.getOption(REASON_OPTION).getAsString(); - Member bot = event.getGuild().getSelfMember(); + Member member = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + .getAsMember(); + Member author = Objects.requireNonNull(event.getMember(), "Author is null"); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") + .getAsString(); + Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); + User user = event.getUser(); - if (author != null && !author.hasPermission(Permission.KICK_MEMBERS)) { + if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( "You can not kick users in this guild since you do not have the KICK_MEMBERS permission.") .setEphemeral(true) @@ -50,11 +54,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = null; - if (user != null) { - userTag = user.getUser().getAsTag(); - } - if (user != null && author != null && !author.canInteract(user)) { + String userTag = user.getAsTag(); + if (!author.canInteract(member)) { event.reply("The user " + userTag + " is too powerful for you to kick.") .setEphemeral(true) .queue(); @@ -72,16 +73,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (user != null && !bot.canInteract(user)) { + if (!bot.canInteract(member)) { event.reply("The user " + userTag + " is too powerful for me to kick.") .setEphemeral(true) .queue(); return; } - if (author != null && user != null) { - kickUser(user, author, reason, user.getIdLong(), event); - } + kickUser(member, author, reason, user.getIdLong(), event); } private static void kickUser(@NotNull Member member, @NotNull Member author, diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 969d4a51bf..231c00595d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -19,12 +19,12 @@ * This command can unban users. This command requires the user to input the id of the user they * want to unban. *

- * The command fails if the user is not banned or the incorrect id was input. + * The command fails if the user is not banned or the given user/user id/user tag was invalid. */ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); - private static final String USER = "user"; - private static final String REASON = "reason"; + private static final String USER_OPTION = "user"; + private static final String REASON_OPTION = "reason"; /** * Creates an instance of the unban command. @@ -32,24 +32,25 @@ public final class UnbanCommand extends SlashCommandAdapter { public UnbanCommand() { super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); - getData().addOption(OptionType.USER, USER, "The user who you want to unban", true) - .addOption(OptionType.STRING, REASON, "Why the user should be unbanned", true); + getData().addOption(OptionType.USER, USER_OPTION, "The user who you want to unban", true) + .addOption(OptionType.STRING, REASON_OPTION, "Why the user should be unbanned", true); } @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - User user = event.getOption(USER).getAsUser(); - Member author = Objects.requireNonNull(event.getMember(), "Member is null); + User user = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") + .getAsUser(); + Member author = Objects.requireNonNull(event.getMember(), "The member is null"); - if (author != null && !author.hasPermission(Permission.BAN_MEMBERS)) { + if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( - "You can not unban users in this guild since you do not have the BAN_MEMBERS permission.") - .setEphemeral(true) - .queue(); + "You can not unban users in this guild since you do not have the BAN_MEMBERS permission.") + .setEphemeral(true) + .queue(); return; } - Member bot = event.getGuild().getSelfMember(); + Member bot = Objects.requireNonNull(event.getGuild(), "The Bot is null").getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") @@ -61,8 +62,9 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String reason = event.getOption(REASON).getAsString(); - event.getGuild().unban(user).queue(v -> { + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") + .getAsString(); + event.getGuild().unban(user).reason(reason).queue(v -> { event .reply("The user " + author.getUser().getAsTag() + " unbanned the user " + user.getAsTag() + " for: " + reason) From d29e57e86fa8729e579b3253f6bde51a0102d3f3 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 14:55:06 +0100 Subject: [PATCH 143/182] Update UnbanCommand.java --- .../tjbot/commands/moderation/UnbanCommand.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 231c00595d..ba9d30cc6f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -16,10 +16,8 @@ import java.util.Objects; /** - * This command can unban users. This command requires the user to input the id of the user they - * want to unban. - *

- * The command fails if the user is not banned or the given user/user id/user tag was invalid. + * This command unban users. Unbanning can also be paired with a reason for the unban. + *

*/ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); From 5d8018f05c355191085ef8c13ee14bc63366fa4c Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 14:57:12 +0100 Subject: [PATCH 144/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index ba9d30cc6f..5064c9a5c7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -16,8 +16,9 @@ import java.util.Objects; /** - * This command unban users. Unbanning can also be paired with a reason for the unban. - *

+ * This command unban users. The unban command requires the user to input the user/user id/user tag. + * It can also be paired with a reason for the unban. + *

*/ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); From 02d6d84a6e400270b6d2e8d4e2e7b9b44af219c7 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 15:00:28 +0100 Subject: [PATCH 145/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5064c9a5c7..2517123934 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -16,8 +16,8 @@ import java.util.Objects; /** - * This command unban users. The unban command requires the user to input the user/user id/user tag. - * It can also be paired with a reason for the unban. + * This command allows you to unban a user. The unban command requires the user to input the + * user/user id/user tag. It can also be paired with a reason for the unban. *

*/ public final class UnbanCommand extends SlashCommandAdapter { From d78895b40fb43fd9b1d7ac2c04f537be5edd8901 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 15:00:42 +0100 Subject: [PATCH 146/182] Revert "Update UnbanCommand.java" This reverts commit 02d6d84a6e400270b6d2e8d4e2e7b9b44af219c7. --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 2517123934..5064c9a5c7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -16,8 +16,8 @@ import java.util.Objects; /** - * This command allows you to unban a user. The unban command requires the user to input the - * user/user id/user tag. It can also be paired with a reason for the unban. + * This command unban users. The unban command requires the user to input the user/user id/user tag. + * It can also be paired with a reason for the unban. *

*/ public final class UnbanCommand extends SlashCommandAdapter { From a4231f103dc98f5485ab46ed40c980d956003b12 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 15:01:19 +0100 Subject: [PATCH 147/182] Fixed the sentence --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5064c9a5c7..2517123934 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -16,8 +16,8 @@ import java.util.Objects; /** - * This command unban users. The unban command requires the user to input the user/user id/user tag. - * It can also be paired with a reason for the unban. + * This command allows you to unban a user. The unban command requires the user to input the + * user/user id/user tag. It can also be paired with a reason for the unban. *

*/ public final class UnbanCommand extends SlashCommandAdapter { From e78cc7f4a38a70dedc428caedeccb0977703ca5d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 15:03:35 +0100 Subject: [PATCH 148/182] Update UnbanCommand.java --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 2517123934..51eb31a581 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -17,7 +17,8 @@ /** * This command allows you to unban a user. The unban command requires the user to input the - * user/user id/user tag. It can also be paired with a reason for the unban. + * user/user id/user tag. Unbanning can also be paired with a reason for unbanning the user. + * The command will fail if the user is not on the ban list. *

*/ public final class UnbanCommand extends SlashCommandAdapter { From f868b1153be810422668ab84a447ff39c07ab530 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 19:16:27 +0100 Subject: [PATCH 149/182] Added reason for kick command --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index b607d58170..76d7addf35 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -96,7 +96,7 @@ private static void kickUser(@NotNull Member member, @NotNull Member author, """ .formatted(guildName, reason))) .mapToResult() - .flatMap(result -> event.getGuild().kick(member, reason)) + .flatMap(result -> event.getGuild().kick(member, reason).reason(reason)) .flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); From 6b8e1d4880100fa38987195c82662a257590c47d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 19:21:29 +0100 Subject: [PATCH 150/182] improved the logger --- .../tjbot/commands/moderation/BanCommand.java | 9 +++++---- .../tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 17a54dbf50..d21a8e3658 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -105,7 +105,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } private static void banUser(@NotNull User user, @NotNull Member author, @NotNull String reason, - int days, long userId, long authorId, @NotNull SlashCommandEvent event) { + int delDays, long userId, long authorId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) @@ -117,13 +117,14 @@ private static void banUser(@NotNull User user, @NotNull Member author, @NotNull """ .formatted(guildName, reason))) .mapToResult() - .flatMap(result -> event.getGuild().ban(user, days, reason)) + .flatMap(result -> event.getGuild().ban(user, delDays, reason)) .flatMap(v -> event.reply(user.getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info( - " '{}' banned the user '{}' and deleted their message history of the last '{}' days. Reason was '{}'", - authorId, userId, days, reason); + " '{} ({})' banned the user '{} ({})' and deleted their message history of the last '{}' days. Reason being'{}'", + author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), delDays, userId, + reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 51eb31a581..a4330104e3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -17,8 +17,8 @@ /** * This command allows you to unban a user. The unban command requires the user to input the - * user/user id/user tag. Unbanning can also be paired with a reason for unbanning the user. - * The command will fail if the user is not on the ban list. + * user/user id/user tag. Unbanning can also be paired with a reason for unbanning the user. The + * command will fail if the user is not on the ban list. *

*/ public final class UnbanCommand extends SlashCommandAdapter { From 7bcb663eefbfbce5362b280d192b9f058608c7db Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 19:22:40 +0100 Subject: [PATCH 151/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index d21a8e3658..8e89f663ef 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -124,7 +124,7 @@ private static void banUser(@NotNull User user, @NotNull Member author, @NotNull logger.info( " '{} ({})' banned the user '{} ({})' and deleted their message history of the last '{}' days. Reason being'{}'", - author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), delDays, userId, + author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), userId, delDays, reason); } } From c4e534b6db73c997e97f369b533c483332067d80 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 21:53:03 +0100 Subject: [PATCH 152/182] Update BanCommand.java --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 8e89f663ef..ff6e20ec2a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -105,7 +105,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } private static void banUser(@NotNull User user, @NotNull Member author, @NotNull String reason, - int delDays, long userId, long authorId, @NotNull SlashCommandEvent event) { + int delDays, long authorId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) From a769472225543cf8da59159a1d582adb83fc989e Mon Sep 17 00:00:00 2001 From: Yusuf Date: Wed, 27 Oct 2021 21:54:21 +0100 Subject: [PATCH 153/182] Update BanCommand.java --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index ff6e20ec2a..1d6d8f572d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -101,11 +101,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(user, author, reason, days, user.getIdLong(), author.getIdLong(), event); + banUser(user, author, reason, days, user.getIdLong(), event); } private static void banUser(@NotNull User user, @NotNull Member author, @NotNull String reason, - int delDays, long authorId, @NotNull SlashCommandEvent event) { + int delDays, long userId, @NotNull SlashCommandEvent event) { String guildName = event.getGuild().getName(); event.getJDA() .openPrivateChannelById(userId) From 05aaf96be1466b00f8e1284641bdd727e13e3cdb Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 28 Oct 2021 10:17:44 +0100 Subject: [PATCH 154/182] All checks pass + fixed everything I was told to fix. --- .../tjbot/commands/moderation/BanCommand.java | 30 +++++++------- .../commands/moderation/KickCommand.java | 39 ++++++++++++------- .../commands/moderation/UnbanCommand.java | 28 ++++++++++--- 3 files changed, 64 insertions(+), 33 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 1d6d8f572d..765c99e45b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -49,14 +49,12 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member member = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") - .getAsMember(); + User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + .getAsUser(); Member author = Objects.requireNonNull(event.getMember(), "Author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); - User user = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") - .getAsUser(); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( @@ -66,14 +64,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = user.getAsTag(); - if (!author.canInteract(member)) { + String userTag = targetUser.getAsTag(); + if (!author.canInteract(event.getMember())) { event.reply("The user " + userTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return; } + Guild guild = event.getGuild(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not ban users in this guild since I do not have the BAN_MEMBERS permission.") @@ -81,10 +80,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild()).getName()); + Objects.requireNonNull(guild).getName()); return; } - if (!bot.canInteract(member)) { + + if (!bot.canInteract(event.getMember())) { event.reply("The user " + userTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); @@ -101,14 +101,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(user, author, reason, days, user.getIdLong(), event); + banUser(targetUser, author, reason, days, guild, event); } private static void banUser(@NotNull User user, @NotNull Member author, @NotNull String reason, - int delDays, long userId, @NotNull SlashCommandEvent event) { - String guildName = event.getGuild().getName(); + int delDays, @NotNull Guild guild, @NotNull SlashCommandEvent event) { + String guildName = guild.getName(); event.getJDA() - .openPrivateChannelById(userId) + .openPrivateChannelById(user.getIdLong()) .flatMap(channel -> channel.sendMessage( """ Hey there, sorry to tell you but unfortunately you have been banned from the server %s. @@ -117,14 +117,14 @@ private static void banUser(@NotNull User user, @NotNull Member author, @NotNull """ .formatted(guildName, reason))) .mapToResult() - .flatMap(result -> event.getGuild().ban(user, delDays, reason)) + .flatMap(result -> guild.ban(user, delDays, reason)) .flatMap(v -> event.reply(user.getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info( " '{} ({})' banned the user '{} ({})' and deleted their message history of the last '{}' days. Reason being'{}'", - author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), userId, delDays, - reason); + author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), user.getIdLong(), + delDays, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 76d7addf35..a875661091 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -25,6 +26,10 @@ public final class KickCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); private static final String USER_OPTION = "user"; private static final String REASON_OPTION = "reason"; + /** + * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. + */ + private static final Integer REASON_MAX_LENGTH = 512; /** * Creates an instance of the kick command. @@ -38,13 +43,13 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member member = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") - .getAsMember(); + Member targetMember = + Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + .getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "Author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); - User user = event.getUser(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( @@ -54,14 +59,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = user.getAsTag(); - if (!author.canInteract(member)) { + String userTag = targetMember.getUser().getAsTag(); + if (!author.canInteract(targetMember)) { event.reply("The user " + userTag + " is too powerful for you to kick.") .setEphemeral(true) .queue(); return; } + Guild guild = event.getGuild(); if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply( "I can not kick users in this guild since I do not have the KICK_MEMBERS permission.") @@ -69,25 +75,32 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild()).getName()); + Objects.requireNonNull(guild).getName()); return; } - if (!bot.canInteract(member)) { + if (!bot.canInteract(targetMember)) { event.reply("The user " + userTag + " is too powerful for me to kick.") .setEphemeral(true) .queue(); return; } - kickUser(member, author, reason, user.getIdLong(), event); + if (reason.length() > REASON_MAX_LENGTH) { + event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") + .setEphemeral(true) + .queue(); + return; + } + + kickUser(targetMember, author, reason, guild, event); } private static void kickUser(@NotNull Member member, @NotNull Member author, - @NotNull String reason, long userId, @NotNull SlashCommandEvent event) { - String guildName = event.getGuild().getName(); + @NotNull String reason, @NotNull Guild guild, @NotNull SlashCommandEvent event) { + String guildName = guild.getName(); event.getJDA() - .openPrivateChannelById(userId) + .openPrivateChannelById(member.getUser().getId()) .flatMap(channel -> channel.sendMessage( """ Hey there, sorry to tell you but unfortunately you have been kicked from the server %s. @@ -96,13 +109,13 @@ private static void kickUser(@NotNull Member member, @NotNull Member author, """ .formatted(guildName, reason))) .mapToResult() - .flatMap(result -> event.getGuild().kick(member, reason).reason(reason)) + .flatMap(result -> guild.kick(member, reason).reason(reason)) .flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), - userId, reason); + member.getUser().getId(), reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index a4330104e3..5c12c6a6fa 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -1,6 +1,7 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -16,15 +17,18 @@ import java.util.Objects; /** - * This command allows you to unban a user. The unban command requires the user to input the - * user/user id/user tag. Unbanning can also be paired with a reason for unbanning the user. The - * command will fail if the user is not on the ban list. - *

+ * This command allows you to unban a user. The unban command requires the user to input the user + * who is subject to get unbanned. Unbanning can also be paired with a reason for unbanning the + * user. The command fails if the user is currently not banned already */ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); private static final String USER_OPTION = "user"; private static final String REASON_OPTION = "reason"; + /** + * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. + */ + private static final Integer REASON_MAX_LENGTH = 512; /** * Creates an instance of the unban command. @@ -38,7 +42,7 @@ public UnbanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - User user = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") + User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") .getAsUser(); Member author = Objects.requireNonNull(event.getMember(), "The member is null"); @@ -64,11 +68,25 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); + + if (reason.length() > REASON_MAX_LENGTH) { + event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") + .setEphemeral(true) + .queue(); + return; + } + + unban(targetUser, reason, author, event); + } + + private static void unban(@NotNull User user, @NotNull String reason, @NotNull Member author, + @NotNull SlashCommandEvent event) { event.getGuild().unban(user).reason(reason).queue(v -> { event .reply("The user " + author.getUser().getAsTag() + " unbanned the user " + user.getAsTag() + " for: " + reason) .queue(); + logger.info(" {} ({}) unbanned the user '{}' for: '{}'", author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), reason); }, throwable -> { From 808028619757c7790d9b888beec1d42738ee9156 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 28 Oct 2021 17:30:53 +0100 Subject: [PATCH 155/182] Fixed everything --- .../tjbot/commands/moderation/BanCommand.java | 21 +++++--------- .../commands/moderation/KickCommand.java | 13 +-------- .../commands/moderation/ModerationUtils.java | 29 +++++++++++++++++++ .../commands/moderation/UnbanCommand.java | 14 ++------- 4 files changed, 40 insertions(+), 37 deletions(-) create mode 100644 application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 765c99e45b..d5f8d27d32 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -28,10 +28,6 @@ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; private static final String DELETE_HISTORY_OPTION = "delete-history"; private static final String REASON_OPTION = "reason"; - /** - * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. - */ - private static final Integer REASON_MAX_LENGTH = 512; private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); /** @@ -56,6 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .getAsString(); Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); + if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") @@ -65,7 +62,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } String userTag = targetUser.getAsTag(); - if (!author.canInteract(event.getMember())) { + // Needed for the permissions check to work as targetUser.getMember just result in an error. + Member targetMember = + Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + .getAsMember(); + if (!author.canInteract(targetMember)) { event.reply("The user " + userTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); @@ -84,7 +85,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!bot.canInteract(event.getMember())) { + if (!bot.canInteract(targetMember)) { event.reply("The user " + userTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); @@ -94,13 +95,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { int days = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); - if (reason.length() > REASON_MAX_LENGTH) { - event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") - .setEphemeral(true) - .queue(); - return; - } - + ModerationUtils.reasonLimit(reason, event); banUser(targetUser, author, reason, days, guild, event); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index a875661091..724d4e07d5 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -3,7 +3,6 @@ import net.dv8tion.jda.api.Permission; import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; -import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; @@ -26,10 +25,6 @@ public final class KickCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(KickCommand.class); private static final String USER_OPTION = "user"; private static final String REASON_OPTION = "reason"; - /** - * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. - */ - private static final Integer REASON_MAX_LENGTH = 512; /** * Creates an instance of the kick command. @@ -86,13 +81,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (reason.length() > REASON_MAX_LENGTH) { - event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") - .setEphemeral(true) - .queue(); - return; - } - + ModerationUtils.reasonLimit(reason, event); kickUser(targetMember, author, reason, guild, event); } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java new file mode 100644 index 0000000000..6e7fc104d5 --- /dev/null +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -0,0 +1,29 @@ +package org.togetherjava.tjbot.commands.moderation; + +import net.dv8tion.jda.api.entities.Guild; +import net.dv8tion.jda.api.entities.User; +import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import org.jetbrains.annotations.NotNull; + +public final class ModerationUtils { + /** + * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. + */ + private final int reasonMaxLength; + + public ModerationUtils() { + reasonMaxLength = 512; + } + + /** + * Checks if the given reason is above the reason limit. + */ + public static void reasonLimit(@NotNull String reason, @NotNull SlashCommandEvent event) { + ModerationUtils reasonLimit = new ModerationUtils(); + if (reason.length() > reasonLimit.reasonMaxLength) { + event.reply("The reason can not be over " + reasonLimit.reasonMaxLength + " characters") + .setEphemeral(true) + .queue(); + } + } +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5c12c6a6fa..43584a1521 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -1,7 +1,6 @@ package org.togetherjava.tjbot.commands.moderation; import net.dv8tion.jda.api.Permission; -import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; @@ -25,10 +24,6 @@ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); private static final String USER_OPTION = "user"; private static final String REASON_OPTION = "reason"; - /** - * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. - */ - private static final Integer REASON_MAX_LENGTH = 512; /** * Creates an instance of the unban command. @@ -55,6 +50,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } Member bot = Objects.requireNonNull(event.getGuild(), "The Bot is null").getSelfMember(); + if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") @@ -69,13 +65,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - if (reason.length() > REASON_MAX_LENGTH) { - event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") - .setEphemeral(true) - .queue(); - return; - } - + ModerationUtils.reasonLimit(reason, event); unban(targetUser, reason, author, event); } From 149d83fb4d0470060c5dcb0093691e047b27a855 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Thu, 28 Oct 2021 19:19:56 +0100 Subject: [PATCH 156/182] Update ModerationUtils.java --- .../tjbot/commands/moderation/ModerationUtils.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 6e7fc104d5..a32d6b1b0f 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -9,19 +9,18 @@ public final class ModerationUtils { /** * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. */ - private final int reasonMaxLength; + private static final int REASON_MAX_LENGTH = 512; - public ModerationUtils() { - reasonMaxLength = 512; + ModerationUtils() { + throw new IllegalStateException("Utility class"); } /** * Checks if the given reason is above the reason limit. */ public static void reasonLimit(@NotNull String reason, @NotNull SlashCommandEvent event) { - ModerationUtils reasonLimit = new ModerationUtils(); - if (reason.length() > reasonLimit.reasonMaxLength) { - event.reply("The reason can not be over " + reasonLimit.reasonMaxLength + " characters") + if (reason.length() > REASON_MAX_LENGTH) { + event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") .setEphemeral(true) .queue(); } From cfb91fce3b4ce06687b52bf31b7ec3aa40a8512b Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 12:16:00 +0100 Subject: [PATCH 157/182] Fixed everything. --- .../togetherjava/tjbot/commands/Commands.java | 4 +- .../tjbot/commands/moderation/BanCommand.java | 43 ++++++++----------- .../commands/moderation/KickCommand.java | 12 +++--- .../commands/moderation/ModerationUtils.java | 26 +++++++---- .../commands/moderation/UnbanCommand.java | 17 ++++---- 5 files changed, 52 insertions(+), 50 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java index 5a42f00dd8..568ef4b3aa 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/Commands.java @@ -43,7 +43,7 @@ public enum Commands { // available. return List.of(new PingCommand(), new DatabaseCommand(database), new TeXCommand(), new TagCommand(tagSystem), new TagManageCommand(tagSystem), - new TagsCommand(tagSystem), new BanCommand(), new UnbanCommand(), - new KickCommand(), new VcActivityCommand()); + new TagsCommand(tagSystem), new BanCommand(), new UnbanCommand(), new KickCommand(), + new VcActivityCommand()); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index d5f8d27d32..bd2c5067fb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -22,7 +22,6 @@ *

* The command fails if the user triggering it is lacking permissions to either ban other users or * to ban the specific given user (for example a moderator attempting to ban an admin). - * */ public final class BanCommand extends SlashCommandAdapter { private static final String USER_OPTION = "user"; @@ -45,14 +44,14 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") - .getAsUser(); + Member targetMember = + Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + .getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "Author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") @@ -61,19 +60,15 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = targetUser.getAsTag(); + String targetUserTag = targetMember.getUser().getAsTag(); // Needed for the permissions check to work as targetUser.getMember just result in an error. - Member targetMember = - Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") - .getAsMember(); if (!author.canInteract(targetMember)) { - event.reply("The user " + userTag + " is too powerful for you to ban.") + event.reply("The user " + targetUserTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return; } - Guild guild = event.getGuild(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not ban users in this guild since I do not have the BAN_MEMBERS permission.") @@ -81,45 +76,45 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(guild).getName()); + event.getGuild().getName()); return; } if (!bot.canInteract(targetMember)) { - event.reply("The user " + userTag + " is too powerful for me to ban.") + event.reply("The user " + targetUserTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); return; } - int days = Math + int deleteHistoryDays = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); - ModerationUtils.reasonLimit(reason, event); - banUser(targetUser, author, reason, days, guild, event); + ModerationUtils.handleReason(reason, event); + banUser(targetMember.getUser(), author, reason, deleteHistoryDays, event.getGuild(), event); } - private static void banUser(@NotNull User user, @NotNull Member author, @NotNull String reason, - int delDays, @NotNull Guild guild, @NotNull SlashCommandEvent event) { - String guildName = guild.getName(); + private static void banUser(@NotNull User targetUser, @NotNull Member author, + @NotNull String reason, int deleteHistoryDays, @NotNull Guild guild, + @NotNull SlashCommandEvent event) { event.getJDA() - .openPrivateChannelById(user.getIdLong()) + .openPrivateChannelById(targetUser.getIdLong()) .flatMap(channel -> channel.sendMessage( """ Hey there, sorry to tell you but unfortunately you have been banned from the server %s. If you think this was a mistake, please contact a moderator or admin of the server. The reason for the ban is: %s """ - .formatted(guildName, reason))) + .formatted(guild.getName(), reason))) .mapToResult() - .flatMap(result -> guild.ban(user, delDays, reason)) - .flatMap(v -> event.reply(user.getAsTag() + " was banned by " + .flatMap(result -> guild.ban(targetUser, deleteHistoryDays, reason)) + .flatMap(v -> event.reply(targetUser.getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info( " '{} ({})' banned the user '{} ({})' and deleted their message history of the last '{}' days. Reason being'{}'", - author.getUser().getAsTag(), author.getIdLong(), user.getAsTag(), user.getIdLong(), - delDays, reason); + author.getUser().getAsTag(), author.getIdLong(), targetUser.getAsTag(), + targetUser.getIdLong(), deleteHistoryDays, reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 724d4e07d5..e9ca0290f1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -62,7 +62,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Guild guild = event.getGuild(); if (!bot.hasPermission(Permission.KICK_MEMBERS)) { event.reply( "I can not kick users in this guild since I do not have the KICK_MEMBERS permission.") @@ -70,7 +69,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have KICK_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(guild).getName()); + event.getGuild().getName()); return; } @@ -81,13 +80,14 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - ModerationUtils.reasonLimit(reason, event); - kickUser(targetMember, author, reason, guild, event); + boolean reasonIsUnderLimit = ModerationUtils.handleReason(reason, event); + if (reasonIsUnderLimit) { + kickUser(targetMember, author, reason, event.getGuild(), event); + } } private static void kickUser(@NotNull Member member, @NotNull Member author, @NotNull String reason, @NotNull Guild guild, @NotNull SlashCommandEvent event) { - String guildName = guild.getName(); event.getJDA() .openPrivateChannelById(member.getUser().getId()) .flatMap(channel -> channel.sendMessage( @@ -96,7 +96,7 @@ private static void kickUser(@NotNull Member member, @NotNull Member author, If you think this was a mistake, please contact a moderator or admin of the server. The reason for the kick is: %s """ - .formatted(guildName, reason))) + .formatted(guild.getName(), reason))) .mapToResult() .flatMap(result -> guild.kick(member, reason).reason(reason)) .flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by " diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index a32d6b1b0f..49ae829adb 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -5,24 +5,32 @@ import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import org.jetbrains.annotations.NotNull; -public final class ModerationUtils { +public enum ModerationUtils { + ; + /** * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. */ private static final int REASON_MAX_LENGTH = 512; - ModerationUtils() { - throw new IllegalStateException("Utility class"); + private ModerationUtils() { + throw new UnsupportedOperationException( + "The Moderation Utility class has tin into an error"); } /** - * Checks if the given reason is above the reason limit. + * The Boolean reasonLimit will check if the handleReason is above the reason limit. If it is it + * will throw an error and will tell the user that the reason can not be over + * {@link ModerationUtils#REASON_MAX_LENGTH} If the reason is under the limit it will pass and + * will allow the command to continue. */ - public static void reasonLimit(@NotNull String reason, @NotNull SlashCommandEvent event) { - if (reason.length() > REASON_MAX_LENGTH) { - event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") - .setEphemeral(true) - .queue(); + public static boolean handleReason(@NotNull String reason, @NotNull SlashCommandEvent event) { + if (reason.length() <= REASON_MAX_LENGTH) { + return true; } + event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") + .setEphemeral(true) + .queue(); + return true; } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 43584a1521..2040dd4dbc 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -18,7 +18,7 @@ /** * This command allows you to unban a user. The unban command requires the user to input the user * who is subject to get unbanned. Unbanning can also be paired with a reason for unbanning the - * user. The command fails if the user is currently not banned already + * user. The command fails if the user is currently not banned already. */ public final class UnbanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(UnbanCommand.class); @@ -50,7 +50,6 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } Member bot = Objects.requireNonNull(event.getGuild(), "The Bot is null").getSelfMember(); - if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") @@ -65,20 +64,20 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - ModerationUtils.reasonLimit(reason, event); + ModerationUtils.handleReason(reason, event); unban(targetUser, reason, author, event); } - private static void unban(@NotNull User user, @NotNull String reason, @NotNull Member author, - @NotNull SlashCommandEvent event) { - event.getGuild().unban(user).reason(reason).queue(v -> { + private static void unban(@NotNull User targetUser, @NotNull String reason, + @NotNull Member author, @NotNull SlashCommandEvent event) { + event.getGuild().unban(targetUser).reason(reason).queue(v -> { event .reply("The user " + author.getUser().getAsTag() + " unbanned the user " - + user.getAsTag() + " for: " + reason) + + targetUser.getAsTag() + " for: " + reason) .queue(); logger.info(" {} ({}) unbanned the user '{}' for: '{}'", author.getUser().getAsTag(), - author.getIdLong(), user.getAsTag(), reason); + author.getIdLong(), targetUser.getAsTag(), reason); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { @@ -86,7 +85,7 @@ private static void unban(@NotNull User user, @NotNull String reason, @NotNull M event.reply("The specified user doesn't exist").setEphemeral(true).queue(); logger.debug("I could not unban the user '{}' because they do not exist", - user.getAsTag()); + targetUser.getAsTag()); } else { event.reply("Sorry, but something went wrong.").setEphemeral(true).queue(); From 33261e0ca6671fc6794fcb0eed7baaf92806d1e8 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 12:23:43 +0100 Subject: [PATCH 158/182] fixed an issue which cause member to null --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index bd2c5067fb..615319c9b4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -44,9 +44,7 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member targetMember = - Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") - .getAsMember(); + Member targetMember = event.getOption(USER_OPTION).getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "Author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); From 6990895e5b801eab298e021a1e6cb06238cec3e5 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 13:04:58 +0100 Subject: [PATCH 159/182] Fixed the issues --- .../tjbot/commands/moderation/BanCommand.java | 90 ++++++++++++------- .../commands/moderation/UnbanCommand.java | 6 +- 2 files changed, 60 insertions(+), 36 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 615319c9b4..560ccbe465 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -5,6 +5,7 @@ import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import net.dv8tion.jda.api.interactions.commands.build.OptionData; import org.jetbrains.annotations.NotNull; @@ -44,52 +45,30 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member targetMember = event.getOption(USER_OPTION).getAsMember(); + OptionMapping userOption = + Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null"); + Member targetMember = userOption.getAsMember(); + User targetUser = userOption.getAsUser(); Member author = Objects.requireNonNull(event.getMember(), "Author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); - if (!author.hasPermission(Permission.BAN_MEMBERS)) { - event.reply( - "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") - .setEphemeral(true) - .queue(); - return; - } - - String targetUserTag = targetMember.getUser().getAsTag(); - // Needed for the permissions check to work as targetUser.getMember just result in an error. - if (!author.canInteract(targetMember)) { - event.reply("The user " + targetUserTag + " is too powerful for you to ban.") - .setEphemeral(true) - .queue(); - return; - } - - if (!bot.hasPermission(Permission.BAN_MEMBERS)) { - event.reply( - "I can not ban users in this guild since I do not have the BAN_MEMBERS permission.") - .setEphemeral(true) - .queue(); - - logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - event.getGuild().getName()); - return; + if (targetMember != null + && handleCanInteractWithTarget(targetMember, event.getGuild(), author, event)) { + return; } - if (!bot.canInteract(targetMember)) { - event.reply("The user " + targetUserTag + " is too powerful for me to ban.") - .setEphemeral(true) - .queue(); + if (handleHasPermissions(author, event.getGuild(), event)) { return; } int deleteHistoryDays = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); - ModerationUtils.handleReason(reason, event); - banUser(targetMember.getUser(), author, reason, deleteHistoryDays, event.getGuild(), event); + boolean reasonIsUnderLimit = ModerationUtils.handleReason(reason, event); + if (reasonIsUnderLimit) { + banUser(targetUser, author, reason, deleteHistoryDays, event.getGuild(), event); + } } private static void banUser(@NotNull User targetUser, @NotNull Member author, @@ -115,4 +94,47 @@ private static void banUser(@NotNull User targetUser, @NotNull Member author, author.getUser().getAsTag(), author.getIdLong(), targetUser.getAsTag(), targetUser.getIdLong(), deleteHistoryDays, reason); } + + private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, + @NotNull Guild guild, @NotNull Member author, @NotNull SlashCommandEvent event) { + String targetUserTag = targetMember.getUser().getAsTag(); + if (!author.canInteract(targetMember)) { + event.reply("The user " + targetUserTag + " is too powerful for you to ban.") + .setEphemeral(true) + .queue(); + return false; + } + + if (!guild.getSelfMember().canInteract(targetMember)) { + event.reply("The user " + targetUserTag + " is too powerful for me to ban.") + .setEphemeral(true) + .queue(); + return false; + } + return true; + } + + private static boolean handleHasPermissions(@NotNull Member author, @NotNull Guild guild, + @NotNull SlashCommandEvent event) { + if (!author.hasPermission(Permission.BAN_MEMBERS)) { + event.reply( + "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") + .setEphemeral(true) + .queue(); + return false; + } + + if (!guild.getSelfMember().hasPermission(Permission.BAN_MEMBERS)) { + event.reply( + "I can not ban users in this guild since I do not have the BAN_MEMBERS permission.") + .setEphemeral(true) + .queue(); + + logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", + event.getGuild().getName()); + return false; + } + return true; + } + } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 2040dd4dbc..b5e0aedb95 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -64,8 +64,10 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - ModerationUtils.handleReason(reason, event); - unban(targetUser, reason, author, event); + boolean reasonIsUnderLimit = ModerationUtils.handleReason(reason, event); + if (reasonIsUnderLimit) { + unban(targetUser, reason, author, event); + } } private static void unban(@NotNull User targetUser, @NotNull String reason, From f4449f970b4226d5dfabae05a82c18fd86945879 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 14:38:12 +0100 Subject: [PATCH 160/182] added spaces to improve readbility --- .../tjbot/commands/moderation/BanCommand.java | 20 ++++++++++--------- .../commands/moderation/KickCommand.java | 3 +++ 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 560ccbe465..3c67235933 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -47,18 +47,21 @@ public BanCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null"); + Member targetMember = userOption.getAsMember(); User targetUser = userOption.getAsUser(); + Member author = Objects.requireNonNull(event.getMember(), "Author is null"); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - if (targetMember != null - && handleCanInteractWithTarget(targetMember, event.getGuild(), author, event)) { - return; + Member bot = Objects.requireNonNull(event.getGuild(), "The Bot is null").getSelfMember(); + if (targetMember != null && handleCanInteractWithTarget(targetMember, bot, author, event)) { + return; } - if (handleHasPermissions(author, event.getGuild(), event)) { + if (handleHasPermissions(author, bot, event)) { return; } @@ -96,7 +99,7 @@ private static void banUser(@NotNull User targetUser, @NotNull Member author, } private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, - @NotNull Guild guild, @NotNull Member author, @NotNull SlashCommandEvent event) { + @NotNull Member bot, @NotNull Member author, @NotNull SlashCommandEvent event) { String targetUserTag = targetMember.getUser().getAsTag(); if (!author.canInteract(targetMember)) { event.reply("The user " + targetUserTag + " is too powerful for you to ban.") @@ -105,7 +108,7 @@ private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, return false; } - if (!guild.getSelfMember().canInteract(targetMember)) { + if (!bot.canInteract(targetMember)) { event.reply("The user " + targetUserTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); @@ -114,7 +117,7 @@ private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, return true; } - private static boolean handleHasPermissions(@NotNull Member author, @NotNull Guild guild, + private static boolean handleHasPermissions(@NotNull Member author, @NotNull Member bot, @NotNull SlashCommandEvent event) { if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( @@ -124,7 +127,7 @@ private static boolean handleHasPermissions(@NotNull Member author, @NotNull Gui return false; } - if (!guild.getSelfMember().hasPermission(Permission.BAN_MEMBERS)) { + if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not ban users in this guild since I do not have the BAN_MEMBERS permission.") .setEphemeral(true) @@ -136,5 +139,4 @@ private static boolean handleHasPermissions(@NotNull Member author, @NotNull Gui } return true; } - } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index e9ca0290f1..a97d1574f0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -41,9 +41,12 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member targetMember = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") .getAsMember(); + Member author = Objects.requireNonNull(event.getMember(), "Author is null"); + String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); + Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { From 2bf9f7b7f9179eabe7b7af480e6cddb3cbed5277 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 14:48:45 +0100 Subject: [PATCH 161/182] Improved some sentences --- .../tjbot/commands/moderation/BanCommand.java | 2 ++ .../tjbot/commands/moderation/KickCommand.java | 4 +++- .../tjbot/commands/moderation/ModerationUtils.java | 13 ++++++++----- .../tjbot/commands/moderation/UnbanCommand.java | 5 ++++- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 3c67235933..81f7949301 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -32,6 +32,8 @@ public final class BanCommand extends SlashCommandAdapter { /** * Creates an instance of the ban command. + * + * @see BanCommand */ public BanCommand() { super("ban", "Bans the given user from the server", SlashCommandVisibility.GUILD); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index a97d1574f0..e27341dca1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -27,7 +27,9 @@ public final class KickCommand extends SlashCommandAdapter { private static final String REASON_OPTION = "reason"; /** - * Creates an instance of the kick command. + * Constructs an instance + * + * @see KickCommand */ public KickCommand() { super("kick", "Kicks the given user from the server", SlashCommandVisibility.GUILD); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 49ae829adb..91fa98d1f4 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -3,6 +3,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; public enum ModerationUtils { @@ -13,16 +14,18 @@ public enum ModerationUtils { */ private static final int REASON_MAX_LENGTH = 512; - private ModerationUtils() { + @Contract(value = " -> fail", pure = true) + ModerationUtils() { throw new UnsupportedOperationException( "The Moderation Utility class has tin into an error"); } /** - * The Boolean reasonLimit will check if the handleReason is above the reason limit. If it is it - * will throw an error and will tell the user that the reason can not be over - * {@link ModerationUtils#REASON_MAX_LENGTH} If the reason is under the limit it will pass and - * will allow the command to continue. + * The Boolean reasonLimit will check if the reason is above the provided limit.
+ *
+ * If it is it will throw an error and will tell the user that the reason can not be over the + * {@link ModerationUtils#REASON_MAX_LENGTH}
+ * If the reason is under the limit it will pass and will allow the command to continue. */ public static boolean handleReason(@NotNull String reason, @NotNull SlashCommandEvent event) { if (reason.length() <= REASON_MAX_LENGTH) { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index b5e0aedb95..18148a9873 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -26,7 +26,9 @@ public final class UnbanCommand extends SlashCommandAdapter { private static final String REASON_OPTION = "reason"; /** - * Creates an instance of the unban command. + * Constructs an instance + * + * @see UnbanCommand */ public UnbanCommand() { super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); @@ -39,6 +41,7 @@ public UnbanCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") .getAsUser(); + Member author = Objects.requireNonNull(event.getMember(), "The member is null"); if (!author.hasPermission(Permission.BAN_MEMBERS)) { From 42c2269de2e4a1b3a671aa0a19cc8a40d304b7ae Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 14:52:54 +0100 Subject: [PATCH 162/182] Update ModerationUtils.java --- .../togetherjava/tjbot/commands/moderation/ModerationUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 91fa98d1f4..c56aaa191d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -17,7 +17,7 @@ public enum ModerationUtils { @Contract(value = " -> fail", pure = true) ModerationUtils() { throw new UnsupportedOperationException( - "The Moderation Utility class has tin into an error"); + "The Moderation Utility class has run into an error"); } /** From eeb64d299d7addfb5b35f75ec46106f1c610bddd Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 15:30:35 +0100 Subject: [PATCH 163/182] Update KickCommand.java --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index e27341dca1..1e8bb4838e 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -112,4 +112,4 @@ private static void kickUser(@NotNull Member member, @NotNull Member author, author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), member.getUser().getId(), reason); } -} +} \ No newline at end of file From 21636627cac5b7f07b327d94f296c231f6a82e70 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 15:33:05 +0100 Subject: [PATCH 164/182] fixed an error on my side --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- .../togetherjava/tjbot/commands/moderation/ModerationUtils.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 1e8bb4838e..e27341dca1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -112,4 +112,4 @@ private static void kickUser(@NotNull Member member, @NotNull Member author, author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), member.getUser().getId(), reason); } -} \ No newline at end of file +} diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index c56aaa191d..af726bffc1 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -34,6 +34,6 @@ public static boolean handleReason(@NotNull String reason, @NotNull SlashCommand event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") .setEphemeral(true) .queue(); - return true; + return false; } } From b0021774fdcc209d457ab09a7a9902fece6e1c22 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 15:35:27 +0100 Subject: [PATCH 165/182] Update ModerationUtils.java --- .../tjbot/commands/moderation/ModerationUtils.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index af726bffc1..5c0e508d99 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -10,7 +10,9 @@ public enum ModerationUtils { ; /** - * As stated in {@link Guild#ban(User, int, String)} The reason can be only 512 characters. + * As stated in {@link Guild#ban(User, int, String)} + *
+ * The reason can be only 512 characters. */ private static final int REASON_MAX_LENGTH = 512; From 792cb263737e9423c77062cf31242159062af875 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 17:28:04 +0100 Subject: [PATCH 166/182] Fixed everything --- .../tjbot/commands/moderation/BanCommand.java | 41 ++++++++++--------- .../commands/moderation/KickCommand.java | 7 ++-- .../commands/moderation/ModerationUtils.java | 19 +++++---- .../commands/moderation/UnbanCommand.java | 7 ++-- 4 files changed, 40 insertions(+), 34 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 81f7949301..764b901fa2 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -48,39 +48,42 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = - Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null"); + Objects.requireNonNull(event.getOption(USER_OPTION), "The target user is null"); Member targetMember = userOption.getAsMember(); - User targetUser = userOption.getAsUser(); Member author = Objects.requireNonNull(event.getMember(), "Author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - Member bot = Objects.requireNonNull(event.getGuild(), "The Bot is null").getSelfMember(); - if (targetMember != null && handleCanInteractWithTarget(targetMember, bot, author, event)) { + Guild guild = Objects.requireNonNull(event.getGuild()); + Member bot = guild.getSelfMember(); + // Member doesn't exist if attempting to ban a user who is not part of + if (targetMember != null + && !handleCanInteractWithTarget(targetMember, bot, author, event)) { return; } - if (handleHasPermissions(author, bot, event)) { + if (!handleHasPermissions(author, bot, event, guild)) { return; } int deleteHistoryDays = Math .toIntExact(Objects.requireNonNull(event.getOption(DELETE_HISTORY_OPTION)).getAsLong()); - boolean reasonIsUnderLimit = ModerationUtils.handleReason(reason, event); - if (reasonIsUnderLimit) { - banUser(targetUser, author, reason, deleteHistoryDays, event.getGuild(), event); + if (!ModerationUtils.handleReason(reason, event)) { + return; } + + banUser(userOption.getAsUser(), author, reason, deleteHistoryDays, event.getGuild(), event); } - private static void banUser(@NotNull User targetUser, @NotNull Member author, + private static void banUser(@NotNull User target, @NotNull Member author, @NotNull String reason, int deleteHistoryDays, @NotNull Guild guild, @NotNull SlashCommandEvent event) { event.getJDA() - .openPrivateChannelById(targetUser.getIdLong()) + .openPrivateChannelById(target.getIdLong()) .flatMap(channel -> channel.sendMessage( """ Hey there, sorry to tell you but unfortunately you have been banned from the server %s. @@ -89,29 +92,29 @@ private static void banUser(@NotNull User targetUser, @NotNull Member author, """ .formatted(guild.getName(), reason))) .mapToResult() - .flatMap(result -> guild.ban(targetUser, deleteHistoryDays, reason)) - .flatMap(v -> event.reply(targetUser.getAsTag() + " was banned by " + .flatMap(result -> guild.ban(target, deleteHistoryDays, reason)) + .flatMap(v -> event.reply(target.getAsTag() + " was banned by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info( " '{} ({})' banned the user '{} ({})' and deleted their message history of the last '{}' days. Reason being'{}'", - author.getUser().getAsTag(), author.getIdLong(), targetUser.getAsTag(), - targetUser.getIdLong(), deleteHistoryDays, reason); + author.getUser().getAsTag(), author.getIdLong(), target.getAsTag(), + target.getIdLong(), deleteHistoryDays, reason); } private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, @NotNull Member bot, @NotNull Member author, @NotNull SlashCommandEvent event) { - String targetUserTag = targetMember.getUser().getAsTag(); + String targetTag = targetMember.getUser().getAsTag(); if (!author.canInteract(targetMember)) { - event.reply("The user " + targetUserTag + " is too powerful for you to ban.") + event.reply("The user " + targetTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return false; } if (!bot.canInteract(targetMember)) { - event.reply("The user " + targetUserTag + " is too powerful for me to ban.") + event.reply("The user " + targetTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); return false; @@ -120,7 +123,7 @@ private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, } private static boolean handleHasPermissions(@NotNull Member author, @NotNull Member bot, - @NotNull SlashCommandEvent event) { + @NotNull SlashCommandEvent event, @NotNull Guild guild) { if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "You can not ban users in this guild since you do not have the BAN_MEMBERS permission.") @@ -136,7 +139,7 @@ private static boolean handleHasPermissions(@NotNull Member author, @NotNull Mem .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - event.getGuild().getName()); + guild.getName()); return false; } return true; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index e27341dca1..3ec7924b1a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -85,10 +85,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - boolean reasonIsUnderLimit = ModerationUtils.handleReason(reason, event); - if (reasonIsUnderLimit) { - kickUser(targetMember, author, reason, event.getGuild(), event); + if (!ModerationUtils.handleReason(reason, event)) { + return; } + + kickUser(targetMember, author, reason, event.getGuild(), event); } private static void kickUser(@NotNull Member member, @NotNull Member author, diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 5c0e508d99..c8bfc3e4e3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -10,24 +10,25 @@ public enum ModerationUtils { ; /** - * As stated in {@link Guild#ban(User, int, String)} - *
+ * As stated in {@link Guild#ban(User, int, String)}
* The reason can be only 512 characters. */ private static final int REASON_MAX_LENGTH = 512; @Contract(value = " -> fail", pure = true) ModerationUtils() { - throw new UnsupportedOperationException( - "The Moderation Utility class has run into an error"); + throw new UnsupportedOperationException(); } /** - * The Boolean reasonLimit will check if the reason is above the provided limit.
- *
- * If it is it will throw an error and will tell the user that the reason can not be over the - * {@link ModerationUtils#REASON_MAX_LENGTH}
- * If the reason is under the limit it will pass and will allow the command to continue. + * @param reason The Boolean reasonLimit will check if the reason is above the provided limit. + *
+ *
+ * If it is it will throw an error and will tell the user that the reason can not be over + * the {@link ModerationUtils#REASON_MAX_LENGTH}
+ * If the reason is under the limit it will pass and will allow the command to continue. + * + * @return {@link ModerationUtils#REASON_MAX_LENGTH} */ public static boolean handleReason(@NotNull String reason, @NotNull SlashCommandEvent event) { if (reason.length() <= REASON_MAX_LENGTH) { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 18148a9873..342716d5a0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -67,10 +67,11 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - boolean reasonIsUnderLimit = ModerationUtils.handleReason(reason, event); - if (reasonIsUnderLimit) { - unban(targetUser, reason, author, event); + if (!ModerationUtils.handleReason(reason, event)) { + return; } + + unban(targetUser, reason, author, event); } private static void unban(@NotNull User targetUser, @NotNull String reason, From 62ee69e9306c499a4aefa3216e0fb360a88bc31d Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 18:10:22 +0100 Subject: [PATCH 167/182] Update ModerationUtils.java --- .../tjbot/commands/moderation/ModerationUtils.java | 6 ------ 1 file changed, 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index c8bfc3e4e3..341260d60a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -3,7 +3,6 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.User; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; -import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; public enum ModerationUtils { @@ -15,11 +14,6 @@ public enum ModerationUtils { */ private static final int REASON_MAX_LENGTH = 512; - @Contract(value = " -> fail", pure = true) - ModerationUtils() { - throw new UnsupportedOperationException(); - } - /** * @param reason The Boolean reasonLimit will check if the reason is above the provided limit. *
From d795cd22bd44d1b4b2d29a84bbdbad9bac604375 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Fri, 29 Oct 2021 18:12:49 +0100 Subject: [PATCH 168/182] Update ModerationUtils.java --- .../togetherjava/tjbot/commands/moderation/ModerationUtils.java | 1 - 1 file changed, 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 341260d60a..6da349c360 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -17,7 +17,6 @@ public enum ModerationUtils { /** * @param reason The Boolean reasonLimit will check if the reason is above the provided limit. *
- *
* If it is it will throw an error and will tell the user that the reason can not be over * the {@link ModerationUtils#REASON_MAX_LENGTH}
* If the reason is under the limit it will pass and will allow the command to continue. From 77441b0211d9cde09bae37b95e0bec758b29eb1c Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:08:18 +0100 Subject: [PATCH 169/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 342716d5a0..8a02eac51a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -52,7 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - Member bot = Objects.requireNonNull(event.getGuild(), "The Bot is null").getSelfMember(); + Member bot = Objects.requireNonNull(event.getGuild(), "The guild is null").getSelfMember(); if (!bot.hasPermission(Permission.BAN_MEMBERS)) { event.reply( "I can not unban users in this guild since I do not have the BAN_MEMBERS permission.") From 04b120cc3f7e7719a4fdc8323aee32a5183e70e9 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:09:02 +0100 Subject: [PATCH 170/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 8a02eac51a..049f972102 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -42,7 +42,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") .getAsUser(); - Member author = Objects.requireNonNull(event.getMember(), "The member is null"); + Member author = Objects.requireNonNull(event.getMember(), "The author is null"); if (!author.hasPermission(Permission.BAN_MEMBERS)) { event.reply( From 216201bd948fd2a04484cf1cef45c8d6ba827abf Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:09:31 +0100 Subject: [PATCH 171/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 3ec7924b1a..4df9ddf680 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -44,7 +44,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") .getAsMember(); - Member author = Objects.requireNonNull(event.getMember(), "Author is null"); + Member author = Objects.requireNonNull(event.getMember(), "The author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); From 12c85a8eaf6beb4b26e7f2b892cba461a1be60ae Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:09:57 +0100 Subject: [PATCH 172/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 049f972102..fd7ad1738b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -60,7 +60,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { .queue(); logger.error("The bot does not have BAN_MEMBERS permission on the server '{}' ", - Objects.requireNonNull(event.getGuild()).getName()); + event.getGuild().getName()); return; } From 67de1ed3995be2a56fd5ba425cd9b7e10868e864 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:10:10 +0100 Subject: [PATCH 173/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 4df9ddf680..07eba925bf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -49,7 +49,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - Member bot = Objects.requireNonNull(event.getGuild(), "The bot is null").getSelfMember(); + Member bot = Objects.requireNonNull(event.getGuild(), "The guild is null").getSelfMember(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( From 71a551404f894a84daf6db43e2ddf3ac7f2eafcd Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:10:19 +0100 Subject: [PATCH 174/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 764b901fa2..10cc1bd829 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -48,7 +48,7 @@ public BanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = - Objects.requireNonNull(event.getOption(USER_OPTION), "The target user is null"); + Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null"); Member targetMember = userOption.getAsMember(); From de6992b02f5e1daf2e896fd3a73742adee91662b Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:10:27 +0100 Subject: [PATCH 175/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 10cc1bd829..8c3de56799 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -52,7 +52,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member targetMember = userOption.getAsMember(); - Member author = Objects.requireNonNull(event.getMember(), "Author is null"); + Member author = Objects.requireNonNull(event.getMember(), "The author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); From 9170329d034556fc5622e851f9ed8c6da2ae35c2 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Sat, 30 Oct 2021 13:10:39 +0100 Subject: [PATCH 176/182] Update application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java Co-authored-by: Tais993 <49957334+Tais993@users.noreply.github.com> --- .../org/togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 07eba925bf..abb94ffeed 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -41,7 +41,7 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { Member targetMember = - Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null") .getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "The author is null"); From 4663673a747b4a236c9332221af7e8ea6cf4f134 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 30 Oct 2021 13:14:49 +0100 Subject: [PATCH 177/182] Fixed --- .../tjbot/commands/moderation/BanCommand.java | 3 ++- .../tjbot/commands/moderation/KickCommand.java | 10 ++++++---- .../tjbot/commands/moderation/UnbanCommand.java | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 8c3de56799..71b4ebc05a 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -59,7 +59,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Guild guild = Objects.requireNonNull(event.getGuild()); Member bot = guild.getSelfMember(); - // Member doesn't exist if attempting to ban a user who is not part of + + // Member doesn't exist if attempting to ban a user who is not part of the guild. if (targetMember != null && !handleCanInteractWithTarget(targetMember, bot, author, event)) { return; diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index abb94ffeed..cf17451a6d 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -4,6 +4,7 @@ import net.dv8tion.jda.api.entities.Guild; import net.dv8tion.jda.api.entities.Member; import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; +import net.dv8tion.jda.api.interactions.commands.OptionMapping; import net.dv8tion.jda.api.interactions.commands.OptionType; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -40,9 +41,10 @@ public KickCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - Member targetMember = - Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null") - .getAsMember(); + OptionMapping userOption = + Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null"); + + Member targetMember = userOption.getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "The author is null"); @@ -59,7 +61,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - String userTag = targetMember.getUser().getAsTag(); + String userTag = userOption.getAsUser().getAsTag(); if (!author.canInteract(targetMember)) { event.reply("The user " + userTag + " is too powerful for you to kick.") .setEphemeral(true) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index fd7ad1738b..5bda0e45bd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -39,7 +39,7 @@ public UnbanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The member is null") + User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") .getAsUser(); Member author = Objects.requireNonNull(event.getMember(), "The author is null"); From 24c62509d42a0c6f8f396b23a026a2c8fbbb72ac Mon Sep 17 00:00:00 2001 From: Yusuf Date: Sat, 30 Oct 2021 22:31:43 +0100 Subject: [PATCH 178/182] Fixed everything Tijs told me to fix --- .../tjbot/commands/moderation/BanCommand.java | 6 +++--- .../commands/moderation/KickCommand.java | 20 +++++++++---------- .../commands/moderation/ModerationUtils.java | 1 + .../commands/moderation/UnbanCommand.java | 14 ++++++------- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 71b4ebc05a..32ee3d7de8 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -50,7 +50,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null"); - Member targetMember = userOption.getAsMember(); + Member target = userOption.getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "The author is null"); @@ -61,8 +61,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = guild.getSelfMember(); // Member doesn't exist if attempting to ban a user who is not part of the guild. - if (targetMember != null - && !handleCanInteractWithTarget(targetMember, bot, author, event)) { + if (target != null + && !handleCanInteractWithTarget(target, bot, author, event)) { return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index cf17451a6d..8655caa839 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -44,7 +44,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null"); - Member targetMember = userOption.getAsMember(); + Member target = userOption.getAsMember(); Member author = Objects.requireNonNull(event.getMember(), "The author is null"); @@ -62,7 +62,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { } String userTag = userOption.getAsUser().getAsTag(); - if (!author.canInteract(targetMember)) { + if (!author.canInteract(target)) { event.reply("The user " + userTag + " is too powerful for you to kick.") .setEphemeral(true) .queue(); @@ -80,7 +80,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - if (!bot.canInteract(targetMember)) { + if (!bot.canInteract(target)) { event.reply("The user " + userTag + " is too powerful for me to kick.") .setEphemeral(true) .queue(); @@ -91,13 +91,13 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - kickUser(targetMember, author, reason, event.getGuild(), event); + kickUser(target, author, reason, event.getGuild(), event); } - private static void kickUser(@NotNull Member member, @NotNull Member author, + private static void kickUser(@NotNull Member target, @NotNull Member author, @NotNull String reason, @NotNull Guild guild, @NotNull SlashCommandEvent event) { event.getJDA() - .openPrivateChannelById(member.getUser().getId()) + .openPrivateChannelById(target.getUser().getId()) .flatMap(channel -> channel.sendMessage( """ Hey there, sorry to tell you but unfortunately you have been kicked from the server %s. @@ -106,13 +106,13 @@ private static void kickUser(@NotNull Member member, @NotNull Member author, """ .formatted(guild.getName(), reason))) .mapToResult() - .flatMap(result -> guild.kick(member, reason).reason(reason)) - .flatMap(v -> event.reply(member.getUser().getAsTag() + " was kicked by " + .flatMap(result -> guild.kick(target, reason).reason(reason)) + .flatMap(v -> event.reply(target.getUser().getAsTag() + " was kicked by " + author.getUser().getAsTag() + " for: " + reason)) .queue(); logger.info(" '{} ({})' kicked the user '{} ({})' due to reason being '{}'", - author.getUser().getAsTag(), author.getIdLong(), member.getUser().getAsTag(), - member.getUser().getId(), reason); + author.getUser().getAsTag(), author.getIdLong(), target.getUser().getAsTag(), + target.getUser().getId(), reason); } } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 6da349c360..2e223764cf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -27,6 +27,7 @@ public static boolean handleReason(@NotNull String reason, @NotNull SlashCommand if (reason.length() <= REASON_MAX_LENGTH) { return true; } + event.reply("The reason can not be over " + REASON_MAX_LENGTH + " characters") .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 5bda0e45bd..d3bb843123 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -39,7 +39,7 @@ public UnbanCommand() { @Override public void onSlashCommand(@NotNull SlashCommandEvent event) { - User targetUser = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") + User target = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") .getAsUser(); Member author = Objects.requireNonNull(event.getMember(), "The author is null"); @@ -71,19 +71,19 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - unban(targetUser, reason, author, event); + unban(target, reason, author, event); } - private static void unban(@NotNull User targetUser, @NotNull String reason, + private static void unban(@NotNull User target, @NotNull String reason, @NotNull Member author, @NotNull SlashCommandEvent event) { - event.getGuild().unban(targetUser).reason(reason).queue(v -> { + event.getGuild().unban(target).reason(reason).queue(v -> { event .reply("The user " + author.getUser().getAsTag() + " unbanned the user " - + targetUser.getAsTag() + " for: " + reason) + + target.getAsTag() + " for: " + reason) .queue(); logger.info(" {} ({}) unbanned the user '{}' for: '{}'", author.getUser().getAsTag(), - author.getIdLong(), targetUser.getAsTag(), reason); + author.getIdLong(), target.getAsTag(), reason); }, throwable -> { if (throwable instanceof ErrorResponseException errorResponseException && errorResponseException.getErrorResponse() == ErrorResponse.UNKNOWN_USER) { @@ -91,7 +91,7 @@ private static void unban(@NotNull User targetUser, @NotNull String reason, event.reply("The specified user doesn't exist").setEphemeral(true).queue(); logger.debug("I could not unban the user '{}' because they do not exist", - targetUser.getAsTag()); + target.getAsTag()); } else { event.reply("Sorry, but something went wrong.").setEphemeral(true).queue(); From 79fe2a6a7f92946a9cf1b70f110fe18bce102010 Mon Sep 17 00:00:00 2001 From: Yusuf Date: Mon, 1 Nov 2021 18:34:38 +0000 Subject: [PATCH 179/182] spotlessApply --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 3 +-- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index 32ee3d7de8..cc97f00c93 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -61,8 +61,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { Member bot = guild.getSelfMember(); // Member doesn't exist if attempting to ban a user who is not part of the guild. - if (target != null - && !handleCanInteractWithTarget(target, bot, author, event)) { + if (target != null && !handleCanInteractWithTarget(target, bot, author, event)) { return; } diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index d3bb843123..0c76a81369 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -74,8 +74,8 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { unban(target, reason, author, event); } - private static void unban(@NotNull User target, @NotNull String reason, - @NotNull Member author, @NotNull SlashCommandEvent event) { + private static void unban(@NotNull User target, @NotNull String reason, @NotNull Member author, + @NotNull SlashCommandEvent event) { event.getGuild().unban(target).reason(reason).queue(v -> { event .reply("The user " + author.getUser().getAsTag() + " unbanned the user " From 199cfee611cca40b9df2c9fee6030f706da54488 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 2 Nov 2021 13:02:26 +0000 Subject: [PATCH 180/182] I have fixed everything that Zabuzard told me to fix. All the checks pass and i have improved the javaDoc. Yusuf --- .../tjbot/commands/moderation/BanCommand.java | 18 +++++++----------- .../tjbot/commands/moderation/KickCommand.java | 10 ++++------ .../commands/moderation/ModerationUtils.java | 18 ++++++++++++------ .../commands/moderation/UnbanCommand.java | 3 --- 4 files changed, 23 insertions(+), 26 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index cc97f00c93..f1c80b18f7 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -31,9 +31,7 @@ public final class BanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); /** - * Creates an instance of the ban command. - * - * @see BanCommand + * Constructs an instance */ public BanCommand() { super("ban", "Bans the given user from the server", SlashCommandVisibility.GUILD); @@ -49,9 +47,7 @@ public BanCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null"); - Member target = userOption.getAsMember(); - Member author = Objects.requireNonNull(event.getMember(), "The author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") @@ -76,7 +72,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - banUser(userOption.getAsUser(), author, reason, deleteHistoryDays, event.getGuild(), event); + banUser(userOption.getAsUser(), author, reason, deleteHistoryDays, guild, event); } private static void banUser(@NotNull User target, @NotNull Member author, @@ -103,17 +99,17 @@ private static void banUser(@NotNull User target, @NotNull Member author, target.getIdLong(), deleteHistoryDays, reason); } - private static boolean handleCanInteractWithTarget(@NotNull Member targetMember, - @NotNull Member bot, @NotNull Member author, @NotNull SlashCommandEvent event) { - String targetTag = targetMember.getUser().getAsTag(); - if (!author.canInteract(targetMember)) { + private static boolean handleCanInteractWithTarget(@NotNull Member target, @NotNull Member bot, + @NotNull Member author, @NotNull SlashCommandEvent event) { + String targetTag = target.getUser().getAsTag(); + if (!author.canInteract(target)) { event.reply("The user " + targetTag + " is too powerful for you to ban.") .setEphemeral(true) .queue(); return false; } - if (!bot.canInteract(targetMember)) { + if (!bot.canInteract(target)) { event.reply("The user " + targetTag + " is too powerful for me to ban.") .setEphemeral(true) .queue(); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 8655caa839..3c75d763cf 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -29,8 +29,6 @@ public final class KickCommand extends SlashCommandAdapter { /** * Constructs an instance - * - * @see KickCommand */ public KickCommand() { super("kick", "Kicks the given user from the server", SlashCommandVisibility.GUILD); @@ -43,15 +41,15 @@ public KickCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { OptionMapping userOption = Objects.requireNonNull(event.getOption(USER_OPTION), "The target is null"); - Member target = userOption.getAsMember(); - Member author = Objects.requireNonNull(event.getMember(), "The author is null"); String reason = Objects.requireNonNull(event.getOption(REASON_OPTION), "The reason is null") .getAsString(); - Member bot = Objects.requireNonNull(event.getGuild(), "The guild is null").getSelfMember(); + + Guild guild = event.getGuild(); + Member bot = guild.getSelfMember(); if (!author.hasPermission(Permission.KICK_MEMBERS)) { event.reply( @@ -91,7 +89,7 @@ public void onSlashCommand(@NotNull SlashCommandEvent event) { return; } - kickUser(target, author, reason, event.getGuild(), event); + kickUser(target, author, reason, guild, event); } private static void kickUser(@NotNull Member target, @NotNull Member author, diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 2e223764cf..3cdb3c136b 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -5,6 +5,10 @@ import net.dv8tion.jda.api.events.interaction.SlashCommandEvent; import org.jetbrains.annotations.NotNull; +/** + * This contains if statements that are common in all the moderation commands suck se the if + * statement for the reason length + */ public enum ModerationUtils { ; @@ -15,13 +19,15 @@ public enum ModerationUtils { private static final int REASON_MAX_LENGTH = 512; /** - * @param reason The Boolean reasonLimit will check if the reason is above the provided limit. - *
- * If it is it will throw an error and will tell the user that the reason can not be over - * the {@link ModerationUtils#REASON_MAX_LENGTH}
- * If the reason is under the limit it will pass and will allow the command to continue. + * This boolean checks if the reason that the user has entered violates the max character length + * or not.
+ * If it does the bot will tell the user has violated the mex character length and will + * terminate the command
+ * If it does bot the bot will be allowed to continue running the command. + * + * @param reason the reason of the action such as banning. + * @throws IllegalArgumentException if the reason is over 512 characters. * - * @return {@link ModerationUtils#REASON_MAX_LENGTH} */ public static boolean handleReason(@NotNull String reason, @NotNull SlashCommandEvent event) { if (reason.length() <= REASON_MAX_LENGTH) { diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 0c76a81369..27709d5ccd 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -27,8 +27,6 @@ public final class UnbanCommand extends SlashCommandAdapter { /** * Constructs an instance - * - * @see UnbanCommand */ public UnbanCommand() { super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); @@ -41,7 +39,6 @@ public UnbanCommand() { public void onSlashCommand(@NotNull SlashCommandEvent event) { User target = Objects.requireNonNull(event.getOption(USER_OPTION), "The user is null") .getAsUser(); - Member author = Objects.requireNonNull(event.getMember(), "The author is null"); if (!author.hasPermission(Permission.BAN_MEMBERS)) { From 4d9dce62c087b329c8ee62c3dabb1dbee0b7b7f0 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 2 Nov 2021 13:24:11 +0000 Subject: [PATCH 181/182] Fixed most of the commands. I still have to improve the javadoc in the ModerationUtils class --- .../togetherjava/tjbot/commands/moderation/BanCommand.java | 2 +- .../togetherjava/tjbot/commands/moderation/KickCommand.java | 2 +- .../tjbot/commands/moderation/ModerationUtils.java | 5 ++--- .../togetherjava/tjbot/commands/moderation/UnbanCommand.java | 2 +- 4 files changed, 5 insertions(+), 6 deletions(-) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java index f1c80b18f7..e3776ea3c6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java @@ -31,7 +31,7 @@ public final class BanCommand extends SlashCommandAdapter { private static final Logger logger = LoggerFactory.getLogger(BanCommand.class); /** - * Constructs an instance + * Constructs an instance. */ public BanCommand() { super("ban", "Bans the given user from the server", SlashCommandVisibility.GUILD); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java index 3c75d763cf..d887bb8472 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/KickCommand.java @@ -28,7 +28,7 @@ public final class KickCommand extends SlashCommandAdapter { private static final String REASON_OPTION = "reason"; /** - * Constructs an instance + * Constructs an instance. */ public KickCommand() { super("kick", "Kicks the given user from the server", SlashCommandVisibility.GUILD); diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 3cdb3c136b..57153479c6 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -6,8 +6,7 @@ import org.jetbrains.annotations.NotNull; /** - * This contains if statements that are common in all the moderation commands suck se the if - * statement for the reason length + * Utility class offering helpers revolving around user moderation, such as banning or kicking. */ public enum ModerationUtils { ; @@ -21,7 +20,7 @@ public enum ModerationUtils { /** * This boolean checks if the reason that the user has entered violates the max character length * or not.
- * If it does the bot will tell the user has violated the mex character length and will + * If it does the bot will tell the user they have violated the mex character length and will * terminate the command
* If it does bot the bot will be allowed to continue running the command. * diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java index 27709d5ccd..c11e6474c0 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/UnbanCommand.java @@ -26,7 +26,7 @@ public final class UnbanCommand extends SlashCommandAdapter { private static final String REASON_OPTION = "reason"; /** - * Constructs an instance + * Constructs an instance. */ public UnbanCommand() { super("unban", "Unbans a given user", SlashCommandVisibility.GUILD); From 02e48034bd2c5eb67dfc9cb92f1f47727f61a956 Mon Sep 17 00:00:00 2001 From: Yusuf Arfan Ismail Date: Tue, 2 Nov 2021 13:46:32 +0000 Subject: [PATCH 182/182] addressed to the second build point. --- .../togetherjava/tjbot/commands/moderation/ModerationUtils.java | 1 + 1 file changed, 1 insertion(+) diff --git a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java index 57153479c6..d35963b9b3 100644 --- a/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java +++ b/application/src/main/java/org/togetherjava/tjbot/commands/moderation/ModerationUtils.java @@ -25,6 +25,7 @@ public enum ModerationUtils { * If it does bot the bot will be allowed to continue running the command. * * @param reason the reason of the action such as banning. + * @param event This is used to be able to use slash command actions such as event.reply(); * @throws IllegalArgumentException if the reason is over 512 characters. * */