|
7 | 7 | import net.javadiscord.javabot.Bot; |
8 | 8 | import net.javadiscord.javabot.command.ResponseException; |
9 | 9 | import net.javadiscord.javabot.command.Responses; |
10 | | -import net.javadiscord.javabot.command.moderation.ModerateUserCommand; |
| 10 | +import net.javadiscord.javabot.command.moderation.ModerateCommand; |
| 11 | +import net.javadiscord.javabot.data.config.guild.ModerationConfig; |
11 | 12 | import net.javadiscord.javabot.util.TimeUtils; |
12 | 13 |
|
13 | 14 | import javax.annotation.Nullable; |
|
23 | 24 | /** |
24 | 25 | * This command deletes messages from a channel. |
25 | 26 | */ |
26 | | -public class PurgeCommand extends ModerateUserCommand { |
27 | | - |
| 27 | +public class PurgeCommand extends ModerateCommand { |
28 | 28 | @Override |
29 | | - protected ReplyCallbackAction handleModerationActionCommand(SlashCommandInteractionEvent event, Member commandUser, Member target) throws ResponseException { |
30 | | - Member member = event.getMember(); |
31 | | - if (member == null) { |
32 | | - return Responses.warning(event, "This command can only be used in a guild."); |
33 | | - } |
34 | | - var config = Bot.config.get(event.getGuild()).getModeration(); |
35 | | - |
| 29 | + protected ReplyCallbackAction handleModerationCommand(SlashCommandInteractionEvent event, Member commandUser) { |
36 | 30 | OptionMapping amountOption = event.getOption("amount"); |
37 | 31 | OptionMapping userOption = event.getOption("user"); |
38 | | - OptionMapping archiveOption = event.getOption("archive"); |
| 32 | + boolean archive = event.getOption("archive", true, OptionMapping::getAsBoolean); |
39 | 33 |
|
| 34 | + ModerationConfig config = Bot.config.get(event.getGuild()).getModeration(); |
40 | 35 | Long amount = (amountOption == null) ? null : amountOption.getAsLong(); |
41 | 36 | User user = (userOption == null) ? null : userOption.getAsUser(); |
42 | | - boolean archive = archiveOption != null && archiveOption.getAsBoolean(); |
43 | 37 | int maxAmount = config.getPurgeMaxMessageCount(); |
44 | | - |
45 | | - if (amount != null && (amount < 1 || amount > maxAmount)) { |
46 | | - return Responses.warning(event, "Invalid amount. If specified, should be between 1 and " + maxAmount + ", inclusive."); |
| 38 | + if (amount == null || amount < 1 || amount > maxAmount) { |
| 39 | + return Responses.warning(event, "Invalid amount. Should be between 1 and " + maxAmount + ", inclusive."); |
47 | 40 | } |
48 | | - |
49 | 41 | Bot.asyncPool.submit(() -> this.purge(amount, user, archive, event.getTextChannel(), config.getLogChannel())); |
50 | 42 | StringBuilder sb = new StringBuilder(); |
51 | | - sb.append(amount != null ? (amount > 1 ? "Up to " + amount + " messages " : "1 message ") : "All messages "); |
| 43 | + sb.append(amount > 1 ? "Up to " + amount + " messages " : "1 message "); |
52 | 44 | if (user != null) { |
53 | 45 | sb.append("by the user ").append(user.getAsTag()).append(' '); |
54 | 46 | } |
|
0 commit comments