From 0bab5fa93e419a61ae4727c6937a6729b8a129fd Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 13 May 2019 20:34:03 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D0=BB=20=D0=BA?= =?UTF-8?q?=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80=D1=81?= =?UTF-8?q?=D0=B8=D0=B8=20SDK=20VK=201.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sadtech/vkbot/core/VkApi.java | 6 +++--- .../sadtech/vkbot/core/distribution/MailSubscriber.java | 6 ++++-- .../org/sadtech/vkbot/core/listener/EventListenerVk.java | 8 ++++---- .../java/org/sadtech/vkbot/core/sender/MailSenderVk.java | 5 +++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/sadtech/vkbot/core/VkApi.java b/src/main/java/org/sadtech/vkbot/core/VkApi.java index c4255b2..08a21bb 100644 --- a/src/main/java/org/sadtech/vkbot/core/VkApi.java +++ b/src/main/java/org/sadtech/vkbot/core/VkApi.java @@ -7,9 +7,9 @@ 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.Fields; import com.vk.api.sdk.objects.users.UserMin; import com.vk.api.sdk.objects.users.UserXtrCounters; -import com.vk.api.sdk.queries.users.UserField; import org.apache.log4j.Logger; import java.util.List; @@ -45,7 +45,7 @@ public class VkApi { public String getUserUniver(Integer id) { List temp = null; try { - temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(UserField.UNIVERSITIES).execute(); + temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(Fields.UNIVERSITIES).execute(); } catch (ApiException | ClientException e) { log.error(e); } @@ -55,7 +55,7 @@ public class VkApi { public String getUserCity(Integer id) { List temp = null; try { - temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(UserField.CITY).execute(); + temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(Fields.CITY).execute(); } catch (ApiException | ClientException e) { log.error(e); } diff --git a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java index f66f387..1681cd6 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java @@ -37,12 +37,14 @@ public class MailSubscriber implements EventSubscribe { log.info("Дистрибьютор получил событие - сообщение"); Gson gson = new Gson(); Message userMessage = gson.fromJson(object, Message.class); + log.info(userMessage); + if (userMessage.getPeerId() > 2000000000) { if (eventDistributionMap.containsKey("chat")) { eventDistributionMap.get("chat").update(userMessage); } } else { - if (admins.contains(userMessage.getUserId()) && eventDistributionMap.containsKey("terminal")) { + if (admins.contains(userMessage.getPeerId()) && eventDistributionMap.containsKey("terminal")) { log.info("Сообщение отправлено в репозиторий команд"); eventDistributionMap.get("terminal").update(userMessage); } else { @@ -54,7 +56,7 @@ public class MailSubscriber implements EventSubscribe { private Mail createMaail(Message message) { Mail mail = new Mail(); - mail.setMessage(message.getBody()); + mail.setMessage(message.getText()); mail.setDate(message.getDate()); mail.setId(message.getId()); mail.setPersonId(message.getPeerId()); diff --git a/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java b/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java index 57c86cb..1f923fc 100644 --- a/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java +++ b/src/main/java/org/sadtech/vkbot/core/listener/EventListenerVk.java @@ -7,7 +7,7 @@ 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.exceptions.LongPollServerKeyExpiredException; -import com.vk.api.sdk.objects.groups.responses.GetLongPollServerResponse; +import com.vk.api.sdk.objects.groups.LongPollServer; import org.apache.log4j.Logger; import org.sadtech.bot.core.repository.impl.EventRepositoryQueue; import org.sadtech.bot.core.service.RawEventService; @@ -42,7 +42,7 @@ public class EventListenerVk implements Runnable { } public void listen() throws ClientException, ApiException { - GetLongPollServerResponse longPollServer = getLongPollServer(); + LongPollServer longPollServer = getLongPollServer(); int lastTimeStamp = longPollServer.getTs(); while (true) { try { @@ -62,10 +62,10 @@ public class EventListenerVk implements Runnable { } } - private GetLongPollServerResponse getLongPollServer() throws ClientException, ApiException { + private LongPollServer getLongPollServer() throws ClientException, ApiException { log.info("LongPoll сервер инициализирован"); if (actor != null) { - return vk.groups().getLongPollServer(actor).execute(); + return vk.groups().getLongPollServer(actor, actor.getGroupId()).execute(); } else { throw new NullPointerException("Group actor"); } diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java index bf76e32..d5fd01b 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java @@ -37,12 +37,13 @@ public class MailSenderVk implements Sent { sendMessage(messagesSendQuery); } + //FIXME: Пофиксить клавиатуры private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Integer peerId) { MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId).message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId)); if (boxAnswer.getKeyboard() != null) { - messages.keyboard(boxAnswer.getKeyboard()); +// messages.keyboard(boxAnswer.getKeyboard()); } else { - messages.keyboard("{\"buttons\":[],\"one_time\":true}"); +// messages.keyboard("{\"buttons\":[],\"one_time\":true}"); } if (boxAnswer.getLat() != null && boxAnswer.getaLong() != null) { messages.lat(boxAnswer.getLat()).lng(boxAnswer.getaLong());