Архитектурные изменения автоответчика

This commit is contained in:
Mark Struchkov 2019-02-06 17:24:22 +03:00
parent f4d5946d77
commit 3b29921d2e
7 changed files with 26 additions and 31 deletions

View File

@ -0,0 +1,13 @@
package org.sadtech.vkbot.core.distribution.impl;
import org.sadtech.vkbot.core.distribution.EventSubscribe;
import org.sadtech.vkbot.core.entity.Comment;
public class CommentSubscriber implements EventSubscribe<Comment> {
@Override
public void update(Comment object) {
}
}

View File

@ -26,7 +26,9 @@ public class EventDistributorVK implements EventDistributable, Runnable {
if (eventService.getJsonObjects().peek() != null) {
JsonObject event = eventService.getJsonObjects().poll();
log.info("Главный дистрибьютор отправил событие дальше");
eventDistributionMap.get(event.get("type").getAsString()).update(event.getAsJsonObject("object"));
if (eventDistributionMap.containsKey(event.get("type").getAsString())) {
eventDistributionMap.get(event.get("type").getAsString()).update(event.getAsJsonObject("object"));
}
}
}
}

View File

@ -9,7 +9,7 @@ public class MailChatSubscriber implements EventSubscribe<Message> {
private MailService mailService;
public MailChatSubscriber(MailService mailService, EventDistributable eventDistributable) {
public MailChatSubscriber(EventDistributable eventDistributable, MailService mailService) {
this.mailService = mailService;
eventDistributable.registerSubscriber("chat", this);
}

View File

@ -52,7 +52,7 @@ public class MailSubscriber implements EventSubscribe<JsonObject>, EventDistribu
eventDistributionMap.get("chat").update(userMessage);
}
} else {
if (admins.contains(userMessage.getUserId())) {
if (admins.contains(userMessage.getUserId()) && eventDistributionMap.containsKey("terminal")) {
log.info("Сообщение отправлено в репозиторий команд");
eventDistributionMap.get("terminal").update(userMessage);
} else {

View File

@ -0,0 +1,4 @@
package org.sadtech.vkbot.core.entity;
public class Comment {
}

View File

@ -13,16 +13,16 @@ import org.sadtech.vkbot.core.insert.InsertWords;
import java.util.List;
public class MailSanderVk implements MailSandler {
public class MailSenderVk implements MailSent {
public static final Logger log = Logger.getLogger(MailSanderVk.class);
public static final Logger log = Logger.getLogger(MailSenderVk.class);
private VkApiClient vkApiClient;
private GroupActor groupActor;
private VkInsertData vkInsertData;
public MailSanderVk(VkConnect vkConnect) {
public MailSenderVk(VkConnect vkConnect) {
this.vkApiClient = vkConnect.getVkApiClient();
this.groupActor = vkConnect.getGroupActor();
this.vkInsertData = new VkInsertData(vkConnect);
@ -48,15 +48,6 @@ public class MailSanderVk implements MailSandler {
return messages;
}
@Override
public void send(MailSend mailSend, Integer peerId) {
MessagesSendQuery messages = createMessage(mailSend, peerId);
if (mailSend.getMessage() != null) {
messages.message(mailSend.getMessage());
}
sendMessage(messages);
}
@Override
public void send(MailSend mailSend, Integer peerId, Integer userId) {
MessagesSendQuery messages = createMessage(mailSend, peerId);
@ -66,17 +57,6 @@ public class MailSanderVk implements MailSandler {
sendMessage(messages);
}
public void send(MailSend mailSend, Integer peerId, List<String> insertWords) {
MessagesSendQuery messages = createMessage(mailSend, peerId);
if (mailSend.getMessage() != null) {
InsertWords insert = new InsertWords();
insert.setInText(mailSend.getMessage());
insert.insert(insertWords);
messages.message(insert.getOutText());
}
sendMessage(messages);
}
@Override
public void send(MailSend mailSend, Integer peerId, Integer userId, List<String> insertWords) {
MessagesSendQuery messages = createMessage(mailSend, peerId);

View File

@ -4,14 +4,10 @@ import org.sadtech.vkbot.core.entity.MailSend;
import java.util.List;
public interface MailSandler {
void send(MailSend mailSend, Integer peerId);
public interface MailSent {
void send(MailSend mailSend, Integer peerId, Integer userId);
void send(MailSend mailSend, Integer peerId, List<String> insertWords);
void send(MailSend mailSend, Integer peerId, Integer userId, List<String> insertWords);
}