From 103f6ce538152561ee143b9371b64d561c67c67d Mon Sep 17 00:00:00 2001 From: floppydiskette Date: Sun, 17 Nov 2024 18:49:21 +0000 Subject: [PATCH] Add timeout command --- .../doki/commands/moderation/Timeout.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 src/main/java/net/hypr/doki/commands/moderation/Timeout.java diff --git a/src/main/java/net/hypr/doki/commands/moderation/Timeout.java b/src/main/java/net/hypr/doki/commands/moderation/Timeout.java new file mode 100644 index 0000000..fbce85d --- /dev/null +++ b/src/main/java/net/hypr/doki/commands/moderation/Timeout.java @@ -0,0 +1,45 @@ +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.UserPermissions; +import com.freya02.botcommands.api.application.ApplicationCommand; +import com.freya02.botcommands.api.application.annotations.AppOption; +import com.freya02.botcommands.api.application.slash.GuildSlashEvent; +import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand; +import net.dv8tion.jda.api.Permission; +import net.dv8tion.jda.api.entities.Member; +import net.hypr.doki.utils.DurationUtils; + +import java.time.Duration; +import java.time.OffsetDateTime; + +@CommandMarker +@BotPermissions(Permission.MODERATE_MEMBERS) +@UserPermissions(Permission.MODERATE_MEMBERS) +public class Timeout extends ApplicationCommand { + @JDASlashCommand( + name = "timeout", + subcommand = "set", + description = "Times out a member" + ) + public void mute(GuildSlashEvent event, + @AppOption(name = "member") Member member, + @AppOption(name = "duration", description = "ex: 2h5m, must be between 1h and 7d") String duration) { + Duration timeoutDuration = DurationUtils.parseDuration(duration); + member.timeoutFor(timeoutDuration).queue(); + event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue(); + } + + @JDASlashCommand( + name = "timeout", + subcommand = "cancel", + description = "Cancels the specified users timeout" + ) + public void cancelMute(GuildSlashEvent event, + @AppOption(name = "member") Member member) { + OffsetDateTime timeoutEnd = member.getTimeOutEnd(); + member.removeTimeout().queue(); + event.replyFormat("Removed %s's timeout (%s remaining)", member.getAsMention(), DurationUtils.getTimeDifference(timeoutEnd)).queue(); + } +}