reworked exception handling, different exceptions whether or why it failed, all of which are unchecked

added feature flags for commands/listeners
added enable/disable command
added feature flag handling to command received handler
added boolean parameter support
fixed 1 parameter commands
fixed posttargets not working on multiple servers, removed unique constraint on posttarget names
added setup validation to suggestions
added quartz property loader
moved join/leave logger to moderation
reworked the way the message listener are handled (separate listener around)
This commit is contained in:
Sheldan
2020-04-04 12:55:01 +02:00
parent c9557fccc2
commit bf94af66d5
132 changed files with 1378 additions and 530 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -0,0 +1,5 @@
package dev.sheldan.abstracto.core.listener;
public interface FeatureAware {
String getFeature();
}

View File

@@ -0,0 +1,8 @@
package dev.sheldan.abstracto.core.listener;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
public interface JoinListener extends FeatureAware {
void execute(Member member, Guild guild);
}

View File

@@ -0,0 +1,8 @@
package dev.sheldan.abstracto.core.listener;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Member;
public interface LeaveListener extends FeatureAware {
void execute(Member member, Guild guild);
}

View File

@@ -2,6 +2,6 @@ package dev.sheldan.abstracto.core.listener;
import dev.sheldan.abstracto.core.models.CachedMessage;
public interface MessageDeletedListener {
public interface MessageDeletedListener extends FeatureAware {
void execute(CachedMessage messageBefore);
}

View File

@@ -0,0 +1,7 @@
package dev.sheldan.abstracto.core.listener;
import net.dv8tion.jda.api.entities.Message;
public interface MessageReceivedListener extends FeatureAware {
void execute(Message message);
}

View File

@@ -3,6 +3,6 @@ package dev.sheldan.abstracto.core.listener;
import dev.sheldan.abstracto.core.models.CachedMessage;
import net.dv8tion.jda.api.entities.Message;
public interface MessageTextUpdatedListener {
public interface MessageTextUpdatedListener extends FeatureAware {
void execute(CachedMessage messageBefore, Message messageAfter);
}

View File

@@ -4,6 +4,6 @@ import dev.sheldan.abstracto.core.models.CachedMessage;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import net.dv8tion.jda.api.entities.MessageReaction;
public interface ReactedAddedListener {
public interface ReactedAddedListener extends FeatureAware {
void executeReactionAdded(CachedMessage message, MessageReaction reaction, AUserInAServer userAdding);
}

View File

@@ -4,6 +4,6 @@ import dev.sheldan.abstracto.core.models.CachedMessage;
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
import net.dv8tion.jda.api.entities.MessageReaction;
public interface ReactedRemovedListener {
public interface ReactedRemovedListener extends FeatureAware {
void executeReactionRemoved(CachedMessage message, MessageReaction reaction, AUserInAServer userRemoving);
}

View File

@@ -8,14 +8,14 @@ import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.SuperBuilder;
import net.dv8tion.jda.api.entities.Member;
import net.dv8tion.jda.api.entities.TextChannel;
import net.dv8tion.jda.api.entities.MessageChannel;
@Getter @NoArgsConstructor
@Setter
@SuperBuilder
public class UserInitiatedServerContext extends ServerContext {
private AChannel channel;
private TextChannel textChannel;
private MessageChannel messageChannel;
private Member member;
private AUser user;
private AUserInAServer aUserInAServer;

View File

@@ -0,0 +1,34 @@
package dev.sheldan.abstracto.core.models.database;
import dev.sheldan.abstracto.core.models.SnowFlake;
import lombok.*;
import javax.persistence.*;
@Entity
@Table(name="feature_flag")
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AFeatureFlag implements SnowFlake {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Getter
@Column(name = "id")
public Long id;
@ManyToOne(fetch = FetchType.LAZY)
@Getter
@Setter
@JoinColumn(name = "server_id")
private AServer server;
@Getter
@Setter
private String key;
@Getter
@Setter
private boolean enabled;
}

View File

@@ -18,7 +18,6 @@ public class PostTarget {
@Getter
private Long id;
@Column(unique = true)
@Getter
private String name;

View File

@@ -13,7 +13,7 @@ import net.dv8tion.jda.api.entities.TextChannel;
@SuperBuilder
public class MessageEmbeddedModel extends UserInitiatedServerContext {
private CachedMessage embeddedMessage;
private TextChannel sourceChannel;
private Member author;
private TextChannel sourceChannel;
private Member embeddingUser;
}

View File

@@ -7,6 +7,7 @@ import net.dv8tion.jda.api.entities.MessageReaction;
public interface EmoteService {
boolean isEmoteUsableByBot(Emote emote);
AEmote buildAEmoteFromReaction(MessageReaction.ReactionEmote reaction);
String getEmoteAsMention(AEmote emote, Long serverId, String defaultText);
String getEmoteAsMention(AEmote emote, Long serverId);
String getEmoteAsMention(AEmote emote, Long serverId, String defaultText) ;
String getEmoteAsMention(AEmote emote, Long serverId) ;
void throwIfEmoteDoesNotExist(String emoteKey, Long serverId) ;
}

View File

@@ -0,0 +1,5 @@
package dev.sheldan.abstracto.core.service;
public interface FeatureFlagService {
boolean isFeatureEnabled(String name, Long serverId);
}

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.service;
import dev.sheldan.abstracto.core.exception.ChannelException;
import dev.sheldan.abstracto.core.exception.GuildException;
import dev.sheldan.abstracto.core.models.database.PostTarget;
import dev.sheldan.abstracto.core.models.embed.MessageToSend;
import net.dv8tion.jda.api.entities.Message;
@@ -19,6 +21,7 @@ public interface PostTargetService {
CompletableFuture<Message> editEmbedInPostTarget(Long messageId, MessageToSend message, String postTargetName, Long serverId);
void editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target, CompletableFuture<Message> future);
void editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, String postTarget, Long serverId, CompletableFuture<Message> future);
void throwIfPostTargetIsNotDefined(String name, Long serverId);
boolean validPostTarget(String name);
List<String> getAvailablePostTargets();
}

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.management;
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.AChannel;
import dev.sheldan.abstracto.core.models.AChannelType;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.management;
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.AConfig;

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.management;
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.exception.ConfigurationException;
import dev.sheldan.abstracto.core.exception.EmoteException;
import dev.sheldan.abstracto.core.models.database.AEmote;
import dev.sheldan.abstracto.core.models.database.AServer;
import net.dv8tion.jda.api.entities.Emote;
@@ -8,15 +10,15 @@ import java.util.Optional;
public interface EmoteManagementService {
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);
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> 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) ;
boolean emoteExists(String name, Long serverId);
boolean emoteExists(String name, AServer server);
AEmote createCustomEmote(String name, String emoteKey, Long emoteId, Boolean animated);

View File

@@ -0,0 +1,14 @@
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.AFeatureFlag;
import dev.sheldan.abstracto.core.models.database.AServer;
import java.util.Optional;
public interface FeatureFlagManagementService {
void createFeatureFlag(String key, Long serverId, Boolean newValue);
void createFeatureFlag(String key, AServer server, Boolean newValue);
boolean getFeatureFlagValue(String key, Long serverId);
void updateOrCreateFeatureFlag(String key, Long serverId, Boolean newValue);
Optional<AFeatureFlag> getFeatureFlag(String key, Long serverId);
}

View File

@@ -1,5 +1,7 @@
package dev.sheldan.abstracto.core.management;
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;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.management;
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.ARole;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.management;
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.*;

View File

@@ -1,4 +1,4 @@
package dev.sheldan.abstracto.core.management;
package dev.sheldan.abstracto.core.service.management;
import dev.sheldan.abstracto.core.models.database.AServer;
import dev.sheldan.abstracto.core.models.database.AUser;

View File

@@ -1,8 +1,8 @@
package dev.sheldan.abstracto.core.utils;
import dev.sheldan.abstracto.core.management.ChannelManagementService;
import dev.sheldan.abstracto.core.management.ServerManagementService;
import dev.sheldan.abstracto.core.management.UserManagementService;
import dev.sheldan.abstracto.core.service.management.ChannelManagementService;
import dev.sheldan.abstracto.core.service.management.ServerManagementService;
import dev.sheldan.abstracto.core.service.management.UserManagementService;
import dev.sheldan.abstracto.core.models.CachedMessage;
import dev.sheldan.abstracto.core.models.ServerChannelUser;
import dev.sheldan.abstracto.core.models.UserInitiatedServerContext;
@@ -41,7 +41,7 @@ public class ContextUtils {
return builder
.member(serverChannelUser.getMember())
.guild(serverChannelUser.getGuild())
.textChannel(serverChannelUser.getTextChannel())
.messageChannel(serverChannelUser.getTextChannel())
.channel(channelManagementService.loadChannel(message.getChannelId()))
.server(serverManagementService.loadOrCreate(message.getServerId()))
.aUserInAServer(aUserInAServer)