changed parameter for slowmode command to be a duration string instead of just seconds

added exception to duration parsing, in case there is a unknown duration indicator
This commit is contained in:
Sheldan
2020-04-21 22:20:39 +02:00
parent ff8817f765
commit 1a74924850
7 changed files with 32 additions and 5 deletions
@@ -6,6 +6,7 @@ import dev.sheldan.abstracto.core.command.config.HelpInfo;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.config.Parameter;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.utils.ParseUtils;
import dev.sheldan.abstracto.moderation.Moderation;
import dev.sheldan.abstracto.moderation.config.ModerationFeatures;
import dev.sheldan.abstracto.moderation.service.SlowModeService;
@@ -26,20 +27,26 @@ public class SlowMode extends AbstractConditionableCommand {
@Override
public CommandResult execute(CommandContext commandContext) {
TextChannel channel;
long seconds = (Long) commandContext.getParameters().getParameters().get(0);
String durationString = (String) commandContext.getParameters().getParameters().get(0);
Duration duration;
if(durationString.equalsIgnoreCase("off")) {
duration = Duration.ZERO;
} else {
duration = ParseUtils.parseDuration(durationString);
}
if(commandContext.getParameters().getParameters().size() == 2) {
channel = (TextChannel) commandContext.getParameters().getParameters().get(1);
} else {
channel = commandContext.getChannel();
}
slowModeService.setSlowMode(channel, Duration.ofSeconds(seconds));
slowModeService.setSlowMode(channel, duration);
return CommandResult.fromSuccess();
}
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder().name("seconds").type(Long.class).optional(false).build());
parameters.add(Parameter.builder().name("duration").type(String.class).optional(false).build());
parameters.add(Parameter.builder().name("channel").type(TextChannel.class).optional(true).build());
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
@@ -28,6 +28,11 @@ public class SlowModeServiceBean implements SlowModeService {
channel.getManager().setSlowmode((int) seconds).queue();
}
@Override
public void disableSlowMOde(TextChannel channel) {
setSlowMode(channel, Duration.ZERO);
}
@Override
public void setSlowMode(AChannel channel, Duration duration) {
Optional<TextChannel> textChannelOptional = botService.getTextChannelFromServer(channel.getServer().getId(), channel.getId());
@@ -1 +1 @@
Sets the slow mode of the the current (or given channel) to the given seconds.
Sets the slow mode of the the current (or given channel) to the given duration.
@@ -1 +1 @@
Sets the slow mode of the the current (or given channel) to the given seconds.
Sets the slow mode of the the current (or given channel) to the given duration.
@@ -7,5 +7,6 @@ import java.time.Duration;
public interface SlowModeService {
void setSlowMode(TextChannel channel, Duration duration);
void disableSlowMOde(TextChannel channel);
void setSlowMode(AChannel channel, Duration duration);
}