Большой рефакторинг
This commit is contained in:
parent
4d5f3ad542
commit
08256dadc3
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
<version>0.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-context</artifactId>
|
||||
@ -14,18 +14,10 @@
|
||||
<name>Bot Context</name>
|
||||
<description>Доменные сущности, интерфейсы, для библиотеки Godfather</description>
|
||||
|
||||
<properties>
|
||||
<skip.deploy>false</skip.deploy>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>javax.mail-api</artifactId>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-utils</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -41,6 +33,10 @@
|
||||
<groupId>org.slf4j</groupId>
|
||||
<artifactId>slf4j-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,9 +1,5 @@
|
||||
package dev.struchkov.godfather.context.domain;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
@ -13,9 +9,6 @@ import javax.persistence.MappedSuperclass;
|
||||
*
|
||||
* @author upagge [28/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@MappedSuperclass
|
||||
public class BasicEntity {
|
||||
|
||||
@ -23,4 +16,12 @@ public class BasicEntity {
|
||||
@GeneratedValue
|
||||
protected Long id;
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,27 +3,17 @@ package dev.struchkov.godfather.context.domain;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.domain.keyboard.KeyBoard;
|
||||
import dev.struchkov.godfather.context.service.usercode.ProcessingData;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Контейнер, которые содержит данные, которые будут отправлены пользователю как ответ на его запрос.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
@Builder(toBuilder = true)
|
||||
public class BoxAnswer {
|
||||
|
||||
/**
|
||||
* Обычное текстовое сообщение.
|
||||
*/
|
||||
@Setter
|
||||
private String message;
|
||||
|
||||
/**
|
||||
@ -33,12 +23,75 @@ public class BoxAnswer {
|
||||
|
||||
private boolean replace;
|
||||
|
||||
private BoxAnswer(Builder builder) {
|
||||
setMessage(builder.message);
|
||||
keyBoard = builder.keyBoard;
|
||||
replace = builder.replace;
|
||||
}
|
||||
|
||||
public static BoxAnswer of(String message) {
|
||||
return BoxAnswer.builder().message(message).build();
|
||||
}
|
||||
|
||||
public static <T extends Message> ProcessingData<T> processing(String messageText) {
|
||||
return message -> builder().message(messageText).build();
|
||||
return message -> of(messageText);
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public KeyBoard getKeyBoard() {
|
||||
return keyBoard;
|
||||
}
|
||||
|
||||
public boolean isReplace() {
|
||||
return replace;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BoxAnswer{" +
|
||||
"message='" + message + '\'' +
|
||||
", keyBoard=" + keyBoard +
|
||||
", replace=" + replace +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
public static final class Builder {
|
||||
private String message;
|
||||
private KeyBoard keyBoard;
|
||||
private boolean replace;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder message(String val) {
|
||||
message = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyBoard(KeyBoard val) {
|
||||
keyBoard = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder replace(boolean val) {
|
||||
replace = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public BoxAnswer build() {
|
||||
return new BoxAnswer(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package dev.struchkov.godfather.context.domain.content;
|
||||
|
||||
/**
|
||||
* Сообщение от пользователя типа "Комментарий к обсуждению группы".
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
public class BoardComment extends Comment {
|
||||
|
||||
public BoardComment() {
|
||||
type = ContentType.BOARD_COMMENT;
|
||||
}
|
||||
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
package dev.struchkov.godfather.context.domain.content;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Абстрактная сущность для сообщений от пользователей с привязкой к какому-то контенту (картинка, видео).
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class Comment extends Message {
|
||||
|
||||
/**
|
||||
* Идентификатор контента, к которому ставлено сообщение.
|
||||
*/
|
||||
private Long contentId;
|
||||
|
||||
}
|
@ -1,14 +1,12 @@
|
||||
package dev.struchkov.godfather.context.domain.content;
|
||||
|
||||
import dev.struchkov.godfather.context.exception.AppBotException;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Заглушка для сообщения от пользователя.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@ToString
|
||||
public class EmptyMessage extends Message {
|
||||
|
||||
public EmptyMessage() {
|
||||
|
@ -1,10 +1,6 @@
|
||||
package dev.struchkov.godfather.context.domain.content;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.content.attachment.Attachment;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
@ -19,11 +15,7 @@ import java.util.List;
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Entity
|
||||
@Getter
|
||||
@Setter
|
||||
@Table(name = "mail")
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Mail extends Message {
|
||||
|
||||
/**
|
||||
@ -56,4 +48,36 @@ public class Mail extends Message {
|
||||
type = ContentType.MAIL;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public List<Attachment> getAttachments() {
|
||||
return attachments;
|
||||
}
|
||||
|
||||
public void setAttachments(List<Attachment> attachments) {
|
||||
this.attachments = attachments;
|
||||
}
|
||||
|
||||
public List<Mail> getForwardMail() {
|
||||
return forwardMail;
|
||||
}
|
||||
|
||||
public void setForwardMail(List<Mail> forwardMail) {
|
||||
this.forwardMail = forwardMail;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,6 @@
|
||||
package dev.struchkov.godfather.context.domain.content;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.BasicEntity;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.EnumType;
|
||||
@ -12,18 +8,14 @@ import javax.persistence.Enumerated;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Абстрактная сущность - Сообщение от пользователя.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
@NoArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class Message extends BasicEntity {
|
||||
|
||||
/**
|
||||
@ -67,4 +59,60 @@ public abstract class Message extends BasicEntity {
|
||||
this.type = source.getType();
|
||||
}
|
||||
|
||||
public Message() {
|
||||
}
|
||||
|
||||
public ContentType getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(ContentType type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public LocalDateTime getCreateDate() {
|
||||
return createDate;
|
||||
}
|
||||
|
||||
public void setCreateDate(LocalDateTime createDate) {
|
||||
this.createDate = createDate;
|
||||
}
|
||||
|
||||
public LocalDateTime getAddDate() {
|
||||
return addDate;
|
||||
}
|
||||
|
||||
public void setAddDate(LocalDateTime addDate) {
|
||||
this.addDate = addDate;
|
||||
}
|
||||
|
||||
public Long getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
public void setPersonId(Long personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
Message message = (Message) o;
|
||||
return type == message.type && Objects.equals(createDate, message.createDate) && Objects.equals(addDate, message.addDate) && Objects.equals(personId, message.personId) && Objects.equals(text, message.text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(type, createDate, addDate, personId, text);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,13 +1,11 @@
|
||||
package dev.struchkov.godfather.context.domain.content.attachment;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import dev.struchkov.godfather.context.domain.BasicEntity;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EnumType;
|
||||
import javax.persistence.Enumerated;
|
||||
import javax.persistence.GeneratedValue;
|
||||
import javax.persistence.Id;
|
||||
|
||||
/**
|
||||
* Абстрактная сущность, для всех вложений к сообщениям от пользователей.
|
||||
@ -15,12 +13,7 @@ import javax.persistence.Id;
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Entity
|
||||
@EqualsAndHashCode
|
||||
public abstract class Attachment {
|
||||
|
||||
@Id
|
||||
@GeneratedValue
|
||||
private Integer id;
|
||||
public abstract class Attachment extends BasicEntity {
|
||||
|
||||
/**
|
||||
* Тип сущности.
|
||||
|
@ -1,22 +1,12 @@
|
||||
package dev.struchkov.godfather.context.domain.content.attachment;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.net.URL;
|
||||
|
||||
|
||||
/**
|
||||
* Вложение типа "Аудиосообщение".
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString
|
||||
@Setter
|
||||
public class AudioMessage extends Attachment {
|
||||
|
||||
/**
|
||||
@ -28,4 +18,8 @@ public class AudioMessage extends Attachment {
|
||||
type = AttachmentType.AUDIO_MESSAGE;
|
||||
}
|
||||
|
||||
public AudioMessage(URL linkOdd) {
|
||||
this.linkOdd = linkOdd;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,17 +1,10 @@
|
||||
package dev.struchkov.godfather.context.domain.content.attachment;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Вложение типа "Карта".
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Geo extends Attachment {
|
||||
|
||||
/**
|
||||
@ -37,9 +30,20 @@ public class Geo extends Attachment {
|
||||
return new Geo().new Builder();
|
||||
}
|
||||
|
||||
public GeoCoordinate getGeoCoordinate() {
|
||||
return geoCoordinate;
|
||||
}
|
||||
|
||||
public String getCountry() {
|
||||
return country;
|
||||
}
|
||||
|
||||
public String getCity() {
|
||||
return city;
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder coordinate(Float lat, Float aLong) {
|
||||
|
@ -1,17 +1,10 @@
|
||||
package dev.struchkov.godfather.context.domain.content.attachment;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Сущность для хранения географических координат.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class GeoCoordinate {
|
||||
|
||||
/**
|
||||
@ -24,4 +17,25 @@ public class GeoCoordinate {
|
||||
*/
|
||||
private Float longitude;
|
||||
|
||||
public GeoCoordinate(Float latitude, Float longitude) {
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
public Float getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public void setLatitude(Float latitude) {
|
||||
this.latitude = latitude;
|
||||
}
|
||||
|
||||
public Float getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public void setLongitude(Float longitude) {
|
||||
this.longitude = longitude;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,14 +1,5 @@
|
||||
package dev.struchkov.godfather.context.domain.content.attachment;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class Link extends Attachment {
|
||||
|
||||
private String url;
|
||||
@ -17,4 +8,12 @@ public class Link extends Attachment {
|
||||
this.type = AttachmentType.LINK;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,20 +1,15 @@
|
||||
package dev.struchkov.godfather.context.domain.keyboard.button;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.NonNull;
|
||||
import lombok.ToString;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* Абстрактная сущность кнопки для клавиатуры.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class SimpleButton implements KeyBoardButton {
|
||||
|
||||
public static final String TYPE = "SIMPLE";
|
||||
@ -28,20 +23,40 @@ public class SimpleButton implements KeyBoardButton {
|
||||
*/
|
||||
protected String callbackData;
|
||||
|
||||
@Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild")
|
||||
protected SimpleButton(String label, String callbackData) {
|
||||
this.label = label;
|
||||
this.callbackData = callbackData;
|
||||
}
|
||||
|
||||
public static SimpleButton of(@NonNull String label, @NonNull String callbackData) {
|
||||
public static SimpleButton of(@NotNull String label, @NotNull String callbackData) {
|
||||
return new SimpleButton(label, callbackData);
|
||||
}
|
||||
|
||||
public static SimpleButton of(@NonNull String label) {
|
||||
public static SimpleButton of(@NotNull String label) {
|
||||
return new SimpleButton(label, label);
|
||||
}
|
||||
|
||||
public String getLabel() {
|
||||
return label;
|
||||
}
|
||||
|
||||
public String getCallbackData() {
|
||||
return callbackData;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
SimpleButton that = (SimpleButton) o;
|
||||
return Objects.equals(label, that.label) && Objects.equals(callbackData, that.callbackData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(label, callbackData);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return TYPE;
|
||||
|
@ -3,11 +3,6 @@ package dev.struchkov.godfather.context.domain.keyboard.simple;
|
||||
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 lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -17,9 +12,6 @@ import java.util.List;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class SimpleKeyBoard implements KeyBoard {
|
||||
|
||||
public static final String TYPE = "SIMPLE";
|
||||
@ -29,15 +21,22 @@ public class SimpleKeyBoard implements KeyBoard {
|
||||
*/
|
||||
protected List<KeyBoardLine> lines = new ArrayList<>();
|
||||
|
||||
@Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild")
|
||||
public SimpleKeyBoard(@Singular("line") List<KeyBoardLine> lines) {
|
||||
public SimpleKeyBoard(List<KeyBoardLine> lines) {
|
||||
this.lines = lines;
|
||||
}
|
||||
|
||||
private SimpleKeyBoard(Builder builder) {
|
||||
lines = builder.lines;
|
||||
}
|
||||
|
||||
public static SimpleKeyBoard single(KeyBoardLine line) {
|
||||
return new SimpleKeyBoard(List.of(line));
|
||||
}
|
||||
|
||||
public static Builder build() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public SimpleKeyBoard single(KeyBoardButton keyBoardButton) {
|
||||
return single(SimpleKeyBoardLine.single(keyBoardButton));
|
||||
}
|
||||
@ -47,4 +46,29 @@ public class SimpleKeyBoard implements KeyBoard {
|
||||
return TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KeyBoardLine> getLines() {
|
||||
return lines;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private List<KeyBoardLine> lines = new ArrayList<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder lines(List<KeyBoardLine> val) {
|
||||
lines = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder line(KeyBoardLine val) {
|
||||
lines.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleKeyBoard build() {
|
||||
return new SimpleKeyBoard(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,10 +2,6 @@ package dev.struchkov.godfather.context.domain.keyboard.simple;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
|
||||
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
|
||||
import lombok.Builder;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Singular;
|
||||
import lombok.ToString;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -15,8 +11,6 @@ import java.util.List;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode
|
||||
public class SimpleKeyBoardLine implements KeyBoardLine {
|
||||
|
||||
/**
|
||||
@ -24,18 +18,45 @@ public class SimpleKeyBoardLine implements KeyBoardLine {
|
||||
*/
|
||||
protected List<KeyBoardButton> buttons = new ArrayList<>();
|
||||
|
||||
@Builder(builderMethodName = "simpleBuilder", buildMethodName = "simpleBuild")
|
||||
public SimpleKeyBoardLine(@Singular(value = "button") List<KeyBoardButton> buttons) {
|
||||
public SimpleKeyBoardLine(List<KeyBoardButton> buttons) {
|
||||
this.buttons = buttons;
|
||||
}
|
||||
|
||||
private SimpleKeyBoardLine(Builder builder) {
|
||||
buttons = builder.buttons;
|
||||
}
|
||||
|
||||
public static SimpleKeyBoardLine single(KeyBoardButton keyBoardButton) {
|
||||
return new SimpleKeyBoardLine(List.of(keyBoardButton));
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<KeyBoardButton> getButtons() {
|
||||
return buttons;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private List<KeyBoardButton> buttons = new ArrayList<>();
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder buttons(List<KeyBoardButton> val) {
|
||||
buttons = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder button(KeyBoardButton val) {
|
||||
buttons.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public SimpleKeyBoardLine build() {
|
||||
return new SimpleKeyBoardLine(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,14 +0,0 @@
|
||||
package dev.struchkov.godfather.context.exception;
|
||||
|
||||
/**
|
||||
* Ошибка, когда что-то не найдено.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
public class NotFoundException extends AppBotException {
|
||||
|
||||
public NotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package dev.struchkov.godfather.context.exception;
|
||||
|
||||
import dev.struchkov.haiti.context.exception.NotFoundException;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/**
|
||||
* Иключения связанные с настройками юнитов.
|
||||
*
|
||||
* @author upagge 28.04.2022
|
||||
*/
|
||||
public class UnitConfigException extends AppBotException{
|
||||
|
||||
public UnitConfigException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
public static Supplier<NotFoundException> unitConfigException(String message, Object... objects) {
|
||||
return () -> new NotFoundException(MessageFormat.format(message, objects));
|
||||
}
|
||||
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
package dev.struchkov.godfather.context.repository;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@ -19,7 +19,7 @@ public interface ContentRepository<T extends Message> {
|
||||
* @param content Объект сообщени
|
||||
* @return Идентификатор сообщения в хранилище
|
||||
*/
|
||||
T add(@NonNull T content);
|
||||
T add(@NotNull T content);
|
||||
|
||||
/**
|
||||
* Получить все сообщения за определенный временной диапазон
|
||||
@ -28,9 +28,9 @@ public interface ContentRepository<T extends Message> {
|
||||
* @param dateTo Конец диапазона
|
||||
* @return Список сообщений
|
||||
*/
|
||||
List<T> betweenByCreateDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<T> betweenByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
List<T> betweenByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<T> betweenByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
/**
|
||||
* Удаляет данные за указанный период
|
||||
@ -38,10 +38,10 @@ public interface ContentRepository<T extends Message> {
|
||||
* @param dateFrom Дата начала
|
||||
* @param dateTo Дата окончания
|
||||
*/
|
||||
void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
void deleteAllByAddDateBefore(@NonNull LocalDateTime date);
|
||||
void deleteAllByAddDateBefore(@NotNull LocalDateTime date);
|
||||
|
||||
void deleteAllByAddDateAfter(@NonNull LocalDateTime date);
|
||||
void deleteAllByAddDateAfter(@NotNull LocalDateTime date);
|
||||
|
||||
}
|
||||
|
@ -1,9 +1,8 @@
|
||||
package dev.struchkov.godfather.context.repository.impl.local;
|
||||
|
||||
import dev.struchkov.godfather.context.repository.ContentRepository;
|
||||
import lombok.NonNull;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import dev.struchkov.godfather.context.domain.content.Mail;
|
||||
import dev.struchkov.godfather.context.repository.ContentRepository;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
@ -14,7 +13,6 @@ import java.util.List;
|
||||
*
|
||||
* @author upagge [27/07/2019]
|
||||
*/
|
||||
@Slf4j
|
||||
public class MailRepositoryList implements ContentRepository<Mail> {
|
||||
|
||||
private final List<Mail> mails = new ArrayList<>();
|
||||
@ -28,7 +26,7 @@ public class MailRepositoryList implements ContentRepository<Mail> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> betweenByCreateDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
||||
public List<Mail> betweenByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
|
||||
ArrayList<Mail> rezultMails = new ArrayList<>();
|
||||
for (int i = mails.size() - 1; i >= 0; i--) {
|
||||
Mail mail = mails.get(i);
|
||||
@ -42,7 +40,7 @@ public class MailRepositoryList implements ContentRepository<Mail> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Mail> betweenByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
||||
public List<Mail> betweenByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
|
||||
ArrayList<Mail> rezultMails = new ArrayList<>();
|
||||
for (int i = mails.size() - 1; i >= 0; i--) {
|
||||
Mail mail = mails.get(i);
|
||||
@ -57,21 +55,21 @@ public class MailRepositoryList implements ContentRepository<Mail> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
||||
public void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
|
||||
mails.removeIf(mail -> dateFrom.isBefore(mail.getAddDate()) && dateTo.isAfter(mail.getAddDate()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllByAddDateBefore(LocalDateTime date) {
|
||||
public void deleteAllByAddDateBefore(@NotNull LocalDateTime date) {
|
||||
mails.removeIf(mail -> date.isBefore(mail.getAddDate()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllByAddDateAfter(LocalDateTime date) {
|
||||
public void deleteAllByAddDateAfter(@NotNull LocalDateTime date) {
|
||||
mails.removeIf(mail -> date.isAfter(mail.getAddDate()));
|
||||
}
|
||||
|
||||
private boolean isTimePeriod(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo, @NonNull LocalDateTime dateTime) {
|
||||
private boolean isTimePeriod(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo, @NotNull LocalDateTime dateTime) {
|
||||
return dateFrom.isBefore(dateTime) && dateTo.isAfter(dateTime);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.struchkov.godfather.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
@ -13,7 +13,7 @@ import java.util.List;
|
||||
*/
|
||||
public interface MessageService<T extends Message> {
|
||||
|
||||
void add(@NonNull T event);
|
||||
void add(@NotNull T event);
|
||||
|
||||
/**
|
||||
* Получить список сообщений за заданный временной интервал
|
||||
@ -22,7 +22,7 @@ public interface MessageService<T extends Message> {
|
||||
* @param dateTo Конец интервала
|
||||
* @return Список сообщений
|
||||
*/
|
||||
List<T> getByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<T> getByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
/**
|
||||
* Получить список ПОСЛЕДНИХ сообщений для каждого пользователя за заданных временной интервал
|
||||
@ -31,19 +31,19 @@ public interface MessageService<T extends Message> {
|
||||
* @param dateTo Конец интервала
|
||||
* @return Список сообщений
|
||||
*/
|
||||
List<T> getLastEventByCreateDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<T> getLastEventByCreateDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
List<T> getLastEventByAddDateTime(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
List<T> getLastEventByAddDateTime(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
/**
|
||||
* Возвращает новые сообщения от последнего запроса.
|
||||
*/
|
||||
List<T> getNewMessage();
|
||||
|
||||
void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo);
|
||||
void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo);
|
||||
|
||||
void deleteAllByAddDateBefore(@NonNull LocalDateTime date);
|
||||
void deleteAllByAddDateBefore(@NotNull LocalDateTime date);
|
||||
|
||||
void deleteAllByAddDateAfter(@NonNull LocalDateTime date);
|
||||
void deleteAllByAddDateAfter(@NotNull LocalDateTime date);
|
||||
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.struchkov.godfather.context.service;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Интерфес для изменения запроса пользователя перед тем, как он попадет в подсистему обработки.
|
||||
@ -12,6 +12,6 @@ import dev.struchkov.godfather.context.domain.content.Message;
|
||||
@FunctionalInterface
|
||||
public interface Modifiable<T extends Message> {
|
||||
|
||||
void change(@NonNull T content);
|
||||
void change(@NotNull T content);
|
||||
|
||||
}
|
||||
|
@ -3,9 +3,9 @@ package dev.struchkov.godfather.context.service.impl;
|
||||
import dev.struchkov.godfather.context.domain.content.Mail;
|
||||
import dev.struchkov.godfather.context.repository.ContentRepository;
|
||||
import dev.struchkov.godfather.context.service.MailService;
|
||||
import lombok.NonNull;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
@ -16,14 +16,18 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class MailServiceImpl implements MailService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MailServiceImpl.class);
|
||||
|
||||
private final ContentRepository<Mail> mailRepository;
|
||||
private boolean newMessage = false;
|
||||
private LocalDateTime oldDateTime = LocalDateTime.now(Clock.tickSeconds(ZoneId.systemDefault()));
|
||||
|
||||
public MailServiceImpl(ContentRepository<Mail> mailRepository) {
|
||||
this.mailRepository = mailRepository;
|
||||
}
|
||||
|
||||
//TODO [13.04.2022]: Подобная реализация с newMessage вызовет проблемы с несколькими инстансами.
|
||||
@Override
|
||||
public void add(Mail mail) {
|
||||
@ -73,17 +77,17 @@ public class MailServiceImpl implements MailService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllByAddDateBetween(@NonNull LocalDateTime dateFrom, @NonNull LocalDateTime dateTo) {
|
||||
public void deleteAllByAddDateBetween(@NotNull LocalDateTime dateFrom, @NotNull LocalDateTime dateTo) {
|
||||
mailRepository.deleteAllByAddDateBetween(dateFrom, dateTo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllByAddDateBefore(@NonNull LocalDateTime date) {
|
||||
public void deleteAllByAddDateBefore(@NotNull LocalDateTime date) {
|
||||
mailRepository.deleteAllByAddDateBefore(date);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteAllByAddDateAfter(@NonNull LocalDateTime date) {
|
||||
public void deleteAllByAddDateAfter(@NotNull LocalDateTime date) {
|
||||
mailRepository.deleteAllByAddDateAfter(date);
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.struchkov.godfather.context.service.sender;
|
||||
|
||||
import lombok.NonNull;
|
||||
import dev.struchkov.godfather.context.domain.BoxAnswer;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Интерфейс для отправки ответов пользователю.
|
||||
@ -16,9 +16,9 @@ public interface Sending {
|
||||
* @param personId Идентификатор пользователя
|
||||
* @param boxAnswer Объект с данными, которые необходимо отправить
|
||||
*/
|
||||
void send(@NonNull Long personId, @NonNull BoxAnswer boxAnswer);
|
||||
void send(@NotNull Long personId, @NotNull BoxAnswer boxAnswer);
|
||||
|
||||
void send(@NonNull Long contentId, @NonNull Long personId, @NonNull BoxAnswer boxAnswer);
|
||||
void send(@NotNull Long contentId, @NotNull Long personId, @NotNull BoxAnswer boxAnswer);
|
||||
|
||||
/**
|
||||
* Возвращает тип объекта отправляющего ответ пользователя. В зависимости от типа ответ будет отправлен с помощью
|
||||
|
@ -1,68 +0,0 @@
|
||||
package dev.struchkov.godfather.context.service.sender.email;
|
||||
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@Getter
|
||||
public class EmailConfig {
|
||||
|
||||
private Properties props = new Properties();
|
||||
private String username;
|
||||
private String password;
|
||||
|
||||
private EmailConfig() {
|
||||
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new EmailConfig().new Builder();
|
||||
}
|
||||
|
||||
public class Builder {
|
||||
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder smtpHost(String smtpHost) {
|
||||
EmailConfig.this.props.setProperty("mail.smtp.host", smtpHost);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder smtpSocketFactoryPort(Integer smtpSocketFactoryPortort) {
|
||||
EmailConfig.this.props.setProperty("mail.smtp.socketFactory.port", smtpSocketFactoryPortort.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder smtpSocketFactoryClass(String smtpSocketFactoryClass) {
|
||||
EmailConfig.this.props.setProperty("mail.smtp.socketFactory.class", smtpSocketFactoryClass);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder smtpAuth(Boolean smtpAuth) {
|
||||
EmailConfig.this.props.setProperty("mail.smtp.auth", (smtpAuth) ? "true" : "false");
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder smtpPort(Integer smtpPort) {
|
||||
EmailConfig.this.props.setProperty("mail.smtp.port", smtpPort.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder email(String username) {
|
||||
EmailConfig.this.username = username;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder password(String password) {
|
||||
EmailConfig.this.password = password;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmailConfig build() {
|
||||
return EmailConfig.this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,57 +0,0 @@
|
||||
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 dev.struchkov.godfather.context.domain.BoxAnswer;
|
||||
|
||||
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;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class EmailSending implements Sending {
|
||||
|
||||
private final EmailConfig emailConfig;
|
||||
|
||||
@Override
|
||||
public void send(@NonNull Long personId, @NonNull BoxAnswer boxAnswer) {
|
||||
Session session = Session.getDefaultInstance(emailConfig.getProps(), new Authenticator() {
|
||||
@Override
|
||||
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.setContent(boxAnswer.getMessage(), "text/html; charset=utf-8");
|
||||
Transport.send(message);
|
||||
} catch (MessagingException e) {
|
||||
log.error(e.getMessage());
|
||||
throw new MailSendException();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(@NonNull Long contentId, @NonNull Long personId, @NonNull BoxAnswer boxAnswer) {
|
||||
throw new MailSendException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendType getType() {
|
||||
return SendType.PUBLIC;
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,13 @@
|
||||
package dev.struchkov.godfather.context.utils;
|
||||
|
||||
import lombok.NonNull;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
/**
|
||||
* Класс для вставки слов в текстовую строку вместо подстрок - шаблонов маркеров.
|
||||
*
|
||||
@ -16,7 +18,7 @@ public class InsertWords {
|
||||
private static final Pattern pattern = Pattern.compile("\\{(\\d+)}");
|
||||
|
||||
private InsertWords() {
|
||||
throw new IllegalStateException(Messages.UTILITY_CLASS);
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -26,9 +28,9 @@ public class InsertWords {
|
||||
* @param words Список слов, которые необходимо поместить вместо шаблона
|
||||
* @return Модифицированная строка
|
||||
*/
|
||||
public static String insert(@NonNull String text, List<String> words) {
|
||||
Matcher m = pattern.matcher(text);
|
||||
StringBuffer result = new StringBuffer();
|
||||
public static String insert(@NotNull String text, List<String> words) {
|
||||
final Matcher m = pattern.matcher(text);
|
||||
final StringBuilder result = new StringBuilder();
|
||||
while (m.find()) {
|
||||
if (Integer.parseInt(m.group(1)) < words.size()) {
|
||||
m.appendReplacement(result, words.get(Integer.parseInt(m.group(1))));
|
||||
|
@ -27,9 +27,9 @@ public class KeyBoards {
|
||||
* @return {@link SimpleKeyBoard}
|
||||
*/
|
||||
public static SimpleKeyBoard keyBoardYesNo() {
|
||||
return SimpleKeyBoard.simpleBuilder().line(
|
||||
SimpleKeyBoardLine.simpleBuilder().button(YES_BUTTON).button(NO_BUTTON).simpleBuild()
|
||||
).simpleBuild();
|
||||
return SimpleKeyBoard.build().line(
|
||||
SimpleKeyBoardLine.builder().button(YES_BUTTON).button(NO_BUTTON).build()
|
||||
).build();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -39,12 +39,12 @@ public class KeyBoards {
|
||||
* @return {@link SimpleKeyBoard}
|
||||
*/
|
||||
public static SimpleKeyBoard verticalMenuString(List<String> labelButtons) {
|
||||
final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder();
|
||||
final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build();
|
||||
for (String labelButton : labelButtons) {
|
||||
final SimpleButton simpleButton = SimpleButton.of(labelButton, "{\"button\": \"" + labelButton + "\"}");
|
||||
keyBoard.line(SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild());
|
||||
keyBoard.line(SimpleKeyBoardLine.builder().button(simpleButton).build());
|
||||
}
|
||||
return keyBoard.simpleBuild();
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,25 +74,25 @@ public class KeyBoards {
|
||||
* @return {@link SimpleKeyBoard}
|
||||
*/
|
||||
public static SimpleKeyBoard verticalDuoMenuString(List<String> labelButton) {
|
||||
final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder();
|
||||
final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build();
|
||||
boolean flag = true;
|
||||
SimpleKeyBoardLine.SimpleKeyBoardLineBuilder keyBoardLine = SimpleKeyBoardLine.simpleBuilder();
|
||||
SimpleKeyBoardLine.Builder keyBoardLine = SimpleKeyBoardLine.builder();
|
||||
for (int i = 0; i <= labelButton.size() - 1; i++) {
|
||||
String label = labelButton.get(i);
|
||||
keyBoardLine.button(SimpleButton.of(label));
|
||||
if (flag) {
|
||||
if (i == labelButton.size() - 1) {
|
||||
keyBoard.line(keyBoardLine.simpleBuild());
|
||||
keyBoard.line(keyBoardLine.build());
|
||||
} else {
|
||||
flag = false;
|
||||
}
|
||||
} else {
|
||||
keyBoard.line(keyBoardLine.simpleBuild());
|
||||
keyBoardLine = SimpleKeyBoardLine.simpleBuilder();
|
||||
keyBoard.line(keyBoardLine.build());
|
||||
keyBoardLine = SimpleKeyBoardLine.builder();
|
||||
flag = true;
|
||||
}
|
||||
}
|
||||
return keyBoard.simpleBuild();
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -102,22 +102,11 @@ public class KeyBoards {
|
||||
* @return {@link SimpleKeyBoard}
|
||||
*/
|
||||
public static SimpleKeyBoard verticalMenuButton(List<SimpleButton> simpleButtons) {
|
||||
final SimpleKeyBoard.SimpleKeyBoardBuilder keyBoard = SimpleKeyBoard.simpleBuilder();
|
||||
final SimpleKeyBoard.Builder keyBoard = SimpleKeyBoard.build();
|
||||
for (SimpleButton simpleButton : simpleButtons) {
|
||||
keyBoard.line(SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild());
|
||||
keyBoard.line(SimpleKeyBoardLine.builder().button(simpleButton).build());
|
||||
}
|
||||
return keyBoard.simpleBuild();
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает клавиатуру из одной кнопки
|
||||
*
|
||||
* @param simpleButton Кнопка
|
||||
* @return {@link SimpleKeyBoard}
|
||||
*/
|
||||
public static SimpleKeyBoard singleton(SimpleButton simpleButton) {
|
||||
final SimpleKeyBoardLine line = SimpleKeyBoardLine.simpleBuilder().button(simpleButton).simpleBuild();
|
||||
return SimpleKeyBoard.simpleBuilder().line(line).simpleBuild();
|
||||
return keyBoard.build();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ package dev.struchkov.godfather.context.utils;
|
||||
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;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
|
||||
|
||||
/**
|
||||
* Используется для отправки сообщений определенного типа.
|
||||
@ -13,13 +14,12 @@ import dev.struchkov.godfather.context.domain.content.Comment;
|
||||
public class Sender {
|
||||
|
||||
private Sender() {
|
||||
throw new IllegalStateException(Messages.UTILITY_CLASS);
|
||||
utilityClass();
|
||||
}
|
||||
|
||||
public static void sends(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
switch (sending.getType()) {
|
||||
case PUBLIC:
|
||||
publicSend(message, boxAnswer, sending);
|
||||
break;
|
||||
case PRIVATE:
|
||||
privateSend(message, boxAnswer, sending);
|
||||
@ -27,12 +27,6 @@ public class Sender {
|
||||
}
|
||||
}
|
||||
|
||||
private static void publicSend(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
if (message instanceof Comment) {
|
||||
sending.send(((Comment) message).getContentId(), message.getPersonId(), boxAnswer);
|
||||
}
|
||||
}
|
||||
|
||||
private static void privateSend(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
sending.send(message.getPersonId(), boxAnswer);
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
<version>0.0.4</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-core</artifactId>
|
||||
@ -14,10 +14,6 @@
|
||||
<name>Bot Core</name>
|
||||
<description>Реализация основной логики для создания ботов без привязки к конкретным социальным сетям.</description>
|
||||
|
||||
<properties>
|
||||
<skip.deploy>false</skip.deploy>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
@ -25,7 +21,7 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech.autoresponder</groupId>
|
||||
<groupId>dev.struchkov</groupId>
|
||||
<artifactId>autoresponder</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -1,8 +1,11 @@
|
||||
package dev.struchkov.godfather.core;
|
||||
|
||||
import dev.struchkov.autoresponder.AutoResponder;
|
||||
import dev.struchkov.autoresponder.entity.UnitPointer;
|
||||
import dev.struchkov.autoresponder.repository.UnitPointerRepository;
|
||||
import dev.struchkov.autoresponder.service.UnitPointerServiceImpl;
|
||||
import dev.struchkov.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.MessageService;
|
||||
import dev.struchkov.godfather.context.service.Modifiable;
|
||||
import dev.struchkov.godfather.context.service.sender.Sending;
|
||||
@ -17,10 +20,7 @@ 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 dev.struchkov.haiti.context.exception.NotFoundException;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
@ -130,7 +130,7 @@ public class GeneralAutoResponder<T extends Message> extends TimerTask {
|
||||
MainUnit mainUnit = actionUnit.action(unitAnswer, event);
|
||||
return !unitAnswer.equals(mainUnit) ? getAction(event, mainUnit) : mainUnit;
|
||||
} else {
|
||||
throw new NotFoundException("ActionUnit для типа " + unitAnswer.getType() + " не зарегистрирован");
|
||||
throw new NotFoundException("ActionUnit для типа {0} не зарегистрирован", unitAnswer.getType());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,14 +1,23 @@
|
||||
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;
|
||||
|
||||
public Clarification(BoxAnswer question, String value) {
|
||||
this.question = question;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public BoxAnswer getQuestion() {
|
||||
return question;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,9 +2,6 @@ package dev.struchkov.godfather.core.domain;
|
||||
|
||||
import dev.struchkov.godfather.context.service.usercode.CheckData;
|
||||
import dev.struchkov.godfather.core.domain.unit.MainUnit;
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@ -13,9 +10,6 @@ import java.time.LocalDateTime;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class Timer {
|
||||
|
||||
/**
|
||||
@ -58,4 +52,140 @@ public class Timer {
|
||||
*/
|
||||
private CheckData checkLoop;
|
||||
|
||||
private Timer(Builder builder) {
|
||||
id = builder.id;
|
||||
unitAnswer = builder.unitAnswer;
|
||||
unitDeath = builder.unitDeath;
|
||||
personId = builder.personId;
|
||||
timeActive = builder.timeActive;
|
||||
timeDeath = builder.timeDeath;
|
||||
periodSec = builder.periodSec;
|
||||
checkLoop = builder.checkLoop;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Integer id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public MainUnit getUnitAnswer() {
|
||||
return unitAnswer;
|
||||
}
|
||||
|
||||
public void setUnitAnswer(MainUnit unitAnswer) {
|
||||
this.unitAnswer = unitAnswer;
|
||||
}
|
||||
|
||||
public MainUnit getUnitDeath() {
|
||||
return unitDeath;
|
||||
}
|
||||
|
||||
public void setUnitDeath(MainUnit unitDeath) {
|
||||
this.unitDeath = unitDeath;
|
||||
}
|
||||
|
||||
public Long getPersonId() {
|
||||
return personId;
|
||||
}
|
||||
|
||||
public void setPersonId(Long personId) {
|
||||
this.personId = personId;
|
||||
}
|
||||
|
||||
public LocalDateTime getTimeActive() {
|
||||
return timeActive;
|
||||
}
|
||||
|
||||
public void setTimeActive(LocalDateTime timeActive) {
|
||||
this.timeActive = timeActive;
|
||||
}
|
||||
|
||||
public LocalDateTime getTimeDeath() {
|
||||
return timeDeath;
|
||||
}
|
||||
|
||||
public void setTimeDeath(LocalDateTime timeDeath) {
|
||||
this.timeDeath = timeDeath;
|
||||
}
|
||||
|
||||
public Integer getPeriodSec() {
|
||||
return periodSec;
|
||||
}
|
||||
|
||||
public void setPeriodSec(Integer periodSec) {
|
||||
this.periodSec = periodSec;
|
||||
}
|
||||
|
||||
public CheckData getCheckLoop() {
|
||||
return checkLoop;
|
||||
}
|
||||
|
||||
public void setCheckLoop(CheckData checkLoop) {
|
||||
this.checkLoop = checkLoop;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private Integer id;
|
||||
private MainUnit unitAnswer;
|
||||
private MainUnit unitDeath;
|
||||
private Long personId;
|
||||
private LocalDateTime timeActive;
|
||||
private LocalDateTime timeDeath;
|
||||
private Integer periodSec;
|
||||
private CheckData checkLoop;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder id(Integer val) {
|
||||
id = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder unitAnswer(MainUnit val) {
|
||||
unitAnswer = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder unitDeath(MainUnit val) {
|
||||
unitDeath = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder personId(Long val) {
|
||||
personId = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder timeActive(LocalDateTime val) {
|
||||
timeActive = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder timeDeath(LocalDateTime val) {
|
||||
timeDeath = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder periodSec(Integer val) {
|
||||
periodSec = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder checkLoop(CheckData val) {
|
||||
checkLoop = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Timer build() {
|
||||
return new Timer(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,32 +1,32 @@
|
||||
package dev.struchkov.godfather.core.domain.question;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.BoxAnswer;
|
||||
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 {
|
||||
|
||||
/**
|
||||
* Вопрос.
|
||||
*/
|
||||
private BoxAnswer boxAnswer;
|
||||
|
||||
/**
|
||||
* Список предполагаемых ответов.
|
||||
*/
|
||||
@Singular
|
||||
private List<QuestionAnswer> questionAnswers;
|
||||
|
||||
}
|
||||
//package dev.struchkov.godfather.core.domain.question;
|
||||
//
|
||||
//import dev.struchkov.godfather.context.domain.BoxAnswer;
|
||||
//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 {
|
||||
//
|
||||
// /**
|
||||
// * Вопрос.
|
||||
// */
|
||||
// private BoxAnswer boxAnswer;
|
||||
//
|
||||
// /**
|
||||
// * Список предполагаемых ответов.
|
||||
// */
|
||||
// @Singular
|
||||
// private List<QuestionAnswer> questionAnswers;
|
||||
//
|
||||
//}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package dev.struchkov.godfather.core.domain.question;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем.
|
||||
* Отвечает за варианты ответов.
|
||||
*
|
||||
* @author upagge [14/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
public class QuestionAnswer {
|
||||
|
||||
/**
|
||||
* Текстовый ответ.
|
||||
*/
|
||||
private String text;
|
||||
|
||||
/**
|
||||
* Количество балов за ответ.
|
||||
*/
|
||||
private int points;
|
||||
|
||||
public QuestionAnswer(String text, Integer points) {
|
||||
this.text = text;
|
||||
this.points = points;
|
||||
}
|
||||
|
||||
public QuestionAnswer(String text) {
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
}
|
||||
//package dev.struchkov.godfather.core.domain.question;
|
||||
//
|
||||
//import lombok.Getter;
|
||||
//import lombok.Setter;
|
||||
//
|
||||
///**
|
||||
// * Используется для конфигурации генерации цепочки Unit-ов в виде тестов для прохождения пользователем.
|
||||
// * Отвечает за варианты ответов.
|
||||
// *
|
||||
// * @author upagge [14/07/2019]
|
||||
// */
|
||||
//@Getter
|
||||
//@Setter
|
||||
//public class QuestionAnswer {
|
||||
//
|
||||
// /**
|
||||
// * Текстовый ответ.
|
||||
// */
|
||||
// private String text;
|
||||
//
|
||||
// /**
|
||||
// * Количество балов за ответ.
|
||||
// */
|
||||
// private int points;
|
||||
//
|
||||
// public QuestionAnswer(String text, Integer points) {
|
||||
// this.text = text;
|
||||
// this.points = points;
|
||||
// }
|
||||
//
|
||||
// public QuestionAnswer(String text) {
|
||||
// this.text = text;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,32 +1,32 @@
|
||||
package dev.struchkov.godfather.core.domain.question;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
/**
|
||||
* Используется для сохранения результатов ответов на вопросы.
|
||||
*
|
||||
* @author upagge [14/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@AllArgsConstructor
|
||||
public class QuestionResult {
|
||||
|
||||
/**
|
||||
* Вопрос.
|
||||
*/
|
||||
private String question;
|
||||
|
||||
/**
|
||||
* Ответ.
|
||||
*/
|
||||
private String answer;
|
||||
|
||||
/**
|
||||
* Количество баллов за ответ.
|
||||
*/
|
||||
private Integer points;
|
||||
|
||||
}
|
||||
//package dev.struchkov.godfather.core.domain.question;
|
||||
//
|
||||
//import lombok.AllArgsConstructor;
|
||||
//import lombok.Getter;
|
||||
//import lombok.Setter;
|
||||
//
|
||||
///**
|
||||
// * Используется для сохранения результатов ответов на вопросы.
|
||||
// *
|
||||
// * @author upagge [14/07/2019]
|
||||
// */
|
||||
//@Getter
|
||||
//@Setter
|
||||
//@AllArgsConstructor
|
||||
//public class QuestionResult {
|
||||
//
|
||||
// /**
|
||||
// * Вопрос.
|
||||
// */
|
||||
// private String question;
|
||||
//
|
||||
// /**
|
||||
// * Ответ.
|
||||
// */
|
||||
// private String answer;
|
||||
//
|
||||
// /**
|
||||
// * Количество баллов за ответ.
|
||||
// */
|
||||
// private Integer points;
|
||||
//
|
||||
//}
|
||||
|
@ -3,21 +3,20 @@ package dev.struchkov.godfather.core.domain.unit;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.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.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static dev.struchkov.godfather.context.exception.UnitConfigException.unitConfigException;
|
||||
import static dev.struchkov.haiti.utils.Inspector.isAnyNotNull;
|
||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||
|
||||
/**
|
||||
* Обработчик запроса, который реализует конструкцию IF в сценарии.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AnswerCheck extends MainUnit {
|
||||
|
||||
/**
|
||||
@ -35,23 +34,99 @@ public class AnswerCheck extends MainUnit {
|
||||
*/
|
||||
private final CheckData<Message> check;
|
||||
|
||||
@Builder
|
||||
protected AnswerCheck(
|
||||
@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> nextUnits,
|
||||
UnitActiveType activeType,
|
||||
MainUnit unitTrue,
|
||||
MainUnit unitFalse,
|
||||
CheckData<Message> check
|
||||
) {
|
||||
super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.CHECK);
|
||||
private AnswerCheck(Builder builder) {
|
||||
super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, null, builder.activeType, TypeUnit.CHECK);
|
||||
unitTrue = builder.unitTrue;
|
||||
unitFalse = builder.unitFalse;
|
||||
check = builder.check;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public MainUnit getUnitTrue() {
|
||||
return unitTrue;
|
||||
}
|
||||
|
||||
public MainUnit getUnitFalse() {
|
||||
return unitFalse;
|
||||
}
|
||||
|
||||
public CheckData<Message> getCheck() {
|
||||
return check;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private Set<String> keyWords = new HashSet<>();
|
||||
private String phrase;
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private MainUnit unitTrue;
|
||||
private MainUnit unitFalse;
|
||||
private CheckData<Message> check;
|
||||
private UnitActiveType activeType;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder keyWords(Set<String> val) {
|
||||
keyWords = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyWord(String val) {
|
||||
keyWords.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder phrase(String val) {
|
||||
phrase = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder pattern(Pattern val) {
|
||||
pattern = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder priority(Integer val) {
|
||||
priority = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder unitTrue(MainUnit unitTrue) {
|
||||
this.unitTrue = unitTrue;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder unitFalse(MainUnit unitFalse) {
|
||||
this.unitFalse = unitFalse;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder check(CheckData<Message> check) {
|
||||
this.check = check;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder activeType(UnitActiveType val) {
|
||||
activeType = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerCheck build() {
|
||||
isNotNull(check, unitConfigException("Необходимо установить параметр проверки."));
|
||||
isAnyNotNull(unitConfigException("Необходимо задать хотя бы один unit результата проверки."));
|
||||
return new AnswerCheck(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,8 @@ import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.service.sender.Sending;
|
||||
import dev.struchkov.godfather.context.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.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ -17,8 +14,6 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AnswerProcessing<M extends Message> extends MainUnit {
|
||||
|
||||
/**
|
||||
@ -31,21 +26,87 @@ public class AnswerProcessing<M extends Message> extends MainUnit {
|
||||
*/
|
||||
private final Sending sending;
|
||||
|
||||
@Builder
|
||||
private AnswerProcessing(
|
||||
@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> nextUnits,
|
||||
UnitActiveType activeType,
|
||||
ProcessingData<M> processingData,
|
||||
Sending sending
|
||||
) {
|
||||
super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.PROCESSING);
|
||||
this.processingData = processingData;
|
||||
this.sending = sending;
|
||||
private AnswerProcessing(Builder<M> builder) {
|
||||
super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, builder.activeType, TypeUnit.PROCESSING);
|
||||
processingData = builder.processingData;
|
||||
sending = builder.sending;
|
||||
}
|
||||
|
||||
public static <M extends Message> Builder<M> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
public ProcessingData<M> getProcessingData() {
|
||||
return processingData;
|
||||
}
|
||||
|
||||
public Sending getSending() {
|
||||
return sending;
|
||||
}
|
||||
|
||||
public static final class Builder<M extends Message> {
|
||||
private Set<String> keyWords = new HashSet<>();
|
||||
private String phrase;
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private Set<MainUnit> nextUnits = new HashSet<>();
|
||||
private ProcessingData<M> processingData;
|
||||
private Sending sending;
|
||||
private UnitActiveType activeType;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder<M> keyWords(Set<String> val) {
|
||||
keyWords = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> keyWord(String val) {
|
||||
keyWords.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> phrase(String val) {
|
||||
phrase = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> pattern(Pattern val) {
|
||||
pattern = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> priority(Integer val) {
|
||||
priority = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> nextUnits(Set<MainUnit> val) {
|
||||
nextUnits = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> nextUnit(MainUnit val) {
|
||||
nextUnits.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> activeType(UnitActiveType val) {
|
||||
activeType = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerProcessing<M> build() {
|
||||
return new AnswerProcessing<>(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -6,13 +6,8 @@ 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;
|
||||
|
||||
@ -21,8 +16,6 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AnswerSave<D> extends MainUnit {
|
||||
|
||||
/**
|
||||
@ -52,29 +45,19 @@ public class AnswerSave<D> extends MainUnit {
|
||||
|
||||
private final CheckSave<? super Message> checkSave;
|
||||
|
||||
@Builder
|
||||
private AnswerSave(
|
||||
@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> nextUnits,
|
||||
Preservable<D> preservable,
|
||||
String key,
|
||||
Pusher<D> pusher,
|
||||
PreservableData<D, ? super Message> preservableData,
|
||||
CheckSave<? super Message> checkSave,
|
||||
boolean hidden
|
||||
) {
|
||||
super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, (hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT, TypeUnit.SAVE);
|
||||
this.key = key;
|
||||
this.pusher = pusher;
|
||||
private AnswerSave(Builder<D> builder) {
|
||||
super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, (builder.hidden) ? UnitActiveType.AFTER : UnitActiveType.DEFAULT, TypeUnit.SAVE);
|
||||
maintenanceNextUnit(nextUnits);
|
||||
this.preservable = preservable;
|
||||
this.preservableData = preservableData;
|
||||
this.hidden = Optional.of(hidden).orElse(false);
|
||||
this.checkSave = checkSave;
|
||||
preservable = builder.preservable;
|
||||
key = builder.key;
|
||||
pusher = builder.pusher;
|
||||
preservableData = builder.preservableData;
|
||||
hidden = builder.hidden;
|
||||
checkSave = builder.checkSave;
|
||||
}
|
||||
|
||||
public static <D> Builder<D> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
private void maintenanceNextUnit(Collection<MainUnit> units) {
|
||||
@ -83,4 +66,121 @@ public class AnswerSave<D> extends MainUnit {
|
||||
}
|
||||
}
|
||||
|
||||
public Preservable<D> getPreservable() {
|
||||
return preservable;
|
||||
}
|
||||
|
||||
public String getKey() {
|
||||
return key;
|
||||
}
|
||||
|
||||
public Pusher<D> getPusher() {
|
||||
return pusher;
|
||||
}
|
||||
|
||||
public PreservableData<D, ? super Message> getPreservableData() {
|
||||
return preservableData;
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
return hidden;
|
||||
}
|
||||
|
||||
public CheckSave<? super Message> getCheckSave() {
|
||||
return checkSave;
|
||||
}
|
||||
|
||||
public static final class Builder<D> {
|
||||
private Set<String> keyWords;
|
||||
private String phrase;
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private Set<MainUnit> nextUnits;
|
||||
private Preservable<D> preservable;
|
||||
private String key;
|
||||
private Pusher<D> pusher;
|
||||
private PreservableData<D, ? super Message> preservableData;
|
||||
private boolean hidden;
|
||||
private CheckSave<? super Message> checkSave;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder<D> keyWords(Set<String> val) {
|
||||
keyWords = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> keyWord(String val) {
|
||||
keyWords.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> phrase(String val) {
|
||||
phrase = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> pattern(Pattern val) {
|
||||
pattern = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> priority(Integer val) {
|
||||
priority = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> nextUnits(Set<MainUnit> val) {
|
||||
nextUnits = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> nextUnit(MainUnit val) {
|
||||
nextUnits.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> preservable(Preservable<D> val) {
|
||||
this.preservable = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> key(String val) {
|
||||
this.key = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> pusher(Pusher<D> val) {
|
||||
this.pusher = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> preservableData(PreservableData<D, ? super Message> val) {
|
||||
this.preservableData = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> hidden(boolean val) {
|
||||
this.hidden = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> checkSave(CheckSave<? super Message> val) {
|
||||
this.checkSave = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerSave<D> build() {
|
||||
return new AnswerSave<>(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -2,25 +2,23 @@ package dev.struchkov.godfather.core.domain.unit;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.exception.UnitConfigException;
|
||||
import dev.struchkov.godfather.context.service.sender.Sending;
|
||||
import dev.struchkov.godfather.context.service.usercode.Insert;
|
||||
import dev.struchkov.godfather.context.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.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||
|
||||
/**
|
||||
* Используется для отправки ответа пользователю.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AnswerText<M extends Message> extends MainUnit {
|
||||
|
||||
/**
|
||||
@ -31,34 +29,122 @@ public class AnswerText<M extends Message> extends MainUnit {
|
||||
/**
|
||||
* Информация, которую необходимо вставить вместо маркеров в строку ответа.
|
||||
*/
|
||||
private final Insert insert;
|
||||
private Insert insert;
|
||||
|
||||
/**
|
||||
* Объект нестандартной отправки ответа.
|
||||
*/
|
||||
private final Sending sending;
|
||||
private Sending sending;
|
||||
|
||||
@Builder(toBuilder = true)
|
||||
private AnswerText(
|
||||
@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> nextUnits,
|
||||
UnitActiveType activeType,
|
||||
ProcessingData<M> boxAnswer,
|
||||
Insert insert,
|
||||
Sending sending
|
||||
) {
|
||||
super(keyWords, phrase, pattern, matchThreshold, priority, nextUnits, activeType, TypeUnit.TEXT);
|
||||
private AnswerText(Builder<M> builder) {
|
||||
super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, builder.activeType, TypeUnit.TEXT);
|
||||
keyWords = builder.keyWords;
|
||||
phrase = builder.phrase;
|
||||
pattern = builder.pattern;
|
||||
matchThreshold = builder.matchThreshold;
|
||||
priority = builder.priority;
|
||||
nextUnits = builder.nextUnits;
|
||||
boxAnswer = builder.boxAnswer;
|
||||
insert = builder.insert;
|
||||
sending = builder.sending;
|
||||
activeType = builder.activeType;
|
||||
}
|
||||
|
||||
public static <M extends Message> AnswerText<M> of(String message) {
|
||||
return AnswerText.<M>builder().boxAnswer(BoxAnswer.processing(message)).build();
|
||||
}
|
||||
|
||||
public static <M extends Message> Builder<M> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
public ProcessingData<M> getBoxAnswer() {
|
||||
return boxAnswer;
|
||||
}
|
||||
|
||||
public Insert getInsert() {
|
||||
return insert;
|
||||
}
|
||||
|
||||
public Sending getSending() {
|
||||
return sending;
|
||||
}
|
||||
|
||||
public static final class Builder<M extends Message> {
|
||||
private ProcessingData<M> boxAnswer;
|
||||
private Insert insert;
|
||||
private Sending sending;
|
||||
private Set<String> keyWords;
|
||||
private String phrase;
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private Set<MainUnit> nextUnits = new HashSet<>();
|
||||
private UnitActiveType activeType;
|
||||
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder<M> boxAnswer(ProcessingData<M> boxAnswer) {
|
||||
this.boxAnswer = boxAnswer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> insert(Insert insert) {
|
||||
this.insert = insert;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> sending(Sending sending) {
|
||||
this.sending = sending;
|
||||
return this;
|
||||
}
|
||||
|
||||
public static AnswerText of(String message) {
|
||||
return builder().boxAnswer(BoxAnswer.processing(message)).build();
|
||||
public Builder<M> keyWords(Set<String> val) {
|
||||
keyWords = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> phrase(String val) {
|
||||
phrase = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> pattern(Pattern val) {
|
||||
pattern = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> priority(Integer val) {
|
||||
priority = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> nextUnits(Set<MainUnit> val) {
|
||||
nextUnits = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> nextUnit(MainUnit val) {
|
||||
nextUnits.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> activeType(UnitActiveType val) {
|
||||
activeType = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerText<M> build() {
|
||||
isNotNull(boxAnswer, UnitConfigException.unitConfigException("BoxAnswer обязательный параметр юнита"));
|
||||
return new AnswerText<>(this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,21 @@
|
||||
package dev.struchkov.godfather.core.domain.unit;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.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;
|
||||
|
||||
import static dev.struchkov.godfather.context.exception.UnitConfigException.unitConfigException;
|
||||
import static dev.struchkov.haiti.utils.Inspector.isNotNull;
|
||||
|
||||
/**
|
||||
* Обработчик таймер, позволяющий отложить обработку других Unit-ов.
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AnswerTimer extends MainUnit {
|
||||
public class AnswerTimer<M extends Message> extends MainUnit {
|
||||
|
||||
/**
|
||||
* Unit обработку которого необходимо отложить.
|
||||
@ -39,27 +35,107 @@ public class AnswerTimer extends MainUnit {
|
||||
/**
|
||||
* Условие срабатывания отложенного Unit.
|
||||
*/
|
||||
private final CheckData checkLoop;
|
||||
private final CheckData<M> checkLoop;
|
||||
|
||||
private AnswerTimer(Builder<M> builder) {
|
||||
super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, null, builder.activeType, TypeUnit.TIMER);
|
||||
unitAnswer = builder.unitAnswer;
|
||||
timeDelaySec = builder.timeDelaySec;
|
||||
timeDeathSec = builder.timeDeathSec;
|
||||
checkLoop = builder.checkLoop;
|
||||
}
|
||||
|
||||
public static <M extends Message> Builder<M> builder() {
|
||||
return new Builder<>();
|
||||
}
|
||||
|
||||
public MainUnit getUnitAnswer() {
|
||||
return unitAnswer;
|
||||
}
|
||||
|
||||
public Integer getTimeDelaySec() {
|
||||
return timeDelaySec;
|
||||
}
|
||||
|
||||
public Integer getTimeDeathSec() {
|
||||
return timeDeathSec;
|
||||
}
|
||||
|
||||
public CheckData<M> getCheckLoop() {
|
||||
return checkLoop;
|
||||
}
|
||||
|
||||
public static final class Builder<M extends Message> {
|
||||
private MainUnit unitAnswer;
|
||||
private Integer timeDelaySec;
|
||||
private Integer timeDeathSec;
|
||||
private CheckData<M> checkLoop;
|
||||
private Set<String> keyWords;
|
||||
private String phrase;
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private UnitActiveType activeType = UnitActiveType.AFTER;
|
||||
|
||||
private Builder() {
|
||||
|
||||
}
|
||||
|
||||
public Builder<M> unitAnswer(MainUnit val) {
|
||||
unitAnswer = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> timeDelaySec(Integer val) {
|
||||
timeDelaySec = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> timeDeathSec(Integer val) {
|
||||
timeDeathSec = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> checkLoop(CheckData<M> val) {
|
||||
checkLoop = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> keyWords(Set<String> val) {
|
||||
keyWords = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> phrase(String val) {
|
||||
phrase = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> pattern(Pattern val) {
|
||||
pattern = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> priority(Integer val) {
|
||||
priority = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> activeType(UnitActiveType val) {
|
||||
activeType = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerTimer<M> build() {
|
||||
isNotNull(unitAnswer, unitConfigException("Необходимо указать юнит, обработка которого будет отложена."));
|
||||
return new AnswerTimer<>(this);
|
||||
}
|
||||
|
||||
@Builder
|
||||
private AnswerTimer(
|
||||
@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,11 +4,6 @@ import dev.struchkov.godfather.core.service.ClarificationQuestion;
|
||||
import dev.struchkov.godfather.core.service.save.LocalPreservable;
|
||||
import dev.struchkov.godfather.core.service.save.Preservable;
|
||||
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;
|
||||
@ -18,9 +13,6 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@Getter
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class AnswerValidity extends MainUnit {
|
||||
|
||||
/**
|
||||
@ -42,24 +34,121 @@ public class AnswerValidity extends MainUnit {
|
||||
|
||||
private final ClarificationQuestion clarificationQuestion;
|
||||
|
||||
@Builder(toBuilder = true)
|
||||
private AnswerValidity(
|
||||
@Singular Set<String> keyWords,
|
||||
String phrase,
|
||||
Pattern pattern,
|
||||
Integer matchThreshold,
|
||||
Integer priority,
|
||||
@Singular Set<MainUnit> nextUnits,
|
||||
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;
|
||||
private AnswerValidity(Builder builder) {
|
||||
super(builder.keyWords, builder.phrase, builder.pattern, builder.matchThreshold, builder.priority, builder.nextUnits, UnitActiveType.DEFAULT, TypeUnit.VALIDITY);
|
||||
unitYes = builder.unitYes;
|
||||
unitNo = builder.unitNo;
|
||||
unitNull = builder.unitNull;
|
||||
clarificationQuestion = builder.clarificationQuestion;
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
public MainUnit getUnitYes() {
|
||||
return unitYes;
|
||||
}
|
||||
|
||||
public MainUnit getUnitNo() {
|
||||
return unitNo;
|
||||
}
|
||||
|
||||
public MainUnit getUnitNull() {
|
||||
return unitNull;
|
||||
}
|
||||
|
||||
public Preservable<String> getTempSave() {
|
||||
return tempSave;
|
||||
}
|
||||
|
||||
public ClarificationQuestion getClarificationQuestion() {
|
||||
return clarificationQuestion;
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
private MainUnit unitYes;
|
||||
private MainUnit unitNo;
|
||||
private MainUnit unitNull;
|
||||
private ClarificationQuestion clarificationQuestion;
|
||||
private Set<String> keyWords;
|
||||
private String phrase;
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private Set<MainUnit> nextUnits;
|
||||
|
||||
private Builder() {
|
||||
}
|
||||
|
||||
public Builder unitYes(MainUnit val) {
|
||||
unitYes = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder unitNo(MainUnit val) {
|
||||
unitNo = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder unitNull(MainUnit val) {
|
||||
unitNull = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clarificationQuestion(ClarificationQuestion val) {
|
||||
clarificationQuestion = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyWords(Set<String> val) {
|
||||
keyWords = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder keyWord(String val) {
|
||||
keyWords.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder phrase(String val) {
|
||||
phrase = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder pattern(Pattern val) {
|
||||
pattern = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder priority(Integer val) {
|
||||
priority = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nextUnits(Set<MainUnit> val) {
|
||||
nextUnits = val;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder nextUnit(MainUnit val) {
|
||||
nextUnits.add(val);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder clearKeyWords() {
|
||||
nextUnits.clear();
|
||||
return this;
|
||||
}
|
||||
|
||||
public AnswerValidity build() {
|
||||
return new AnswerValidity(this);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,11 +1,8 @@
|
||||
package dev.struchkov.godfather.core.domain.unit;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import org.sadtech.autoresponder.entity.Unit;
|
||||
import dev.struchkov.autoresponder.entity.Unit;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
@ -16,25 +13,19 @@ import java.util.regex.Pattern;
|
||||
*
|
||||
* @author upagge [08/07/2019]
|
||||
*/
|
||||
@ToString
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class MainUnit extends Unit<MainUnit> {
|
||||
|
||||
/**
|
||||
* Тип Unit-а.
|
||||
*/
|
||||
@Getter
|
||||
protected final String type;
|
||||
|
||||
/**
|
||||
* Режим срабатывания Unit-а.
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
protected UnitActiveType activeType;
|
||||
|
||||
@Getter
|
||||
private String uuid = UUID.randomUUID().toString();
|
||||
private final String uuid = UUID.randomUUID().toString();
|
||||
|
||||
protected MainUnit(
|
||||
Set<String> keyWords,
|
||||
@ -51,4 +42,34 @@ public abstract class MainUnit extends Unit<MainUnit> {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setActiveType(UnitActiveType activeType) {
|
||||
this.activeType = activeType;
|
||||
}
|
||||
|
||||
public UnitActiveType getActiveType() {
|
||||
return activeType;
|
||||
}
|
||||
|
||||
public String getUuid() {
|
||||
return uuid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
MainUnit mainUnit = (MainUnit) o;
|
||||
return Objects.equals(type, mainUnit.type) && activeType == mainUnit.activeType && Objects.equals(uuid, mainUnit.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), type, activeType, uuid);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,8 @@ 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@ -12,9 +13,10 @@ import java.util.Optional;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@Slf4j
|
||||
public class AnswerCheckAction implements ActionUnit<AnswerCheck, Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AnswerCheckAction.class);
|
||||
|
||||
@Override
|
||||
public MainUnit action(AnswerCheck answerCheck, Message mail) {
|
||||
MainUnit unitAnswer;
|
||||
|
@ -22,7 +22,7 @@ public class AnswerProcessingAction implements ActionUnit<AnswerProcessing<Messa
|
||||
|
||||
@Override
|
||||
public MainUnit action(AnswerProcessing<Message> answerProcessing, Message message) {
|
||||
BoxAnswer boxAnswer = answerProcessing.getProcessingData().processing(message);
|
||||
final BoxAnswer boxAnswer = answerProcessing.getProcessingData().processing(message);
|
||||
|
||||
Sending answerProcessingSending = answerProcessing.getSending();
|
||||
if (answerProcessingSending != null) {
|
||||
|
@ -7,8 +7,6 @@ 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;
|
||||
|
||||
@ -17,22 +15,20 @@ import java.util.List;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class AnswerTextAction implements ActionUnit<AnswerText, Message> {
|
||||
public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message> {
|
||||
|
||||
private Sending sending;
|
||||
private final Sending sending;
|
||||
|
||||
@Override
|
||||
public MainUnit action(AnswerText answerText, Message message) {
|
||||
BoxAnswer boxAnswer = answerText.getBoxAnswer().processing(message);
|
||||
if (answerText.getInsert() != null) {
|
||||
List<String> words = answerText.getInsert().insert(message.getPersonId());
|
||||
String newMessage = InsertWords.insert(boxAnswer.getMessage(), words);
|
||||
boxAnswer.setMessage(newMessage);
|
||||
public AnswerTextAction(Sending sending) {
|
||||
this.sending = sending;
|
||||
}
|
||||
|
||||
Sending answerTextSending = answerText.getSending();
|
||||
@Override
|
||||
public MainUnit action(AnswerText<Message> answerText, Message message) {
|
||||
final BoxAnswer boxAnswer = answerText.getBoxAnswer().processing(message);
|
||||
replaceMarkers(answerText, message, boxAnswer);
|
||||
|
||||
final Sending answerTextSending = answerText.getSending();
|
||||
if (answerTextSending != null) {
|
||||
Sender.sends(message, boxAnswer, answerTextSending);
|
||||
} else {
|
||||
@ -42,5 +38,13 @@ public class AnswerTextAction implements ActionUnit<AnswerText, Message> {
|
||||
return answerText;
|
||||
}
|
||||
|
||||
private void replaceMarkers(AnswerText<Message> answerText, Message message, BoxAnswer boxAnswer) {
|
||||
if (answerText.getInsert() != null) {
|
||||
final List<String> words = answerText.getInsert().insert(message.getPersonId());
|
||||
final String newMessage = InsertWords.insert(boxAnswer.getMessage(), words);
|
||||
boxAnswer.setMessage(newMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ public class AnswerTimerAction implements ActionUnit<AnswerTimer, Message> {
|
||||
.ofNullable(answerTimer.getTimeDelaySec())
|
||||
.orElseThrow(() -> new TimerSettingException("Не установлена временная задержка таймера")));
|
||||
|
||||
Timer.TimerBuilder timer = Timer.builder()
|
||||
Timer.Builder timer = Timer.builder()
|
||||
.personId(message.getPersonId())
|
||||
.unitAnswer(answerTimer.getUnitAnswer())
|
||||
.timeActive(timeActive)
|
||||
|
@ -39,7 +39,7 @@ public class AnswerValidityAction implements ActionUnit<AnswerValidity, Message>
|
||||
return unit.getUnitNull();
|
||||
} else {
|
||||
unit.getTempSave().save(personId, "temp", value);
|
||||
AnswerValidity newValidity = unit.toBuilder()
|
||||
AnswerValidity newValidity = unit.builder()
|
||||
.clearKeyWords().keyWords(WORDS_YES_NO)
|
||||
.build();
|
||||
return AnswerText.builder()
|
||||
|
@ -1,7 +1,7 @@
|
||||
package dev.struchkov.godfather.core.service.save.data;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.core.utils.Pair;
|
||||
import dev.struchkov.haiti.utils.Pair;
|
||||
|
||||
/**
|
||||
* TODO: Добавить описание класса.
|
||||
|
@ -1,23 +0,0 @@
|
||||
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<R extends JpaRepository<D, Long>, D extends SaveObjectJpa> implements Preservable<D> {
|
||||
//
|
||||
// protected final R jpaRepository;
|
||||
//
|
||||
// @Override
|
||||
// public void save(Long personId, String key, R save) {
|
||||
// save.setPersonId(personId);
|
||||
// jpaRepository.save(save);
|
||||
// }
|
||||
//
|
||||
//}
|
@ -1,25 +0,0 @@
|
||||
package dev.struchkov.godfather.core.service.save.jpa;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.BasicEntity;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.MappedSuperclass;
|
||||
|
||||
/**
|
||||
* TODO: Добавить описание класса.
|
||||
*
|
||||
* @author upagge [01/08/2019]
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
@MappedSuperclass
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public abstract class SaveObjectJpa extends BasicEntity {
|
||||
|
||||
@Column(name = "personId")
|
||||
private Long personId;
|
||||
|
||||
}
|
@ -1,125 +0,0 @@
|
||||
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<String> {
|
||||
|
||||
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<String, String> saveElement) {
|
||||
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append("<table cellspacing=\"0\" cellpadding=\"0\" width=\"600\" bgcolor=\"#FFFFFF\">\n" +
|
||||
" <tbody>\n" +
|
||||
" <tr>\n" +
|
||||
" <td>\n" +
|
||||
" <table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n" +
|
||||
" <tbody>\n" +
|
||||
" <tr>\n" +
|
||||
" <td width=\"149\" valign=\"top\" bgcolor=\"#476695\" style=\"border-radius: 5px 0px 0px 0px;\"> </td>\n" +
|
||||
" <td width=\"100%\" bgcolor=\"#476695\" valign=\"top\" style=\"border-radius: 0px 5px 0px 0px;\"> </td>\n" +
|
||||
" </tr>\n" +
|
||||
" </tbody>\n" +
|
||||
" </table>\n" +
|
||||
" </td>\n" +
|
||||
" </tr>\n" +
|
||||
" <tr>\n" +
|
||||
" <td>\n" +
|
||||
" <div style=\"padding:18px 18px 13px 18px;border-left:1px solid #dadee3;border-right:1px solid #dadee3;font-size:12px;color:black;\">\n" +
|
||||
" <h1 style=\"margin:2px 0px 15px 0;padding:0px 0px 4px;border-bottom:1px solid #D8DFE6;color:#45668E;font-size:100%;\">")
|
||||
.append(nameForm)
|
||||
.append("</h1>\n" +
|
||||
" <div style=\"line-height:160%;\">\n" +
|
||||
" <table cellspacing=\"0\" cellpadding=\"0\" border=\"0\">\n" +
|
||||
" <tbody>");
|
||||
for (Map.Entry<String, String> element : saveElement.entrySet()) {
|
||||
stringBuilder.append("<tr>\n" +
|
||||
" <td valign=\"top\" style=\"padding-right:10px;color:#808080\">")
|
||||
.append(element.getKey())
|
||||
.append(":\n" +
|
||||
" </td>\n" +
|
||||
" <td style=\"padding-bottom:6px\">")
|
||||
.append(element.getValue())
|
||||
.append("</td></tr>");
|
||||
}
|
||||
stringBuilder.append("</tbody>\n" +
|
||||
" </table>\n" +
|
||||
" \n" +
|
||||
" </div>\n" +
|
||||
" </div>\n" +
|
||||
" </td>\n" +
|
||||
" </tr>\n" +
|
||||
" <tr>\n" +
|
||||
" <td>\n" +
|
||||
" <table cellspacing=\"0\" cellpadding=\"0\" width=\"100%\">\n" +
|
||||
" <tbody>\n" +
|
||||
" <tr>\n" +
|
||||
" <td width=\"3\">\n" +
|
||||
" <div style=\"width:0;height:1px;max-height:1px;line-height:1px;font-size:0;border-left:1px solid #e6e7eb;border-right:1px solid #e8ebed;\"></div>\n" +
|
||||
" <div style=\"width:0;height:1px;max-height:1px;line-height:1px;font-size:0;border-left:1px solid #f5f5f5;border-right:1px solid #e6e7eb;\"></div>\n" +
|
||||
" </td>\n" +
|
||||
" <td width=\"100%\" valign=\"bottom\">\n" +
|
||||
" <div style=\"height:1px;max-height:1px;line-height:0;font-size:0;border-bottom:1px solid #dadee3;\"> </div>\n" +
|
||||
" </td>\n" +
|
||||
" <td width=\"3\" align=\"right\">\n" +
|
||||
" <div style=\"width:0;height:1px;max-height:1px;line-height:1px;font-size:0;border-left:1px solid #e8ebed;border-right:1px solid #e6e7eb;\"></div>\n" +
|
||||
" <div style=\"width:0;height:1px;max-height:1px;line-height:1px;font-size:0;border-left:1px solid #e6e7eb;border-right:1px solid #f5f5f5;\"></div>\n" +
|
||||
" </td>\n" +
|
||||
" </tr>\n" +
|
||||
" </tbody>\n" +
|
||||
" </table>\n" +
|
||||
" </td>\n" +
|
||||
" </tr>\n" +
|
||||
" <tr>\n" +
|
||||
" <td bgcolor=\"#ffffff\" align=\"center\" style=\"padding:13px 0 0 0;font-size:12px;color:#888888;\"></td>\n" +
|
||||
" </tr>\n" +
|
||||
" </tbody>\n" +
|
||||
" </table>");
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
package dev.struchkov.godfather.core.service.timer;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.service.usercode.CheckData;
|
||||
import dev.struchkov.godfather.context.utils.MessageUtils;
|
||||
import dev.struchkov.godfather.core.GeneralAutoResponder;
|
||||
import dev.struchkov.godfather.core.domain.Timer;
|
||||
import dev.struchkov.godfather.context.service.usercode.CheckData;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.time.LocalDateTime;
|
||||
@ -17,9 +18,10 @@ import java.util.TimerTask;
|
||||
*
|
||||
* @author upagge [11/07/2019]
|
||||
*/
|
||||
@Slf4j
|
||||
public class TimerActionTask extends TimerTask {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TimerActionTask.class);
|
||||
|
||||
private final TimerService timerService;
|
||||
private final GeneralAutoResponder generalAutoresponder;
|
||||
|
||||
|
@ -2,19 +2,23 @@ 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 org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class TimerServiceImpl implements TimerService {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(TimerServiceImpl.class);
|
||||
|
||||
private final TimerRepository timerRepository;
|
||||
|
||||
public TimerServiceImpl(TimerRepository timerRepository) {
|
||||
this.timerRepository = timerRepository;
|
||||
}
|
||||
|
||||
public TimerRepository getTimerRepository() {
|
||||
return timerRepository;
|
||||
}
|
||||
|
@ -1,17 +0,0 @@
|
||||
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<K, D> {
|
||||
|
||||
private K key;
|
||||
private D value;
|
||||
|
||||
}
|
@ -1,95 +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<QuestionResult> preservable;
|
||||
private final List<Question> questions;
|
||||
private Pusher<QuestionResult> pusher;
|
||||
|
||||
private QuestionUtils(List<Question> questions, Preservable<QuestionResult> preservable) {
|
||||
this.questions = questions;
|
||||
this.preservable = preservable;
|
||||
}
|
||||
|
||||
private QuestionUtils(List<Question> questions, Preservable<QuestionResult> preservable, Pusher<QuestionResult> pusher) {
|
||||
this.questions = questions;
|
||||
this.preservable = preservable;
|
||||
this.pusher = pusher;
|
||||
}
|
||||
|
||||
public static QuestionUtils builder(Preservable<QuestionResult> preservable, List<Question> questions) {
|
||||
return new QuestionUtils(questions, preservable);
|
||||
}
|
||||
|
||||
public static QuestionUtils builder(Preservable<QuestionResult> preservable, Pusher<QuestionResult> pusher, List<Question> 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<String> 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(message -> boxAnswer);
|
||||
|
||||
for (QuestionAnswer questionAnswer : question.getQuestionAnswers()) {
|
||||
AnswerSave.AnswerSaveBuilder answerSaveBuilder = AnswerSave.<QuestionResult>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;
|
||||
}
|
||||
|
||||
}
|
||||
//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<QuestionResult> preservable;
|
||||
// private final List<Question> questions;
|
||||
// private Pusher<QuestionResult> pusher;
|
||||
//
|
||||
// private QuestionUtils(List<Question> questions, Preservable<QuestionResult> preservable) {
|
||||
// this.questions = questions;
|
||||
// this.preservable = preservable;
|
||||
// }
|
||||
//
|
||||
// private QuestionUtils(List<Question> questions, Preservable<QuestionResult> preservable, Pusher<QuestionResult> pusher) {
|
||||
// this.questions = questions;
|
||||
// this.preservable = preservable;
|
||||
// this.pusher = pusher;
|
||||
// }
|
||||
//
|
||||
// public static QuestionUtils builder(Preservable<QuestionResult> preservable, List<Question> questions) {
|
||||
// return new QuestionUtils(questions, preservable);
|
||||
// }
|
||||
//
|
||||
// public static QuestionUtils builder(Preservable<QuestionResult> preservable, Pusher<QuestionResult> pusher, List<Question> 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<String> collectAnswer = question.getQuestionAnswers().stream()
|
||||
// .map(QuestionAnswer::getText)
|
||||
// .collect(Collectors.toList());
|
||||
// BoxAnswer boxAnswer = question.getBoxAnswer().toBuilder()
|
||||
// .keyBoard(KeyBoards.verticalDuoMenuString(collectAnswer)).build();
|
||||
//
|
||||
// AnswerText.Builder answerTextBuilder = AnswerText.builder()
|
||||
// .boxAnswer(message -> boxAnswer);
|
||||
//
|
||||
// for (QuestionAnswer questionAnswer : question.getQuestionAnswers()) {
|
||||
// AnswerSave.AnswerSaveBuilder answerSaveBuilder = AnswerSave.<QuestionResult>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;
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
66
pom.xml
66
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.4-SNAPSHOT</version>
|
||||
<version>0.0.4</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
@ -32,41 +32,46 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<godfather.context.ver>0.0.4-SNAPSHOT</godfather.context.ver>
|
||||
<godfather.core.ver>0.0.4-SNAPSHOT</godfather.core.ver>
|
||||
<autoresponder.ver>1.9.4-RELEASE</autoresponder.ver>
|
||||
<godfather.ver>0.0.4</godfather.ver>
|
||||
|
||||
<godfather.context.ver>${godfather.ver}</godfather.context.ver>
|
||||
<godfather.core.ver>${godfather.ver}</godfather.core.ver>
|
||||
|
||||
<autoresponder.ver>2.0.0</autoresponder.ver>
|
||||
<haiti.utils>1.0.2</haiti.utils>
|
||||
|
||||
<gson.ver>2.9.0</gson.ver>
|
||||
<mail.ver>1.6.2</mail.ver>
|
||||
<lombok.ver>1.18.22</lombok.ver>
|
||||
<javax.persistence.api.ver>2.2</javax.persistence.api.ver>
|
||||
<validation.api.ver>2.0.1.Final</validation.api.ver>
|
||||
<slf4j.api.ver>1.7.36</slf4j.api.ver>
|
||||
<jetbrains.annotations.ver>23.0.0</jetbrains.annotations.ver>
|
||||
|
||||
<plugin.maven.compiler.ver>3.9.0</plugin.maven.compiler.ver>
|
||||
<plugin.nexus.staging.ver>1.6.12</plugin.nexus.staging.ver>
|
||||
<plugin.maven.compiler.ver>3.10.1</plugin.maven.compiler.ver>
|
||||
<plugin.nexus.staging.ver>1.6.13</plugin.nexus.staging.ver>
|
||||
<plugin.maven.source.ver>3.2.1</plugin.maven.source.ver>
|
||||
<plugin.maven.javadoc.ver>3.3.2</plugin.maven.javadoc.ver>
|
||||
<plugin.maven.javadoc.ver>3.4.0</plugin.maven.javadoc.ver>
|
||||
<plugin.maven.gpg.ver>3.0.1</plugin.maven.gpg.ver>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.google.code.gson</groupId>
|
||||
<artifactId>gson</artifactId>
|
||||
<version>${gson.ver}</version>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-context</artifactId>
|
||||
<version>${godfather.core.ver}</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>dev.struchkov</groupId>
|
||||
<artifactId>autoresponder</artifactId>
|
||||
<version>${autoresponder.ver}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>javax.mail-api</artifactId>
|
||||
<version>${mail.ver}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.ver}</version>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-utils</artifactId>
|
||||
<version>${haiti.utils}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>javax.persistence</groupId>
|
||||
<artifactId>javax.persistence-api</artifactId>
|
||||
@ -78,15 +83,9 @@
|
||||
<version>${validation.api.ver}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-context</artifactId>
|
||||
<version>${godfather.core.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech.autoresponder</groupId>
|
||||
<artifactId>autoresponder</artifactId>
|
||||
<version>${autoresponder.ver}</version>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>${jetbrains.annotations.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -118,13 +117,6 @@
|
||||
<configuration>
|
||||
<source>${java.version}</source>
|
||||
<target>${java.version}</target>
|
||||
<annotationProcessorPaths>
|
||||
<path>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>${lombok.ver}</version>
|
||||
</path>
|
||||
</annotationProcessorPaths>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
Loading…
Reference in New Issue
Block a user