From edebc5c4faada8b5dfedef9ff4450c3d27c86007 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 30 Dec 2018 23:17:08 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8E=20vk-api=20snapshot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vk-bot/pom.xml | 22 ++++++++++++------- .../java/org/sadtech/vkbot/VkOpenMethod.java | 3 +++ .../sadtech/vkbot/config/SpringConfigVk.java | 4 ---- .../org/sadtech/vkbot/config/TestMain.java | 7 +++++- .../listener/handlers/DispetcherHandler.java | 2 +- .../vkbot/listener/impl/EventListenerVk.java | 17 +++++++++++--- 6 files changed, 38 insertions(+), 17 deletions(-) diff --git a/vk-bot/pom.xml b/vk-bot/pom.xml index 8139c8a..cf57bdb 100644 --- a/vk-bot/pom.xml +++ b/vk-bot/pom.xml @@ -12,7 +12,6 @@ vk-bot 0.1-SNAPSHOT - war @@ -35,7 +34,7 @@ - 0.5.12 + 0.5.13-SNAPSHOT 5.1.3.RELEASE 5.1.3.RELEASE @@ -64,6 +63,12 @@ + + com.vk.api + sdk + ${vk.api.ver} + + org.projectlombok lombok @@ -76,12 +81,6 @@ ${log4j} - - com.vk.api - sdk - ${vk.api.ver} - - org.springframework spring-core @@ -119,6 +118,12 @@ ${javax.servlet} + + com.google.code.gson + gson + 2.8.5 + + org.mortbay.jetty jetty-util @@ -153,5 +158,6 @@ ${hibernate.core} + \ No newline at end of file diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java index d26c51b..6308980 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/VkOpenMethod.java @@ -17,5 +17,8 @@ public class VkOpenMethod { this.actor = actor; } + public void sendMessage(Integer id, String text) { + vk.messages().send(actor).userId(id).peerId(id).message(text); + } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java index 8519254..35ee625 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/SpringConfigVk.java @@ -8,10 +8,6 @@ import com.vk.api.sdk.exceptions.ApiException; import com.vk.api.sdk.exceptions.ClientException; import com.vk.api.sdk.httpclient.HttpTransportClient; import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; -import org.sadtech.vkbot.listener.data.impl.ResponseDataVk; -import org.sadtech.vkbot.listener.impl.EventListenerVk; -import org.sadtech.vkbot.service.UserService; -import org.sadtech.vkbot.service.impl.UserServiceImpl; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java b/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java index de506c8..a741b01 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/config/TestMain.java @@ -1,17 +1,22 @@ package org.sadtech.vkbot.config; +import lombok.extern.log4j.Log4j; import org.sadtech.vkbot.listener.EventListenable; import org.sadtech.vkbot.listener.Observable; import org.springframework.context.annotation.AnnotationConfigApplicationContext; - +@Log4j public class TestMain { public static void main(String[] args) throws Exception { + log.info("\n\n\n\n=== Запуск прогарммы ===\n\n"); + AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(SpringConfigVk.class); context.register(DataConfig.class); EventListenable eventListener = context.getBean(EventListenable.class); eventListener.listen(); Observable dispetcherHandler = context.getBean(Observable.class); dispetcherHandler.packaging(); + + log.info("\n\n=== Конец программы ===\n\n"); } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java index f47bfbf..c120a03 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/handlers/DispetcherHandler.java @@ -29,7 +29,7 @@ public class DispetcherHandler implements Observable { objects = new ArrayList(date.getJsonObjects()); date.cleanAll(); for (JsonObject object : objects) { - System.out.println(object); + log.info(object); } } diff --git a/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java b/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java index 6f6c413..5010b4b 100644 --- a/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java +++ b/vk-bot/src/main/java/org/sadtech/vkbot/listener/impl/EventListenerVk.java @@ -1,5 +1,7 @@ package org.sadtech.vkbot.listener.impl; +import com.google.gson.JsonObject; +import com.google.gson.JsonParser; 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; @@ -8,9 +10,12 @@ 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 jdk.nashorn.internal.parser.JSONParser; import lombok.extern.log4j.Log4j; +import org.json.JSONObject; import org.sadtech.vkbot.listener.EventListenable; import org.sadtech.vkbot.listener.data.ResponsibleData; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Component; @@ -43,18 +48,24 @@ public class EventListenerVk implements EventListenable { } @Async - public void listen() throws ClientException, ApiException { + public void listen() throws Exception { initServer(); do { GetLongPollEventsResponse eventsResponse; eventsResponse = longPollEventsQuery.execute(); - log.info(eventsResponse); if (eventsResponse.getUpdates().toArray().length != 0) { responseData.add(eventsResponse.getUpdates().get(0)); -// log.info(eventsResponse.getUpdates()); + 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\"}]]}"; + vk.messages().send(actor).peerId(244319573).keyboard(test).message("Сообщение получено").execute(); + + + } longPollEventsQuery = longPoll.getEvents(server.getServer(), server.getKey(), eventsResponse.getTs()).waitTime(20); } while (true); } + + }