diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/TypeUnit.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/TypeUnit.java index 96bcbcb..bfd9f39 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/TypeUnit.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/TypeUnit.java @@ -14,9 +14,10 @@ public class TypeUnit { public static final String TIMER = "TIMER"; public static final String CHECK = "CHECK"; public static final String VALIDITY = "VALIDITY"; - public static final String BACK_CMD = "BACK_CMD"; + public static final String BACK_CMD = "BACK_CMD"; public static final String TELEPORT_CMD = "TELEPORT_CMD"; + public static final String REPLACE_CMD = "REPLACE_CMD"; private TypeUnit() { utilityClass(); diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerCheck.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerCheck.java index dc75f64..761eed0 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerCheck.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerCheck.java @@ -6,6 +6,7 @@ import dev.struchkov.godfather.context.domain.content.Message; import dev.struchkov.godfather.context.service.Accessibility; import dev.struchkov.godfather.context.service.usercode.CheckData; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -41,12 +42,13 @@ public class AnswerCheck extends MainUnit { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, new HashSet<>(), builder.activeType, + builder.notSaveHistory, builder.accessibility, TypeUnit.CHECK ); @@ -73,8 +75,8 @@ public class AnswerCheck extends MainUnit { public static final class Builder { private String name; - private Set keyWords = new HashSet<>(); - private String phrase; + private final Set keyWords = new HashSet<>(); + private final Set phrases = new HashSet<>(); private Pattern pattern; private Integer matchThreshold; private Integer priority; @@ -83,6 +85,7 @@ public class AnswerCheck extends MainUnit { private CheckData check; private UnitActiveType activeType; private Accessibility accessibility; + private boolean notSaveHistory; private Builder() { } @@ -113,7 +116,12 @@ public class AnswerCheck extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } @@ -157,6 +165,11 @@ public class AnswerCheck extends MainUnit { return this; } + public Builder notSaveHistory() { + notSaveHistory = true; + return this; + } + public AnswerCheck build() { isNotNull(check, unitConfigException("Необходимо установить параметр проверки.")); isAnyNotNull(unitConfigException("Необходимо задать хотя бы один unit результата проверки.")); diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerSave.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerSave.java index 1c7f9e9..226dfd9 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerSave.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerSave.java @@ -55,12 +55,13 @@ public class AnswerSave extends MainUnit { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, (builder.hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT, + builder.notSaveHistory, builder.accessibility, TypeUnit.SAVE ); @@ -110,7 +111,7 @@ public class AnswerSave extends MainUnit { public static final class Builder { private String name; private Set keyWords = new HashSet<>(); - private String phrase; + private Set phrases = new HashSet<>(); private Pattern pattern; private Integer matchThreshold; private Integer priority; @@ -122,6 +123,7 @@ public class AnswerSave extends MainUnit { private boolean hidden; private CheckSave checkSave; private Accessibility accessibility; + private boolean notSaveHistory; private Builder() { } @@ -152,7 +154,12 @@ public class AnswerSave extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } @@ -211,11 +218,16 @@ public class AnswerSave extends MainUnit { return this; } - public Builder accessibility(Accessibility val) { + public Builder accessibility(Accessibility val) { accessibility = val; return this; } + public Builder notSaveHistory() { + notSaveHistory = true; + return this; + } + public AnswerSave build() { isNotNull(preservable, "Не указан репозиторий для сохранения формы пользователя"); isNotNull(preservableData, "Не указаны данные для сохранения"); diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerText.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerText.java index a7018df..d491c10 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerText.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerText.java @@ -11,6 +11,7 @@ import dev.struchkov.godfather.context.service.usercode.Insert; import dev.struchkov.godfather.context.service.usercode.MessageFunction; import dev.struchkov.godfather.context.service.usercode.ProcessingData; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.function.Consumer; @@ -45,12 +46,13 @@ public class AnswerText extends MainUnit { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, builder.activeType, + builder.notSaveHistory, builder.accessibility, TypeUnit.TEXT ); @@ -80,18 +82,19 @@ public class AnswerText extends MainUnit { } public static final class Builder { + private final Set keyWords = new HashSet<>(); + private final Set phrases = new HashSet<>(); private String name; private ProcessingData boxAnswer; private Insert insert; private Sending sending; - private Set keyWords = new HashSet<>(); - private String phrase; private Pattern pattern; private Integer matchThreshold; private Integer priority; private Set nextUnits = new HashSet<>(); private UnitActiveType activeType; private Accessibility accessibility; + private boolean notSaveHistory; private Builder() { } @@ -158,7 +161,12 @@ public class AnswerText extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } @@ -187,11 +195,16 @@ public class AnswerText extends MainUnit { return this; } - public Builder accessibility(Accessibility val) { + public Builder accessibility(Accessibility val) { accessibility = val; return this; } + public Builder notSaveHistory() { + notSaveHistory = true; + return this; + } + public Builder activeType(UnitActiveType val) { activeType = val; return this; diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerTimer.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerTimer.java index 71e01fb..ef51233 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerTimer.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerTimer.java @@ -3,10 +3,10 @@ package dev.struchkov.godfather.context.domain.unit; import dev.struchkov.autoresponder.entity.KeyWord; import dev.struchkov.godfather.context.domain.TypeUnit; import dev.struchkov.godfather.context.domain.content.Message; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; import dev.struchkov.godfather.context.service.Accessibility; import dev.struchkov.godfather.context.service.usercode.CheckData; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -46,12 +46,13 @@ public class AnswerTimer extends MainUnit { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, null, builder.activeType, + builder.notSaveHistory, builder.accessibility, TypeUnit.TIMER ); @@ -87,13 +88,14 @@ public class AnswerTimer extends MainUnit { private Integer timeDelaySec; private Integer timeDeathSec; private CheckData checkLoop; - private Set keyWords = new HashSet<>(); - private String phrase; + private final Set keyWords = new HashSet<>(); + private final Set phrases = new HashSet<>(); private Pattern pattern; private Integer matchThreshold; private Integer priority; private UnitActiveType activeType = UnitActiveType.AFTER; private Accessibility accessibility; + private boolean notSaveHistory; private Builder() { } @@ -144,7 +146,12 @@ public class AnswerTimer extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } @@ -163,11 +170,16 @@ public class AnswerTimer extends MainUnit { return this; } - public Builder accessibility(Accessibility val) { + public Builder accessibility(Accessibility val) { accessibility = val; return this; } + public Builder notSaveHistory() { + notSaveHistory = true; + return this; + } + public Builder activeType(UnitActiveType val) { activeType = val; return this; diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerValidity.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerValidity.java index eaa86d4..23cf582 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerValidity.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/AnswerValidity.java @@ -7,6 +7,7 @@ import dev.struchkov.godfather.context.service.ClarificationQuestion; import dev.struchkov.godfather.context.service.save.LocalPreservable; import dev.struchkov.godfather.context.service.save.Preservable; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -42,12 +43,13 @@ public class AnswerValidity extends MainUnit { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, UnitActiveType.DEFAULT, + builder.notSaveHistory, builder.accessibility, TypeUnit.VALIDITY ); @@ -82,18 +84,19 @@ public class AnswerValidity extends MainUnit { } public static final class Builder { + private final Set keyWords = new HashSet<>(); + private final Set phrases = new HashSet<>(); private String name; private MainUnit unitYes; private MainUnit unitNo; private MainUnit unitNull; private ClarificationQuestion clarificationQuestion; - private Set keyWords = new HashSet<>(); - private String phrase; private Pattern pattern; private Integer matchThreshold; private Integer priority; private Set nextUnits = new HashSet<>(); private Accessibility accessibility; + private boolean notSaveHistory; private Builder() { } @@ -144,7 +147,12 @@ public class AnswerValidity extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } @@ -183,6 +191,11 @@ public class AnswerValidity extends MainUnit { return this; } + public Builder notSaveHistory() { + notSaveHistory = true; + return this; + } + public AnswerValidity build() { return new AnswerValidity(this); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/LazyUnit.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/LazyUnit.java deleted file mode 100644 index 62a255b..0000000 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/LazyUnit.java +++ /dev/null @@ -1,36 +0,0 @@ -package dev.struchkov.godfather.context.domain.unit; - -import dev.struchkov.autoresponder.entity.KeyWord; -import dev.struchkov.godfather.context.domain.UnitDefinition; -import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; -import dev.struchkov.godfather.context.service.Accessibility; - -import java.util.Set; -import java.util.regex.Pattern; - -public class LazyUnit extends MainUnit { - - private final UnitDefinition unitDefinition; - - private LazyUnit( - String name, - Set keyWords, - String phrase, - Pattern pattern, - Integer matchThreshold, - Integer priority, - Set nextUnits, - UnitActiveType activeType, - String type, - UnitDefinition unitDefinition, - Accessibility accessibility - ) { - super(name, keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, accessibility, type); - this.unitDefinition = unitDefinition; - } - - public static LazyUnit create(String name, UnitDefinition unitDefinition) { - return new LazyUnit(name, null, null, null, null, null, null, null, null, unitDefinition, null); - } - -} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/MainUnit.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/MainUnit.java index 46a9f5a..8ed3ad3 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/MainUnit.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/MainUnit.java @@ -40,25 +40,29 @@ public abstract class MainUnit extends Unit { /** * Проверка доступа пользователя к юниту. */ - private Accessibility accessibility; + private final Accessibility accessibility; + + private final boolean notSaveHistory; protected MainUnit( String name, Set keyWords, - String phrase, + Set phrases, Pattern pattern, Integer matchThreshold, Integer priority, Set nextUnits, UnitActiveType activeType, + boolean notSaveHistory, Accessibility accessibility, String type ) { - super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits); + super(keyWords, phrases, pattern, matchThreshold, priority, nextUnits); this.name = name; this.activeType = Optional.ofNullable(activeType).orElse(UnitActiveType.DEFAULT); this.accessibility = accessibility; this.type = type; + this.notSaveHistory = notSaveHistory; } public String getType() { @@ -85,6 +89,10 @@ public abstract class MainUnit extends Unit { return name; } + public boolean isNotSaveHistory() { + return notSaveHistory; + } + public Optional getAccessibility() { return Optional.ofNullable(accessibility); } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/ReplaceCmd.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/ReplaceCmd.java new file mode 100644 index 0000000..f9aed0a --- /dev/null +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/ReplaceCmd.java @@ -0,0 +1,124 @@ +package dev.struchkov.godfather.context.domain.unit.cmd; + +import dev.struchkov.autoresponder.entity.KeyWord; +import dev.struchkov.godfather.context.domain.TypeUnit; +import dev.struchkov.godfather.context.domain.unit.MainUnit; +import dev.struchkov.godfather.context.domain.unit.UnitActiveType; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Set; +import java.util.regex.Pattern; +import java.util.stream.Collectors; + +public class ReplaceCmd extends MainUnit { + + private final MainUnit thisUnit; + + private ReplaceCmd(Builder builder) { + super( + builder.name, + builder.keyWords, + builder.phrases, + builder.pattern, + builder.matchThreshold, + builder.priority, + new HashSet<>(), + builder.activeType, + true, + null, + TypeUnit.REPLACE_CMD + ); + this.thisUnit = builder.thisUnit; + } + + public static Builder builder() { + return new Builder(); + } + + public MainUnit getThisUnit() { + return thisUnit; + } + + public static final class Builder { + private final Set keyWords = new HashSet<>(); + private String name; + private Set phrases = new HashSet<>(); + private Pattern pattern; + private Integer matchThreshold; + private Integer priority; + private UnitActiveType activeType = UnitActiveType.AFTER; + + private MainUnit thisUnit; + + private Builder() { + } + + public Builder name(String name) { + this.name = name; + return this; + } + + public Builder keyWords(Set val) { + keyWords.addAll(val); + return this; + } + + public Builder keyWord(KeyWord val) { + keyWords.add(val); + return this; + } + + public Builder stringKeyWords(Set val) { + keyWords.addAll(val.stream().map(KeyWord::of).collect(Collectors.toSet())); + return this; + } + + public Builder keyWord(String val) { + keyWords.add(KeyWord.of(val)); + return this; + } + + public Builder phrase(String val) { + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); + return this; + } + + public Builder pattern(Pattern val) { + pattern = val; + return this; + } + + public Builder matchThreshold(Integer val) { + matchThreshold = val; + return this; + } + + public Builder priority(Integer val) { + priority = val; + return this; + } + + public Builder activeType(UnitActiveType val) { + activeType = val; + return this; + } + + public Builder thisUnit(MainUnit val) { + thisUnit = val; + return this; + } + + + public ReplaceCmd build() { + return new ReplaceCmd(this); + } + + } + +} diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/RollBackCmd.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/RollBackCmd.java index 0cf8be4..257f7ac 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/RollBackCmd.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/RollBackCmd.java @@ -6,6 +6,7 @@ import dev.struchkov.godfather.context.domain.unit.MainUnit; import dev.struchkov.godfather.context.domain.unit.UnitActiveType; import dev.struchkov.godfather.context.exception.UnitConfigException; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -30,12 +31,13 @@ public class RollBackCmd extends MainUnit { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, new HashSet<>(), builder.activeType, + true, null, TypeUnit.BACK_CMD ); @@ -66,7 +68,7 @@ public class RollBackCmd extends MainUnit { public static final class Builder { private final Set keyWords = new HashSet<>(); private String name; - private String phrase; + private Set phrases = new HashSet<>(); private Pattern pattern; private Integer matchThreshold; private Integer priority; @@ -103,7 +105,12 @@ public class RollBackCmd extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/TeleportCmd.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/TeleportCmd.java index 545bf23..5b9a879 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/TeleportCmd.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/unit/cmd/TeleportCmd.java @@ -5,6 +5,7 @@ import dev.struchkov.godfather.context.domain.TypeUnit; import dev.struchkov.godfather.context.domain.unit.MainUnit; import dev.struchkov.godfather.context.domain.unit.UnitActiveType; +import java.util.Collection; import java.util.HashSet; import java.util.Set; import java.util.regex.Pattern; @@ -18,36 +19,37 @@ public class TeleportCmd extends MainUnit { /** * Название юнита, в которое необходимо осуществить перенос. */ - private String unitNameToTeleport; + private final String unitNameToTeleport; private TeleportCmd(Builder builder) { super( builder.name, builder.keyWords, - builder.phrase, + builder.phrases, builder.pattern, builder.matchThreshold, builder.priority, new HashSet<>(), builder.activeType, + true, null, TypeUnit.TELEPORT_CMD ); this.unitNameToTeleport = builder.unitNameToTeleport; } - public String getUnitNameToTeleport() { - return unitNameToTeleport; - } - public static Builder builder() { return new Builder(); } + public String getUnitNameToTeleport() { + return unitNameToTeleport; + } + public static final class Builder { + private final Set keyWords = new HashSet<>(); + private final Set phrases = new HashSet<>(); private String name; - private Set keyWords = new HashSet<>(); - private String phrase; private Pattern pattern; private Integer matchThreshold; private Integer priority; @@ -83,7 +85,12 @@ public class TeleportCmd extends MainUnit { } public Builder phrase(String val) { - phrase = val; + phrases.add(val); + return this; + } + + public Builder phrases(Collection val) { + phrases.addAll(val); return this; } diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/StorylineMapRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/StorylineMapRepository.java index dbb7c1f..8044296 100644 --- a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/StorylineMapRepository.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/StorylineMapRepository.java @@ -39,7 +39,7 @@ public class StorylineMapRepository implements StorylineRepository { public Optional findByCountLast(long personId, String unitName) { if (map.containsKey(personId)) { final Stack stack = map.get(personId); - StorylineHistory storylineHistory = null; + StorylineHistory storylineHistory; while (!stack.isEmpty()) { storylineHistory = stack.pop(); if (unitName.equals(storylineHistory.getUnitName())) { diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java index 9b74510..09ccf9d 100644 --- a/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java @@ -19,6 +19,7 @@ import dev.struchkov.godfather.core.service.action.AnswerSaveAction; import dev.struchkov.godfather.core.service.action.AnswerTextAction; import dev.struchkov.godfather.core.service.action.AnswerTimerAction; import dev.struchkov.godfather.core.service.action.AnswerValidityAction; +import dev.struchkov.godfather.core.service.action.cmd.ReplaceCmdAction; import dev.struchkov.godfather.core.service.timer.TimerService; import dev.struchkov.haiti.context.exception.NotFoundException; @@ -51,6 +52,7 @@ public class GeneralAutoResponder { actionUnitMap.put(TypeUnit.CHECK, new AnswerCheckAction()); actionUnitMap.put(TypeUnit.TEXT, new AnswerTextAction(sending)); actionUnitMap.put(TypeUnit.VALIDITY, new AnswerValidityAction()); + actionUnitMap.put(TypeUnit.REPLACE_CMD, new ReplaceCmdAction()); } public void initModifiable(List> modifiable) { @@ -128,14 +130,7 @@ public class GeneralAutoResponder { public void answer(UnitRequest unitRequest) { try { unitRequest = getAction(unitRequest); - unitRequest = activeUnitAfter(unitRequest); - - final Optional optDefaultUnit = storyLineService.getDefaultUnit(); - final MainUnit unit = unitRequest.getUnit(); - final T message = unitRequest.getMessage(); - if (optDefaultUnit.isEmpty() || !optDefaultUnit.get().equals(unit)) { - storyLineService.save(message.getPersonId(), unit.getName(), message); - } + activeUnitAfter(unitRequest); } catch (Exception e) { if (errorHandler != null) { errorHandler.handle(unitRequest.getMessage(), e); @@ -161,10 +156,15 @@ public class GeneralAutoResponder { private UnitRequest getAction(UnitRequest unitRequest) { final MainUnit unit = unitRequest.getUnit(); + final T message = unitRequest.getMessage(); final String typeUnit = unit.getType(); if (actionUnitMap.containsKey(typeUnit)) { ActionUnit actionUnit = actionUnitMap.get(typeUnit); UnitRequest newUnitRequest = actionUnit.action(unitRequest); + final Optional optDefaultUnit = storyLineService.getDefaultUnit(); + if (!unit.isNotSaveHistory() && (optDefaultUnit.isEmpty() || !optDefaultUnit.get().equals(unit))) { + storyLineService.save(message.getPersonId(), unit.getName(), message); + } final MainUnit newUnit = newUnitRequest.getUnit(); return !unit.equals(newUnit) ? getAction(newUnitRequest) : unitRequest; } else { diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/cmd/ReplaceCmdAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/cmd/ReplaceCmdAction.java new file mode 100644 index 0000000..c8db08f --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/cmd/ReplaceCmdAction.java @@ -0,0 +1,18 @@ +package dev.struchkov.godfather.core.service.action.cmd; + +import dev.struchkov.godfather.context.domain.UnitRequest; +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.domain.unit.MainUnit; +import dev.struchkov.godfather.context.domain.unit.cmd.ReplaceCmd; +import dev.struchkov.godfather.core.service.action.ActionUnit; + +public class ReplaceCmdAction implements ActionUnit { + + @Override + public UnitRequest action(UnitRequest unitRequest) { + final ReplaceCmd unit = unitRequest.getUnit(); + final Message message = unitRequest.getMessage(); + return UnitRequest.of(unit.getThisUnit(), message); + } + +} diff --git a/pom.xml b/pom.xml index 4ff8941..ebf976c 100644 --- a/pom.xml +++ b/pom.xml @@ -37,7 +37,7 @@ ${godfather.ver} ${godfather.ver} - 3.1.0 + 3.2.0 1.0.2 2.2