From 593e5f8c34c5b2453897dd08bf58150dabe5088d Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 8 May 2019 17:14:04 +0300 Subject: [PATCH 01/11] =?UTF-8?q?=D0=91=D0=B0=D0=B3=D1=84=D0=B8=D0=BA?= =?UTF-8?q?=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 5 +++-- .../sadtech/vkbot/core/keyboard/ButtonKeyBoard.java | 8 ++++---- .../java/org/sadtech/vkbot/core/keyboard/KeyBoard.java | 9 ++++----- .../core/service/distribution/CommentService.java | 10 ---------- 4 files changed, 11 insertions(+), 21 deletions(-) delete mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java diff --git a/pom.xml b/pom.xml index af7e00f..fbb1acf 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.vkbot vkbot-core - 0.1.0-RELEASE + 0.1.1-SNAPSHOT jar @@ -23,6 +23,7 @@ + 0.5.2-SNAPSHOT 0.5.13-SNAPSHOT 1.2.17 @@ -43,7 +44,7 @@ org.sadtech.bot bot-core - 0.4.3-SNAPSHOT + ${bot.core.ver} diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java index 58802e4..77b6ed1 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java @@ -4,13 +4,13 @@ import com.google.gson.JsonObject; public class ButtonKeyBoard { - private String type; + private String type = "text"; private String payload; private String label; - private ColorButton color; + private ColorButton color = ColorButton.DEFAULT; + + public ButtonKeyBoard() { - private ButtonKeyBoard() { - throw new IllegalStateException(); } public JsonObject getButton() { diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java index 537b05e..d139675 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java @@ -8,12 +8,11 @@ import java.util.List; public class KeyBoard { - private List lineKeyBoards; - private boolean oneTime; + private List lineKeyBoards = new ArrayList<>(); + private boolean oneTime = true; + + public KeyBoard() { - private KeyBoard() { - lineKeyBoards = new ArrayList<>(); - throw new IllegalStateException(); } public JsonObject getKeyboard() { diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java deleted file mode 100644 index 6830e21..0000000 --- a/src/main/java/org/sadtech/vkbot/core/service/distribution/CommentService.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.sadtech.vkbot.core.service.distribution; - -import org.sadtech.bot.core.domain.Comment; -import org.sadtech.bot.core.service.EventService; - -//@TODO: Дописать класс -public interface CommentService extends EventService { - - -} From 0bab5fa93e419a61ae4727c6937a6729b8a129fd Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 13 May 2019 20:34:03 +0300 Subject: [PATCH 02/11] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BA=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=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()); From aab0f6b0756f5fce9f3b64db98b9f49cccd55cfd Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 13 May 2019 20:53:01 +0300 Subject: [PATCH 03/11] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BA=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=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 | 4 +--- .../org/sadtech/vkbot/core/sender/MailSenderVk.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/sadtech/vkbot/core/VkApi.java b/src/main/java/org/sadtech/vkbot/core/VkApi.java index 08a21bb..eebb050 100644 --- a/src/main/java/org/sadtech/vkbot/core/VkApi.java +++ b/src/main/java/org/sadtech/vkbot/core/VkApi.java @@ -32,9 +32,7 @@ public class VkApi { try { List temp = vk.users().get(actor).userIds(String.valueOf(id)).execute(); JsonParser parser = new JsonParser(); - JsonObject object = parser.parse(temp.get(0).toString().substring(15)).getAsJsonObject(); - object.add("last_name", object.get("lastName")); - object.add("first_name", object.get("firstName")); + JsonObject object = parser.parse(temp.get(0).toString()).getAsJsonObject(); userMin = gson.fromJson(object, UserMin.class); } catch (ApiException | ClientException e) { log.error(e); 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 d5fd01b..1ea63a4 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java @@ -11,6 +11,8 @@ import org.sadtech.bot.core.sender.Sent; import org.sadtech.vkbot.core.VkConnect; import org.sadtech.vkbot.core.VkInsertData; +import java.util.concurrent.ThreadLocalRandom; + public class MailSenderVk implements Sent { private static final Logger log = Logger.getLogger(MailSenderVk.class); @@ -28,7 +30,7 @@ public class MailSenderVk implements Sent { @Override public void send(Integer idPerson, String message) { - sendMessage(vkApiClient.messages().send(groupActor).peerId(idPerson).message(message)); + sendMessage(vkApiClient.messages().send(groupActor).peerId(idPerson).message(message).randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE))); } @Override @@ -39,7 +41,7 @@ public class MailSenderVk implements Sent { //FIXME: Пофиксить клавиатуры private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Integer peerId) { - MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId).message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId)); + MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId).message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId)).randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)); if (boxAnswer.getKeyboard() != null) { // messages.keyboard(boxAnswer.getKeyboard()); } else { @@ -65,4 +67,8 @@ public class MailSenderVk implements Sent { log.error(e); } } + + private Integer reandomId() { + return null; + } } From 0a960d6972422620ba3dca6c51f5071f41829e4b Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Mon, 13 May 2019 21:14:08 +0300 Subject: [PATCH 04/11] =?UTF-8?q?=D0=9F=D1=80=D0=B8=D0=B2=D0=B5=D0=BB=20?= =?UTF-8?q?=D0=BA=20=D0=BD=D0=BE=D0=B2=D0=BE=D0=B9=20=D0=B2=D0=B5=D1=80?= =?UTF-8?q?=D1=81=D0=B8=D0=B8=20SDK=20VK=201.0.2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vkbot/core/keyboard/ButtonKeyBoard.java | 67 ------------------- .../vkbot/core/keyboard/ColorButton.java | 7 -- .../sadtech/vkbot/core/keyboard/KeyBoard.java | 60 ----------------- .../vkbot/core/keyboard/KeyBoardService.java | 60 ++++++++++++----- .../vkbot/core/keyboard/LineKeyBoard.java | 47 ------------- .../vkbot/core/sender/MailSenderVk.java | 10 +-- 6 files changed, 50 insertions(+), 201 deletions(-) delete mode 100644 src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java delete mode 100644 src/main/java/org/sadtech/vkbot/core/keyboard/ColorButton.java delete mode 100644 src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java delete mode 100644 src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java deleted file mode 100644 index 77b6ed1..0000000 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java +++ /dev/null @@ -1,67 +0,0 @@ -package org.sadtech.vkbot.core.keyboard; - -import com.google.gson.JsonObject; - -public class ButtonKeyBoard { - - private String type = "text"; - private String payload; - private String label; - private ColorButton color = ColorButton.DEFAULT; - - public ButtonKeyBoard() { - - } - - public JsonObject getButton() { - JsonObject newButton = new JsonObject(); - newButton.addProperty("color", color.toString().toLowerCase()); - newButton.add("action", generateAction()); - return newButton; - } - - private JsonObject generateAction() { - JsonObject action = new JsonObject(); - action.addProperty("type", type); - action.addProperty("payload", payload); - action.addProperty("label", label); - return action; - } - - public static Builder builder() { - return new ButtonKeyBoard().new Builder(); - } - - public class Builder { - - private Builder() { - - } - - public Builder color(ColorButton color) { - ButtonKeyBoard.this.color = color; - return this; - } - - public Builder label(String label) { - ButtonKeyBoard.this.label = label; - return this; - } - - public Builder payload(String payload) { - ButtonKeyBoard.this.payload = payload; - return this; - } - - public Builder type(String type) { - ButtonKeyBoard.this.type = type; - return this; - } - - public ButtonKeyBoard build() { - return ButtonKeyBoard.this; - } - - } - -} diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/ColorButton.java b/src/main/java/org/sadtech/vkbot/core/keyboard/ColorButton.java deleted file mode 100644 index 6eb856b..0000000 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/ColorButton.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.sadtech.vkbot.core.keyboard; - -public enum ColorButton { - - PRIMARY, DEFAULT, NEGATIVE, POSITIVE - -} diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java deleted file mode 100644 index d139675..0000000 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java +++ /dev/null @@ -1,60 +0,0 @@ -package org.sadtech.vkbot.core.keyboard; - -import com.google.gson.JsonArray; -import com.google.gson.JsonObject; - -import java.util.ArrayList; -import java.util.List; - -public class KeyBoard { - - private List lineKeyBoards = new ArrayList<>(); - private boolean oneTime = true; - - public KeyBoard() { - - } - - public JsonObject getKeyboard() { - JsonObject keyboard = new JsonObject(); - keyboard.addProperty("one_time", oneTime); - - JsonArray menuLine = new JsonArray(); - for (LineKeyBoard lineKeyboard : lineKeyBoards) { - menuLine.add(lineKeyboard.getLine()); - } - - keyboard.add("buttons", menuLine); - return keyboard; - } - - public static Builder builder() { - return new KeyBoard().new Builder(); - } - - public void addLine(LineKeyBoard lineKeyBoard) { - lineKeyBoards.add(lineKeyBoard); - } - - public class Builder { - - private Builder() { - - } - - public Builder lineKeyBoard(LineKeyBoard lineKeyBoard) { - KeyBoard.this.lineKeyBoards.add(lineKeyBoard); - return this; - } - - public Builder oneTime(boolean oneTime) { - KeyBoard.this.oneTime = oneTime; - return this; - } - - public KeyBoard build() { - return KeyBoard.this; - } - - } -} diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java index 11f70b1..dcecd16 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java @@ -1,5 +1,10 @@ package org.sadtech.vkbot.core.keyboard; +import com.vk.api.sdk.objects.messages.*; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; import java.util.List; public class KeyBoardService { @@ -8,27 +13,50 @@ public class KeyBoardService { throw new IllegalStateException(); } - public static KeyBoard keyBoardYesNo() { - ButtonKeyBoard yesButton = ButtonKeyBoard.builder().color(ColorButton.POSITIVE).label("Да").payload("{\"button\": \"yes\"}").build(); - ButtonKeyBoard noButton = ButtonKeyBoard.builder().color(ColorButton.NEGATIVE).label("Нет").payload("{\"button\": \"no\"}").build(); - LineKeyBoard lineKeyBoard = LineKeyBoard.builder().setButtonKeyBoard(yesButton).setButtonKeyBoard(noButton).build(); - return KeyBoard.builder().lineKeyBoard(lineKeyBoard).oneTime(true).build(); + public static Keyboard keyBoardYesNo() { + KeyboardButton yesButton = new KeyboardButton(); + KeyboardButtonAction buttonActionYes = new KeyboardButtonAction(); + buttonActionYes.setLabel("Да"); + buttonActionYes.setType(KeyboardButtonActionType.TEXT); + buttonActionYes.setPayload("{\"button\": \"yes\"}"); + yesButton.setAction(buttonActionYes); + yesButton.setColor(KeyboardButtonColor.POSITIVE); + + KeyboardButton noButton = new KeyboardButton(); + KeyboardButtonAction buttonActionNo = new KeyboardButtonAction(); + buttonActionNo.setLabel("Да"); + buttonActionNo.setType(KeyboardButtonActionType.TEXT); + buttonActionNo.setPayload("{\"button\": \"no\"}"); + noButton.setAction(buttonActionNo); + noButton.setColor(KeyboardButtonColor.NEGATIVE); + + List line1 = new ArrayList<>(); + line1.add(yesButton); + line1.add(noButton); + + Keyboard keyboard = new Keyboard(); + keyboard.setButtons(Collections.singletonList(line1)); + keyboard.setOneTime(true); + return keyboard; } - public static KeyBoard verticalMenuString(List labelButtons) { - KeyBoard keyBoard = KeyBoard.builder().oneTime(true).build(); + public static Keyboard verticalKeyboard(List labelButtons) { + Keyboard keyBoard = new Keyboard(); + keyBoard.setOneTime(true); + List menu = new ArrayList<>(); for (String labelButton : labelButtons) { - ButtonKeyBoard buttonKeyBoard = ButtonKeyBoard.builder().label(labelButton).type("text").payload("{\"button\": \"" + labelButton + "\"}").build(); - keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build()); - } - return keyBoard; - } + KeyboardButton button = new KeyboardButton(); + button.setColor(KeyboardButtonColor.DEFAULT); - public static KeyBoard verticalMenuButton(List buttonKeyBoards) { - KeyBoard keyBoard = KeyBoard.builder().oneTime(true).build(); - for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) { - keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build()); + KeyboardButtonAction buttonAction = new KeyboardButtonAction(); + buttonAction.setPayload("{\"button\": \"" + labelButton + "\"}"); + buttonAction.setType(KeyboardButtonActionType.TEXT); + buttonAction.setLabel(labelButton); + + button.setAction(buttonAction); + menu.add(button); } + keyBoard.setButtons(Collections.singletonList(menu)); return keyBoard; } } diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java b/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java deleted file mode 100644 index 6b28849..0000000 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/LineKeyBoard.java +++ /dev/null @@ -1,47 +0,0 @@ -package org.sadtech.vkbot.core.keyboard; - -import com.google.gson.JsonArray; - -import java.util.ArrayList; -import java.util.List; - -public class LineKeyBoard { - - private List buttonKeyBoards = new ArrayList<>(); - - public LineKeyBoard() { - - } - - public LineKeyBoard(List buttonKeyBoards) { - this.buttonKeyBoards = buttonKeyBoards; - } - - public JsonArray getLine() { - JsonArray line = new JsonArray(); - for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) { - line.add(buttonKeyBoard.getButton()); - } - return line; - } - - public static Builder builder() { - return new LineKeyBoard().new Builder(); - } - - public class Builder { - - private Builder() { - - } - - public Builder setButtonKeyBoard(ButtonKeyBoard buttonKeyBoard) { - LineKeyBoard.this.buttonKeyBoards.add(buttonKeyBoard); - return this; - } - - public LineKeyBoard build() { - return LineKeyBoard.this; - } - } -} 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 1ea63a4..d2fb0b2 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java @@ -1,9 +1,11 @@ package org.sadtech.vkbot.core.sender; +import com.google.gson.Gson; 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.messages.Keyboard; import com.vk.api.sdk.queries.messages.MessagesSendQuery; import org.apache.log4j.Logger; import org.sadtech.bot.core.domain.BoxAnswer; @@ -21,6 +23,7 @@ public class MailSenderVk implements Sent { private final GroupActor groupActor; private final VkInsertData vkInsertData; + private final Gson gson = new Gson(); public MailSenderVk(VkConnect vkConnect) { this.vkApiClient = vkConnect.getVkApiClient(); @@ -43,7 +46,8 @@ public class MailSenderVk implements Sent { private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Integer peerId) { MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId).message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId)).randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)); if (boxAnswer.getKeyboard() != null) { -// messages.keyboard(boxAnswer.getKeyboard()); + Keyboard keyBoard = gson.fromJson(boxAnswer.getKeyboard(), Keyboard.class); + messages.keyboard(keyBoard); } else { // messages.keyboard("{\"buttons\":[],\"one_time\":true}"); } @@ -68,7 +72,5 @@ public class MailSenderVk implements Sent { } } - private Integer reandomId() { - return null; - } + } From 9026f500208f9a4175304809ccabcbffbf1bca1f Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Tue, 14 May 2019 01:33:47 +0300 Subject: [PATCH 05/11] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D0=BF=D0=BE=D0=B4=D0=B4=D0=B5=D1=80=D0=B6=D0=BA=D1=83?= =?UTF-8?q?=20=D0=B3=D0=BE=D0=BB=D0=BE=D1=81=D0=BE=D0=B2=D1=8B=D1=85=20?= =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 ++++ .../core/distribution/MailSubscriber.java | 65 +++++++++++++++++-- 2 files changed, 73 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index fbb1acf..8be0fe9 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,18 @@ bot-core ${bot.core.ver} + + + com.google.cloud + google-cloud-speech + 1.3.0 + + + + com.google.cloud + google-cloud-storage + 1.73.0 + 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 1681cd6..fda8c42 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java @@ -1,16 +1,23 @@ package org.sadtech.vkbot.core.distribution; +import com.google.cloud.speech.v1.*; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.google.protobuf.ByteString; import com.vk.api.sdk.objects.messages.Message; +import com.vk.api.sdk.objects.messages.MessageAttachment; +import com.vk.api.sdk.objects.messages.MessageAttachmentType; +import org.apache.commons.io.IOUtils; +import org.apache.commons.lang3.ArrayUtils; import org.apache.log4j.Logger; import org.sadtech.bot.core.domain.Mail; import org.sadtech.vkbot.core.service.distribution.MailService; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.io.*; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.*; public class MailSubscriber implements EventSubscribe { @@ -39,6 +46,44 @@ public class MailSubscriber implements EventSubscribe { Message userMessage = gson.fromJson(object, Message.class); log.info(userMessage); + if (userMessage.getAttachments()!=null) { + for (MessageAttachment attachment : userMessage.getAttachments()) { + if (MessageAttachmentType.AUDIO_MESSAGE.equals(attachment.getType())) { + try (SpeechClient speechClient = SpeechClient.create()) { + + byte[] data = IOUtils.toByteArray(userMessage.getAttachments().get(0).getAudioMessage().getLinkOgg().openStream()); + ByteString audioBytes = ByteString.copyFrom(data); + + // Builds the sync recognize request + RecognitionConfig config = RecognitionConfig.newBuilder() + .setEncoding(RecognitionConfig.AudioEncoding.OGG_OPUS) + .setSampleRateHertz(16000) + .setLanguageCode("ru-RU") + .build(); + RecognitionAudio audio = RecognitionAudio.newBuilder() + .setContent(audioBytes) + .build(); + + // Performs speech recognition on the audio file + RecognizeResponse response = speechClient.recognize(config, audio); + List results = response.getResultsList(); + + for (SpeechRecognitionResult result : results) { + // There can be several alternative transcripts for a given chunk of speech. Just use the + // first (most likely) one here. + SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); + userMessage.setText(alternative.getTranscript()); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + + + if (userMessage.getPeerId() > 2000000000) { if (eventDistributionMap.containsKey("chat")) { eventDistributionMap.get("chat").update(userMessage); @@ -54,6 +99,18 @@ public class MailSubscriber implements EventSubscribe { } } + public byte[] getBytes(InputStream inputStream) throws IOException { + ByteArrayOutputStream byteBuffer = new ByteArrayOutputStream(); + int bufferSize = 1024; + byte[] buffer = new byte[bufferSize]; + + int len = 0; + while ((len = inputStream.read(buffer)) != -1) { + byteBuffer.write(buffer, 0, len); + } + return byteBuffer.toByteArray(); + } + private Mail createMaail(Message message) { Mail mail = new Mail(); mail.setMessage(message.getText()); From 2ebbe9356dfdc5b969c7a378ab4a8d56b47f7238 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 15 May 2019 13:22:23 +0300 Subject: [PATCH 06/11] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D0=BE=D1=81?= =?UTF-8?q?=D0=BC=D1=8B=D1=81=D0=BB=D0=B8=D0=BB=20=D0=BA=D0=BB=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=B0=D1=82=D1=83=D1=80=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vkbot/core/convert/KeyBoardConvert.java | 70 +++++++++++++++++++ .../vkbot/core/sender/MailSenderVk.java | 15 +++- 2 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 src/main/java/org/sadtech/vkbot/core/convert/KeyBoardConvert.java diff --git a/src/main/java/org/sadtech/vkbot/core/convert/KeyBoardConvert.java b/src/main/java/org/sadtech/vkbot/core/convert/KeyBoardConvert.java new file mode 100644 index 0000000..69a9677 --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/convert/KeyBoardConvert.java @@ -0,0 +1,70 @@ +package org.sadtech.vkbot.core.convert; + +import com.vk.api.sdk.objects.messages.*; +import org.sadtech.bot.core.domain.keyboard.ButtonColor; +import org.sadtech.bot.core.domain.keyboard.KeyBoard; +import org.sadtech.bot.core.domain.keyboard.KeyBoardButton; +import org.sadtech.bot.core.domain.keyboard.KeyBoardLine; + +import java.util.ArrayList; +import java.util.List; + +public final class KeyBoardConvert { + + private KeyBoardConvert() { + + } + + public static Keyboard convertKeyboard(KeyBoard keyboard) { + Keyboard keyboardVk = new Keyboard(); + keyboardVk.setOneTime(keyboard.isOneTime()); + + List> listButton = new ArrayList<>(); + for (KeyBoardLine keyBoardLine : keyboard.getKeyBoardLines()) { + List buttonList = new ArrayList<>(); + for (KeyBoardButton button : keyBoardLine.getKeyBoardButtons()) { + buttonList.add(convertButton(button)); + } + listButton.add(buttonList); + } + keyboardVk.setButtons(listButton); + + return keyboardVk; + } + + private static KeyboardButton convertButton(KeyBoardButton button) { + KeyboardButton buttonVk = new KeyboardButton(); + buttonVk.setColor(convertColor(button.getColor())); + + KeyboardButtonAction buttonActionVk = new KeyboardButtonAction(); + buttonActionVk.setLabel(button.getLabel()); + buttonActionVk.setType(KeyboardButtonActionType.TEXT); + buttonActionVk.setPayload(button.getPayload()); + + buttonVk.setAction(buttonActionVk); + return buttonVk; + } + + + private static KeyboardButtonColor convertColor(ButtonColor color) { + KeyboardButtonColor buttonColorVk; + switch (color) { + case DEFAULT: + buttonColorVk = KeyboardButtonColor.DEFAULT; + break; + case PRIMARY: + buttonColorVk = KeyboardButtonColor.PRIMARY; + break; + case NEGATIVE: + buttonColorVk = KeyboardButtonColor.NEGATIVE; + break; + case POSITIVE: + buttonColorVk = KeyboardButtonColor.POSITIVE; + break; + default: + buttonColorVk = KeyboardButtonColor.DEFAULT; + } + return buttonColorVk; + } + +} 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 d2fb0b2..5a400cf 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java @@ -5,14 +5,21 @@ 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.messages.Keyboard; +import com.vk.api.sdk.objects.messages.*; import com.vk.api.sdk.queries.messages.MessagesSendQuery; import org.apache.log4j.Logger; import org.sadtech.bot.core.domain.BoxAnswer; +import org.sadtech.bot.core.domain.keyboard.ButtonColor; +import org.sadtech.bot.core.domain.keyboard.KeyBoard; +import org.sadtech.bot.core.domain.keyboard.KeyBoardButton; +import org.sadtech.bot.core.domain.keyboard.KeyBoardLine; import org.sadtech.bot.core.sender.Sent; import org.sadtech.vkbot.core.VkConnect; import org.sadtech.vkbot.core.VkInsertData; +import org.sadtech.vkbot.core.convert.KeyBoardConvert; +import java.util.ArrayList; +import java.util.List; import java.util.concurrent.ThreadLocalRandom; public class MailSenderVk implements Sent { @@ -46,8 +53,7 @@ public class MailSenderVk implements Sent { private MessagesSendQuery createMessage(BoxAnswer boxAnswer, Integer peerId) { MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(peerId).message(vkInsertData.insertWords(boxAnswer.getMessage(), peerId)).randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)); if (boxAnswer.getKeyboard() != null) { - Keyboard keyBoard = gson.fromJson(boxAnswer.getKeyboard(), Keyboard.class); - messages.keyboard(keyBoard); + messages.keyboard(KeyBoardConvert.convertKeyboard(boxAnswer.getKeyboard())); } else { // messages.keyboard("{\"buttons\":[],\"one_time\":true}"); } @@ -64,6 +70,9 @@ public class MailSenderVk implements Sent { return messages; } + + + private void sendMessage(MessagesSendQuery messages) { try { messages.execute(); From f74ee0bcbde2f6a92de85d05d51ef94b425e82ab Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Wed, 15 May 2019 13:23:28 +0300 Subject: [PATCH 07/11] =?UTF-8?q?=D1=80=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3=20=D0=B2=20=D0=BE=D1=82=D0=BF?= =?UTF-8?q?=D1=80=D0=B0=D0=B2=D0=BA=D0=B5=20=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=B0=D1=82=D1=83=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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 5a400cf..baa3743 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java @@ -55,7 +55,9 @@ public class MailSenderVk implements Sent { if (boxAnswer.getKeyboard() != null) { messages.keyboard(KeyBoardConvert.convertKeyboard(boxAnswer.getKeyboard())); } else { -// messages.keyboard("{\"buttons\":[],\"one_time\":true}"); + Keyboard keyboard = new Keyboard(); + keyboard.setOneTime(true); + messages.keyboard(keyboard); } if (boxAnswer.getLat() != null && boxAnswer.getaLong() != null) { messages.lat(boxAnswer.getLat()).lng(boxAnswer.getaLong()); From 3a5b6b0d0a42cb5e7521ed08c256aed103b779c8 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 17 May 2019 00:30:34 +0300 Subject: [PATCH 08/11] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 +--- .../core/distribution/MailSubscriber.java | 65 +++++-------------- .../vkbot/core/sender/MailSenderVk.java | 11 +--- .../distribution/impl/MailServiceImpl.java | 9 +-- 4 files changed, 28 insertions(+), 69 deletions(-) diff --git a/pom.xml b/pom.xml index 8be0fe9..0701693 100644 --- a/pom.xml +++ b/pom.xml @@ -47,17 +47,9 @@ ${bot.core.ver} - - com.google.cloud - google-cloud-speech - 1.3.0 - - - com.google.cloud - google-cloud-storage - 1.73.0 - + + 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 fda8c42..a88ccd6 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java @@ -1,22 +1,21 @@ package org.sadtech.vkbot.core.distribution; -import com.google.cloud.speech.v1.*; import com.google.gson.Gson; import com.google.gson.JsonObject; -import com.google.protobuf.ByteString; import com.vk.api.sdk.objects.messages.Message; import com.vk.api.sdk.objects.messages.MessageAttachment; import com.vk.api.sdk.objects.messages.MessageAttachmentType; -import org.apache.commons.io.IOUtils; -import org.apache.commons.lang3.ArrayUtils; import org.apache.log4j.Logger; import org.sadtech.bot.core.domain.Mail; +import org.sadtech.bot.core.domain.attachment.Attachment; +import org.sadtech.bot.core.domain.attachment.AudioMessage; import org.sadtech.vkbot.core.service.distribution.MailService; -import java.io.*; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.time.Instant; +import java.time.LocalDateTime; import java.util.*; public class MailSubscriber implements EventSubscribe { @@ -46,44 +45,6 @@ public class MailSubscriber implements EventSubscribe { Message userMessage = gson.fromJson(object, Message.class); log.info(userMessage); - if (userMessage.getAttachments()!=null) { - for (MessageAttachment attachment : userMessage.getAttachments()) { - if (MessageAttachmentType.AUDIO_MESSAGE.equals(attachment.getType())) { - try (SpeechClient speechClient = SpeechClient.create()) { - - byte[] data = IOUtils.toByteArray(userMessage.getAttachments().get(0).getAudioMessage().getLinkOgg().openStream()); - ByteString audioBytes = ByteString.copyFrom(data); - - // Builds the sync recognize request - RecognitionConfig config = RecognitionConfig.newBuilder() - .setEncoding(RecognitionConfig.AudioEncoding.OGG_OPUS) - .setSampleRateHertz(16000) - .setLanguageCode("ru-RU") - .build(); - RecognitionAudio audio = RecognitionAudio.newBuilder() - .setContent(audioBytes) - .build(); - - // Performs speech recognition on the audio file - RecognizeResponse response = speechClient.recognize(config, audio); - List results = response.getResultsList(); - - for (SpeechRecognitionResult result : results) { - // There can be several alternative transcripts for a given chunk of speech. Just use the - // first (most likely) one here. - SpeechRecognitionAlternative alternative = result.getAlternativesList().get(0); - userMessage.setText(alternative.getTranscript()); - } - } catch (IOException e) { - e.printStackTrace(); - } - } - } - } - - - - if (userMessage.getPeerId() > 2000000000) { if (eventDistributionMap.containsKey("chat")) { eventDistributionMap.get("chat").update(userMessage); @@ -114,9 +75,19 @@ public class MailSubscriber implements EventSubscribe { private Mail createMaail(Message message) { Mail mail = new Mail(); mail.setMessage(message.getText()); - mail.setDate(message.getDate()); + mail.setDate(LocalDateTime.ofInstant(Instant.ofEpochSecond(message.getDate()), TimeZone.getDefault().toZoneId())); mail.setId(message.getId()); mail.setPersonId(message.getPeerId()); + + List attachments = new ArrayList<>(); + for (MessageAttachment attachment : message.getAttachments()) { + if (MessageAttachmentType.AUDIO_MESSAGE.equals(attachment.getType())) { + AudioMessage audioMessage = new AudioMessage(); + audioMessage.setLinkOdd(attachment.getAudioMessage().getLinkOgg()); + attachments.add(audioMessage); + } + } + mail.setAttachments(attachments); return mail; } 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 baa3743..6b3e8d9 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSenderVk.java @@ -5,21 +5,16 @@ 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.messages.*; +import com.vk.api.sdk.objects.messages.Keyboard; import com.vk.api.sdk.queries.messages.MessagesSendQuery; import org.apache.log4j.Logger; import org.sadtech.bot.core.domain.BoxAnswer; -import org.sadtech.bot.core.domain.keyboard.ButtonColor; -import org.sadtech.bot.core.domain.keyboard.KeyBoard; -import org.sadtech.bot.core.domain.keyboard.KeyBoardButton; -import org.sadtech.bot.core.domain.keyboard.KeyBoardLine; import org.sadtech.bot.core.sender.Sent; import org.sadtech.vkbot.core.VkConnect; import org.sadtech.vkbot.core.VkInsertData; import org.sadtech.vkbot.core.convert.KeyBoardConvert; -import java.util.ArrayList; -import java.util.List; +import java.util.Collections; import java.util.concurrent.ThreadLocalRandom; public class MailSenderVk implements Sent { @@ -49,7 +44,6 @@ 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)).randomId(ThreadLocalRandom.current().nextInt(0, Integer.MAX_VALUE)); if (boxAnswer.getKeyboard() != null) { @@ -57,6 +51,7 @@ public class MailSenderVk implements Sent { } else { Keyboard keyboard = new Keyboard(); keyboard.setOneTime(true); + keyboard.setButtons(Collections.EMPTY_LIST); messages.keyboard(keyboard); } if (boxAnswer.getLat() != null && boxAnswer.getaLong() != null) { diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java index ebbef13..8e839c7 100644 --- a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java +++ b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java @@ -6,6 +6,7 @@ import org.sadtech.bot.core.repository.MailRepository; import org.sadtech.bot.core.repository.impl.MailRepositoryList; import org.sadtech.vkbot.core.service.distribution.MailService; +import java.time.LocalDateTime; import java.util.ArrayList; import java.util.HashSet; import java.util.List; @@ -33,8 +34,8 @@ public class MailServiceImpl implements MailService { } @Override - public List getFirstEventByTime(Integer timeFrom, Integer timeTo) { - log.info("Запрошены сообщения " + timeFrom + "-" + timeTo); + public List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { + log.info("Запрошены сообщения " + timeFrom + " - " + timeTo); List mails = mailRepository.getMailByTime(timeFrom, timeTo); Set people = new HashSet<>(); List returnMails = new ArrayList<>(); @@ -48,7 +49,7 @@ public class MailServiceImpl implements MailService { } @Override - public List getLastEventByTime(Integer timeFrom, Integer timeTo) { + public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { List mails = mailRepository.getMailByTime(timeFrom, timeTo); Set people = new HashSet<>(); List returnMails = new ArrayList<>(); @@ -62,7 +63,7 @@ public class MailServiceImpl implements MailService { } @Override - public List getEvent(Integer timeFrom, Integer timeTo) { + public List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) { log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo); return mailRepository.getMailByTime(timeFrom, timeTo); } From a4601316cacc2a43f86a592e63aeeb46afb17ef6 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 17 May 2019 00:32:11 +0300 Subject: [PATCH 09/11] =?UTF-8?q?=D0=A3=D0=B4=D0=B0=D0=BB=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BD=D0=B5=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../vkbot/core/keyboard/KeyBoardService.java | 62 ------------------- 1 file changed, 62 deletions(-) delete mode 100644 src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java diff --git a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java deleted file mode 100644 index dcecd16..0000000 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java +++ /dev/null @@ -1,62 +0,0 @@ -package org.sadtech.vkbot.core.keyboard; - -import com.vk.api.sdk.objects.messages.*; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; - -public class KeyBoardService { - - private KeyBoardService() { - throw new IllegalStateException(); - } - - public static Keyboard keyBoardYesNo() { - KeyboardButton yesButton = new KeyboardButton(); - KeyboardButtonAction buttonActionYes = new KeyboardButtonAction(); - buttonActionYes.setLabel("Да"); - buttonActionYes.setType(KeyboardButtonActionType.TEXT); - buttonActionYes.setPayload("{\"button\": \"yes\"}"); - yesButton.setAction(buttonActionYes); - yesButton.setColor(KeyboardButtonColor.POSITIVE); - - KeyboardButton noButton = new KeyboardButton(); - KeyboardButtonAction buttonActionNo = new KeyboardButtonAction(); - buttonActionNo.setLabel("Да"); - buttonActionNo.setType(KeyboardButtonActionType.TEXT); - buttonActionNo.setPayload("{\"button\": \"no\"}"); - noButton.setAction(buttonActionNo); - noButton.setColor(KeyboardButtonColor.NEGATIVE); - - List line1 = new ArrayList<>(); - line1.add(yesButton); - line1.add(noButton); - - Keyboard keyboard = new Keyboard(); - keyboard.setButtons(Collections.singletonList(line1)); - keyboard.setOneTime(true); - return keyboard; - } - - public static Keyboard verticalKeyboard(List labelButtons) { - Keyboard keyBoard = new Keyboard(); - keyBoard.setOneTime(true); - List menu = new ArrayList<>(); - for (String labelButton : labelButtons) { - KeyboardButton button = new KeyboardButton(); - button.setColor(KeyboardButtonColor.DEFAULT); - - KeyboardButtonAction buttonAction = new KeyboardButtonAction(); - buttonAction.setPayload("{\"button\": \"" + labelButton + "\"}"); - buttonAction.setType(KeyboardButtonActionType.TEXT); - buttonAction.setLabel(labelButton); - - button.setAction(buttonAction); - menu.add(button); - } - keyBoard.setButtons(Collections.singletonList(menu)); - return keyBoard; - } -} From a584af0e92133f784942aa0e610b6c5cd71e89d2 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Fri, 17 May 2019 18:59:51 +0300 Subject: [PATCH 10/11] =?UTF-8?q?=D0=A0=D0=B5=D1=84=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=B8=D0=BD=D0=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 3 - .../core/distribution/MailSubscriber.java | 2 +- .../service/distribution/MailService.java | 8 --- .../distribution/impl/MailServiceImpl.java | 71 ------------------- 4 files changed, 1 insertion(+), 83 deletions(-) delete mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java delete mode 100644 src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java diff --git a/pom.xml b/pom.xml index 0701693..e33e9b0 100644 --- a/pom.xml +++ b/pom.xml @@ -47,9 +47,6 @@ ${bot.core.ver} - - - 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 a88ccd6..b4aeadf 100644 --- a/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java +++ b/src/main/java/org/sadtech/vkbot/core/distribution/MailSubscriber.java @@ -9,7 +9,7 @@ import org.apache.log4j.Logger; import org.sadtech.bot.core.domain.Mail; import org.sadtech.bot.core.domain.attachment.Attachment; import org.sadtech.bot.core.domain.attachment.AudioMessage; -import org.sadtech.vkbot.core.service.distribution.MailService; +import org.sadtech.bot.core.service.MailService; import java.io.ByteArrayOutputStream; import java.io.IOException; diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java deleted file mode 100644 index 5d1bbe7..0000000 --- a/src/main/java/org/sadtech/vkbot/core/service/distribution/MailService.java +++ /dev/null @@ -1,8 +0,0 @@ -package org.sadtech.vkbot.core.service.distribution; - -import org.sadtech.bot.core.domain.Mail; -import org.sadtech.bot.core.service.EventService; - -public interface MailService extends EventService { - -} diff --git a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java b/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java deleted file mode 100644 index 8e839c7..0000000 --- a/src/main/java/org/sadtech/vkbot/core/service/distribution/impl/MailServiceImpl.java +++ /dev/null @@ -1,71 +0,0 @@ -package org.sadtech.vkbot.core.service.distribution.impl; - -import org.apache.log4j.Logger; -import org.sadtech.bot.core.domain.Mail; -import org.sadtech.bot.core.repository.MailRepository; -import org.sadtech.bot.core.repository.impl.MailRepositoryList; -import org.sadtech.vkbot.core.service.distribution.MailService; - -import java.time.LocalDateTime; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public class MailServiceImpl implements MailService { - - private static final Logger log = Logger.getLogger(MailServiceImpl.class); - - private final MailRepository mailRepository; - - public MailServiceImpl() { - this.mailRepository = new MailRepositoryList(); - } - - public MailServiceImpl(MailRepository mailRepository) { - this.mailRepository = mailRepository; - } - - @Override - public void add(Mail mail) { - mailRepository.add(mail); - log.info("Сообщение добавлено в репозиторий"); - log.info(mail); - } - - @Override - public List getFirstEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрошены сообщения " + timeFrom + " - " + timeTo); - List mails = mailRepository.getMailByTime(timeFrom, timeTo); - Set people = new HashSet<>(); - List returnMails = new ArrayList<>(); - for (int i = mails.size() - 1; i >= 0; i--) { - if (!people.contains(mails.get(i).getPersonId())) { - returnMails.add(mails.get(i)); - people.add(mails.get(i).getPersonId()); - } - } - return returnMails; - } - - @Override - public List getLastEventByTime(LocalDateTime timeFrom, LocalDateTime timeTo) { - List mails = mailRepository.getMailByTime(timeFrom, timeTo); - Set people = new HashSet<>(); - List returnMails = new ArrayList<>(); - for (Mail mail : mails) { - if (!people.contains(mail.getPersonId())) { - returnMails.add(mail); - people.add(mail.getPersonId()); - } - } - return returnMails; - } - - @Override - public List getEvent(LocalDateTime timeFrom, LocalDateTime timeTo) { - log.info("Запрос на получение сообщений в интервале от " + timeFrom + " до " + timeTo); - return mailRepository.getMailByTime(timeFrom, timeTo); - } - -} From 39f0f2e94fa17b4a3905b9ad97ef943b93189b8e Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 18 May 2019 13:18:57 +0300 Subject: [PATCH 11/11] release-0.2.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index e33e9b0..ce1a15b 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.vkbot vkbot-core - 0.1.1-SNAPSHOT + 0.2.0-RELEASE jar @@ -23,7 +23,7 @@ - 0.5.2-SNAPSHOT + 0.6.0-RELEASE 0.5.13-SNAPSHOT 1.2.17