Сбилдилось
This commit is contained in:
10
pom.xml
10
pom.xml
@@ -23,9 +23,8 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<social.core.ver>0.6.3-SNAPSHOT</social.core.ver>
|
<social.autoresponder.ver>0.6.6-SNAPSHOT</social.autoresponder.ver>
|
||||||
|
<vksdk.ver>1.0.6</vksdk.ver>
|
||||||
<vksdk.ver>0.5.13-FORK</vksdk.ver>
|
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@@ -34,11 +33,10 @@
|
|||||||
<artifactId>sdk</artifactId>
|
<artifactId>sdk</artifactId>
|
||||||
<version>${vksdk.ver}</version>
|
<version>${vksdk.ver}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.sadtech.social</groupId>
|
<groupId>org.sadtech.social</groupId>
|
||||||
<artifactId>social-core</artifactId>
|
<artifactId>social-autoresponder</artifactId>
|
||||||
<version>${social.core.ver}</version>
|
<version>${social.autoresponder.ver}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.springframework.data</groupId>
|
<groupId>org.springframework.data</groupId>
|
||||||
|
|||||||
18
src/main/java/org/sadtech/vkbot/MessageAutoresponderVk.java
Normal file
18
src/main/java/org/sadtech/vkbot/MessageAutoresponderVk.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package org.sadtech.vkbot;
|
||||||
|
|
||||||
|
import org.sadtech.autoresponder.repository.UnitPointerRepository;
|
||||||
|
import org.sadtech.social.bot.GeneralAutoResponder;
|
||||||
|
import org.sadtech.social.bot.domain.unit.MainUnit;
|
||||||
|
import org.sadtech.social.core.domain.content.Mail;
|
||||||
|
import org.sadtech.social.core.service.MessageService;
|
||||||
|
import org.sadtech.social.core.service.sender.Sending;
|
||||||
|
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
public class MessageAutoresponderVk extends GeneralAutoResponder<Mail> {
|
||||||
|
|
||||||
|
public MessageAutoresponderVk(Set<MainUnit> menuUnit, Sending sending, MessageService<Mail> messageService, UnitPointerRepository unitPointerRepository) {
|
||||||
|
super(menuUnit, sending, messageService, unitPointerRepository);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,75 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.config;
|
|
||||||
|
|
||||||
import org.sadtech.vkbot.core.exception.ConfigException;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
import java.util.Optional;
|
|
||||||
|
|
||||||
public class VkConfig {
|
|
||||||
|
|
||||||
private VkConfigGroup configGroup;
|
|
||||||
private VkConfigUser configUser;
|
|
||||||
private VkConfigService configService;
|
|
||||||
|
|
||||||
public VkConfigGroup getConfigGroup() {
|
|
||||||
return Optional.ofNullable(configGroup)
|
|
||||||
.orElseThrow(() -> new ConfigException("Конфигурация сервиса для группы найдена"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkConfigUser getConfigUser() {
|
|
||||||
return Optional.ofNullable(configUser)
|
|
||||||
.orElseThrow(() -> new ConfigException("Конфигурация для пользователя не найдена"));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkConfigService getConfigService() {
|
|
||||||
return Optional.ofNullable(configService)
|
|
||||||
.orElseThrow(() -> new ConfigException("Конфигурация сервиса не найдена"));
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new VkConfig().new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
private Builder() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder configGroup(VkConfigGroup configGroup) {
|
|
||||||
VkConfig.this.configGroup = configGroup;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder configUser(VkConfigUser configUser) {
|
|
||||||
VkConfig.this.configUser = configUser;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder configService(VkConfigService configService) {
|
|
||||||
VkConfig.this.configService = configService;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkConfig build() {
|
|
||||||
return VkConfig.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof VkConfig)) return false;
|
|
||||||
VkConfig vkConfig = (VkConfig) o;
|
|
||||||
return Objects.equals(configGroup, vkConfig.configGroup) &&
|
|
||||||
Objects.equals(configUser, vkConfig.configUser) &&
|
|
||||||
Objects.equals(configService, vkConfig.configService);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(configGroup, configUser, configService);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.config;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class VkConfigGroup {
|
|
||||||
|
|
||||||
private String groupToken;
|
|
||||||
private Integer groupId;
|
|
||||||
|
|
||||||
public String getGroupToken() {
|
|
||||||
return groupToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getGroupId() {
|
|
||||||
return groupId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new VkConfigGroup().new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
private Builder() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder groupId(Integer groupId) {
|
|
||||||
VkConfigGroup.this.groupId = groupId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder groupToken(String groupToken) {
|
|
||||||
VkConfigGroup.this.groupToken = groupToken;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkConfigGroup build() {
|
|
||||||
return VkConfigGroup.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof VkConfigGroup)) return false;
|
|
||||||
VkConfigGroup that = (VkConfigGroup) o;
|
|
||||||
return Objects.equals(groupToken, that.groupToken) &&
|
|
||||||
Objects.equals(groupId, that.groupId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(groupToken, groupId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,56 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.config;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class VkConfigService {
|
|
||||||
|
|
||||||
private String serviceToken;
|
|
||||||
private Integer appId;
|
|
||||||
|
|
||||||
public String getServiceToken() {
|
|
||||||
return serviceToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getAppId() {
|
|
||||||
return appId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new VkConfigService().new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
private Builder() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder serviceToken(String serviceToken) {
|
|
||||||
VkConfigService.this.serviceToken = serviceToken;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder appId(Integer appId) {
|
|
||||||
VkConfigService.this.appId = appId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkConfigService build() {
|
|
||||||
return VkConfigService.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof VkConfigService)) return false;
|
|
||||||
VkConfigService that = (VkConfigService) o;
|
|
||||||
return Objects.equals(serviceToken, that.serviceToken) &&
|
|
||||||
Objects.equals(appId, that.appId);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(serviceToken, appId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.config;
|
|
||||||
|
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
public class VkConfigUser {
|
|
||||||
|
|
||||||
private Integer userId;
|
|
||||||
private String token;
|
|
||||||
|
|
||||||
private VkConfigUser() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Integer getUserId() {
|
|
||||||
return userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getToken() {
|
|
||||||
return token;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Builder builder() {
|
|
||||||
return new VkConfigUser().new Builder();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class Builder {
|
|
||||||
private Builder() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder userId(Integer userId) {
|
|
||||||
VkConfigUser.this.userId = userId;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Builder token(String token) {
|
|
||||||
VkConfigUser.this.token = token;
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkConfigUser build() {
|
|
||||||
return VkConfigUser.this;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object o) {
|
|
||||||
if (this == o) return true;
|
|
||||||
if (!(o instanceof VkConfigUser)) return false;
|
|
||||||
VkConfigUser that = (VkConfigUser) o;
|
|
||||||
return Objects.equals(userId, that.userId) &&
|
|
||||||
Objects.equals(token, that.token);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hash(userId, token);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,73 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.config;
|
|
||||||
|
|
||||||
import com.vk.api.sdk.client.VkApiClient;
|
|
||||||
import com.vk.api.sdk.client.actors.GroupActor;
|
|
||||||
import com.vk.api.sdk.client.actors.ServiceActor;
|
|
||||||
import com.vk.api.sdk.client.actors.UserActor;
|
|
||||||
import com.vk.api.sdk.httpclient.HttpTransportClient;
|
|
||||||
|
|
||||||
public class VkConnect {
|
|
||||||
|
|
||||||
private final VkConfig vkConfig;
|
|
||||||
|
|
||||||
private VkApiClient vkApiClient;
|
|
||||||
private GroupActor groupActor;
|
|
||||||
private ServiceActor serviceActor;
|
|
||||||
private UserActor userActor;
|
|
||||||
|
|
||||||
public VkConnect(VkConfig vkConfig) {
|
|
||||||
this.vkConfig = vkConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VkApiClient getVkApiClient() {
|
|
||||||
if (vkApiClient != null) {
|
|
||||||
return vkApiClient;
|
|
||||||
} else {
|
|
||||||
initVkApiClient();
|
|
||||||
return vkApiClient;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public GroupActor getGroupActor() {
|
|
||||||
if (groupActor != null) {
|
|
||||||
return groupActor;
|
|
||||||
} else {
|
|
||||||
initGroupActor();
|
|
||||||
return groupActor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public UserActor getUserActor() {
|
|
||||||
if (userActor != null) {
|
|
||||||
return userActor;
|
|
||||||
} else {
|
|
||||||
initUserActor();
|
|
||||||
return userActor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initUserActor() {
|
|
||||||
userActor = new UserActor(vkConfig.getConfigUser().getUserId(), vkConfig.getConfigUser().getToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ServiceActor getServiceActor() {
|
|
||||||
if (serviceActor != null) {
|
|
||||||
return serviceActor;
|
|
||||||
} else {
|
|
||||||
initServiceActor();
|
|
||||||
return serviceActor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initVkApiClient() {
|
|
||||||
vkApiClient = new VkApiClient(HttpTransportClient.getInstance());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initGroupActor() {
|
|
||||||
groupActor = new GroupActor(vkConfig.getConfigGroup().getGroupId(), vkConfig.getConfigGroup().getGroupToken());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initServiceActor() {
|
|
||||||
serviceActor = new ServiceActor(vkConfig.getConfigService().getAppId(), vkConfig.getConfigService().getServiceToken());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.convert;
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface Convert<T, C> {
|
|
||||||
|
|
||||||
C converting(T target);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,7 @@ import org.sadtech.social.core.domain.keyboard.KeyBoardButton;
|
|||||||
import org.sadtech.social.core.domain.keyboard.KeyBoardLine;
|
import org.sadtech.social.core.domain.keyboard.KeyBoardLine;
|
||||||
import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonAccount;
|
import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonAccount;
|
||||||
import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText;
|
import org.sadtech.social.core.domain.keyboard.button.KeyBoardButtonText;
|
||||||
import org.sadtech.vkbot.core.config.VkConnect;
|
import org.sadtech.vkbot.config.VkConnect;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.sadtech.social.core.domain.content.Mail;
|
|||||||
import org.sadtech.social.core.domain.content.attachment.Attachment;
|
import org.sadtech.social.core.domain.content.attachment.Attachment;
|
||||||
import org.sadtech.social.core.domain.content.attachment.AudioMessage;
|
import org.sadtech.social.core.domain.content.attachment.AudioMessage;
|
||||||
import org.sadtech.social.core.domain.content.attachment.Geo;
|
import org.sadtech.social.core.domain.content.attachment.Geo;
|
||||||
|
import org.sadtech.vkbot.convert.Convert;
|
||||||
|
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
@@ -21,8 +22,8 @@ public class MessageMailConvert implements Convert<Message, Mail> {
|
|||||||
Mail mail = new Mail();
|
Mail mail = new Mail();
|
||||||
mail.setText(message.getText());
|
mail.setText(message.getText());
|
||||||
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId()));
|
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId()));
|
||||||
mail.setId(message.getId());
|
mail.setId(message.getId().longValue());
|
||||||
mail.setPersonId(message.getPeerId());
|
mail.setPersonId(message.getPeerId().longValue());
|
||||||
List<MessageAttachment> attachments = message.getAttachments();
|
List<MessageAttachment> attachments = message.getAttachments();
|
||||||
|
|
||||||
if (attachments != null && !attachments.isEmpty()) {
|
if (attachments != null && !attachments.isEmpty()) {
|
||||||
@@ -54,8 +55,8 @@ public class MessageMailConvert implements Convert<Message, Mail> {
|
|||||||
Mail mail = new Mail();
|
Mail mail = new Mail();
|
||||||
mail.setText(foreignMessage.getText());
|
mail.setText(foreignMessage.getText());
|
||||||
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(foreignMessage.getDate()), TimeZone.getDefault().toZoneId()));
|
mail.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(foreignMessage.getDate()), TimeZone.getDefault().toZoneId()));
|
||||||
mail.setId(foreignMessage.getId());
|
mail.setId(foreignMessage.getId().longValue());
|
||||||
mail.setPersonId(foreignMessage.getPeerId());
|
mail.setPersonId(foreignMessage.getPeerId().longValue());
|
||||||
|
|
||||||
List<MessageAttachment> attachments = foreignMessage.getAttachments();
|
List<MessageAttachment> attachments = foreignMessage.getAttachments();
|
||||||
if (attachments != null && !attachments.isEmpty()) {
|
if (attachments != null && !attachments.isEmpty()) {
|
||||||
|
|||||||
@@ -1,23 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.convert;
|
|
||||||
|
|
||||||
import com.vk.api.sdk.objects.board.TopicComment;
|
|
||||||
import org.sadtech.social.core.domain.content.BoardComment;
|
|
||||||
|
|
||||||
import java.time.Instant;
|
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
public class TopicCommentToBoardComment implements Convert<TopicComment, BoardComment> {
|
|
||||||
@Override
|
|
||||||
public BoardComment converting(TopicComment target) {
|
|
||||||
BoardComment boardComment = new BoardComment();
|
|
||||||
boardComment.setContentId(target.getTopicId());
|
|
||||||
boardComment.setCreateDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(target.getDate()), TimeZone.getDefault().toZoneId()));
|
|
||||||
boardComment.setText(target.getText());
|
|
||||||
boardComment.setPersonId(target.getFromId());
|
|
||||||
|
|
||||||
|
|
||||||
System.out.println(target);
|
|
||||||
return boardComment;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package org.sadtech.vkbot.core.distribution.subscriber;
|
package org.sadtech.vkbot.core.distribution.subscriber;
|
||||||
|
|
||||||
import org.sadtech.vkbot.core.convert.Convert;
|
import org.sadtech.vkbot.convert.Convert;
|
||||||
|
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|||||||
@@ -30,11 +30,11 @@ public class AccountSubscribe extends AbstractBasketSubscribe<Message, Message>
|
|||||||
try {
|
try {
|
||||||
Integer valueSum = Integer.valueOf(message.getAttachments().get(0).getLink().getTitle().split(" ")[0]);
|
Integer valueSum = Integer.valueOf(message.getAttachments().get(0).getLink().getTitle().split(" ")[0]);
|
||||||
if (accountService.pay(Integer.valueOf(message.getText()), message.getPeerId(), valueSum) && answerSuccessfulPayment != null) {
|
if (accountService.pay(Integer.valueOf(message.getText()), message.getPeerId(), valueSum) && answerSuccessfulPayment != null) {
|
||||||
sending.send(message.getPeerId(), answerSuccessfulPayment);
|
sending.send(message.getPeerId().longValue(), answerSuccessfulPayment);
|
||||||
}
|
}
|
||||||
} catch (PaymentException e) {
|
} catch (PaymentException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
sending.send(message.getPeerId(), BoxAnswer.builder().message(e.getDescription()).build());
|
sending.send(message.getPeerId().longValue(), BoxAnswer.builder().message(e.getDescription()).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,96 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.distribution.subscriber;
|
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
|
||||||
import com.google.gson.JsonObject;
|
|
||||||
import com.vk.api.sdk.objects.board.TopicComment;
|
|
||||||
import org.sadtech.social.core.domain.content.BoardComment;
|
|
||||||
import org.sadtech.social.core.service.BoardCommentService;
|
|
||||||
import org.sadtech.vkbot.core.convert.Convert;
|
|
||||||
import org.sadtech.vkbot.core.convert.TopicCommentToBoardComment;
|
|
||||||
|
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class BoardCommentSubscribe extends AbstractBasketSubscribe<JsonObject, TopicComment> {
|
|
||||||
|
|
||||||
private final BoardCommentService boardCommentService;
|
|
||||||
private final Convert<TopicComment, BoardComment> topicConvert = new TopicCommentToBoardComment();
|
|
||||||
private Set<Integer> answerTopicsId;
|
|
||||||
private Set<Integer> noAnswerPersonId;
|
|
||||||
private Boolean respondAppeal = true;
|
|
||||||
|
|
||||||
public BoardCommentSubscribe(BoardCommentService boardCommentService) {
|
|
||||||
this.boardCommentService = boardCommentService;
|
|
||||||
this.convert = (object) -> {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
return gson.fromJson(object.getAsJsonObject("object"), TopicComment.class);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getAnswerTopicsId() {
|
|
||||||
return answerTopicsId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setAnswerTopicsId(Set<Integer> answerTopicsId) {
|
|
||||||
this.answerTopicsId = answerTopicsId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Set<Integer> getNoAnswerPersonId() {
|
|
||||||
return noAnswerPersonId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setNoAnswerPersonId(Set<Integer> noAnswerPersonId) {
|
|
||||||
this.noAnswerPersonId = noAnswerPersonId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Boolean getRespondAppeal() {
|
|
||||||
return respondAppeal;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setRespondAppeal(Boolean respondAppeal) {
|
|
||||||
this.respondAppeal = respondAppeal;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean check(JsonObject object) {
|
|
||||||
String type = object.get("type").getAsString();
|
|
||||||
return "board_post_new".equals(type);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void processing(TopicComment object) {
|
|
||||||
if (checkPerson(object.getFromId())
|
|
||||||
&& checkTopic(object.getTopicId())
|
|
||||||
&& checkRespondAppeal(object.getText(), object.getFromId())) {
|
|
||||||
boardCommentService.add(topicConvert.converting(object));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkRespondAppeal(String message, Integer groupId) {
|
|
||||||
if (respondAppeal) {
|
|
||||||
Pattern pattern = Pattern.compile("\\[club" + groupId);
|
|
||||||
Matcher m = pattern.matcher(message);
|
|
||||||
return m.find();
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkTopic(Integer topicId) {
|
|
||||||
if (answerTopicsId == null) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return answerTopicsId.contains(topicId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean checkPerson(Integer personId) {
|
|
||||||
if (noAnswerPersonId == null) {
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return !noAnswerPersonId.contains(personId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,7 @@ import com.google.gson.JsonObject;
|
|||||||
import com.vk.api.sdk.objects.messages.Message;
|
import com.vk.api.sdk.objects.messages.Message;
|
||||||
import org.sadtech.social.core.domain.content.Mail;
|
import org.sadtech.social.core.domain.content.Mail;
|
||||||
import org.sadtech.social.core.service.MailService;
|
import org.sadtech.social.core.service.MailService;
|
||||||
import org.sadtech.vkbot.core.convert.Convert;
|
import org.sadtech.vkbot.convert.Convert;
|
||||||
import org.sadtech.vkbot.core.convert.MessageMailConvert;
|
import org.sadtech.vkbot.core.convert.MessageMailConvert;
|
||||||
|
|
||||||
public class MailSubscriber extends AbstractBasketSubscribe<JsonObject, Message> {
|
public class MailSubscriber extends AbstractBasketSubscribe<JsonObject, Message> {
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.exception;
|
|
||||||
|
|
||||||
public class ConfigException extends RuntimeException {
|
|
||||||
|
|
||||||
public ConfigException(String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ import com.vk.api.sdk.exceptions.LongPollServerKeyExpiredException;
|
|||||||
import com.vk.api.sdk.objects.callback.longpoll.responses.GetLongPollEventsResponse;
|
import com.vk.api.sdk.objects.callback.longpoll.responses.GetLongPollEventsResponse;
|
||||||
import com.vk.api.sdk.objects.groups.LongPollServer;
|
import com.vk.api.sdk.objects.groups.LongPollServer;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.sadtech.vkbot.core.config.VkConnect;
|
import org.sadtech.vkbot.config.VkConnect;
|
||||||
import org.sadtech.vkbot.core.service.RawEventService;
|
import org.sadtech.vkbot.core.service.RawEventService;
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
|
|||||||
@@ -1,65 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.sender;
|
|
||||||
|
|
||||||
import com.vk.api.sdk.client.VkApiClient;
|
|
||||||
import com.vk.api.sdk.client.actors.GroupActor;
|
|
||||||
import com.vk.api.sdk.client.actors.UserActor;
|
|
||||||
import com.vk.api.sdk.exceptions.ApiException;
|
|
||||||
import com.vk.api.sdk.exceptions.ClientException;
|
|
||||||
import org.sadtech.social.core.domain.BoxAnswer;
|
|
||||||
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.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 Sending {
|
|
||||||
|
|
||||||
private final VkApiClient vkApiClient;
|
|
||||||
private final GroupActor groupActor;
|
|
||||||
private final UserActor userActor;
|
|
||||||
private final VkInsertData vkInsertData;
|
|
||||||
|
|
||||||
public BoardCommentSenderVk(VkConnect vkConnect) {
|
|
||||||
this.vkApiClient = vkConnect.getVkApiClient();
|
|
||||||
this.groupActor = vkConnect.getGroupActor();
|
|
||||||
this.vkInsertData = new VkInsertData(vkConnect);
|
|
||||||
this.userActor = vkConnect.getUserActor();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Integer integer, BoxAnswer boxAnswer) {
|
|
||||||
throw new MailSendException();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void send(Integer contentId, Integer personId, BoxAnswer boxAnswer) {
|
|
||||||
try {
|
|
||||||
StringBuilder insertAnswer = new StringBuilder(vkInsertData.insertWords(boxAnswer.getMessage(), personId));
|
|
||||||
if (boxAnswer.getKeyBoard() != null) {
|
|
||||||
insertAnswer.append("\n\nМеню:\n");
|
|
||||||
for (KeyBoardLine keyBoardLine : boxAnswer.getKeyBoard().getKeyBoardLines()) {
|
|
||||||
for (KeyBoardButton keyBoardButton : keyBoardLine.getKeyBoardButtons()) {
|
|
||||||
switch (keyBoardButton.getType()) {
|
|
||||||
case TEXT:
|
|
||||||
insertAnswer.append("- ").append(((KeyBoardButtonText) keyBoardButton).getLabel()).append("\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
vkApiClient.board().createComment(userActor, groupActor.getGroupId(), contentId)
|
|
||||||
.message(insertAnswer.toString()).fromGroup(true).execute();
|
|
||||||
} catch (ApiException | ClientException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public SendType getType() {
|
|
||||||
return SendType.PUBLIC;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,9 +11,9 @@ import org.sadtech.social.core.domain.BoxAnswer;
|
|||||||
import org.sadtech.social.core.domain.keyboard.KeyBoard;
|
import org.sadtech.social.core.domain.keyboard.KeyBoard;
|
||||||
import org.sadtech.social.core.service.sender.SendType;
|
import org.sadtech.social.core.service.sender.SendType;
|
||||||
import org.sadtech.social.core.service.sender.Sending;
|
import org.sadtech.social.core.service.sender.Sending;
|
||||||
import org.sadtech.vkbot.core.config.VkConnect;
|
import org.sadtech.vkbot.config.VkConnect;
|
||||||
import org.sadtech.vkbot.core.convert.KeyBoardConvert;
|
import org.sadtech.vkbot.core.convert.KeyBoardConvert;
|
||||||
import org.sadtech.vkbot.core.utils.VkInsertData;
|
import org.sadtech.vkbot.utils.VkInsertData;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
@@ -34,14 +34,14 @@ public class MailSenderVk implements Sending {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Integer personId, BoxAnswer boxAnswer) {
|
public void send(Long personId, BoxAnswer boxAnswer) {
|
||||||
MessagesSendQuery messagesSendQuery = createMessage(boxAnswer, personId);
|
MessagesSendQuery messagesSendQuery = createMessage(boxAnswer, personId.longValue());
|
||||||
sendMessage(messagesSendQuery);
|
sendMessage(messagesSendQuery);
|
||||||
}
|
}
|
||||||
|
|
||||||
private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Integer peerId) {
|
private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Long peerId) {
|
||||||
MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId)
|
MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId.intValue())
|
||||||
.message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId))
|
.message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId.intValue()))
|
||||||
.randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE));
|
.randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE));
|
||||||
messages.keyboard(convertKeyBoard(boxAnswer.getKeyBoard()));
|
messages.keyboard(convertKeyBoard(boxAnswer.getKeyBoard()));
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class MailSenderVk implements Sending {
|
|||||||
}
|
}
|
||||||
if (boxAnswer.getStickerId() != null) {
|
if (boxAnswer.getStickerId() != null) {
|
||||||
try {
|
try {
|
||||||
vkApiClient.messages().send(groupActor).peerId(peerId).stickerId(boxAnswer.getStickerId())
|
vkApiClient.messages().send(groupActor).peerId(peerId.intValue()).stickerId(boxAnswer.getStickerId())
|
||||||
.randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)).execute();
|
.randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)).execute();
|
||||||
} catch (ApiException | ClientException e) {
|
} catch (ApiException | ClientException e) {
|
||||||
log.error(e.getMessage());
|
log.error(e.getMessage());
|
||||||
@@ -80,7 +80,7 @@ public class MailSenderVk implements Sending {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void send(Integer integer, Integer integer1, BoxAnswer boxAnswer) {
|
public void send(Long integer, Long integer1, BoxAnswer boxAnswer) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import com.vk.api.sdk.objects.users.Fields;
|
|||||||
import com.vk.api.sdk.objects.users.UserMin;
|
import com.vk.api.sdk.objects.users.UserMin;
|
||||||
import com.vk.api.sdk.objects.users.UserXtrCounters;
|
import com.vk.api.sdk.objects.users.UserXtrCounters;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.sadtech.vkbot.core.config.VkConnect;
|
import org.sadtech.vkbot.config.VkConnect;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
package org.sadtech.vkbot.core.utils;
|
|
||||||
|
|
||||||
import org.sadtech.vkbot.core.config.VkConnect;
|
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
public class VkInsertData {
|
|
||||||
|
|
||||||
private final VkApi vkApi;
|
|
||||||
|
|
||||||
public VkInsertData(VkConnect vkConnect) {
|
|
||||||
this.vkApi = new VkApi(vkConnect);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String insertWords(String message, Integer personId) {
|
|
||||||
Pattern pattern = Pattern.compile("%(\\w+)%");
|
|
||||||
Matcher m = pattern.matcher(message);
|
|
||||||
StringBuffer result = new StringBuffer();
|
|
||||||
while (m.find()) {
|
|
||||||
m.appendReplacement(result, insert(m.group(0), personId));
|
|
||||||
}
|
|
||||||
m.appendTail(result);
|
|
||||||
return result.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
private String insert(String key, Integer userId) {
|
|
||||||
String string = "";
|
|
||||||
switch (key) {
|
|
||||||
case "%firstname%":
|
|
||||||
string = vkApi.getUserMini(userId).getFirstName();
|
|
||||||
break;
|
|
||||||
case "%lastname%":
|
|
||||||
string = vkApi.getUserMini(userId).getLastName();
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return string;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user