added assignable role place module including: setting up, configuring, deleting commands and documentation

upgraded JDA version to 4.2.0
refactored multiple interfaces to be more convenient/contain more information (reaction added/removed now gets the actual event)
added generic way to check for conditions. these conditions are provided by modules and are loosely connected via condition context and a condition name
added changeable flag to emotes to indicate that they can be updated via setEmote
refactored emote parsing in command parameters, the command parameters will now contain a fake emote
added feature to embed templates for fields to force a new message regardless of the discord limit
added some more functionality to message and channel service regarding field edit/embed sending
introduced the full emote parameter, to have both the emote (if custom) and a fake aemote at hand
refactored some methods to already throw exceptions within the retrieval methods, instead of optionals which need to be dealt outside
changed getEmotes to getEmotesBag to have duplicates of emotes
fixed setEmote to behave correctly with new parameter types
fixed creation of emotes, which previously created additional instances
fixed templating multiple fields handling
refactored command handling to allow async commands, they are the same interface, but configuration dicates whether or not it is async
added generic exception reporting for async commands
refactored a bunch of service methods to be named optional, and the non optional methods throw exceptions in case nothing is found
added a few more customized exceptions
added clearing freemarker internal template cache to clear cache
added feature to skip, not use, embeds if they look to be empty (no fields, no description, no attachment)
added virtual env to gitignore
fixed initial sync of roles un-marking roles as deleted
added some convenience methods to remove reactions from users directly
fixed post command handling in case it is not a templatable instance
fixed exceptions without cause in generic exception model
This commit is contained in:
Sheldan
2020-07-23 02:22:58 +02:00
parent 5317199bf4
commit fd4d784081
201 changed files with 6547 additions and 527 deletions

View File

@@ -5,8 +5,11 @@ 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.util.concurrent.CompletableFuture;
public interface Command extends FeatureAware {
CommandResult execute(CommandContext commandContext);
default CommandResult execute(CommandContext commandContext) {return CommandResult.fromSuccess();};
default CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {return CompletableFuture.completedFuture(CommandResult.fromSuccess());};
CommandConfiguration getConfiguration();
}

View File

@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.command.condition;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.models.InsufficientPermissionMessage;
import dev.sheldan.abstracto.core.command.models.exception.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.management.CommandInServerManagementService;

View File

@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.command.condition;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.models.FeatureDisabledMessage;
import dev.sheldan.abstracto.core.command.models.exception.FeatureDisabledMessage;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.service.FeatureConfigService;
import dev.sheldan.abstracto.core.service.FeatureFlagService;

View File

@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.command.condition;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.models.IncorrectFeatureModeMessage;
import dev.sheldan.abstracto.core.command.models.exception.IncorrectFeatureModeMessage;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.AFeatureMode;
import dev.sheldan.abstracto.core.service.FeatureConfigService;

View File

@@ -2,7 +2,7 @@ package dev.sheldan.abstracto.core.command.condition;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.models.UserImmuneMessage;
import dev.sheldan.abstracto.core.command.models.exception.UserImmuneMessage;
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.management.CommandInServerManagementService;

View File

@@ -13,6 +13,12 @@ public class CommandConfiguration {
private String module;
private String description;
@Builder.Default
private boolean async = false;
@Builder.Default
private boolean reportsException = false;
@Builder.Default
private List<Parameter> parameters = new ArrayList<>();

View File

@@ -0,0 +1,27 @@
package dev.sheldan.abstracto.core.command.exception;
import dev.sheldan.abstracto.core.command.models.exception.CommandParameterKeyValueWrongTypeModel;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.templating.Templatable;
import java.util.List;
public class CommandParameterKeyValueWrongTypeException extends AbstractoRunTimeException implements Templatable {
private CommandParameterKeyValueWrongTypeModel model;
public CommandParameterKeyValueWrongTypeException(List<String> expectedValues) {
super("Command parameter value did not have expected values present");
this.model = CommandParameterKeyValueWrongTypeModel.builder().expectedValues(expectedValues).build();
}
@Override
public String getTemplateName() {
return "command_parameter_value_wrong_type_exception";
}
@Override
public Object getTemplateModel() {
return model;
}
}

View File

@@ -0,0 +1,22 @@
package dev.sheldan.abstracto.core.command.execution;
import dev.sheldan.abstracto.core.command.exception.CommandParameterKeyValueWrongTypeException;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public interface CommandParameterKey {
static <T extends Enum<T>> T getEnumFromKey(Class<T> clazz, String key) {
try {
if(clazz != null && key != null ) {
return Enum.valueOf(clazz, key.trim().toUpperCase());
}
} catch (IllegalArgumentException e) {
List<T> ts = Arrays.asList(clazz.getEnumConstants());
List<String> keys = ts.stream().map(Enum::toString).map(String::toLowerCase).collect(Collectors.toList());
throw new CommandParameterKeyValueWrongTypeException(keys);
}
throw new IllegalArgumentException("Clazz and key must not be null");
}
}

View File

@@ -23,6 +23,10 @@ public class CommandResult {
return CommandResult.builder().result(ResultState.SELF_DESTRUCT).build();
}
public static CommandResult fromReportedError() {
return CommandResult.builder().result(ResultState.REPORTED_ERROR).build();
}
public static CommandResult fromError(String message){
return CommandResult.builder().result(ResultState.ERROR).message(message).build();
}

View File

@@ -1,5 +1,5 @@
package dev.sheldan.abstracto.core.command.execution;
public enum ResultState {
ERROR, SUCCESSFUL, IGNORED, CONDITION, SELF_DESTRUCT
ERROR, SUCCESSFUL, IGNORED, CONDITION, SELF_DESTRUCT, REPORTED_ERROR
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.core.command.models.exception;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
@Builder
public class CommandParameterKeyValueWrongTypeModel {
private List<String> expectedValues;
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.command.models;
package dev.sheldan.abstracto.core.command.models.exception;
import dev.sheldan.abstracto.core.config.FeatureConfig;
import lombok.Builder;

View File

@@ -0,0 +1,26 @@
package dev.sheldan.abstracto.core.command.models.exception;
import dev.sheldan.abstracto.core.models.FullUser;
import dev.sheldan.abstracto.templating.Templatable;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class GenericExceptionModel {
private FullUser user;
private Throwable throwable;
public Templatable getTemplate() {
Throwable current = throwable;
while(!(current instanceof Templatable) && (current.getCause() != null && !current.getCause().equals(current))) {
current = current.getCause();
}
if(current instanceof Templatable) {
return (Templatable) current;
}
return null;
}
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.command.models;
package dev.sheldan.abstracto.core.command.models.exception;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.config.FeatureConfig;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.command.models;
package dev.sheldan.abstracto.core.command.models.exception;
import lombok.Builder;
import lombok.Getter;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.command.models;
package dev.sheldan.abstracto.core.command.models.exception;
import lombok.Builder;
import lombok.Getter;

View File

@@ -0,0 +1,9 @@
package dev.sheldan.abstracto.core.command.service;
import dev.sheldan.abstracto.core.command.Command;
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
public interface ExceptionService {
CommandResult reportExceptionToContext(Throwable exception, CommandContext context, Command command);
}

View File

@@ -4,6 +4,12 @@ public class AbstractoRunTimeException extends RuntimeException {
public AbstractoRunTimeException(String message) {
super(message);
}
public AbstractoRunTimeException() {
super();
}
public AbstractoRunTimeException(Throwable throwable) {
super(throwable);
}
public AbstractoRunTimeException(String message, Throwable cause) {
super(message, cause);

View File

@@ -7,12 +7,10 @@ import java.util.HashMap;
public class ChannelNotFoundException extends AbstractoRunTimeException implements Templatable {
private final Long channelId;
private final Long guildId;
public ChannelNotFoundException(Long channelId, Long guildId) {
super("");
public ChannelNotFoundException(Long channelId) {
super("Channel not found in database");
this.channelId = channelId;
this.guildId = guildId;
}
@Override
@@ -24,7 +22,6 @@ public class ChannelNotFoundException extends AbstractoRunTimeException implemen
public Object getTemplateModel() {
HashMap<String, Long> param = new HashMap<>();
param.put("channelId", this.channelId);
param.put("guildID", this.guildId);
return param;
}
}

View File

@@ -0,0 +1,28 @@
package dev.sheldan.abstracto.core.exception;
import dev.sheldan.abstracto.templating.Templatable;
import java.util.HashMap;
import java.util.List;
public class EmoteNotFoundInDbException extends AbstractoRunTimeException implements Templatable {
private final Integer emoteId;
public EmoteNotFoundInDbException(Integer emoteId) {
super("");
this.emoteId = emoteId;
}
@Override
public String getTemplateName() {
return "emote_not_found_in_db_exception";
}
@Override
public Object getTemplateModel() {
HashMap<String, Object> param = new HashMap<>();
param.put("emoteId", this.emoteId);
return param;
}
}

View File

@@ -0,0 +1,25 @@
package dev.sheldan.abstracto.core.exception;
import dev.sheldan.abstracto.core.models.exception.EmoteNotUsable;
import dev.sheldan.abstracto.templating.Templatable;
import net.dv8tion.jda.api.entities.Emote;
public class EmoteNotUsableException extends AbstractoRunTimeException implements Templatable {
private EmoteNotUsable model;
public EmoteNotUsableException(Emote emote) {
super("");
this.model = EmoteNotUsable.builder().emote(emote).build();
}
@Override
public String getTemplateName() {
return "emote_not_usable";
}
@Override
public Object getTemplateModel() {
return model;
}
}

View File

@@ -0,0 +1,24 @@
package dev.sheldan.abstracto.core.exception;
import dev.sheldan.abstracto.core.models.exception.EmoteNotInServerModel;
import dev.sheldan.abstracto.templating.Templatable;
public class ExceptionNotInServerException extends AbstractoRunTimeException implements Templatable {
private EmoteNotInServerModel model;
public ExceptionNotInServerException(Long emoteId) {
super("Emote not available in server");
this.model = EmoteNotInServerModel.builder().emoteId(emoteId).build();
}
@Override
public String getTemplateName() {
return "emote_not_available_in_server_exception";
}
@Override
public Object getTemplateModel() {
return model;
}
}

View File

@@ -4,15 +4,15 @@ import dev.sheldan.abstracto.templating.Templatable;
import java.util.HashMap;
public class GuildException extends AbstractoRunTimeException implements Templatable {
public class GuildNotFoundException extends AbstractoRunTimeException implements Templatable {
private final Long guildId;
public GuildException(String message, Long guildId) {
public GuildNotFoundException(String message, Long guildId) {
super(message);
this.guildId = guildId;
}
public GuildException(Long guildId) {
public GuildNotFoundException(Long guildId) {
super("");
this.guildId = guildId;
}

View File

@@ -0,0 +1,7 @@
package dev.sheldan.abstracto.core.exception;
public class InvalidConditionParametersException extends AbstractoRunTimeException {
public InvalidConditionParametersException(String message) {
super(message);
}
}

View File

@@ -0,0 +1,25 @@
package dev.sheldan.abstracto.core.exception;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.models.exception.RoleDeletedModel;
import dev.sheldan.abstracto.templating.Templatable;
public class RoleDeletedException extends AbstractoRunTimeException implements Templatable {
private RoleDeletedModel model;
public RoleDeletedException(ARole role) {
super("Role has been marked as deleted and cannot be used.");
this.model = RoleDeletedModel.builder().role(role).build();
}
@Override
public String getTemplateName() {
return "";
}
@Override
public Object getTemplateModel() {
return model;
}
}

View File

@@ -7,12 +7,10 @@ import java.util.HashMap;
public class RoleNotFoundInDBException extends AbstractoRunTimeException implements Templatable {
private final Long roleId;
private final Long serverId;
public RoleNotFoundInDBException(Long roleId, Long serverId) {
public RoleNotFoundInDBException(Long roleId) {
super("");
this.roleId = roleId;
this.serverId = serverId;
}
@Override
@@ -24,7 +22,6 @@ public class RoleNotFoundInDBException extends AbstractoRunTimeException impleme
public Object getTemplateModel() {
HashMap<String, Long> param = new HashMap<>();
param.put("roleId", this.roleId);
param.put("serverId", this.serverId);
return param;
}
}

View File

@@ -2,8 +2,8 @@ package dev.sheldan.abstracto.core.listener;
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import net.dv8tion.jda.api.entities.MessageReaction;
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionAddEvent;
public interface ReactedAddedListener extends FeatureAware {
void executeReactionAdded(CachedMessage message, MessageReaction reaction, AUserInAServer userAdding);
void executeReactionAdded(CachedMessage message, GuildMessageReactionAddEvent event, AUserInAServer userAdding);
}

View File

@@ -2,8 +2,8 @@ package dev.sheldan.abstracto.core.listener;
import dev.sheldan.abstracto.core.models.cache.CachedMessage;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import net.dv8tion.jda.api.entities.MessageReaction;
import net.dv8tion.jda.api.events.message.guild.react.GuildMessageReactionRemoveEvent;
public interface ReactedRemovedListener extends FeatureAware {
void executeReactionRemoved(CachedMessage message, MessageReaction reaction, AUserInAServer userRemoving);
void executeReactionRemoved(CachedMessage message, GuildMessageReactionRemoveEvent reaction, AUserInAServer userRemoving);
}

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.core.models;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.List;
@Getter
@Setter
@Builder
public class ConditionContext {
private List<ConditionContextVariable> expectedVariables;
}

View File

@@ -0,0 +1,15 @@
package dev.sheldan.abstracto.core.models;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import java.util.HashMap;
@Getter
@Setter
@Builder
public class ConditionContextInstance {
private HashMap<String, Object> parameters;
private String conditionName;
}

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.models;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class ConditionContextVariable {
private String name;
private Class type;
}

View File

@@ -0,0 +1,27 @@
package dev.sheldan.abstracto.core.models;
import dev.sheldan.abstracto.core.models.database.AEmote;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Emote;
import java.io.Serializable;
@Getter
@Setter
@Builder
public class FullEmote implements Serializable {
private AEmote fakeEmote;
private Emote emote;
public String getEmoteRepr() {
if(!fakeEmote.getCustom()) {
return fakeEmote.getEmoteKey();
} else if(emote != null) {
return emote.getAsMention();
} else {
return fakeEmote.getEmoteId().toString();
}
}
}

View File

@@ -12,4 +12,12 @@ import net.dv8tion.jda.api.entities.Role;
public class FullRole {
private ARole role;
private Role serverRole;
public String getRoleRepr() {
if(serverRole != null) {
return serverRole.getAsMention();
} else {
return role.getId().toString();
}
}
}

View File

@@ -25,6 +25,7 @@ public class AEmote implements Serializable {
@Column
private String name;
// the way discord calls them and the unicode char for default Tweemoji emotes
@Column
@Setter
private String emoteKey;
@@ -61,6 +62,15 @@ public class AEmote implements Serializable {
this.updated = Instant.now();
}
@Column(name = "changeable")
@Getter
@Setter
@Builder.Default
private boolean changeable = true;
@Transient
private boolean fake;
@Override
public boolean equals(Object o) {
if (this == o) return true;

View File

@@ -0,0 +1,12 @@
package dev.sheldan.abstracto.core.models.exception;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class EmoteNotInServerModel {
private Long emoteId;
}

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.models.exception;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import net.dv8tion.jda.api.entities.Emote;
@Getter
@Setter
@Builder
public class EmoteNotUsable {
private Emote emote;
}

View File

@@ -0,0 +1,13 @@
package dev.sheldan.abstracto.core.models.exception;
import dev.sheldan.abstracto.core.models.database.ARole;
import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
@Getter
@Setter
@Builder
public class RoleDeletedModel {
private ARole role;
}

View File

@@ -27,8 +27,11 @@ public interface BotService {
CompletableFuture<Void> deleteMessage(Long channelId, Long messageId);
CompletableFuture<Member> forceReloadMember(Member member);
Optional<Emote> getEmote(Long serverId, AEmote emote);
Optional<TextChannel> getTextChannelFromServer(Guild serverId, Long textChannelId);
Optional<TextChannel> getTextChannelFromServer(Long serverId, Long textChannelId);
Optional<Emote> getEmote(AEmote emote);
Optional<TextChannel> getTextChannelFromServerOptional(Guild serverId, Long textChannelId);
TextChannel getTextChannelFromServer(Guild serverId, Long textChannelId);
Optional<TextChannel> getTextChannelFromServerOptional(Long serverId, Long textChannelId);
TextChannel getTextChannelFromServer(Long serverId, Long textChannelId);
Optional<Guild> getGuildById(Long serverId);
Guild getGuildByIdNullable(Long serverId);
Member getBotInGuild(AServer server);

View File

@@ -22,10 +22,17 @@ public interface ChannelService {
CompletableFuture<Message> sendEmbedToAChannel(MessageEmbed embed, AChannel channel);
CompletableFuture<Message> sendEmbedToChannel(MessageEmbed embed, MessageChannel channel);
List<CompletableFuture<Message>> sendMessageToSendToAChannel(MessageToSend messageToSend, AChannel channel);
CompletableFuture<Message> sendMessageToSendToAChannel(MessageToSend messageToSend, AChannel channel, Integer embedIndex);
List<CompletableFuture<Message>> sendMessageToSendToChannel(MessageToSend messageToSend, MessageChannel textChannel);
Optional<TextChannel> getTextChannelInGuild(Long serverId, Long channelId);
void editMessageInAChannel(MessageToSend messageToSend, AChannel channel, Long messageId);
void editMessageInAChannel(MessageToSend messageToSend, MessageChannel channel, Long messageId);
CompletableFuture<Message> editMessageInAChannelFuture(MessageToSend messageToSend, MessageChannel channel, Long messageId);
CompletableFuture<Message> editEmbedMessageInAChannel(MessageEmbed embedToSend, MessageChannel channel, Long messageId);
CompletableFuture<Message> editTextMessageInAChannel(String text, MessageChannel channel, Long messageId);
List<CompletableFuture<Message>> editMessagesInAChannelFuture(MessageToSend messageToSend, MessageChannel channel, List<Long> messageIds);
CompletableFuture<Message> removeFieldFromMessage(MessageChannel channel, Long messageId, Integer index);
CompletableFuture<Message> removeFieldFromMessage(MessageChannel channel, Long messageId, Integer index, Integer embedIndex);
CompletableFuture<Void> deleteTextChannel(AChannel channel);
CompletableFuture<Void> deleteTextChannel(Long serverId, Long channelId);
List<CompletableFuture<Message>> sendEmbedTemplateInChannel(String templateKey, Object model, MessageChannel channel);

View File

@@ -0,0 +1,7 @@
package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.models.ConditionContextInstance;
public interface ConditionService {
boolean checkConditions(ConditionContextInstance context);
}

View File

@@ -15,9 +15,10 @@ public interface EmoteService {
String getEmoteAsMention(AEmote emote, Long serverId);
String getUsableEmoteOrDefault(Long serverId, String name);
void throwIfEmoteDoesNotExist(String emoteKey, Long serverId);
AEmote getEmoteOrFakeEmote(String emoteKey, Long serverId);
AEmote getEmoteOrDefaultEmote(String emoteKey, Long serverId);
String getDefaultEmote(String emoteKey);
boolean isReactionEmoteAEmote(MessageReaction.ReactionEmote reaction, AEmote storedEmote, Emote actualEmoteInGuild);
boolean isReactionEmoteAEmote(MessageReaction.ReactionEmote reaction, AEmote storedEmote);
Optional<CachedReaction> getReactionFromMessageByEmote(CachedMessage message, AEmote emote);
boolean compareAEmote(AEmote a, AEmote b);
AEmote getFakeEmote(Object object);
}

View File

@@ -1,8 +1,10 @@
package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.database.AEmote;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import dev.sheldan.abstracto.templating.model.MessageToSend;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.MessageChannel;
import net.dv8tion.jda.api.entities.User;
@@ -13,6 +15,20 @@ import java.util.concurrent.CompletableFuture;
public interface MessageService {
void addReactionToMessage(String emoteKey, Long serverId, Message message);
CompletableFuture<Void> addReactionToMessageWithFuture(String emoteKey, Long serverId, Message message);
CompletableFuture<Void> addReactionToMessageWithFuture(AEmote emote, Long serverId, Message message);
CompletableFuture<Void> addReactionToMessageWithFuture(Long emoteId, Long serverId, Message message);
CompletableFuture<Void> removeReactionFromMessageWithFuture(AEmote emote, Long serverId, Message message);
CompletableFuture<Void> clearReactionFromMessageWithFuture(AEmote emote, Message message);
CompletableFuture<Void> removeReactionFromMessageWithFuture(Integer emoteId, Long serverId, Message message);
CompletableFuture<Void> clearReactionFromMessageWithFuture(Integer emoteId, Long serverId, Message message);
CompletableFuture<Void> removeReactionFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId);
CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId, Long userId);
CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId, Member member);
CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Message message, Member member);
CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(Integer emoteId, Message message, Member member);
CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(AEmote emote, Message message, Long userId);
CompletableFuture<Void> removeReactionOfUserFromMessageWithFuture(Integer emoteId, Message message, Long userId);
CompletableFuture<Void> clearReactionFromMessageWithFuture(AEmote emote, Long serverId, Long channelId, Long messageId);
List<CompletableFuture<Void>> addReactionsToMessageWithFuture(List<String> emoteKeys, Long serverId, Message message);
CompletableFuture<Void> deleteMessageInChannelInServer(Long serverId, Long channelId, Long messageId);
CompletableFuture<Message> createStatusMessage(MessageToSend messageToSend, AChannel channel);

View File

@@ -7,10 +7,17 @@ import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.Role;
import java.util.List;
import java.util.concurrent.CompletableFuture;
public interface RoleService {
void addRoleToUser(AUserInAServer aUserInAServer, ARole role);
CompletableFuture<Void> addRoleToUserFuture(AUserInAServer aUserInAServer, ARole role);
void addRoleToMember(Member member, ARole role);
CompletableFuture<Void> addRoleToMemberFuture(Member member, ARole role);
void removeRoleFromMember(Member member, ARole role);
CompletableFuture<Void> removeRoleFromMemberFuture(Member member, ARole role);
void removeRoleFromUser(AUserInAServer aUserInAServer, ARole role);
CompletableFuture<Void> removeRoleFromUserFuture(AUserInAServer aUserInAServer, ARole role);
void markDeleted(Role role, AServer server);
void markDeleted(Long id, AServer server);
Role getRoleFromGuild(ARole role);
@@ -19,4 +26,5 @@ public interface RoleService {
boolean memberHasRole(Member member, Role role);
boolean memberHasRole(Member member, ARole role);
boolean isRoleInServer(ARole role);
boolean canBotInteractWithRole(ARole role);
}

View File

@@ -0,0 +1,10 @@
package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.models.ConditionContext;
import dev.sheldan.abstracto.core.models.ConditionContextInstance;
public interface SystemCondition {
boolean checkCondition(ConditionContextInstance conditionContext);
String getConditionName();
ConditionContext getExpectedContext();
}

View File

@@ -7,7 +7,8 @@ import dev.sheldan.abstracto.core.models.database.AServer;
import java.util.Optional;
public interface ChannelManagementService {
Optional<AChannel> loadChannel(Long id);
Optional<AChannel> loadChannelOptional(Long id);
AChannel loadChannel(Long id);
AChannel createChannel(Long id, AChannelType type, AServer server);
AChannel markAsDeleted(Long id);
boolean channelExists(Long id);

View File

@@ -7,16 +7,23 @@ import net.dv8tion.jda.api.entities.Emote;
import java.util.Optional;
public interface EmoteManagementService {
Optional<AEmote> loadEmote(Long id);
AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, Long serverId) ;
AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, AServer server) ;
AEmote createDefaultEmote(String name, String emoteKey, Long serverId) ;
AEmote createDefaultEmote(String name, String emoteKey, AServer server) ;
Optional<AEmote> loadEmoteOptional(Integer id);
AEmote loadEmote(Integer id);
AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, Long serverId, boolean validateName);
AEmote createCustomEmote(String name, AEmote fakeEmote, Long serverId, boolean validateName);
AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, AServer server, boolean validateName);
AEmote createDefaultEmote(String name, String emoteKey, Long serverId, boolean validateName);
AEmote createDefaultEmote(String name, String emoteKey, AServer server, boolean validateName);
Optional<AEmote> loadEmoteByName(String name, Long serverId);
Optional<AEmote> loadEmoteByName(String name, AServer server);
AEmote setEmoteToCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, Long serverId) ;
AEmote setEmoteToCustomEmote(String name, Emote emote, Long serverId) ;
AEmote setEmoteToDefaultEmote(String name, String emoteKey, Long serverId) ;
AEmote setEmoteToCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated, Long serverId);
AEmote setEmoteToCustomEmote(String name, Emote emote, Long serverId);
AEmote setEmoteToDefaultEmote(String name, String emoteKey, Long serverId);
AEmote setEmoteToAEmote(String name, AEmote emote, Long serverId);
AEmote createEmote(String name, AEmote emote, Long serverId, boolean validateName);
boolean emoteExists(String name, Long serverId);
boolean emoteExists(Long emoteId);
void deleteEmote(AEmote aEmote);
Optional<AEmote> loadEmote(Long id);
boolean emoteExists(String name, AServer server);
}

View File

@@ -7,6 +7,7 @@ import java.util.Optional;
public interface RoleManagementService {
ARole createRole(Long id, AServer server);
Optional<ARole> findRole(Long id, AServer server);
Optional<ARole> findRoleOptional(Long id);
ARole findRole(Long id);
void markDeleted(ARole role);
}

View File

@@ -3,10 +3,13 @@ package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.*;
import java.util.List;
import java.util.Optional;
public interface ServerManagementService {
AServer createServer(Long id);
AServer loadOrCreate(Long id);
AServer loadServer(Long id);
Optional<AServer> loadServerOptional(Long id);
void addChannelToServer(AServer server, AChannel channel);
AUserInAServer addUserToServer(AServer server, AUser user);
AUserInAServer addUserToServer(Long serverId, Long userId);

View File

@@ -1,7 +1,6 @@
package dev.sheldan.abstracto.core.utils;
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
@@ -16,7 +15,6 @@ import org.springframework.stereotype.Component;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Optional;
@Component
@Slf4j
@@ -38,8 +36,7 @@ public class ContextUtils {
m = clazz.getMethod("builder");
UserInitiatedServerContext.UserInitiatedServerContextBuilder<?, ?> builder = (UserInitiatedServerContext.UserInitiatedServerContextBuilder) m.invoke(null, null);
AUserInAServer aUserInAServer = userInServerManagementService.loadUser(message.getServerId(), message.getAuthorId());
Optional<AChannel> channelOptional = channelManagementService.loadChannel(message.getChannelId());
AChannel channel = channelOptional.orElseThrow(() -> new ChannelNotFoundException(message.getChannelId(), message.getServerId()));
AChannel channel = channelManagementService.loadChannel(message.getChannelId());
return builder
.member(guildChannelMember.getMember())
.guild(guildChannelMember.getGuild())

View File

@@ -49,8 +49,7 @@ public class ContextUtilsTest {
AUserInAServer aUserInAServer = AUserInAServer.builder().userReference(AUser.builder().id(AUTHOR_ID).build()).serverReference(server).build();
when(userInServerManagementService.loadUser(eq(SERVER_ID), eq(AUTHOR_ID))).thenReturn(aUserInAServer);
AChannel channel = AChannel.builder().id(CHANNEL_ID).build();
Optional<AChannel> op = Optional.of(channel);
when(channelManagementService.loadChannel(eq(CHANNEL_ID))).thenReturn(op);
when(channelManagementService.loadChannel(eq(CHANNEL_ID))).thenReturn(channel);
}
@Test