Доработки для загрузки фото
This commit is contained in:
parent
9192b7cd97
commit
87c565f4d2
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.12</version>
|
||||
<version>0.0.14</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-context</artifactId>
|
||||
|
@ -4,6 +4,7 @@ import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
|
||||
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -16,7 +17,7 @@ public class SimpleKeyBoardLine implements KeyBoardLine {
|
||||
/**
|
||||
* Кнопки в строке.
|
||||
*/
|
||||
protected List<KeyBoardButton> buttons = new ArrayList<>();
|
||||
protected List<KeyBoardButton> buttons;
|
||||
|
||||
public SimpleKeyBoardLine(List<KeyBoardButton> buttons) {
|
||||
this.buttons = buttons;
|
||||
@ -26,8 +27,8 @@ public class SimpleKeyBoardLine implements KeyBoardLine {
|
||||
buttons = builder.buttons;
|
||||
}
|
||||
|
||||
public static SimpleKeyBoardLine simpleLine(KeyBoardButton keyBoardButton) {
|
||||
return new SimpleKeyBoardLine(List.of(keyBoardButton));
|
||||
public static SimpleKeyBoardLine simpleLine(KeyBoardButton... keyBoardButton) {
|
||||
return new SimpleKeyBoardLine(Arrays.stream(keyBoardButton).toList());
|
||||
}
|
||||
|
||||
public static Builder builder() {
|
||||
|
@ -3,9 +3,9 @@ package dev.struchkov.godfather.context.domain.unit;
|
||||
import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.context.domain.TypeUnit;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.repository.preser.AnswerSavePreservable;
|
||||
import dev.struchkov.godfather.context.service.Accessibility;
|
||||
import dev.struchkov.godfather.context.service.save.CheckSave;
|
||||
import dev.struchkov.godfather.context.service.save.Preservable;
|
||||
import dev.struchkov.godfather.context.service.save.PreservableData;
|
||||
import dev.struchkov.godfather.context.service.save.Pusher;
|
||||
|
||||
@ -27,7 +27,7 @@ public class AnswerSave<D> extends MainUnit {
|
||||
/**
|
||||
* Объект отвечающий за сохранение - репозиторий.
|
||||
*/
|
||||
private final Preservable<D> preservable;
|
||||
private final AnswerSavePreservable<D> preservable;
|
||||
|
||||
/**
|
||||
* Ключ для данных.
|
||||
@ -84,7 +84,7 @@ public class AnswerSave<D> extends MainUnit {
|
||||
}
|
||||
}
|
||||
|
||||
public Preservable<D> getPreservable() {
|
||||
public AnswerSavePreservable<D> getPreservable() {
|
||||
return preservable;
|
||||
}
|
||||
|
||||
@ -110,13 +110,13 @@ public class AnswerSave<D> extends MainUnit {
|
||||
|
||||
public static final class Builder<D> {
|
||||
private String name;
|
||||
private Set<KeyWord> keyWords = new HashSet<>();
|
||||
private Set<String> phrases = new HashSet<>();
|
||||
private final Set<KeyWord> keyWords = new HashSet<>();
|
||||
private final Set<String> phrases = new HashSet<>();
|
||||
private Pattern pattern;
|
||||
private Integer matchThreshold;
|
||||
private Integer priority;
|
||||
private Set<MainUnit> nextUnits = new HashSet<>();
|
||||
private Preservable<D> preservable;
|
||||
private AnswerSavePreservable<D> preservable;
|
||||
private String key;
|
||||
private Pusher<D> pusher;
|
||||
private PreservableData<D, ? super Message> preservableData;
|
||||
@ -188,7 +188,7 @@ public class AnswerSave<D> extends MainUnit {
|
||||
return this;
|
||||
}
|
||||
|
||||
public Builder<D> preservable(Preservable<D> val) {
|
||||
public Builder<D> preservable(AnswerSavePreservable<D> val) {
|
||||
this.preservable = val;
|
||||
return this;
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import dev.struchkov.autoresponder.entity.KeyWord;
|
||||
import dev.struchkov.godfather.context.domain.TypeUnit;
|
||||
import dev.struchkov.godfather.context.service.Accessibility;
|
||||
import dev.struchkov.godfather.context.service.ClarificationQuestion;
|
||||
import dev.struchkov.godfather.context.service.save.LocalPreservable;
|
||||
import dev.struchkov.godfather.context.service.save.Preservable;
|
||||
import dev.struchkov.godfather.context.repository.preser.AnswerSaveMapPreservable;
|
||||
import dev.struchkov.godfather.context.repository.preser.Preservable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
@ -35,7 +35,7 @@ public class AnswerValidity extends MainUnit {
|
||||
*/
|
||||
private final MainUnit unitNull;
|
||||
|
||||
private final Preservable<String> tempSave = new LocalPreservable<>();
|
||||
private final Preservable<String> tempSave = new AnswerSaveMapPreservable<>();
|
||||
|
||||
private final ClarificationQuestion clarificationQuestion;
|
||||
|
||||
|
@ -57,6 +57,18 @@ public class RollBackCmd extends MainUnit {
|
||||
return RollBackCmd.builder().countBack(1).build();
|
||||
}
|
||||
|
||||
public static RollBackCmd doubleRollBack() {
|
||||
return RollBackCmd.builder().countBack(2).build();
|
||||
}
|
||||
|
||||
public static RollBackCmd rollBack(String unitName) {
|
||||
return RollBackCmd.builder().rollbackUnitName(unitName).build();
|
||||
}
|
||||
|
||||
public static RollBackCmd rollBack(String phrase, String unitName) {
|
||||
return RollBackCmd.builder().phrase(phrase).rollbackUnitName(unitName).build();
|
||||
}
|
||||
|
||||
public int getCountBack() {
|
||||
return countBack;
|
||||
}
|
||||
|
@ -0,0 +1,37 @@
|
||||
package dev.struchkov.godfather.context.repository.preser;
|
||||
|
||||
import dev.struchkov.godfather.context.service.save.Pusher;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class AnswerSaveMapPreservable<S> implements AnswerSavePreservable<S> {
|
||||
|
||||
private final Map<Long, Map<String, S>> saveMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void save(Long personId, String key, S save) {
|
||||
saveMap.computeIfAbsent(personId, k -> new HashMap<>()).put(key, save);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S> getByKey(Long personId, String key) {
|
||||
if (saveMap.containsKey(personId)
|
||||
&& saveMap.get(personId).containsKey(key)) {
|
||||
return Optional.of(saveMap.get(personId).get(key));
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, S> getAllSaveElement(Long personId) {
|
||||
return saveMap.get(personId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void push(Long personId, Pusher<S> pusher) {
|
||||
Optional.ofNullable(pusher).ifPresent(sPusher -> sPusher.push(getAllSaveElement(personId)));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
package dev.struchkov.godfather.context.repository.preser;
|
||||
|
||||
import dev.struchkov.godfather.context.service.save.Pusher;
|
||||
|
||||
public interface AnswerSavePreservable<T> extends Preservable<T> {
|
||||
|
||||
/**
|
||||
* Финальное сохранение, можно реализовать как отправку данных куда-то
|
||||
*
|
||||
* @param personId Идентификатор пользователя
|
||||
*/
|
||||
void push(Long personId, Pusher<T> pusher);
|
||||
|
||||
}
|
@ -1,6 +1,4 @@
|
||||
package dev.struchkov.godfather.context.service.save;
|
||||
|
||||
import dev.struchkov.godfather.context.service.save.Pusher;
|
||||
package dev.struchkov.godfather.context.repository.preser;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -22,15 +20,6 @@ public interface Preservable<S> {
|
||||
|
||||
Optional<S> getByKey(Long personId, String key);
|
||||
|
||||
/**
|
||||
* Финальное сохранение, можно реализовать как отправку данных куда-то
|
||||
*
|
||||
* @param personId Идентификатор пользователя
|
||||
*/
|
||||
default void push(Long personId, Pusher<S> pusher) {
|
||||
Optional.ofNullable(pusher).ifPresent(sPusher -> sPusher.push(getAllSaveElement(personId)));
|
||||
}
|
||||
|
||||
Map<String, S> getAllSaveElement(Long personId);
|
||||
|
||||
}
|
@ -0,0 +1,10 @@
|
||||
package dev.struchkov.godfather.context.service;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.domain.unit.AnswerText;
|
||||
|
||||
public interface UnitContextFactory<M extends Message> {
|
||||
|
||||
AnswerText.Builder<M> createAnswerText();
|
||||
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
package dev.struchkov.godfather.context.service.save;
|
||||
|
||||
import dev.struchkov.godfather.context.service.save.Preservable;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
public class LocalPreservable<S> implements Preservable<S> {
|
||||
|
||||
private final Map<Long, Map<String, S>> saveMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void save(Long personId, String key, S save) {
|
||||
if (!saveMap.containsKey(personId)) {
|
||||
saveMap.put(personId, new HashMap<>());
|
||||
}
|
||||
saveMap.get(personId).put(key, save);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<S> getByKey(Long personId, String key) {
|
||||
if (saveMap.containsKey(personId)) {
|
||||
if (saveMap.get(personId).containsKey(key)) {
|
||||
return Optional.of(saveMap.get(personId).get(key));
|
||||
}
|
||||
}
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, S> getAllSaveElement(Long personId) {
|
||||
return saveMap.get(personId);
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
package dev.struchkov.godfather.context.service.usercode;
|
||||
|
||||
import dev.struchkov.godfather.context.domain.BoxAnswer;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ProcessingData<C extends Message> {
|
||||
public interface ProcessingData<C> {
|
||||
|
||||
BoxAnswer processing(C content);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
<parent>
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.12</version>
|
||||
<version>0.0.14</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>bot-core</artifactId>
|
||||
|
@ -4,8 +4,8 @@ import dev.struchkov.godfather.context.domain.UnitRequest;
|
||||
import dev.struchkov.godfather.context.domain.content.Message;
|
||||
import dev.struchkov.godfather.context.domain.unit.AnswerSave;
|
||||
import dev.struchkov.godfather.context.domain.unit.MainUnit;
|
||||
import dev.struchkov.godfather.context.repository.preser.AnswerSavePreservable;
|
||||
import dev.struchkov.godfather.context.service.save.CheckSave;
|
||||
import dev.struchkov.godfather.context.service.save.Preservable;
|
||||
import dev.struchkov.godfather.context.service.save.PreservableData;
|
||||
|
||||
/**
|
||||
@ -20,7 +20,7 @@ public class AnswerSaveAction<D> implements ActionUnit<AnswerSave<D>, Message> {
|
||||
final AnswerSave<D> answerSave = unitRequest.getUnit();
|
||||
final Message message = unitRequest.getMessage();
|
||||
|
||||
final Preservable<D> preservable = answerSave.getPreservable();
|
||||
final AnswerSavePreservable<D> preservable = answerSave.getPreservable();
|
||||
final Long personId = message.getPersonId();
|
||||
|
||||
final CheckSave<? super Message> checkSave = answerSave.getCheckSave();
|
||||
|
@ -9,7 +9,7 @@
|
||||
//import dev.struchkov.godfather.core.domain.unit.AnswerText;
|
||||
//import dev.struchkov.godfather.core.domain.unit.MainUnit;
|
||||
//import dev.struchkov.godfather.core.domain.unit.UnitActiveType;
|
||||
//import dev.struchkov.godfather.context.service.save.Preservable;
|
||||
//import dev.struchkov.godfather.context.repository.preser.Preservable;
|
||||
//import dev.struchkov.godfather.context.service.save.Pusher;
|
||||
//
|
||||
//import java.util.List;
|
||||
|
4
pom.xml
4
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>dev.struchkov.godfather</groupId>
|
||||
<artifactId>godfather-bot</artifactId>
|
||||
<version>0.0.12</version>
|
||||
<version>0.0.14</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<modules>
|
||||
@ -32,7 +32,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
|
||||
<godfather.ver>0.0.12</godfather.ver>
|
||||
<godfather.ver>0.0.14</godfather.ver>
|
||||
|
||||
<godfather.context.ver>${godfather.ver}</godfather.context.ver>
|
||||
<godfather.core.ver>${godfather.ver}</godfather.core.ver>
|
||||
|
Loading…
Reference in New Issue
Block a user