Добавил версию vk-api snapshot

This commit is contained in:
Mark Struchkov 2018-12-30 23:17:08 +03:00
parent 9a719d70b8
commit edebc5c4fa
6 changed files with 38 additions and 17 deletions

View File

@ -12,7 +12,6 @@
<artifactId>vk-bot</artifactId>
<version>0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<plugin>
@ -35,7 +34,7 @@
</build>
<properties>
<vk.api.ver>0.5.12</vk.api.ver>
<vk.api.ver>0.5.13-SNAPSHOT</vk.api.ver>
<spring.core>5.1.3.RELEASE</spring.core>
<spring.context>5.1.3.RELEASE</spring.context>
@ -64,6 +63,12 @@
<dependencies>
<dependency>
<groupId>com.vk.api</groupId>
<artifactId>sdk</artifactId>
<version>${vk.api.ver}</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
@ -76,12 +81,6 @@
<version>${log4j}</version>
</dependency>
<dependency>
<groupId>com.vk.api</groupId>
<artifactId>sdk</artifactId>
<version>${vk.api.ver}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
@ -119,6 +118,12 @@
<version>${javax.servlet}</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-util</artifactId>
@ -153,5 +158,6 @@
<version>${hibernate.core}</version>
</dependency>
</dependencies>
</project>

View File

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

View File

@ -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;

View File

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

View File

@ -29,7 +29,7 @@ public class DispetcherHandler implements Observable {
objects = new ArrayList<JsonObject>(date.getJsonObjects());
date.cleanAll();
for (JsonObject object : objects) {
System.out.println(object);
log.info(object);
}
}

View File

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