Skip to content

Commit df0e45b

Browse files
Fixed /purge and made the amount of messages to delete required
1 parent e985696 commit df0e45b

File tree

2 files changed

+12
-20
lines changed

2 files changed

+12
-20
lines changed

src/main/java/net/javadiscord/javabot/systems/moderation/PurgeCommand.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import net.javadiscord.javabot.Bot;
88
import net.javadiscord.javabot.command.ResponseException;
99
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;
1112
import net.javadiscord.javabot.util.TimeUtils;
1213

1314
import javax.annotation.Nullable;
@@ -23,32 +24,23 @@
2324
/**
2425
* This command deletes messages from a channel.
2526
*/
26-
public class PurgeCommand extends ModerateUserCommand {
27-
27+
public class PurgeCommand extends ModerateCommand {
2828
@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) {
3630
OptionMapping amountOption = event.getOption("amount");
3731
OptionMapping userOption = event.getOption("user");
38-
OptionMapping archiveOption = event.getOption("archive");
32+
boolean archive = event.getOption("archive", true, OptionMapping::getAsBoolean);
3933

34+
ModerationConfig config = Bot.config.get(event.getGuild()).getModeration();
4035
Long amount = (amountOption == null) ? null : amountOption.getAsLong();
4136
User user = (userOption == null) ? null : userOption.getAsUser();
42-
boolean archive = archiveOption != null && archiveOption.getAsBoolean();
4337
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.");
4740
}
48-
4941
Bot.asyncPool.submit(() -> this.purge(amount, user, archive, event.getTextChannel(), config.getLogChannel()));
5042
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 ");
5244
if (user != null) {
5345
sb.append("by the user ").append(user.getAsTag()).append(' ');
5446
}

src/main/resources/commands/slash/staff.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -238,15 +238,15 @@
238238
id: moderation.staffRoleId
239239
options:
240240
- name: amount
241-
description: Number of messages to remove. If left blank, all messages will be removed.
241+
description: Number of messages to remove.
242242
type: INTEGER
243-
required: false
243+
required: true
244244
- name: user
245245
description: The user whose messages to remove. If left blank, messages from any user are removed.
246246
type: USER
247247
required: false
248248
- name: archive
249-
description: If true, save removed messages in an archive.
249+
description: Whether the removed messages should be saved in an archive. This defaults to true, if left blank.
250250
type: BOOLEAN
251251
required: false
252252
handler: net.javadiscord.javabot.systems.moderation.PurgeCommand

0 commit comments

Comments
 (0)