Рефакторинг определения actionunit
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
88beadb445
commit
e17a87730b
@ -1,19 +1,12 @@
|
||||
package dev.struchkov.godfather.quarkus.core;
|
||||
|
||||
import dev.struchkov.autoresponder.Responder;
|
||||
import dev.struchkov.godfather.exception.ConfigAppException;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.quarkus.context.service.ErrorHandler;
|
||||
import dev.struchkov.godfather.quarkus.context.service.Modifiable;
|
||||
import dev.struchkov.godfather.quarkus.context.service.PersonSettingService;
|
||||
import dev.struchkov.godfather.quarkus.context.service.Sending;
|
||||
import dev.struchkov.godfather.quarkus.core.action.ActionUnit;
|
||||
import dev.struchkov.godfather.quarkus.core.action.AnswerCheckAction;
|
||||
import dev.struchkov.godfather.quarkus.core.action.AnswerSaveAction;
|
||||
import dev.struchkov.godfather.quarkus.core.action.AnswerTextAction;
|
||||
import dev.struchkov.godfather.quarkus.core.action.cmd.ReplaceCmdAction;
|
||||
import dev.struchkov.godfather.quarkus.core.service.StorylineService;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.UnitRequest;
|
||||
@ -38,46 +31,26 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
|
||||
protected final PersonSettingService personSettingService;
|
||||
protected final StorylineService<M> storyLineService;
|
||||
protected Map<String, ActionUnit> actionUnitMap = new HashMap<>();
|
||||
protected Map<String, Map<Class, ActionUnit>> actionUnitMap = new HashMap<>();
|
||||
protected List<Modifiable<M>> modifiable;
|
||||
protected ErrorHandler errorHandler;
|
||||
|
||||
protected GeneralAutoResponder(
|
||||
Sending sending,
|
||||
PersonSettingService personSettingService,
|
||||
StorylineService<M> storyLineService
|
||||
) {
|
||||
this.personSettingService = personSettingService;
|
||||
this.storyLineService = storyLineService;
|
||||
init(sending);
|
||||
}
|
||||
|
||||
private void init(Sending sending) {
|
||||
actionUnitMap.put(TypeUnit.CHECK, new AnswerCheckAction<>(sending));
|
||||
actionUnitMap.put(TypeUnit.TEXT, new AnswerTextAction(sending));
|
||||
actionUnitMap.put(TypeUnit.REPLACE_CMD, new ReplaceCmdAction());
|
||||
public void registrationActionUnit(ActionUnit actionUnit) {
|
||||
actionUnitMap.computeIfAbsent(actionUnit.getUnitType(), k -> new HashMap<>()).putIfAbsent(actionUnit.getMessageType(), actionUnit);
|
||||
}
|
||||
|
||||
public void initModifiable(List<Modifiable<M>> modifiable) {
|
||||
this.modifiable = modifiable;
|
||||
}
|
||||
|
||||
public void initTextAnswerActionUnit(AnswerTextAction action) {
|
||||
actionUnitMap.put(TypeUnit.TEXT, action);
|
||||
}
|
||||
|
||||
public void initActionUnit(String typeUnit, ActionUnit<? extends MainUnit<M>, M> actionUnit) {
|
||||
if (!actionUnitMap.containsKey(typeUnit)) {
|
||||
actionUnitMap.put(typeUnit, actionUnit);
|
||||
} else {
|
||||
throw new ConfigAppException("Обработка такого типа юнита уже зарегистрирована");
|
||||
}
|
||||
}
|
||||
|
||||
public void initSaveAction(AnswerSaveAction<M, ?> answerSaveAction) {
|
||||
actionUnitMap.put(TypeUnit.SAVE, answerSaveAction);
|
||||
}
|
||||
|
||||
/**
|
||||
* Позволяет установить перехватчик и обработчик исключений, возникающих при обработке юнитов.
|
||||
*/
|
||||
@ -92,7 +65,7 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
public Uni<Void> processingNewMessage(M newMessage) {
|
||||
return Uni.createFrom().item(newMessage)
|
||||
.onItem().ifNotNull().transformToUni(
|
||||
message -> personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
|
||||
message -> personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
|
||||
.replaceIfNullWith(TRUE)
|
||||
.chain(
|
||||
state -> {
|
||||
@ -113,14 +86,14 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
if (checkEmpty(newMessages)) return Uni.createFrom().voidItem();
|
||||
|
||||
final Set<String> personIds = newMessages.stream()
|
||||
.map(Message::getPersonId)
|
||||
.map(Message::getFromPersonId)
|
||||
.collect(Collectors.toSet());
|
||||
return personSettingService.getAllPersonIdDisableMessages(personIds)
|
||||
.replaceIfNullWith(emptySet())
|
||||
.onItem().transformToMulti(
|
||||
disableIds -> {
|
||||
final List<M> allowedMessages = newMessages.stream()
|
||||
.filter(message -> !disableIds.contains(message.getPersonId()))
|
||||
.filter(message -> !disableIds.contains(message.getFromPersonId()))
|
||||
.toList();
|
||||
return Multi.createFrom().iterable(allowedMessages);
|
||||
}
|
||||
@ -138,7 +111,7 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
.onItem().transformToMulti(modifiables -> Multi.createFrom().iterable(modifiables))
|
||||
.onItem().transformToUni(mModifiable -> mModifiable.change(message))
|
||||
.concatenate().toUni().replaceWith(
|
||||
storyLineService.getNextUnitByPersonId(message.getPersonId())
|
||||
storyLineService.getNextUnitByPersonId(message.getFromPersonId())
|
||||
.onItem().ifNotNull().transformToUni(
|
||||
nextUnits -> Uni.createFrom().optional(
|
||||
Responder.nextUnit(message, nextUnits).or(storyLineService::getDefaultUnit)
|
||||
@ -184,29 +157,31 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
final M message = unitRequest.getMessage();
|
||||
final String typeUnit = unit.getType();
|
||||
if (actionUnitMap.containsKey(typeUnit)) {
|
||||
ActionUnit<MainUnit, M> actionUnit = actionUnitMap.get(typeUnit);
|
||||
return actionUnit.action(unitRequest)
|
||||
.onItem().transformToUni(
|
||||
newUnitRequest -> {
|
||||
final Optional<MainUnit<M>> optDefaultUnit = storyLineService.getDefaultUnit();
|
||||
if (!unit.isNotSaveHistory() && (optDefaultUnit.isEmpty() || !optDefaultUnit.get().equals(unit))) {
|
||||
return Uni.combine().all().unis(
|
||||
Uni.createFrom().item(newUnitRequest),
|
||||
storyLineService.save(message.getPersonId(), unit.getName(), message)
|
||||
).asTuple();
|
||||
Map<Class, ActionUnit> actionMap = actionUnitMap.get(typeUnit);
|
||||
if (actionMap.containsKey(message.getClass())) {
|
||||
final ActionUnit<MainUnit, M> actionUnit = actionMap.get(message.getClass());
|
||||
return actionUnit.action(unitRequest)
|
||||
.flatMap(
|
||||
newUnitRequest -> {
|
||||
final Optional<MainUnit<M>> optDefaultUnit = storyLineService.getDefaultUnit();
|
||||
if (!unit.isNotSaveHistory() && (optDefaultUnit.isEmpty() || !optDefaultUnit.get().equals(unit))) {
|
||||
return Uni.combine().all().unis(
|
||||
Uni.createFrom().item(newUnitRequest),
|
||||
storyLineService.save(message.getFromPersonId(), unit.getName(), message)
|
||||
).asTuple();
|
||||
}
|
||||
return Uni.combine().all().unis(Uni.createFrom().item(newUnitRequest), Uni.createFrom().voidItem()).asTuple();
|
||||
}
|
||||
return Uni.combine().all().unis(Uni.createFrom().item(newUnitRequest), Uni.createFrom().voidItem()).asTuple();
|
||||
}
|
||||
).onItem().transformToUni(
|
||||
t -> {
|
||||
final UnitRequest<MainUnit, M> newUnitRequest = t.getItem1();
|
||||
final MainUnit<M> newUnit = newUnitRequest.getUnit();
|
||||
return !unit.equals(newUnit) ? getAction(newUnitRequest) : Uni.createFrom().item(unitRequest);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
throw new NotFoundException("ActionUnit для типа {0} не зарегистрирован", unit.getType());
|
||||
).onItem().transformToUni(
|
||||
t -> {
|
||||
final UnitRequest<MainUnit, M> newUnitRequest = t.getItem1();
|
||||
final MainUnit<M> newUnit = newUnitRequest.getUnit();
|
||||
return !unit.equals(newUnit) ? getAction(newUnitRequest) : Uni.createFrom().item(unitRequest);
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
throw new NotFoundException("ActionUnit для типа {0} не зарегистрирован", unit.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,7 +10,6 @@ import io.smallrye.mutiny.Uni;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ActionUnit<U extends MainUnit, M extends Message> {
|
||||
|
||||
/**
|
||||
@ -20,4 +19,8 @@ public interface ActionUnit<U extends MainUnit, M extends Message> {
|
||||
*/
|
||||
Uni<UnitRequest<MainUnit, M>> action(UnitRequest<U, M> unitRequest);
|
||||
|
||||
String getUnitType();
|
||||
|
||||
Class<M> getMessageType();
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.quarkus.context.service.Sending;
|
||||
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.AnswerCheck;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.AnswerText;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.UnitRequest;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
@ -18,7 +19,7 @@ import static dev.struchkov.haiti.utils.Checker.checkTrue;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCheck<M>, M> {
|
||||
public class AnswerCheckAction implements ActionUnit<AnswerCheck<Message>, Message> {
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
@ -27,22 +28,22 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, M>> action(UnitRequest<AnswerCheck<M>, M> unitRequest) {
|
||||
final AnswerCheck<M> unit = unitRequest.getUnit();
|
||||
final M message = unitRequest.getMessage();
|
||||
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerCheck<Message>, Message> unitRequest) {
|
||||
final AnswerCheck<Message> unit = unitRequest.getUnit();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
return unit.getCheck().checked(message)
|
||||
.onItem().call(checkValue -> {
|
||||
if (checkTrue(checkValue)) {
|
||||
final BoxAnswer answerIfTrue = unit.getIntermediateAnswerIfTrue();
|
||||
if (checkNotNull(answerIfTrue)) {
|
||||
answerIfTrue.setRecipientIfNull(message.getPersonId());
|
||||
answerIfTrue.setRecipientIfNull(message.getFromPersonId());
|
||||
return sending.send(answerIfTrue);
|
||||
}
|
||||
} else {
|
||||
final BoxAnswer answerIfFalse = unit.getIntermediateAnswerIfFalse();
|
||||
if (checkNotNull(answerIfFalse)) {
|
||||
answerIfFalse.setRecipientIfNull(message.getPersonId());
|
||||
answerIfFalse.setRecipientIfNull(message.getFromPersonId());
|
||||
return sending.send(answerIfFalse);
|
||||
}
|
||||
}
|
||||
@ -59,4 +60,14 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerText.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -17,17 +17,17 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerSaveAction<M extends Message, D> implements ActionUnit<AnswerSave<M, D>, M> {
|
||||
public class AnswerSaveAction<D> implements ActionUnit<AnswerSave<Message, D>, Message> {
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, M>> action(UnitRequest<AnswerSave<M, D>, M> unitRequest) {
|
||||
final AnswerSave<M, D> answerSave = unitRequest.getUnit();
|
||||
final M message = unitRequest.getMessage();
|
||||
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerSave<Message, D>, Message> unitRequest) {
|
||||
final AnswerSave<Message, D> answerSave = unitRequest.getUnit();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
final AnswerSavePreservable<D> preservable = answerSave.getPreservable();
|
||||
final String personId = message.getPersonId();
|
||||
final String personId = message.getFromPersonId();
|
||||
|
||||
final CheckSave<M> checkSave = answerSave.getCheckSave();
|
||||
final CheckSave<Message> checkSave = answerSave.getCheckSave();
|
||||
if (checkNotNull(checkSave)) {
|
||||
return Uni.createFrom().voidItem()
|
||||
.onItem().transformToUni(
|
||||
@ -43,7 +43,7 @@ public class AnswerSaveAction<M extends Message, D> implements ActionUnit<Answer
|
||||
);
|
||||
}
|
||||
|
||||
final PreservableData<D, M> preservableData = answerSave.getPreservableData();
|
||||
final PreservableData<D, Message> preservableData = answerSave.getPreservableData();
|
||||
final Pusher<D> pusher = answerSave.getPusher();
|
||||
|
||||
return Uni.createFrom().voidItem()
|
||||
@ -72,4 +72,15 @@ public class AnswerSaveAction<M extends Message, D> implements ActionUnit<Answer
|
||||
v -> UnitRequest.of(answerSave, message)
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerSave.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.godfather.quarkus.core.action;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||
import dev.struchkov.godfather.quarkus.context.service.Sending;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.AnswerText;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
|
||||
@ -15,7 +15,7 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message> {
|
||||
public class AnswerTextAction implements ActionUnit<AnswerText<Mail>, Mail> {
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
@ -24,13 +24,13 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerText<Message>, Message> unitRequest) {
|
||||
final Message message = unitRequest.getMessage();
|
||||
final AnswerText<Message> unit = unitRequest.getUnit();
|
||||
public Uni<UnitRequest<MainUnit, Mail>> action(UnitRequest<AnswerText<Mail>, Mail> unitRequest) {
|
||||
final Mail message = unitRequest.getMessage();
|
||||
final AnswerText<Mail> unit = unitRequest.getUnit();
|
||||
|
||||
return unit.getAnswer().processing(message)
|
||||
.onItem().ifNotNull().transformToUni(boxAnswer -> {
|
||||
boxAnswer.setRecipientIfNull(message.getPersonId());
|
||||
boxAnswer.setRecipientIfNull(message.getFromPersonId());
|
||||
return sending.send(boxAnswer);
|
||||
})
|
||||
.onItem().ifNotNull().transformToUni(sentBox -> {
|
||||
@ -43,4 +43,14 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
.replaceWith(UnitRequest.of(unit, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerText.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Mail> getMessageType() {
|
||||
return Mail.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
package dev.struchkov.godfather.quarkus.core.action;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.content.ChatMail;
|
||||
import dev.struchkov.godfather.quarkus.context.service.Sending;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.AnswerText;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.UnitRequest;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.func.CallBackConsumer;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
|
||||
/**
|
||||
* Обработчик Unit-а {@link AnswerText}.
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerTextChatMailAction implements ActionUnit<AnswerText<ChatMail>, ChatMail> {
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
public AnswerTextChatMailAction(Sending sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, ChatMail>> action(UnitRequest<AnswerText<ChatMail>, ChatMail> unitRequest) {
|
||||
final ChatMail message = unitRequest.getMessage();
|
||||
final AnswerText<ChatMail> unit = unitRequest.getUnit();
|
||||
|
||||
return unit.getAnswer().processing(message)
|
||||
.onItem().ifNotNull().transformToUni(boxAnswer -> {
|
||||
boxAnswer.setRecipientIfNull(message.getChatId());
|
||||
return sending.send(boxAnswer);
|
||||
})
|
||||
.onItem().ifNotNull().transformToUni(sentBox -> {
|
||||
final CallBackConsumer callBack = unit.getCallBack();
|
||||
if (checkNotNull(callBack)) {
|
||||
return callBack.processing(sentBox);
|
||||
}
|
||||
return Uni.createFrom().voidItem();
|
||||
})
|
||||
.replaceWith(UnitRequest.of(unit, message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerText.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMail> getMessageType() {
|
||||
return ChatMail.class;
|
||||
}
|
||||
|
||||
}
|
@ -16,4 +16,14 @@ public class ReplaceCmdAction implements ActionUnit<ReplaceCmd<Message>, Message
|
||||
return Uni.createFrom().item(UnitRequest.of(unit.getThisUnit(), message));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return ReplaceCmd.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,35 +11,45 @@ import io.smallrye.mutiny.Uni;
|
||||
|
||||
import static dev.struchkov.godfather.exception.RollBackException.rollBackException;
|
||||
|
||||
public class RollBackCmdAction<M extends Message> implements ActionUnit<RollBackCmd<M>, M> {
|
||||
public class RollBackCmdAction implements ActionUnit<RollBackCmd<Message>, Message> {
|
||||
|
||||
private final StorylineService<M> storyLineService;
|
||||
private final StorylineService<Message> storyLineService;
|
||||
|
||||
public RollBackCmdAction(StorylineService<M> storyLineService) {
|
||||
public RollBackCmdAction(StorylineService<Message> storyLineService) {
|
||||
this.storyLineService = storyLineService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, M>> action(UnitRequest<RollBackCmd<M>, M> unitRequest) {
|
||||
final RollBackCmd<M> unit = unitRequest.getUnit();
|
||||
final M message = unitRequest.getMessage();
|
||||
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<RollBackCmd<Message>, Message> unitRequest) {
|
||||
final RollBackCmd<Message> unit = unitRequest.getUnit();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
final int countToBack = unit.getCountBack();
|
||||
final String rollbackUnitName = unit.getRollbackUnitName();
|
||||
|
||||
final Uni<StorylineHistory> uniHistory = (rollbackUnitName != null)
|
||||
? storyLineService.replaceUserToBack(message.getPersonId(), rollbackUnitName).onItem().ifNull().failWith(rollBackException("Юнит для возвращения не был найден"))
|
||||
: storyLineService.replaceUserToBack(message.getPersonId(), countToBack).onItem().ifNull().failWith(rollBackException("Юнит для возвращения не был найден"));
|
||||
? storyLineService.replaceUserToBack(message.getFromPersonId(), rollbackUnitName).onItem().ifNull().failWith(rollBackException("Юнит для возвращения не был найден"))
|
||||
: storyLineService.replaceUserToBack(message.getFromPersonId(), countToBack).onItem().ifNull().failWith(rollBackException("Юнит для возвращения не был найден"));
|
||||
|
||||
return uniHistory
|
||||
.onItem().transform(
|
||||
history -> {
|
||||
final String unitName = history.getUnitName();
|
||||
final MainUnit<M> nextUnit = storyLineService.getUnitByName(unitName).orElse(unit);
|
||||
final M oldMessage = (M) history.getMessage();
|
||||
final MainUnit<Message> nextUnit = storyLineService.getUnitByName(unitName).orElse(unit);
|
||||
final Message oldMessage = history.getMessage();
|
||||
return UnitRequest.of(nextUnit, oldMessage);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return RollBackCmd.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,30 +1,26 @@
|
||||
package dev.struchkov.godfather.simple.core;
|
||||
|
||||
import dev.struchkov.autoresponder.Responder;
|
||||
import dev.struchkov.godfather.exception.ConfigAppException;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.simple.context.service.Accessibility;
|
||||
import dev.struchkov.godfather.simple.context.service.ErrorHandler;
|
||||
import dev.struchkov.godfather.simple.context.service.Modifiable;
|
||||
import dev.struchkov.godfather.simple.context.service.PersonSettingService;
|
||||
import dev.struchkov.godfather.simple.context.service.Sending;
|
||||
import dev.struchkov.godfather.simple.core.action.ActionUnit;
|
||||
import dev.struchkov.godfather.simple.core.action.AnswerCheckAction;
|
||||
import dev.struchkov.godfather.simple.core.action.AnswerSaveAction;
|
||||
import dev.struchkov.godfather.simple.core.action.AnswerTextAction;
|
||||
import dev.struchkov.godfather.simple.core.action.cmd.ReplaceCmdAction;
|
||||
import dev.struchkov.godfather.simple.core.service.StorylineService;
|
||||
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
|
||||
import dev.struchkov.godfather.simple.domain.unit.UnitRequest;
|
||||
import dev.struchkov.haiti.context.exception.NotFoundException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -33,48 +29,30 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
|
||||
public class GeneralAutoResponder<M extends Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(GeneralAutoResponder.class);
|
||||
|
||||
protected final PersonSettingService personSettingService;
|
||||
protected final StorylineService<M> storyLineService;
|
||||
|
||||
protected Map<String, ActionUnit> actionUnitMap = new HashMap<>();
|
||||
protected Map<String, Map<Class, ActionUnit>> actionUnitMap = new HashMap<>();
|
||||
protected List<Modifiable<M>> modifiable;
|
||||
protected ErrorHandler errorHandler;
|
||||
protected ExecutorService executorService;
|
||||
|
||||
protected GeneralAutoResponder(
|
||||
Sending sending,
|
||||
PersonSettingService personSettingService,
|
||||
StorylineService<M> storyLineService
|
||||
) {
|
||||
this.personSettingService = personSettingService;
|
||||
this.storyLineService = storyLineService;
|
||||
init(sending);
|
||||
}
|
||||
|
||||
private void init(Sending sending) {
|
||||
actionUnitMap.put(TypeUnit.CHECK, new AnswerCheckAction<>(sending));
|
||||
actionUnitMap.put(TypeUnit.TEXT, new AnswerTextAction(sending));
|
||||
actionUnitMap.put(TypeUnit.REPLACE_CMD, new ReplaceCmdAction());
|
||||
}
|
||||
|
||||
public void initModifiable(List<Modifiable<M>> modifiable) {
|
||||
this.modifiable = modifiable;
|
||||
}
|
||||
|
||||
public void initTextAnswerActionUnit(AnswerTextAction action) {
|
||||
actionUnitMap.put(TypeUnit.TEXT, action);
|
||||
}
|
||||
|
||||
public void initActionUnit(String typeUnit, ActionUnit<? extends MainUnit<M>, M> actionUnit) {
|
||||
if (!actionUnitMap.containsKey(typeUnit)) {
|
||||
actionUnitMap.put(typeUnit, actionUnit);
|
||||
} else {
|
||||
throw new ConfigAppException("Обработка такого типа юнита уже зарегистрирована");
|
||||
}
|
||||
}
|
||||
|
||||
public void initSaveAction(AnswerSaveAction<M, ?> answerSaveAction) {
|
||||
actionUnitMap.put(TypeUnit.SAVE, answerSaveAction);
|
||||
public void registrationActionUnit(ActionUnit actionUnit) {
|
||||
actionUnitMap.computeIfAbsent(actionUnit.getUnitType(), k -> new HashMap<>()).putIfAbsent(actionUnit.getMessageType(), actionUnit);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,15 +73,20 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
public void processingNewMessage(M newMessage) {
|
||||
if (checkNotNull(newMessage)) {
|
||||
if (checkNotNull(executorService)) {
|
||||
executorService.submit(() -> {
|
||||
final boolean state = personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
|
||||
.orElse(true);
|
||||
if (state) {
|
||||
processing(newMessage);
|
||||
}
|
||||
CompletableFuture.runAsync(
|
||||
() -> {
|
||||
final boolean state = personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
|
||||
.orElse(true);
|
||||
if (state) {
|
||||
processing(newMessage);
|
||||
}
|
||||
}, executorService
|
||||
).exceptionally(ex -> {
|
||||
log.error(ex.getMessage(), ex);
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
final boolean state = personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
|
||||
final boolean state = personSettingService.getStateProcessingByPersonId(newMessage.getFromPersonId())
|
||||
.orElse(true);
|
||||
if (state) {
|
||||
processing(newMessage);
|
||||
@ -115,11 +98,11 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
public void processingNewMessages(List<M> newMessages) {
|
||||
if (checkNotEmpty(newMessages)) {
|
||||
final Set<String> personIds = newMessages.stream()
|
||||
.map(Message::getPersonId)
|
||||
.map(Message::getFromPersonId)
|
||||
.collect(Collectors.toSet());
|
||||
final Set<String> disableIds = personSettingService.getAllPersonIdDisableMessages(personIds);
|
||||
final List<M> allowedMessages = newMessages.stream()
|
||||
.filter(message -> !disableIds.contains(message.getPersonId()))
|
||||
.filter(message -> !disableIds.contains(message.getFromPersonId()))
|
||||
.toList();
|
||||
if (checkNotNull(executorService)) {
|
||||
for (M allowedMessage : allowedMessages) {
|
||||
@ -137,7 +120,7 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
if (checkNotEmpty(modifiable)) {
|
||||
modifiable.forEach(m -> m.change(message));
|
||||
}
|
||||
final Set<MainUnit<M>> units = storyLineService.getNextUnitByPersonId(message.getPersonId());
|
||||
final Set<MainUnit<M>> units = storyLineService.getNextUnitByPersonId(message.getFromPersonId());
|
||||
final Optional<MainUnit<M>> optAnswer = Responder.nextUnit(message, units)
|
||||
.or(storyLineService::getDefaultUnit);
|
||||
if (optAnswer.isPresent()) {
|
||||
@ -183,17 +166,19 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
final M message = unitRequest.getMessage();
|
||||
final String typeUnit = unit.getType();
|
||||
if (actionUnitMap.containsKey(typeUnit)) {
|
||||
ActionUnit actionUnit = actionUnitMap.get(typeUnit);
|
||||
UnitRequest<MainUnit<M>, M> newUnitRequest = actionUnit.action(unitRequest);
|
||||
final Optional<MainUnit<M>> optDefaultUnit = storyLineService.getDefaultUnit();
|
||||
if (!unit.isNotSaveHistory() && (optDefaultUnit.isEmpty() || !optDefaultUnit.get().equals(unit))) {
|
||||
storyLineService.save(message.getPersonId(), unit.getName(), message);
|
||||
Map<Class, ActionUnit> actionMap = actionUnitMap.get(typeUnit);
|
||||
if (actionMap.containsKey(message.getClass())) {
|
||||
final ActionUnit actionUnit = actionMap.get(message.getClass());
|
||||
UnitRequest<MainUnit<M>, M> newUnitRequest = actionUnit.action(unitRequest);
|
||||
final Optional<MainUnit<M>> optDefaultUnit = storyLineService.getDefaultUnit();
|
||||
if (!unit.isNotSaveHistory() && (optDefaultUnit.isEmpty() || !optDefaultUnit.get().equals(unit))) {
|
||||
storyLineService.save(message.getFromPersonId(), unit.getName(), message);
|
||||
}
|
||||
final MainUnit<M> newUnit = newUnitRequest.getUnit();
|
||||
return !unit.equals(newUnit) ? getAction(newUnitRequest) : unitRequest;
|
||||
}
|
||||
final MainUnit<M> newUnit = newUnitRequest.getUnit();
|
||||
return !unit.equals(newUnit) ? getAction(newUnitRequest) : unitRequest;
|
||||
} else {
|
||||
throw new NotFoundException("ActionUnit для типа {0} не зарегистрирован", unit.getType());
|
||||
}
|
||||
throw new NotFoundException("ActionUnit для типа {0} не зарегистрирован", unit.getType());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ import dev.struchkov.godfather.simple.domain.unit.UnitRequest;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface ActionUnit<U extends MainUnit, M extends Message> {
|
||||
|
||||
/**
|
||||
@ -19,4 +18,8 @@ public interface ActionUnit<U extends MainUnit, M extends Message> {
|
||||
*/
|
||||
UnitRequest<MainUnit, M> action(UnitRequest<U, M> unitRequest);
|
||||
|
||||
String getUnitType();
|
||||
|
||||
Class<M> getMessageType();
|
||||
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCheck<M>, M> {
|
||||
public class AnswerCheckAction implements ActionUnit<AnswerCheck<Message>, Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AnswerCheckAction.class);
|
||||
|
||||
@ -29,18 +29,18 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitRequest<MainUnit, M> action(UnitRequest<AnswerCheck<M>, M> unitRequest) {
|
||||
final AnswerCheck<M> unit = unitRequest.getUnit();
|
||||
public UnitRequest<MainUnit, Message> action(UnitRequest<AnswerCheck<Message>, Message> unitRequest) {
|
||||
final AnswerCheck<Message> unit = unitRequest.getUnit();
|
||||
log.debug("Началась обработка unit: {}.", unit.getName());
|
||||
|
||||
final M message = unitRequest.getMessage();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
MainUnit<M> unitAnswer;
|
||||
MainUnit<Message> unitAnswer;
|
||||
if (unit.getCheck().checked(message)) {
|
||||
log.debug("Unit: {}. Проверка пройдена", unit.getName());
|
||||
final BoxAnswer answerIfTrue = unit.getIntermediateAnswerIfTrue();
|
||||
if (checkNotNull(answerIfTrue)) {
|
||||
answerIfTrue.setRecipientIfNull(message.getPersonId());
|
||||
answerIfTrue.setRecipientIfNull(message.getFromPersonId());
|
||||
sending.send(answerIfTrue);
|
||||
}
|
||||
unitAnswer = unit.getUnitTrue();
|
||||
@ -48,7 +48,7 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
|
||||
log.debug("Unit: {}. Проверка НЕ пройдена", unit.getName());
|
||||
final BoxAnswer answerIfFalse = unit.getIntermediateAnswerIfFalse();
|
||||
if (checkNotNull(answerIfFalse)) {
|
||||
answerIfFalse.setRecipientIfNull(message.getPersonId());
|
||||
answerIfFalse.setRecipientIfNull(message.getFromPersonId());
|
||||
sending.send(answerIfFalse);
|
||||
}
|
||||
unitAnswer = unit.getUnitFalse();
|
||||
@ -57,4 +57,14 @@ public class AnswerCheckAction<M extends Message> implements ActionUnit<AnswerCh
|
||||
return UnitRequest.of(Objects.requireNonNullElse(unitAnswer, unit), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerCheck.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -16,25 +16,25 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerSaveAction<M extends Message, D> implements ActionUnit<AnswerSave<M, D>, M> {
|
||||
public class AnswerSaveAction<D> implements ActionUnit<AnswerSave<Message, D>, Message> {
|
||||
|
||||
@Override
|
||||
public UnitRequest<MainUnit, M> action(UnitRequest<AnswerSave<M, D>, M> unitRequest) {
|
||||
final AnswerSave<M, D> answerSave = unitRequest.getUnit();
|
||||
final M message = unitRequest.getMessage();
|
||||
public UnitRequest<MainUnit, Message> action(UnitRequest<AnswerSave<Message, D>, Message> unitRequest) {
|
||||
final AnswerSave<Message, D> answerSave = unitRequest.getUnit();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
final AnswerSavePreservable<D> preservable = answerSave.getPreservable();
|
||||
final String personId = message.getPersonId();
|
||||
final String personId = message.getFromPersonId();
|
||||
|
||||
final CheckSave<M> checkSave = answerSave.getCheckSave();
|
||||
final CheckSave<Message> checkSave = answerSave.getCheckSave();
|
||||
if (checkNotNull(checkSave)) {
|
||||
MainUnit<M> unit = checkSave.check(message);
|
||||
MainUnit<Message> unit = checkSave.check(message);
|
||||
if (checkNotNull(unit)) {
|
||||
return UnitRequest.of(unit, message);
|
||||
}
|
||||
}
|
||||
|
||||
final PreservableData<D, M> preservableData = answerSave.getPreservableData();
|
||||
final PreservableData<D, Message> preservableData = answerSave.getPreservableData();
|
||||
if (checkNotNull(preservableData)) {
|
||||
D data = preservableData.getData(message);
|
||||
if (checkNotNull(data)) {
|
||||
@ -49,4 +49,14 @@ public class AnswerSaveAction<M extends Message, D> implements ActionUnit<Answer
|
||||
return UnitRequest.of(answerSave, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerSave.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,65 @@
|
||||
package dev.struchkov.godfather.simple.core.action;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.content.ChatMail;
|
||||
import dev.struchkov.godfather.simple.context.service.Sending;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.simple.domain.SentBox;
|
||||
import dev.struchkov.godfather.simple.domain.unit.AnswerText;
|
||||
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
|
||||
import dev.struchkov.godfather.simple.domain.unit.UnitRequest;
|
||||
import dev.struchkov.godfather.simple.domain.unit.func.CallBackConsumer;
|
||||
import dev.struchkov.godfather.simple.domain.unit.func.ProcessingData;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
|
||||
/**
|
||||
* Обработчик Unit-а {@link AnswerText}.
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerTextChatMailAction implements ActionUnit<AnswerText<ChatMail>, ChatMail> {
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
public AnswerTextChatMailAction(Sending sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitRequest<MainUnit, ChatMail> action(UnitRequest<AnswerText<ChatMail>, ChatMail> unitRequest) {
|
||||
final ChatMail message = unitRequest.getMessage();
|
||||
final AnswerText<ChatMail> unit = unitRequest.getUnit();
|
||||
|
||||
final ProcessingData<ChatMail> answerProcessing = unit.getAnswer();
|
||||
if (checkNotNull(answerProcessing)) {
|
||||
final Optional<BoxAnswer> optAnswer = answerProcessing.processing(message);
|
||||
if (optAnswer.isPresent()) {
|
||||
final BoxAnswer answer = optAnswer.get();
|
||||
|
||||
answer.setRecipientIfNull(message.getChatId());
|
||||
|
||||
final Optional<? extends SentBox> optSentBox = sending.send(answer);
|
||||
final CallBackConsumer callBack = unit.getCallBack();
|
||||
if (checkNotNull(callBack) && optAnswer.isPresent()) {
|
||||
final SentBox sentBox = optSentBox.get();
|
||||
callBack.processing(sentBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return UnitRequest.of(unit, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerText.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<ChatMail> getMessageType() {
|
||||
return ChatMail.class;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
package dev.struchkov.godfather.simple.core.action;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||
import dev.struchkov.godfather.simple.context.service.Sending;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.simple.domain.SentBox;
|
||||
@ -19,26 +19,26 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message> {
|
||||
public class AnswerTextMailAction implements ActionUnit<AnswerText<Mail>, Mail> {
|
||||
|
||||
private final Sending sending;
|
||||
|
||||
public AnswerTextAction(Sending sending) {
|
||||
public AnswerTextMailAction(Sending sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitRequest<MainUnit, Message> action(UnitRequest<AnswerText<Message>, Message> unitRequest) {
|
||||
final Message message = unitRequest.getMessage();
|
||||
final AnswerText<Message> unit = unitRequest.getUnit();
|
||||
public UnitRequest<MainUnit, Mail> action(UnitRequest<AnswerText<Mail>, Mail> unitRequest) {
|
||||
final Mail message = unitRequest.getMessage();
|
||||
final AnswerText<Mail> unit = unitRequest.getUnit();
|
||||
|
||||
final ProcessingData<Message> answerProcessing = unit.getAnswer();
|
||||
final ProcessingData<Mail> answerProcessing = unit.getAnswer();
|
||||
if (checkNotNull(answerProcessing)) {
|
||||
final Optional<BoxAnswer> optAnswer = answerProcessing.processing(message);
|
||||
if (optAnswer.isPresent()) {
|
||||
final BoxAnswer answer = optAnswer.get();
|
||||
|
||||
answer.setRecipientIfNull(message.getPersonId());
|
||||
answer.setRecipientIfNull(message.getFromPersonId());
|
||||
|
||||
final Optional<? extends SentBox> optSentBox = sending.send(answer);
|
||||
final CallBackConsumer callBack = unit.getCallBack();
|
||||
@ -52,4 +52,14 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
return UnitRequest.of(unit, message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return AnswerText.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Mail> getMessageType() {
|
||||
return Mail.class;
|
||||
}
|
||||
|
||||
}
|
@ -15,4 +15,14 @@ public class ReplaceCmdAction implements ActionUnit<ReplaceCmd<Message>, Message
|
||||
return UnitRequest.of(unit.getThisUnit(), message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return ReplaceCmd.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,29 +10,39 @@ import dev.struchkov.godfather.simple.domain.unit.cmd.RollBackCmd;
|
||||
|
||||
import static dev.struchkov.godfather.exception.RollBackException.rollBackException;
|
||||
|
||||
public class RollBackCmdAction<M extends Message> implements ActionUnit<RollBackCmd<M>, M> {
|
||||
public class RollBackCmdAction implements ActionUnit<RollBackCmd<Message>, Message> {
|
||||
|
||||
private final StorylineService<M> storyLineService;
|
||||
private final StorylineService<Message> storyLineService;
|
||||
|
||||
public RollBackCmdAction(StorylineService<M> storyLineService) {
|
||||
public RollBackCmdAction(StorylineService<Message> storyLineService) {
|
||||
this.storyLineService = storyLineService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public UnitRequest<MainUnit, M> action(UnitRequest<RollBackCmd<M>, M> unitRequest) {
|
||||
final RollBackCmd<M> unit = unitRequest.getUnit();
|
||||
final M message = unitRequest.getMessage();
|
||||
public UnitRequest<MainUnit, Message> action(UnitRequest<RollBackCmd<Message>, Message> unitRequest) {
|
||||
final RollBackCmd<Message> unit = unitRequest.getUnit();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
final int countToBack = unit.getCountBack();
|
||||
final String rollbackUnitName = unit.getRollbackUnitName();
|
||||
|
||||
StorylineHistory history = rollbackUnitName != null
|
||||
? storyLineService.replaceUserToBack(message.getPersonId(), rollbackUnitName).orElseThrow(rollBackException("Юнит для возвращения не был найден"))
|
||||
: storyLineService.replaceUserToBack(message.getPersonId(), countToBack).orElseThrow(rollBackException("Юнит для возвращения не был найден"));
|
||||
? storyLineService.replaceUserToBack(message.getFromPersonId(), rollbackUnitName).orElseThrow(rollBackException("Юнит для возвращения не был найден"))
|
||||
: storyLineService.replaceUserToBack(message.getFromPersonId(), countToBack).orElseThrow(rollBackException("Юнит для возвращения не был найден"));
|
||||
final String unitName = history.getUnitName();
|
||||
final MainUnit<M> nextUnit = storyLineService.getUnitByName(unitName).orElse(unit);
|
||||
final M oldMessage = (M) history.getMessage();
|
||||
final MainUnit<Message> nextUnit = storyLineService.getUnitByName(unitName).orElse(unit);
|
||||
final Message oldMessage = history.getMessage();
|
||||
return UnitRequest.of(nextUnit, oldMessage);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getUnitType() {
|
||||
return RollBackCmd.TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Message> getMessageType() {
|
||||
return Message.class;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,25 @@
|
||||
package dev.struchkov.godfather.simple.core.provider;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.content.ChatMail;
|
||||
import dev.struchkov.godfather.simple.context.service.EventHandler;
|
||||
import dev.struchkov.godfather.simple.core.GeneralAutoResponder;
|
||||
|
||||
public class ChatStoryLineHandler implements EventHandler<ChatMail> {
|
||||
|
||||
private final GeneralAutoResponder<ChatMail> generalAutoResponder;
|
||||
|
||||
public ChatStoryLineHandler(GeneralAutoResponder<ChatMail> generalAutoResponder) {
|
||||
this.generalAutoResponder = generalAutoResponder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(ChatMail message) {
|
||||
generalAutoResponder.processingNewMessage(message);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return ChatMail.TYPE;
|
||||
}
|
||||
|
||||
}
|
@ -4,11 +4,11 @@ import dev.struchkov.godfather.main.domain.content.Mail;
|
||||
import dev.struchkov.godfather.simple.context.service.EventHandler;
|
||||
import dev.struchkov.godfather.simple.core.GeneralAutoResponder;
|
||||
|
||||
public class StoryLineHandler implements EventHandler<Mail> {
|
||||
public class PersonStoryLineHandler implements EventHandler<Mail> {
|
||||
|
||||
private final GeneralAutoResponder<Mail> generalAutoResponder;
|
||||
|
||||
public StoryLineHandler(GeneralAutoResponder<Mail> generalAutoResponder) {
|
||||
public PersonStoryLineHandler(GeneralAutoResponder<Mail> generalAutoResponder) {
|
||||
this.generalAutoResponder = generalAutoResponder;
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ package dev.struchkov.godfather.simple.core.service;
|
||||
import dev.struchkov.autoresponder.entity.Unit;
|
||||
import dev.struchkov.godfather.main.domain.StorylineHistory;
|
||||
import dev.struchkov.godfather.main.domain.UnitPointer;
|
||||
import dev.struchkov.godfather.main.domain.content.Mail;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.simple.context.repository.StorylineRepository;
|
||||
import dev.struchkov.godfather.simple.context.service.UnitPointerService;
|
||||
import dev.struchkov.godfather.simple.core.Storyline;
|
||||
@ -20,11 +20,11 @@ import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||
/**
|
||||
* Отвечает за работу со сценарием в личных сообщениях с пользователем.
|
||||
*/
|
||||
public class StorylineMailService implements StorylineService<Mail> {
|
||||
public class StorylineMailService<T extends Message> implements StorylineService<T> {
|
||||
|
||||
private final UnitPointerService unitPointerService;
|
||||
private final StorylineRepository storylineRepository;
|
||||
private final Storyline<Mail> storyLine;
|
||||
private final Storyline<T> storyLine;
|
||||
private String defaultUnitName;
|
||||
|
||||
public StorylineMailService(
|
||||
@ -32,7 +32,7 @@ public class StorylineMailService implements StorylineService<Mail> {
|
||||
StorylineRepository storylineRepository,
|
||||
List<Object> unitConfigurations
|
||||
) {
|
||||
this.storyLine = new StorylineFactory<Mail>(unitConfigurations).createStoryLine();
|
||||
this.storyLine = new StorylineFactory<T>(unitConfigurations).createStoryLine();
|
||||
this.unitPointerService = unitPointerService;
|
||||
this.storylineRepository = storylineRepository;
|
||||
}
|
||||
@ -44,27 +44,27 @@ public class StorylineMailService implements StorylineService<Mail> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MainUnit<Mail>> getUnitNameByPersonId(@NotNull String personId) {
|
||||
public Optional<MainUnit<T>> getUnitNameByPersonId(@NotNull String personId) {
|
||||
isNotNull(personId);
|
||||
return unitPointerService.getUnitNameByPersonId(personId)
|
||||
.flatMap(storyLine::getUnit);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<MainUnit<Mail>> getNextUnitByPersonId(@NotNull String personId) {
|
||||
final Optional<Set<MainUnit<Mail>>> optMainUnits = getUnitNameByPersonId(personId)
|
||||
public Set<MainUnit<T>> getNextUnitByPersonId(@NotNull String personId) {
|
||||
final Optional<Set<MainUnit<T>>> optMainUnits = getUnitNameByPersonId(personId)
|
||||
.map(Unit::getNextUnits)
|
||||
.filter(mainUnits -> !mainUnits.isEmpty());
|
||||
if (optMainUnits.isEmpty()) {
|
||||
storylineRepository.cleanHistoryByPersonId(personId);
|
||||
}
|
||||
final Set<MainUnit<Mail>> nextUnits = optMainUnits.orElse(storyLine.getStartingUnits());
|
||||
final Set<MainUnit<T>> nextUnits = optMainUnits.orElse(storyLine.getStartingUnits());
|
||||
nextUnits.addAll(storyLine.getGlobalUnits());
|
||||
return nextUnits;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(String personId, String unitName, Mail mail) {
|
||||
public void save(String personId, String unitName, T mail) {
|
||||
isNotNull(personId, unitName, mail);
|
||||
unitPointerService.save(new UnitPointer(personId, unitName));
|
||||
|
||||
@ -86,7 +86,7 @@ public class StorylineMailService implements StorylineService<Mail> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MainUnit<Mail>> getDefaultUnit() {
|
||||
public Optional<MainUnit<T>> getDefaultUnit() {
|
||||
if (defaultUnitName == null) return Optional.empty();
|
||||
return storyLine.getUnit(defaultUnitName);
|
||||
}
|
||||
@ -103,7 +103,7 @@ public class StorylineMailService implements StorylineService<Mail> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<MainUnit<Mail>> getUnitByName(String unitName) {
|
||||
public Optional<MainUnit<T>> getUnitByName(String unitName) {
|
||||
return storyLine.getUnit(unitName);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
package dev.struchkov.godfather.main.domain.content;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.event.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class ChatMail extends Message implements Event {
|
||||
|
||||
public static final String TYPE = "CHAT_MAIL";
|
||||
|
||||
private String chatId;
|
||||
|
||||
/**
|
||||
* Имя отправителя.
|
||||
*/
|
||||
private String firstName;
|
||||
|
||||
/**
|
||||
* Фамилия отправителя.
|
||||
*/
|
||||
private String lastName;
|
||||
|
||||
/**
|
||||
* Вложения к сообщению.
|
||||
*/
|
||||
private List<Attachment> attachments = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* Пересланные сообщения.
|
||||
*/
|
||||
private List<ChatMail> forwardMail;
|
||||
|
||||
public void addAttachment(Attachment attachment) {
|
||||
this.attachments.add(attachment);
|
||||
}
|
||||
|
||||
public void addAttachments(Collection<Attachment> attachments) {
|
||||
this.attachments.addAll(attachments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getEventType() {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
}
|
@ -1,6 +1,8 @@
|
||||
package dev.struchkov.godfather.main.domain.content;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.event.Event;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
@ -12,6 +14,8 @@ import java.util.List;
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class Mail extends Message implements Event {
|
||||
|
||||
public static final String TYPE = "MAIL";
|
||||
|
@ -2,6 +2,8 @@ package dev.struchkov.godfather.main.domain.content;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.DeliverableText;
|
||||
import dev.struchkov.haiti.utils.container.ContextKey;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.HashMap;
|
||||
@ -16,6 +18,8 @@ import static dev.struchkov.haiti.utils.Checker.checkNotNull;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public abstract class Message implements DeliverableText {
|
||||
|
||||
protected String id;
|
||||
@ -33,7 +37,7 @@ public abstract class Message implements DeliverableText {
|
||||
/**
|
||||
* Идентификатор пользователя, отправившего сообщение.
|
||||
*/
|
||||
protected String personId;
|
||||
protected String fromPersonId;
|
||||
|
||||
/**
|
||||
* Текстовое сообщение.
|
||||
@ -44,7 +48,7 @@ public abstract class Message implements DeliverableText {
|
||||
|
||||
protected Message(Message source) {
|
||||
this.id = source.getId();
|
||||
this.personId = source.getPersonId();
|
||||
this.fromPersonId = source.getFromPersonId();
|
||||
this.text = source.getText();
|
||||
this.createDate = source.getCreateDate();
|
||||
this.contentType = source.getContentType();
|
||||
@ -54,46 +58,6 @@ public abstract class Message implements DeliverableText {
|
||||
protected Message() {
|
||||
}
|
||||
|
||||
public ContentType getContentType() {
|
||||
return contentType;
|
||||
}
|
||||
|
||||
public void setContentType(ContentType type) {
|
||||
this.contentType = type;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(LocalDateTime createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public String getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
public void setPersonId(String personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public Map<ContextKey, Object> getPayload() {
|
||||
return payload;
|
||||
}
|
||||
|
@ -1,24 +0,0 @@
|
||||
package dev.struchkov.godfather.main.domain.unit;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
/**
|
||||
* Тип Unit-а. Обределяет способ обработки.
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
public class TypeUnit {
|
||||
|
||||
public static final String TEXT = "TEXT";
|
||||
public static final String SAVE = "SAVE";
|
||||
public static final String CHECK = "CHECK";
|
||||
|
||||
public static final String BACK_CMD = "BACK_CMD";
|
||||
public static final String REPLACE_CMD = "REPLACE_CMD";
|
||||
|
||||
private TypeUnit() {
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.quarkus.domain.unit;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.func.CheckData;
|
||||
@ -21,6 +20,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class AnswerCheck<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ANSWER_CHECK";
|
||||
|
||||
/**
|
||||
* Unit для true.
|
||||
*/
|
||||
@ -59,7 +60,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
|
||||
new HashSet<>(),
|
||||
builder.activeType,
|
||||
builder.notSaveHistory,
|
||||
TypeUnit.CHECK
|
||||
TYPE
|
||||
);
|
||||
unitTrue = builder.unitTrue;
|
||||
unitFalse = builder.unitFalse;
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.quarkus.domain.unit;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.func.CheckSave;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.func.PreservableData;
|
||||
@ -26,6 +25,8 @@ import static dev.struchkov.haiti.utils.Checker.checkNull;
|
||||
*/
|
||||
public class AnswerSave<M extends Message, D> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ANSWER_SAVE";
|
||||
|
||||
/**
|
||||
* Объект отвечающий за сохранение - репозиторий.
|
||||
*/
|
||||
@ -66,7 +67,7 @@ public class AnswerSave<M extends Message, D> extends MainUnit<M> {
|
||||
builder.nextUnits,
|
||||
(builder.hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT,
|
||||
builder.notSaveHistory,
|
||||
TypeUnit.SAVE
|
||||
TYPE
|
||||
);
|
||||
maintenanceNextUnit(nextUnits);
|
||||
preservable = builder.preservable;
|
||||
@ -112,6 +113,7 @@ public class AnswerSave<M extends Message, D> extends MainUnit<M> {
|
||||
}
|
||||
|
||||
public static final class Builder<M extends Message, D> {
|
||||
|
||||
private String name = UUID.randomUUID().toString();
|
||||
private String description;
|
||||
private Set<MainUnit<M>> nextUnits;
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.quarkus.domain.unit;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.quarkus.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.func.CallBackConsumer;
|
||||
@ -27,6 +26,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class AnswerText<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ANSWER_TEXT";
|
||||
|
||||
/**
|
||||
* Объект, который необходимо отправить пользователю.
|
||||
*/
|
||||
@ -50,7 +51,7 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
|
||||
builder.nextUnits,
|
||||
builder.activeType,
|
||||
builder.notSaveHistory,
|
||||
TypeUnit.TEXT
|
||||
TYPE
|
||||
);
|
||||
answer = builder.boxAnswer;
|
||||
callBack = builder.callBack;
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.quarkus.domain.unit.cmd;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
|
||||
import dev.struchkov.haiti.utils.Checker;
|
||||
@ -16,6 +15,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ReplaceCmd<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "REPLACE_CMD";
|
||||
|
||||
private final MainUnit thisUnit;
|
||||
|
||||
private ReplaceCmd(Builder<M> builder) {
|
||||
@ -31,7 +32,7 @@ public class ReplaceCmd<M extends Message> extends MainUnit<M> {
|
||||
new HashSet<>(),
|
||||
builder.activeType,
|
||||
true,
|
||||
TypeUnit.REPLACE_CMD
|
||||
TYPE
|
||||
);
|
||||
this.thisUnit = builder.thisUnit;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package dev.struchkov.godfather.quarkus.domain.unit.cmd;
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.exception.UnitConfigException;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.quarkus.domain.unit.MainUnit;
|
||||
|
||||
@ -21,6 +20,8 @@ import static dev.struchkov.haiti.utils.Checker.checkNull;
|
||||
*/
|
||||
public class RollBackCmd<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ROLLBACK_CMD";
|
||||
|
||||
/**
|
||||
* Количество юнитов, на которые можно откатиться назад.
|
||||
*/
|
||||
@ -44,7 +45,7 @@ public class RollBackCmd<M extends Message> extends MainUnit<M> {
|
||||
new HashSet<>(),
|
||||
builder.activeType,
|
||||
true,
|
||||
TypeUnit.BACK_CMD
|
||||
TYPE
|
||||
);
|
||||
this.countBack = builder.countBack;
|
||||
this.rollbackUnitName = builder.rollbackUnitName;
|
||||
@ -83,6 +84,7 @@ public class RollBackCmd<M extends Message> extends MainUnit<M> {
|
||||
}
|
||||
|
||||
public static final class Builder<M extends Message> {
|
||||
|
||||
private String name = UUID.randomUUID().toString();
|
||||
private String description;
|
||||
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.simple.domain.unit;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.simple.domain.unit.func.CheckData;
|
||||
@ -21,6 +20,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class AnswerCheck<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ANSWER_CHECK";
|
||||
|
||||
/**
|
||||
* Unit для true.
|
||||
*/
|
||||
@ -59,7 +60,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
|
||||
new HashSet<>(),
|
||||
builder.activeType,
|
||||
builder.notSaveHistory,
|
||||
TypeUnit.CHECK
|
||||
TYPE
|
||||
);
|
||||
unitTrue = builder.unitTrue;
|
||||
unitFalse = builder.unitFalse;
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.simple.domain.unit;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.simple.domain.unit.func.CheckSave;
|
||||
import dev.struchkov.godfather.simple.domain.unit.func.PreservableData;
|
||||
@ -25,6 +24,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class AnswerSave<M extends Message, D> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ANSWER_SAVE";
|
||||
|
||||
/**
|
||||
* Объект отвечающий за сохранение - репозиторий.
|
||||
*/
|
||||
@ -65,7 +66,7 @@ public class AnswerSave<M extends Message, D> extends MainUnit<M> {
|
||||
builder.nextUnits,
|
||||
(builder.hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT,
|
||||
builder.notSaveHistory,
|
||||
TypeUnit.SAVE
|
||||
TYPE
|
||||
);
|
||||
maintenanceNextUnit(nextUnits);
|
||||
preservable = builder.preservable;
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.simple.domain.unit;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.simple.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.simple.domain.unit.func.CallBackConsumer;
|
||||
@ -27,6 +26,8 @@ import java.util.stream.Collectors;
|
||||
*/
|
||||
public class AnswerText<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ANSWER_TEXT";
|
||||
|
||||
/**
|
||||
* Объект, который необходимо отправить пользователю.
|
||||
*/
|
||||
@ -47,7 +48,7 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
|
||||
builder.nextUnits,
|
||||
builder.activeType,
|
||||
builder.notSaveHistory,
|
||||
TypeUnit.TEXT
|
||||
TYPE
|
||||
);
|
||||
answer = builder.boxAnswer;
|
||||
callBack = builder.callBack;
|
||||
|
@ -2,7 +2,6 @@ package dev.struchkov.godfather.simple.domain.unit.cmd;
|
||||
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
|
||||
import dev.struchkov.haiti.utils.Checker;
|
||||
@ -16,6 +15,8 @@ import java.util.stream.Collectors;
|
||||
|
||||
public class ReplaceCmd<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "REPLACE_CMD";
|
||||
|
||||
private final MainUnit thisUnit;
|
||||
|
||||
private ReplaceCmd(Builder<M> builder) {
|
||||
@ -31,7 +32,7 @@ public class ReplaceCmd<M extends Message> extends MainUnit<M> {
|
||||
new HashSet<>(),
|
||||
builder.activeType,
|
||||
true,
|
||||
TypeUnit.REPLACE_CMD
|
||||
TYPE
|
||||
);
|
||||
this.thisUnit = builder.thisUnit;
|
||||
}
|
||||
|
@ -3,7 +3,6 @@ package dev.struchkov.godfather.simple.domain.unit.cmd;
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.exception.UnitConfigException;
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import dev.struchkov.godfather.main.domain.unit.TypeUnit;
|
||||
import dev.struchkov.godfather.main.domain.unit.UnitActiveType;
|
||||
import dev.struchkov.godfather.simple.domain.unit.MainUnit;
|
||||
|
||||
@ -21,6 +20,8 @@ import static dev.struchkov.haiti.utils.Checker.checkNull;
|
||||
*/
|
||||
public class RollBackCmd<M extends Message> extends MainUnit<M> {
|
||||
|
||||
public static final String TYPE = "ROLLBACK_CMD";
|
||||
|
||||
/**
|
||||
* Количество юнитов, на которые можно откатиться назад.
|
||||
*/
|
||||
@ -44,7 +45,7 @@ public class RollBackCmd<M extends Message> extends MainUnit<M> {
|
||||
new HashSet<>(),
|
||||
builder.activeType,
|
||||
true,
|
||||
TypeUnit.BACK_CMD
|
||||
TYPE
|
||||
);
|
||||
this.countBack = builder.countBack;
|
||||
this.rollbackUnitName = builder.rollbackUnitName;
|
||||
|
Loading…
Reference in New Issue
Block a user