Revert "Revert "release-0.0.27""

This reverts commit 7c3711ab90.
This commit is contained in:
Struchkov Mark 2022-09-21 19:15:29 +03:00
parent 7c3711ab90
commit eb2e7ba012
22 changed files with 113 additions and 137 deletions

View File

@ -3,10 +3,9 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent> <parent>
<artifactId>godfather-bot</artifactId>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<version>0.0.25</version> <artifactId>bot-context</artifactId>
<relativePath>../../pom.xml</relativePath> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId> <artifactId>bot-context</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,6 +1,7 @@
package dev.struchkov.godfather.quarkus.context.service; package dev.struchkov.godfather.quarkus.context.service;
import dev.struchkov.godfather.main.domain.content.Message; import dev.struchkov.godfather.main.domain.content.Message;
import io.smallrye.mutiny.Uni;
/** /**
* Используется для перехвата исключений, которые возникают при обработке юнитов. * Используется для перехвата исключений, которые возникают при обработке юнитов.
@ -13,6 +14,6 @@ public interface ErrorHandler {
* @param message Сообщение, после которого возникло исключение. * @param message Сообщение, после которого возникло исключение.
* @param e Объект исключения. * @param e Объект исключения.
*/ */
void handle(Message message, Throwable e); Uni<Void> handle(Message message, Throwable e);
} }

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-context</artifactId> <artifactId>bot-context</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<artifactId>bot-context</artifactId> <artifactId>bot-context</artifactId>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core</artifactId> <artifactId>bot-core</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-core</artifactId> <artifactId>bot-core</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -28,9 +28,11 @@ import java.util.Optional;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static dev.struchkov.haiti.utils.Checker.checkNotEmpty; import static dev.struchkov.haiti.utils.Checker.checkEmpty;
import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Checker.checkNotNull;
import static dev.struchkov.haiti.utils.Checker.checkNull; import static java.lang.Boolean.TRUE;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
public class GeneralAutoResponder<M extends Message> { public class GeneralAutoResponder<M extends Message> {
@ -84,26 +86,33 @@ public class GeneralAutoResponder<M extends Message> {
} }
public Uni<Void> processingNewMessage(M newMessage) { public Uni<Void> processingNewMessage(M newMessage) {
if (newMessage != null) { return Uni.createFrom().item(newMessage)
return personSettingService.getStateProcessingByPersonId(newMessage.getPersonId()) .onItem().ifNotNull().transformToUni(
.onItem().transformToUni( message -> personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
.replaceIfNullWith(TRUE)
.chain(
state -> { state -> {
if (checkNull(state) || state) { if (TRUE.equals(state)) {
return processing(newMessage); return processing(newMessage);
} }
return Uni.createFrom().voidItem(); return Uni.createFrom().voidItem();
} }
); )
} ).replaceWithVoid();
return Uni.createFrom().voidItem();
} }
public Uni<Void> processingNewMessages(List<M> newMessages) { public Uni<Void> processingNewMessages(List<M> newMessages) {
if (newMessages != null && !newMessages.isEmpty()) { return Uni.createFrom().item(newMessages)
.onItem().ifNotNull().transformToUni(
messages -> {
if (checkEmpty(newMessages)) return Uni.createFrom().voidItem();
final Set<Long> personIds = newMessages.stream() final Set<Long> personIds = newMessages.stream()
.map(Message::getPersonId) .map(Message::getPersonId)
.collect(Collectors.toSet()); .collect(Collectors.toSet());
return personSettingService.getAllPersonIdDisableMessages(personIds) return personSettingService.getAllPersonIdDisableMessages(personIds)
.replaceIfNullWith(emptySet())
.onItem().transformToMulti( .onItem().transformToMulti(
disableIds -> { disableIds -> {
final List<M> allowedMessages = newMessages.stream() final List<M> allowedMessages = newMessages.stream()
@ -115,56 +124,34 @@ public class GeneralAutoResponder<M extends Message> {
.onItem().transform(this::processing) .onItem().transform(this::processing)
.toUni().replaceWithVoid(); .toUni().replaceWithVoid();
} }
return Uni.createFrom().voidItem(); );
} }
private Uni<Void> processing(M message) { private Uni<Void> processing(M message) {
return Uni.createFrom().item(message) return Uni.createFrom().item(message)
.onItem().transformToUni( .onItem().ifNotNull().transform(m -> modifiable)
mail -> { .replaceIfNullWith(emptyList())
if (checkNotEmpty(modifiable)) { .onItem().transformToMulti(modifiables -> Multi.createFrom().iterable(modifiables))
return Multi.createFrom().iterable(modifiable) .onItem().transformToUni(mModifiable -> mModifiable.change(message))
.onItem().transformToUni(m -> m.change(mail)) .concatenate().toUni().replaceWith(
.concatenate().toUni().replaceWith(mail); storyLineService.getNextUnitByPersonId(message.getPersonId())
} .onItem().ifNotNull().transformToUni(
return Uni.createFrom().item(mail); nextUnits -> Uni.createFrom().optional(
} Responder.nextUnit(message, nextUnits).or(storyLineService::getDefaultUnit)
).onItem().transformToUni( )
mail -> { ).onItem().ifNotNull().transformToUni(answerUnit -> answer(UnitRequest.of(answerUnit, message)))
final Uni<Set<MainUnit<M>>> uniUnits = storyLineService.getNextUnitByPersonId(mail.getPersonId());
return Uni.combine().all().unis(uniUnits, Uni.createFrom().item(mail)).asTuple();
}
).onItem().transformToUni(
t -> {
final Set<MainUnit<M>> units = t.getItem1();
final M mail = t.getItem2();
final Optional<MainUnit<M>> optAnswer = Responder.nextUnit(mail, units).or(storyLineService::getDefaultUnit);
if (optAnswer.isPresent()) {
final MainUnit<M> answer = optAnswer.get();
//TODO [05.08.2022]: нужно ли проверку встраивать в поток?
// if (checkPermission(answer.getAccessibility(), message)) {
return answer(UnitRequest.of(answer, message));
// }
}
return Uni.createFrom().voidItem();
}
); );
} }
// private boolean checkPermission(Optional<Accessibility> accessibility, M message) {
// return accessibility.isEmpty() || accessibility.get().check(message);
// }
public Uni<Void> answer(UnitRequest<MainUnit, M> unitRequest) { public Uni<Void> answer(UnitRequest<MainUnit, M> unitRequest) {
return getAction(unitRequest) return getAction(unitRequest)
.onItem().transformToUni( .chain(request -> activeUnitAfter(unitRequest))
request -> activeUnitAfter(unitRequest) .onFailure().call(
)
.onFailure().invoke(
throwable -> { throwable -> {
if (errorHandler != null) { if (checkNotNull(errorHandler)) {
errorHandler.handle(unitRequest.getMessage(), throwable); return errorHandler.handle(unitRequest.getMessage(), throwable);
} }
return Uni.createFrom().voidItem();
} }
) )
.replaceWithVoid(); .replaceWithVoid();
@ -178,7 +165,7 @@ public class GeneralAutoResponder<M extends Message> {
.findFirst(); .findFirst();
if (first.isPresent()) { if (first.isPresent()) {
return Uni.createFrom().voidItem().onItem().transformToUni( return Uni.createFrom().voidItem().onItem().transformToUni(
v-> getAction(UnitRequest.of(first.get(), unitRequest.getMessage())) v -> getAction(UnitRequest.of(first.get(), unitRequest.getMessage()))
) )
.onItem().transformToUni( .onItem().transformToUni(
uR -> activeUnitAfter(UnitRequest.of(first.get(), unitRequest.getMessage())) uR -> activeUnitAfter(UnitRequest.of(first.get(), unitRequest.getMessage()))

View File

@ -28,48 +28,32 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
@Override @Override
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerText<Message>, Message> unitRequest) { public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerText<Message>, Message> unitRequest) {
final AnswerText<Message> unit = unitRequest.getUnit();
final Message message = unitRequest.getMessage(); final Message message = unitRequest.getMessage();
final AnswerText<Message> unit = unitRequest.getUnit();
return unit.getAnswer().processing(message) return Uni.createFrom().voidItem()
.onItem().transformToUni( .chain(request -> unit.getAnswer().processing(message))
boxAnswer -> { .onItem().ifNotNull().transformToUni(boxAnswer -> replaceMarkers(unit, message, boxAnswer))
if (checkNotNull(boxAnswer)) { .onItem().ifNotNull().transformToUni(boxAnswer -> {
return replaceMarkers(unit, message, boxAnswer);
}
return Uni.createFrom().nullItem();
}
).onItem().transformToUni(
boxAnswer -> {
if (checkNotNull(boxAnswer)) {
final Sending answerTextSending = unit.getSending(); final Sending answerTextSending = unit.getSending();
if (answerTextSending != null) { if (checkNotNull(answerTextSending)) {
return Sender.sends(message, boxAnswer, answerTextSending); return Sender.sends(message, boxAnswer, answerTextSending);
} else { } else {
return Sender.sends(message, boxAnswer, this.sending); return Sender.sends(message, boxAnswer, this.sending);
} }
} }).replaceWith(UnitRequest.of(unit, message));
return Uni.createFrom().nullItem();
}
).onItem().transform(
v -> UnitRequest.of(unit, message)
);
} }
private Uni<BoxAnswer> replaceMarkers(AnswerText<Message> answerText, Message message, BoxAnswer boxAnswer) { private Uni<BoxAnswer> replaceMarkers(AnswerText<Message> answerText, Message message, BoxAnswer boxAnswer) {
if (answerText.getInsert() != null) { return Uni.createFrom().item(answerText.getInsert())
return answerText.getInsert().insert(message.getPersonId()) .onItem().ifNotNull().transformToUni(insert -> insert.insert(message.getPersonId()))
.onItem().transformToUni( .onItem().ifNotNull().transform(words -> {
words -> {
if (checkNotEmpty(words)) { if (checkNotEmpty(words)) {
final String newMessage = InsertWords.insert(boxAnswer.getMessage(), words); final String newMessage = InsertWords.insert(boxAnswer.getMessage(), words);
boxAnswer.setMessage(newMessage); boxAnswer.setMessage(newMessage);
} }
return Uni.createFrom().item(boxAnswer); return boxAnswer;
} })
); .replaceIfNullWith(boxAnswer);
}
return Uni.createFrom().item(boxAnswer);
} }
} }

View File

@ -167,7 +167,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
return this; return this;
} }
private Builder<M> triggerCheck(Predicate<M> trigger) { public Builder<M> triggerCheck(Predicate<M> trigger) {
triggerCheck = trigger; triggerCheck = trigger;
return this; return this;
} }

View File

@ -19,13 +19,18 @@ public class Sender {
} }
public static Uni<Void> sends(Message message, BoxAnswer boxAnswer, Sending sending) { public static Uni<Void> sends(Message message, BoxAnswer boxAnswer, Sending sending) {
return Uni.createFrom().item(sending)
.onItem().ifNotNull().transformToUni(
sender -> {
switch (sending.getType()) { switch (sending.getType()) {
case PUBLIC: case PUBLIC:
break; break;
case PRIVATE: case PRIVATE:
return privateSend(message, boxAnswer, sending); return privateSend(message, boxAnswer, sending);
} }
return Uni.createFrom().voidItem(); return Uni.createFrom().nullItem();
}
).replaceWithVoid();
} }
private static Uni<Void> privateSend(Message message, BoxAnswer boxAnswer, Sending sending) { private static Uni<Void> privateSend(Message message, BoxAnswer boxAnswer, Sending sending) {

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>bot-core</artifactId> <artifactId>bot-core</artifactId>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -164,7 +164,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
return this; return this;
} }
private Builder<M> triggerCheck(Predicate<M> trigger) { public Builder<M> triggerCheck(Predicate<M> trigger) {
triggerCheck = trigger; triggerCheck = trigger;
return this; return this;
} }

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<artifactId>bot-core</artifactId> <artifactId>bot-core</artifactId>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>bot-data</artifactId> <artifactId>bot-data</artifactId>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-data</artifactId> <artifactId>bot-data</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>bot-data</artifactId> <artifactId>bot-data</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>bot-domain</artifactId> <artifactId>bot-domain</artifactId>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.25</version> <version>0.0.27</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>