Актуализация с socail-utils
Рефакторинг lombok Добавил вложенные сообщения
This commit is contained in:
parent
9207713665
commit
8f5242c48f
7
pom.xml
7
pom.xml
@ -26,7 +26,6 @@
|
||||
<social.core.ver>0.6.3-SNAPSHOT</social.core.ver>
|
||||
|
||||
<vksdk.ver>0.5.13-FORK</vksdk.ver>
|
||||
<log4j.ver>1.2.17</log4j.ver>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
@ -36,12 +35,6 @@
|
||||
<version>${vksdk.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>${log4j.ver}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.sadtech.social</groupId>
|
||||
<artifactId>social-core</artifactId>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.sadtech.vkbot.core.convert;
|
||||
|
||||
import com.vk.api.sdk.objects.messages.ForeignMessage;
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import com.vk.api.sdk.objects.messages.MessageAttachment;
|
||||
import org.sadtech.social.core.domain.content.Mail;
|
||||
@ -9,6 +10,7 @@ import org.sadtech.social.core.domain.content.attachment.Geo;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.List;
|
||||
import java.util.TimeZone;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -21,13 +23,62 @@ public class MessageMailConvert implements Convert<Message, Mail> {
|
||||
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId()));
|
||||
mail.setId(message.getId());
|
||||
mail.setPersonId(message.getPeerId());
|
||||
mail.setAttachments(message.getAttachments()
|
||||
.stream()
|
||||
List<MessageAttachment> attachments = message.getAttachments();
|
||||
|
||||
if (attachments != null && !attachments.isEmpty()) {
|
||||
mail.setAttachments(
|
||||
attachments.stream()
|
||||
.map(this::convertAttachment)
|
||||
.collect(Collectors.toList()));
|
||||
if (message.getGeo() != null) {
|
||||
mail.getAttachments().add(convertGeo(message.getGeo()));
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
com.vk.api.sdk.objects.base.Geo messageGeo = message.getGeo();
|
||||
if (messageGeo != null) {
|
||||
mail.getAttachments().add(convertGeo(messageGeo));
|
||||
}
|
||||
|
||||
List<ForeignMessage> fwdMessages = message.getFwdMessages();
|
||||
if (fwdMessages != null && !fwdMessages.isEmpty()) {
|
||||
mail.setForwardMail(
|
||||
fwdMessages.stream()
|
||||
.map(this::convertFwdMessage)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
mail.setAddDate(LocalDateTime.now());
|
||||
return mail;
|
||||
}
|
||||
|
||||
private Mail convertFwdMessage(ForeignMessage foreignMessage) {
|
||||
Mail mail = new Mail();
|
||||
mail.setText(foreignMessage.getText());
|
||||
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(foreignMessage.getDate()), TimeZone.getDefault().toZoneId()));
|
||||
mail.setId(foreignMessage.getId());
|
||||
mail.setPersonId(foreignMessage.getPeerId());
|
||||
|
||||
List<MessageAttachment> attachments = foreignMessage.getAttachments();
|
||||
if (attachments != null && !attachments.isEmpty()) {
|
||||
mail.setAttachments(
|
||||
attachments.stream()
|
||||
.map(this::convertAttachment)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
}
|
||||
|
||||
com.vk.api.sdk.objects.base.Geo messageGeo = foreignMessage.getGeo();
|
||||
if (messageGeo != null) {
|
||||
mail.getAttachments().add(convertGeo(messageGeo));
|
||||
}
|
||||
|
||||
List<ForeignMessage> fwdMessages = foreignMessage.getFwdMessages();
|
||||
if (fwdMessages != null && !fwdMessages.isEmpty())
|
||||
mail.setForwardMail(
|
||||
fwdMessages.stream()
|
||||
.map(this::convertFwdMessage)
|
||||
.collect(Collectors.toList())
|
||||
);
|
||||
mail.setAddDate(LocalDateTime.now());
|
||||
return mail;
|
||||
}
|
||||
|
||||
|
@ -2,26 +2,21 @@ package org.sadtech.vkbot.core.distribution.subscriber;
|
||||
|
||||
import com.vk.api.sdk.objects.messages.Message;
|
||||
import com.vk.api.sdk.objects.messages.MessageAttachmentType;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.social.core.domain.BoxAnswer;
|
||||
import org.sadtech.social.core.exception.PaymentException;
|
||||
import org.sadtech.social.core.service.AccountService;
|
||||
import org.sadtech.social.core.service.sender.Sent;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.sadtech.social.core.service.sender.Sending;
|
||||
|
||||
@Slf4j
|
||||
@RequiredArgsConstructor
|
||||
public class AccountSubscribe extends AbstractBasketSubscribe<Message, Message> {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(AccountSubscribe.class);
|
||||
|
||||
private final AccountService accountService;
|
||||
private final Sent sent;
|
||||
private final Sending sending;
|
||||
private BoxAnswer answerSuccessfulPayment;
|
||||
|
||||
public AccountSubscribe(AccountService accountService, Sent sent) {
|
||||
this.accountService = accountService;
|
||||
this.sent = sent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean check(Message userMessage) {
|
||||
return userMessage.getAttachments().size() > 0
|
||||
@ -35,11 +30,11 @@ public class AccountSubscribe extends AbstractBasketSubscribe<Message, Message>
|
||||
try {
|
||||
Integer valueSum = Integer.valueOf(message.getAttachments().get(0).getLink().getTitle().split(" ")[0]);
|
||||
if (accountService.pay(Integer.valueOf(message.getText()), message.getPeerId(), valueSum) && answerSuccessfulPayment != null) {
|
||||
sent.send(message.getPeerId(), answerSuccessfulPayment);
|
||||
sending.send(message.getPeerId(), answerSuccessfulPayment);
|
||||
}
|
||||
} catch (PaymentException e) {
|
||||
log.error(e.getMessage());
|
||||
sent.send(message.getPeerId(), BoxAnswer.builder().message(e.getDescription()).build());
|
||||
sending.send(message.getPeerId(), BoxAnswer.builder().message(e.getDescription()).build());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ import javax.persistence.Table;
|
||||
@NoArgsConstructor
|
||||
public class JsonObjectId extends BasicEntity {
|
||||
|
||||
@Column(name = "json", length = 500)
|
||||
@Column(name = "json", length = 3000)
|
||||
private String json;
|
||||
|
||||
public JsonObjectId(String json) {
|
||||
|
@ -50,7 +50,7 @@ public class EventListenerVk implements Runnable {
|
||||
}
|
||||
|
||||
private LongPollServer getLongPollServer() throws ClientException, ApiException {
|
||||
log.info("LongPoll сервер инициализирован");
|
||||
log.debug("LongPoll сервер инициализирован");
|
||||
if (actor != null) {
|
||||
return vk.groups().getLongPollServer(actor, actor.getGroupId()).execute();
|
||||
} else {
|
||||
|
@ -20,7 +20,10 @@ public class RawEventRepositorySet implements RawEventRepository {
|
||||
jsonObjects.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<JsonObject> findNewEvent() {
|
||||
return jsonObjects;
|
||||
Set<JsonObject> copy = new HashSet<>(jsonObjects);
|
||||
jsonObjects.removeAll(copy);
|
||||
return copy;
|
||||
}
|
||||
}
|
||||
|
@ -10,11 +10,12 @@ import org.sadtech.social.core.domain.keyboard.KeyBoardButton;
|
||||
import org.sadtech.social.core.domain.keyboard.KeyBoardLine;
|
||||
import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText;
|
||||
import org.sadtech.social.core.exception.MailSendException;
|
||||
import org.sadtech.social.core.service.sender.Sent;
|
||||
import org.sadtech.social.core.service.sender.SendType;
|
||||
import org.sadtech.social.core.service.sender.Sending;
|
||||
import org.sadtech.vkbot.core.config.VkConnect;
|
||||
import org.sadtech.vkbot.core.utils.VkInsertData;
|
||||
|
||||
public class BoardCommentSenderVk implements Sent {
|
||||
public class BoardCommentSenderVk implements Sending {
|
||||
|
||||
private final VkApiClient vkApiClient;
|
||||
private final GroupActor groupActor;
|
||||
@ -56,4 +57,9 @@ public class BoardCommentSenderVk implements Sent {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendType getType() {
|
||||
return SendType.PUBLIC;
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,11 @@ import com.vk.api.sdk.exceptions.ApiException;
|
||||
import com.vk.api.sdk.exceptions.ClientException;
|
||||
import com.vk.api.sdk.objects.messages.Keyboard;
|
||||
import com.vk.api.sdk.queries.messages.MessagesSendQuery;
|
||||
import org.apache.log4j.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.social.core.domain.BoxAnswer;
|
||||
import org.sadtech.social.core.domain.keyboard.KeyBoard;
|
||||
import org.sadtech.social.core.service.sender.Sent;
|
||||
import org.sadtech.social.core.service.sender.SendType;
|
||||
import org.sadtech.social.core.service.sender.Sending;
|
||||
import org.sadtech.vkbot.core.config.VkConnect;
|
||||
import org.sadtech.vkbot.core.convert.KeyBoardConvert;
|
||||
import org.sadtech.vkbot.core.utils.VkInsertData;
|
||||
@ -17,9 +18,8 @@ import org.sadtech.vkbot.core.utils.VkInsertData;
|
||||
import java.util.Collections;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
public class MailSenderVk implements Sent {
|
||||
|
||||
private static final Logger log = Logger.getLogger(MailSenderVk.class);
|
||||
@Slf4j
|
||||
public class MailSenderVk implements Sending {
|
||||
|
||||
private final VkApiClient vkApiClient;
|
||||
private final GroupActor groupActor;
|
||||
@ -75,7 +75,7 @@ public class MailSenderVk implements Sent {
|
||||
try {
|
||||
messages.execute();
|
||||
} catch (ApiException | ClientException e) {
|
||||
log.error(e);
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,4 +84,9 @@ public class MailSenderVk implements Sent {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public SendType getType() {
|
||||
return SendType.PRIVATE;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -10,15 +10,14 @@ import com.vk.api.sdk.exceptions.ClientException;
|
||||
import com.vk.api.sdk.objects.users.Fields;
|
||||
import com.vk.api.sdk.objects.users.UserMin;
|
||||
import com.vk.api.sdk.objects.users.UserXtrCounters;
|
||||
import org.apache.log4j.Logger;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.sadtech.vkbot.core.config.VkConnect;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class VkApi {
|
||||
|
||||
private static final Logger log = Logger.getLogger(String.valueOf(VkApi.class));
|
||||
|
||||
private final VkApiClient vk;
|
||||
private final ServiceActor actor;
|
||||
|
||||
@ -36,7 +35,7 @@ public class VkApi {
|
||||
JsonObject object = parser.parse(temp.get(0).toString()).getAsJsonObject();
|
||||
userMin = gson.fromJson(object, UserMin.class);
|
||||
} catch (ApiException | ClientException e) {
|
||||
log.error(e);
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return userMin;
|
||||
}
|
||||
@ -46,7 +45,7 @@ public class VkApi {
|
||||
try {
|
||||
temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(Fields.UNIVERSITIES).execute();
|
||||
} catch (ApiException | ClientException e) {
|
||||
log.error(e);
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
return temp != null ? temp.get(0).getUniversities().get(0).getName() : null;
|
||||
}
|
||||
@ -56,7 +55,7 @@ public class VkApi {
|
||||
try {
|
||||
temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(Fields.CITY).execute();
|
||||
} catch (ApiException | ClientException e) {
|
||||
log.error(e);
|
||||
log.error(e.getMessage());
|
||||
}
|
||||
if (temp != null && checkCity(temp)) {
|
||||
return temp.get(0).getCity().getTitle();
|
||||
|
Reference in New Issue
Block a user