mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-07-03 03:44:32 +00:00
[AB-99/AB-66] changed commands to use embeds for exceptions instead of direct messages
added models instead of using HashMaps for exceptions added a lot of exceptions for different cases refactored a few commands to be fully async instead of fire and forget
This commit is contained in:
@@ -3,8 +3,8 @@ package dev.sheldan.abstracto.core.command;
|
||||
import dev.sheldan.abstracto.core.command.condition.ConditionResult;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameters;
|
||||
import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.ParameterTooLong;
|
||||
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterException;
|
||||
import dev.sheldan.abstracto.core.command.exception.ParameterTooLongException;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandManager;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.ExceptionService;
|
||||
@@ -200,7 +200,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
}
|
||||
String value = unParsedCommandParameter.getParameters().get(i);
|
||||
if(param.getMaxLength() != null && (value.length() + Constants.PARAMETER_LIMIT) > param.getMaxLength()) {
|
||||
throw new ParameterTooLong("The passed parameter was too long.", command, param.getName(), value.length(), param.getMaxLength());
|
||||
throw new ParameterTooLongException(command, param.getName(), value.length(), param.getMaxLength());
|
||||
}
|
||||
try {
|
||||
if(param.getType().equals(Integer.class)){
|
||||
@@ -302,7 +302,7 @@ public class CommandReceivedHandler extends ListenerAdapter {
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException e) {
|
||||
throw new IncorrectParameter(command, param.getType(), param.getName());
|
||||
throw new IncorrectParameterException(command, param.getType(), param.getName());
|
||||
} catch (IllegalArgumentException e) {
|
||||
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package dev.sheldan.abstracto.core.command.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.config.ModuleInterface;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFound;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.UnParsedCommandParameter;
|
||||
@@ -11,7 +11,6 @@ import dev.sheldan.abstracto.core.service.ConfigService;
|
||||
import dev.sheldan.abstracto.core.service.management.DefaultConfigManagementService;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@@ -47,7 +46,7 @@ public class CommandManager implements CommandRegistry {
|
||||
boolean hasRemainderParameter = commandConfiguration.getParameters().stream().anyMatch(Parameter::isRemainder);
|
||||
if(unParsedCommandParameter.getParameters().size() < commandConfiguration.getNecessaryParameterCount()) {
|
||||
String nextParameterName = commandConfiguration.getParameters().get(commandConfiguration.getNecessaryParameterCount() - 1).getName();
|
||||
throw new InsufficientParameters(o, nextParameterName);
|
||||
throw new InsufficientParametersException(o, nextParameterName);
|
||||
}
|
||||
parameterFit = paramCountFits || hasRemainderParameter;
|
||||
} else {
|
||||
@@ -58,7 +57,7 @@ public class CommandManager implements CommandRegistry {
|
||||
if(commandOptional.isPresent()){
|
||||
return commandOptional.get();
|
||||
}
|
||||
throw new CommandNotFound("Command not found.");
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
private boolean commandNameMatches(String name, CommandConfiguration commandConfiguration) {
|
||||
@@ -81,7 +80,7 @@ public class CommandManager implements CommandRegistry {
|
||||
if(commandOptional.isPresent()){
|
||||
return commandOptional.get();
|
||||
}
|
||||
throw new CommandNotFound("Command not found.");
|
||||
throw new CommandNotFoundException();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -26,6 +26,8 @@ import java.util.List;
|
||||
@Slf4j
|
||||
public class CommandServiceBean implements CommandService {
|
||||
|
||||
public static final String NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE = "no_feature_command_found_exception";
|
||||
|
||||
@Autowired
|
||||
private ModuleManagementService moduleManagementService;
|
||||
|
||||
|
||||
@@ -5,10 +5,20 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.exception.GenericExceptionModel;
|
||||
import dev.sheldan.abstracto.core.models.FullUser;
|
||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerManagementService;
|
||||
import dev.sheldan.abstracto.core.service.management.UserManagementService;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@@ -16,37 +26,105 @@ import org.springframework.stereotype.Component;
|
||||
@Slf4j
|
||||
public class ExceptionServiceBean implements ExceptionService {
|
||||
|
||||
public static final String MODEL_WRAPPER_TEMPLATE_KEY = "model_wrapper";
|
||||
@Autowired
|
||||
private ChannelService channelService;
|
||||
|
||||
@Autowired
|
||||
private TemplateService templateService;
|
||||
|
||||
@Autowired
|
||||
private UserInServerManagementService userInServerManagementService;
|
||||
|
||||
@Autowired
|
||||
private UserManagementService userManagementService;
|
||||
|
||||
@Override
|
||||
public CommandResult reportExceptionToContext(Throwable throwable, CommandContext context, Command command) {
|
||||
if(command != null && command.getConfiguration().isReportsException()) {
|
||||
if(command != null && command.getConfiguration().isSupportsEmbedException()) {
|
||||
try {
|
||||
FullUser fullUser = FullUser
|
||||
.builder()
|
||||
.aUserInAServer(context.getUserInitiatedContext().getAUserInAServer())
|
||||
.member(context.getAuthor())
|
||||
.build();
|
||||
GenericExceptionModel modMailExceptionModel = GenericExceptionModel
|
||||
.builder()
|
||||
.user(fullUser)
|
||||
.throwable(throwable)
|
||||
.build();
|
||||
channelService.sendEmbedTemplateInChannel("generic_command_exception", modMailExceptionModel, context.getChannel());
|
||||
GenericExceptionModel exceptionModel = buildCommandModel(throwable, context);
|
||||
channelService.sendEmbedTemplateInChannel("generic_command_exception", exceptionModel, context.getChannel());
|
||||
} catch (Exception e) {
|
||||
log.error("Failed to notify about assignable role exception.", e);
|
||||
}
|
||||
} else if(throwable instanceof Templatable){
|
||||
Templatable exception = (Templatable) throwable;
|
||||
String text = templateService.renderTemplate(exception.getTemplateName(), exception.getTemplateModel());
|
||||
GenericExceptionModel exceptionModel = buildCommandModel(throwable, context);
|
||||
String text = templateService.renderTemplate(MODEL_WRAPPER_TEMPLATE_KEY, exceptionModel);
|
||||
channelService.sendTextToChannel(text, context.getChannel());
|
||||
} else {
|
||||
channelService.sendTextToChannel(throwable.getLocalizedMessage(), context.getChannel());
|
||||
}
|
||||
return CommandResult.fromReportedError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportExceptionToGuildMessageReceivedContext(Throwable exception, GuildMessageReceivedEvent event) {
|
||||
if(exception instanceof Templatable){
|
||||
GenericExceptionModel model = buildMemberContext(exception, event.getMember());
|
||||
String text = templateService.renderTemplate(MODEL_WRAPPER_TEMPLATE_KEY, model);
|
||||
channelService.sendTextToChannel(text, event.getChannel());
|
||||
} else {
|
||||
channelService.sendTextToChannel(exception.getLocalizedMessage(), event.getChannel());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportExceptionToPrivateMessageReceivedContext(Throwable exception, PrivateMessageReceivedEvent event) {
|
||||
if(exception instanceof Templatable){
|
||||
GenericExceptionModel model = buildPrivateMessageReceivedModel(exception, event.getAuthor());
|
||||
String text = templateService.renderTemplate(MODEL_WRAPPER_TEMPLATE_KEY, model);
|
||||
channelService.sendTextToChannel(text, event.getChannel());
|
||||
} else {
|
||||
channelService.sendTextToChannel(exception.getLocalizedMessage(), event.getChannel());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reportExceptionToChannel(Throwable exception, MessageChannel channel, Member member) {
|
||||
if(exception instanceof Templatable){
|
||||
GenericExceptionModel model = buildMemberContext(exception, member);
|
||||
String text = templateService.renderTemplate(MODEL_WRAPPER_TEMPLATE_KEY, model);
|
||||
channelService.sendTextToChannel(text, channel);
|
||||
} else {
|
||||
channelService.sendTextToChannel(exception.getLocalizedMessage(), channel);
|
||||
}
|
||||
}
|
||||
|
||||
private GenericExceptionModel buildCommandModel(Throwable throwable, CommandContext context) {
|
||||
FullUserInServer fullUser = FullUserInServer.builder().member(context.getAuthor()).aUserInAServer(context.getUserInitiatedContext().getAUserInAServer()).build();
|
||||
return GenericExceptionModel
|
||||
.builder()
|
||||
.user(fullUser)
|
||||
.throwable(throwable)
|
||||
.build();
|
||||
}
|
||||
|
||||
private GenericExceptionModel buildMemberContext(Throwable throwable, Member member) {
|
||||
AUserInAServer userInAServer = userInServerManagementService.loadUser(member);
|
||||
FullUserInServer fullUser = FullUserInServer
|
||||
.builder()
|
||||
.aUserInAServer(userInAServer)
|
||||
.member(member)
|
||||
.build();
|
||||
return GenericExceptionModel
|
||||
.builder()
|
||||
.user(fullUser)
|
||||
.throwable(throwable)
|
||||
.build();
|
||||
}
|
||||
|
||||
private GenericExceptionModel buildPrivateMessageReceivedModel(Throwable throwable, User user) {
|
||||
AUser aUser = userManagementService.loadUser(user.getIdLong());
|
||||
FullUser fullUser = FullUser
|
||||
.builder()
|
||||
.user(user)
|
||||
.auser(aUser)
|
||||
.build();
|
||||
return GenericExceptionModel
|
||||
.builder()
|
||||
.fullUser(fullUser)
|
||||
.throwable(throwable)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CommandManagementServiceBean implements CommandManagementService {
|
||||
|
||||
@Override
|
||||
public ACommand findCommandByName(String name) {
|
||||
return findCommandByNameOptional(name).orElseThrow(() -> new CommandNotFoundException(String.format("Command %s was not found.", name)));
|
||||
return findCommandByNameOptional(name).orElseThrow(CommandNotFoundException::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -43,6 +43,7 @@ public class AddToChannelGroup extends AbstractConditionableCommand {
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.aliases(aliases)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -39,6 +39,7 @@ public class CreateChannelGroup extends AbstractConditionableCommand {
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.aliases(aliases)
|
||||
.supportsEmbedException(true)
|
||||
.templated(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -39,6 +39,7 @@ public class DeleteChannelGroup extends AbstractConditionableCommand {
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.aliases(aliases)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -40,6 +40,7 @@ public class DisableCommand extends AbstractConditionableCommand {
|
||||
.name("disableCommand")
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -40,6 +40,7 @@ public class EnableCommand extends AbstractConditionableCommand {
|
||||
.name("enableCommand")
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.templated(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -82,6 +82,7 @@ public class ListChannelGroups extends AbstractConditionableCommand {
|
||||
.aliases(aliases)
|
||||
.templated(true)
|
||||
.help(helpInfo)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@ import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.execution.*;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatures;
|
||||
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import dev.sheldan.abstracto.core.models.template.commands.PostTargetDisplayModel;
|
||||
import dev.sheldan.abstracto.core.models.template.commands.PostTargetErrorModel;
|
||||
import dev.sheldan.abstracto.core.models.template.commands.PostTargetModelEntry;
|
||||
import dev.sheldan.abstracto.core.service.ChannelService;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
@@ -33,7 +33,6 @@ import java.util.Optional;
|
||||
public class PostTargetCommand extends AbstractConditionableCommand {
|
||||
|
||||
public static final String POST_TARGET_SHOW_TARGETS = "posttarget_show_targets";
|
||||
public static final String POST_TARGET_INVALID_TARGET_TEMPLATE = "posttarget_invalid_target";
|
||||
|
||||
@Autowired
|
||||
private PostTargetManagement postTargetManagement;
|
||||
@@ -73,10 +72,7 @@ public class PostTargetCommand extends AbstractConditionableCommand {
|
||||
}
|
||||
String targetName = (String) commandContext.getParameters().getParameters().get(0);
|
||||
if(!postTargetService.validPostTarget(targetName)) {
|
||||
PostTargetErrorModel postTargetErrorModel = (PostTargetErrorModel) ContextConverter.fromCommandContext(commandContext, PostTargetErrorModel.class);
|
||||
postTargetErrorModel.setValidPostTargets(postTargetService.getAvailablePostTargets());
|
||||
String errorMessage = templateService.renderTemplate(POST_TARGET_INVALID_TARGET_TEMPLATE, postTargetErrorModel);
|
||||
return CommandResult.fromError(errorMessage);
|
||||
throw new PostTargetNotValidException(targetName, postTargetService.getAvailablePostTargets());
|
||||
}
|
||||
GuildChannel channel = (GuildChannel) commandContext.getParameters().getParameters().get(1);
|
||||
Guild guild = channel.getGuild();
|
||||
@@ -95,6 +91,7 @@ public class PostTargetCommand extends AbstractConditionableCommand {
|
||||
.name("posttarget")
|
||||
.module(ChannelsModuleInterface.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -45,6 +45,7 @@ public class RemoveFromChannelGroup extends AbstractConditionableCommand {
|
||||
.parameters(parameters)
|
||||
.templated(true)
|
||||
.help(helpInfo)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -35,6 +35,7 @@ public class ClearCache extends AbstractConditionableCommand {
|
||||
.name("clearCache")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -42,6 +42,7 @@ public class SetConfig extends AbstractConditionableCommand {
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
|
||||
@@ -37,6 +37,7 @@ public class SetPrefix extends AbstractConditionableCommand {
|
||||
.name("setPrefix")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -10,6 +10,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.exception.FeatureNotFoundException;
|
||||
import dev.sheldan.abstracto.core.interactive.InteractiveService;
|
||||
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
@@ -19,6 +20,7 @@ import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
public class Setup extends AbstractConditionableCommand {
|
||||
@@ -36,7 +38,7 @@ public class Setup extends AbstractConditionableCommand {
|
||||
private SetupService setupService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
public CompletableFuture<CommandResult> executeAsync(CommandContext commandContext) {
|
||||
String name = (String) commandContext.getParameters().getParameters().get(0);
|
||||
if(featureManagementService.featureExists(name)) {
|
||||
FeatureConfig feature = featureConfigService.getFeatureDisplayForFeature(name);
|
||||
@@ -46,9 +48,10 @@ public class Setup extends AbstractConditionableCommand {
|
||||
.channelId(commandContext.getChannel().getIdLong())
|
||||
.userId(commandContext.getAuthor().getIdLong())
|
||||
.build();
|
||||
setupService.performSetup(feature, initiatingUser, commandContext.getMessage().getIdLong());
|
||||
return setupService.performSetup(feature, initiatingUser, commandContext.getMessage().getIdLong())
|
||||
.thenApply(aVoid -> CommandResult.fromSuccess());
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
throw new FeatureNotFoundException(name, featureConfigService.getFeaturesAsList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,6 +63,8 @@ public class Setup extends AbstractConditionableCommand {
|
||||
.name("setup")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.async(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
@@ -52,7 +53,7 @@ public class Allow extends AbstractConditionableCommand {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
commandService.unRestrictCommand(command, commandContext.getUserInitiatedContext().getServer());
|
||||
} else {
|
||||
return CommandResult.fromError(templateService.renderTemplate("no_feature_command_found", new Object()));
|
||||
return CommandResult.fromError(templateService.renderTemplate(CommandServiceBean.NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE, new Object()));
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
@@ -55,7 +56,7 @@ public class AllowRole extends AbstractConditionableCommand {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
commandService.allowCommandForRole(command, role);
|
||||
} else {
|
||||
return CommandResult.fromError(templateService.renderTemplate("no_feature_command_found", new Object()));
|
||||
return CommandResult.fromError(templateService.renderTemplate(CommandServiceBean.NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE, new Object()));
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
@@ -54,7 +55,7 @@ public class DisAllowRole extends AbstractConditionableCommand {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
commandService.disAllowCommandForRole(command, role);
|
||||
} else {
|
||||
return CommandResult.fromError(templateService.renderTemplate("no_feature_command_found", new Object()));
|
||||
return CommandResult.fromError(templateService.renderTemplate(CommandServiceBean.NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE, new Object()));
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -70,6 +70,7 @@ public class Disable extends AbstractConditionableCommand {
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ public class Enable extends AbstractConditionableCommand {
|
||||
.name("enable")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.templated(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -53,6 +53,7 @@ public class Features extends AbstractConditionableCommand {
|
||||
.name("features")
|
||||
.module(ConfigModuleInterface.CONFIG)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
@@ -54,7 +55,7 @@ public class MakeAffected extends AbstractConditionableCommand {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
commandService.makeRoleAffectedByCommand(command, role);
|
||||
} else {
|
||||
return CommandResult.fromError(templateService.renderTemplate("no_feature_command_found", new Object()));
|
||||
return CommandResult.fromError(templateService.renderTemplate(CommandServiceBean.NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE, new Object()));
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
@@ -54,7 +55,7 @@ public class MakeImmune extends AbstractConditionableCommand {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
commandService.makeRoleImmuneForCommand(command, role);
|
||||
} else {
|
||||
return CommandResult.fromError(templateService.renderTemplate("no_feature_command_found", new Object()));
|
||||
return CommandResult.fromError(templateService.renderTemplate(CommandServiceBean.NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE, new Object()));
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandService;
|
||||
import dev.sheldan.abstracto.core.command.service.CommandServiceBean;
|
||||
import dev.sheldan.abstracto.core.command.service.management.CommandManagementService;
|
||||
import dev.sheldan.abstracto.core.command.service.management.FeatureManagementService;
|
||||
import dev.sheldan.abstracto.core.commands.config.ConfigModuleInterface;
|
||||
@@ -52,7 +53,7 @@ public class Restrict extends AbstractConditionableCommand {
|
||||
ACommand command = commandManagementService.findCommandByName(name);
|
||||
commandService.restrictCommand(command, commandContext.getUserInitiatedContext().getServer());
|
||||
} else {
|
||||
return CommandResult.fromError(templateService.renderTemplate("no_feature_command_found", new Object()));
|
||||
return CommandResult.fromError(templateService.renderTemplate(CommandServiceBean.NO_FEATURE_COMMAND_FOUND_EXCEPTION_TEMPLATE, new Object()));
|
||||
}
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@@ -45,6 +45,7 @@ public class Echo extends AbstractConditionableCommand {
|
||||
.name("echo")
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.templated(true)
|
||||
.supportsEmbedException(true)
|
||||
.causesReaction(false)
|
||||
.parameters(parameters)
|
||||
.help(helpInfo)
|
||||
|
||||
@@ -46,6 +46,7 @@ public class SetEmote extends AbstractConditionableCommand {
|
||||
.name("setEmote")
|
||||
.module(UtilityModuleInterface.UTILITY)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
|
||||
@@ -4,8 +4,8 @@ import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class NoChannelProvidedException extends AbstractoRunTimeException implements Templatable {
|
||||
public NoChannelProvidedException(String message) {
|
||||
super(message);
|
||||
public NoChannelProvidedException() {
|
||||
super("No channel was provided");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -81,7 +81,7 @@ public class PostTargetSetupStep extends AbstractConfigSetupStep {
|
||||
result = SetupStepResult.fromCancelled();
|
||||
} else {
|
||||
if(message.getMentionedChannels().size() == 0) {
|
||||
throw new NoChannelProvidedException("No channel was provided.");
|
||||
throw new NoChannelProvidedException();
|
||||
}
|
||||
TextChannel textChannel = message.getMentionedChannels().get(0);
|
||||
PostTargetDelayedActionConfig build = PostTargetDelayedActionConfig
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.listener;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.service.ExceptionService;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.service.BotService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
@@ -37,6 +38,9 @@ public class MessageReceivedListenerBean extends ListenerAdapter {
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
|
||||
@Autowired
|
||||
private ExceptionService exceptionService;
|
||||
|
||||
@Override
|
||||
public void onGuildMessageReceived(@Nonnull GuildMessageReceivedEvent event) {
|
||||
messageCache.putMessageInCache(event.getMessage());
|
||||
@@ -49,6 +53,7 @@ public class MessageReceivedListenerBean extends ListenerAdapter {
|
||||
messageReceivedListener.execute(event.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("Listener {} had exception when executing.", messageReceivedListener, e);
|
||||
exceptionService.reportExceptionToGuildMessageReceivedContext(e, event);
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -63,6 +68,7 @@ public class MessageReceivedListenerBean extends ListenerAdapter {
|
||||
messageReceivedListener.execute(event.getMessage());
|
||||
} catch (Exception e) {
|
||||
log.error("Listener {} had exception when executing.", messageReceivedListener, e);
|
||||
exceptionService.reportExceptionToPrivateMessageReceivedContext(e, event);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.exception.CategoryNotFoundException;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||
import dev.sheldan.abstracto.core.exception.GuildNotFoundException;
|
||||
@@ -171,7 +170,7 @@ public class ChannelServiceBean implements ChannelService {
|
||||
if(messageToSend.getEmbeds() != null && !messageToSend.getEmbeds().isEmpty()) {
|
||||
messageAction = channel.editMessageById(messageId, messageToSend.getEmbeds().get(0));
|
||||
} else {
|
||||
throw new AbstractoRunTimeException("Message to send did not contain anything to send.");
|
||||
throw new IllegalArgumentException("Message to send did not contain anything to send.");
|
||||
}
|
||||
}
|
||||
return messageAction.submit();
|
||||
|
||||
@@ -45,7 +45,7 @@ public class FeatureConfigServiceBean implements FeatureConfigService {
|
||||
if(any.isPresent()) {
|
||||
return any.get();
|
||||
}
|
||||
throw new FeatureNotFoundException("", featureEnum.getKey(), getFeaturesAsList());
|
||||
throw new FeatureNotFoundException(featureEnum.getKey(), getFeaturesAsList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -83,7 +83,7 @@ public class FeatureConfigServiceBean implements FeatureConfigService {
|
||||
if(foundFeature.isPresent()) {
|
||||
return foundFeature.get().getFeature();
|
||||
}
|
||||
throw new FeatureNotFoundException("", key, getFeaturesAsList());
|
||||
throw new FeatureNotFoundException(key, getFeaturesAsList());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,7 +121,7 @@ public class FeatureConfigServiceBean implements FeatureConfigService {
|
||||
if(foundFeature.isPresent()) {
|
||||
return foundFeature.get();
|
||||
}
|
||||
throw new FeatureModeNotFoundException("", key, getFeatureModesFromFeatureAsString(featureConfig.getFeature().getKey()));
|
||||
throw new FeatureModeNotFoundException(key, getFeatureModesFromFeatureAsString(featureConfig.getFeature().getKey()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -47,7 +47,7 @@ public class FeatureFlagServiceBean implements FeatureFlagService {
|
||||
public void enableFeature(FeatureConfig name, AServer server) {
|
||||
FeatureEnum feature = name.getFeature();
|
||||
if(!featureConfigService.doesFeatureExist(name)) {
|
||||
throw new FeatureNotFoundException("Feature not found.", feature.getKey(), featureConfigService.getFeaturesAsList());
|
||||
throw new FeatureNotFoundException(feature.getKey(), featureConfigService.getFeaturesAsList());
|
||||
}
|
||||
updateFeatureFlag(feature, server, true);
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public class FeatureFlagServiceBean implements FeatureFlagService {
|
||||
public void disableFeature(FeatureConfig name, AServer server) {
|
||||
FeatureEnum feature = name.getFeature();
|
||||
if(!featureConfigService.doesFeatureExist(name)) {
|
||||
throw new FeatureNotFoundException("Feature not found.", feature.getKey(), featureConfigService.getFeaturesAsList());
|
||||
throw new FeatureNotFoundException(feature.getKey(), featureConfigService.getFeaturesAsList());
|
||||
}
|
||||
updateFeatureFlag(feature, server, false);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.EmoteNotDefinedException;
|
||||
import dev.sheldan.abstracto.core.exception.ExceptionNotInServerException;
|
||||
import dev.sheldan.abstracto.core.exception.ConfiguredEmoteNotUsableException;
|
||||
import dev.sheldan.abstracto.core.exception.EmoteNotInServerException;
|
||||
import dev.sheldan.abstracto.core.exception.GuildNotFoundException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
@@ -55,7 +55,7 @@ public class MessageServiceBean implements MessageService {
|
||||
return message.addReaction(emoteById).submit();
|
||||
} else {
|
||||
log.error("Emote with key {} and id {} for guild {} was not found.", emoteKey, emote.getEmoteId(), guild.getId());
|
||||
throw new EmoteNotDefinedException(emoteKey);
|
||||
throw new ConfiguredEmoteNotUsableException(emote);
|
||||
}
|
||||
} else {
|
||||
return message.addReaction(emote.getEmoteKey()).submit();
|
||||
@@ -79,7 +79,7 @@ public class MessageServiceBean implements MessageService {
|
||||
public CompletableFuture<Void> addReactionToMessageWithFuture(Long emoteId, Long serverId, Message message) {
|
||||
Emote emoteById = botService.getInstance().getEmoteById(emoteId);
|
||||
if(emoteById == null) {
|
||||
throw new ExceptionNotInServerException(emoteId);
|
||||
throw new EmoteNotInServerException(emoteId);
|
||||
}
|
||||
return message.addReaction(emoteById).submit();
|
||||
}
|
||||
@@ -89,7 +89,7 @@ public class MessageServiceBean implements MessageService {
|
||||
if(Boolean.TRUE.equals(emote.getCustom())) {
|
||||
Emote emoteById = botService.getInstance().getEmoteById(emote.getEmoteId());
|
||||
if(emoteById == null) {
|
||||
throw new ExceptionNotInServerException(emote.getEmoteId());
|
||||
throw new EmoteNotInServerException(emote.getEmoteId());
|
||||
}
|
||||
return message.removeReaction(emoteById).submit();
|
||||
} else {
|
||||
@@ -102,7 +102,7 @@ public class MessageServiceBean implements MessageService {
|
||||
if(Boolean.TRUE.equals(emote.getCustom())) {
|
||||
Emote emoteById = botService.getInstance().getEmoteById(emote.getEmoteId());
|
||||
if(emoteById == null) {
|
||||
throw new ExceptionNotInServerException(emote.getEmoteId());
|
||||
throw new EmoteNotInServerException(emote.getEmoteId());
|
||||
}
|
||||
return message.clearReactions(emoteById).submit();
|
||||
} else {
|
||||
@@ -150,7 +150,7 @@ public class MessageServiceBean implements MessageService {
|
||||
if(Boolean.TRUE.equals(emote.getCustom())) {
|
||||
Emote emoteById = botService.getInstance().getEmoteById(emote.getEmoteId());
|
||||
if(emoteById == null) {
|
||||
throw new ExceptionNotInServerException(emote.getEmoteId());
|
||||
throw new EmoteNotInServerException(emote.getEmoteId());
|
||||
}
|
||||
return message.removeReaction(emoteById, member.getUser()).submit();
|
||||
} else {
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.service.ExceptionService;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotFoundException;
|
||||
import dev.sheldan.abstracto.core.interactive.DelayedActionConfig;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.interactive.*;
|
||||
import dev.sheldan.abstracto.core.models.AServerChannelUserId;
|
||||
import dev.sheldan.abstracto.core.models.template.commands.SetupCompletedNotificationModel;
|
||||
import dev.sheldan.abstracto.core.models.template.commands.SetupInitialMessageModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.TextChannel;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -17,6 +19,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
@@ -46,8 +49,11 @@ public class SetupServiceBean implements SetupService {
|
||||
@Autowired
|
||||
private BotService botService;
|
||||
|
||||
@Autowired
|
||||
private ExceptionService exceptionService;
|
||||
|
||||
@Override
|
||||
public void performSetup(FeatureConfig featureConfig, AServerChannelUserId user, Long initialMessageId) {
|
||||
public CompletableFuture<Void> performSetup(FeatureConfig featureConfig, AServerChannelUserId user, Long initialMessageId) {
|
||||
List<String> requiredSystemConfigKeys = featureConfig.getRequiredSystemConfigKeys();
|
||||
List<SetupExecution> steps = new ArrayList<>();
|
||||
requiredSystemConfigKeys.forEach(s -> {
|
||||
@@ -87,21 +93,23 @@ public class SetupServiceBean implements SetupService {
|
||||
.featureConfig(featureConfig)
|
||||
.build();
|
||||
Optional<TextChannel> textChannelInGuild = channelService.getTextChannelInGuild(user.getGuildId(), user.getChannelId());
|
||||
textChannelInGuild.ifPresent(textChannel -> {
|
||||
if(textChannelInGuild.isPresent()) {
|
||||
TextChannel textChannel = textChannelInGuild.get();
|
||||
String text = templateService.renderTemplate("setup_initial_message", setupInitialMessageModel);
|
||||
channelService.sendTextToChannel(text, textChannel);
|
||||
executeSetup(featureConfig, steps, user, new ArrayList<>());
|
||||
});
|
||||
|
||||
return executeSetup(featureConfig, steps, user, new ArrayList<>());
|
||||
}
|
||||
throw new ChannelNotFoundException(user.getChannelId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void executeSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfig> delayedActionConfigs) {
|
||||
steps.stream().findFirst().ifPresent(execution -> executeStep(user, execution, delayedActionConfigs, featureConfig));
|
||||
public CompletableFuture<Void> executeSetup(FeatureConfig featureConfig, List<SetupExecution> steps, AServerChannelUserId user, List<DelayedActionConfig> delayedActionConfigs) {
|
||||
SetupExecution nextStep = steps.get(0);
|
||||
return executeStep(user, nextStep, delayedActionConfigs, featureConfig);
|
||||
}
|
||||
|
||||
private void executeStep(AServerChannelUserId aUserInAServer, SetupExecution execution, List<DelayedActionConfig> delayedActionConfigs, FeatureConfig featureConfig) {
|
||||
execution.getStep().execute(aUserInAServer, execution.getParameter()).thenAccept(aVoid -> {
|
||||
private CompletableFuture<Void> executeStep(AServerChannelUserId aUserInAServer, SetupExecution execution, List<DelayedActionConfig> delayedActionConfigs, FeatureConfig featureConfig) {
|
||||
return execution.getStep().execute(aUserInAServer, execution.getParameter()).thenAccept(aVoid -> {
|
||||
if(aVoid.getResult().equals(SetupStepResultType.SUCCESS)) {
|
||||
delayedActionConfigs.addAll(aVoid.getDelayedActionConfigList());
|
||||
if(execution.getNextStep() != null) {
|
||||
@@ -122,12 +130,9 @@ public class SetupServiceBean implements SetupService {
|
||||
|
||||
@Transactional
|
||||
public void showExceptionMessage(Throwable throwable, AServerChannelUserId aServerChannelUserId) {
|
||||
if(throwable instanceof Templatable) {
|
||||
Templatable exception = (Templatable) throwable;
|
||||
String text = templateService.renderTemplate(exception.getTemplateName(), exception.getTemplateModel());
|
||||
Optional<TextChannel> channelOptional = botService.getTextChannelFromServerOptional(aServerChannelUserId.getGuildId(), aServerChannelUserId.getChannelId());
|
||||
channelOptional.ifPresent(channel -> channelService.sendTextToChannel(text, channel));
|
||||
}
|
||||
Optional<TextChannel> channelOptional = botService.getTextChannelFromServerOptional(aServerChannelUserId.getGuildId(), aServerChannelUserId.getChannelId());
|
||||
Member member = botService.getMemberInServer(aServerChannelUserId.getGuildId(), aServerChannelUserId.getUserId());
|
||||
channelOptional.ifPresent(textChannel -> exceptionService.reportExceptionToChannel(throwable, textChannel, member));
|
||||
}
|
||||
|
||||
@Transactional
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.service;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullUser;
|
||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.service.management.UserInServerService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -13,8 +13,8 @@ public class UserInServerServiceBean implements UserInServerService {
|
||||
private BotService botService;
|
||||
|
||||
@Override
|
||||
public FullUser getFullUser(AUserInAServer aUserInAServer) {
|
||||
return FullUser
|
||||
public FullUserInServer getFullUser(AUserInAServer aUserInAServer) {
|
||||
return FullUserInServer
|
||||
.builder()
|
||||
.member(botService.getMemberInServer(aUserInAServer))
|
||||
.aUserInAServer(aUserInAServer)
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package dev.sheldan.abstracto.core.service.management;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.exception.ChannelAlreadyInChannelGroupException;
|
||||
import dev.sheldan.abstracto.core.command.exception.ChannelGroupExistsException;
|
||||
import dev.sheldan.abstracto.core.command.exception.ChannelGroupNotFoundException;
|
||||
import dev.sheldan.abstracto.core.command.exception.ChannelNotInChannelGroupException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
@@ -56,7 +58,7 @@ public class ChannelGroupManagementServiceBean implements ChannelGroupManagement
|
||||
public AChannelGroup addChannelToChannelGroup(AChannelGroup channelGroup, AChannel channel) {
|
||||
Predicate<AChannel> channelInGroupPredicate = channel1 -> channel1.getId().equals(channel.getId());
|
||||
if(channelGroup.getChannels().stream().anyMatch(channelInGroupPredicate)) {
|
||||
throw new ChannelGroupExistsException(String.format("Channel %s is already part of group %s.", channel.getId(), channelGroup.getGroupName()));
|
||||
throw new ChannelAlreadyInChannelGroupException(channel, channelGroup);
|
||||
}
|
||||
channelGroup.getChannels().add(channel);
|
||||
channel.getGroups().add(channelGroup);
|
||||
@@ -67,7 +69,7 @@ public class ChannelGroupManagementServiceBean implements ChannelGroupManagement
|
||||
public void removeChannelFromChannelGroup(AChannelGroup channelGroup, AChannel channel) {
|
||||
Predicate<AChannel> channelInGroupPredicate = channel1 -> channel1.getId().equals(channel.getId());
|
||||
if(channelGroup.getChannels().stream().noneMatch(channelInGroupPredicate)) {
|
||||
throw new ChannelGroupExistsException(String.format("Channel %s is not part of group %s.", channel.getId(), channelGroup.getGroupName()));
|
||||
throw new ChannelNotInChannelGroupException(channel, channelGroup);
|
||||
}
|
||||
channelGroup.getChannels().removeIf(channelInGroupPredicate);
|
||||
channel.getGroups().removeIf(channelGroup1 -> channelGroup1.getId().equals(channelGroup.getId()));
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.IncorrectParameter;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParameters;
|
||||
import dev.sheldan.abstracto.core.command.exception.IncorrectParameterException;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientParametersException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -52,17 +52,17 @@ public abstract class AbstractConditionableCommand implements ConditionalCommand
|
||||
if(context.getParameters() != null && context.getParameters().getParameters() != null && context.getParameters().getParameters().size() >= i) {
|
||||
boolean parameterIsPresent = i < context.getParameters().getParameters().size();
|
||||
if(parameterIsPresent && !desiredType.isInstance(context.getParameters().getParameters().get(i))) {
|
||||
throw new IncorrectParameter(this, desiredType, parameter.getName());
|
||||
throw new IncorrectParameterException(this, desiredType, parameter.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void checkMandatoryExp(CommandContext context, int i, Parameter parameter, Class desiredType) {
|
||||
if(context.getParameters() == null || context.getParameters().getParameters() == null || context.getParameters().getParameters().isEmpty() || i >= context.getParameters().getParameters().size()) {
|
||||
throw new InsufficientParameters(this, parameter.getName());
|
||||
throw new InsufficientParametersException(this, parameter.getName());
|
||||
}
|
||||
if(!desiredType.isInstance(context.getParameters().getParameters().get(i))) {
|
||||
throw new IncorrectParameter(this, desiredType, parameter.getName());
|
||||
throw new IncorrectParameterException(this, desiredType, parameter.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.exception.CommandDisabledException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.models.database.ACommand;
|
||||
import dev.sheldan.abstracto.core.command.service.ChannelGroupCommandService;
|
||||
@@ -21,6 +22,9 @@ public class CommandDisabledCondition implements CommandCondition {
|
||||
public ConditionResult shouldExecute(CommandContext context, Command command) {
|
||||
ACommand acommand = commandManagementService.findCommandByName(command.getConfiguration().getName());
|
||||
Boolean booleanResult = channelGroupCommandService.isCommandEnabled(acommand, context.getUserInitiatedContext().getChannel());
|
||||
if(!booleanResult) {
|
||||
throw new CommandDisabledException();
|
||||
}
|
||||
return ConditionResult.builder().result(booleanResult).reason("Command is disabled.").build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.exception.InsufficientPermissionException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
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;
|
||||
@@ -10,9 +10,12 @@ import dev.sheldan.abstracto.core.command.service.management.CommandManagementSe
|
||||
import dev.sheldan.abstracto.core.models.database.ARole;
|
||||
import dev.sheldan.abstracto.core.service.RoleService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class CommandDisallowedCondition implements CommandCondition {
|
||||
|
||||
@@ -41,11 +44,7 @@ public class CommandDisallowedCondition implements CommandCondition {
|
||||
return ConditionResult.builder().result(true).build();
|
||||
}
|
||||
}
|
||||
InsufficientPermissionMessage insufficientPermissionMessage = InsufficientPermissionMessage
|
||||
.builder()
|
||||
.allowedRoles(roleService.getRolesFromGuild(commandForServer.getAllowedRoles()))
|
||||
.build();
|
||||
String message = templateService.renderTemplate("insufficient_role", insufficientPermissionMessage);
|
||||
return ConditionResult.builder().result(false).reason(message).build();
|
||||
List<Role> allowedRoles = roleService.getRolesFromGuild(commandForServer.getAllowedRoles());
|
||||
throw new InsufficientPermissionException(allowedRoles);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.exception.FeatureDisabledException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
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;
|
||||
@@ -30,11 +30,7 @@ public class FeatureEnabledCondition implements CommandCondition {
|
||||
if(feature != null) {
|
||||
featureFlagValue = featureFlagService.getFeatureFlagValue(feature, context.getGuild().getIdLong());
|
||||
if(!featureFlagValue) {
|
||||
FeatureDisabledMessage featureDisabledMessage = FeatureDisabledMessage
|
||||
.builder()
|
||||
.featureConfig(featureConfigService.getFeatureDisplayForFeature(feature))
|
||||
.build();
|
||||
reason = templateService.renderTemplate("feature_disabled_message", featureDisabledMessage);
|
||||
throw new FeatureDisabledException(featureConfigService.getFeatureDisplayForFeature(feature));
|
||||
}
|
||||
}
|
||||
return ConditionResult.builder().reason(reason).result(featureFlagValue).build();
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package dev.sheldan.abstracto.core.command.condition;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.exception.ImmuneUserException;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
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;
|
||||
@@ -41,17 +41,11 @@ public class ImmuneUserCondition implements CommandCondition {
|
||||
Member member = any.get();
|
||||
for (ARole role : commandForServer.getImmuneRoles()) {
|
||||
if (roleService.memberHasRole(member, role)) {
|
||||
UserImmuneMessage userImmuneMessage = UserImmuneMessage
|
||||
.builder()
|
||||
.role(roleService.getRoleFromGuild(role))
|
||||
.build();
|
||||
String message = templateService.renderTemplate("immune_role", userImmuneMessage);
|
||||
return ConditionResult.builder().result(false).reason(message).build();
|
||||
throw new ImmuneUserException(roleService.getRoleFromGuild(role));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ConditionResult.builder().result(true).build();
|
||||
|
||||
}
|
||||
|
||||
private Member toMember(Object o) {
|
||||
|
||||
@@ -17,7 +17,7 @@ public class CommandConfiguration {
|
||||
private boolean async = false;
|
||||
|
||||
@Builder.Default
|
||||
private boolean reportsException = false;
|
||||
private boolean supportsEmbedException = false;
|
||||
|
||||
@Builder.Default
|
||||
private List<Parameter> parameters = new ArrayList<>();
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
|
||||
public class AbstractoTemplatedException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String templateKey;
|
||||
|
||||
public AbstractoTemplatedException(String message, String templateKey) {
|
||||
super(message);
|
||||
this.templateKey = templateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return templateKey;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelAlreadyInChannelGroupExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class ChannelAlreadyInChannelGroupException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final ChannelAlreadyInChannelGroupExceptionModel model;
|
||||
|
||||
public ChannelAlreadyInChannelGroupException(AChannel channel, AChannelGroup group) {
|
||||
super("Channel is already part of channel group");
|
||||
this.model = ChannelAlreadyInChannelGroupExceptionModel.builder().channel(channel).channelGroup(group).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "channel_already_in_channel_group_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupExistsExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ChannelGroupExistsException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String name;
|
||||
private final ChannelGroupExistsExceptionModel model;
|
||||
|
||||
public ChannelGroupExistsException(String name) {
|
||||
super("");
|
||||
this.name = name;
|
||||
super("Channel group already exists");
|
||||
this.model = ChannelGroupExistsExceptionModel.builder().name(name).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21,8 +20,6 @@ public class ChannelGroupExistsException extends AbstractoRunTimeException imple
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("name", this.name);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ChannelGroupNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private String name;
|
||||
private List<String> available;
|
||||
private final ChannelGroupNotFoundExceptionModel model;
|
||||
|
||||
public ChannelGroupNotFoundException(String key, List<String> available) {
|
||||
super("");
|
||||
this.name = key;
|
||||
this.available = available;
|
||||
super("Channel group not found");
|
||||
this.model = ChannelGroupNotFoundExceptionModel.builder().name(key).available(available).build();
|
||||
}
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
@@ -23,9 +21,6 @@ public class ChannelGroupNotFoundException extends AbstractoRunTimeException imp
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("name", this.name);
|
||||
param.put("available", String.join(", ", this.available));
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelNotInChannelGroupExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class ChannelNotInChannelGroupException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final ChannelNotInChannelGroupExceptionModel model;
|
||||
|
||||
public ChannelNotInChannelGroupException(AChannel channel, AChannelGroup group) {
|
||||
super("Channel is already part of channel group");
|
||||
this.model = ChannelNotInChannelGroupExceptionModel.builder().channel(channel).channelGroup(group).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "channel_not_in_channel_group_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -3,19 +3,15 @@ package dev.sheldan.abstracto.core.command.exception;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class CommandNotFound extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
public CommandNotFound(String s) {
|
||||
super(s);
|
||||
}
|
||||
public class CommandDisabledException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "command_not_found";
|
||||
return "command_disabled_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return null;
|
||||
return new Object();
|
||||
}
|
||||
}
|
||||
@@ -5,15 +5,12 @@ import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class CommandNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
public CommandNotFoundException() {
|
||||
super("");
|
||||
}
|
||||
public CommandNotFoundException(String text) {
|
||||
super(text);
|
||||
super("Command not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "command_not_found_exception_text";
|
||||
return "command_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.CommandParameterKeyValueWrongTypeModel;
|
||||
import dev.sheldan.abstracto.core.command.models.exception.CommandParameterKeyValueWrongTypeExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
@@ -8,11 +8,11 @@ import java.util.List;
|
||||
|
||||
public class CommandParameterKeyValueWrongTypeException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private CommandParameterKeyValueWrongTypeModel model;
|
||||
private CommandParameterKeyValueWrongTypeExceptionModel model;
|
||||
|
||||
public CommandParameterKeyValueWrongTypeException(List<String> expectedValues) {
|
||||
super("Command parameter value did not have expected values present");
|
||||
this.model = CommandParameterKeyValueWrongTypeModel.builder().expectedValues(expectedValues).build();
|
||||
this.model = CommandParameterKeyValueWrongTypeExceptionModel.builder().expectedValues(expectedValues).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.FeatureDisabledExceptionModel;
|
||||
import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class FeatureDisabledException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final FeatureDisabledExceptionModel model;
|
||||
|
||||
public FeatureDisabledException(FeatureConfig featureConfig) {
|
||||
super("Feature has been disabled");
|
||||
this.model = FeatureDisabledExceptionModel.builder().featureConfig(featureConfig).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "feature_disabled_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ImmuneUserExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
public class ImmuneUserException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final transient ImmuneUserExceptionModel model;
|
||||
|
||||
public ImmuneUserException(Role role) {
|
||||
super("User is immune against the command");
|
||||
this.model = ImmuneUserExceptionModel.builder().role(role).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "immune_role_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class IncorrectParameter extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final transient Command command;
|
||||
private final String parameterName;
|
||||
private final Class clazz;
|
||||
|
||||
public IncorrectParameter(Command command, Class expected, String parameterName) {
|
||||
super("");
|
||||
this.command = command;
|
||||
this.parameterName = parameterName;
|
||||
this.clazz = expected;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "incorrect_parameters";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> model = new HashMap<>();
|
||||
model.put("parameterName", parameterName);
|
||||
model.put("class", this.clazz);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.IncorrectParameterExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class IncorrectParameterException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final IncorrectParameterExceptionModel model;
|
||||
|
||||
public IncorrectParameterException(Command command, Class expected, String parameterName) {
|
||||
super("Incorrect parameter given for parameter");
|
||||
this.model = IncorrectParameterExceptionModel.builder().clazz(expected).parameterName(parameterName).command(command).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "incorrect_parameters_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
@Getter
|
||||
public class InsufficientParameters extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final transient Command command;
|
||||
private final String parameterName;
|
||||
|
||||
public InsufficientParameters(Command command, String parameterName) {
|
||||
super("");
|
||||
this.command = command;
|
||||
this.parameterName = parameterName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "insufficient_parameters";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> model = new HashMap<>();
|
||||
model.put("parameterName", parameterName);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.InsufficientParametersExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
|
||||
public class InsufficientParametersException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final InsufficientParametersExceptionModel model;
|
||||
|
||||
public InsufficientParametersException(Command command, String parameterName) {
|
||||
super("Insufficient parameters given for command");
|
||||
this.model = InsufficientParametersExceptionModel.builder().command(command).parameterName(parameterName).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "insufficient_parameters_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.InsufficientPermissionExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class InsufficientPermissionException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final InsufficientPermissionExceptionModel model;
|
||||
|
||||
public InsufficientPermissionException(List<Role> allowedRoles) {
|
||||
super("Insufficient permissions, required role not given.");
|
||||
this.model = InsufficientPermissionExceptionModel.builder().allowedRoles(allowedRoles).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "insufficient_role_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ParameterTooLong extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
|
||||
private final transient 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);
|
||||
this.command = command;
|
||||
this.parameterName = parameterName;
|
||||
this.actualLength = actualLength;
|
||||
this.maximumLength = maximumLength;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "parameter_too_long";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> model = new HashMap<>();
|
||||
model.put("parameterName", parameterName);
|
||||
model.put("actualLength", actualLength);
|
||||
model.put("maximumLength", maximumLength);
|
||||
model.put("command", command);
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
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,15 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ChannelAlreadyInChannelGroupExceptionModel implements Serializable {
|
||||
private AChannel channel;
|
||||
private AChannelGroup channelGroup;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ChannelGroupExistsExceptionModel implements Serializable {
|
||||
private String name;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ChannelGroupNotFoundExceptionModel implements Serializable {
|
||||
private String name;
|
||||
private List<String> available;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AChannel;
|
||||
import dev.sheldan.abstracto.core.models.database.AChannelGroup;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ChannelNotInChannelGroupExceptionModel implements Serializable {
|
||||
private AChannel channel;
|
||||
private AChannelGroup channelGroup;
|
||||
}
|
||||
@@ -9,6 +9,6 @@ import java.util.List;
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class CommandParameterKeyValueWrongTypeModel {
|
||||
public class CommandParameterKeyValueWrongTypeExceptionModel {
|
||||
private List<String> expectedValues;
|
||||
}
|
||||
@@ -5,9 +5,11 @@ import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
public class FeatureDisabledMessage {
|
||||
public class FeatureDisabledExceptionModel implements Serializable {
|
||||
private FeatureConfig featureConfig;
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.FullUser;
|
||||
import dev.sheldan.abstracto.core.models.FullUserInServer;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
@@ -10,7 +11,8 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@Builder
|
||||
public class GenericExceptionModel {
|
||||
private FullUser user;
|
||||
private FullUserInServer user;
|
||||
private FullUser fullUser;
|
||||
private Throwable throwable;
|
||||
|
||||
public Templatable getTemplate() {
|
||||
|
||||
@@ -8,6 +8,6 @@ import net.dv8tion.jda.api.entities.Role;
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class UserImmuneMessage {
|
||||
public class ImmuneUserExceptionModel {
|
||||
private Role role;
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
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 IncorrectParameterExceptionModel implements Serializable {
|
||||
private final transient Command command;
|
||||
private final String parameterName;
|
||||
private final Class clazz;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.Command;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class InsufficientParametersExceptionModel implements Serializable {
|
||||
private final transient Command command;
|
||||
private final String parameterName;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class InsufficientPermissionExceptionModel implements Serializable {
|
||||
private transient List<Role> allowedRoles;
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
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;
|
||||
}
|
||||
@@ -3,7 +3,14 @@ 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;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.MessageChannel;
|
||||
import net.dv8tion.jda.api.events.message.guild.GuildMessageReceivedEvent;
|
||||
import net.dv8tion.jda.api.events.message.priv.PrivateMessageReceivedEvent;
|
||||
|
||||
public interface ExceptionService {
|
||||
CommandResult reportExceptionToContext(Throwable exception, CommandContext context, Command command);
|
||||
void reportExceptionToGuildMessageReceivedContext(Throwable exception, GuildMessageReceivedEvent event);
|
||||
void reportExceptionToPrivateMessageReceivedContext(Throwable exception, PrivateMessageReceivedEvent event);
|
||||
void reportExceptionToChannel(Throwable exception, MessageChannel channel, Member member);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,11 @@ package dev.sheldan.abstracto.core.config;
|
||||
import dev.sheldan.abstracto.core.interactive.SetupStep;
|
||||
import dev.sheldan.abstracto.core.service.FeatureValidator;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public interface FeatureConfig {
|
||||
public interface FeatureConfig extends Serializable {
|
||||
FeatureEnum getFeature();
|
||||
default List<FeatureConfig> getRequiredFeatures() {
|
||||
return Collections.emptyList();
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.CategoryNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class CategoryNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final Long categoryId;
|
||||
private final Long guildId;
|
||||
private final CategoryNotFoundExceptionModel model;
|
||||
|
||||
public CategoryNotFoundException(Long categoryId, Long guildId) {
|
||||
super("");
|
||||
this.categoryId = categoryId;
|
||||
this.guildId = guildId;
|
||||
super("Category not found");
|
||||
this.model = CategoryNotFoundExceptionModel.builder().categoryId(categoryId).guildId(guildId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,9 +19,6 @@ public class CategoryNotFoundException extends AbstractoRunTimeException impleme
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Long> param = new HashMap<>();
|
||||
param.put("categoryId", this.categoryId);
|
||||
param.put("guildId", this.guildId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.ChannelNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ChannelNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final Long channelId;
|
||||
private final ChannelNotFoundExceptionModel model;
|
||||
|
||||
public ChannelNotFoundException(Long channelId) {
|
||||
super("Channel not found in database");
|
||||
this.channelId = channelId;
|
||||
this.model = ChannelNotFoundExceptionModel.builder().channelId(channelId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,8 +19,6 @@ public class ChannelNotFoundException extends AbstractoRunTimeException implemen
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Long> param = new HashMap<>();
|
||||
param.put("channelId", this.channelId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.ConfigurationKeyNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class ConfigurationKeyNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String key;
|
||||
private final ConfigurationKeyNotFoundExceptionModel model;
|
||||
|
||||
public ConfigurationKeyNotFoundException(String key) {
|
||||
super("");
|
||||
this.key = key;
|
||||
super("Configuration key not found");
|
||||
this.model = ConfigurationKeyNotFoundExceptionModel.builder().key(key).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,8 +19,6 @@ public class ConfigurationKeyNotFoundException extends AbstractoRunTimeException
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("key", this.key);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,25 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AEmote;
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteConfiguredButNotUsableExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class ConfiguredEmoteNotUsableException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final EmoteConfiguredButNotUsableExceptionModel model;
|
||||
|
||||
public ConfiguredEmoteNotUsableException(AEmote emote) {
|
||||
super("Emote was configured in database, but is not usable by the bot anymore.");
|
||||
this.model = EmoteConfiguredButNotUsableExceptionModel.builder().emote(emote).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "emote_defined_but_not_usable_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -1,19 +1,18 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.DurationFormatExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class DurationFormatException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String invalidFormat;
|
||||
private final List<String> validFormats;
|
||||
private final DurationFormatExceptionModel model;
|
||||
|
||||
|
||||
public DurationFormatException(String wrongFormat, List<String> validFormats) {
|
||||
super("");
|
||||
this.invalidFormat = wrongFormat;
|
||||
this.validFormats = validFormats;
|
||||
super("Duration format exception ");
|
||||
this.model = DurationFormatExceptionModel.builder().invalidFormat(wrongFormat).validFormats(validFormats).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,9 +22,6 @@ public class DurationFormatException extends AbstractoRunTimeException implement
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("format", this.invalidFormat);
|
||||
param.put("valid", String.join(", ", this.validFormats));
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotDefinedExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EmoteNotDefinedException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String emoteKey;
|
||||
private final EmoteNotDefinedExceptionModel model;
|
||||
|
||||
public EmoteNotDefinedException(String key) {
|
||||
super("");
|
||||
this.emoteKey = key;
|
||||
super(String.format("Emote %s not defined", key));
|
||||
this.model = EmoteNotDefinedExceptionModel.builder().emoteKey(key).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,8 +19,6 @@ public class EmoteNotDefinedException extends AbstractoRunTimeException implemen
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("emoteKey", this.emoteKey);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,17 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class EmoteNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String emoteKey;
|
||||
private final List<String> available;
|
||||
private final EmoteNotFoundExceptionModel model;
|
||||
|
||||
public EmoteNotFoundException(String key, List<String> availableEmotes) {
|
||||
super("");
|
||||
this.emoteKey = key;
|
||||
this.available = availableEmotes;
|
||||
super("Emote not found");
|
||||
this.model = EmoteNotFoundExceptionModel.builder().emoteKey(key).available(availableEmotes).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -23,9 +21,6 @@ public class EmoteNotFoundException extends AbstractoRunTimeException implements
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("emoteKey", this.emoteKey);
|
||||
param.put("available", String.join(",", this.available));
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotFoundInDbExceptionModel;
|
||||
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;
|
||||
private final EmoteNotFoundInDbExceptionModel model;
|
||||
|
||||
public EmoteNotFoundInDbException(Integer emoteId) {
|
||||
super("");
|
||||
this.emoteId = emoteId;
|
||||
super("Emote not found in database");
|
||||
this.model = EmoteNotFoundInDbExceptionModel.builder().emoteId(emoteId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -21,8 +19,6 @@ public class EmoteNotFoundInDbException extends AbstractoRunTimeException implem
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> param = new HashMap<>();
|
||||
param.put("emoteId", this.emoteId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotInServerModel;
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotInServerExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class ExceptionNotInServerException extends AbstractoRunTimeException implements Templatable {
|
||||
public class EmoteNotInServerException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private EmoteNotInServerModel model;
|
||||
private final EmoteNotInServerExceptionModel model;
|
||||
|
||||
public ExceptionNotInServerException(Long emoteId) {
|
||||
public EmoteNotInServerException(Long emoteId) {
|
||||
super("Emote not available in server");
|
||||
this.model = EmoteNotInServerModel.builder().emoteId(emoteId).build();
|
||||
this.model = EmoteNotInServerExceptionModel.builder().emoteId(emoteId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1,21 +1,21 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotUsable;
|
||||
import dev.sheldan.abstracto.core.models.exception.EmoteNotUsableExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
import net.dv8tion.jda.api.entities.Emote;
|
||||
|
||||
public class EmoteNotUsableException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private EmoteNotUsable model;
|
||||
private final EmoteNotUsableExceptionModel model;
|
||||
|
||||
public EmoteNotUsableException(Emote emote) {
|
||||
super("");
|
||||
this.model = EmoteNotUsable.builder().emote(emote).build();
|
||||
super(String.format("Emote %s not usable by bot.", emote.getId()));
|
||||
this.model = EmoteNotUsableExceptionModel.builder().emote(emote).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "emote_not_usable";
|
||||
return "emote_not_usable_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.FeatureModeNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FeatureModeNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String featureMode;
|
||||
private final List<String> availableModes;
|
||||
private final FeatureModeNotFoundExceptionModel model;
|
||||
|
||||
public FeatureModeNotFoundException(String message, String featureMode, List<String> availableModes) {
|
||||
super(message);
|
||||
this.featureMode = featureMode;
|
||||
this.availableModes = availableModes;
|
||||
public FeatureModeNotFoundException(String featureMode, List<String> availableModes) {
|
||||
super("Feature mode not found.");
|
||||
this.model = FeatureModeNotFoundExceptionModel.builder().availableModes(availableModes).featureMode(featureMode).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "feature_mode_not_found";
|
||||
return "feature_mode_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("featureMode", this.featureMode);
|
||||
parameters.put("availableModes", this.availableModes);
|
||||
return parameters;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,27 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.FeatureNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class FeatureNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String feature;
|
||||
private final List<String> availableFeatures;
|
||||
private final FeatureNotFoundExceptionModel model;
|
||||
|
||||
public FeatureNotFoundException(String feature, List<String> availableFeatures) {
|
||||
super("Feature not found.");
|
||||
this.model = FeatureNotFoundExceptionModel.builder().featureName(feature).availableFeatures(availableFeatures).build();
|
||||
|
||||
public FeatureNotFoundException(String message, String feature, List<String> availableFeatures) {
|
||||
super(message);
|
||||
this.feature = feature;
|
||||
this.availableFeatures = availableFeatures;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "feature_not_found";
|
||||
return "feature_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> parameters = new HashMap<>();
|
||||
parameters.put("featureName", this.feature);
|
||||
parameters.put("availableFeatures", this.availableFeatures);
|
||||
return parameters;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,20 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.GuildNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GuildNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
private final Long guildId;
|
||||
|
||||
public GuildNotFoundException(String message, Long guildId) {
|
||||
super(message);
|
||||
this.guildId = guildId;
|
||||
}
|
||||
private final GuildNotFoundExceptionModel model;
|
||||
|
||||
public GuildNotFoundException(Long guildId) {
|
||||
super("");
|
||||
this.guildId = guildId;
|
||||
super("Guild not found");
|
||||
this.model = GuildNotFoundExceptionModel.builder().guildId(guildId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,8 +18,6 @@ public class GuildNotFoundException extends AbstractoRunTimeException implements
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Long> param = new HashMap<>();
|
||||
param.put("guildId", this.guildId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import dev.sheldan.abstracto.templating.Templatable;
|
||||
public class MemberNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
public MemberNotFoundException() {
|
||||
super("");
|
||||
super("Member was not found");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.PostTargetNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PostTargetNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String postTargetKey;
|
||||
private final PostTargetNotFoundExceptionModel model;
|
||||
|
||||
public PostTargetNotFoundException(String key) {
|
||||
super("");
|
||||
this.postTargetKey = key;
|
||||
super("Post target not found");
|
||||
this.model = PostTargetNotFoundExceptionModel.builder().postTargetKey(key).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "post_target_not_found";
|
||||
return "post_target_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("key", this.postTargetKey);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,31 +1,26 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.PostTargetNotValidExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class PostTargetNotValidException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final String postTargetKey;
|
||||
private final List<String> availableTargets;
|
||||
private final PostTargetNotValidExceptionModel model;
|
||||
|
||||
public PostTargetNotValidException(String key, List<String> available) {
|
||||
super("");
|
||||
this.postTargetKey = key;
|
||||
this.availableTargets = available;
|
||||
super("Given post target was not in the list of valid post targets");
|
||||
this.model = PostTargetNotValidExceptionModel.builder().availableTargets(available).postTargetKey(key).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "post_target_not_valid";
|
||||
return "post_target_not_valid_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, String> param = new HashMap<>();
|
||||
param.put("key", this.postTargetKey);
|
||||
param.put("available", String.join(",", this.availableTargets));
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
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.core.models.exception.RoleDeletedExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class RoleDeletedException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private RoleDeletedModel model;
|
||||
private final RoleDeletedExceptionModel model;
|
||||
|
||||
public RoleDeletedException(ARole role) {
|
||||
super("Role has been marked as deleted and cannot be used.");
|
||||
this.model = RoleDeletedModel.builder().role(role).build();
|
||||
this.model = RoleDeletedExceptionModel.builder().role(role).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "";
|
||||
return "role_disabled_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.RoleNotFoundInDBExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RoleNotFoundInDBException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final Long roleId;
|
||||
private final RoleNotFoundInDBExceptionModel model;
|
||||
|
||||
public RoleNotFoundInDBException(Long roleId) {
|
||||
super("");
|
||||
this.roleId = roleId;
|
||||
super("Role not found in database");
|
||||
this.model = RoleNotFoundInDBExceptionModel.builder().roleId(roleId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -20,8 +19,6 @@ public class RoleNotFoundInDBException extends AbstractoRunTimeException impleme
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Long> param = new HashMap<>();
|
||||
param.put("roleId", this.roleId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,18 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.RoleNotFoundInGuildExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RoleNotFoundInGuildException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final Long roleId;
|
||||
private final Long serverId;
|
||||
private final RoleNotFoundInGuildExceptionModel model;
|
||||
|
||||
public RoleNotFoundInGuildException(Long roleId, Long serverId) {
|
||||
super("");
|
||||
this.roleId = roleId;
|
||||
this.serverId = serverId;
|
||||
super("Role not found in guild");
|
||||
this.model = RoleNotFoundInGuildExceptionModel.builder().roleId(roleId).serverId(serverId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -22,9 +19,6 @@ public class RoleNotFoundInGuildException extends AbstractoRunTimeException impl
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Long> param = new HashMap<>();
|
||||
param.put("roleId", this.roleId);
|
||||
param.put("serverId", this.serverId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,24 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.UserInServerNotFoundExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class UserInServerNotFoundException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final Long userInServerId;
|
||||
private final UserInServerNotFoundExceptionModel model;
|
||||
|
||||
public UserInServerNotFoundException(Long userInServerId) {
|
||||
super("");
|
||||
this.userInServerId = userInServerId;
|
||||
super("User in server not found");
|
||||
this.model = UserInServerNotFoundExceptionModel.builder().userInServerId(userInServerId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "core_user_in_server_not_found_exception";
|
||||
return "user_in_server_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Long> param = new HashMap<>();
|
||||
param.put("userInServerId", this.userInServerId);
|
||||
return param;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,20 @@ package dev.sheldan.abstracto.core.interactive;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class SetupStepException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final SetupStepExceptionModel model;
|
||||
|
||||
public SetupStepException(Throwable throwable) {
|
||||
super("", throwable);
|
||||
super("Failed to execute setup step", throwable);
|
||||
SetupStepExceptionModel.SetupStepExceptionModelBuilder builder = SetupStepExceptionModel.builder();
|
||||
if(getCause() instanceof Templatable) {
|
||||
Templatable templatable = (Templatable) getCause();
|
||||
builder.templateKey(templatable.getTemplateName());
|
||||
builder.templateModel(templatable.getTemplateModel());
|
||||
}
|
||||
builder.message(getCause().getMessage());
|
||||
this.model = builder.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -17,14 +26,6 @@ public class SetupStepException extends AbstractoRunTimeException implements Tem
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
HashMap<String, Object> stringStringHashMap = new HashMap<>();
|
||||
if(getCause() instanceof Templatable) {
|
||||
Templatable templatable = (Templatable) getCause();
|
||||
stringStringHashMap.put("templateKey", templatable.getTemplateName());
|
||||
stringStringHashMap.put("templateModel", templatable.getTemplateModel());
|
||||
}
|
||||
stringStringHashMap.put("message", getCause().getMessage());
|
||||
|
||||
return stringStringHashMap;
|
||||
return model;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package dev.sheldan.abstracto.core.interactive;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class SetupStepExceptionModel implements Serializable {
|
||||
private String templateKey;
|
||||
private transient Object templateModel;
|
||||
private String message;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import java.io.Serializable;
|
||||
@Builder
|
||||
public class FullEmote implements Serializable {
|
||||
private AEmote fakeEmote;
|
||||
private Emote emote;
|
||||
private transient Emote emote;
|
||||
|
||||
public String getEmoteRepr() {
|
||||
if(!fakeEmote.getCustom()) {
|
||||
|
||||
@@ -6,12 +6,14 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class FullRole {
|
||||
public class FullRole implements Serializable {
|
||||
private ARole role;
|
||||
private Role serverRole;
|
||||
private transient Role serverRole;
|
||||
|
||||
public String getRoleRepr() {
|
||||
if(serverRole != null) {
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.models;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.database.AUserInAServer;
|
||||
import dev.sheldan.abstracto.core.models.database.AUser;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.User;
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
public class FullUser {
|
||||
private AUserInAServer aUserInAServer;
|
||||
private Member member;
|
||||
private AUser auser;
|
||||
private User user;
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user