diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml deleted file mode 100644 index dad10a1..0000000 --- a/vk-bot/pom.xml +++ /dev/null @@ -1,183 +0,0 @@ - - - - consultant - org.sadtech - 1.0-SNAPSHOT - - 4.0.0 - - org.sadtech - vk-bot - 0.2-SNAPSHOT - jar - - - - org.apache.maven.plugins - maven-compiler-plugin - - 7 - 7 - - - - - org.apache.maven.plugins - maven-war-plugin - - false - - - - - - - 0.5.13-SNAPSHOT - - 5.1.3.RELEASE - 5.1.3.RELEASE - 5.1.3.RELEASE - 5.1.3.RELEASE - 5.1.3.RELEASE - 5.1.3.RELEASE - 2.1.3.RELEASE - - 3.1.0 - 2.2 - - 5.4.0.Final - 5.2.10.Final - - 8.0.13 - - 1.18.4 - - 1.2.17 - - 20180813 - - 6.1.25 - - - - - - com.vk.api - sdk - ${vk.api.ver} - - - - org.projectlombok - lombok - ${lombok} - - - - log4j - log4j - ${log4j} - - - - - org.springframework - spring-core - ${spring.core} - - - org.springframework - spring-context - ${spring.context} - - - org.springframework - spring-context-support - ${spring.context} - - - org.springframework - spring-web - ${spring.web} - - - org.springframework - spring-webmvc - ${spring.webmvc} - - - org.springframework.data - spring-data-jpa - ${spring.data} - - - org.springframework - spring-orm - 5.1.3.RELEASE - - - - com.google.code.gson - gson - 2.8.5 - - - - org.mortbay.jetty - jetty-util - ${jetty.util} - - - - org.json - json - ${json} - - - - javax.persistence - javax.persistence-api - ${javax.persistance} - - - mysql - mysql-connector-java - ${mysql.connector} - - - - org.hibernate - hibernate-entitymanager - ${hibernate.entitymanager} - - - org.hibernate - hibernate-core - ${hibernate.core} - - - - org.slf4j - slf4j-nop - 1.7.13 - - - - org.sadtech - consultant-core - 1.0-SNAPSHOT - compile - - - org.jetbrains - annotations-java5 - 16.0.2 - compile - - - - - \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java deleted file mode 100644 index 7385191..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/SourceMessage.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.sadtech.vkbot.core; - -public enum SourceMessage { - VK("VK"), - FB("FB"); - - private final String value; - - private SourceMessage(String value) { - this.value = value; - } - - public String getValue() { - return this.value; - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java deleted file mode 100644 index 6c2e68e..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/VkApi.java +++ /dev/null @@ -1,43 +0,0 @@ -package org.sadtech.vkbot.core; - -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -import com.vk.api.sdk.exceptions.ApiException; -import com.vk.api.sdk.exceptions.ClientException; -import com.vk.api.sdk.objects.users.UserXtrCounters; -import lombok.extern.log4j.Log4j; -import org.springframework.stereotype.Component; - -import java.util.List; - -@Log4j -@Component -public class VkApi { - - private static VkApiClient vk; - private static GroupActor actor; - - public VkApi(VkApiClient vk, GroupActor actor) { - this.vk = vk; - this.actor = actor; - } - - public static void sendMessage(Integer id, String text) { - try { - vk.messages().send(actor).userId(id).message(text).execute(); - } catch (ApiException | ClientException e) { - e.printStackTrace(); - } - } - - public static UserXtrCounters getUserVk(Integer id) { - List temp = null; - try { - temp = vk.users().get(actor).userIds(String.valueOf(id)).execute(); - } catch (ApiException | ClientException e) { - e.printStackTrace(); - } - return temp.get(0); - } - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java deleted file mode 100644 index 47e0dc8..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/ResponsibleData.java +++ /dev/null @@ -1,17 +0,0 @@ -package org.sadtech.vkbot.core.data; - -import com.google.gson.JsonObject; - -import java.util.Queue; - -public interface ResponsibleData { - - void add(JsonObject jsonObject); - - void remove(int id); - - void cleanAll(); - - Queue getJsonObjects(); - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java deleted file mode 100644 index a5532b4..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/data/impl/ResponseDataVk.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.sadtech.vkbot.core.data.impl; - -import com.google.gson.JsonObject; -import org.sadtech.vkbot.core.data.ResponsibleData; -import org.springframework.stereotype.Component; - -import java.util.Queue; -import java.util.concurrent.ConcurrentLinkedQueue; - -@Component -public class ResponseDataVk implements ResponsibleData { - - private Queue jsonObjects = new ConcurrentLinkedQueue<>(); - - @Override - public void add(JsonObject jsonObject) { - jsonObjects.offer(jsonObject); - } - - @Override - public void remove(int id) { - jsonObjects.remove(id); - } - - @Override - public void cleanAll() { - jsonObjects.clear(); - } - - public Queue getJsonObjects() { - return jsonObjects; - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java deleted file mode 100644 index f5fe281..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/Handled.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.sadtech.vkbot.core.handlers; - -import org.sadtech.vkbot.core.listener.Observer; - -public interface Handled { - - void sortAndSend() throws Exception; - void registerObserver(Observer o); -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java deleted file mode 100644 index fb7c5e9..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/DispatcherHandlerVk.java +++ /dev/null @@ -1,48 +0,0 @@ -package org.sadtech.vkbot.core.handlers.impl; - -import com.google.gson.JsonObject; -import lombok.extern.log4j.Log4j; -import org.sadtech.vkbot.core.handlers.Handled; -import org.sadtech.vkbot.core.listener.Observable; -import org.sadtech.vkbot.core.data.ResponsibleData; -import org.sadtech.vkbot.core.listener.Observer; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -import java.util.ArrayList; -import java.util.List; - -@Log4j -@Component("dispatcherHandler") -public class DispatcherHandlerVk implements Observable, Handled { - - private ResponsibleData date; - private List observers = new ArrayList<>(); - private JsonObject event; - - public DispatcherHandlerVk(ResponsibleData date) { - this.date = date; - } - - @Async - public void sortAndSend() { - while (true) { - if (date.getJsonObjects().peek() != null) { - event = date.getJsonObjects().poll(); - notifyObservers(); - } - } - } - - @Override - public void registerObserver(Observer o) { - observers.add(o); - } - - @Override - public void notifyObservers() { - for (Observer observer : observers) { - observer.update(event); - } - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java deleted file mode 100644 index aa1513c..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/handlers/impl/MessageHandlerVk.java +++ /dev/null @@ -1,65 +0,0 @@ -package org.sadtech.vkbot.core.handlers.impl; - -import com.google.gson.Gson; -import com.google.gson.JsonObject; -import com.vk.api.sdk.objects.messages.Message; -import com.vk.api.sdk.objects.users.UserXtrCounters; -import lombok.extern.log4j.Log4j; -import org.sadtech.consultant.database.entity.Mail; -import org.sadtech.consultant.database.entity.Person; -import org.sadtech.consultant.processing.MessageLogicService; -import org.sadtech.consultant.processing.PersonLogicService; -import org.sadtech.vkbot.core.SourceMessage; -import org.sadtech.vkbot.core.VkApi; -import org.sadtech.vkbot.core.handlers.Handled; -import org.sadtech.vkbot.core.listener.Observer; -import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.stereotype.Component; - -@Log4j -@Component -public class MessageHandlerVk implements Observer { - - private MessageLogicService messageLogicService; - private PersonLogicService personLogicService; - private Message userMessage; - - public MessageHandlerVk(@Qualifier("dispatcherHandler") Handled dispatcherHandler, PersonLogicService personLogicService, MessageLogicService messageLogicService) { - this.messageLogicService = messageLogicService; - this.personLogicService = personLogicService; - dispatcherHandler.registerObserver(this); - } - - @Override - public void update(JsonObject object) { - if (object.get("type").toString().equals("\"message_new\"")) { - Gson gson = new Gson(); - userMessage = gson.fromJson(object.getAsJsonObject("object"), com.vk.api.sdk.objects.messages.Message.class); - sortAndSend(); - } - } - - public void sortAndSend() { - Person user; - Integer userVkId = userMessage.getUserId(); - if (personLogicService.checkPersonBySocialNetworksId(SourceMessage.VK.name(), userVkId)) { - user = personLogicService.getUserBySocialId(SourceMessage.VK.name(), userMessage.getUserId()); - } else { - user = new Person(); - UserXtrCounters userXtrCounters = VkApi.getUserVk(userVkId); - user.setCity("city"); - user.setName(userXtrCounters.getFirstName()); - user.setLastName(userXtrCounters.getLastName()); - user.getSocialNetworks().put(String.valueOf(SourceMessage.VK), userMessage.getUserId()); - personLogicService.addUser(user); - } - - Mail message = new Mail(); - message.setPerson(user); - message.setText(userMessage.getBody()); - message.setDate(Long.valueOf(userMessage.getDate())); - message.setSourceMessage(SourceMessage.VK.name()); - log.info(message); - messageLogicService.addMessage(message); - } -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java deleted file mode 100644 index 14308f4..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/EventListenable.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.sadtech.vkbot.core.listener; - -public interface EventListenable { - void listen() throws Exception; -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java deleted file mode 100644 index bcab5b7..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observable.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sadtech.vkbot.core.listener; - -public interface Observable { - - // void removeObserver(Observer o); - void notifyObservers(); - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java deleted file mode 100644 index 2edd654..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/Observer.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.vkbot.core.listener; - -import com.google.gson.JsonObject; - -public interface Observer { - void update(JsonObject object); -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java deleted file mode 100644 index dca38d5..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/listener/impl/EventListenerVk.java +++ /dev/null @@ -1,61 +0,0 @@ -package org.sadtech.vkbot.core.listener.impl; - -import com.vk.api.sdk.actions.LongPoll; -import com.vk.api.sdk.callback.longpoll.queries.GetLongPollEventsQuery; -import com.vk.api.sdk.callback.longpoll.responses.GetLongPollEventsResponse; -import com.vk.api.sdk.client.VkApiClient; -import com.vk.api.sdk.client.actors.GroupActor; -import com.vk.api.sdk.exceptions.ApiException; -import com.vk.api.sdk.exceptions.ClientException; -import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; -import lombok.extern.log4j.Log4j; -import org.sadtech.vkbot.core.listener.EventListenable; -import org.sadtech.vkbot.core.data.ResponsibleData; -import org.springframework.scheduling.annotation.Async; -import org.springframework.stereotype.Component; - -@Log4j -@Component -public class EventListenerVk implements EventListenable { - - private VkApiClient vk; - private GroupActor actor; - private ResponsibleData responseData; - - private GetLongPollEventsQuery longPollEventsQuery; - private LongPoll longPoll; - private GetLongPollServerResponse server; - - public EventListenerVk(VkApiClient vk, GroupActor actor, ResponsibleData responseData) { - this.vk = vk; - this.actor = actor; - this.responseData = responseData; - longPoll = new LongPoll(vk); - } - - private void initServer() throws ClientException, ApiException { - server = vk.groups().getLongPollServer(actor).execute(); - String key = server.getKey(); - String serverUrl = server.getServer(); - Integer ts = server.getTs(); - longPoll = new LongPoll(vk); - longPollEventsQuery = longPoll.getEvents(serverUrl, key, ts).waitTime(20); - } - - @Async - public void listen() throws Exception { - initServer(); - do { - GetLongPollEventsResponse eventsResponse; - eventsResponse = longPollEventsQuery.execute(); - if (eventsResponse.getUpdates().toArray().length != 0) { - responseData.add(eventsResponse.getUpdates().get(0)); - log.info(eventsResponse.getUpdates()); -// String test = "{\"one_time\":false,\"buttons\":[[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"1\\\"}\",\"label\":\"Red2\"},\"color\":\"negative\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"2\\\"}\",\"label\":\"Green\"},\"color\":\"positive\"}],[{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"3\\\"}\",\"label\":\"White\"},\"color\":\"default\"},{\"action\":{\"type\":\"text\",\"payload\":\"{\\\"button\\\": \\\"4\\\"}\",\"label\":\"Blue\"},\"color\":\"primary\"}]]}"; - } - longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); - } while (true); - } - - -} diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java deleted file mode 100644 index d250f01..0000000 --- a/vk-bot/src/main/java/org/sadtech/vkbot/core/sendler/MessageSendVk.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.sadtech.vkbot.core.sendler; - -import org.sadtech.consultant.MessageSender; -import org.sadtech.consultant.processing.MessageHandler; -import org.sadtech.vkbot.core.SourceMessage; -import org.sadtech.vkbot.core.VkApi; -import org.springframework.stereotype.Component; - -@Component -public class MessageSendVk implements MessageSender { - - public MessageSendVk(MessageHandler messageHandler) { - messageHandler.addMessageSendler(SourceMessage.VK.name(), this); - } - - @Override - public void send(Integer idNetSoc, String text) { - VkApi.sendMessage(idNetSoc, text); - } -}