org.khasanof.executors.matcher.SimpleAudioMatcher Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spring-boot-starter-fluent Show documentation
Show all versions of spring-boot-starter-fluent Show documentation
Fluent - Easy Telegram Bots with Spring
The newest version!
package org.khasanof.executors.matcher;
import org.khasanof.annotation.methods.HandleAudio;
import org.khasanof.enums.scopes.AudioScope;
import org.khasanof.models.matcher.MatcherParameters;
import org.khasanof.models.matcher.MatcherProperty;
import org.khasanof.models.matcher.function.PropertyFunction;
import org.khasanof.service.expression.ExpressionMatcherService;
import org.springframework.stereotype.Component;
import org.telegram.telegrambots.meta.api.objects.Audio;
import org.telegram.telegrambots.meta.api.objects.Message;
import java.util.HashSet;
import java.util.Set;
import java.util.function.Function;
/**
* @author Nurislom
* @see org.khasanof.executors.matcher
* @since 09.07.2023 16:04
*/
@Component
public class SimpleAudioMatcher extends GenericMatcher {
private final Set matcherProperties = new HashSet<>();
public SimpleAudioMatcher(ExpressionMatcherService expressionMatcherService) {
super(expressionMatcherService);
fillMatcherProperties();
}
@Override
public boolean matcher(HandleAudio annotation, Message value) {
return expressionMatcherService.match(createParameters(annotation, value));
}
private MatcherParameters createParameters(HandleAudio annotation, Message value) {
return new MatcherParameters(value, annotation.property(), annotation.match(), annotation.value(), matcherProperties);
}
void fillMatcherProperties() {
matcherProperties.add(new MatcherProperty(AudioScope.TITLE, audioPropertyFunction(Audio::getTitle)));
matcherProperties.add(new MatcherProperty(AudioScope.DURATION, audioPropertyFunction(Audio::getDuration)));
matcherProperties.add(new MatcherProperty(AudioScope.FILE_NAME, audioPropertyFunction(Audio::getFileName)));
matcherProperties.add(new MatcherProperty(AudioScope.FILE_SIZE, audioPropertyFunction(Audio::getFileSize)));
matcherProperties.add(new MatcherProperty(AudioScope.MIME_TYPE, audioPropertyFunction(Audio::getMimeType)));
matcherProperties.add(new MatcherProperty(AudioScope.PERFORMER, audioPropertyFunction(Audio::getPerformer)));
matcherProperties.add(new MatcherProperty(AudioScope.CAPTION, (PropertyFunction) Message::getCaption));
}
private PropertyFunction audioPropertyFunction(Function