Revert "release-0.0.27"

This reverts commit 1a2d2d4602.
This commit is contained in:
Struchkov Mark 2022-09-21 19:15:16 +03:00
parent 1a2d2d4602
commit 7c3711ab90
22 changed files with 136 additions and 112 deletions

View File

@ -3,9 +3,10 @@
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>
<artifactId>bot-context</artifactId> <version>0.0.25</version>
<version>0.0.27</version> <relativePath>../../pom.xml</relativePath>
</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.27</version> <version>0.0.25</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -1,7 +1,6 @@
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;
/** /**
* Используется для перехвата исключений, которые возникают при обработке юнитов. * Используется для перехвата исключений, которые возникают при обработке юнитов.
@ -14,6 +13,6 @@ public interface ErrorHandler {
* @param message Сообщение, после которого возникло исключение. * @param message Сообщение, после которого возникло исключение.
* @param e Объект исключения. * @param e Объект исключения.
*/ */
Uni<Void> handle(Message message, Throwable e); 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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</version>
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>

View File

@ -28,11 +28,9 @@ 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.checkEmpty; import static dev.struchkov.haiti.utils.Checker.checkNotEmpty;
import static dev.struchkov.haiti.utils.Checker.checkNotNull; import static dev.struchkov.haiti.utils.Checker.checkNotNull;
import static java.lang.Boolean.TRUE; import static dev.struchkov.haiti.utils.Checker.checkNull;
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
public class GeneralAutoResponder<M extends Message> { public class GeneralAutoResponder<M extends Message> {
@ -86,33 +84,26 @@ public class GeneralAutoResponder<M extends Message> {
} }
public Uni<Void> processingNewMessage(M newMessage) { public Uni<Void> processingNewMessage(M newMessage) {
return Uni.createFrom().item(newMessage) if (newMessage != null) {
.onItem().ifNotNull().transformToUni( return personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
message -> personSettingService.getStateProcessingByPersonId(newMessage.getPersonId()) .onItem().transformToUni(
.replaceIfNullWith(TRUE)
.chain(
state -> { state -> {
if (TRUE.equals(state)) { if (checkNull(state) || 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) {
return Uni.createFrom().item(newMessages) if (newMessages != null && !newMessages.isEmpty()) {
.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()
@ -124,34 +115,56 @@ 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().ifNotNull().transform(m -> modifiable) .onItem().transformToUni(
.replaceIfNullWith(emptyList()) mail -> {
.onItem().transformToMulti(modifiables -> Multi.createFrom().iterable(modifiables)) if (checkNotEmpty(modifiable)) {
.onItem().transformToUni(mModifiable -> mModifiable.change(message)) return Multi.createFrom().iterable(modifiable)
.concatenate().toUni().replaceWith( .onItem().transformToUni(m -> m.change(mail))
storyLineService.getNextUnitByPersonId(message.getPersonId()) .concatenate().toUni().replaceWith(mail);
.onItem().ifNotNull().transformToUni( }
nextUnits -> Uni.createFrom().optional( return Uni.createFrom().item(mail);
Responder.nextUnit(message, nextUnits).or(storyLineService::getDefaultUnit) }
) ).onItem().transformToUni(
).onItem().ifNotNull().transformToUni(answerUnit -> answer(UnitRequest.of(answerUnit, message))) mail -> {
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)
.chain(request -> activeUnitAfter(unitRequest)) .onItem().transformToUni(
.onFailure().call( request -> activeUnitAfter(unitRequest)
)
.onFailure().invoke(
throwable -> { throwable -> {
if (checkNotNull(errorHandler)) { if (errorHandler != null) {
return errorHandler.handle(unitRequest.getMessage(), throwable); errorHandler.handle(unitRequest.getMessage(), throwable);
} }
return Uni.createFrom().voidItem();
} }
) )
.replaceWithVoid(); .replaceWithVoid();

View File

@ -28,32 +28,48 @@ 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 Message message = unitRequest.getMessage();
final AnswerText<Message> unit = unitRequest.getUnit(); final AnswerText<Message> unit = unitRequest.getUnit();
return Uni.createFrom().voidItem() final Message message = unitRequest.getMessage();
.chain(request -> unit.getAnswer().processing(message))
.onItem().ifNotNull().transformToUni(boxAnswer -> replaceMarkers(unit, message, boxAnswer)) return unit.getAnswer().processing(message)
.onItem().ifNotNull().transformToUni(boxAnswer -> { .onItem().transformToUni(
boxAnswer -> {
if (checkNotNull(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 (checkNotNull(answerTextSending)) { if (answerTextSending != null) {
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) {
return Uni.createFrom().item(answerText.getInsert()) if (answerText.getInsert() != null) {
.onItem().ifNotNull().transformToUni(insert -> insert.insert(message.getPersonId())) return answerText.getInsert().insert(message.getPersonId())
.onItem().ifNotNull().transform(words -> { .onItem().transformToUni(
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 boxAnswer; return Uni.createFrom().item(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;
} }
public Builder<M> triggerCheck(Predicate<M> trigger) { private Builder<M> triggerCheck(Predicate<M> trigger) {
triggerCheck = trigger; triggerCheck = trigger;
return this; return this;
} }

View File

@ -19,18 +19,13 @@ 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().nullItem(); return Uni.createFrom().voidItem();
}
).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.27</version> <version>0.0.25</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;
} }
public Builder<M> triggerCheck(Predicate<M> trigger) { private 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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</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.27</version> <version>0.0.25</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>