mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-24 13:44:33 +00:00
[AB-54] adding various command parameter handlers
removing old parameter length validation
This commit is contained in:
@@ -1,13 +0,0 @@
|
||||
package dev.sheldan.abstracto.core;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
public class Constants {
|
||||
|
||||
private Constants() {
|
||||
|
||||
}
|
||||
|
||||
@Value("${abstracto.parameter.lowerBound}")
|
||||
public static final int PARAMETER_LIMIT = 0;
|
||||
}
|
||||
@@ -19,7 +19,6 @@ public class Parameter implements Serializable {
|
||||
private boolean optional = false;
|
||||
@Builder.Default
|
||||
private boolean remainder = false;
|
||||
private Integer maxLength;
|
||||
@Builder.Default
|
||||
private Boolean templated = false;
|
||||
@Builder.Default
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ParameterTooLongExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class ParameterTooLongException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final ParameterTooLongExceptionModel model;
|
||||
|
||||
public ParameterTooLongException(Command command, String parameterName, Integer actualLength, Integer maximumLength) {
|
||||
super("Parameter was too long for command");
|
||||
this.model = ParameterTooLongExceptionModel
|
||||
.builder()
|
||||
.actualLength(actualLength)
|
||||
.maximumLength(maximumLength)
|
||||
.parameterName(parameterName)
|
||||
.command(command)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "parameter_too_long_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
|
||||
public interface CommandParameterHandler {
|
||||
boolean handles(Class clazz);
|
||||
Object handle(String input, CommandParameterIterators iterators, Class clazz, Message context);
|
||||
Integer getPriority();
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package dev.sheldan.abstracto.core.command.handler;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class CommandParameterIterators {
|
||||
private Iterator<TextChannel> channelIterator;
|
||||
private Iterator<Emote> emoteIterator;
|
||||
private Iterator<Member> memberIterator;
|
||||
private Iterator<Role> roleIterator;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ParameterTooLongExceptionModel implements Serializable {
|
||||
private final transient Command command;
|
||||
private final String parameterName;
|
||||
private final Integer actualLength;
|
||||
private final Integer maximumLength;
|
||||
}
|
||||
@@ -52,6 +52,9 @@ public class AChannel implements SnowFlake, Serializable {
|
||||
@Column
|
||||
private Boolean deleted;
|
||||
|
||||
@Transient
|
||||
private boolean fake;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
|
||||
@@ -44,6 +44,9 @@ public class ARole implements SnowFlake, Serializable {
|
||||
@Column(name = "updated")
|
||||
private Instant updated;
|
||||
|
||||
@Transient
|
||||
private boolean fake;
|
||||
|
||||
@PreUpdate
|
||||
private void onUpdate() {
|
||||
this.updated = Instant.now();
|
||||
|
||||
@@ -36,6 +36,9 @@ public class AServer implements SnowFlake, Serializable {
|
||||
@Column(name = "updated")
|
||||
private Instant updated;
|
||||
|
||||
@Transient
|
||||
private boolean fake;
|
||||
|
||||
@PreUpdate
|
||||
private void onUpdate() {
|
||||
this.updated = Instant.now();
|
||||
|
||||
@@ -40,4 +40,5 @@ public interface ChannelService {
|
||||
|
||||
CompletableFuture<TextChannel> createTextChannel(String name, AServer server, Long categoryId);
|
||||
Optional<TextChannel> getChannelFromAChannel(AChannel channel);
|
||||
AChannel getFakeChannelFromTextChannel(TextChannel textChannel);
|
||||
}
|
||||
|
||||
@@ -21,4 +21,5 @@ public interface EmoteService {
|
||||
Optional<CachedReaction> getReactionFromMessageByEmote(CachedMessage message, AEmote emote);
|
||||
boolean compareAEmote(AEmote a, AEmote b);
|
||||
AEmote getFakeEmote(Object object);
|
||||
AEmote getFakeEmoteFromEmote(Emote emote);
|
||||
}
|
||||
|
||||
@@ -27,4 +27,5 @@ public interface RoleService {
|
||||
boolean memberHasRole(Member member, ARole role);
|
||||
boolean isRoleInServer(ARole role);
|
||||
boolean canBotInteractWithRole(ARole role);
|
||||
ARole getFakeRoleFromRole(Role role);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ public class ParseUtils {
|
||||
private static List<String> validDuration = Arrays.asList("w", "d", "h", "m", "s");
|
||||
|
||||
public static Duration parseDuration(String textToParseFrom) {
|
||||
if(textToParseFrom == null || textToParseFrom.isEmpty()) {
|
||||
throw new DurationFormatException("", validDuration);
|
||||
}
|
||||
Matcher matcher = ParseUtils.messageRegex.matcher(textToParseFrom);
|
||||
Duration start = Duration.ZERO;
|
||||
String rest = textToParseFrom;
|
||||
|
||||
Reference in New Issue
Block a user