Add timeout command

This commit is contained in:
floppydiskette 2024-11-17 18:49:21 +00:00
parent 33457e8270
commit 103f6ce538
Signed by: fwoppydwisk
SSH key fingerprint: SHA256:Hqn452XQ1ETzUt/FthJu6+OFkS4NBxCv5VQSEvuk7CE

View file

@ -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();
}
}