UniTrigger
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Struchkov Mark 2023-03-19 10:29:03 +03:00
parent 9c2f04c483
commit 8f8b524b0e
Signed by: upagge
GPG Key ID: D3018BE7BA428CA6
4 changed files with 61 additions and 4 deletions

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<modelVersion>4.0.0</modelVersion>
<groupId>dev.struchkov.godfather.telegram</groupId>

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<project xmlns="http://maven.apache.org/POM/4.0.0" 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">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>telegram-core</artifactId>

View File

@ -0,0 +1,55 @@
package dev.struchkov.godfather.telegram.quarkus.core.util;
import dev.struchkov.godfather.main.domain.content.Mail;
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 java.util.function.Predicate;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public class UnitTrigger {
private UnitTrigger() {
utilityClass();
}
public static Predicate<Mail> clickButtonRaw(String rawCallBackData) {
return 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 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> isCommand() {
return mail -> Attachments.findFirstCommand(mail.getAttachments()).isPresent();
}
public static Predicate<Mail> isClickButton() {
return mail -> Attachments.findFirstButtonClick(mail.getAttachments()).isPresent();
}
public static Predicate<Mail> isLinks() {
return mail -> Attachments.findFirstLink(mail.getAttachments()).isPresent();
}
}

View File

@ -9,9 +9,9 @@ import java.util.function.Predicate;
import static dev.struchkov.haiti.utils.Exceptions.utilityClass;
public class TriggerChecks {
public class UnitTrigger {
private TriggerChecks() {
private UnitTrigger() {
utilityClass();
}