mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-07 01:30:49 +00:00
[AB-166] refactored conditions to not use exceptions for their regular case, split up feature mode exception into condition and exception, if the conditions need to be checked somewhere else, a separate exception is required, fixed command not being disabled properly in channels
This commit is contained in:
@@ -4,13 +4,15 @@ import dev.sheldan.abstracto.core.command.Command;
|
||||
import dev.sheldan.abstracto.core.command.condition.ConditionResult;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.modmail.condition.ModMailContextCondition;
|
||||
import dev.sheldan.abstracto.modmail.exception.NotInModMailThreadException;
|
||||
import dev.sheldan.abstracto.modmail.condition.detail.NotInModMailThreadConditionDetail;
|
||||
import dev.sheldan.abstracto.modmail.models.database.ModMailThread;
|
||||
import dev.sheldan.abstracto.modmail.service.management.ModMailThreadManagementService;
|
||||
import dev.sheldan.abstracto.templating.service.TemplateService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
/**
|
||||
* This {@link dev.sheldan.abstracto.core.command.condition.CommandCondition} checks the channel it is executed in
|
||||
* and checks if the channel is a valid and open mod mail thread.
|
||||
@@ -26,10 +28,10 @@ public class RequiresModMailCondition implements ModMailContextCondition {
|
||||
|
||||
@Override
|
||||
public ConditionResult shouldExecute(CommandContext commandContext, Command command) {
|
||||
ModMailThread thread = modMailThreadManagementService.getByChannel(commandContext.getUserInitiatedContext().getChannel());
|
||||
if(thread != null) {
|
||||
Optional<ModMailThread> threadOptional = modMailThreadManagementService.getByChannelOptional(commandContext.getUserInitiatedContext().getChannel());
|
||||
if(threadOptional.isPresent()) {
|
||||
return ConditionResult.builder().result(true).build();
|
||||
}
|
||||
return ConditionResult.builder().result(false).exception(new NotInModMailThreadException()).build();
|
||||
return ConditionResult.builder().result(false).conditionDetail(new NotInModMailThreadConditionDetail()).build();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user