mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-19 20:21:14 +00:00
fixed some code smells
This commit is contained in:
@@ -4,6 +4,10 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
|
||||
public class Constants {
|
||||
|
||||
private Constants() {
|
||||
|
||||
}
|
||||
|
||||
@Value("${abstracto.parameter.lowerBound}")
|
||||
public static int PARAMETER_LIMIT = 0;
|
||||
public static final int PARAMETER_LIMIT = 0;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,8 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.listener.FeatureAware;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public interface Command extends FeatureAware {
|
||||
|
||||
CommandResult execute(CommandContext commandContext);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package dev.sheldan.abstracto.core.command;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class UtilityModuleInterface implements ModuleInterface {
|
||||
|
||||
public static final String UTILITY = "utility";
|
||||
|
||||
@Override
|
||||
public ModuleInfo getInfo() {
|
||||
return ModuleInfo.builder().name(UTILITY).description("General utilities").build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getParentModule() {
|
||||
return "default";
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,6 @@ public abstract class AbstractConditionableCommand implements ConditionalCommand
|
||||
@Autowired
|
||||
protected CommandDisabledCondition commandDisabledCondition;
|
||||
|
||||
@Autowired
|
||||
protected ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
protected CommandDisallowedCondition commandDisallowedCondition;
|
||||
|
||||
|
||||
@@ -5,19 +5,14 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.models.InsufficientPermissionMessage;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommandInAServer;
|
||||
import dev.sheldan.abstracto.core.command.service.ChannelGroupCommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.concurrent.locks.Condition;
|
||||
|
||||
@Component
|
||||
public class CommandDisallowedCondition implements CommandCondition {
|
||||
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.config;
|
||||
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInfo;
|
||||
|
||||
public interface ModuleInterface {
|
||||
ModuleInfo getInfo();
|
||||
String getParentModule();
|
||||
|
||||
@@ -8,9 +8,9 @@ import java.util.HashMap;
|
||||
|
||||
public class IncorrectParameter extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Command command;
|
||||
private String parameterName;
|
||||
private Class clazz;
|
||||
private final Command command;
|
||||
private final String parameterName;
|
||||
private final Class clazz;
|
||||
|
||||
public IncorrectParameter(String s, Command command, Class expected, String parameterName) {
|
||||
super(s);
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.HashMap;
|
||||
@Getter
|
||||
public class InsufficientParameters extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Command command;
|
||||
private String parameterName;
|
||||
private final Command command;
|
||||
private final String parameterName;
|
||||
|
||||
public InsufficientParameters(String s, Command command, String parameterName) {
|
||||
super(s);
|
||||
|
||||
@@ -9,10 +9,10 @@ import java.util.HashMap;
|
||||
public class ParameterTooLong extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
|
||||
private Command command;
|
||||
private String parameterName;
|
||||
private Integer actualLength;
|
||||
private Integer maximumLength;
|
||||
private final Command command;
|
||||
private final String parameterName;
|
||||
private final Integer actualLength;
|
||||
private final Integer maximumLength;
|
||||
|
||||
public ParameterTooLong(String s, Command command, String parameterName, Integer actualLength, Integer maximumLength) {
|
||||
super(s);
|
||||
|
||||
@@ -9,6 +9,10 @@ import java.lang.reflect.Method;
|
||||
@Slf4j
|
||||
public class ContextConverter {
|
||||
|
||||
private ContextConverter() {
|
||||
|
||||
}
|
||||
|
||||
public static <T extends UserInitiatedServerContext> UserInitiatedServerContext fromCommandContext(CommandContext commandContext, Class<T> clazz) {
|
||||
Method m = null;
|
||||
try {
|
||||
|
||||
@@ -4,7 +4,6 @@ import dev.sheldan.abstracto.core.models.database.AFeature;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name = "command")
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class FeatureNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String feature;
|
||||
private List<String> availableFeatures;
|
||||
private final String feature;
|
||||
private final List<String> availableFeatures;
|
||||
|
||||
public FeatureNotFoundException(String message, String feature, List<String> availableFeatures) {
|
||||
super(message);
|
||||
|
||||
@@ -4,7 +4,6 @@ import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Entity
|
||||
@Table(name="channelGroup")
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.core.models.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.SnowFlake;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@@ -4,13 +4,14 @@ import dev.sheldan.abstracto.core.models.SnowFlake;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Table(name="role")
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class ARole implements SnowFlake {
|
||||
public class ARole implements SnowFlake, Serializable {
|
||||
|
||||
@Id
|
||||
@Getter
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.models.SnowFlake;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -13,7 +14,7 @@ import java.util.List;
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Getter
|
||||
public class AServer implements SnowFlake {
|
||||
public class AServer implements SnowFlake, Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.sheldan.abstracto.core.models.database;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
|
||||
@Entity
|
||||
@Getter
|
||||
@@ -10,7 +11,7 @@ import javax.persistence.*;
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AUserInAServer {
|
||||
public class AUserInAServer implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@@ -3,8 +3,6 @@ package dev.sheldan.abstracto.core.models.database;
|
||||
import lombok.*;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
@Table(name="posttarget")
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import dev.sheldan.abstracto.core.models.database.AFeatureFlag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@@ -28,5 +28,6 @@ public interface BotService {
|
||||
Optional<TextChannel> getTextChannelFromServer(Guild serverId, Long textChannelId);
|
||||
Optional<TextChannel> getTextChannelFromServer(Long serverId, Long textChannelId);
|
||||
Optional<Guild> getGuildById(Long serverId);
|
||||
Guild getGuildByIdNullable(Long serverId);
|
||||
void shutdown();
|
||||
}
|
||||
|
||||
@@ -7,7 +7,6 @@ import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface MessageService {
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
package dev.sheldan.abstracto.core.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.ConfigurationException;
|
||||
import dev.sheldan.abstracto.core.exception.PostTargetException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
|
||||
@@ -10,6 +10,10 @@ import java.util.Optional;
|
||||
|
||||
public class EmoteUtils {
|
||||
|
||||
private EmoteUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static boolean isReactionEmoteAEmote(MessageReaction.ReactionEmote reaction, AEmote emote, Emote emoteInGuild) {
|
||||
if(reaction.isEmote() && emote.getCustom()) {
|
||||
if(emoteInGuild != null) {
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
package dev.sheldan.abstracto.core.utils;
|
||||
|
||||
public class MessageUtils {
|
||||
|
||||
private MessageUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static String buildMessageUrl(Long serverId, Long channelId, Long messageId) {
|
||||
return String.format("https://discordapp.com/channels/%s/%s/%s", serverId, channelId, messageId);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,10 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class ParseUtils {
|
||||
|
||||
private ParseUtils() {
|
||||
|
||||
}
|
||||
|
||||
private static Pattern messageRegex = Pattern.compile("(?<number>\\d+)(?<unit>[ywdhms]+)");
|
||||
|
||||
public static Duration parseDuration(String textToParseFrom) {
|
||||
|
||||
@@ -53,11 +53,11 @@ public class ContextUtilsTest {
|
||||
@Test
|
||||
public void testFromMessage() {
|
||||
PingModel pingModel = (PingModel) classToTest.fromMessage(buildCachedMessage(), PingModel.class);
|
||||
assertEquals(pingModel.getUser().getId(), AUTHOR_ID);
|
||||
assertEquals(pingModel.getAUserInAServer().getUserReference().getId(), AUTHOR_ID);
|
||||
assertEquals(pingModel.getAUserInAServer().getServerReference().getId(), SERVER_ID);
|
||||
assertEquals(pingModel.getServer().getId(), SERVER_ID);
|
||||
assertEquals(pingModel.getChannel().getId(), CHANNEL_ID);
|
||||
assertEquals(AUTHOR_ID, pingModel.getUser().getId());
|
||||
assertEquals(AUTHOR_ID, pingModel.getAUserInAServer().getUserReference().getId());
|
||||
assertEquals(SERVER_ID, pingModel.getAUserInAServer().getServerReference().getId());
|
||||
assertEquals(SERVER_ID, pingModel.getServer().getId());
|
||||
assertEquals(CHANNEL_ID, pingModel.getChannel().getId());
|
||||
}
|
||||
|
||||
private CachedMessage buildCachedMessage() {
|
||||
|
||||
Reference in New Issue
Block a user