mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-30 07:06:24 +00:00
[AB-138] improving logging at various places fixing various issues regarding async commands and exception handling, fixing role role calculation being done twice
This commit is contained in:
@@ -25,6 +25,6 @@ public class CommandDisabledCondition implements CommandCondition {
|
||||
if(!booleanResult) {
|
||||
return ConditionResult.builder().result(true).exception(new CommandDisabledException()).build();
|
||||
}
|
||||
return ConditionResult.builder().result(true).reason("Command is disabled.").build();
|
||||
return ConditionResult.builder().result(true).reason("Command is enabled.").build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,8 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Role;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -17,6 +19,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class CommandDisallowedCondition implements CommandCondition {
|
||||
|
||||
|
||||
@@ -40,7 +43,9 @@ public class CommandDisallowedCondition implements CommandCondition {
|
||||
return ConditionResult.builder().result(true).build();
|
||||
}
|
||||
for (ARole role : commandForServer.getAllowedRoles()) {
|
||||
if (roleService.memberHasRole(context.getAuthor(), role)) {
|
||||
Member author = context.getAuthor();
|
||||
if (roleService.memberHasRole(author, role)) {
|
||||
log.trace("Member {} is able to execute restricted command {}, because of role {}.", author.getIdLong(), aCommand.getName(), role.getId());
|
||||
return ConditionResult.builder().result(true).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ import dev.sheldan.abstracto.core.config.FeatureEnum;
|
||||
import dev.sheldan.abstracto.core.service.FeatureConfigService;
|
||||
import dev.sheldan.abstracto.core.service.FeatureFlagService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class FeatureEnabledCondition implements CommandCondition {
|
||||
|
||||
@Autowired
|
||||
@@ -29,6 +31,7 @@ public class FeatureEnabledCondition implements CommandCondition {
|
||||
if(feature != null) {
|
||||
featureFlagValue = featureFlagService.getFeatureFlagValue(feature, context.getGuild().getIdLong());
|
||||
if(!featureFlagValue) {
|
||||
log.trace("Feature {} is disabled, disallows command {} to be executed in guild {}.", feature.getKey(), command.getConfiguration().getName(), context.getGuild().getId());
|
||||
FeatureDisabledException exception = new FeatureDisabledException(featureConfigService.getFeatureDisplayForFeature(command.getFeature()));
|
||||
return ConditionResult.builder().result(false).exception(exception).build();
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ 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 lombok.extern.slf4j.Slf4j;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
@@ -17,9 +18,9 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.Optional;
|
||||
|
||||
@Component
|
||||
@Slf4j
|
||||
public class ImmuneUserCondition implements CommandCondition {
|
||||
|
||||
|
||||
@Autowired
|
||||
private CommandInServerManagementService commandInServerManagementService;
|
||||
|
||||
@@ -41,6 +42,7 @@ public class ImmuneUserCondition implements CommandCondition {
|
||||
Member member = any.get();
|
||||
for (ARole role : commandForServer.getImmuneRoles()) {
|
||||
if (roleService.memberHasRole(member, role)) {
|
||||
log.trace("Member {} is immune against command {}, because of role {}.", member.getIdLong(), aCommand.getName(), role.getId());
|
||||
ImmuneUserException exception = new ImmuneUserException(roleService.getRoleFromGuild(role));
|
||||
return ConditionResult.builder().result(false).exception(exception).build();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package dev.sheldan.abstracto.core.command.config;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class AbstracatoModuleInterface implements ModuleInterface {
|
||||
public class AbstractoModuleInterface implements ModuleInterface {
|
||||
@Override
|
||||
public ModuleInfo getInfo() {
|
||||
return ModuleInfo.builder().name("default").description("Default module provided by abstracto").build();
|
||||
@@ -33,7 +33,7 @@ public class ContextConverter {
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Failed to execute builder method", e);
|
||||
}
|
||||
throw new AbstractoRunTimeException("Failed to create model from context");
|
||||
throw new AbstractoRunTimeException("Failed to create UserInitiatedServerContext from CommandContext.");
|
||||
}
|
||||
|
||||
public static <T extends SlimUserInitiatedServerContext> SlimUserInitiatedServerContext slimFromCommandContext(CommandContext commandContext, Class<T> clazz) {
|
||||
@@ -50,6 +50,6 @@ public class ContextConverter {
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Failed to execute builder method", e);
|
||||
}
|
||||
throw new AbstractoRunTimeException("Failed to create model from context");
|
||||
throw new AbstractoRunTimeException("Failed to create SlimUserInitiatedServerContext from CommandContext");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import java.util.List;
|
||||
|
||||
public interface ChannelGroupCommandManagementService {
|
||||
void setCommandInGroupTo(ACommand command, AChannelGroup group, Boolean enabled);
|
||||
AChannelGroupCommand createCommandInGroupTo(ACommand command, AChannelGroup group);
|
||||
AChannelGroupCommand createCommandInGroup(ACommand command, AChannelGroup group);
|
||||
AChannelGroupCommand getChannelGroupCommand(ACommand command, AChannelGroup group);
|
||||
List<AChannelGroupCommand> getAllGroupCommandsForCommand(ACommand command);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.core.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.models.exception.ServerChannelConflictExceptionModel;
|
||||
import dev.sheldan.abstracto.templating.Templatable;
|
||||
|
||||
public class ServerChannelConflictException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final ServerChannelConflictExceptionModel model;
|
||||
|
||||
public ServerChannelConflictException(Long serverId, Long channelId) {
|
||||
super("Given channel was not part of the assumed server.");
|
||||
this.model = ServerChannelConflictExceptionModel.builder().channelId(channelId).serverId(serverId).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "server_channel_conflict_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
package dev.sheldan.abstracto.core.models.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Builder
|
||||
public class ServerChannelConflictExceptionModel implements Serializable {
|
||||
private final Long serverId;
|
||||
private final Long channelId;
|
||||
}
|
||||
@@ -5,7 +5,8 @@ import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter @SuperBuilder
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
public class EchoModel extends UserInitiatedServerContext {
|
||||
private String text;
|
||||
}
|
||||
|
||||
@@ -4,7 +4,8 @@ import dev.sheldan.abstracto.core.models.context.UserInitiatedServerContext;
|
||||
import lombok.Getter;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
|
||||
@Getter @SuperBuilder
|
||||
@Getter
|
||||
@SuperBuilder
|
||||
public class PingModel extends UserInitiatedServerContext {
|
||||
private Long latency;
|
||||
}
|
||||
|
||||
@@ -7,14 +7,14 @@ import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
import java.util.List;
|
||||
|
||||
public interface PostTargetManagement {
|
||||
PostTarget createPostTarget(String name, AServer server, AChannel targetChanel);
|
||||
PostTarget createOrUpdate(String name, AServer server, AChannel targetChannel);
|
||||
PostTarget createPostTarget(String name, AChannel targetChanel);
|
||||
PostTarget createOrUpdate(String name, AChannel targetChannel);
|
||||
PostTarget createOrUpdate(String name, AServer server, Long channelId);
|
||||
PostTarget createOrUpdate(String name, Long serverId, Long channelId);
|
||||
PostTarget getPostTarget(String name, AServer server);
|
||||
PostTarget getPostTarget(String name, Long serverId);
|
||||
Boolean postTargetExists(String name, AServer server);
|
||||
boolean postTargetExists(String name, Long serverId);
|
||||
PostTarget updatePostTarget(PostTarget target, AServer server, AChannel newTargetChannel);
|
||||
PostTarget updatePostTarget(PostTarget target, AChannel newTargetChannel);
|
||||
List<PostTarget> getPostTargetsInServer(AServer server);
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ public class ChannelUtils {
|
||||
}
|
||||
|
||||
public static String buildChannelUrl(Long serverId, Long channelId) {
|
||||
return String.format("https://discordapp.com/channels/%s/%s/", serverId, channelId);
|
||||
return String.format("https://discord.com/channels/%s/%s/", serverId, channelId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,6 +49,6 @@ public class ContextUtils {
|
||||
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException e) {
|
||||
log.error("Failed to execute builder method", e);
|
||||
}
|
||||
throw new AbstractoRunTimeException("Failed to create model from message");
|
||||
throw new AbstractoRunTimeException("Failed to create UserInitiatedServerContext from message");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,6 @@ public class MessageUtils {
|
||||
}
|
||||
|
||||
public static String buildMessageUrl(Long serverId, Long channelId, Long messageId) {
|
||||
return String.format("https://discordapp.com/channels/%s/%s/%s", serverId, channelId, messageId);
|
||||
return String.format("https://discord.com/channels/%s/%s/%s", serverId, channelId, messageId);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user