Доработки для загрузки фото

This commit is contained in:
Struchkov Mark 2022-07-19 20:36:31 +03:00
parent 9192b7cd97
commit 87c565f4d2
15 changed files with 96 additions and 71 deletions

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.12</version> <version>0.0.14</version>
</parent> </parent>
<artifactId>bot-context</artifactId> <artifactId>bot-context</artifactId>

View File

@ -4,6 +4,7 @@ import dev.struchkov.godfather.context.domain.keyboard.KeyBoardButton;
import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine; import dev.struchkov.godfather.context.domain.keyboard.KeyBoardLine;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; 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) { public SimpleKeyBoardLine(List<KeyBoardButton> buttons) {
this.buttons = buttons; this.buttons = buttons;
@ -26,8 +27,8 @@ public class SimpleKeyBoardLine implements KeyBoardLine {
buttons = builder.buttons; buttons = builder.buttons;
} }
public static SimpleKeyBoardLine simpleLine(KeyBoardButton keyBoardButton) { public static SimpleKeyBoardLine simpleLine(KeyBoardButton... keyBoardButton) {
return new SimpleKeyBoardLine(List.of(keyBoardButton)); return new SimpleKeyBoardLine(Arrays.stream(keyBoardButton).toList());
} }
public static Builder builder() { public static Builder builder() {

View File

@ -3,9 +3,9 @@ package dev.struchkov.godfather.context.domain.unit;
import dev.struchkov.autoresponder.entity.KeyWord; import dev.struchkov.autoresponder.entity.KeyWord;
import dev.struchkov.godfather.context.domain.TypeUnit; import dev.struchkov.godfather.context.domain.TypeUnit;
import dev.struchkov.godfather.context.domain.content.Message; 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.Accessibility;
import dev.struchkov.godfather.context.service.save.CheckSave; 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.PreservableData;
import dev.struchkov.godfather.context.service.save.Pusher; 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; return preservable;
} }
@ -110,13 +110,13 @@ public class AnswerSave<D> extends MainUnit {
public static final class Builder<D> { public static final class Builder<D> {
private String name; private String name;
private Set<KeyWord> keyWords = new HashSet<>(); private final Set<KeyWord> keyWords = new HashSet<>();
private Set<String> phrases = new HashSet<>(); private final Set<String> phrases = new HashSet<>();
private Pattern pattern; private Pattern pattern;
private Integer matchThreshold; private Integer matchThreshold;
private Integer priority; private Integer priority;
private Set<MainUnit> nextUnits = new HashSet<>(); private Set<MainUnit> nextUnits = new HashSet<>();
private Preservable<D> preservable; private AnswerSavePreservable<D> preservable;
private String key; private String key;
private Pusher<D> pusher; private Pusher<D> pusher;
private PreservableData<D, ? super Message> preservableData; private PreservableData<D, ? super Message> preservableData;
@ -188,7 +188,7 @@ public class AnswerSave<D> extends MainUnit {
return this; return this;
} }
public Builder<D> preservable(Preservable<D> val) { public Builder<D> preservable(AnswerSavePreservable<D> val) {
this.preservable = val; this.preservable = val;
return this; return this;
} }

View File

@ -4,8 +4,8 @@ import dev.struchkov.autoresponder.entity.KeyWord;
import dev.struchkov.godfather.context.domain.TypeUnit; import dev.struchkov.godfather.context.domain.TypeUnit;
import dev.struchkov.godfather.context.service.Accessibility; import dev.struchkov.godfather.context.service.Accessibility;
import dev.struchkov.godfather.context.service.ClarificationQuestion; import dev.struchkov.godfather.context.service.ClarificationQuestion;
import dev.struchkov.godfather.context.service.save.LocalPreservable; import dev.struchkov.godfather.context.repository.preser.AnswerSaveMapPreservable;
import dev.struchkov.godfather.context.service.save.Preservable; import dev.struchkov.godfather.context.repository.preser.Preservable;
import java.util.Collection; import java.util.Collection;
import java.util.HashSet; import java.util.HashSet;
@ -35,7 +35,7 @@ public class AnswerValidity extends MainUnit {
*/ */
private final MainUnit unitNull; private final MainUnit unitNull;
private final Preservable<String> tempSave = new LocalPreservable<>(); private final Preservable<String> tempSave = new AnswerSaveMapPreservable<>();
private final ClarificationQuestion clarificationQuestion; private final ClarificationQuestion clarificationQuestion;

View File

@ -57,6 +57,18 @@ public class RollBackCmd extends MainUnit {
return RollBackCmd.builder().countBack(1).build(); 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() { public int getCountBack() {
return countBack; return countBack;
} }

View File

@ -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)));
}
}

View File

@ -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);
}

View File

@ -1,6 +1,4 @@
package dev.struchkov.godfather.context.service.save; package dev.struchkov.godfather.context.repository.preser;
import dev.struchkov.godfather.context.service.save.Pusher;
import java.util.Map; import java.util.Map;
import java.util.Optional; import java.util.Optional;
@ -22,15 +20,6 @@ public interface Preservable<S> {
Optional<S> getByKey(Long personId, String key); 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); Map<String, S> getAllSaveElement(Long personId);
} }

View File

@ -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();
}

View File

@ -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);
}
}

View File

@ -1,10 +1,9 @@
package dev.struchkov.godfather.context.service.usercode; package dev.struchkov.godfather.context.service.usercode;
import dev.struchkov.godfather.context.domain.BoxAnswer; import dev.struchkov.godfather.context.domain.BoxAnswer;
import dev.struchkov.godfather.context.domain.content.Message;
@FunctionalInterface @FunctionalInterface
public interface ProcessingData<C extends Message> { public interface ProcessingData<C> {
BoxAnswer processing(C content); BoxAnswer processing(C content);

View File

@ -6,7 +6,7 @@
<parent> <parent>
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.12</version> <version>0.0.14</version>
</parent> </parent>
<artifactId>bot-core</artifactId> <artifactId>bot-core</artifactId>

View File

@ -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.content.Message;
import dev.struchkov.godfather.context.domain.unit.AnswerSave; import dev.struchkov.godfather.context.domain.unit.AnswerSave;
import dev.struchkov.godfather.context.domain.unit.MainUnit; 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.CheckSave;
import dev.struchkov.godfather.context.service.save.Preservable;
import dev.struchkov.godfather.context.service.save.PreservableData; 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 AnswerSave<D> answerSave = unitRequest.getUnit();
final Message message = unitRequest.getMessage(); final Message message = unitRequest.getMessage();
final Preservable<D> preservable = answerSave.getPreservable(); final AnswerSavePreservable<D> preservable = answerSave.getPreservable();
final Long personId = message.getPersonId(); final Long personId = message.getPersonId();
final CheckSave<? super Message> checkSave = answerSave.getCheckSave(); final CheckSave<? super Message> checkSave = answerSave.getCheckSave();

View File

@ -9,7 +9,7 @@
//import dev.struchkov.godfather.core.domain.unit.AnswerText; //import dev.struchkov.godfather.core.domain.unit.AnswerText;
//import dev.struchkov.godfather.core.domain.unit.MainUnit; //import dev.struchkov.godfather.core.domain.unit.MainUnit;
//import dev.struchkov.godfather.core.domain.unit.UnitActiveType; //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 dev.struchkov.godfather.context.service.save.Pusher;
// //
//import java.util.List; //import java.util.List;

View File

@ -6,7 +6,7 @@
<groupId>dev.struchkov.godfather</groupId> <groupId>dev.struchkov.godfather</groupId>
<artifactId>godfather-bot</artifactId> <artifactId>godfather-bot</artifactId>
<version>0.0.12</version> <version>0.0.14</version>
<packaging>pom</packaging> <packaging>pom</packaging>
<modules> <modules>
@ -32,7 +32,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <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.context.ver>${godfather.ver}</godfather.context.ver>
<godfather.core.ver>${godfather.ver}</godfather.core.ver> <godfather.core.ver>${godfather.ver}</godfather.core.ver>