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,87 +86,72 @@ 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())
state -> { .replaceIfNullWith(TRUE)
if (checkNull(state) || state) { .chain(
return processing(newMessage); state -> {
} if (TRUE.equals(state)) {
return Uni.createFrom().voidItem(); return processing(newMessage);
} }
); return Uni.createFrom().voidItem();
} }
return Uni.createFrom().voidItem(); )
).replaceWithVoid();
} }
public Uni<Void> processingNewMessages(List<M> newMessages) { public Uni<Void> processingNewMessages(List<M> newMessages) {
if (newMessages != null && !newMessages.isEmpty()) { return Uni.createFrom().item(newMessages)
final Set<Long> personIds = newMessages.stream() .onItem().ifNotNull().transformToUni(
.map(Message::getPersonId) messages -> {
.collect(Collectors.toSet()); if (checkEmpty(newMessages)) return Uni.createFrom().voidItem();
return personSettingService.getAllPersonIdDisableMessages(personIds)
.onItem().transformToMulti(
disableIds -> {
final List<M> allowedMessages = newMessages.stream()
.filter(message -> !disableIds.contains(message.getPersonId()))
.toList();
return Multi.createFrom().iterable(allowedMessages);
}
)
.onItem().transform(this::processing)
.toUni().replaceWithVoid();
}
return Uni.createFrom().voidItem();
}
private Uni<Void> processing(M message) { final Set<Long> personIds = newMessages.stream()
return Uni.createFrom().item(message) .map(Message::getPersonId)
.onItem().transformToUni( .collect(Collectors.toSet());
mail -> { return personSettingService.getAllPersonIdDisableMessages(personIds)
if (checkNotEmpty(modifiable)) { .replaceIfNullWith(emptySet())
return Multi.createFrom().iterable(modifiable) .onItem().transformToMulti(
.onItem().transformToUni(m -> m.change(mail)) disableIds -> {
.concatenate().toUni().replaceWith(mail); final List<M> allowedMessages = newMessages.stream()
} .filter(message -> !disableIds.contains(message.getPersonId()))
return Uni.createFrom().item(mail); .toList();
} return Multi.createFrom().iterable(allowedMessages);
).onItem().transformToUni( }
mail -> { )
final Uni<Set<MainUnit<M>>> uniUnits = storyLineService.getNextUnitByPersonId(mail.getPersonId()); .onItem().transform(this::processing)
return Uni.combine().all().unis(uniUnits, Uni.createFrom().item(mail)).asTuple(); .toUni().replaceWithVoid();
}
).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) { private Uni<Void> processing(M message) {
// return accessibility.isEmpty() || accessibility.get().check(message); return Uni.createFrom().item(message)
// } .onItem().ifNotNull().transform(m -> modifiable)
.replaceIfNullWith(emptyList())
.onItem().transformToMulti(modifiables -> Multi.createFrom().iterable(modifiables))
.onItem().transformToUni(mModifiable -> mModifiable.change(message))
.concatenate().toUni().replaceWith(
storyLineService.getNextUnitByPersonId(message.getPersonId())
.onItem().ifNotNull().transformToUni(
nextUnits -> Uni.createFrom().optional(
Responder.nextUnit(message, nextUnits).or(storyLineService::getDefaultUnit)
)
).onItem().ifNotNull().transformToUni(answerUnit -> answer(UnitRequest.of(answerUnit, 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); final Sending answerTextSending = unit.getSending();
} if (checkNotNull(answerTextSending)) {
return Uni.createFrom().nullItem(); return Sender.sends(message, boxAnswer, answerTextSending);
} } else {
).onItem().transformToUni( return Sender.sends(message, boxAnswer, this.sending);
boxAnswer -> { }
if (checkNotNull(boxAnswer)) { }).replaceWith(UnitRequest.of(unit, message));
final Sending answerTextSending = unit.getSending();
if (answerTextSending != null) {
return Sender.sends(message, boxAnswer, answerTextSending);
} else {
return Sender.sends(message, boxAnswer, this.sending);
}
}
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 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;
} }
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) {
switch (sending.getType()) { return Uni.createFrom().item(sending)
case PUBLIC: .onItem().ifNotNull().transformToUni(
break; sender -> {
case PRIVATE: switch (sending.getType()) {
return privateSend(message, boxAnswer, sending); case PUBLIC:
} break;
return Uni.createFrom().voidItem(); case PRIVATE:
return privateSend(message, boxAnswer, sending);
}
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>