From dc2051d85a51b22fbafd470560d2899a81099b8d Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 17 Feb 2023 21:21:29 +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=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B8=D1=82=D1=8C?= =?UTF-8?q?=20=D0=BA=D0=B0=D0=BA=D0=BE=D0=B5-=D0=BD=D0=B8=D0=B1=D1=83?= =?UTF-8?q?=D0=B4=D1=8C=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82=D0=B2=D0=B8=D0=B5?= =?UTF-8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BA=D0=BE=D0=B9=20AnswerText?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quarkus/core/action/AnswerTextAction.java | 8 ++++++++ .../godfather/quarkus/core/unit/AnswerText.java | 14 ++++++++++++++ .../core/unit/func/ActionBeforeSending.java | 10 ++++++++++ .../simple/core/action/AnswerTextAction.java | 7 +++++++ .../godfather/simple/core/unit/AnswerText.java | 17 ++++++++++++++++- .../core/unit/func/ActionBeforeSending.java | 8 ++++++++ 6 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java create mode 100644 bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/func/ActionBeforeSending.java 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 c91cea3..2d1b16e 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 @@ -5,6 +5,7 @@ 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.unit.func.ActionBeforeSending; import dev.struchkov.godfather.quarkus.core.unit.func.CallBackConsumer; import io.smallrye.mutiny.Uni; @@ -29,6 +30,13 @@ public class AnswerTextAction implements ActionUnit, Message final AnswerText unit = unitRequest.getUnit(); return unit.getAnswer().processing(message) + .onItem().ifNotNull().call(v -> { + final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending(); + if (checkNotNull(actionBeforeSending)) { + return actionBeforeSending.execute(); + } + return Uni.createFrom().nullItem(); + }) .onItem().ifNotNull().transformToUni(boxAnswer -> { boxAnswer.setRecipientIfNull(message.getPersonId()); return sending.send(boxAnswer); diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerText.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerText.java index 131427b..591d0c6 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerText.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/AnswerText.java @@ -5,6 +5,7 @@ import dev.struchkov.godfather.main.core.unit.TypeUnit; import dev.struchkov.godfather.main.core.unit.UnitActiveType; import dev.struchkov.godfather.main.domain.content.Message; import dev.struchkov.godfather.quarkus.context.service.Accessibility; +import dev.struchkov.godfather.quarkus.core.unit.func.ActionBeforeSending; import dev.struchkov.godfather.quarkus.core.unit.func.CallBackConsumer; import dev.struchkov.godfather.quarkus.core.unit.func.ProcessingData; import dev.struchkov.godfather.quarkus.domain.BoxAnswer; @@ -38,6 +39,8 @@ public class AnswerText extends MainUnit { */ private final CallBackConsumer callBack; + private final ActionBeforeSending actionBeforeSending; + private AnswerText(Builder builder) { super( builder.name, @@ -56,6 +59,7 @@ public class AnswerText extends MainUnit { ); answer = builder.boxAnswer; callBack = builder.callBack; + actionBeforeSending = builder.actionBeforeSending; } public static AnswerText of(String message) { @@ -78,6 +82,10 @@ public class AnswerText extends MainUnit { return callBack; } + public ActionBeforeSending getActionBeforeSending() { + return actionBeforeSending; + } + public static final class Builder { private String name = UUID.randomUUID().toString(); @@ -98,6 +106,7 @@ public class AnswerText extends MainUnit { private ProcessingData boxAnswer; private CallBackConsumer callBack; + private ActionBeforeSending actionBeforeSending; private Builder() { } @@ -140,6 +149,11 @@ public class AnswerText extends MainUnit { return this; } + public Builder actionBeforeSending(ActionBeforeSending action) { + this.actionBeforeSending = action; + return this; + } + public Builder triggerWords(Set val) { if (triggerWords == null) { triggerWords = new HashSet<>(); diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java new file mode 100644 index 0000000..492e6d3 --- /dev/null +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/unit/func/ActionBeforeSending.java @@ -0,0 +1,10 @@ +package dev.struchkov.godfather.quarkus.core.unit.func; + +import io.smallrye.mutiny.Uni; + +@FunctionalInterface +public interface ActionBeforeSending { + + Uni execute(); + +} diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java index 57799f2..15dd9bc 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/action/AnswerTextAction.java @@ -5,6 +5,7 @@ import dev.struchkov.godfather.simple.context.service.Sending; import dev.struchkov.godfather.simple.core.unit.AnswerText; import dev.struchkov.godfather.simple.core.unit.MainUnit; import dev.struchkov.godfather.simple.core.unit.UnitRequest; +import dev.struchkov.godfather.simple.core.unit.func.ActionBeforeSending; import dev.struchkov.godfather.simple.core.unit.func.CallBackConsumer; import dev.struchkov.godfather.simple.core.unit.func.ProcessingData; import dev.struchkov.godfather.simple.domain.BoxAnswer; @@ -39,6 +40,12 @@ public class AnswerTextAction implements ActionUnit, Message final BoxAnswer answer = optAnswer.get(); answer.setRecipientIfNull(message.getPersonId()); + + final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending(); + if (checkNotNull(actionBeforeSending)) { + actionBeforeSending.execute(message.getPersonId()); + } + final Optional optSentBox = sending.send(answer); final CallBackConsumer callBack = unit.getCallBack(); if (checkNotNull(callBack) && optAnswer.isPresent()) { diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerText.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerText.java index 32c3ba5..b6c0f26 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerText.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/AnswerText.java @@ -5,6 +5,7 @@ import dev.struchkov.godfather.main.core.unit.TypeUnit; import dev.struchkov.godfather.main.core.unit.UnitActiveType; import dev.struchkov.godfather.main.domain.content.Message; import dev.struchkov.godfather.simple.context.service.Accessibility; +import dev.struchkov.godfather.simple.core.unit.func.ActionBeforeSending; import dev.struchkov.godfather.simple.core.unit.func.CallBackConsumer; import dev.struchkov.godfather.simple.core.unit.func.ProcessingData; import dev.struchkov.godfather.simple.domain.BoxAnswer; @@ -35,6 +36,8 @@ public class AnswerText extends MainUnit { private final CallBackConsumer callBack; + private final ActionBeforeSending actionBeforeSending; + private AnswerText(Builder builder) { super( builder.name, @@ -53,6 +56,7 @@ public class AnswerText extends MainUnit { ); answer = builder.boxAnswer; callBack = builder.callBack; + actionBeforeSending = builder.actionBeforeSending; } public static AnswerText of(String message) { @@ -75,6 +79,10 @@ public class AnswerText extends MainUnit { return callBack; } + public ActionBeforeSending getActionBeforeSending() { + return actionBeforeSending; + } + public static final class Builder { private String name = UUID.randomUUID().toString(); @@ -95,6 +103,7 @@ public class AnswerText extends MainUnit { private ProcessingData boxAnswer; private CallBackConsumer callBack; + private ActionBeforeSending actionBeforeSending; private Builder() { } @@ -132,11 +141,16 @@ public class AnswerText extends MainUnit { return this; } - public Builder callBack(CallBackConsumer callBack) { + public Builder callBack(CallBackConsumer callBack) { this.callBack = callBack; return this; } + public Builder actionBeforeSending(ActionBeforeSending action) { + this.actionBeforeSending = action; + return this; + } + public Builder triggerWords(Set val) { if (triggerWords == null) { triggerWords = new HashSet<>(); @@ -239,4 +253,5 @@ public class AnswerText extends MainUnit { } } + } diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/func/ActionBeforeSending.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/func/ActionBeforeSending.java new file mode 100644 index 0000000..747a824 --- /dev/null +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/unit/func/ActionBeforeSending.java @@ -0,0 +1,8 @@ +package dev.struchkov.godfather.simple.core.unit.func; + +@FunctionalInterface +public interface ActionBeforeSending { + + void execute(String personId); + +}