From 6663b08c8c7f9eb213f35d1212b23a385c205c9f Mon Sep 17 00:00:00 2001 From: floppydiskette Date: Sun, 24 Nov 2024 20:46:50 +0000 Subject: [PATCH 1/2] Fix some IntelliJ stuff --- .idea/inspectionProfiles/Project_Default.xml | 7 +++++++ src/main/java/net/hypr/doki/utils/DurationUtils.java | 1 + 2 files changed, 8 insertions(+) diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml index e28d6f3..41dbda4 100644 --- a/.idea/inspectionProfiles/Project_Default.xml +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -1,7 +1,14 @@ \ No newline at end of file diff --git a/src/main/java/net/hypr/doki/utils/DurationUtils.java b/src/main/java/net/hypr/doki/utils/DurationUtils.java index 208f8e9..2341fbb 100644 --- a/src/main/java/net/hypr/doki/utils/DurationUtils.java +++ b/src/main/java/net/hypr/doki/utils/DurationUtils.java @@ -47,6 +47,7 @@ public class DurationUtils { .plusSeconds(seconds); } + @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean isDurationBetween(Duration target, Duration lowerThreshold, Duration upperThreshold) { if (target == lowerThreshold || target == upperThreshold) return true; return !target.isNegative() && From 24961d3b17d2cb59adb63983fcbbfe972437e9db Mon Sep 17 00:00:00 2001 From: floppydiskette Date: Sun, 24 Nov 2024 20:47:12 +0000 Subject: [PATCH 2/2] Add reason parameter to /timeout --- .../java/net/hypr/doki/commands/moderation/Timeout.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/hypr/doki/commands/moderation/Timeout.java b/src/main/java/net/hypr/doki/commands/moderation/Timeout.java index 796178e..bcdab66 100644 --- a/src/main/java/net/hypr/doki/commands/moderation/Timeout.java +++ b/src/main/java/net/hypr/doki/commands/moderation/Timeout.java @@ -2,6 +2,7 @@ package net.hypr.doki.commands.moderation; import com.freya02.botcommands.api.annotations.BotPermissions; import com.freya02.botcommands.api.annotations.CommandMarker; +import com.freya02.botcommands.api.annotations.Optional; import com.freya02.botcommands.api.annotations.UserPermissions; import com.freya02.botcommands.api.application.ApplicationCommand; import com.freya02.botcommands.api.application.annotations.AppOption; @@ -13,6 +14,7 @@ import net.hypr.doki.utils.DurationUtils; import java.time.Duration; import java.time.OffsetDateTime; +import java.util.Objects; @CommandMarker @BotPermissions(Permission.MODERATE_MEMBERS) @@ -25,13 +27,15 @@ public class Timeout extends ApplicationCommand { ) public void timeout(GuildSlashEvent event, @AppOption(name = "member") Member member, - @AppOption(name = "duration", description = "ex: 2h5m, must be between 1m and 7d") String duration) { + @AppOption(name = "duration", description = "ex: 2h5m, must be between 1m and 7d") String duration, + @Optional @AppOption(name = "reason") String reason) { Duration timeoutDuration = DurationUtils.parseDuration(duration); if (!DurationUtils.isDurationBetween(timeoutDuration, Duration.ofMinutes(1), Duration.ofDays(7))) { event.replyFormat("Invalid duration %s!, must be between 1m and 7d", duration).queue(); return; } - member.timeoutFor(timeoutDuration).queue(); + member.timeoutFor(timeoutDuration) + .reason(Objects.requireNonNullElse(reason, "No reason provided")).queue(); event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue(); }