parent
1a2d2d4602
commit
7c3711ab90
@ -3,9 +3,10 @@
|
||||
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>
|
||||
<artifactId>bot-context</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-context</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package dev.struchkov.godfather.quarkus.context.service;
|
||||
|
||||
import dev.struchkov.godfather.main.domain.content.Message;
|
||||
import io.smallrye.mutiny.Uni;
|
||||
|
||||
/**
|
||||
* Используется для перехвата исключений, которые возникают при обработке юнитов.
|
||||
@ -14,6 +13,6 @@ public interface ErrorHandler {
|
||||
* @param message Сообщение, после которого возникло исключение.
|
||||
* @param e Объект исключения.
|
||||
*/
|
||||
Uni<Void> handle(Message message, Throwable e);
|
||||
void handle(Message message, Throwable e);
|
||||
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-context</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-context</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-core</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-core</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -28,11 +28,9 @@ import java.util.Optional;
|
||||
import java.util.Set;
|
||||
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 java.lang.Boolean.TRUE;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static dev.struchkov.haiti.utils.Checker.checkNull;
|
||||
|
||||
public class GeneralAutoResponder<M extends Message> {
|
||||
|
||||
@ -86,33 +84,26 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
}
|
||||
|
||||
public Uni<Void> processingNewMessage(M newMessage) {
|
||||
return Uni.createFrom().item(newMessage)
|
||||
.onItem().ifNotNull().transformToUni(
|
||||
message -> personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
|
||||
.replaceIfNullWith(TRUE)
|
||||
.chain(
|
||||
if (newMessage != null) {
|
||||
return personSettingService.getStateProcessingByPersonId(newMessage.getPersonId())
|
||||
.onItem().transformToUni(
|
||||
state -> {
|
||||
if (TRUE.equals(state)) {
|
||||
if (checkNull(state) || state) {
|
||||
return processing(newMessage);
|
||||
}
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
)
|
||||
).replaceWithVoid();
|
||||
|
||||
);
|
||||
}
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
|
||||
public Uni<Void> processingNewMessages(List<M> newMessages) {
|
||||
return Uni.createFrom().item(newMessages)
|
||||
.onItem().ifNotNull().transformToUni(
|
||||
messages -> {
|
||||
if (checkEmpty(newMessages)) return Uni.createFrom().voidItem();
|
||||
|
||||
if (newMessages != null && !newMessages.isEmpty()) {
|
||||
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()
|
||||
@ -124,34 +115,56 @@ public class GeneralAutoResponder<M extends Message> {
|
||||
.onItem().transform(this::processing)
|
||||
.toUni().replaceWithVoid();
|
||||
}
|
||||
);
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
|
||||
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)))
|
||||
.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();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// private boolean checkPermission(Optional<Accessibility> accessibility, M message) {
|
||||
// return accessibility.isEmpty() || accessibility.get().check(message);
|
||||
// }
|
||||
|
||||
public Uni<Void> answer(UnitRequest<MainUnit, M> unitRequest) {
|
||||
return getAction(unitRequest)
|
||||
.chain(request -> activeUnitAfter(unitRequest))
|
||||
.onFailure().call(
|
||||
.onItem().transformToUni(
|
||||
request -> activeUnitAfter(unitRequest)
|
||||
)
|
||||
.onFailure().invoke(
|
||||
throwable -> {
|
||||
if (checkNotNull(errorHandler)) {
|
||||
return errorHandler.handle(unitRequest.getMessage(), throwable);
|
||||
if (errorHandler != null) {
|
||||
errorHandler.handle(unitRequest.getMessage(), throwable);
|
||||
}
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
)
|
||||
.replaceWithVoid();
|
||||
|
@ -28,32 +28,48 @@ public class AnswerTextAction implements ActionUnit<AnswerText<Message>, Message
|
||||
|
||||
@Override
|
||||
public Uni<UnitRequest<MainUnit, Message>> action(UnitRequest<AnswerText<Message>, Message> unitRequest) {
|
||||
final Message message = unitRequest.getMessage();
|
||||
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 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 (checkNotNull(answerTextSending)) {
|
||||
if (answerTextSending != null) {
|
||||
return Sender.sends(message, boxAnswer, answerTextSending);
|
||||
} else {
|
||||
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) {
|
||||
return Uni.createFrom().item(answerText.getInsert())
|
||||
.onItem().ifNotNull().transformToUni(insert -> insert.insert(message.getPersonId()))
|
||||
.onItem().ifNotNull().transform(words -> {
|
||||
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 boxAnswer;
|
||||
})
|
||||
.replaceIfNullWith(boxAnswer);
|
||||
return Uni.createFrom().item(boxAnswer);
|
||||
}
|
||||
);
|
||||
}
|
||||
return Uni.createFrom().item(boxAnswer);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> triggerCheck(Predicate<M> trigger) {
|
||||
private Builder<M> triggerCheck(Predicate<M> trigger) {
|
||||
triggerCheck = trigger;
|
||||
return this;
|
||||
}
|
||||
|
@ -19,18 +19,13 @@ public class Sender {
|
||||
}
|
||||
|
||||
public static Uni<Void> sends(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
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();
|
||||
return Uni.createFrom().voidItem();
|
||||
}
|
||||
|
||||
private static Uni<Void> privateSend(Message message, BoxAnswer boxAnswer, Sending sending) {
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>bot-core</artifactId>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -164,7 +164,7 @@ public class AnswerCheck<M extends Message> extends MainUnit<M> {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<M> triggerCheck(Predicate<M> trigger) {
|
||||
private Builder<M> triggerCheck(Predicate<M> trigger) {
|
||||
triggerCheck = trigger;
|
||||
return this;
|
||||
}
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-core</artifactId>
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>bot-data</artifactId>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-data</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>bot-data</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>bot-domain</artifactId>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.27</version>
|
||||
<version>0.0.25</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user