release-0.0.27

This commit is contained in:
Struchkov Mark 2022-09-19 20:22:10 +03:00
parent dd6b166506
commit 1a2d2d4602
22 changed files with 113 additions and 137 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -28,9 +28,11 @@ import java.util.Optional;
import java.util.Set;
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.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> {
@ -84,87 +86,72 @@ public class GeneralAutoResponder<M extends Message> {
}
public Uni<Void> processingNewMessage(M newMessage) {
if (newMessage != null) {
return personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
.onItem().transformToUni(
state -> {
if (checkNull(state) || state) {
return processing(newMessage);
}
return Uni.createFrom().voidItem();
}
);
}
return Uni.createFrom().voidItem();
return Uni.createFrom().item(newMessage)
.onItem().ifNotNull().transformToUni(
message -> personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
.replaceIfNullWith(TRUE)
.chain(
state -> {
if (TRUE.equals(state)) {
return processing(newMessage);
}
return Uni.createFrom().voidItem();
}
)
).replaceWithVoid();
}
public Uni<Void> processingNewMessages(List<M> newMessages) {
if (newMessages != null && !newMessages.isEmpty()) {
final Set<Long> personIds = newMessages.stream()
.map(Message::getPersonId)
.collect(Collectors.toSet());
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();
}
return Uni.createFrom().item(newMessages)
.onItem().ifNotNull().transformToUni(
messages -> {
if (checkEmpty(newMessages)) return Uni.createFrom().voidItem();
private Uni<Void> processing(M message) {
return Uni.createFrom().item(message)
.onItem().transformToUni(
mail -> {
if (checkNotEmpty(modifiable)) {
return Multi.createFrom().iterable(modifiable)
.onItem().transformToUni(m -> m.change(mail))
.concatenate().toUni().replaceWith(mail);
}
return Uni.createFrom().item(mail);
}
).onItem().transformToUni(
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();
final Set<Long> personIds = newMessages.stream()
.map(Message::getPersonId)
.collect(Collectors.toSet());
return personSettingService.getAllPersonIdDisableMessages(personIds)
.replaceIfNullWith(emptySet())
.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();
}
);
}
// private boolean checkPermission(Optional<Accessibility> accessibility, M message) {
// return accessibility.isEmpty() || accessibility.get().check(message);
// }
private Uni<Void> processing(M 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) {
return getAction(unitRequest)
.onItem().transformToUni(
request -> activeUnitAfter(unitRequest)
)
.onFailure().invoke(
.chain(request -> activeUnitAfter(unitRequest))
.onFailure().call(
throwable -> {
if (errorHandler != null) {
errorHandler.handle(unitRequest.getMessage(), throwable);
if (checkNotNull(errorHandler)) {
return errorHandler.handle(unitRequest.getMessage(), throwable);
}
return Uni.createFrom().voidItem();
}
)
.replaceWithVoid();
@ -178,7 +165,7 @@ public class GeneralAutoResponder<M extends Message> {
.findFirst();
if (first.isPresent()) {
return Uni.createFrom().voidItem().onItem().transformToUni(
v-> getAction(UnitRequest.of(first.get(), unitRequest.getMessage()))
v -> getAction(UnitRequest.of(first.get(), unitRequest.getMessage()))
)
.onItem().transformToUni(
uR -> activeUnitAfter(UnitRequest.of(first.get(), unitRequest.getMessage()))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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