Skip to content

Commit 18347fa

Browse files
committed
Bugfix with temp ban/mute using weeks/months
* cant Instant#plus weeks and months * also some improvements to the option order (UX) * added fixme for code duplication
1 parent db38285 commit 18347fa

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

application/src/main/java/org/togetherjava/tjbot/commands/moderation/BanCommand.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public final class BanCommand extends SlashCommandAdapter {
4848
private static final String ACTION_VERB = "ban";
4949
private static final String PERMANENT_DURATION = "permanent";
5050
private static final List<String> DURATIONS = List.of(PERMANENT_DURATION, "1 hour", "3 hours",
51-
"1 day", "2 days", "3 days", "7 days", "1 month");
51+
"1 day", "2 days", "3 days", "7 days", "30 days");
5252
private final Predicate<String> hasRequiredRole;
5353
private final ModerationActionsStore actionsStore;
5454

@@ -151,15 +151,13 @@ private static Optional<RestAction<InteractionHook>> handleNotAlreadyBannedRespo
151151
return Optional.empty();
152152
}
153153

154-
// 1 day, 1 days, 1 month, ...
154+
// 1 minute, 1 day, 2 days, ...
155155
String[] data = durationText.split(" ", 2);
156156
int duration = Integer.parseInt(data[0]);
157157
ChronoUnit unit = switch (data[1]) {
158158
case "minute", "minutes" -> ChronoUnit.MINUTES;
159159
case "hour", "hours" -> ChronoUnit.HOURS;
160160
case "day", "days" -> ChronoUnit.DAYS;
161-
case "week", "weeks" -> ChronoUnit.WEEKS;
162-
case "month", "months" -> ChronoUnit.MONTHS;
163161
default -> throw new IllegalArgumentException(
164162
"Unsupported ban duration: " + durationText);
165163
};

application/src/main/java/org/togetherjava/tjbot/commands/moderation/MuteCommand.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ public final class MuteCommand extends SlashCommandAdapter {
4040
private static final String COMMAND_NAME = "mute";
4141
private static final String ACTION_VERB = "mute";
4242
private static final String PERMANENT_DURATION = "permanent";
43-
private static final List<String> DURATIONS = List.of(PERMANENT_DURATION, "1 hour", "3 hours",
44-
"1 day", "2 days", "3 days", "7 days", "1 month");
43+
private static final List<String> DURATIONS = List.of("10 minutes", "30 minutes", "1 hour",
44+
"3 hours", "1 day", "3 days", "7 days", PERMANENT_DURATION);
4545
private final Predicate<String> hasRequiredRole;
4646
private final ModerationActionsStore actionsStore;
4747

@@ -106,21 +106,20 @@ private static RestAction<Boolean> sendDm(@NotNull ISnowflake target,
106106
target.getUser(), durationText + dmNoticeText, reason);
107107
}
108108

109+
// FIXME Code duplication with BanCommand, get rid of it
109110
private static @NotNull Optional<TemporaryMuteData> computeTemporaryMuteData(
110111
@NotNull String durationText) {
111112
if (PERMANENT_DURATION.equals(durationText)) {
112113
return Optional.empty();
113114
}
114115

115-
// 1 day, 1 days, 1 month, ...
116+
// 1 minute, 1 day, 2 days, ...
116117
String[] data = durationText.split(" ", 2);
117118
int duration = Integer.parseInt(data[0]);
118119
ChronoUnit unit = switch (data[1]) {
119120
case "minute", "minutes" -> ChronoUnit.MINUTES;
120121
case "hour", "hours" -> ChronoUnit.HOURS;
121122
case "day", "days" -> ChronoUnit.DAYS;
122-
case "week", "weeks" -> ChronoUnit.WEEKS;
123-
case "month", "months" -> ChronoUnit.MONTHS;
124123
default -> throw new IllegalArgumentException(
125124
"Unsupported mute duration: " + durationText);
126125
};

application/src/main/java/org/togetherjava/tjbot/commands/moderation/temp/TemporaryModerationRoutine.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
import org.togetherjava.tjbot.commands.moderation.ModerationActionsStore;
1313

1414
import java.time.Instant;
15-
import java.util.Collection;
16-
import java.util.Comparator;
1715
import java.util.Map;
1816
import java.util.Objects;
1917
import java.util.concurrent.Executors;

0 commit comments

Comments
 (0)