Более удобный API для AnswerText
This commit is contained in:
parent
423e17f896
commit
812c82467c
@ -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<BoxAnswer> toUni() {
|
||||
return Uni.createFrom().item(this);
|
||||
}
|
||||
|
||||
public static final class Builder {
|
||||
|
||||
private String message;
|
||||
|
@ -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<M extends Message> extends MainUnit<M> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answer(Consumer<M> answer) {
|
||||
this.boxAnswer = message -> {
|
||||
answer.accept(message);
|
||||
return Uni.createFrom().nullItem();
|
||||
};
|
||||
public Builder<M> answerConsumer(Consumer<M> consumer) {
|
||||
this.boxAnswer = message -> Uni.createFrom().item(() -> {
|
||||
consumer.accept(message);
|
||||
return null;
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answer(Function<M, Uni<BoxAnswer>> answer) {
|
||||
public Builder<M> answerConsumerUni(UniConsumer<M> uniConsumer) {
|
||||
this.boxAnswer = message -> uniConsumer.accept(message).replaceWith(() -> null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answerUni(Uni<?> answer) {
|
||||
this.boxAnswer = message -> answer.replaceWith(() -> null);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answer(BoxAnswer boxAnswer) {
|
||||
this.boxAnswer = message -> Uni.createFrom().item(boxAnswer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answerUni(Function<M, Uni<BoxAnswer>> answer) {
|
||||
this.boxAnswer = answer::apply;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answer(Function<M, BoxAnswer> answer) {
|
||||
this.boxAnswer = message -> Uni.createFrom().item(() -> answer.apply(message));
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answer(Supplier<BoxAnswer> answer) {
|
||||
this.boxAnswer = message -> Uni.createFrom().item(answer.get());
|
||||
this.boxAnswer = message -> Uni.createFrom().item(answer);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> answerUni(Supplier<Uni<BoxAnswer>> answer) {
|
||||
this.boxAnswer = message -> answer.get();
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -189,11 +216,16 @@ public class AnswerText<M extends Message> extends MainUnit<M> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> triggerCheck(UniPredicate<M> trigger) {
|
||||
public Builder<M> triggerCheckUni(UniPredicate<M> trigger) {
|
||||
triggerCheck = trigger;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> triggerCheck(Predicate<M> trigger) {
|
||||
triggerCheck = UniPredicate.predicate(trigger);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
|
@ -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<M extends Message> extends MainUnit<M> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> triggerCheck(UniPredicate<M> trigger) {
|
||||
public Builder<M> triggerCheckUni(UniPredicate<M> trigger) {
|
||||
triggerCheck = trigger;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> triggerCheck(Predicate<M> trigger) {
|
||||
triggerCheck = UniPredicate.predicate(trigger);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> matchThreshold(Integer val) {
|
||||
matchThreshold = val;
|
||||
return this;
|
||||
|
@ -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<T> {
|
||||
|
||||
Uni<Void> accept(T t);
|
||||
|
||||
static <D> UniConsumer<D> consumer(Consumer<D> consumer) {
|
||||
return t -> Uni.createFrom().deferred(() -> {
|
||||
consumer.accept(t);
|
||||
return Uni.createFrom().voidItem();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user