diff --git a/bot-context/pom.xml b/bot-context/pom.xml
index a8eb960..24a18f5 100644
--- a/bot-context/pom.xml
+++ b/bot-context/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.godfather
godfather-bot
- 0.0.6
+ 0.0.7
bot-context
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/UnitDefinition.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/UnitDefinition.java
new file mode 100644
index 0000000..e933d3d
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/UnitDefinition.java
@@ -0,0 +1,77 @@
+package dev.struchkov.godfather.context.domain;
+
+import java.lang.reflect.Method;
+import java.util.HashSet;
+import java.util.Set;
+
+public class UnitDefinition {
+
+ private final Set nextUnitNames = new HashSet<>();
+ private final Set dependentUnits = new HashSet<>();
+
+ private String name;
+ private Object objectConfig;
+ private Method method;
+ private boolean lazy;
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Object getObjectConfig() {
+ return objectConfig;
+ }
+
+ public void setObjectConfig(Object objectConfig) {
+ this.objectConfig = objectConfig;
+ }
+
+ public Method getMethod() {
+ return method;
+ }
+
+ public void setMethod(Method method) {
+ this.method = method;
+ }
+
+ public Set getNextUnitNames() {
+ return new HashSet<>(nextUnitNames);
+ }
+
+ public void setNextUnitNames(Set nextUnitNames) {
+ this.nextUnitNames.addAll(nextUnitNames);
+ }
+
+ public void setNextUnitName(String nextUnitName) {
+ this.nextUnitNames.add(nextUnitName);
+ }
+
+ public void removeNextUnit(String nextUnitName) {
+ this.nextUnitNames.remove(nextUnitName);
+ }
+
+ public void removeDependentUnit(String dependentUnitName) {
+ this.dependentUnits.remove(dependentUnitName);
+ }
+
+ public Set getDependentUnits() {
+ return new HashSet<>(dependentUnits);
+ }
+
+ public void setDependentUnits(Set dependentUnitNames) {
+ this.dependentUnits.addAll(dependentUnitNames);
+ }
+
+ public boolean isLazy() {
+ return lazy;
+ }
+
+ public void setLazy(boolean lazy) {
+ this.lazy = lazy;
+ }
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/UnitPointer.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/UnitPointer.java
new file mode 100644
index 0000000..882adfc
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/UnitPointer.java
@@ -0,0 +1,36 @@
+package dev.struchkov.godfather.context.domain;
+
+import java.util.Objects;
+
+public class UnitPointer {
+
+ private Long personId;
+ private String unitName;
+
+ public UnitPointer(Long personId, String unitName) {
+ this.personId = personId;
+ this.unitName = unitName;
+ }
+
+ public Long getPersonId() {
+ return personId;
+ }
+
+ public String getUnitName() {
+ return unitName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) return true;
+ if (o == null || getClass() != o.getClass()) return false;
+ UnitPointer that = (UnitPointer) o;
+ return Objects.equals(personId, that.personId) && Objects.equals(unitName, that.unitName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(personId, unitName);
+ }
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/annotation/Unit.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/annotation/Unit.java
new file mode 100644
index 0000000..06dcc80
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/annotation/Unit.java
@@ -0,0 +1,20 @@
+package dev.struchkov.godfather.context.domain.annotation;
+
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+@Retention(RUNTIME)
+@Target({METHOD, PARAMETER})
+public @interface Unit {
+
+ String value() default "";
+
+ boolean lazy() default false;
+
+ boolean mainUnit() default false;
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java
index eba5ff8..6cb0d7e 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/SimpleButton.java
@@ -33,7 +33,7 @@ public class SimpleButton implements KeyBoardButton {
}
public static SimpleButton simpleButton(@NotNull String label) {
- return new SimpleButton(label, label);
+ return new SimpleButton(label, null);
}
public String getLabel() {
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java
index 8f737d4..1b32b53 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/simple/SimpleKeyBoard.java
@@ -33,7 +33,7 @@ public class SimpleKeyBoard implements KeyBoard {
return new SimpleKeyBoard(List.of(line));
}
- public static Builder build() {
+ public static Builder builder() {
return new Builder();
}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java
index a88c6a5..6f7c4e3 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/UnitConfigException.java
@@ -16,8 +16,12 @@ public class UnitConfigException extends AppBotException{
super(message);
}
+ public UnitConfigException(String message, Object... objects) {
+ super(MessageFormat.format(message, objects));
+ }
+
public static Supplier unitConfigException(String message, Object... objects) {
- return () -> new NotFoundException(MessageFormat.format(message, objects));
+ return () -> new NotFoundException(message, objects);
}
}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/PersonSettingRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/PersonSettingRepository.java
new file mode 100644
index 0000000..c6883d0
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/PersonSettingRepository.java
@@ -0,0 +1,16 @@
+package dev.struchkov.godfather.context.repository;
+
+import java.util.Optional;
+import java.util.Set;
+
+public interface PersonSettingRepository {
+
+ Set findAllByAllowedProcessing(Set personIds);
+
+ void disableMessageProcessing(Long personId);
+
+ void enableMessageProcessing(Long personId);
+
+ Optional findStateByPersonId(Long personId);
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/UnitPointerRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/UnitPointerRepository.java
new file mode 100644
index 0000000..d261962
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/UnitPointerRepository.java
@@ -0,0 +1,19 @@
+package dev.struchkov.godfather.context.repository;
+
+import dev.struchkov.godfather.context.domain.UnitPointer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Optional;
+
+/**
+ * Контракт для сохранения позиции пользователя в сценарии.
+ */
+public interface UnitPointerRepository {
+
+ UnitPointer save(@NotNull UnitPointer unitPointer);
+
+ Optional findUnitNameByPersonId(@NotNull Long personId);
+
+ void removeByPersonId(@NotNull Long personId);
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/PersonSettingLocalRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/PersonSettingLocalRepository.java
new file mode 100644
index 0000000..0b301f6
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/PersonSettingLocalRepository.java
@@ -0,0 +1,37 @@
+package dev.struchkov.godfather.context.repository.impl.local;
+
+import dev.struchkov.godfather.context.repository.PersonSettingRepository;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+public class PersonSettingLocalRepository implements PersonSettingRepository {
+
+ private final Map map = new HashMap<>();
+
+ @Override
+ public Set findAllByAllowedProcessing(Set personIds) {
+ return personIds.stream()
+ .filter(map::get)
+ .collect(Collectors.toSet());
+ }
+
+ @Override
+ public void disableMessageProcessing(Long personId) {
+ map.put(personId, false);
+ }
+
+ @Override
+ public void enableMessageProcessing(Long personId) {
+ map.put(personId, true);
+ }
+
+ @Override
+ public Optional findStateByPersonId(Long personId) {
+ return Optional.ofNullable(map.get(personId));
+ }
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/UnitPointLocalRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/UnitPointLocalRepository.java
new file mode 100644
index 0000000..88e9b0b
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/UnitPointLocalRepository.java
@@ -0,0 +1,31 @@
+package dev.struchkov.godfather.context.repository.impl.local;
+
+import dev.struchkov.godfather.context.domain.UnitPointer;
+import dev.struchkov.godfather.context.repository.UnitPointerRepository;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Optional;
+
+public class UnitPointLocalRepository implements UnitPointerRepository {
+
+ public static final Map map = new HashMap<>();
+
+ @Override
+ public UnitPointer save(@NotNull UnitPointer unitPointer) {
+ map.put(unitPointer.getPersonId(), unitPointer.getUnitName());
+ return unitPointer;
+ }
+
+ @Override
+ public Optional findUnitNameByPersonId(@NotNull Long personId) {
+ return Optional.ofNullable(map.get(personId));
+ }
+
+ @Override
+ public void removeByPersonId(@NotNull Long personId) {
+ map.remove(personId);
+ }
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/EventProvider.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/EventProvider.java
new file mode 100644
index 0000000..26b8a6d
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/EventProvider.java
@@ -0,0 +1,9 @@
+package dev.struchkov.godfather.context.service;
+
+import dev.struchkov.godfather.context.domain.content.Message;
+
+public interface EventProvider {
+
+ void sendEvent(M message);
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/PersonSettingService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/PersonSettingService.java
new file mode 100644
index 0000000..972d0ae
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/PersonSettingService.java
@@ -0,0 +1,18 @@
+package dev.struchkov.godfather.context.service;
+
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Optional;
+import java.util.Set;
+
+public interface PersonSettingService {
+
+ Set getAllPersonIdDisableMessages(@NotNull Set personIds);
+
+ Optional getStateProcessingByPersonId(@NotNull Long personId);
+
+ void disableMessageProcessing(@NotNull Long personId);
+
+ void enableMessageProcessing(@NotNull Long personId);
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/UnitPointerService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/UnitPointerService.java
new file mode 100644
index 0000000..404429f
--- /dev/null
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/UnitPointerService.java
@@ -0,0 +1,21 @@
+package dev.struchkov.godfather.context.service;
+
+import dev.struchkov.godfather.context.domain.UnitPointer;
+import org.jetbrains.annotations.NotNull;
+
+import java.util.Optional;
+
+/**
+ * Сервис для взаимодействия с сущностью {@link UnitPointer}.
+ *
+ * @author upagge [07/07/2019]
+ */
+public interface UnitPointerService {
+
+ UnitPointer save(@NotNull UnitPointer unitPointer);
+
+ Optional getUnitNameByPersonId(@NotNull Long personId);
+
+ void removeByPersonId(@NotNull Long personId);
+
+}
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java
index c9a016a..038c933 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java
@@ -18,8 +18,6 @@ public interface Sending {
*/
void send(@NotNull Long personId, @NotNull BoxAnswer boxAnswer);
- void send(@NotNull Long contentId, @NotNull Long personId, @NotNull BoxAnswer boxAnswer);
-
/**
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью
* разных методов.
diff --git a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/SimpleKeyBoards.java
similarity index 97%
rename from bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java
rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/SimpleKeyBoards.java
index 178c0f8..3aee316 100644
--- a/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java
+++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/SimpleKeyBoards.java
@@ -12,12 +12,12 @@ import java.util.List;
*
* @author upagge [08/07/2019]
*/
-public class KeyBoards {
+public class SimpleKeyBoards {
public static final SimpleButton YES_BUTTON = SimpleButton.simpleButton("Да", "{\"button\": \"yes\"}");
public static final SimpleButton NO_BUTTON = SimpleButton.simpleButton("Нет", "{\"button\": \"no\"}");
- private KeyBoards() {
+ private SimpleKeyBoards() {
throw new IllegalStateException();
}
@@ -27,7 +27,7 @@ public class KeyBoards {
* @return {@link SimpleKeyBoard}
*/
public static SimpleKeyBoard keyBoardYesNo() {
- return SimpleKeyBoard.build().line(
+ return SimpleKeyBoard.builder().line(
SimpleKeyBoardLine.builder().button(YES_BUTTON).button(NO_BUTTON).build()
).build();
}
@@ -39,7 +39,7 @@ public class KeyBoards {
* @return {@link SimpleKeyBoard}
*/
public static SimpleKeyBoard verticalMenuString(List labelButtons) {
- final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build();
+ final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.builder();
for (String labelButton : labelButtons) {
final SimpleButton simpleButton = SimpleButton.simpleButton(labelButton, "{\"button\": \"" + labelButton + "\"}");
keyBoard.line(SimpleKeyBoardLine.builder().button(simpleButton).build());
@@ -74,7 +74,7 @@ public class KeyBoards {
* @return {@link SimpleKeyBoard}
*/
public static SimpleKeyBoard verticalDuoMenuString(List labelButton) {
- final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build();
+ final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.builder();
boolean flag = true;
SimpleKeyBoardLine.Builder keyBoardLine = SimpleKeyBoardLine.builder();
for (int i = 0; i <= labelButton.size() - 1; i++) {
@@ -102,7 +102,7 @@ public class KeyBoards {
* @return {@link SimpleKeyBoard}
*/
public static SimpleKeyBoard verticalMenuButton(List simpleButtons) {
- final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build();
+ final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.builder();
for (SimpleButton simpleButton : simpleButtons) {
keyBoard.line(SimpleKeyBoardLine.builder().button(simpleButton).build());
}
diff --git a/bot-core/pom.xml b/bot-core/pom.xml
index 2e67d3f..5e4db41 100644
--- a/bot-core/pom.xml
+++ b/bot-core/pom.xml
@@ -6,7 +6,7 @@
dev.struchkov.godfather
godfather-bot
- 0.0.6
+ 0.0.7
bot-core
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 c307260..508f40a 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
@@ -1,16 +1,17 @@
package dev.struchkov.godfather.core;
-import dev.struchkov.autoresponder.AutoResponder;
-import dev.struchkov.autoresponder.entity.UnitPointer;
-import dev.struchkov.autoresponder.repository.UnitPointerRepository;
-import dev.struchkov.autoresponder.service.UnitPointerServiceImpl;
+import dev.struchkov.autoresponder.Responder;
+import dev.struchkov.autoresponder.entity.Unit;
+import dev.struchkov.godfather.context.domain.UnitPointer;
import dev.struchkov.godfather.context.domain.content.Message;
import dev.struchkov.godfather.context.exception.ConfigAppException;
-import dev.struchkov.godfather.context.service.MessageService;
import dev.struchkov.godfather.context.service.Modifiable;
+import dev.struchkov.godfather.context.service.PersonSettingService;
+import dev.struchkov.godfather.context.service.UnitPointerService;
import dev.struchkov.godfather.context.service.sender.Sending;
import dev.struchkov.godfather.core.domain.unit.MainUnit;
import dev.struchkov.godfather.core.domain.unit.UnitActiveType;
+import dev.struchkov.godfather.core.service.Accessibility;
import dev.struchkov.godfather.core.service.action.ActionUnit;
import dev.struchkov.godfather.core.service.action.AnswerCheckAction;
import dev.struchkov.godfather.core.service.action.AnswerProcessingAction;
@@ -27,26 +28,26 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
-import java.util.TimerTask;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.function.Consumer;
+import java.util.stream.Collectors;
-public class GeneralAutoResponder extends TimerTask {
+public class GeneralAutoResponder {
+
+ private final PersonSettingService personSettingService;
+ private final UnitPointerService unitPointerService;
+ private final StoryLine storyLine;
- protected final AutoResponder autoResponder;
- private final MessageService messageService;
protected Map> actionUnitMap = new HashMap<>();
- protected List> modifiables;
- private ExecutorService executorService = Executors.newFixedThreadPool(10);
+ protected List> modifiable;
- protected GeneralAutoResponder(Set menuUnit,
- Sending sending,
- MessageService messageService,
- UnitPointerRepository unitPointerRepository
+ protected GeneralAutoResponder(
+ Sending sending,
+ PersonSettingService personSettingService,
+ UnitPointerService unitPointerService,
+ List