diff --git a/bot-context/pom.xml b/bot-context/pom.xml
index fa90386..b1e62d2 100644
--- a/bot-context/pom.xml
+++ b/bot-context/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.godfather
godfather-bot
- 0.0.12
+ 0.0.14
bot-context
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java
index e5c599f..30638ab 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoardLine.java
@@ -4,6 +4,7 @@ import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
/**
@@ -16,7 +17,7 @@ public class SimpleKeyBoardLine implements KeyBoardLine {
/**
* Кнопки в строке.
*/
- protected List buttons = new ArrayList<>();
+ protected List buttons;
public SimpleKeyBoardLine(List buttons) {
this.buttons = buttons;
@@ -26,8 +27,8 @@ public class SimpleKeyBoardLine implements KeyBoardLine {
buttons = builder.buttons;
}
- public static SimpleKeyBoardLine simpleLine(KeyBoardButton keyBoardButton) {
- return new SimpleKeyBoardLine(List.of(keyBoardButton));
+ public static SimpleKeyBoardLine simpleLine(KeyBoardButton... keyBoardButton) {
+ return new SimpleKeyBoardLine(Arrays.stream(keyBoardButton).toList());
}
public static Builder builder() {
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 226dfd9..9155f49 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
@@ -3,9 +3,9 @@ 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.repository.preser.AnswerSavePreservable;
import dev.struchkov.godfather.context.service.Accessibility;
import dev.struchkov.godfather.context.service.save.CheckSave;
-import dev.struchkov.godfather.context.service.save.Preservable;
import dev.struchkov.godfather.context.service.save.PreservableData;
import dev.struchkov.godfather.context.service.save.Pusher;
@@ -27,7 +27,7 @@ public class AnswerSave extends MainUnit {
/**
* Объект отвечающий за сохранение - репозиторий.
*/
- private final Preservable preservable;
+ private final AnswerSavePreservable preservable;
/**
* Ключ для данных.
@@ -84,7 +84,7 @@ public class AnswerSave extends MainUnit {
}
}
- public Preservable getPreservable() {
+ public AnswerSavePreservable getPreservable() {
return preservable;
}
@@ -110,13 +110,13 @@ public class AnswerSave extends MainUnit {
public static final class Builder {
private String name;
- private Set keyWords = new HashSet<>();
- private Set phrases = new HashSet<>();
+ private final Set keyWords = new HashSet<>();
+ private final Set phrases = new HashSet<>();
private Pattern pattern;
private Integer matchThreshold;
private Integer priority;
private Set nextUnits = new HashSet<>();
- private Preservable preservable;
+ private AnswerSavePreservable preservable;
private String key;
private Pusher pusher;
private PreservableData preservableData;
@@ -188,7 +188,7 @@ public class AnswerSave extends MainUnit {
return this;
}
- public Builder preservable(Preservable val) {
+ public Builder preservable(AnswerSavePreservable val) {
this.preservable = 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 23cf582..c57bf6d 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
@@ -4,8 +4,8 @@ import dev.struchkov.autoresponder.entity.KeyWord;
import dev.struchkov.godfather.context.domain.TypeUnit;
import dev.struchkov.godfather.context.service.Accessibility;
import dev.struchkov.godfather.context.service.ClarificationQuestion;
-import dev.struchkov.godfather.context.service.save.LocalPreservable;
-import dev.struchkov.godfather.context.service.save.Preservable;
+import dev.struchkov.godfather.context.repository.preser.AnswerSaveMapPreservable;
+import dev.struchkov.godfather.context.repository.preser.Preservable;
import java.util.Collection;
import java.util.HashSet;
@@ -35,7 +35,7 @@ public class AnswerValidity extends MainUnit {
*/
private final MainUnit unitNull;
- private final Preservable tempSave = new LocalPreservable<>();
+ private final Preservable tempSave = new AnswerSaveMapPreservable<>();
private final ClarificationQuestion clarificationQuestion;
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 257f7ac..4748172 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
@@ -57,6 +57,18 @@ public class RollBackCmd extends MainUnit {
return RollBackCmd.builder().countBack(1).build();
}
+ public static RollBackCmd doubleRollBack() {
+ return RollBackCmd.builder().countBack(2).build();
+ }
+
+ public static RollBackCmd rollBack(String unitName) {
+ return RollBackCmd.builder().rollbackUnitName(unitName).build();
+ }
+
+ public static RollBackCmd rollBack(String phrase, String unitName) {
+ return RollBackCmd.builder().phrase(phrase).rollbackUnitName(unitName).build();
+ }
+
public int getCountBack() {
return countBack;
}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/AnswerSaveMapPreservable.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/AnswerSaveMapPreservable.java
new file mode 100644
index 0000000..086d6fb
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/AnswerSaveMapPreservable.java
@@ -0,0 +1,37 @@
+package dev.struchkov.godfather.context.repository.preser;
+
+import dev.struchkov.godfather.context.service.save.Pusher;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class AnswerSaveMapPreservable implements AnswerSavePreservable {
+
+ private final Map> saveMap = new HashMap<>();
+
+ @Override
+ public void save(Long personId, String key, S save) {
+ saveMap.computeIfAbsent(personId, k -> new HashMap<>()).put(key, save);
+ }
+
+ @Override
+ public Optional getByKey(Long personId, String key) {
+ if (saveMap.containsKey(personId)
+ && saveMap.get(personId).containsKey(key)) {
+ return Optional.of(saveMap.get(personId).get(key));
+ }
+ return Optional.empty();
+ }
+
+ @Override
+ public Map getAllSaveElement(Long personId) {
+ return saveMap.get(personId);
+ }
+
+ @Override
+ public void push(Long personId, Pusher pusher) {
+ Optional.ofNullable(pusher).ifPresent(sPusher -> sPusher.push(getAllSaveElement(personId)));
+ }
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/AnswerSavePreservable.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/AnswerSavePreservable.java
new file mode 100644
index 0000000..526fff1
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/AnswerSavePreservable.java
@@ -0,0 +1,14 @@
+package dev.struchkov.godfather.context.repository.preser;
+
+import dev.struchkov.godfather.context.service.save.Pusher;
+
+public interface AnswerSavePreservable extends Preservable {
+
+ /**
+ * Финальное сохранение, можно реализовать как отправку данных куда-то
+ *
+ * @param personId Идентификатор пользователя
+ */
+ void push(Long personId, Pusher pusher);
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/save/Preservable.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/Preservable.java
similarity index 55%
rename from bot-context/src/main/java/dev/struchkov/godfather/context/service/save/Preservable.java
rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/Preservable.java
index a5ed2d5..8910c80 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/save/Preservable.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/preser/Preservable.java
@@ -1,6 +1,4 @@
-package dev.struchkov.godfather.context.service.save;
-
-import dev.struchkov.godfather.context.service.save.Pusher;
+package dev.struchkov.godfather.context.repository.preser;
import java.util.Map;
import java.util.Optional;
@@ -22,15 +20,6 @@ public interface Preservable {
Optional getByKey(Long personId, String key);
- /**
- * Финальное сохранение, можно реализовать как отправку данных куда-то
- *
- * @param personId Идентификатор пользователя
- */
- default void push(Long personId, Pusher pusher) {
- Optional.ofNullable(pusher).ifPresent(sPusher -> sPusher.push(getAllSaveElement(personId)));
- }
-
Map getAllSaveElement(Long personId);
}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/UnitContextFactory.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/UnitContextFactory.java
new file mode 100644
index 0000000..d33aba7
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/UnitContextFactory.java
@@ -0,0 +1,10 @@
+package dev.struchkov.godfather.context.service;
+
+import dev.struchkov.godfather.context.domain.content.Message;
+import dev.struchkov.godfather.context.domain.unit.AnswerText;
+
+public interface UnitContextFactory {
+
+ AnswerText.Builder createAnswerText();
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/save/LocalPreservable.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/save/LocalPreservable.java
deleted file mode 100644
index 99ab0f6..0000000
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/save/LocalPreservable.java
+++ /dev/null
@@ -1,37 +0,0 @@
-package dev.struchkov.godfather.context.service.save;
-
-import dev.struchkov.godfather.context.service.save.Preservable;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Optional;
-
-public class LocalPreservable implements Preservable {
-
- private final Map> saveMap = new HashMap<>();
-
- @Override
- public void save(Long personId, String key, S save) {
- if (!saveMap.containsKey(personId)) {
- saveMap.put(personId, new HashMap<>());
- }
- saveMap.get(personId).put(key, save);
- }
-
- @Override
- public Optional getByKey(Long personId, String key) {
- if (saveMap.containsKey(personId)) {
- if (saveMap.get(personId).containsKey(key)) {
- return Optional.of(saveMap.get(personId).get(key));
- }
- }
- return Optional.empty();
- }
-
- @Override
- public Map getAllSaveElement(Long personId) {
- return saveMap.get(personId);
- }
-
-
-}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/usercode/ProcessingData.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/usercode/ProcessingData.java
index fda5b84..ca46acf 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/usercode/ProcessingData.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/usercode/ProcessingData.java
@@ -1,10 +1,9 @@
package dev.struchkov.godfather.context.service.usercode;
import dev.struchkov.godfather.context.domain.BoxAnswer;
-import dev.struchkov.godfather.context.domain.content.Message;
@FunctionalInterface
-public interface ProcessingData {
+public interface ProcessingData {
BoxAnswer processing(C content);
diff --git a/bot-core/pom.xml b/bot-core/pom.xml
index 32a4d90..e1d5fda 100644
--- a/bot-core/pom.xml
+++ b/bot-core/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.godfather
godfather-bot
- 0.0.12
+ 0.0.14
bot-core
diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerSaveAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerSaveAction.java
index 4a75d19..059f09b 100644
--- a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerSaveAction.java
+++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerSaveAction.java
@@ -4,8 +4,8 @@ import dev.struchkov.godfather.context.domain.UnitRequest;
import dev.struchkov.godfather.context.domain.content.Message;
import dev.struchkov.godfather.context.domain.unit.AnswerSave;
import dev.struchkov.godfather.context.domain.unit.MainUnit;
+import dev.struchkov.godfather.context.repository.preser.AnswerSavePreservable;
import dev.struchkov.godfather.context.service.save.CheckSave;
-import dev.struchkov.godfather.context.service.save.Preservable;
import dev.struchkov.godfather.context.service.save.PreservableData;
/**
@@ -20,7 +20,7 @@ public class AnswerSaveAction implements ActionUnit, Message> {
final AnswerSave answerSave = unitRequest.getUnit();
final Message message = unitRequest.getMessage();
- final Preservable preservable = answerSave.getPreservable();
+ final AnswerSavePreservable preservable = answerSave.getPreservable();
final Long personId = message.getPersonId();
final CheckSave super Message> checkSave = answerSave.getCheckSave();
diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java
index a52746b..a1e2558 100644
--- a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java
+++ b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java
@@ -9,7 +9,7 @@
//import dev.struchkov.godfather.core.domain.unit.AnswerText;
//import dev.struchkov.godfather.core.domain.unit.MainUnit;
//import dev.struchkov.godfather.core.domain.unit.UnitActiveType;
-//import dev.struchkov.godfather.context.service.save.Preservable;
+//import dev.struchkov.godfather.context.repository.preser.Preservable;
//import dev.struchkov.godfather.context.service.save.Pusher;
//
//import java.util.List;
diff --git a/pom.xml b/pom.xml
index 87be887..c400431 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.godfather
godfather-bot
- 0.0.12
+ 0.0.14
pom
@@ -32,7 +32,7 @@
UTF-8
UTF-8
- 0.0.12
+ 0.0.14
${godfather.ver}
${godfather.ver}