Размышления над архитектурой
* Продолжаю настроивать взаимодействие с юнитами * Главный класс автоответчика разбил на методы
This commit is contained in:
parent
b5a8680f09
commit
04062ba8b1
12
pom.xml
12
pom.xml
@ -20,11 +20,20 @@
|
|||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>uPagge</id>
|
||||||
|
<name>Struchkov Mark</name>
|
||||||
|
<email>upagge@mail.ru</email>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<gson.ver>2.8.5</gson.ver>
|
<gson.ver>2.8.5</gson.ver>
|
||||||
<vksdk.ver>0.5.13-SNAPSHOT</vksdk.ver>
|
<vksdk.ver>0.5.13-SNAPSHOT</vksdk.ver>
|
||||||
<log4j.ver>1.2.17</log4j.ver>
|
<log4j.ver>1.2.17</log4j.ver>
|
||||||
<json.ver>20180813</json.ver>
|
<json.ver>20180813</json.ver>
|
||||||
|
<autoresponder.ver>1.1.2-SNAPHOT</autoresponder.ver>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -51,8 +60,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.sadtech.autoresponder</groupId>
|
<groupId>org.sadtech.autoresponder</groupId>
|
||||||
<artifactId>autoresponder</artifactId>
|
<artifactId>autoresponder</artifactId>
|
||||||
<version>1.1.2-SNAPHOT</version>
|
<version>${autoresponder.ver}</version>
|
||||||
<scope>compile</scope>
|
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.entity.unit;
|
|
||||||
|
|
||||||
import org.sadtech.vkbot.autoresponder.DataService;
|
|
||||||
|
|
||||||
public class SaveAnswer extends TextAnswer {
|
|
||||||
|
|
||||||
private SaveAnswer prevSaveAnswer;
|
|
||||||
private DataService dataService;
|
|
||||||
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.entity.unit;
|
|
||||||
|
|
||||||
import org.sadtech.vkbot.core.keyboard.KeyBoard;
|
|
||||||
|
|
||||||
public class TextAndKeyBoardAnswer extends TextAnswer {
|
|
||||||
|
|
||||||
KeyBoard keyBoard;
|
|
||||||
|
|
||||||
public KeyBoard getKeyBoard() {
|
|
||||||
return keyBoard;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKeyBoard(KeyBoard keyBoard) {
|
|
||||||
this.keyBoard = keyBoard;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,16 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.entity.unit;
|
|
||||||
|
|
||||||
import org.sadtech.autoresponder.entity.Unit;
|
|
||||||
|
|
||||||
public class TextAnswer extends Unit {
|
|
||||||
|
|
||||||
private String answer;
|
|
||||||
|
|
||||||
public String getAnswer() {
|
|
||||||
return answer;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAnswer(String answer) {
|
|
||||||
this.answer = answer;
|
|
||||||
}
|
|
||||||
}
|
|
@ -0,0 +1,7 @@
|
|||||||
|
package org.sadtech.vkbot.core.keyboard;
|
||||||
|
|
||||||
|
public interface ButtonKeyBoardService {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,4 @@
|
|||||||
|
package org.sadtech.vkbot.core.keyboard;
|
||||||
|
|
||||||
|
public interface LineKeyBoardService {
|
||||||
|
}
|
@ -1,6 +1,6 @@
|
|||||||
package org.sadtech.vkbot.core.listener;
|
package org.sadtech.vkbot.core.listener;
|
||||||
|
|
||||||
public interface EventListenable extends Runnable {
|
public interface EventListener extends Runnable {
|
||||||
|
|
||||||
void listen() throws Exception;
|
void listen() throws Exception;
|
||||||
|
|
@ -1,4 +1,4 @@
|
|||||||
package org.sadtech.vkbot.core.listener.impl;
|
package org.sadtech.vkbot.core.listener;
|
||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.vk.api.sdk.actions.LongPoll;
|
import com.vk.api.sdk.actions.LongPoll;
|
||||||
@ -15,9 +15,8 @@ import org.sadtech.vkbot.core.repository.EventRepository;
|
|||||||
import org.sadtech.vkbot.core.repository.impl.EventRepositoryQueue;
|
import org.sadtech.vkbot.core.repository.impl.EventRepositoryQueue;
|
||||||
import org.sadtech.vkbot.core.service.EventService;
|
import org.sadtech.vkbot.core.service.EventService;
|
||||||
import org.sadtech.vkbot.core.service.impl.EventServiceImpl;
|
import org.sadtech.vkbot.core.service.impl.EventServiceImpl;
|
||||||
import org.sadtech.vkbot.core.listener.EventListenable;
|
|
||||||
|
|
||||||
public class EventListenerVk implements EventListenable, Runnable {
|
public class EventListenerVk implements EventListener, Runnable {
|
||||||
|
|
||||||
public static final Logger log = Logger.getLogger(EventListenerVk.class);
|
public static final Logger log = Logger.getLogger(EventListenerVk.class);
|
||||||
|
|
@ -1,24 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.repository.unit;
|
|
||||||
|
|
||||||
import org.sadtech.vkbot.core.entity.unit.TextAndKeyBoardAnswer;
|
|
||||||
import org.sadtech.autoresponder.repository.UnitRepository;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TextAndKeyBoardAnswerRepository implements UnitRepository<TextAndKeyBoardAnswer> {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addUnit(TextAndKeyBoardAnswer unit) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addUnits(List<TextAndKeyBoardAnswer> units) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TextAndKeyBoardAnswer> menuUnits() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.repository.unit;
|
|
||||||
|
|
||||||
import org.sadtech.vkbot.core.entity.unit.TextAnswer;
|
|
||||||
import org.sadtech.autoresponder.repository.UnitRepository;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class TextAnswerRepository implements UnitRepository<TextAnswer> {
|
|
||||||
|
|
||||||
private List<TextAnswer> textAnswers;
|
|
||||||
|
|
||||||
public TextAnswerRepository() {
|
|
||||||
textAnswers = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextAnswerRepository(List<TextAnswer> textAnswers) {
|
|
||||||
this.textAnswers = textAnswers;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addUnit(TextAnswer unit) {
|
|
||||||
textAnswers.add(unit);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addUnits(List<TextAnswer> units) {
|
|
||||||
textAnswers.addAll(units);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public List<TextAnswer> menuUnits() {
|
|
||||||
return textAnswers;
|
|
||||||
}
|
|
||||||
}
|
|
@ -6,9 +6,8 @@ import com.vk.api.sdk.exceptions.ApiException;
|
|||||||
import com.vk.api.sdk.exceptions.ClientException;
|
import com.vk.api.sdk.exceptions.ClientException;
|
||||||
import org.sadtech.vkbot.core.VkConnect;
|
import org.sadtech.vkbot.core.VkConnect;
|
||||||
import org.sadtech.vkbot.core.entity.Person;
|
import org.sadtech.vkbot.core.entity.Person;
|
||||||
import org.sadtech.vkbot.core.keyboard.KeyBoard;
|
|
||||||
|
|
||||||
public class MailSanderVk {
|
public class MailSanderVk implements MailSandler {
|
||||||
|
|
||||||
private Person person;
|
private Person person;
|
||||||
private VkApiClient vkApiClient;
|
private VkApiClient vkApiClient;
|
||||||
@ -29,20 +28,12 @@ public class MailSanderVk {
|
|||||||
this.person = person;
|
this.person = person;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendText(String messageText) {
|
@Override
|
||||||
|
public void send(String text) {
|
||||||
try {
|
try {
|
||||||
vkApiClient.messages().send(groupActor).userId(person.getId()).message(messageText).execute();
|
vkApiClient.messages().send(groupActor).userId(person.getId()).message(text).execute();
|
||||||
} catch (ApiException | ClientException e) {
|
} catch (ApiException | ClientException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void sendTextandKeyBoard(String message, KeyBoard keyBoard) {
|
|
||||||
try {
|
|
||||||
vkApiClient.messages().send(groupActor).userId(person.getId()).message(message).keyboard(keyBoard.getKeyboard(true).toString()).execute();
|
|
||||||
} catch (ApiException | ClientException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
11
src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java
Normal file
11
src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package org.sadtech.vkbot.core.sender;
|
||||||
|
|
||||||
|
import org.sadtech.vkbot.core.entity.Person;
|
||||||
|
|
||||||
|
public interface MailSandler {
|
||||||
|
|
||||||
|
void send(String text);
|
||||||
|
|
||||||
|
void setPerson(Person person);
|
||||||
|
|
||||||
|
}
|
@ -33,6 +33,7 @@ public class MailServiceImpl implements MailService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Mail> getFirstMailByTime(Integer timeFrom, Integer timeTo) {
|
public List<Mail> getFirstMailByTime(Integer timeFrom, Integer timeTo) {
|
||||||
|
log.info("Запрошены сообщения от " + timeFrom + " до " + timeTo);
|
||||||
List<Mail> mails = messageRepository.getMailByTime(timeFrom, timeTo);
|
List<Mail> mails = messageRepository.getMailByTime(timeFrom, timeTo);
|
||||||
Set<Person> people = new HashSet<>();
|
Set<Person> people = new HashSet<>();
|
||||||
List<Mail> returnMails = new ArrayList<>();
|
List<Mail> returnMails = new ArrayList<>();
|
||||||
|
Loading…
Reference in New Issue
Block a user