Абстрактный класс для автоответчика
Чтобы можно было реализовать автоответчики для комментариев и прочего
This commit is contained in:
parent
85a9849c0a
commit
809d17715e
@ -4,7 +4,7 @@ import com.google.gson.JsonObject;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.sadtech.vkbot.core.distribution.EventDistributable;
|
import org.sadtech.vkbot.core.distribution.EventDistributable;
|
||||||
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
import org.sadtech.vkbot.core.distribution.EventSubscribe;
|
||||||
import org.sadtech.vkbot.core.service.EventService;
|
import org.sadtech.vkbot.core.service.RawEventService;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -13,18 +13,18 @@ public class EventDistributorVK implements EventDistributable, Runnable {
|
|||||||
|
|
||||||
public static final Logger log = Logger.getLogger(EventDistributorVK.class);
|
public static final Logger log = Logger.getLogger(EventDistributorVK.class);
|
||||||
|
|
||||||
private EventService eventService;
|
private RawEventService rawEventService;
|
||||||
private Map<String, EventSubscribe> eventDistributionMap = new HashMap<>();
|
private Map<String, EventSubscribe> eventDistributionMap = new HashMap<>();
|
||||||
|
|
||||||
public EventDistributorVK(EventService eventService) {
|
public EventDistributorVK(RawEventService rawEventService) {
|
||||||
this.eventService = eventService;
|
this.rawEventService = rawEventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void distribute() {
|
public void distribute() {
|
||||||
while (true) {
|
while (true) {
|
||||||
if (eventService.getJsonObjects().peek() != null) {
|
if (rawEventService.getJsonObjects().peek() != null) {
|
||||||
JsonObject event = eventService.getJsonObjects().poll();
|
JsonObject event = rawEventService.getJsonObjects().poll();
|
||||||
log.info("Главный дистрибьютор отправил событие дальше");
|
log.info("Главный дистрибьютор отправил событие дальше");
|
||||||
if (eventDistributionMap.containsKey(event.get("type").getAsString())) {
|
if (eventDistributionMap.containsKey(event.get("type").getAsString())) {
|
||||||
eventDistributionMap.get(event.get("type").getAsString()).update(event.getAsJsonObject("object"));
|
eventDistributionMap.get(event.get("type").getAsString()).update(event.getAsJsonObject("object"));
|
||||||
|
@ -12,8 +12,8 @@ import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse;
|
|||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.sadtech.vkbot.core.VkConnect;
|
import org.sadtech.vkbot.core.VkConnect;
|
||||||
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.RawEventService;
|
||||||
import org.sadtech.vkbot.core.service.impl.EventServiceImpl;
|
import org.sadtech.vkbot.core.service.impl.RawEventServiceImpl;
|
||||||
|
|
||||||
public class EventListenerVk implements EventListener, Runnable {
|
public class EventListenerVk implements EventListener, Runnable {
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ public class EventListenerVk implements EventListener, Runnable {
|
|||||||
private VkApiClient vk;
|
private VkApiClient vk;
|
||||||
private GroupActor actor;
|
private GroupActor actor;
|
||||||
|
|
||||||
private EventService eventService;
|
private RawEventService rawEventService;
|
||||||
|
|
||||||
private GetLongPollEventsQuery longPollEventsQuery;
|
private GetLongPollEventsQuery longPollEventsQuery;
|
||||||
private LongPoll longPoll;
|
private LongPoll longPoll;
|
||||||
@ -31,19 +31,19 @@ public class EventListenerVk implements EventListener, Runnable {
|
|||||||
public EventListenerVk(VkConnect vkConnect) {
|
public EventListenerVk(VkConnect vkConnect) {
|
||||||
vk = vkConnect.getVkApiClient();
|
vk = vkConnect.getVkApiClient();
|
||||||
actor = vkConnect.getGroupActor();
|
actor = vkConnect.getGroupActor();
|
||||||
eventService = new EventServiceImpl(new EventRepositoryQueue());
|
rawEventService = new RawEventServiceImpl(new EventRepositoryQueue());
|
||||||
longPoll = new LongPoll(vk);
|
longPoll = new LongPoll(vk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventListenerVk(VkConnect vkConnect, EventService eventService) {
|
public EventListenerVk(VkConnect vkConnect, RawEventService rawEventService) {
|
||||||
this.vk = vkConnect.getVkApiClient();
|
this.vk = vkConnect.getVkApiClient();
|
||||||
this.actor = vkConnect.getGroupActor();
|
this.actor = vkConnect.getGroupActor();
|
||||||
this.eventService = eventService;
|
this.rawEventService = rawEventService;
|
||||||
longPoll = new LongPoll(vk);
|
longPoll = new LongPoll(vk);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EventService getEventService() {
|
public RawEventService getRawEventService() {
|
||||||
return eventService;
|
return rawEventService;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void listen() throws ClientException, ApiException {
|
public void listen() throws ClientException, ApiException {
|
||||||
@ -56,7 +56,7 @@ public class EventListenerVk implements EventListener, Runnable {
|
|||||||
log.info("Полученно событие от ВК");
|
log.info("Полученно событие от ВК");
|
||||||
log.info(eventsResponse.getUpdates());
|
log.info(eventsResponse.getUpdates());
|
||||||
for (JsonObject update : eventsResponse.getUpdates()) {
|
for (JsonObject update : eventsResponse.getUpdates()) {
|
||||||
eventService.add(update);
|
rawEventService.add(update);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20);
|
longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20);
|
||||||
|
@ -5,7 +5,7 @@ import org.sadtech.vkbot.core.repository.EventRepository;
|
|||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public interface EventService {
|
public interface RawEventService {
|
||||||
|
|
||||||
void cleanAll();
|
void cleanAll();
|
||||||
|
|
@ -4,7 +4,7 @@ import com.vk.api.sdk.objects.messages.Message;
|
|||||||
import org.sadtech.vkbot.core.entity.Mail;
|
import org.sadtech.vkbot.core.entity.Mail;
|
||||||
import org.sadtech.vkbot.core.service.distribution.impl.EventService;
|
import org.sadtech.vkbot.core.service.distribution.impl.EventService;
|
||||||
|
|
||||||
public interface MailService extends EventService<Mail>, SortEventService<Mail> {
|
public interface MailService extends EventService<Mail> {
|
||||||
|
|
||||||
void add(Message message);
|
void add(Message message);
|
||||||
|
|
||||||
|
@ -1,13 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.service.distribution;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public interface SortEventService<T> {
|
|
||||||
|
|
||||||
List<T> getEvent(Integer timeFrom, Integer timeTo);
|
|
||||||
|
|
||||||
List<T> getFirstMailByTime(Integer timeFrom, Integer timeTo);
|
|
||||||
|
|
||||||
List<T> getLastMailByTime(Integer timeFrom, Integer timeTo);
|
|
||||||
|
|
||||||
}
|
|
@ -4,6 +4,8 @@ import org.sadtech.vkbot.core.entity.Comment;
|
|||||||
import org.sadtech.vkbot.core.repository.CommentRepository;
|
import org.sadtech.vkbot.core.repository.CommentRepository;
|
||||||
import org.sadtech.vkbot.core.service.distribution.CommentService;
|
import org.sadtech.vkbot.core.service.distribution.CommentService;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class CommentServiceImpl implements CommentService {
|
public class CommentServiceImpl implements CommentService {
|
||||||
|
|
||||||
private CommentRepository commentRepository;
|
private CommentRepository commentRepository;
|
||||||
@ -16,4 +18,19 @@ public class CommentServiceImpl implements CommentService {
|
|||||||
public void add(Comment comment) {
|
public void add(Comment comment) {
|
||||||
commentRepository.add(comment);
|
commentRepository.add(comment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Comment> getEvent(Integer timeFrom, Integer timeTo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Comment> getFirstMailByTime(Integer timeFrom, Integer timeTo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<Comment> getLastMailByTime(Integer timeFrom, Integer timeTo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,15 @@
|
|||||||
package org.sadtech.vkbot.core.service.distribution.impl;
|
package org.sadtech.vkbot.core.service.distribution.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public interface EventService<T> {
|
public interface EventService<T> {
|
||||||
|
|
||||||
void add(T event);
|
void add(T event);
|
||||||
|
|
||||||
|
List<T> getEvent(Integer timeFrom, Integer timeTo);
|
||||||
|
|
||||||
|
List<T> getFirstMailByTime(Integer timeFrom, Integer timeTo);
|
||||||
|
|
||||||
|
List<T> getLastMailByTime(Integer timeFrom, Integer timeTo);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -3,17 +3,17 @@ package org.sadtech.vkbot.core.service.impl;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.sadtech.vkbot.core.repository.EventRepository;
|
import org.sadtech.vkbot.core.repository.EventRepository;
|
||||||
import org.sadtech.vkbot.core.service.EventService;
|
import org.sadtech.vkbot.core.service.RawEventService;
|
||||||
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
|
|
||||||
public class EventServiceImpl implements EventService {
|
public class RawEventServiceImpl implements RawEventService {
|
||||||
|
|
||||||
public static final Logger log = Logger.getLogger(EventServiceImpl.class);
|
public static final Logger log = Logger.getLogger(RawEventServiceImpl.class);
|
||||||
|
|
||||||
private EventRepository eventRepository;
|
private EventRepository eventRepository;
|
||||||
|
|
||||||
public EventServiceImpl(EventRepository eventRepository) {
|
public RawEventServiceImpl(EventRepository eventRepository) {
|
||||||
this.eventRepository = eventRepository;
|
this.eventRepository = eventRepository;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user