Новый сортировщик для бесед

This commit is contained in:
Mark Struchkov 2019-02-06 01:44:22 +03:00
parent f6e69a374c
commit f4d5946d77
3 changed files with 29 additions and 12 deletions

View File

@ -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<Message> {
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<JsonObject> {
@Override
public void update(JsonObject object) {
public void update(Message message) {
mailService.add(message);
}
}

View File

@ -47,11 +47,11 @@ public class MailSubscriber implements EventSubscribe<JsonObject>, 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<JsonObject>, EventDistribu
log.info("Сообщение отправленно на добавление в репозиторий");
mailService.add(userMessage);
}
// }
}
}

View File

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