diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java index 5ee15cf..dee6a44 100644 --- a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/BoxAnswer.java @@ -7,7 +7,6 @@ import dev.struchkov.godfather.main.domain.jackson.TelegramPayloadSerializer; import dev.struchkov.godfather.main.domain.keyboard.KeyBoard; import dev.struchkov.godfather.quarkus.domain.content.send.SendAttachment; import dev.struchkov.haiti.utils.container.ContextKey; -import io.smallrye.mutiny.Uni; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.Setter; @@ -149,10 +148,6 @@ public class BoxAnswer { return Optional.empty(); } - public Uni toUni() { - return Uni.createFrom().item(this); - } - public static final class Builder { private String message; diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/AnswerText.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/AnswerText.java index cd8fd84..5e9db50 100644 --- a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/AnswerText.java +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/AnswerText.java @@ -6,6 +6,7 @@ import dev.struchkov.godfather.main.domain.unit.UnitActiveType; import dev.struchkov.godfather.quarkus.domain.BoxAnswer; import dev.struchkov.godfather.quarkus.domain.unit.func.CallBackConsumer; import dev.struchkov.godfather.quarkus.domain.unit.func.ProcessingData; +import dev.struchkov.godfather.quarkus.domain.unit.func.UniConsumer; import dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate; import io.smallrye.mutiny.Uni; @@ -15,6 +16,7 @@ import java.util.Set; import java.util.UUID; import java.util.function.Consumer; import java.util.function.Function; +import java.util.function.Predicate; import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -108,21 +110,46 @@ public class AnswerText extends MainUnit { return this; } - public Builder answer(Consumer answer) { - this.boxAnswer = message -> { - answer.accept(message); - return Uni.createFrom().nullItem(); - }; + public Builder answerConsumer(Consumer consumer) { + this.boxAnswer = message -> Uni.createFrom().item(() -> { + consumer.accept(message); + return null; + }); return this; } - public Builder answer(Function> answer) { + public Builder answerConsumerUni(UniConsumer uniConsumer) { + this.boxAnswer = message -> uniConsumer.accept(message).replaceWith(() -> null); + return this; + } + + public Builder answerUni(Uni answer) { + this.boxAnswer = message -> answer.replaceWith(() -> null); + return this; + } + + public Builder answer(BoxAnswer boxAnswer) { + this.boxAnswer = message -> Uni.createFrom().item(boxAnswer); + return this; + } + + public Builder answerUni(Function> answer) { this.boxAnswer = answer::apply; return this; } + public Builder answer(Function answer) { + this.boxAnswer = message -> Uni.createFrom().item(() -> answer.apply(message)); + return this; + } + public Builder answer(Supplier answer) { - this.boxAnswer = message -> Uni.createFrom().item(answer.get()); + this.boxAnswer = message -> Uni.createFrom().item(answer); + return this; + } + + public Builder answerUni(Supplier> answer) { + this.boxAnswer = message -> answer.get(); return this; } @@ -189,11 +216,16 @@ public class AnswerText extends MainUnit { return this; } - public Builder triggerCheck(UniPredicate trigger) { + public Builder triggerCheckUni(UniPredicate trigger) { triggerCheck = trigger; return this; } + public Builder triggerCheck(Predicate trigger) { + triggerCheck = UniPredicate.predicate(trigger); + return this; + } + public Builder matchThreshold(Integer val) { matchThreshold = val; return this; diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/cmd/ReplaceCmd.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/cmd/ReplaceCmd.java index 90363f5..1da9bba 100644 --- a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/cmd/ReplaceCmd.java +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/cmd/ReplaceCmd.java @@ -10,6 +10,7 @@ import dev.struchkov.haiti.utils.Checker; import java.util.HashSet; import java.util.Set; import java.util.UUID; +import java.util.function.Predicate; import java.util.regex.Pattern; import java.util.stream.Collectors; @@ -131,11 +132,16 @@ public class ReplaceCmd extends MainUnit { return this; } - public Builder triggerCheck(UniPredicate trigger) { + public Builder triggerCheckUni(UniPredicate trigger) { triggerCheck = trigger; return this; } + public Builder triggerCheck(Predicate trigger) { + triggerCheck = UniPredicate.predicate(trigger); + return this; + } + public Builder matchThreshold(Integer val) { matchThreshold = val; return this; diff --git a/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniConsumer.java b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniConsumer.java new file mode 100644 index 0000000..068a0db --- /dev/null +++ b/bot-domain/bot-domain-quarkus/src/main/java/dev/struchkov/godfather/quarkus/domain/unit/func/UniConsumer.java @@ -0,0 +1,18 @@ +package dev.struchkov.godfather.quarkus.domain.unit.func; + +import io.smallrye.mutiny.Uni; + +import java.util.function.Consumer; + +public interface UniConsumer { + + Uni accept(T t); + + static UniConsumer consumer(Consumer consumer) { + return t -> Uni.createFrom().deferred(() -> { + consumer.accept(t); + return Uni.createFrom().voidItem(); + }); + } + +}