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); + +}