Compare commits
No commits in common. "master" and "v1.0.3" have entirely different histories.
4 changed files with 5 additions and 31 deletions
|
@ -1,14 +1,7 @@
|
||||||
<component name="InspectionProjectProfileManager">
|
<component name="InspectionProjectProfileManager">
|
||||||
<profile version="1.0">
|
<profile version="1.0">
|
||||||
<option name="myName" value="Project Default" />
|
<option name="myName" value="Project Default" />
|
||||||
<inspection_tool class="GrazieInspection" enabled="false" level="GRAMMAR_ERROR" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="InstantiationOfUtilityClass" enabled="false" level="WARNING" enabled_by_default="false" />
|
<inspection_tool class="InstantiationOfUtilityClass" enabled="false" level="WARNING" enabled_by_default="false" />
|
||||||
<inspection_tool class="LanguageDetectionInspection" enabled="false" level="WARNING" enabled_by_default="false" />
|
|
||||||
<inspection_tool class="SpellCheckingInspection" enabled="false" level="TYPO" enabled_by_default="false">
|
|
||||||
<option name="processCode" value="true" />
|
|
||||||
<option name="processLiterals" value="true" />
|
|
||||||
<option name="processComments" value="true" />
|
|
||||||
</inspection_tool>
|
|
||||||
<inspection_tool class="XmlHighlighting" enabled="false" level="ERROR" enabled_by_default="false" />
|
<inspection_tool class="XmlHighlighting" enabled="false" level="ERROR" enabled_by_default="false" />
|
||||||
</profile>
|
</profile>
|
||||||
</component>
|
</component>
|
|
@ -2,7 +2,6 @@ package net.hypr.doki.commands.moderation;
|
||||||
|
|
||||||
import com.freya02.botcommands.api.annotations.BotPermissions;
|
import com.freya02.botcommands.api.annotations.BotPermissions;
|
||||||
import com.freya02.botcommands.api.annotations.CommandMarker;
|
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.annotations.UserPermissions;
|
||||||
import com.freya02.botcommands.api.application.ApplicationCommand;
|
import com.freya02.botcommands.api.application.ApplicationCommand;
|
||||||
import com.freya02.botcommands.api.application.annotations.AppOption;
|
import com.freya02.botcommands.api.application.annotations.AppOption;
|
||||||
|
@ -10,12 +9,10 @@ import com.freya02.botcommands.api.application.slash.GuildSlashEvent;
|
||||||
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
import com.freya02.botcommands.api.application.slash.annotations.JDASlashCommand;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Member;
|
import net.dv8tion.jda.api.entities.Member;
|
||||||
import net.dv8tion.jda.api.exceptions.HierarchyException;
|
|
||||||
import net.hypr.doki.utils.DurationUtils;
|
import net.hypr.doki.utils.DurationUtils;
|
||||||
|
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.time.OffsetDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
@CommandMarker
|
@CommandMarker
|
||||||
@BotPermissions(Permission.MODERATE_MEMBERS)
|
@BotPermissions(Permission.MODERATE_MEMBERS)
|
||||||
|
@ -28,21 +25,13 @@ public class Timeout extends ApplicationCommand {
|
||||||
)
|
)
|
||||||
public void timeout(GuildSlashEvent event,
|
public void timeout(GuildSlashEvent event,
|
||||||
@AppOption(name = "member") Member member,
|
@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);
|
Duration timeoutDuration = DurationUtils.parseDuration(duration);
|
||||||
if (!DurationUtils.isDurationBetween(timeoutDuration, Duration.ofMinutes(1), Duration.ofDays(7))) {
|
if (!DurationUtils.isDurationBetween(timeoutDuration, Duration.ofMinutes(1), Duration.ofDays(7))) {
|
||||||
event.replyFormat("Invalid duration %s!, must be between 1m and 7d", duration).queue();
|
event.replyFormat("Invalid duration %s!, must be between 1m and 7d", duration).queue();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
member.timeoutFor(timeoutDuration).queue();
|
||||||
try {
|
|
||||||
member.timeoutFor(timeoutDuration)
|
|
||||||
.reason(Objects.requireNonNullElse(reason, "No reason provided")).queue();
|
|
||||||
} catch (HierarchyException ex) {
|
|
||||||
event.replyFormat("Failed to time out %s (member has roles above me!)", member.getAsMention()).setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue();
|
event.replyFormat("Timed out %s for %s", member.getAsMention(), duration).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,16 +41,9 @@ public class Timeout extends ApplicationCommand {
|
||||||
description = "Cancels the specified users timeout"
|
description = "Cancels the specified users timeout"
|
||||||
)
|
)
|
||||||
public void cancelTimeout(GuildSlashEvent event,
|
public void cancelTimeout(GuildSlashEvent event,
|
||||||
@AppOption(name = "member") Member member,
|
@AppOption(name = "member") Member member) {
|
||||||
@Optional @AppOption(name = "reason") String reason) {
|
|
||||||
OffsetDateTime timeoutEnd = member.getTimeOutEnd();
|
OffsetDateTime timeoutEnd = member.getTimeOutEnd();
|
||||||
try {
|
member.removeTimeout().queue();
|
||||||
member.removeTimeout()
|
|
||||||
.reason(Objects.requireNonNullElse(reason, "No reason provided")).queue();
|
|
||||||
} catch (HierarchyException ex) {
|
|
||||||
event.replyFormat("Failed to remove %s's timeout (member has roles above me!)", member.getAsMention()).setEphemeral(true).queue();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
event.replyFormat("Removed %s's timeout (%s remaining)", member.getAsMention(), DurationUtils.getTimeDifference(timeoutEnd)).queue();
|
event.replyFormat("Removed %s's timeout (%s remaining)", member.getAsMention(), DurationUtils.getTimeDifference(timeoutEnd)).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,7 @@ import java.util.Objects;
|
||||||
|
|
||||||
@CommandMarker
|
@CommandMarker
|
||||||
@BotPermissions(Permission.MESSAGE_SEND_POLLS)
|
@BotPermissions(Permission.MESSAGE_SEND_POLLS)
|
||||||
@UserPermissions(Permission.MESSAGE_MANAGE)
|
@UserPermissions(Permission.MESSAGE_SEND_POLLS)
|
||||||
public class Poll extends ApplicationCommand {
|
public class Poll extends ApplicationCommand {
|
||||||
@JDASlashCommand(
|
@JDASlashCommand(
|
||||||
name = "poll",
|
name = "poll",
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class DurationUtils {
|
||||||
.plusSeconds(seconds);
|
.plusSeconds(seconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("BooleanMethodIsAlwaysInverted")
|
|
||||||
public static boolean isDurationBetween(Duration target, Duration lowerThreshold, Duration upperThreshold) {
|
public static boolean isDurationBetween(Duration target, Duration lowerThreshold, Duration upperThreshold) {
|
||||||
if (target == lowerThreshold || target == upperThreshold) return true;
|
if (target == lowerThreshold || target == upperThreshold) return true;
|
||||||
return !target.isNegative() &&
|
return !target.isNegative() &&
|
||||||
|
|
Loading…
Reference in a new issue