diff --git a/bot-context/pom.xml b/bot-context/pom.xml new file mode 100644 index 0000000..12253a4 --- /dev/null +++ b/bot-context/pom.xml @@ -0,0 +1,53 @@ + + + + dev.struchkov.godfather + godfather-bot + 0.0.1-SNAPSHOT + + 4.0.0 + + bot-context + + + + org.apache.maven.plugins + maven-compiler-plugin + + 16 + 16 + + + + + + + + com.google.code.gson + gson + + + javax.mail + javax.mail-api + + + org.projectlombok + lombok + + + org.springframework.data + spring-data-jpa + + + javax.persistence + javax.persistence-api + + + javax.validation + validation-api + + + + \ No newline at end of file diff --git a/src/main/java/org/sadtech/social/core/domain/BasicEntity.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java similarity index 89% rename from src/main/java/org/sadtech/social/core/domain/BasicEntity.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java index 1632fce..276e4a6 100644 --- a/src/main/java/org/sadtech/social/core/domain/BasicEntity.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BasicEntity.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain; +package dev.struchkov.godfather.context.domain; import lombok.Data; import lombok.ToString; diff --git a/src/main/java/org/sadtech/social/core/domain/BoxAnswer.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java similarity index 79% rename from src/main/java/org/sadtech/social/core/domain/BoxAnswer.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java index c5fc72e..3baddef 100644 --- a/src/main/java/org/sadtech/social/core/domain/BoxAnswer.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/BoxAnswer.java @@ -1,13 +1,13 @@ -package org.sadtech.social.core.domain; +package dev.struchkov.godfather.context.domain; +import dev.struchkov.godfather.context.domain.content.attachment.GeoCoordinate; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; +import dev.struchkov.godfather.context.utils.Description; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import org.sadtech.social.core.domain.content.attachment.GeoCoordinate; -import org.sadtech.social.core.domain.keyboard.KeyBoard; -import org.sadtech.social.core.utils.Description; /** * Контейнер, которые содержит данные, которые будут отправлены пользователю как ответ на его запрос. diff --git a/src/main/java/org/sadtech/social/core/domain/content/BoardComment.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java similarity index 83% rename from src/main/java/org/sadtech/social/core/domain/content/BoardComment.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java index 7a94bbd..6d34d7b 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/BoardComment.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/BoardComment.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain.content; +package dev.struchkov.godfather.context.domain.content; /** * Сообщение от пользователя типа "Комментарий к обсуждению группы". diff --git a/src/main/java/org/sadtech/social/core/domain/content/Comment.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java similarity index 83% rename from src/main/java/org/sadtech/social/core/domain/content/Comment.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java index e614b63..20f8c13 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Comment.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Comment.java @@ -1,9 +1,9 @@ -package org.sadtech.social.core.domain.content; +package dev.struchkov.godfather.context.domain.content; +import dev.struchkov.godfather.context.utils.Description; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; -import org.sadtech.social.core.utils.Description; /** * Абстрактная сущность для сообщений от пользователей с привязкой к какому-то контенту (картинка, видео). diff --git a/src/main/java/org/sadtech/social/core/domain/content/ContentType.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/ContentType.java similarity index 77% rename from src/main/java/org/sadtech/social/core/domain/content/ContentType.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/ContentType.java index 4c14165..0f304b5 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/ContentType.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/ContentType.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain.content; +package dev.struchkov.godfather.context.domain.content; /** * Тип сообщения от пользователя {@link Message}. diff --git a/src/main/java/org/sadtech/social/core/domain/content/EmptyMessage.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java similarity index 79% rename from src/main/java/org/sadtech/social/core/domain/content/EmptyMessage.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java index d00c8fa..5aa597e 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/EmptyMessage.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/EmptyMessage.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.domain.content; +package dev.struchkov.godfather.context.domain.content; +import dev.struchkov.godfather.context.exception.AppBotException; import lombok.ToString; -import org.sadtech.social.core.exception.AppBotException; /** * Заглушка для сообщения от пользователя. diff --git a/src/main/java/org/sadtech/social/core/domain/content/Mail.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java similarity index 83% rename from src/main/java/org/sadtech/social/core/domain/content/Mail.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java index 64dd705..527a763 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Mail.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Mail.java @@ -1,10 +1,10 @@ -package org.sadtech.social.core.domain.content; +package dev.struchkov.godfather.context.domain.content; +import dev.struchkov.godfather.context.domain.content.attachment.Attachment; +import dev.struchkov.godfather.context.utils.Description; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.ToString; -import org.sadtech.social.core.domain.content.attachment.Attachment; -import org.sadtech.social.core.utils.Description; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/org/sadtech/social/core/domain/content/Message.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java similarity index 89% rename from src/main/java/org/sadtech/social/core/domain/content/Message.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java index 012b6d8..a3187de 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/Message.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/Message.java @@ -1,9 +1,9 @@ -package org.sadtech.social.core.domain.content; +package dev.struchkov.godfather.context.domain.content; import lombok.Data; import lombok.EqualsAndHashCode; -import org.sadtech.social.core.domain.BasicEntity; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.domain.BasicEntity; +import dev.struchkov.godfather.context.utils.Description; import javax.persistence.Column; import javax.persistence.EnumType; diff --git a/src/main/java/org/sadtech/social/core/domain/content/attachment/Attachment.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java similarity index 85% rename from src/main/java/org/sadtech/social/core/domain/content/attachment/Attachment.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java index e2c2666..e1b6726 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/attachment/Attachment.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Attachment.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.domain.content.attachment; +package dev.struchkov.godfather.context.domain.content.attachment; import lombok.EqualsAndHashCode; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/org/sadtech/social/core/domain/content/attachment/AttachmentType.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AttachmentType.java similarity index 71% rename from src/main/java/org/sadtech/social/core/domain/content/attachment/AttachmentType.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AttachmentType.java index d4f31aa..35e20f2 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/attachment/AttachmentType.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AttachmentType.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain.content.attachment; +package dev.struchkov.godfather.context.domain.content.attachment; /** * Тип вложения {@link Attachment} к сообщению. diff --git a/src/main/java/org/sadtech/social/core/domain/content/attachment/AudioMessage.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java similarity index 80% rename from src/main/java/org/sadtech/social/core/domain/content/attachment/AudioMessage.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java index a2c3f18..4c5d158 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/attachment/AudioMessage.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/AudioMessage.java @@ -1,10 +1,10 @@ -package org.sadtech.social.core.domain.content.attachment; +package dev.struchkov.godfather.context.domain.content.attachment; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Setter; import lombok.ToString; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; import java.net.URL; diff --git a/src/main/java/org/sadtech/social/core/domain/content/attachment/Geo.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java similarity index 90% rename from src/main/java/org/sadtech/social/core/domain/content/attachment/Geo.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java index 10af5c5..236442f 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/attachment/Geo.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/Geo.java @@ -1,9 +1,9 @@ -package org.sadtech.social.core.domain.content.attachment; +package dev.struchkov.godfather.context.domain.content.attachment; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; /** * Вложение типа "Карта". diff --git a/src/main/java/org/sadtech/social/core/domain/content/attachment/GeoCoordinate.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java similarity index 75% rename from src/main/java/org/sadtech/social/core/domain/content/attachment/GeoCoordinate.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java index 9c1c3b5..e31e16a 100644 --- a/src/main/java/org/sadtech/social/core/domain/content/attachment/GeoCoordinate.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/content/attachment/GeoCoordinate.java @@ -1,8 +1,8 @@ -package org.sadtech.social.core.domain.content.attachment; +package dev.struchkov.godfather.context.domain.content.attachment; import lombok.AllArgsConstructor; import lombok.Data; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; /** * Сущность для хранения географических координат. diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/ButtonColor.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java similarity index 77% rename from src/main/java/org/sadtech/social/core/domain/keyboard/ButtonColor.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java index 80916c9..8b91c78 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/ButtonColor.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonColor.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain.keyboard; +package dev.struchkov.godfather.context.domain.keyboard; /** * Цвета кнопок на клавиатуре {@link KeyBoard}. diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/ButtonType.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java similarity index 73% rename from src/main/java/org/sadtech/social/core/domain/keyboard/ButtonType.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java index ef8e844..1cd0846 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/ButtonType.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/ButtonType.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain.keyboard; +package dev.struchkov.godfather.context.domain.keyboard; /** * Тип кнопки на клавиатуре {@link KeyBoard}. diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoard.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java similarity index 85% rename from src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoard.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java index 372be57..8315667 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoard.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoard.java @@ -1,11 +1,11 @@ -package org.sadtech.social.core.domain.keyboard; +package dev.struchkov.godfather.context.domain.keyboard; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Singular; import lombok.ToString; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoardButton.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java similarity index 83% rename from src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoardButton.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java index d554588..b9c6f9a 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoardButton.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardButton.java @@ -1,11 +1,11 @@ -package org.sadtech.social.core.domain.keyboard; +package dev.struchkov.godfather.context.domain.keyboard; import lombok.AccessLevel; import lombok.AllArgsConstructor; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; /** * Абстрактная сущность кнопки для клавиатуры. diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoardLine.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java similarity index 82% rename from src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoardLine.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java index 85677fe..1db2f70 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/KeyBoardLine.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/KeyBoardLine.java @@ -1,11 +1,11 @@ -package org.sadtech.social.core.domain.keyboard; +package dev.struchkov.godfather.context.domain.keyboard; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.Singular; import lombok.ToString; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.utils.Description; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonAccount.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java similarity index 76% rename from src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonAccount.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java index 221ea0a..40b861b 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonAccount.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonAccount.java @@ -1,12 +1,12 @@ -package org.sadtech.social.core.domain.keyboard.button; +package dev.struchkov.godfather.context.domain.keyboard.button; +import dev.struchkov.godfather.context.domain.keyboard.ButtonType; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; -import org.sadtech.social.core.domain.keyboard.ButtonType; -import org.sadtech.social.core.domain.keyboard.KeyBoardButton; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; +import dev.struchkov.godfather.context.utils.Description; /** * Кнопка клавиатуры для оплаты счета. diff --git a/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java similarity index 69% rename from src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java index 428cb3a..18ca140 100644 --- a/src/main/java/org/sadtech/social/core/domain/keyboard/button/KeyBoardButtonText.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/keyboard/button/KeyBoardButtonText.java @@ -1,13 +1,13 @@ -package org.sadtech.social.core.domain.keyboard.button; +package dev.struchkov.godfather.context.domain.keyboard.button; import lombok.Builder; import lombok.EqualsAndHashCode; import lombok.Getter; import lombok.ToString; -import org.sadtech.social.core.domain.keyboard.ButtonColor; -import org.sadtech.social.core.domain.keyboard.ButtonType; -import org.sadtech.social.core.domain.keyboard.KeyBoardButton; -import org.sadtech.social.core.utils.Description; +import dev.struchkov.godfather.context.domain.keyboard.ButtonColor; +import dev.struchkov.godfather.context.domain.keyboard.ButtonType; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; +import dev.struchkov.godfather.context.utils.Description; @Getter @ToString diff --git a/src/main/java/org/sadtech/social/core/domain/money/Account.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java similarity index 93% rename from src/main/java/org/sadtech/social/core/domain/money/Account.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java index 62d8b40..52e92d9 100644 --- a/src/main/java/org/sadtech/social/core/domain/money/Account.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/Account.java @@ -1,10 +1,10 @@ -package org.sadtech.social.core.domain.money; +package dev.struchkov.godfather.context.domain.money; +import dev.struchkov.godfather.context.utils.Description; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; -import org.sadtech.social.core.utils.Description; import javax.persistence.Column; import javax.persistence.Entity; diff --git a/src/main/java/org/sadtech/social/core/domain/money/AccountStatus.java b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java similarity index 75% rename from src/main/java/org/sadtech/social/core/domain/money/AccountStatus.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java index 90ba094..1f654f3 100644 --- a/src/main/java/org/sadtech/social/core/domain/money/AccountStatus.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/domain/money/AccountStatus.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.domain.money; +package dev.struchkov.godfather.context.domain.money; /** * Состояние счета. diff --git a/src/main/java/org/sadtech/social/core/exception/AccessException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/AccessException.java similarity index 81% rename from src/main/java/org/sadtech/social/core/exception/AccessException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/AccessException.java index 16f1515..f89587c 100644 --- a/src/main/java/org/sadtech/social/core/exception/AccessException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/AccessException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; /** * Ошибка доступа к чему-либо. diff --git a/src/main/java/org/sadtech/social/core/exception/AppBotException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/AppBotException.java similarity index 91% rename from src/main/java/org/sadtech/social/core/exception/AppBotException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/AppBotException.java index 93d04ba..f5ac30b 100644 --- a/src/main/java/org/sadtech/social/core/exception/AppBotException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/AppBotException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; import java.time.LocalDateTime; diff --git a/src/main/java/org/sadtech/social/core/exception/ConfigAppException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/ConfigAppException.java similarity index 82% rename from src/main/java/org/sadtech/social/core/exception/ConfigAppException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/ConfigAppException.java index bdd2cca..cb31393 100644 --- a/src/main/java/org/sadtech/social/core/exception/ConfigAppException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/ConfigAppException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; /** * Исключения настройки бота. diff --git a/src/main/java/org/sadtech/social/core/exception/MailSendException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/MailSendException.java similarity index 84% rename from src/main/java/org/sadtech/social/core/exception/MailSendException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/MailSendException.java index 93cc175..067a553 100644 --- a/src/main/java/org/sadtech/social/core/exception/MailSendException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/MailSendException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; /** * Ошибки при отправке сообщений. diff --git a/src/main/java/org/sadtech/social/core/exception/NotFoundException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java similarity index 82% rename from src/main/java/org/sadtech/social/core/exception/NotFoundException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java index a80b38c..a5b9b49 100644 --- a/src/main/java/org/sadtech/social/core/exception/NotFoundException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/NotFoundException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; /** * Ошибка, когда что-то не найдено. diff --git a/src/main/java/org/sadtech/social/core/exception/PaymentException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/PaymentException.java similarity index 80% rename from src/main/java/org/sadtech/social/core/exception/PaymentException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/PaymentException.java index 5e0ba0a..2d65297 100644 --- a/src/main/java/org/sadtech/social/core/exception/PaymentException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/PaymentException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; /** * Ошибка оплаты. diff --git a/src/main/java/org/sadtech/social/core/exception/TimerSettingException.java b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/TimerSettingException.java similarity index 81% rename from src/main/java/org/sadtech/social/core/exception/TimerSettingException.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/exception/TimerSettingException.java index acdf137..ab30bdd 100644 --- a/src/main/java/org/sadtech/social/core/exception/TimerSettingException.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/exception/TimerSettingException.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.exception; +package dev.struchkov.godfather.context.exception; /** * Ошибка таймера. diff --git a/src/main/java/org/sadtech/social/core/repository/AccountRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java similarity index 77% rename from src/main/java/org/sadtech/social/core/repository/AccountRepository.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java index 7da2cc9..72306c6 100644 --- a/src/main/java/org/sadtech/social/core/repository/AccountRepository.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/AccountRepository.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.repository; +package dev.struchkov.godfather.context.repository; import lombok.NonNull; -import org.sadtech.social.core.domain.money.Account; +import dev.struchkov.godfather.context.domain.money.Account; import java.util.Optional; diff --git a/src/main/java/org/sadtech/social/core/repository/ContentRepository.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java similarity index 93% rename from src/main/java/org/sadtech/social/core/repository/ContentRepository.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java index c8fc79e..5215f90 100644 --- a/src/main/java/org/sadtech/social/core/repository/ContentRepository.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/ContentRepository.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.repository; +package dev.struchkov.godfather.context.repository; import lombok.NonNull; -import org.sadtech.social.core.domain.content.Message; +import dev.struchkov.godfather.context.domain.content.Message; import java.time.LocalDateTime; import java.util.List; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/jpa/AccountRepositoryJpaImpl.java similarity index 71% rename from src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/jpa/AccountRepositoryJpaImpl.java index 1cae137..926d5cc 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/jpa/AccountRepositoryJpaImpl.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/jpa/AccountRepositoryJpaImpl.java @@ -1,10 +1,10 @@ -package org.sadtech.social.core.repository.impl.jpa; +package dev.struchkov.godfather.context.repository.impl.jpa; +import dev.struchkov.godfather.context.repository.AccountRepository; +import dev.struchkov.godfather.context.repository.jpa.AccountRepositoryJpa; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.social.core.domain.money.Account; -import org.sadtech.social.core.repository.AccountRepository; -import org.sadtech.social.core.repository.jpa.AccountRepositoryJpa; +import dev.struchkov.godfather.context.domain.money.Account; import java.util.Optional; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/jpa/MailRepositoryJpaImpl.java similarity index 84% rename from src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/jpa/MailRepositoryJpaImpl.java index 6accaa1..690b936 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/jpa/MailRepositoryJpaImpl.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/jpa/MailRepositoryJpaImpl.java @@ -1,10 +1,10 @@ -package org.sadtech.social.core.repository.impl.jpa; +package dev.struchkov.godfather.context.repository.impl.jpa; +import dev.struchkov.godfather.context.repository.ContentRepository; +import dev.struchkov.godfather.context.repository.jpa.MailRepositoryJpa; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.social.core.domain.content.Mail; -import org.sadtech.social.core.repository.ContentRepository; -import org.sadtech.social.core.repository.jpa.MailRepositoryJpa; +import dev.struchkov.godfather.context.domain.content.Mail; import java.time.LocalDateTime; import java.util.List; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/local/AccountRepositoryMap.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java similarity index 79% rename from src/main/java/org/sadtech/social/core/repository/impl/local/AccountRepositoryMap.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java index 3cabae2..1c1c41f 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/local/AccountRepositoryMap.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/AccountRepositoryMap.java @@ -1,8 +1,8 @@ -package org.sadtech.social.core.repository.impl.local; +package dev.struchkov.godfather.context.repository.impl.local; +import dev.struchkov.godfather.context.repository.AccountRepository; import lombok.NonNull; -import org.sadtech.social.core.domain.money.Account; -import org.sadtech.social.core.repository.AccountRepository; +import dev.struchkov.godfather.context.domain.money.Account; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java similarity index 92% rename from src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java index 7708411..c77df88 100644 --- a/src/main/java/org/sadtech/social/core/repository/impl/local/MailRepositoryList.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/impl/local/MailRepositoryList.java @@ -1,9 +1,9 @@ -package org.sadtech.social.core.repository.impl.local; +package dev.struchkov.godfather.context.repository.impl.local; +import dev.struchkov.godfather.context.repository.ContentRepository; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; -import org.sadtech.social.core.domain.content.Mail; -import org.sadtech.social.core.repository.ContentRepository; +import dev.struchkov.godfather.context.domain.content.Mail; import java.time.LocalDateTime; import java.util.ArrayList; diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/jpa/AccountRepositoryJpa.java similarity index 67% rename from src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/jpa/AccountRepositoryJpa.java index 919ea31..08707c1 100644 --- a/src/main/java/org/sadtech/social/core/repository/jpa/AccountRepositoryJpa.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/jpa/AccountRepositoryJpa.java @@ -1,6 +1,6 @@ -package org.sadtech.social.core.repository.jpa; +package dev.struchkov.godfather.context.repository.jpa; -import org.sadtech.social.core.domain.money.Account; +import dev.struchkov.godfather.context.domain.money.Account; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/jpa/MailRepositoryJpa.java similarity index 81% rename from src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/repository/jpa/MailRepositoryJpa.java index d7ee062..9907f58 100644 --- a/src/main/java/org/sadtech/social/core/repository/jpa/MailRepositoryJpa.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/repository/jpa/MailRepositoryJpa.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.repository.jpa; +package dev.struchkov.godfather.context.repository.jpa; -import org.sadtech.social.core.domain.content.Mail; -import org.sadtech.social.core.repository.impl.jpa.MailRepositoryJpaImpl; +import dev.struchkov.godfather.context.domain.content.Mail; +import dev.struchkov.godfather.context.repository.impl.jpa.MailRepositoryJpaImpl; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; diff --git a/src/main/java/org/sadtech/social/core/service/AccountService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java similarity index 89% rename from src/main/java/org/sadtech/social/core/service/AccountService.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java index f840405..a9f5367 100644 --- a/src/main/java/org/sadtech/social/core/service/AccountService.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/AccountService.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.service; +package dev.struchkov.godfather.context.service; import lombok.NonNull; -import org.sadtech.social.core.domain.money.Account; +import dev.struchkov.godfather.context.domain.money.Account; /** * Интерфейс сервиса по работе с оплатой. diff --git a/src/main/java/org/sadtech/social/core/service/MailService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/MailService.java similarity index 65% rename from src/main/java/org/sadtech/social/core/service/MailService.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/MailService.java index 003b120..4fe5f5f 100644 --- a/src/main/java/org/sadtech/social/core/service/MailService.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/MailService.java @@ -1,6 +1,6 @@ -package org.sadtech.social.core.service; +package dev.struchkov.godfather.context.service; -import org.sadtech.social.core.domain.content.Mail; +import dev.struchkov.godfather.context.domain.content.Mail; /** * Интерфейс для взаимодействия с личными сообщениями. diff --git a/src/main/java/org/sadtech/social/core/service/MessageService.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java similarity index 93% rename from src/main/java/org/sadtech/social/core/service/MessageService.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java index a0644dd..f37a647 100644 --- a/src/main/java/org/sadtech/social/core/service/MessageService.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/MessageService.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.service; +package dev.struchkov.godfather.context.service; import lombok.NonNull; -import org.sadtech.social.core.domain.content.Message; +import dev.struchkov.godfather.context.domain.content.Message; import java.time.LocalDateTime; import java.util.List; diff --git a/src/main/java/org/sadtech/social/core/service/Modifiable.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java similarity index 81% rename from src/main/java/org/sadtech/social/core/service/Modifiable.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java index dc52b10..c2a696e 100644 --- a/src/main/java/org/sadtech/social/core/service/Modifiable.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/Modifiable.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.service; +package dev.struchkov.godfather.context.service; import lombok.NonNull; -import org.sadtech.social.core.domain.content.Message; +import dev.struchkov.godfather.context.domain.content.Message; /** * Интерфес для изменения запроса пользователя перед тем, как он попадет в подсистему обработки. diff --git a/src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java similarity index 80% rename from src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java index c291aae..2082653 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/AccountServiceImpl.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/AccountServiceImpl.java @@ -1,14 +1,14 @@ -package org.sadtech.social.core.service.impl; +package dev.struchkov.godfather.context.service.impl; +import dev.struchkov.godfather.context.exception.AccessException; +import dev.struchkov.godfather.context.exception.NotFoundException; +import dev.struchkov.godfather.context.repository.AccountRepository; +import dev.struchkov.godfather.context.service.AccountService; import lombok.NonNull; import lombok.RequiredArgsConstructor; -import org.sadtech.social.core.domain.money.Account; -import org.sadtech.social.core.domain.money.AccountStatus; -import org.sadtech.social.core.exception.AccessException; -import org.sadtech.social.core.exception.NotFoundException; -import org.sadtech.social.core.exception.PaymentException; -import org.sadtech.social.core.repository.AccountRepository; -import org.sadtech.social.core.service.AccountService; +import dev.struchkov.godfather.context.domain.money.Account; +import dev.struchkov.godfather.context.domain.money.AccountStatus; +import dev.struchkov.godfather.context.exception.PaymentException; @RequiredArgsConstructor public class AccountServiceImpl implements AccountService { diff --git a/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java similarity index 93% rename from src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java index 4cd5bf1..bd1a504 100644 --- a/src/main/java/org/sadtech/social/core/service/impl/MailServiceImpl.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/impl/MailServiceImpl.java @@ -1,11 +1,11 @@ -package org.sadtech.social.core.service.impl; +package dev.struchkov.godfather.context.service.impl; +import dev.struchkov.godfather.context.repository.ContentRepository; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.sadtech.social.core.domain.content.Mail; -import org.sadtech.social.core.repository.ContentRepository; -import org.sadtech.social.core.service.MailService; +import dev.struchkov.godfather.context.domain.content.Mail; +import dev.struchkov.godfather.context.service.MailService; import java.time.Clock; import java.time.LocalDateTime; diff --git a/src/main/java/org/sadtech/social/core/service/sender/SendType.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/SendType.java similarity index 76% rename from src/main/java/org/sadtech/social/core/service/sender/SendType.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/SendType.java index b2c6ceb..405a7d5 100644 --- a/src/main/java/org/sadtech/social/core/service/sender/SendType.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/SendType.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.service.sender; +package dev.struchkov.godfather.context.service.sender; /** * Тип объекта отправляющего ответы пользователю. diff --git a/src/main/java/org/sadtech/social/core/service/sender/Sending.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java similarity index 88% rename from src/main/java/org/sadtech/social/core/service/sender/Sending.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java index a3a7501..d21bf15 100644 --- a/src/main/java/org/sadtech/social/core/service/sender/Sending.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/Sending.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.service.sender; +package dev.struchkov.godfather.context.service.sender; import lombok.NonNull; -import org.sadtech.social.core.domain.BoxAnswer; +import dev.struchkov.godfather.context.domain.BoxAnswer; /** * Интерфейс для отправки ответов пользователю. diff --git a/src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java similarity index 96% rename from src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java index 6793b38..5bcdd5e 100644 --- a/src/main/java/org/sadtech/social/core/service/sender/email/EmailConfig.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailConfig.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.service.sender.email; +package dev.struchkov.godfather.context.service.sender.email; import lombok.Getter; diff --git a/src/main/java/org/sadtech/social/core/service/sender/email/EmailSending.java b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java similarity index 84% rename from src/main/java/org/sadtech/social/core/service/sender/email/EmailSending.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java index 94c2bc0..a6b0a7b 100644 --- a/src/main/java/org/sadtech/social/core/service/sender/email/EmailSending.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/service/sender/email/EmailSending.java @@ -1,12 +1,12 @@ -package org.sadtech.social.core.service.sender.email; +package dev.struchkov.godfather.context.service.sender.email; +import dev.struchkov.godfather.context.exception.MailSendException; +import dev.struchkov.godfather.context.service.sender.SendType; +import dev.struchkov.godfather.context.service.sender.Sending; import lombok.NonNull; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; -import org.sadtech.social.core.domain.BoxAnswer; -import org.sadtech.social.core.exception.MailSendException; -import org.sadtech.social.core.service.sender.SendType; -import org.sadtech.social.core.service.sender.Sending; +import dev.struchkov.godfather.context.domain.BoxAnswer; import javax.mail.Authenticator; import javax.mail.Message; diff --git a/src/main/java/org/sadtech/social/core/utils/Description.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Description.java similarity index 90% rename from src/main/java/org/sadtech/social/core/utils/Description.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/Description.java index 7a2a706..98db99e 100644 --- a/src/main/java/org/sadtech/social/core/utils/Description.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Description.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.utils; +package dev.struchkov.godfather.context.utils; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/org/sadtech/social/core/utils/InsertWords.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java similarity index 96% rename from src/main/java/org/sadtech/social/core/utils/InsertWords.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java index 5b9ad77..136ec10 100644 --- a/src/main/java/org/sadtech/social/core/utils/InsertWords.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/InsertWords.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.utils; +package dev.struchkov.godfather.context.utils; import lombok.NonNull; diff --git a/src/main/java/org/sadtech/social/core/utils/KeyBoards.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java similarity index 92% rename from src/main/java/org/sadtech/social/core/utils/KeyBoards.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java index e5878f7..f083de0 100644 --- a/src/main/java/org/sadtech/social/core/utils/KeyBoards.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/KeyBoards.java @@ -1,10 +1,10 @@ -package org.sadtech.social.core.utils; +package dev.struchkov.godfather.context.utils; -import org.sadtech.social.core.domain.keyboard.ButtonColor; -import org.sadtech.social.core.domain.keyboard.KeyBoard; -import org.sadtech.social.core.domain.keyboard.KeyBoardButton; -import org.sadtech.social.core.domain.keyboard.KeyBoardLine; -import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText; +import dev.struchkov.godfather.context.domain.keyboard.ButtonColor; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoard; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton; +import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; +import dev.struchkov.godfather.context.domain.keyboard.button.KeyBoardButtonText; import java.util.Arrays; import java.util.List; diff --git a/src/main/java/org/sadtech/social/core/utils/MessageUtils.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/MessageUtils.java similarity index 65% rename from src/main/java/org/sadtech/social/core/utils/MessageUtils.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/MessageUtils.java index d42f41b..1e00301 100644 --- a/src/main/java/org/sadtech/social/core/utils/MessageUtils.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/MessageUtils.java @@ -1,7 +1,7 @@ -package org.sadtech.social.core.utils; +package dev.struchkov.godfather.context.utils; -import org.sadtech.social.core.domain.content.EmptyMessage; -import org.sadtech.social.core.domain.content.Message; +import dev.struchkov.godfather.context.domain.content.EmptyMessage; +import dev.struchkov.godfather.context.domain.content.Message; /** * Класс для хранения объекта заглушки для {@link Message}. diff --git a/src/main/java/org/sadtech/social/core/utils/Messages.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Messages.java similarity index 88% rename from src/main/java/org/sadtech/social/core/utils/Messages.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/Messages.java index 014cab3..4e9d7ab 100644 --- a/src/main/java/org/sadtech/social/core/utils/Messages.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Messages.java @@ -1,4 +1,4 @@ -package org.sadtech.social.core.utils; +package dev.struchkov.godfather.context.utils; /** * Класс утилита, содержащий сообщения об ошибках, и сообщения логирования. diff --git a/src/main/java/org/sadtech/social/core/utils/Sender.java b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java similarity index 71% rename from src/main/java/org/sadtech/social/core/utils/Sender.java rename to bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java index 3e350c8..c2470c7 100644 --- a/src/main/java/org/sadtech/social/core/utils/Sender.java +++ b/bot-context/src/main/java/dev/struchkov/godfather/context/utils/Sender.java @@ -1,11 +1,9 @@ -package org.sadtech.social.core.utils; +package dev.struchkov.godfather.context.utils; -import org.sadtech.social.core.domain.BoxAnswer; -import org.sadtech.social.core.domain.content.Comment; -import org.sadtech.social.core.domain.content.Message; -import org.sadtech.social.core.service.sender.Sending; - -import static org.sadtech.social.core.utils.Messages.UTILITY_CLASS; +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.service.sender.Sending; +import dev.struchkov.godfather.context.domain.content.Comment; /** * Используется для отправки сообщений определенного типа. @@ -15,7 +13,7 @@ import static org.sadtech.social.core.utils.Messages.UTILITY_CLASS; public class Sender { private Sender() { - throw new IllegalStateException(UTILITY_CLASS); + throw new IllegalStateException(Messages.UTILITY_CLASS); } public static void sends(Message message, BoxAnswer boxAnswer, Sending sending) { diff --git a/bot-core/pom.xml b/bot-core/pom.xml new file mode 100644 index 0000000..9401411 --- /dev/null +++ b/bot-core/pom.xml @@ -0,0 +1,154 @@ + + + 4.0.0 + + dev.struchkov.godfather + godfather-bot + 0.0.1-SNAPSHOT + + + bot-core + 0.0.1-SNAPSHOT + jar + + Bot Core + Реализация основной логики для создания ботов без привязки к конкретным социальным сетям. + https://github.com/uPagge/social-bot + + + BSD 3-Clause "New" or "Revised" License + https://github.com/uPagge/social-bot/blob/master/LICENSE + + + + + scm:git:https://github.com/uPagge/social-bot.git + https://github.com/uPagge/social-bot + scm:git:https://github.com/uPagge/social-bot.git + + + + + ossrh + https://oss.sonatype.org/content/repositories/snapshots + + + + + + dev.struchkov.godfather + bot-context + + + + org.sadtech.autoresponder + autoresponder + + + + commons-io + commons-io + + + + + + release + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + org.apache.maven.plugins + maven-source-plugin + 2.2.1 + + + attach-sources + + jar-no-fork + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 2.9.1 + + + attach-javadocs + + jar + + + + + + org.apache.maven.plugins + maven-gpg-plugin + 1.5 + + + sign-artifacts + verify + + sign + + + + + + org.sonatype.plugins + nexus-staging-maven-plugin + 1.6.7 + true + + ossrh + https://oss.sonatype.org/ + true + + + + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + 16 + 16 + + + + + + + + uPagge + Struchkov Mark + upagge@mail.ru + SADTECH + + + + \ No newline at end of file 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 new file mode 100644 index 0000000..b53555d --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/GeneralAutoResponder.java @@ -0,0 +1,148 @@ +package dev.struchkov.godfather.core; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.exception.ConfigAppException; +import dev.struchkov.godfather.context.exception.NotFoundException; +import dev.struchkov.godfather.context.service.AccountService; +import dev.struchkov.godfather.context.service.MessageService; +import dev.struchkov.godfather.context.service.Modifiable; +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.action.ActionUnit; +import dev.struchkov.godfather.core.service.action.AnswerAccountAction; +import dev.struchkov.godfather.core.service.action.AnswerCheckAction; +import dev.struchkov.godfather.core.service.action.AnswerProcessingAction; +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.timer.TimerService; +import dev.struchkov.godfather.core.utils.TypeUnit; +import org.sadtech.autoresponder.AutoResponder; +import org.sadtech.autoresponder.entity.UnitPointer; +import org.sadtech.autoresponder.repository.UnitPointerRepository; +import org.sadtech.autoresponder.service.UnitPointerServiceImpl; + +import java.util.HashMap; +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; + +public class GeneralAutoResponder extends TimerTask { + + protected final AutoResponder autoResponder; + private final MessageService messageService; + protected Map> actionUnitMap = new HashMap<>(); + protected List> modifiables; + private ExecutorService executorService = Executors.newFixedThreadPool(10); + + protected GeneralAutoResponder(Set menuUnit, + Sending sending, + MessageService messageService, + UnitPointerRepository unitPointerRepository + ) { + this.messageService = messageService; + autoResponder = new AutoResponder<>(new UnitPointerServiceImpl<>(unitPointerRepository), menuUnit); + init(sending); + } + + private void init(Sending sending) { + actionUnitMap.put(TypeUnit.CHECK, new AnswerCheckAction()); + actionUnitMap.put(TypeUnit.PROCESSING, new AnswerProcessingAction(sending)); + actionUnitMap.put(TypeUnit.TEXT, new AnswerTextAction(sending)); + actionUnitMap.put(TypeUnit.VALIDITY, new AnswerValidityAction()); + } + + public void initModifiables(List> modifiables) { + this.modifiables = modifiables; + } + + protected void initActionUnit(String typeUnit, ActionUnit actionUnit) { + if (!actionUnitMap.containsKey(typeUnit)) { + actionUnitMap.put(typeUnit, actionUnit); + } else { + throw new ConfigAppException("Обработка такого типа юнита уже зарегистрирована"); + } + } + + public void initDefaultUnit(U defaultUnit) { + autoResponder.setDefaultUnit(defaultUnit); + } + + public void initSaveAction(AnswerSaveAction answerSaveAction) { + actionUnitMap.put(TypeUnit.SAVE, answerSaveAction); + } + + public void initTimerAction(TimerService timerService) { + actionUnitMap.put(TypeUnit.TIMER, new AnswerTimerAction(timerService, this)); + } + + public void initAccountAction(AccountService accountService, TimerService timerService) { + actionUnitMap.put(TypeUnit.ACCOUNT, new AnswerAccountAction(accountService, timerService)); + } + + public void setDefaultUnit(MainUnit mainUnit) { + autoResponder.setDefaultUnit(mainUnit); + } + + public void checkNewMessage() { + List eventByTime = messageService.getNewMessage(); + if (eventByTime != null && !eventByTime.isEmpty()) { + executorService.execute( + () -> eventByTime.parallelStream().forEach(processing()) + ); + } + } + + private Consumer processing() { + return event -> { + if (modifiables != null) { + modifiables.forEach(modifiable -> modifiable.change(event)); + } + autoResponder.answer(event.getPersonId(), event.getText()).ifPresent(unitAnswer -> answer(event, unitAnswer)); + }; + } + + public void answer(T event, MainUnit unitAnswer) { + unitAnswer = getAction(event, unitAnswer); + unitAnswer = activeUnitAfter(unitAnswer, event); + if (!(autoResponder.getDefaultUnit() != null && autoResponder.getDefaultUnit().equals(unitAnswer))) { + autoResponder.getUnitPointerService().save(new UnitPointer<>(event.getPersonId(), unitAnswer)); + } + } + + private MainUnit activeUnitAfter(MainUnit mainUnit, T content) { + if (mainUnit.getNextUnits() != null) { + Optional first = mainUnit.getNextUnits().stream() + .filter(unit -> UnitActiveType.AFTER.equals(unit.getActiveType())) + .findFirst(); + if (first.isPresent()) { + getAction(content, first.get()); + return activeUnitAfter(first.get(), content); + } + } + return mainUnit; + } + + private MainUnit getAction(T event, MainUnit unitAnswer) { + if (actionUnitMap.containsKey(unitAnswer.getType())) { + ActionUnit actionUnit = actionUnitMap.get(unitAnswer.getType()); + MainUnit mainUnit = actionUnit.action(unitAnswer, event); + if (!unitAnswer.equals(mainUnit)) return getAction(event, mainUnit); + return mainUnit; + } + throw new NotFoundException("ActionUnit для типа " + unitAnswer.getType() + " не зарегистрирован"); + } + + @Override + public void run() { + checkNewMessage(); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java new file mode 100644 index 0000000..aa53af9 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/AccountAutoCheck.java @@ -0,0 +1,33 @@ +package dev.struchkov.godfather.core.domain; + +import dev.struchkov.godfather.context.domain.money.Account; +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.ToString; + +/** + * Объект, для автоматической проверки оплаты счета {@link Account}. + * + * @author upagge [11/07/2019] + */ +@Getter +@EqualsAndHashCode +@ToString +@Builder +public class AccountAutoCheck { + + @Description("Unut, который обрабатывается при успешной оплате") + private MainUnit successfulPayment; + + @Description("Unit, который обрабатывается при не успешной оплате") + private MainUnit failedPayment; + + @Description("Период проверки") + private Integer periodSec; + + @Description("Время жизни счета") + private Integer lifeTimeHours; +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java new file mode 100644 index 0000000..bb259dc --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Clarification.java @@ -0,0 +1,14 @@ +package dev.struchkov.godfather.core.domain; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import lombok.Builder; +import lombok.Getter; + +@Builder +@Getter +public class Clarification { + + private BoxAnswer question; + private String value; + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java new file mode 100644 index 0000000..2599b98 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/Timer.java @@ -0,0 +1,44 @@ +package dev.struchkov.godfather.core.domain; + +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import dev.struchkov.godfather.core.service.usercode.CheckData; +import lombok.Builder; +import lombok.Data; + +import java.time.LocalDateTime; + +/** + * Используется для отложенной активации обработки Unit-ов. + * + * @author upagge [11/07/2019] + */ +@Builder +@Data +public class Timer { + + @Description("Идентификатор таймера") + private Integer id; + + @Description("Unit, обработка которого откладывается") + private MainUnit unitAnswer; + + @Description("Unit, который будет обработан после удаления таймера") + private MainUnit unitDeath; + + @Description("Идентификатор пользователя") + private Long personId; + + @Description("Время активации таймера") + private LocalDateTime timeActive; + + @Description("Время смерти таймера") + private LocalDateTime timeDeath; + + @Description("Интервал срабатывания таймера") + private Integer periodSec; + + @Description("Условие срабатывания таймера") + private CheckData checkLoop; + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java new file mode 100644 index 0000000..918b3e6 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/Question.java @@ -0,0 +1,29 @@ +package dev.struchkov.godfather.core.domain.question; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.utils.Description; +import lombok.Builder; +import lombok.Getter; +import lombok.Setter; +import lombok.Singular; + +import java.util.List; + +/** + * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем. + * + * @author upagge [14/07/2019] + */ +@Getter +@Setter +@Builder +public class Question { + + @Description("Вопрос") + private BoxAnswer boxAnswer; + + @Singular + @Description("Список предполагаемых ответов") + private List questionAnswers; + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java new file mode 100644 index 0000000..109a313 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionAnswer.java @@ -0,0 +1,32 @@ +package dev.struchkov.godfather.core.domain.question; + +import dev.struchkov.godfather.context.utils.Description; +import lombok.Getter; +import lombok.Setter; + +/** + * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем. + * Отвечает за варианты ответов. + * + * @author upagge [14/07/2019] + */ +@Getter +@Setter +public class QuestionAnswer { + + @Description("Текстовый ответ") + private String text; + + @Description("Количество балов за ответ") + private int points; + + public QuestionAnswer(String text, Integer points) { + this.text = text; + this.points = points; + } + + public QuestionAnswer(String text) { + this.text = text; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java new file mode 100644 index 0000000..a0b9c73 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/question/QuestionResult.java @@ -0,0 +1,27 @@ +package dev.struchkov.godfather.core.domain.question; + +import dev.struchkov.godfather.context.utils.Description; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.Setter; + +/** + * Используется для сохранения результатов ответов на вопросы. + * + * @author upagge [14/07/2019] + */ +@Getter +@Setter +@AllArgsConstructor +public class QuestionResult { + + @Description("Вопрос") + private String question; + + @Description("Ответ") + private String answer; + + @Description("Количество баллов за ответ") + private Integer points; + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java new file mode 100644 index 0000000..c81d37e --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerAccount.java @@ -0,0 +1,60 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.domain.AccountAutoCheck; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; + +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Юнит для обработки платежей. + * + * @author upagge [08/07/2019] + */ +@Getter +@EqualsAndHashCode(callSuper = true) +public class AnswerAccount extends MainUnit { + + @Description("Сумма к оплате") + private final Integer totalSum; + + @Description("Время жизни счета") + private final Integer timeHours; + + @Description("Настройки для автоматической проверки оплаты") + private final AccountAutoCheck autoCheck; + + @Builder + private AnswerAccount( + @Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + UnitActiveType activeType, + Integer totalSum, + Integer timeHours, + AccountAutoCheck autoCheck + ) { + super( + keyWords, + phrase, + pattern, + matchThreshold, + priority, + nextUnits, + (activeType == null) ? UnitActiveType.AFTER : activeType, + TypeUnit.ACCOUNT + ); + this.totalSum = totalSum; + this.timeHours = timeHours; + this.autoCheck = autoCheck; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java new file mode 100644 index 0000000..c555550 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerCheck.java @@ -0,0 +1,52 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.service.usercode.CheckData; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; + +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Обработчик запроса, который реализует конструкцию IF в сценарии. + * + * @author upagge [08/07/2019] + */ +@Getter +@EqualsAndHashCode(callSuper = true) +public class AnswerCheck extends MainUnit { + + @Description("Unit для true") + private final MainUnit unitTrue; + + @Description("Unit для false") + private final MainUnit unitFalse; + + @Description("Условие проверки") + private final CheckData check; + + @Builder + protected AnswerCheck( + @Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + UnitActiveType activeType, + MainUnit unitTrue, + MainUnit unitFalse, + CheckData check + ) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.CHECK); + this.unitTrue = unitTrue; + this.unitFalse = unitFalse; + this.check = check; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java new file mode 100644 index 0000000..1b5f4cf --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerProcessing.java @@ -0,0 +1,46 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.service.sender.Sending; +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.service.usercode.ProcessingData; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; + +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Обработчик для кастомных реализаций. + * + * @author upagge [08/07/2019] + */ +@Getter +@EqualsAndHashCode(callSuper = true) +public class AnswerProcessing extends MainUnit { + + @Description("Кастомная обработка") + private final ProcessingData processingData; + + @Description("Объект для сквозной отправки ответа") + private final Sending sending; + + @Builder + private AnswerProcessing(@Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + UnitActiveType activeType, + ProcessingData processingData, + Sending sending) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.PROCESSING); + this.processingData = processingData; + this.sending = sending; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java new file mode 100644 index 0000000..ff50e4d --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerSave.java @@ -0,0 +1,75 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.service.save.CheckSave; +import dev.struchkov.godfather.core.service.save.Preservable; +import dev.struchkov.godfather.core.service.save.data.PreservableData; +import dev.struchkov.godfather.core.service.save.push.Pusher; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; + +import java.util.Collection; +import java.util.Optional; +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Обработчик для сохранения ответов пользователя. Так же допускается скрытое сохранение. + * + * @author upagge [08/07/2019] + */ +@Getter +@EqualsAndHashCode(callSuper = true) +public class AnswerSave extends MainUnit { + + @Description("Объект отвечающий за сохранение - репозиторий") + private final Preservable preservable; + + @Description("Ключ для данных") + private final String key; + + @Description("Отправка результатов") + private final Pusher pusher; + + @Description("Данные для скрытого сохранения") + private final PreservableData preservableData; + + @Description("Скрытое сохранение") + private final boolean hidden; + + private final CheckSave checkSave; + + @Builder + private AnswerSave(@Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + Preservable preservable, + String key, + Pusher pusher, + PreservableData preservableData, + CheckSave checkSave, + boolean hidden) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, (hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT, TypeUnit.SAVE); + this.key = key; + this.pusher = pusher; + maintenanceNextUnit(nextUnits); + this.preservable = preservable; + this.preservableData = preservableData; + this.hidden = Optional.of(hidden).orElse(false); + this.checkSave = checkSave; + } + + private void maintenanceNextUnit(Collection units) { + if (units != null) { + units.forEach(mainUnit -> mainUnit.setActiveType(UnitActiveType.AFTER)); + } + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java new file mode 100644 index 0000000..6e5e76f --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerText.java @@ -0,0 +1,55 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.service.sender.Sending; +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.service.usercode.Insert; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; + +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Используется для отправки ответа пользователю. + * + * @author upagge [08/07/2019] + */ +@Getter +@EqualsAndHashCode(callSuper = true) +public class AnswerText extends MainUnit { + + @Description("Объект, который необходимо отправить пользователю") + private final BoxAnswer boxAnswer; + + @Description("Информация, которую необходимо вставить вместо маркеров в строку ответа") + private final Insert insert; + + @Description("Объект нестандартной отправки ответа") + private final Sending sending; + + @Builder(toBuilder = true) + private AnswerText(@Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + UnitActiveType activeType, + BoxAnswer boxAnswer, + Insert insert, + Sending sending) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.TEXT); + this.boxAnswer = boxAnswer; + this.insert = insert; + this.sending = sending; + } + + public static AnswerText of(String message) { + return AnswerText.builder().boxAnswer(BoxAnswer.of(message)).build(); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java new file mode 100644 index 0000000..29abe01 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerTimer.java @@ -0,0 +1,56 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.service.usercode.CheckData; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; +import lombok.ToString; + +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Обработчик таймер, позволяющий отложить обработку других Unit-ов. + * + * @author upagge [08/07/2019] + */ +@Getter +@ToString +@EqualsAndHashCode(callSuper = true) +public class AnswerTimer extends MainUnit { + + @Description("Unit обработку которого необходимо отложить") + private final MainUnit unitAnswer; + + @Description("Задержка обработки в секундах") + private final Integer timeDelaySec; + + @Description("Время, через которое таймер будет удален в секундах") + private final Integer timeDeathSec; + + @Description("Условие срабатывания отложенного Unit") + private final CheckData checkLoop; + + @Builder + private AnswerTimer(@Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + UnitActiveType activeType, + MainUnit unitAnswer, + Integer timeDelaySec, + Integer timeDeathSec, + CheckData checkLoop) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, (activeType == null) ? UnitActiveType.AFTER : activeType, TypeUnit.TIMER); + this.unitAnswer = unitAnswer; + this.timeDelaySec = timeDelaySec; + this.timeDeathSec = timeDeathSec; + this.checkLoop = checkLoop; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java new file mode 100644 index 0000000..de0b6b8 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/AnswerValidity.java @@ -0,0 +1,59 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.utils.Description; +import dev.struchkov.godfather.core.service.save.LocalPreservable; +import dev.struchkov.godfather.core.service.save.Preservable; +import dev.struchkov.godfather.core.service.usercode.ClarificationQuestion; +import dev.struchkov.godfather.core.utils.TypeUnit; +import lombok.Builder; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Singular; +import lombok.ToString; + +import java.util.Set; +import java.util.regex.Pattern; + +/** + * Обработка данных со страницы пользователя. + * + * @author upagge [11/07/2019] + */ +@Getter +@ToString +@EqualsAndHashCode(callSuper = true) +public class AnswerValidity extends MainUnit { + + @Description("Unit обрабатывается, если пользователь подтверждает данные") + private final MainUnit unitYes; + + @Description("Unit обрабатывается, если пользователь отклоняет данные") + private final MainUnit unitNo; + + @Description("Unit обрабатывается, если данные не найдены") + private final MainUnit unitNull; + + private final Preservable tempSave = new LocalPreservable<>(); + + private final ClarificationQuestion clarificationQuestion; + + @Builder(toBuilder = true) + private AnswerValidity(@Singular Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + @Singular Set nextUnits, + UnitActiveType activeType, + MainUnit unitYes, + MainUnit unitNo, + MainUnit unitNull, + ClarificationQuestion clarificationQuestion) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, UnitActiveType.DEFAULT, TypeUnit.VALIDITY); + this.unitYes = unitYes; + this.unitNo = unitNo; + this.unitNull = unitNull; + this.clarificationQuestion = clarificationQuestion; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java new file mode 100644 index 0000000..4f6a327 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/MainUnit.java @@ -0,0 +1,49 @@ +package dev.struchkov.godfather.core.domain.unit; + +import dev.struchkov.godfather.context.utils.Description; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; +import lombok.ToString; +import org.sadtech.autoresponder.entity.Unit; + +import java.util.Optional; +import java.util.Set; +import java.util.UUID; +import java.util.regex.Pattern; + +/** + * Главный обработчик {@link Unit}, от него наследуются все остальные Unit-ы. + * + * @author upagge [08/07/2019] + */ +@ToString +@EqualsAndHashCode(callSuper = true) +public abstract class MainUnit extends Unit { + + @Getter + @Description("Тип Unit-а") + protected final String type; + + @Getter + @Setter + @Description("Режим срабатывания Unit-а") + protected UnitActiveType activeType; + + @Getter + private String uuid = UUID.randomUUID().toString(); + + protected MainUnit(Set keyWords, + String phrase, + Pattern pattern, + Integer matchThreshold, + Integer priority, + Set nextUnits, + UnitActiveType activeType, + String type) { + super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits); + this.activeType = Optional.ofNullable(activeType).orElse(UnitActiveType.DEFAULT); + this.type = type; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/UnitActiveType.java b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/UnitActiveType.java new file mode 100644 index 0000000..0297508 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/domain/unit/UnitActiveType.java @@ -0,0 +1,13 @@ +package dev.struchkov.godfather.core.domain.unit; + +/** + * Тип активации Unit-а. Определяет порядок обработки Unit. + * + * @author upagge [11/07/2019] + */ +public enum UnitActiveType { + + DEFAULT, + AFTER + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/repository/TimerRepository.java b/bot-core/src/main/java/dev/struchkov/godfather/core/repository/TimerRepository.java new file mode 100644 index 0000000..1a34f69 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/repository/TimerRepository.java @@ -0,0 +1,29 @@ +package dev.struchkov.godfather.core.repository; + +import dev.struchkov.godfather.core.domain.Timer; + +import java.time.LocalDateTime; +import java.util.Collection; + +/** + * Репозиторий для работы с хранилищем таймеров {@link Timer}. + * + * @author upagge [11/07/2019] + */ +public interface TimerRepository { + + Integer add(Timer timer); + + /** + * Получить все таймеры, время активации которых меньше, чем переданное время + * + * @param time Время + * @return Коллекция таймеров + */ + Collection getTimerActive(LocalDateTime time); + + void remove(Integer id); + + void edit(Timer timer); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/repository/TimerRepositoryMap.java b/bot-core/src/main/java/dev/struchkov/godfather/core/repository/TimerRepositoryMap.java new file mode 100644 index 0000000..4958fe6 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/repository/TimerRepositoryMap.java @@ -0,0 +1,42 @@ +package dev.struchkov.godfather.core.repository; + +import dev.struchkov.godfather.core.domain.Timer; + +import java.time.LocalDateTime; +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * Локальная реализация репозитория {@link TimerRepository} на основе HashMap. + * + * @author upagge [11/07/2019] + */ +public class TimerRepositoryMap implements TimerRepository { + + private final Map map = new HashMap<>(); + private Integer count = 0; + + public Integer add(Timer timer) { + timer.setId(count); + map.put(count, timer); + return count++; + } + + @Override + public Collection getTimerActive(LocalDateTime time) { + return map.values().parallelStream().filter(timer -> time.isAfter(timer.getTimeActive())).collect(Collectors.toSet()); + } + + @Override + public void remove(Integer id) { + map.remove(id); + } + + @Override + public void edit(Timer timer) { + map.put(timer.getId(), timer); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/ActionUnit.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/ActionUnit.java new file mode 100644 index 0000000..cc783f2 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/ActionUnit.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.domain.unit.MainUnit; + +/** + * Интерфейс для обработки Unit-ов. + * + * @author upagge [11/07/2019] + */ +@FunctionalInterface +public interface ActionUnit { + + /** + * Метод обработки Unit-а. + * + * @param unit Unit, который необходимо обработать + * @param content Запрос пользователя + * @return Новый Unit, который может нуждаться в обработке + */ + MainUnit action(M unit, C content); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java new file mode 100644 index 0000000..ec35fe7 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerAccountAction.java @@ -0,0 +1,81 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.domain.content.Mail; +import dev.struchkov.godfather.context.domain.keyboard.button.KeyBoardButtonAccount; +import dev.struchkov.godfather.context.domain.money.Account; +import dev.struchkov.godfather.context.service.AccountService; +import dev.struchkov.godfather.context.utils.KeyBoards; +import dev.struchkov.godfather.core.domain.AccountAutoCheck; +import dev.struchkov.godfather.core.domain.Timer; +import dev.struchkov.godfather.core.domain.unit.AnswerAccount; +import dev.struchkov.godfather.core.domain.unit.AnswerText; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import dev.struchkov.godfather.core.service.timer.TimerService; + +import java.time.Clock; +import java.time.LocalDateTime; +import java.time.ZoneId; + +/** + * Обработчик Unit-а {@link AnswerAccount}. + * + * @author upagge [11/07/2019] + */ +public class AnswerAccountAction implements ActionUnit { + + private final AccountService accountService; + private TimerService timerService; + + public AnswerAccountAction(AccountService accountService, TimerService timerService) { + this.accountService = accountService; + this.timerService = timerService; + } + + public AnswerAccountAction(AccountService accountService) { + this.accountService = accountService; + } + + @Override + public MainUnit action(AnswerAccount answerAccount, Mail mail) { + final Account account = new Account(); + account.setBelongsPersonId(mail.getPersonId()); + account.setTotalSum(answerAccount.getTotalSum()); + + final Integer accountId = accountService.add(account).getId(); + + settingCheckTimer(answerAccount, mail, accountId); + + KeyBoardButtonAccount buttonAccount = KeyBoardButtonAccount.builder() + .accountId(accountId) + .amount(answerAccount.getTotalSum()).build(); + + BoxAnswer boxAnswer = BoxAnswer.builder() + .message("Для оплаты укажите номер счета " + accountId + "\nСумма к оплате: " + + answerAccount.getTotalSum()) + .keyBoard(KeyBoards.singelton(buttonAccount)) + .build(); + + return AnswerText.builder().boxAnswer(boxAnswer).build(); + } + + private void settingCheckTimer(AnswerAccount answerAccount, Mail mail, Integer accountId) { + AccountAutoCheck autoCheck = answerAccount.getAutoCheck(); + if (autoCheck != null && timerService != null) { + Timer timer = Timer.builder() + .personId(mail.getPersonId()) + .unitAnswer(autoCheck.getSuccessfulPayment()) + .unitDeath(autoCheck.getFailedPayment()) + .checkLoop(content1 -> accountService.paymentVerification(accountId)) + .periodSec(autoCheck.getPeriodSec()) + .timeActive(LocalDateTime + .now(Clock.tickSeconds(ZoneId.systemDefault())) + .plusSeconds(autoCheck.getPeriodSec())) + .timeDeath(LocalDateTime + .now(Clock.tickSeconds(ZoneId.systemDefault())) + .plusHours(autoCheck.getLifeTimeHours())) + .build(); + timerService.add(timer); + } + } +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java new file mode 100644 index 0000000..a6de446 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerCheckAction.java @@ -0,0 +1,31 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.domain.unit.AnswerCheck; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import lombok.extern.slf4j.Slf4j; + +import java.util.Optional; + +/** + * Обработчик Unit-а {@link AnswerCheck}. + * + * @author upagge [11/07/2019] + */ +@Slf4j +public class AnswerCheckAction implements ActionUnit { + + @Override + public MainUnit action(AnswerCheck answerCheck, Message mail) { + MainUnit unitAnswer; + if (answerCheck.getCheck().checked(mail)) { + log.info("Проверка пройдена"); + unitAnswer = answerCheck.getUnitTrue(); + } else { + log.info("Проверка не пройдена"); + unitAnswer = answerCheck.getUnitFalse(); + } + return Optional.ofNullable(unitAnswer).orElse(answerCheck); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java new file mode 100644 index 0000000..3cb4600 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerProcessingAction.java @@ -0,0 +1,36 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.service.sender.Sending; +import dev.struchkov.godfather.context.utils.Sender; +import dev.struchkov.godfather.core.domain.unit.AnswerProcessing; +import dev.struchkov.godfather.core.domain.unit.MainUnit; + +/** + * Обработчик Unit-а {@link AnswerProcessing}. + * + * @author upagge [11/07/2019] + */ +public class AnswerProcessingAction implements ActionUnit, Message> { + + private final Sending sending; + + public AnswerProcessingAction(Sending sending) { + this.sending = sending; + } + + @Override + public MainUnit action(AnswerProcessing answerProcessing, Message message) { + BoxAnswer boxAnswer = answerProcessing.getProcessingData().processing(message); + + Sending answerProcessingSending = answerProcessing.getSending(); + if (answerProcessingSending != null) { + Sender.sends(message, boxAnswer, answerProcessingSending); + } else { + Sender.sends(message, boxAnswer, this.sending); + } + return answerProcessing; + } + +} 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 new file mode 100644 index 0000000..ba3c2b3 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerSaveAction.java @@ -0,0 +1,39 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.domain.unit.AnswerSave; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import dev.struchkov.godfather.core.service.save.CheckSave; +import dev.struchkov.godfather.core.service.save.Preservable; +import dev.struchkov.godfather.core.service.save.data.PreservableData; + +/** + * Обработчик Unit-а {@link AnswerSave}. + * + * @author upagge [11/07/2019] + */ +public class AnswerSaveAction implements ActionUnit, Message> { + + @Override + public MainUnit action(AnswerSave answerSave, Message mail) { + Preservable preservable = answerSave.getPreservable(); + Long personId = mail.getPersonId(); + + CheckSave checkSave = answerSave.getCheckSave(); + if (checkSave != null) { + MainUnit unit = checkSave.check(mail); + if (unit != null) { + return unit; + } + } + + PreservableData preservableData = answerSave.getPreservableData(); + D data = preservableData.getData(mail); + if (data != null) { + preservable.save(personId, answerSave.getKey(), data); + } + + preservable.push(personId, answerSave.getPusher()); + return answerSave; + } +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java new file mode 100644 index 0000000..520d0f7 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTextAction.java @@ -0,0 +1,46 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.service.sender.Sending; +import dev.struchkov.godfather.context.utils.InsertWords; +import dev.struchkov.godfather.context.utils.Sender; +import dev.struchkov.godfather.core.domain.unit.AnswerText; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import lombok.AllArgsConstructor; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Обработчик Unit-а {@link AnswerText}. + * + * @author upagge [11/07/2019] + */ +@AllArgsConstructor +@NoArgsConstructor +public class AnswerTextAction implements ActionUnit { + + private Sending sending; + + @Override + public MainUnit action(AnswerText answerText, Message message) { + BoxAnswer boxAnswer = answerText.getBoxAnswer().toBuilder().build(); + if (answerText.getInsert() != null) { + List words = answerText.getInsert().insert(message.getPersonId()); + String newMessage = InsertWords.insert(boxAnswer.getMessage(), words); + boxAnswer.setMessage(newMessage); + } + + Sending answerTextSending = answerText.getSending(); + if (answerTextSending != null) { + Sender.sends(message, boxAnswer, answerTextSending); + } else { + Sender.sends(message, boxAnswer, this.sending); + } + + return answerText; + } + + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java new file mode 100644 index 0000000..47850f8 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerTimerAction.java @@ -0,0 +1,68 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.exception.TimerSettingException; +import dev.struchkov.godfather.core.GeneralAutoResponder; +import dev.struchkov.godfather.core.domain.Timer; +import dev.struchkov.godfather.core.domain.unit.AnswerTimer; +import dev.struchkov.godfather.core.domain.unit.MainUnit; +import dev.struchkov.godfather.core.service.timer.TimerActionTask; +import dev.struchkov.godfather.core.service.timer.TimerService; + +import java.time.Clock; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Optional; + +/** + * Обработчик Unit-а {@link AnswerTimer}. + * + * @author upagge [11/07/2019] + */ +public class AnswerTimerAction implements ActionUnit { + + private TimerService timerService; + private Long verificationPeriodSec = 15L; + + public AnswerTimerAction(TimerService timerService, GeneralAutoResponder generalAutoresponder) { + this.timerService = timerService; + TimerActionTask timerActionTask = new TimerActionTask(timerService, generalAutoresponder); + java.util.Timer timer = new java.util.Timer(true); + timer.schedule(timerActionTask, 0, 1000L * verificationPeriodSec); + } + + public Long getVerificationPeriodSec() { + return verificationPeriodSec; + } + + public void setVerificationPeriodSec(Long verificationPeriodSec) { + this.verificationPeriodSec = verificationPeriodSec; + } + + @Override + public MainUnit action(AnswerTimer answerTimer, Message message) { + LocalDateTime timeActive = LocalDateTime + .now(Clock.tickSeconds(ZoneId.systemDefault())) + .plusSeconds(Optional + .ofNullable(answerTimer.getTimeDelaySec()) + .orElseThrow(() -> new TimerSettingException("Не установлена временная задержка таймера"))); + + Timer.TimerBuilder timer = Timer.builder() + .personId(message.getPersonId()) + .unitAnswer(answerTimer.getUnitAnswer()) + .timeActive(timeActive) + .periodSec(answerTimer.getTimeDelaySec()) + .checkLoop(answerTimer.getCheckLoop()); + + if (answerTimer.getTimeDeathSec() != null) { + timer.timeDeath(LocalDateTime + .now(Clock.tickSeconds(ZoneId.systemDefault())) + .plusSeconds(answerTimer.getTimeDeathSec())); + } else if (answerTimer.getCheckLoop() == null) { + timer.timeDeath(timeActive); + } + + timerService.add(timer.build()); + return answerTimer; + } +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java new file mode 100644 index 0000000..f858391 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/action/AnswerValidityAction.java @@ -0,0 +1,53 @@ +package dev.struchkov.godfather.core.service.action; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.domain.Clarification; +import dev.struchkov.godfather.core.domain.unit.AnswerText; +import dev.struchkov.godfather.core.domain.unit.AnswerValidity; +import dev.struchkov.godfather.core.domain.unit.MainUnit; + +import java.util.Collections; +import java.util.Set; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +/** + * Обработчик Unit-а {@link AnswerValidity}. + * + * @author upagge [11/07/2019] + */ +public class AnswerValidityAction implements ActionUnit { + + public static final Set WORDS_YES = Set.of("да", "ага"); + public static final Set WORDS_NO = Set.of("нет", "неа"); + public static final Set WORDS_YES_NO = Set.of("да", "ага", "нет", "неа"); + + @Override + public MainUnit action(AnswerValidity unit, Message content) { + String message = content.getText(); + Long personId = content.getPersonId(); + if (WORDS_YES.contains(message.toLowerCase())) { + unit.getTempSave().getByKey(personId, "temp").ifPresent(content::setText); + return unit.getUnitYes(); + } else if (WORDS_NO.contains(message.toLowerCase())) { + unit.getTempSave().getByKey(personId, "temp").ifPresent(content::setText); + return unit.getUnitNo(); + } else { + Clarification clarification = unit.getClarificationQuestion().getClarification(content); + final String value = clarification.getValue(); + if (value == null) { + return unit.getUnitNull(); + } else { + unit.getTempSave().save(personId, "temp", value); + AnswerValidity newValidity = unit.toBuilder() + .clearKeyWords().keyWords(WORDS_YES_NO) + .build(); + return AnswerText.builder() + .boxAnswer(clarification.getQuestion()) + .nextUnit(newValidity) + .build(); + } + } + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/CheckSave.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/CheckSave.java new file mode 100644 index 0000000..c074d86 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/CheckSave.java @@ -0,0 +1,16 @@ +package dev.struchkov.godfather.core.service.save; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.domain.unit.MainUnit; + +/** + * TODO: Добавить описание интерфейса. + * + * @author upagge [04/08/2019] + */ +@FunctionalInterface +public interface CheckSave { + + MainUnit check(D content); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/LocalPreservable.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/LocalPreservable.java new file mode 100644 index 0000000..50f520c --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/LocalPreservable.java @@ -0,0 +1,35 @@ +package dev.struchkov.godfather.core.service.save; + +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 null; + } + + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/Preservable.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/Preservable.java new file mode 100644 index 0000000..53c0f9c --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/Preservable.java @@ -0,0 +1,37 @@ +package dev.struchkov.godfather.core.service.save; + +import dev.struchkov.godfather.core.service.save.push.Pusher; + +import java.util.Map; +import java.util.Optional; + +/** + * Интерфейс для сохранения и взаимодейтсвия с ответами прав пользователя. + * + * @author upagge [11/07/2019] + */ +public interface Preservable { + + /** + * Сохранение данных для пользователя + * + * @param personId Идентификатор пользователя + * @param save Объект данных + */ + void save(Long personId, String key, S save); + + 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-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableData.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableData.java new file mode 100644 index 0000000..8978dce --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableData.java @@ -0,0 +1,10 @@ +package dev.struchkov.godfather.core.service.save.data; + +import dev.struchkov.godfather.context.domain.content.Message; + +@FunctionalInterface +public interface PreservableData { + + E getData(C content); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java new file mode 100644 index 0000000..b9a9d97 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/data/PreservableDataSimple.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.core.service.save.data; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.utils.Pair; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [13/07/2019] + */ +public class PreservableDataSimple implements PreservableData, Message> { + + private final String fieldName; + + public PreservableDataSimple(String fieldName) { + this.fieldName = fieldName; + } + + @Override + public Pair getData(Message content) { + return new Pair<>(fieldName, content.getText()); + } +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java new file mode 100644 index 0000000..bb93656 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/PreservableJpa.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.core.service.save.jpa;//package org.sadtech.social.bot.service.save.jpa; +// +//import lombok.RequiredArgsConstructor; +//import org.sadtech.social.bot.service.save.Preservable; +//import org.springframework.data.jpa.repository.JpaRepository; +// +///** +// * TODO: Добавить описание класса. +// * +// * @author upagge [01/08/2019] +// */ +//@RequiredArgsConstructor +//public abstract class PreservableJpa, D extends SaveObjectJpa> implements Preservable { +// +// protected final R jpaRepository; +// +// @Override +// public void save(Long personId, String key, R save) { +// save.setPersonId(personId); +// jpaRepository.save(save); +// } +// +//} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java new file mode 100644 index 0000000..393428a --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/jpa/SaveObjectJpa.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.core.service.save.jpa; + +import dev.struchkov.godfather.context.domain.BasicEntity; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import javax.persistence.Column; +import javax.persistence.MappedSuperclass; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [01/08/2019] + */ +@EqualsAndHashCode(callSuper = true) +@MappedSuperclass +@Data +public abstract class SaveObjectJpa extends BasicEntity { + + @Column(name = "personId") + private Long personId; + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java new file mode 100644 index 0000000..50c155f --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/EmailPusher.java @@ -0,0 +1,125 @@ +package dev.struchkov.godfather.core.service.save.push; + +import dev.struchkov.godfather.context.exception.MailSendException; +import dev.struchkov.godfather.context.service.sender.email.EmailConfig; +import lombok.extern.slf4j.Slf4j; + +import javax.mail.Authenticator; +import javax.mail.Message; +import javax.mail.MessagingException; +import javax.mail.PasswordAuthentication; +import javax.mail.Session; +import javax.mail.Transport; +import javax.mail.internet.InternetAddress; +import javax.mail.internet.MimeMessage; +import java.util.Map; + +/** + * Сохранение результатов анкеты на Email. + * + * @author upagge [11/07/2019] + */ +// todo [upagge] [11/07/2019]: Отрефакторить +@Slf4j +public class EmailPusher implements Pusher { + + private final EmailConfig emailConfig; + private final String nameForm; + + public EmailPusher(EmailConfig emailConfig, String nameForm) { + this.emailConfig = emailConfig; + this.nameForm = nameForm; + } + + @Override + public void push(Map saveElement) { + + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
  
\n" + + "
\n" + + "
\n" + + "

") + .append(nameForm) + .append("

\n" + + "
\n" + + " \n" + + " "); + for (Map.Entry element : saveElement.entrySet()) { + stringBuilder.append("\n" + + " \n" + + " "); + } + stringBuilder.append("\n" + + "
") + .append(element.getKey()) + .append(":\n" + + " ") + .append(element.getValue()) + .append("
\n" + + " \n" + + "
\n" + + "
\n" + + "
\n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + " \n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "
 
\n" + + "
\n" + + "
\n" + + "
\n" + + "
\n" + + "
"); + + Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() { + protected PasswordAuthentication getPasswordAuthentication() { + return new PasswordAuthentication(emailConfig.getUsername(), emailConfig.getPassword()); + } + }); + + try { + Message message = new MimeMessage(session); + message.setFrom(new InternetAddress(emailConfig.getUsername())); + message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(emailConfig.getUsername())); + message.setSubject(nameForm); + message.setContent(stringBuilder.toString(), "text/html; charset=utf-8"); + Transport.send(message); + } catch (MessagingException e) { + log.error(e.getMessage()); + throw new MailSendException(); + } + + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/Pusher.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/Pusher.java new file mode 100644 index 0000000..2002ef5 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/Pusher.java @@ -0,0 +1,15 @@ +package dev.struchkov.godfather.core.service.save.push; + +import java.util.Map; + +/** + * TODO: Добавить описание класса. + * + * @author upagge [13/07/2019] + */ +@FunctionalInterface +public interface Pusher { + + void push(Map saveElement); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/UserSanderPusher.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/UserSanderPusher.java new file mode 100644 index 0000000..6e45953 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/save/push/UserSanderPusher.java @@ -0,0 +1,29 @@ +package dev.struchkov.godfather.core.service.save.push; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.service.sender.Sending; + +import java.util.Map; + +public class UserSanderPusher implements Pusher { + + private final Long personId; + private final String nameForm; + private final Sending sending; + + public UserSanderPusher(Long personId, String nameForm, Sending sending) { + this.personId = personId; + this.nameForm = nameForm; + this.sending = sending; + } + + @Override + public void push(Map saveElement) { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.append("========= ").append(nameForm).append(" =========\n"); + saveElement.forEach((key, value) -> stringBuilder.append(key).append(": ").append(value).append("\n")); + stringBuilder.append("===================="); + sending.send(this.personId, BoxAnswer.builder().message(stringBuilder.toString()).build()); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java new file mode 100644 index 0000000..87748a5 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerActionTask.java @@ -0,0 +1,84 @@ +package dev.struchkov.godfather.core.service.timer; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.context.utils.MessageUtils; +import dev.struchkov.godfather.core.GeneralAutoResponder; +import dev.struchkov.godfather.core.domain.Timer; +import dev.struchkov.godfather.core.service.usercode.CheckData; +import lombok.extern.slf4j.Slf4j; + +import java.time.Clock; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.TimerTask; + +/** + * Обслуживание таймеров. Отвечает за активацию, удаление, перенастройку таймеров. + * + * @author upagge [11/07/2019] + */ +@Slf4j +public class TimerActionTask extends TimerTask { + + private final TimerService timerService; + private final GeneralAutoResponder generalAutoresponder; + + public TimerActionTask(TimerService timerService, GeneralAutoResponder generalAutoresponder) { + this.generalAutoresponder = generalAutoresponder; + log.info("Инициализация сервиса по активации таймеров"); + this.timerService = timerService; + } + + @Override + public void run() { + LocalDateTime nowDate = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault())); + log.info("Сервис таймеров сработал. Время: {}", nowDate); + + timerService.getTimerActive() + .parallelStream() + .forEach(timer -> processingTimer(timer, nowDate)); + + } + + private void processingTimer(Timer timer, LocalDateTime nowDate) { + Message emptyMessage = MessageUtils.EMPTY_MESSAGE; + emptyMessage.setPersonId(timer.getPersonId()); + CheckData checkLoop = timer.getCheckLoop(); + + if (!timeDeath(nowDate, timer.getTimeDeath())) { + if (checkLoop != null) { + if (checkLoop.checked(emptyMessage)) { + generalAutoresponder.answer(emptyMessage, timer.getUnitAnswer()); + timerService.remove(timer.getId()); + } else { + reinstallation(timer); + } + } else { + generalAutoresponder.answer(emptyMessage, timer.getUnitAnswer()); + reinstallation(timer); + } + } else { + generalAutoresponder.answer(emptyMessage, timer.getUnitAnswer()); + death(timer, emptyMessage); + } + } + + private void reinstallation(Timer timer) { + if (timer.getPeriodSec() != null) { + timer.setTimeActive(timer.getTimeActive().plusSeconds(timer.getPeriodSec())); + timerService.edit(timer.getId(), timer); + } + } + + private void death(Timer timer, Message emptyMessage) { + if (timer.getUnitDeath() != null) { + generalAutoresponder.answer(emptyMessage, timer.getUnitDeath()); + } + timerService.remove(timer.getId()); + } + + private boolean timeDeath(LocalDateTime nowTime, LocalDateTime timeDeath) { + return timeDeath != null && nowTime.isAfter(timeDeath); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerService.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerService.java new file mode 100644 index 0000000..da5cc35 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerService.java @@ -0,0 +1,17 @@ +package dev.struchkov.godfather.core.service.timer; + +import dev.struchkov.godfather.core.domain.Timer; + +import java.util.List; + +public interface TimerService { + + List getTimerActive(); + + Integer add(Timer timer); + + void remove(Integer id); + + void edit(Integer id, Timer timer); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java new file mode 100644 index 0000000..eac6133 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/timer/TimerServiceImpl.java @@ -0,0 +1,42 @@ +package dev.struchkov.godfather.core.service.timer; + +import dev.struchkov.godfather.core.domain.Timer; +import dev.struchkov.godfather.core.repository.TimerRepository; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; + +import java.time.LocalDateTime; +import java.util.ArrayList; +import java.util.List; + +@Slf4j +@RequiredArgsConstructor +public class TimerServiceImpl implements TimerService { + + private final TimerRepository timerRepository; + + public TimerRepository getTimerRepository() { + return timerRepository; + } + + @Override + public List getTimerActive() { + return new ArrayList<>(timerRepository.getTimerActive(LocalDateTime.now())); + } + + public Integer add(Timer timer) { + log.info("Таймер установлен: {}", timer); + return timerRepository.add(timer); + } + + public void remove(Integer id) { + log.info("Таймер удален"); + timerRepository.remove(id); + } + + public void edit(Integer id, Timer timer) { + timer.setId(id); + timerRepository.edit(timer); + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/CheckData.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/CheckData.java new file mode 100644 index 0000000..969c27c --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/CheckData.java @@ -0,0 +1,10 @@ +package dev.struchkov.godfather.core.service.usercode; + +import dev.struchkov.godfather.context.domain.content.Message; + +@FunctionalInterface +public interface CheckData { + + boolean checked(C content); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/ClarificationQuestion.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/ClarificationQuestion.java new file mode 100644 index 0000000..ead7fad --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/ClarificationQuestion.java @@ -0,0 +1,11 @@ +package dev.struchkov.godfather.core.service.usercode; + +import dev.struchkov.godfather.context.domain.content.Message; +import dev.struchkov.godfather.core.domain.Clarification; + +@FunctionalInterface +public interface ClarificationQuestion { + + Clarification getClarification(C message); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/Insert.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/Insert.java new file mode 100644 index 0000000..87ce0c0 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/Insert.java @@ -0,0 +1,10 @@ +package dev.struchkov.godfather.core.service.usercode; + +import java.util.List; + +@FunctionalInterface +public interface Insert { + + List insert(Long personId); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/ProcessingData.java b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/ProcessingData.java new file mode 100644 index 0000000..5fe70b6 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/service/usercode/ProcessingData.java @@ -0,0 +1,11 @@ +package dev.struchkov.godfather.core.service.usercode; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.domain.content.Message; + +@FunctionalInterface +public interface ProcessingData { + + BoxAnswer processing(C content); + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java new file mode 100644 index 0000000..9e14895 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/Pair.java @@ -0,0 +1,17 @@ +package dev.struchkov.godfather.core.utils; + +import lombok.AllArgsConstructor; +import lombok.EqualsAndHashCode; +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +@EqualsAndHashCode +@AllArgsConstructor +public class Pair { + + private K key; + private D value; + +} 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 new file mode 100644 index 0000000..e6876ee --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/QuestionUtils.java @@ -0,0 +1,95 @@ +package dev.struchkov.godfather.core.utils; + +import dev.struchkov.godfather.context.domain.BoxAnswer; +import dev.struchkov.godfather.context.utils.KeyBoards; +import dev.struchkov.godfather.core.domain.question.Question; +import dev.struchkov.godfather.core.domain.question.QuestionAnswer; +import dev.struchkov.godfather.core.domain.question.QuestionResult; +import dev.struchkov.godfather.core.domain.unit.AnswerSave; +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.core.service.save.Preservable; +import dev.struchkov.godfather.core.service.save.push.Pusher; + +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +/** + * Утилита для быстрой генерации цепочки Unit-ов, образующих сценарий "Тестирование". + * + * @author upagge [14/07/2019] + */ +public class QuestionUtils { + + private final Preservable preservable; + private final List questions; + private Pusher pusher; + + private QuestionUtils(List questions, Preservable preservable) { + this.questions = questions; + this.preservable = preservable; + } + + private QuestionUtils(List questions, Preservable preservable, Pusher pusher) { + this.questions = questions; + this.preservable = preservable; + this.pusher = pusher; + } + + public static QuestionUtils builder(Preservable preservable, List questions) { + return new QuestionUtils(questions, preservable); + } + + public static QuestionUtils builder(Preservable preservable, Pusher pusher, List list) { + return new QuestionUtils(list, preservable, pusher); + } + + public MainUnit build(MainUnit finishUnit) { + return generateTest(finishUnit); + } + + public MainUnit build() { + return generateTest(null); + } + + private MainUnit generateTest(MainUnit finishUnit) { + AnswerText previousUnit = null; + for (int i = questions.size() - 1; i >= 0; i--) { + Question question = this.questions.get(i); + List collectAnswer = question.getQuestionAnswers().stream() + .map(QuestionAnswer::getText) + .collect(Collectors.toList()); + BoxAnswer boxAnswer = question.getBoxAnswer().toBuilder() + .keyBoard(KeyBoards.verticalDuoMenuString(collectAnswer)).build(); + + AnswerText.AnswerTextBuilder answerTextBuilder = AnswerText.builder() + .boxAnswer(boxAnswer); + + for (QuestionAnswer questionAnswer : question.getQuestionAnswers()) { + AnswerSave.AnswerSaveBuilder answerSaveBuilder = AnswerSave.builder() + .preservable(preservable) + .preservableData( + message -> new QuestionResult( + question.getBoxAnswer().getMessage(), + questionAnswer.getText(), + questionAnswer.getPoints() + ) + ) + .phrase(questionAnswer.getText()); + if (i != this.questions.size() - 1) { + answerSaveBuilder.nextUnit(previousUnit).build(); + } else { + answerSaveBuilder.pusher(pusher); + Optional.of(finishUnit).ifPresent(answerSaveBuilder::nextUnit); + } + answerTextBuilder.nextUnit(answerSaveBuilder.build()); + } + if (i == 0) answerTextBuilder.activeType(UnitActiveType.AFTER); + previousUnit = answerTextBuilder.build(); + } + return previousUnit; + } + +} diff --git a/bot-core/src/main/java/dev/struchkov/godfather/core/utils/TypeUnit.java b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/TypeUnit.java new file mode 100644 index 0000000..6296c40 --- /dev/null +++ b/bot-core/src/main/java/dev/struchkov/godfather/core/utils/TypeUnit.java @@ -0,0 +1,23 @@ +package dev.struchkov.godfather.core.utils; + +/** + * Тип 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 PROCESSING = "PROCESSING"; + public static final String TIMER = "TIMER"; + public static final String CHECK = "CHECK"; + public static final String VALIDITY = "VALIDITY"; + public static final String ACCOUNT = "ACCOUNT"; + + private TypeUnit() { + throw new IllegalStateException("Утилитарный класс"); + } + + +} diff --git a/pom.xml b/pom.xml index aa3f0d3..7135400 100644 --- a/pom.xml +++ b/pom.xml @@ -4,28 +4,32 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 4.0.0 - org.sadtech.social - social-core - 0.8.0-SNAPSHOT - jar + dev.struchkov.godfather + godfather-bot + 0.0.1-SNAPSHOT + + bot-context + bot-core + + pom - Social Core + GodFather Bot - Набор классов для реализации абстрактных проектов для социальных сетей и месенджеров, без привязки к конкретным + Набор классов для реализации абстрактных проектов для социальных сетей и мессенджеров, без привязки к конкретным сервисам. - https://github.com/uPagge/social-core + https://github.com/Godfather-Bots/godfather BSD 3-Clause "New" or "Revised" License - https://github.com/uPagge/social-core/blob/master/LICENSE + https://github.com/Godfather-Bots/godfather/blob/master/LICENSE - scm:git:https://github.com/uPagge/social-core.git - https://github.com/uPagge/social-core - scm:git:https://github.com/uPagge/social-core.git + scm:git:https://github.com/Godfather-Bots/godfather.git + https://github.com/Godfather-Bots/godfathere + scm:git:https://github.com/Godfather-Bots/godfather.git @@ -36,48 +40,72 @@ - 2.8.5 - 1.4 - 1.18.10 + 17 + 17 + + 0.0.1-SNAPSHOT + 1.9.4-RELEASE + + 2.8.9 + 1.6.2 + 1.18.22 2.3.0.RELEASE 2.2 2.0.1.Final + 2.11.0 - - - com.google.code.gson - gson - ${gson.ver} - + + + + com.google.code.gson + gson + ${gson.ver} + + + javax.mail + javax.mail-api + ${mail.ver} + + + org.projectlombok + lombok + ${lombok.ver} + + + org.springframework.data + spring-data-jpa + ${spring.data.jpa.ver} + + + javax.persistence + javax.persistence-api + ${javax.persistence.api.ver} + + + javax.validation + validation-api + ${validation.api.ver} + + + dev.struchkov.godfather + bot-context + ${godfather.core.ver} + - - javax.mail - mail - ${mail.ver} - + + org.sadtech.autoresponder + autoresponder + ${autoresponder.ver} + - - org.projectlombok - lombok - ${lombok.ver} - - - org.springframework.data - spring-data-jpa - ${spring.data.jpa.ver} - - - javax.persistence - javax.persistence-api - ${javax.persistence.api.ver} - - - javax.validation - validation-api - ${validation.api.ver} - - + + commons-io + commons-io + ${commons.io.ver} + + + @@ -153,12 +181,16 @@ + + org.apache.maven.plugins + maven-compiler-plugin + org.apache.maven.plugins maven-compiler-plugin - 8 - 8 + 16 + 16