From f4d5946d77ca495ff7f9f2daa85d979e7ee23ccc Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 6 Feb 2019 01:44:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=BE=D0=B2=D1=8B=D0=B9=20=D1=81=D0=BE?= =?UTF-8?q?=D1=80=D1=82=D0=B8=D1=80=D0=BE=D0=B2=D1=89=D0=B8=D0=BA=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=B1=D0=B5=D1=81=D0=B5=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../distribution/impl/MailChatSubscriber.java | 26 ++++++++++++++++--- .../distribution/impl/MailSubscriber.java | 13 +++++----- .../handlers/impl/MailServiceImpl.java | 2 +- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java index 121d141..33c56fa 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailChatSubscriber.java @@ -1,11 +1,29 @@ package org.sadtech.vkbot.core.distribution.impl; -import com.google.gson.JsonObject; +import com.vk.api.sdk.objects.messages.Message; +import org.sadtech.vkbot.core.distribution.EventDistributable; import org.sadtech.vkbot.core.distribution.EventSubscribe; +import org.sadtech.vkbot.core.service.handlers.MailService; + +public class MailChatSubscriber implements EventSubscribe { + + private MailService mailService; + + public MailChatSubscriber(MailService mailService, EventDistributable eventDistributable) { + this.mailService = mailService; + eventDistributable.registerSubscriber("chat", this); + } + + public MailChatSubscriber(EventDistributable eventDistributable) { + eventDistributable.registerSubscriber("chat", this); + } + + public void setMailService(MailService mailService) { + this.mailService = mailService; + } -public class MailChatSubscriber implements EventSubscribe { @Override - public void update(JsonObject object) { - + public void update(Message message) { + mailService.add(message); } } diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java index ffb2f04..55cd800 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/impl/MailSubscriber.java @@ -47,11 +47,11 @@ public class MailSubscriber implements EventSubscribe, EventDistribu log.info("Дистрибьютор получил событие - сообщение"); Gson gson = new Gson(); Message userMessage = gson.fromJson(object, Message.class); -// if (userMessage.getPeerId()>200000000) { -// if (eventDistributionMap.containsKey("chat")) { -// eventDistributionMap.get("chat").update(userMessage); -// } -// } else { + if (userMessage.getPeerId()>2000000000) { + if (eventDistributionMap.containsKey("chat")) { + eventDistributionMap.get("chat").update(userMessage); + } + } else { if (admins.contains(userMessage.getUserId())) { log.info("Сообщение отправлено в репозиторий команд"); eventDistributionMap.get("terminal").update(userMessage); @@ -59,8 +59,7 @@ public class MailSubscriber implements EventSubscribe, EventDistribu log.info("Сообщение отправленно на добавление в репозиторий"); mailService.add(userMessage); } -// } - + } } diff --git a/src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java index 21368c0..2d26725 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/vkbot/core/service/handlers/impl/MailServiceImpl.java @@ -42,7 +42,7 @@ public class MailServiceImpl implements MailService { Mail mail = new Mail(); mail.setDate(message.getDate()); if (!message.getFromId().equals(message.getPeerId())) { - mail.setBody(message.getBody().replaceFirst("\\[club([0-9]+)\\|\\@\\w+] ", "")); + mail.setBody(message.getBody().replaceFirst("\\[club([0-9]+)\\|\\@\\w+][ ,.]", "")); } else { mail.setBody(message.getBody()); }