Обновление api

This commit is contained in:
Struchkov Mark 2022-08-02 21:55:45 +03:00
parent d4f6a672ef
commit d2cf3ed645
18 changed files with 84 additions and 468 deletions

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.22</version>
<version>0.0.25</version>
</parent>
<artifactId>bot-context</artifactId>

View File

@ -8,6 +8,7 @@ import dev.struchkov.godfather.context.service.usercode.CheckData;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -41,6 +42,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
private AnswerCheck(Builder<M> builder) {
super(
builder.name,
builder.description,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
@ -75,7 +77,8 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
}
public static final class Builder<M extends Message> {
private String name;
private String name = UUID.randomUUID().toString();
private String description;
private Set<KeyWord> triggerWords;
private Set<String> triggerPhrases;
@ -101,6 +104,11 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
return this;
}
public Builder<M> description(String description) {
this.description = description;
return this;
}
public Builder<M> triggerWords(Set<KeyWord> val) {
if (triggerWords == null) {
triggerWords = new HashSet<>();

View File

@ -12,6 +12,7 @@ import dev.struchkov.godfather.context.service.save.Pusher;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -56,6 +57,7 @@ public class AnswerSave<M extends Message, D> extends MainUnit<M> {
private AnswerSave(Builder<M, D> builder) {
super(
builder.name,
builder.description,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
@ -112,7 +114,8 @@ public class AnswerSave<M extends Message, D> extends MainUnit<M> {
}
public static final class Builder<M extends Message, D> {
private String name;
private String name = UUID.randomUUID().toString();
private String description;
private Set<MainUnit<M>> nextUnits;
private Set<KeyWord> triggerWords;
@ -141,6 +144,11 @@ public class AnswerSave<M extends Message, D> extends MainUnit<M> {
return this;
}
public Builder<M, D> description(String description) {
this.description = description;
return this;
}
public Builder<M, D> triggerWords(Set<KeyWord> val) {
if (checkNull(triggerWords)) {
triggerWords = new HashSet<>();

View File

@ -14,6 +14,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
@ -48,6 +49,7 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
private AnswerText(Builder<M> builder) {
super(
builder.name,
builder.description,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
@ -90,7 +92,8 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
}
public static final class Builder<M extends Message> {
private String name;
private String name = UUID.randomUUID().toString();
private String description;
private Set<MainUnit<M>> nextUnits;
private Set<KeyWord> triggerWords;
@ -117,6 +120,11 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
return this;
}
public Builder<M> description(String description) {
this.description = description;
return this;
}
public Builder<M> processing(Consumer<M> answer) {
this.boxAnswer = message -> {
answer.accept(message);

View File

@ -8,6 +8,7 @@ import dev.struchkov.godfather.context.service.usercode.CheckData;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -45,6 +46,7 @@ public class AnswerTimer<M extends Message> extends MainUnit<M> {
private AnswerTimer(Builder<M> builder) {
super(
builder.name,
builder.description,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
@ -84,7 +86,8 @@ public class AnswerTimer<M extends Message> extends MainUnit<M> {
}
public static final class Builder<M extends Message> {
private String name;
private String name = UUID.randomUUID().toString();
private String description;
private Set<KeyWord> triggerWords;
private Set<String> triggerPhrases;
@ -110,6 +113,11 @@ public class AnswerTimer<M extends Message> extends MainUnit<M> {
return this;
}
public Builder<M> description(String description) {
this.description = description;
return this;
}
public Builder<M> unitAnswer(MainUnit<M> val) {
unitAnswer = val;
return this;

View File

@ -8,7 +8,6 @@ import dev.struchkov.godfather.context.service.Accessibility;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
@ -19,26 +18,26 @@ import java.util.regex.Pattern;
*/
public abstract class MainUnit<M extends Message> extends Unit<MainUnit<M>, M> {
/**
* Уникальное имя юнита
*/
private String name;
/**
* Описание юнита, что он делает. Никак не влияет на работу юнита и не участвует в ней. Возможно отображение этого текста в логах.
*/
private final String description;
/**
* Тип Unit-а.
*/
protected final String type;
/**
* Уникальный идентификатор юнита
*/
private final String uuid = UUID.randomUUID().toString();
/**
* Режим срабатывания Unit-а.
*/
protected UnitActiveType activeType;
/**
* Уникальное имя юнита
*/
private String name;
/**
* Проверка доступа пользователя к юниту.
*/
@ -48,6 +47,7 @@ public abstract class MainUnit<M extends Message> extends Unit<MainUnit<M>, M> {
protected MainUnit(
String name,
String description,
Set<KeyWord> keyWords,
Set<String> phrases,
Predicate<M> triggerCheck,
@ -62,6 +62,7 @@ public abstract class MainUnit<M extends Message> extends Unit<MainUnit<M>, M> {
) {
super(keyWords, phrases, triggerCheck, patterns, matchThreshold, priority, nextUnits);
this.name = name;
this.description = description;
this.activeType = Optional.ofNullable(activeType).orElse(UnitActiveType.DEFAULT);
this.accessibility = accessibility;
this.type = type;
@ -80,10 +81,6 @@ public abstract class MainUnit<M extends Message> extends Unit<MainUnit<M>, M> {
this.activeType = activeType;
}
public String getUuid() {
return uuid;
}
public void setName(String name) {
this.name = name;
}
@ -100,19 +97,21 @@ public abstract class MainUnit<M extends Message> extends Unit<MainUnit<M>, M> {
return Optional.ofNullable(accessibility);
}
//TODO [27.05.2022]: Возможно стоит добавить имя юнита и убрать остальное
public String getDescription() {
return description;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
if (!super.equals(o)) return false;
MainUnit mainUnit = (MainUnit) o;
return Objects.equals(type, mainUnit.type) && activeType == mainUnit.activeType && Objects.equals(uuid, mainUnit.uuid);
MainUnit<?> unit = (MainUnit<?>) o;
return name.equals(unit.name);
}
@Override
public int hashCode() {
return Objects.hash(super.hashCode(), type, activeType, uuid);
return Objects.hash(name);
}
}

View File

@ -9,6 +9,7 @@ import dev.struchkov.haiti.utils.Checker;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -20,6 +21,7 @@ public class ReplaceCmd<M extends Message> extends MainUnit<M> {
private ReplaceCmd(Builder<M> builder) {
super(
builder.name,
builder.description,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
@ -44,7 +46,8 @@ public class ReplaceCmd<M extends Message> extends MainUnit<M> {
}
public static final class Builder<M extends Message> {
private String name;
private String name = UUID.randomUUID().toString();
private String description;
private Set<String> triggerPhrases;
private Predicate<M> triggerCheck;
@ -65,6 +68,11 @@ public class ReplaceCmd<M extends Message> extends MainUnit<M> {
return this;
}
public Builder<M> description(String description) {
this.description = description;
return this;
}
public Builder<M> triggerWords(Set<KeyWord> val) {
if (Checker.checkNull(triggerWords)) {
triggerWords = new HashSet<>();

View File

@ -9,6 +9,7 @@ import dev.struchkov.godfather.context.exception.UnitConfigException;
import java.util.HashSet;
import java.util.Set;
import java.util.UUID;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
@ -33,6 +34,7 @@ public class RollBackCmd<M extends Message> extends MainUnit<M> {
private RollBackCmd(Builder<M> builder) {
super(
builder.name,
builder.description,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
@ -82,7 +84,8 @@ public class RollBackCmd<M extends Message> extends MainUnit<M> {
}
public static final class Builder<M extends Message> {
private String name;
private String name = UUID.randomUUID().toString();
private String description;
private Set<String> triggerPhrases;
private Predicate<M> triggerCheck;
@ -104,6 +107,11 @@ public class RollBackCmd<M extends Message> extends MainUnit<M> {
return this;
}
public Builder<M> description(String description) {
this.description = description;
return this;
}
public Builder<M> triggerWords(Set<KeyWord> val) {
if (checkNull(triggerWords)) {
triggerWords = new HashSet<>();

View File

@ -1,163 +0,0 @@
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.content.Message;
import dev.struchkov.godfather.context.domain.unit.MainUnit;
import dev.struchkov.godfather.context.domain.unit.UnitActiveType;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Predicate;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkNull;
/**
* Позволяет перенести пользователя в произвольное место в сценарии.
*/
public class TeleportCmd<M extends Message> extends MainUnit<M> {
/**
* Название юнита, в которое необходимо осуществить перенос.
*/
private final String unitNameToTeleport;
private TeleportCmd(Builder<M> builder) {
super(
builder.name,
builder.triggerWords,
builder.triggerPhrases,
builder.triggerCheck,
builder.triggerPatterns,
builder.matchThreshold,
builder.priority,
new HashSet<>(),
builder.activeType,
true,
null,
TypeUnit.TELEPORT_CMD
);
this.unitNameToTeleport = builder.unitNameToTeleport;
}
public static <M extends Message> Builder<M> builder() {
return new Builder<>();
}
public String getUnitNameToTeleport() {
return unitNameToTeleport;
}
public static final class Builder<M extends Message> {
private String name;
private Set<KeyWord> triggerWords;
private Set<String> triggerPhrases;
private Set<Pattern> triggerPatterns;
private Predicate<M> triggerCheck;
private Integer matchThreshold;
private Integer priority;
private UnitActiveType activeType = UnitActiveType.DEFAULT;
private String unitNameToTeleport;
private Builder() {
}
public Builder<M> name(String name) {
this.name = name;
return this;
}
public Builder<M> triggerWords(Set<KeyWord> val) {
if (checkNull(triggerWords)) {
triggerWords = new HashSet<>();
}
triggerWords.addAll(val);
return this;
}
public Builder<M> triggerWord(KeyWord val) {
if (checkNull(triggerWords)) {
triggerWords = new HashSet<>();
}
triggerWords.add(val);
return this;
}
public Builder<M> triggerStringWords(Set<String> val) {
if (checkNull(triggerWords)) {
triggerWords = new HashSet<>();
}
triggerWords.addAll(val.stream().map(KeyWord::of).collect(Collectors.toSet()));
return this;
}
public Builder<M> triggerWord(String val) {
if (checkNull(triggerWords)) {
triggerWords = new HashSet<>();
}
triggerWords.add(KeyWord.of(val));
return this;
}
public Builder<M> triggerPhrase(String... val) {
if (checkNull(triggerPhrases)) {
triggerPhrases = new HashSet<>();
}
if (val.length == 1) {
triggerPhrases.add(val[0]);
} else {
triggerPhrases.addAll(Set.of(val));
}
triggerPhrases.addAll(Set.of(val));
return this;
}
public Builder<M> triggerPattern(Pattern... val) {
if (checkNull(triggerPatterns)) {
triggerPatterns = new HashSet<>();
}
if (val.length == 1) {
triggerPatterns.add(val[0]);
} else {
triggerPatterns.addAll(Set.of(val));
}
triggerPatterns.addAll(Set.of(val));
return this;
}
public Builder<M> triggerCheck(Predicate<M> trigger) {
triggerCheck = trigger;
return this;
}
public Builder<M> matchThreshold(Integer val) {
matchThreshold = val;
return this;
}
public Builder<M> priority(Integer val) {
priority = val;
return this;
}
public Builder<M> activeType(UnitActiveType val) {
activeType = val;
return this;
}
public Builder<M> unitNameToTeleport(String val) {
unitNameToTeleport = val;
return this;
}
public TeleportCmd<M> build() {
return new TeleportCmd<>(this);
}
}
}

View File

@ -1,47 +0,0 @@
package dev.struchkov.godfather.context.repository;
import dev.struchkov.godfather.context.domain.content.Message;
import org.jetbrains.annotations.NotNull;
import java.time.LocalDateTime;
import java.util.List;
/**
* Интерфейс взаимодействия со всеми наследниками текстовых запросов пользователей.
*
* @author upagge [08/07/2019]
*/
public interface ContentRepository<T extends Message> {
/**
* Добавить сообщение в хранилище
*
* @param content Объект сообщени
* @return Идентификатор сообщения в хранилище
*/
T add(@NotNull T content);
/**
* Получить все сообщения за определенный временной диапазон
*
* @param dateFrom Начало временного диапазона
* @param dateTo Конец диапазона
* @return Список сообщений
*/
List<T> betweenByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
List<T> betweenByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
/**
* Удаляет данные за указанный период
*
* @param dateFrom Дата начала
* @param dateTo Дата окончания
*/
void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
void deleteAllByAddDateBefore(@NotNull LocalDateTime date);
void deleteAllByAddDateAfter(@NotNull LocalDateTime date);
}

View File

@ -1,76 +0,0 @@
package dev.struchkov.godfather.context.repository.impl.local;
import dev.struchkov.godfather.context.domain.content.Mail;
import dev.struchkov.godfather.context.repository.ContentRepository;
import org.jetbrains.annotations.NotNull;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;
/**
* Локальная реализация репозитория на основе {@link ArrayList} для взаимодействия с сущностью {@link Mail}.
*
* @author upagge [27/07/2019]
*/
public class MailRepositoryList implements ContentRepository<Mail> {
private final List<Mail> mails = new ArrayList<>();
private Long count = 0L;
@Override
public Mail add(Mail mail) {
mail.setId(count++);
mails.add(mail);
return mail;
}
@Override
public List<Mail> betweenByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
ArrayList<Mail> rezultMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) {
Mail mail = mails.get(i);
if (isTimePeriod(dateFrom, dateTo, mail.getAddDate())) {
rezultMails.add(mail);
} else if (mail.getCreateDate().isBefore(dateFrom)) {
break;
}
}
return rezultMails;
}
@Override
public List<Mail> betweenByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
ArrayList<Mail> rezultMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) {
Mail mail = mails.get(i);
LocalDateTime addDate = mail.getAddDate();
if (isTimePeriod(dateFrom, dateTo, addDate)) {
rezultMails.add(mail);
} else if (addDate.isBefore(dateFrom)) {
break;
}
}
return rezultMails;
}
@Override
public void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
mails.removeIf(mail -> dateFrom.isBefore(mail.getAddDate()) && dateTo.isAfter(mail.getAddDate()));
}
@Override
public void deleteAllByAddDateBefore(@NotNull LocalDateTime date) {
mails.removeIf(mail -> date.isBefore(mail.getAddDate()));
}
@Override
public void deleteAllByAddDateAfter(@NotNull LocalDateTime date) {
mails.removeIf(mail -> date.isAfter(mail.getAddDate()));
}
private boolean isTimePeriod(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo, @NotNull LocalDateTime dateTime) {
return dateFrom.isBefore(dateTime) && dateTo.isAfter(dateTime);
}
}

View File

@ -25,7 +25,7 @@ public interface StorylineService<M extends Message> {
Optional<MainUnit<M>> getDefaultUnit();
/**
* Ленивая (поздняя) связка юнитов между собой. Осуществляется уже после создания сценария. С помощью данного подхода можно реализовать циклические зависимости юнитов. Либо можно использовать {@link dev.struchkov.godfather.context.domain.unit.cmd.TeleportCmd}
* Ленивая (поздняя) связка юнитов между собой. Осуществляется уже после создания сценария. С помощью данного подхода можно реализовать циклические зависимости юнитов.
*/
void lazyLink(String firstName, String secondName);

View File

@ -1,113 +0,0 @@
package dev.struchkov.godfather.context.service.impl;
import dev.struchkov.godfather.context.domain.content.Mail;
import dev.struchkov.godfather.context.repository.ContentRepository;
import dev.struchkov.godfather.context.service.MailService;
import org.jetbrains.annotations.NotNull;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.time.Clock;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class MailServiceImpl implements MailService {
private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class);
private final ContentRepository<Mail> mailRepository;
private boolean newMessage = false;
private LocalDateTime oldDateTime = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault()));
public MailServiceImpl(ContentRepository<Mail> mailRepository) {
this.mailRepository = mailRepository;
}
//TODO [13.04.2022]: Подобная реализация с newMessage вызовет проблемы с несколькими инстансами.
@Override
public void add(Mail mail) {
mailRepository.add(mail);
newMessage = true;
log.trace("Сообщение добавлено в репозиторий | {}", mail);
}
@Override
public List<Mail> getByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.trace("Запрошены все сообщения {} - {} ", timeFrom, timeTo);
return mailRepository.betweenByAddDateTime(timeFrom, timeTo);
}
@Override
public List<Mail> getLastEventByCreateDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
final List<Mail> mails = mailRepository.betweenByCreateDateTime(timeFrom, timeTo);
if (mails != null && !mails.isEmpty()) {
return findLastMailEachUser(mails);
} else {
return Collections.emptyList();
}
}
@Override
public List<Mail> getLastEventByAddDateTime(LocalDateTime timeFrom, LocalDateTime timeTo) {
log.trace("Запрошены последние сообщения {} - {} ", timeFrom, timeTo);
final List<Mail> mails = mailRepository.betweenByAddDateTime(timeFrom, timeTo);
if (mails != null && !mails.isEmpty()) {
return findLastMailEachUser(mails);
} else {
return Collections.emptyList();
}
}
@Override
public List<Mail> getNewMessage() {
final LocalDateTime newData = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())).plusNanos(999999999);
if (newMessage) {
final List<Mail> lastEventByAddDateTime = getLastEventByAddDateTime(oldDateTime, newData);
newMessage = false;
oldDateTime = newData;
return lastEventByAddDateTime;
}
return Collections.emptyList();
}
@Override
public void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
mailRepository.deleteAllByAddDateBetween(dateFrom, dateTo);
}
@Override
public void deleteAllByAddDateBefore(@NotNull LocalDateTime date) {
mailRepository.deleteAllByAddDateBefore(date);
}
@Override
public void deleteAllByAddDateAfter(@NotNull LocalDateTime date) {
mailRepository.deleteAllByAddDateAfter(date);
}
/**
* Возвращает только последнее сообщение каждого пользователя переданного из списка.
*/
private List<Mail> findLastMailEachUser(List<Mail> mails) {
final Set<Long> people = new HashSet<>();
final List<Mail> returnMails = new ArrayList<>();
for (int i = mails.size() - 1; i >= 0; i--) {
if (!people.contains(mails.get(i).getPersonId())) {
returnMails.add(mails.get(i));
people.add(mails.get(i).getPersonId());
}
}
if (!returnMails.isEmpty()) {
return returnMails;
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,7 +6,7 @@
<parent>
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.22</version>
<version>0.0.25</version>
</parent>
<artifactId>bot-core</artifactId>

View File

@ -23,9 +23,9 @@ import java.util.stream.Collectors;
import static dev.struchkov.godfather.context.exception.UnitConfigException.unitConfigException;
public class StorylineMaker<M extends Message> {
public class StorylineFactory<M extends Message> {
private static final Logger log = LoggerFactory.getLogger(StorylineMaker.class);
private static final Logger log = LoggerFactory.getLogger(StorylineFactory.class);
private final List<Object> configurations = new ArrayList<>();
@ -35,7 +35,7 @@ public class StorylineMaker<M extends Message> {
private final Set<String> mainUnits = new HashSet<>();
private final Set<String> globalUnits = new HashSet<>();
public StorylineMaker(List<Object> unitConfigurations) {
public StorylineFactory(List<Object> unitConfigurations) {
this.configurations.addAll(unitConfigurations);
}

View File

@ -9,7 +9,7 @@ import dev.struchkov.godfather.context.repository.StorylineRepository;
import dev.struchkov.godfather.context.service.StorylineService;
import dev.struchkov.godfather.context.service.UnitPointerService;
import dev.struchkov.godfather.core.Storyline;
import dev.struchkov.godfather.core.StorylineMaker;
import dev.struchkov.godfather.core.StorylineFactory;
import dev.struchkov.haiti.utils.Inspector;
import org.jetbrains.annotations.NotNull;
@ -34,7 +34,7 @@ public class StorylineMailService implements StorylineService<Mail> {
StorylineRepository storylineRepository,
List<Object> unitConfigurations
) {
this.storyLine = new StorylineMaker<Mail>(unitConfigurations).createStoryLine();
this.storyLine = new StorylineFactory<Mail>(unitConfigurations).createStoryLine();
this.unitPointerService = unitPointerService;
this.storylineRepository = storylineRepository;
}

View File

@ -1,32 +0,0 @@
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.TeleportCmd;
import dev.struchkov.godfather.context.service.StorylineService;
import dev.struchkov.godfather.core.service.action.ActionUnit;
import java.util.Optional;
public class TeleportCmdAction<M extends Message> implements ActionUnit<TeleportCmd<M>, M> {
private final StorylineService<M> storyLineService;
public TeleportCmdAction(StorylineService<M> storyLineService) {
this.storyLineService = storyLineService;
}
@Override
public UnitRequest<MainUnit, M> action(UnitRequest<TeleportCmd<M>, M> unitRequest) {
final TeleportCmd<M> unit = unitRequest.getUnit();
final M message = unitRequest.getMessage();
final Optional<MainUnit<M>> optNextUnit = storyLineService.getUnitByName(unit.getUnitNameToTeleport());
if (optNextUnit.isPresent()) {
return UnitRequest.of(optNextUnit.get(), message);
} else {
return UnitRequest.of(unit, message);
}
}
}

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId>
<version>0.0.22</version>
<version>0.0.25</version>
<packaging>pom</packaging>
<modules>
@ -35,8 +35,8 @@
<godfather.context.ver>${project.version}</godfather.context.ver>
<godfather.core.ver>${project.version}</godfather.core.ver>
<autoresponder.ver>3.4.0</autoresponder.ver>
<haiti.utils>1.3.0</haiti.utils>
<autoresponder.ver>3.5.0</autoresponder.ver>
<haiti.utils>1.4.0</haiti.utils>
<javax.persistence.api.ver>2.2</javax.persistence.api.ver>
<validation.api.ver>2.0.1.Final</validation.api.ver>