mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-03 16:34:09 +00:00
addressed sonar code smells
This commit is contained in:
@@ -5,8 +5,6 @@ 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);
|
||||
|
||||
@@ -33,7 +33,7 @@ public class CommandDisallowedCondition implements CommandCondition {
|
||||
public ConditionResult shouldExecute(CommandContext context, Command command) {
|
||||
ACommand aCommand = commandService.findCommandByName(command.getConfiguration().getName());
|
||||
ACommandInAServer commandForServer = commandInServerManagementService.getCommandForServer(aCommand, context.getUserInitiatedContext().getServer());
|
||||
if(!commandForServer.getRestricted()) {
|
||||
if(Boolean.FALSE.equals(commandForServer.getRestricted())) {
|
||||
return ConditionResult.builder().result(true).build();
|
||||
}
|
||||
for (ARole role : commandForServer.getAllowedRoles()) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.execution;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
@@ -30,6 +31,6 @@ public class ContextConverter {
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Failed to execute builder method", e);
|
||||
}
|
||||
throw new RuntimeException("Failed to create model from context");
|
||||
throw new AbstractoRunTimeException("Failed to create model from context");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Entity
|
||||
@@ -15,7 +16,7 @@ import java.util.Objects;
|
||||
@Getter
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ACommand {
|
||||
public class ACommand implements Serializable {
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@@ -6,6 +6,7 @@ import lombok.*;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
@@ -17,7 +18,7 @@ import java.util.Objects;
|
||||
@NoArgsConstructor
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class ACommandInAServer {
|
||||
public class ACommandInAServer implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
|
||||
@@ -7,6 +7,7 @@ import lombok.NoArgsConstructor;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
@@ -19,7 +20,7 @@ import java.util.Objects;
|
||||
@Getter
|
||||
@Cacheable
|
||||
@org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
|
||||
public class AModule {
|
||||
public class AModule implements Serializable {
|
||||
|
||||
@Id
|
||||
@Column(name = "id")
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
|
||||
public interface CommandService {
|
||||
ACommand createCommand(String name, String moduleName, FeatureEnum featureEnum);
|
||||
Boolean doesCommandExist(String name);
|
||||
boolean doesCommandExist(String name);
|
||||
void allowCommandForRole(ACommand aCommand, ARole role);
|
||||
void allowFeatureForRole(FeatureEnum featureEnum, ARole role);
|
||||
void makeRoleImmuneForCommand(ACommand aCommand, ARole role);
|
||||
|
||||
@@ -8,5 +8,5 @@ public interface CommandManagementService {
|
||||
ACommand createCommand(String name, String moduleName, String featureName);
|
||||
ACommand createCommand(String name, AModule moduleName, AFeature feature);
|
||||
ACommand findCommandByName(String name);
|
||||
Boolean doesCommandExist(String name);
|
||||
boolean doesCommandExist(String name);
|
||||
}
|
||||
|
||||
@@ -6,12 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class CategoryNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long categoryId;
|
||||
private Long guildId;
|
||||
|
||||
public CategoryNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
private final Long categoryId;
|
||||
private final Long guildId;
|
||||
|
||||
public CategoryNotFoundException(Long categoryId, Long guildId) {
|
||||
super("");
|
||||
|
||||
@@ -6,12 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class ChannelNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long channelId;
|
||||
private Long guildId;
|
||||
|
||||
public ChannelNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
private final Long channelId;
|
||||
private final Long guildId;
|
||||
|
||||
public ChannelNotFoundException(Long channelId, Long guildId) {
|
||||
super("");
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
public class ConfigurationKeyNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String key;
|
||||
private final String key;
|
||||
|
||||
public ConfigurationKeyNotFoundException(String key) {
|
||||
super("");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class DurationFormatException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String invalidFormat;
|
||||
private List<String> validFormats;
|
||||
private final String invalidFormat;
|
||||
private final List<String> validFormats;
|
||||
|
||||
public DurationFormatException(String wrongFormat, List<String> validFormats) {
|
||||
super("");
|
||||
|
||||
@@ -3,11 +3,10 @@ package dev.sheldan.abstracto.core.exception;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EmoteNotDefinedException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String emoteKey;
|
||||
private final String emoteKey;
|
||||
|
||||
public EmoteNotDefinedException(String key) {
|
||||
super("");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class EmoteNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String emoteKey;
|
||||
private List<String> available;
|
||||
private final String emoteKey;
|
||||
private final List<String> available;
|
||||
|
||||
public EmoteNotFoundException(String key, List<String> availableEmotes) {
|
||||
super("");
|
||||
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.templating.Templatable;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GuildException extends AbstractoRunTimeException implements Templatable {
|
||||
private Long guildId;
|
||||
private final Long guildId;
|
||||
|
||||
public GuildException(String message, Long guildId) {
|
||||
super(message);
|
||||
|
||||
@@ -3,11 +3,10 @@ package dev.sheldan.abstracto.core.exception;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class PostTargetNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String postTargetKey;
|
||||
private final String postTargetKey;
|
||||
|
||||
public PostTargetNotFoundException(String key) {
|
||||
super("");
|
||||
|
||||
@@ -7,8 +7,8 @@ import java.util.List;
|
||||
|
||||
public class PostTargetNotValidException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String postTargetKey;
|
||||
private List<String> availableTargets;
|
||||
private final String postTargetKey;
|
||||
private final List<String> availableTargets;
|
||||
|
||||
public PostTargetNotValidException(String key, List<String> available) {
|
||||
super("");
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class RoleNotFoundInDBException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long roleId;
|
||||
private Long serverId;
|
||||
private final Long roleId;
|
||||
private final Long serverId;
|
||||
|
||||
public RoleNotFoundInDBException(Long roleId, Long serverId) {
|
||||
super("");
|
||||
|
||||
@@ -6,8 +6,8 @@ import java.util.HashMap;
|
||||
|
||||
public class RoleNotFoundInGuildException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long roleId;
|
||||
private Long serverId;
|
||||
private final Long roleId;
|
||||
private final Long serverId;
|
||||
|
||||
public RoleNotFoundInGuildException(Long roleId, Long serverId) {
|
||||
super("");
|
||||
|
||||
@@ -6,7 +6,7 @@ import java.util.HashMap;
|
||||
|
||||
public class UserInServerNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private Long userInServerId;
|
||||
private final Long userInServerId;
|
||||
|
||||
public UserInServerNotFoundException(Long userInServerId) {
|
||||
super("");
|
||||
|
||||
@@ -27,9 +27,7 @@ public abstract class AbstractConfigSetupStep implements SetupStep {
|
||||
|
||||
|
||||
protected Runnable getTimeoutRunnable(Long serverId, Long channelId) {
|
||||
return () -> {
|
||||
interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
};
|
||||
return () -> interactiveUtils.sendTimeoutMessage(serverId, channelId);
|
||||
}
|
||||
|
||||
protected boolean checkForExit(Message message) {
|
||||
|
||||
@@ -22,8 +22,6 @@ public class InteractiveUtils {
|
||||
public void sendTimeoutMessage(Long serverId, Long channelId) {
|
||||
String s = templateService.renderSimpleTemplate("setup_configuration_timeout");
|
||||
Optional<TextChannel> channelOptional = channelService.getTextChannelInGuild(serverId, channelId);
|
||||
channelOptional.ifPresent(channel -> {
|
||||
channelService.sendTextToChannelNoFuture(s, channel);
|
||||
});
|
||||
channelOptional.ifPresent(channel -> channelService.sendTextToChannelNoFuture(s, channel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package dev.sheldan.abstracto.core.models;
|
||||
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
@@ -5,7 +5,6 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.time.Instant;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -2,7 +2,6 @@ package dev.sheldan.abstracto.core.models.database;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.SnowFlake;
|
||||
import lombok.*;
|
||||
import net.dv8tion.jda.api.entities.ChannelType;
|
||||
import org.hibernate.annotations.CacheConcurrencyStrategy;
|
||||
|
||||
import javax.persistence.*;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AConfig implements Serializable {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer Id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
@@ -75,7 +75,7 @@ public class AConfig implements Serializable {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AConfig config = (AConfig) o;
|
||||
return Objects.equals(Id, config.Id) &&
|
||||
return Objects.equals(id, config.id) &&
|
||||
Objects.equals(name, config.name) &&
|
||||
Objects.equals(stringValue, config.stringValue) &&
|
||||
Objects.equals(doubleValue, config.doubleValue) &&
|
||||
@@ -84,6 +84,6 @@ public class AConfig implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(Id, name, stringValue, doubleValue, server);
|
||||
return Objects.hash(id, name, stringValue, doubleValue, server);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import java.time.Instant;
|
||||
public class ADefaultConfig implements Serializable {
|
||||
@javax.persistence.Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer Id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
|
||||
@@ -20,7 +20,7 @@ public class AEmote implements Serializable {
|
||||
|
||||
@javax.persistence.Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
private Integer Id;
|
||||
private Integer id;
|
||||
|
||||
@Column
|
||||
private String name;
|
||||
@@ -66,7 +66,7 @@ public class AEmote implements Serializable {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
AEmote emote = (AEmote) o;
|
||||
return Objects.equals(Id, emote.Id) &&
|
||||
return Objects.equals(id, emote.id) &&
|
||||
Objects.equals(name, emote.name) &&
|
||||
Objects.equals(emoteKey, emote.emoteKey) &&
|
||||
Objects.equals(emoteId, emote.emoteId) &&
|
||||
@@ -77,6 +77,6 @@ public class AEmote implements Serializable {
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(Id, name, emoteKey, emoteId, animated, custom, serverRef);
|
||||
return Objects.hash(id, name, emoteKey, emoteId, animated, custom, serverRef);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.models.template.commands.help;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.config.SingleLevelPackedModule;
|
||||
import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -5,7 +5,6 @@ import dev.sheldan.abstracto.core.models.cache.CachedReaction;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.entities.MessageReaction;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public interface MessageCache {
|
||||
|
||||
@@ -12,6 +12,6 @@ public interface PostTargetManagement {
|
||||
PostTarget getPostTarget(String name, AServer server);
|
||||
PostTarget getPostTarget(String name, Long serverId);
|
||||
Boolean postTargetExists(String name, AServer server);
|
||||
Boolean postTargetExists(String name, Long serverId);
|
||||
boolean postTargetExists(String name, Long serverId);
|
||||
PostTarget updatePostTarget(PostTarget target, AServer server, AChannel newTargetChannel);
|
||||
}
|
||||
|
||||
@@ -32,10 +32,10 @@ public class EmoteUtils {
|
||||
}
|
||||
|
||||
public static boolean compareAEmote(AEmote a, AEmote b) {
|
||||
if(a.getCustom() && b.getCustom()) {
|
||||
if(Boolean.TRUE.equals(a.getCustom()) && Boolean.TRUE.equals(b.getCustom())) {
|
||||
return a.getEmoteId().equals(b.getEmoteId());
|
||||
} else {
|
||||
if(!a.getCustom() && !b.getCustom()) {
|
||||
if(Boolean.FALSE.equals(a.getCustom()) && Boolean.FALSE.equals(b.getCustom())) {
|
||||
return a.getEmoteKey().equals(b.getEmoteKey());
|
||||
} else {
|
||||
return false;
|
||||
|
||||
Reference in New Issue
Block a user