From 6f64494504408ba50a624a8495434fa21244b118 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Tue, 13 Dec 2022 21:52:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=20=D1=83=D1=81=D1=82=D0=B0=D0=BD=D0=B0=D0=B2=D0=BB=D0=B8?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BF=D0=BE=D0=BB=D1=83=D1=87=D0=B0?= =?UTF-8?q?=D1=82=D0=B5=D0=BB=D1=8F=20=D0=B2=20BoxAnswer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quarkus/context/service/Sending.java | 5 +-- .../simple/context/service/Sending.java | 5 +-- .../core/action/AnswerCheckAction.java | 15 ++++++- .../quarkus/core/action/AnswerTextAction.java | 6 +-- .../godfather/quarkus/core/utils/Sender.java | 40 ------------------- .../simple/core/action/AnswerCheckAction.java | 10 ++++- .../simple/core/action/AnswerTextAction.java | 6 +-- .../simple/core/pusher/UserSanderPusher.java | 5 ++- .../godfather/simple/core/utils/Sender.java | 34 ---------------- .../godfather/main/domain/BoxAnswer.java | 28 +++++++++++++ 10 files changed, 63 insertions(+), 91 deletions(-) delete mode 100644 bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java delete mode 100644 bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/utils/Sender.java diff --git a/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/Sending.java b/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/Sending.java index 4210d5b..c04e0b4 100644 --- a/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/Sending.java +++ b/bot-context/bot-context-quarkus/src/main/java/dev/struchkov/godfather/quarkus/context/service/Sending.java @@ -13,12 +13,11 @@ import org.jetbrains.annotations.NotNull; public interface Sending { /** - * Отрпавляет ответ пользователю + * Отправляет сообщение пользователю * - * @param personId Идентификатор пользователя * @param boxAnswer Объект с данными, которые необходимо отправить */ - Uni send(@NotNull String personId, @NotNull BoxAnswer boxAnswer); + Uni send(@NotNull BoxAnswer boxAnswer); void addPreSendProcess(@NotNull PreSendProcessing processing); diff --git a/bot-context/bot-context-simple/src/main/java/dev/struchkov/godfather/simple/context/service/Sending.java b/bot-context/bot-context-simple/src/main/java/dev/struchkov/godfather/simple/context/service/Sending.java index c9dc0ee..c2eb819 100644 --- a/bot-context/bot-context-simple/src/main/java/dev/struchkov/godfather/simple/context/service/Sending.java +++ b/bot-context/bot-context-simple/src/main/java/dev/struchkov/godfather/simple/context/service/Sending.java @@ -12,12 +12,11 @@ import org.jetbrains.annotations.NotNull; public interface Sending { /** - * Отрпавляет ответ пользователю + * Отравляет сообщение пользователю. * - * @param personId Идентификатор пользователя * @param boxAnswer Объект с данными, которые необходимо отправить */ - void send(@NotNull String personId, @NotNull BoxAnswer boxAnswer); + void send(@NotNull BoxAnswer boxAnswer); void addPreSendProcess(@NotNull PreSendProcessing processing); diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerCheckAction.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerCheckAction.java index c60e7f9..18ef5b4 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerCheckAction.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerCheckAction.java @@ -1,5 +1,6 @@ package dev.struchkov.godfather.quarkus.core.action; +import dev.struchkov.godfather.main.domain.BoxAnswer; import dev.struchkov.godfather.main.domain.content.Message; import dev.struchkov.godfather.quarkus.context.service.Sending; import dev.struchkov.godfather.quarkus.core.unit.AnswerCheck; @@ -9,6 +10,7 @@ import io.smallrye.mutiny.Uni; import java.util.Objects; +import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Checker.checkTrue; /** @@ -32,10 +34,19 @@ public class AnswerCheckAction implements ActionUnit { if (checkTrue(checkValue)) { - return sending.send(message.getPersonId(), unit.getIntermediateAnswerIfTrue()); + final BoxAnswer answerIfTrue = unit.getIntermediateAnswerIfTrue(); + if (checkNotNull(answerIfTrue)) { + answerIfTrue.setRecipientIfNull(message.getPersonId()); + return sending.send(answerIfTrue); + } } else { - return sending.send(message.getPersonId(), unit.getIntermediateAnswerIfFalse()); + final BoxAnswer answerIfFalse = unit.getIntermediateAnswerIfFalse(); + if (checkNotNull(answerIfFalse)) { + answerIfFalse.setRecipientIfNull(message.getPersonId()); + return sending.send(answerIfFalse); + } } + return Uni.createFrom().voidItem(); }) .onItem().transform( checkValue -> { diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java index 74c8609..085b27e 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/action/AnswerTextAction.java @@ -7,7 +7,6 @@ import dev.struchkov.godfather.quarkus.context.service.Sending; import dev.struchkov.godfather.quarkus.core.unit.AnswerText; import dev.struchkov.godfather.quarkus.core.unit.MainUnit; import dev.struchkov.godfather.quarkus.core.unit.UnitRequest; -import dev.struchkov.godfather.quarkus.core.utils.Sender; import io.smallrye.mutiny.Uni; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; @@ -35,10 +34,11 @@ public class AnswerTextAction implements ActionUnit, Message .onItem().ifNotNull().transformToUni(boxAnswer -> replaceMarkers(unit, message, boxAnswer)) .onItem().ifNotNull().transformToUni(boxAnswer -> { final Sending answerTextSending = unit.getSending(); + boxAnswer.setRecipientIfNull(message.getPersonId()); if (checkNotNull(answerTextSending)) { - return Sender.sends(message, boxAnswer, answerTextSending); + return answerTextSending.send(boxAnswer); } else { - return Sender.sends(message, boxAnswer, this.sending); + return sending.send(boxAnswer); } }).replaceWith(UnitRequest.of(unit, message)); } diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java deleted file mode 100644 index 5293528..0000000 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/utils/Sender.java +++ /dev/null @@ -1,40 +0,0 @@ -package dev.struchkov.godfather.quarkus.core.utils; - -import dev.struchkov.godfather.main.domain.BoxAnswer; -import dev.struchkov.godfather.main.domain.content.Message; -import dev.struchkov.godfather.quarkus.context.service.Sending; -import io.smallrye.mutiny.Uni; - -import static dev.struchkov.haiti.utils.Exceptions.utilityClass; - -/** - * Используется для отправки сообщений определенного типа. - * - * @author upagge - */ -public class Sender { - - private Sender() { - utilityClass(); - } - - public static Uni sends(Message message, BoxAnswer boxAnswer, Sending sending) { - return Uni.createFrom().item(sending) - .onItem().ifNotNull().transformToUni( - sender -> { - switch (sending.getType()) { - case PUBLIC: - break; - case PRIVATE: - return privateSend(message, boxAnswer, sending); - } - return Uni.createFrom().nullItem(); - } - ).replaceWithVoid(); - } - - private static Uni privateSend(Message message, BoxAnswer boxAnswer, Sending sending) { - return sending.send(message.getPersonId(), boxAnswer); - } - -} diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerCheckAction.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerCheckAction.java index 8933ca3..39d245a 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerCheckAction.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerCheckAction.java @@ -39,12 +39,18 @@ public class AnswerCheckAction implements ActionUnit, Message replaceMarkers(unit, message, answer); final Sending answerTextSending = unit.getSending(); + answer.setRecipientIfNull(message.getPersonId()); if (answerTextSending != null) { - Sender.sends(message, answer, answerTextSending); + answerTextSending.send(answer); } else { - Sender.sends(message, answer, this.sending); + sending.send(answer); } } diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/pusher/UserSanderPusher.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/pusher/UserSanderPusher.java index c6fc223..a5c2351 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/pusher/UserSanderPusher.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/pusher/UserSanderPusher.java @@ -1,5 +1,6 @@ package dev.struchkov.godfather.simple.core.pusher; +import dev.struchkov.godfather.main.domain.BoxAnswer; import dev.struchkov.godfather.simple.context.service.Pusher; import dev.struchkov.godfather.simple.context.service.Sending; @@ -25,7 +26,9 @@ public class UserSanderPusher implements Pusher { stringBuilder.append("========= ").append(nameForm).append(" =========\n"); saveElement.forEach((key, value) -> stringBuilder.append(key).append(": ").append(value).append("\n")); stringBuilder.append("===================="); - sending.send(this.personId, boxAnswer(stringBuilder.toString())); + final BoxAnswer boxAnswer = boxAnswer(stringBuilder.toString()); + boxAnswer.setRecipientIfNull(this.personId); + sending.send(boxAnswer); } } diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/utils/Sender.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/utils/Sender.java deleted file mode 100644 index 265d8ea..0000000 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/utils/Sender.java +++ /dev/null @@ -1,34 +0,0 @@ -package dev.struchkov.godfather.simple.core.utils; - -import dev.struchkov.godfather.main.domain.BoxAnswer; -import dev.struchkov.godfather.main.domain.content.Message; -import dev.struchkov.godfather.simple.context.service.Sending; - -import static dev.struchkov.haiti.utils.Exceptions.utilityClass; - -/** - * Используется для отправки сообщений определенного типа. - * - * @author upagge - */ -public class Sender { - - private Sender() { - utilityClass(); - } - - public static void sends(Message message, BoxAnswer boxAnswer, Sending sending) { - switch (sending.getType()) { - case PUBLIC: - break; - case PRIVATE: - privateSend(message, boxAnswer, sending); - break; - } - } - - private static void privateSend(Message message, BoxAnswer boxAnswer, Sending sending) { - sending.send(message.getPersonId(), boxAnswer); - } - -} diff --git a/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java b/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java index 9e4f426..dacd14b 100644 --- a/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java +++ b/bot-domain/bot-domain-main/src/main/java/dev/struchkov/godfather/main/domain/BoxAnswer.java @@ -2,6 +2,8 @@ package dev.struchkov.godfather.main.domain; import dev.struchkov.godfather.main.domain.keyboard.KeyBoard; +import static dev.struchkov.haiti.utils.Checker.checkNull; + /** * Контейнер, которые содержит данные, которые будут отправлены пользователю как ответ на его запрос. * @@ -24,10 +26,16 @@ public class BoxAnswer { */ private String message; + /** + *

Получатель сообщения

+ */ + private String recipientPersonId; + private BoxAnswer(Builder builder) { message = builder.message; keyBoard = builder.keyBoard; replace = builder.replace; + recipientPersonId = builder.recipientPersonId; } public static BoxAnswer boxAnswer(boolean replace, String message) { @@ -78,6 +86,20 @@ public class BoxAnswer { return replace; } + public String getRecipientPersonId() { + return recipientPersonId; + } + + public void setRecipientPersonId(String recipientPersonId) { + this.recipientPersonId = recipientPersonId; + } + + public void setRecipientIfNull(String recipientPersonId) { + if (checkNull(this.recipientPersonId)) { + this.recipientPersonId = recipientPersonId; + } + } + @Override public String toString() { return "BoxAnswer{" + @@ -91,6 +113,7 @@ public class BoxAnswer { private String message; private KeyBoard keyBoard; private boolean replace; + private String recipientPersonId; private Builder() { } @@ -110,6 +133,11 @@ public class BoxAnswer { return this; } + public Builder recipientPersonId(String val) { + recipientPersonId = val; + return this; + } + public BoxAnswer build() { return new BoxAnswer(this); }