Объединил UnitTrigger

This commit is contained in:
Struchkov Mark 2023-05-14 01:51:20 +03:00
parent abf27f1bec
commit 697c0c038d
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
3 changed files with 15 additions and 71 deletions

View File

@ -38,7 +38,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<godfather.core.ver>0.0.65</godfather.core.ver>
<godfather.core.ver>0.0.66-SNAPSHOT</godfather.core.ver>
<!-- https://mvnrepository.com/artifact/org.telegram/telegrambots -->
<telegrambots.ver>6.5.0</telegrambots.ver>

View File

@ -1,8 +1,8 @@
package dev.struchkov.godfather.telegram.simple.core.util;
package dev.struchkov.godfather.telegram.main.core.util;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
import java.util.Arrays;
import java.util.Optional;
@ -28,6 +28,18 @@ public class UnitTrigger {
};
}
public static Predicate<Mail> isCommandByType(String commandType) {
return mail -> {
final Optional<CommandAttachment> optCommand = Attachments.findFirstCommand(mail.getAttachments());
if (optCommand.isPresent()) {
final CommandAttachment command = optCommand.get();
final String type = command.getCommandType();
return type.equals(commandType);
}
return false;
};
}
public static Predicate<Mail> isButtonClick() {
return mail -> Attachments.findFirstButtonClick(mail.getAttachments()).isPresent();
}

View File

@ -1,68 +0,0 @@
package dev.struchkov.godfather.telegram.quarkus.core.util;
import dev.struchkov.godfather.main.domain.content.Mail;
import dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate;
import dev.struchkov.godfather.telegram.domain.attachment.ButtonClickAttachment;
import dev.struchkov.godfather.telegram.domain.attachment.CommandAttachment;
import dev.struchkov.godfather.telegram.main.core.util.Attachments;
import java.util.Optional;
import static dev.struchkov.godfather.quarkus.domain.unit.func.UniPredicate.predicate;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public class UnitTrigger {
private UnitTrigger() {
utilityClass();
}
public static UniPredicate<Mail> clickButtonRaw(String rawCallBackData) {
return predicate(
mail -> {
final Optional<ButtonClickAttachment> optButtonClick = Attachments.findFirstButtonClick(mail.getAttachments());
if (optButtonClick.isPresent()) {
final ButtonClickAttachment buttonClick = optButtonClick.get();
final String rawData = buttonClick.getRawCallBackData();
return rawData.equals(rawCallBackData);
}
return false;
}
);
}
public static UniPredicate<Mail> isCommandByType(String commandType) {
return predicate(
mail -> {
final Optional<CommandAttachment> optCommand = Attachments.findFirstCommand(mail.getAttachments());
if (optCommand.isPresent()) {
final CommandAttachment command = optCommand.get();
final String type = command.getCommandType();
return type.equals(commandType);
}
return false;
}
);
}
public static UniPredicate<Mail> isCommand() {
return predicate(mail -> Attachments.findFirstCommand(mail.getAttachments()).isPresent());
}
public static UniPredicate<Mail> isButtonClick() {
return predicate(mail -> Attachments.findFirstButtonClick(mail.getAttachments()).isPresent());
}
public static UniPredicate<Mail> isButtonClickArg(String argType) {
return predicate(
mail -> Attachments.findFirstButtonClick(mail.getAttachments())
.flatMap(click -> click.getArgByType(argType))
.isPresent()
);
}
public static UniPredicate<Mail> isLinks() {
return predicate(mail -> Attachments.findFirstLink(mail.getAttachments()).isPresent());
}
}