From e5994c80525eaaf5175cd97baf53c595beb29d02 Mon Sep 17 00:00:00 2001 From: Struchkov Mark Date: Fri, 17 Feb 2023 21:37:21 +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=BE=D0=B1=D1=89=D0=B5=D0=B5=20=D0=B4=D0=B5=D0=B9=D1=81=D1=82?= =?UTF-8?q?=D0=B2=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20=D0=BE?= =?UTF-8?q?=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA=D0=BE=D0=B9=20=D0=B4=D0=BB?= =?UTF-8?q?=D1=8F=20AnswerTextAction?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../quarkus/core/GeneralAutoResponder.java | 4 ++++ .../quarkus/core/action/AnswerTextAction.java | 16 ++++++++++++++-- .../core/unit/func/ActionBeforeSending.java | 2 +- .../simple/core/GeneralAutoResponder.java | 4 ++++ .../simple/core/action/AnswerTextAction.java | 12 +++++++++++- 5 files changed, 34 insertions(+), 4 deletions(-) diff --git a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java index d571c6c..1b4dca2 100644 --- a/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java +++ b/bot-core/bot-core-quarkus/src/main/java/dev/struchkov/godfather/quarkus/core/GeneralAutoResponder.java @@ -62,6 +62,10 @@ public class GeneralAutoResponder { this.modifiable = modifiable; } + public void initTextAnswerActionUnit(AnswerTextAction action) { + actionUnitMap.put(TypeUnit.TEXT, action); + } + public void initActionUnit(String typeUnit, ActionUnit, M> actionUnit) { if (!actionUnitMap.containsKey(typeUnit)) { actionUnitMap.put(typeUnit, actionUnit); 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 2d1b16e..ce9d98c 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 @@ -20,10 +20,16 @@ public class AnswerTextAction implements ActionUnit, Message private final Sending sending; + private ActionBeforeSending actionBeforeSending; + public AnswerTextAction(Sending sending) { this.sending = sending; } + public void setActionBeforeSending(ActionBeforeSending actionBeforeSending) { + this.actionBeforeSending = actionBeforeSending; + } + @Override public Uni> action(UnitRequest, Message> unitRequest) { final Message message = unitRequest.getMessage(); @@ -31,9 +37,15 @@ public class AnswerTextAction implements ActionUnit, Message return unit.getAnswer().processing(message) .onItem().ifNotNull().call(v -> { - final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending(); if (checkNotNull(actionBeforeSending)) { - return actionBeforeSending.execute(); + return actionBeforeSending.execute(message.getPersonId()); + } + return Uni.createFrom().nullItem(); + }) + .onItem().ifNotNull().call(v -> { + final ActionBeforeSending unitActionBeforeSending = unit.getActionBeforeSending(); + if (checkNotNull(unitActionBeforeSending)) { + return unitActionBeforeSending.execute(message.getPersonId()); } return Uni.createFrom().nullItem(); }) 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 index 492e6d3..2236fb0 100644 --- 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 @@ -5,6 +5,6 @@ import io.smallrye.mutiny.Uni; @FunctionalInterface public interface ActionBeforeSending { - Uni execute(); + Uni execute(String personId); } diff --git a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java index 51a0357..8237a4f 100644 --- a/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java +++ b/bot-core/bot-core-simple/src/main/java/dev/struchkov/godfather/simple/core/GeneralAutoResponder.java @@ -61,6 +61,10 @@ public class GeneralAutoResponder { this.modifiable = modifiable; } + public void initTextAnswerActionUnit(AnswerTextAction action) { + actionUnitMap.put(TypeUnit.TEXT, action); + } + public void initActionUnit(String typeUnit, ActionUnit, M> actionUnit) { if (!actionUnitMap.containsKey(typeUnit)) { actionUnitMap.put(typeUnit, actionUnit); 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 15dd9bc..1d3ada2 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 @@ -24,10 +24,16 @@ public class AnswerTextAction implements ActionUnit, Message private final Sending sending; + private ActionBeforeSending actionBeforeSending; + public AnswerTextAction(Sending sending) { this.sending = sending; } + public void setActionBeforeSending(ActionBeforeSending actionBeforeSending) { + this.actionBeforeSending = actionBeforeSending; + } + @Override public UnitRequest action(UnitRequest, Message> unitRequest) { final Message message = unitRequest.getMessage(); @@ -41,11 +47,15 @@ public class AnswerTextAction implements ActionUnit, Message answer.setRecipientIfNull(message.getPersonId()); - final ActionBeforeSending actionBeforeSending = unit.getActionBeforeSending(); if (checkNotNull(actionBeforeSending)) { actionBeforeSending.execute(message.getPersonId()); } + final ActionBeforeSending unitActionBeforeSending = unit.getActionBeforeSending(); + if (checkNotNull(unitActionBeforeSending)) { + unitActionBeforeSending.execute(message.getPersonId()); + } + final Optional optSentBox = sending.send(answer); final CallBackConsumer callBack = unit.getCallBack(); if (checkNotNull(callBack) && optAnswer.isPresent()) {