From e0befdf62adb82185d201f015647c1e2b65a6e59 Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sat, 26 Jan 2019 15:11:47 +0300 Subject: [PATCH] =?UTF-8?q?*=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=8C=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D0=B2=D0=BE=D0=B7=D0=B2=D1=80=D0=B0=D1=89=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=BA=D0=BB=D0=B0=D0=B2=D0=B8=D0=B0=D1=82=D1=83=D1=80?= =?UTF-8?q?=D1=8B=20*=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=B8=D1=82=D0=B5=D0=BB=D0=B1=D1=81=D0=BA?= =?UTF-8?q?=D1=83=D1=8E=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D1=8E=20=D1=8E=D0=BD=D0=B8=D1=82=D0=B0=20=D1=81=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D0=B2=D0=B8=D0=B0=D1=82=D1=83=D1=80=D0=BE=D0=B9,?= =?UTF-8?q?=20=D0=BE=D1=82=20=D0=BD=D0=B5=D0=B5=20=D0=B1=D1=83=D0=B4=D1=83?= =?UTF-8?q?=D1=82=20=D0=BD=D0=B0=D1=81=D0=BB=D0=B5=D0=B4=D0=BE=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=D1=81=D1=8F=20=D0=B2=D1=81=D0=B5=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20*=20=D0=94=D0=BE?= =?UTF-8?q?=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20=D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=B5=D1=80=D1=8C=20=D0=B4=D0=BB=D1=8F=20=D0=B0=D0=BA?= =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=B0=D1=86=D0=B8=D0=B8=20=D1=8E=D0=BD=D0=B8?= =?UTF-8?q?=D1=82=D0=B0=20=D0=B5=D1=89=D0=B5=20=D0=BE=D1=82=D0=BF=D1=80?= =?UTF-8?q?=D0=B0=D0=B2=D0=BB=D1=8F=D0=B5=D1=82=D1=81=D1=8F=20Mail=20(?= =?UTF-8?q?=D0=BD=D1=83=D0=B6=D0=BD=D0=BE=20=D0=B1=D1=8B=D0=BB=D0=BE=20?= =?UTF-8?q?=D0=B4=D0=BB=D1=8F=20=D1=8E=D0=BD=D0=B8=D1=82=D0=B0,=20=D0=BA?= =?UTF-8?q?=D0=BE=D1=82=D0=BE=D1=80=D1=8B=D0=B9=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D1=8F=D0=B5=D1=82=20=D0=BE=D1=82=D0=B2=D0=B5=D1=82?= =?UTF-8?q?=D1=8B=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D0=B5=D0=BB=D1=8F)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 ------ .../sadtech/vkbot/core/keyboard/KeyBoard.java | 17 ++++++++++++++--- .../vkbot/core/keyboard/KeyBoardService.java | 14 ++++++-------- .../vkbot/core/sender/MailSanderVk.java | 19 +++++++++++++++++-- .../vkbot/core/sender/MailSandler.java | 2 ++ 5 files changed, 39 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 93d7037..f2f6c73 100644 --- a/pom.xml +++ b/pom.xml @@ -33,7 +33,6 @@ 0.5.13-SNAPSHOT 1.2.17 20180813 - 1.1.2-SNAPHOT @@ -57,11 +56,6 @@ json ${json.ver} - - org.sadtech.autoresponder - autoresponder - ${autoresponder.ver} - 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 9f9937e..4037f3d 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoard.java @@ -9,18 +9,24 @@ import java.util.List; public class KeyBoard { private List lineKeyBoards = new ArrayList<>(); + private boolean oneTime; public KeyBoard() { } - public KeyBoard(List lineKeyBoards) { + public KeyBoard(List lineKeyBoards, boolean oneTime) { this.lineKeyBoards = lineKeyBoards; + this.oneTime = oneTime; } - public JSONObject getKeyboard(Boolean one_time) { + public void setOneTime(boolean oneTime) { + this.oneTime = oneTime; + } + + public JSONObject getKeyboard() { JSONObject keyboard = new JSONObject(); - keyboard.put("one_time", one_time); + keyboard.put("one_time", oneTime); JSONArray menuLine = new JSONArray(); for (LineKeyBoard lineKeyboard : lineKeyBoards) { @@ -50,6 +56,11 @@ public class KeyBoard { return this; } + public Builder setOneTime(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 81de780..fc77787 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/KeyBoardService.java @@ -1,31 +1,29 @@ package org.sadtech.vkbot.core.keyboard; -import org.json.JSONObject; - import java.util.List; public class KeyBoardService { - private JSONObject keyBoardYesNo = generateKeyBoardYesNo(); + private KeyBoard keyBoardYesNo = generateKeyBoardYesNo(); - private JSONObject generateKeyBoardYesNo() { + private KeyBoard generateKeyBoardYesNo() { ButtonKeyBoard yesButton = ButtonKeyBoard.builder().setColor(ColorButton.POSITIVE).setLabel("Да").setPayload("{\"button\": \"yes\"}").build(); ButtonKeyBoard noButton = ButtonKeyBoard.builder().setColor(ColorButton.NEGATIVE).setLabel("Нет").setPayload("{\"button\": \"no\"}").build(); LineKeyBoard lineKeyBoard = LineKeyBoard.builder().setButtonKeyBoard(yesButton).setButtonKeyBoard(noButton).build(); KeyBoard keyBoard = KeyBoard.builder().setLineKeyBoard(lineKeyBoard).build(); - return keyBoard.getKeyboard(true); + return keyBoard; } - public static JSONObject verticalMenu(List labelButtons) { + public static KeyBoard verticalMenu(List labelButtons) { KeyBoard keyBoard = new KeyBoard(); for (String labelButton : labelButtons) { ButtonKeyBoard buttonKeyBoard = ButtonKeyBoard.builder().setLabel(labelButton).setType("text").setPayload("{\"button\": \"" + labelButton + "\"}").build(); keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build()); } - return keyBoard.getKeyboard(true); + return keyBoard; } - public JSONObject getKeyBoardYesNo() { + public KeyBoard getKeyBoardYesNo() { return keyBoardYesNo; } } diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java index a195800..1358b7d 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java @@ -10,6 +10,8 @@ import org.sadtech.vkbot.core.entity.Person; public class MailSanderVk implements MailSandler { private Person person; + + private Integer idRecipient; private VkApiClient vkApiClient; private GroupActor groupActor; @@ -24,14 +26,27 @@ public class MailSanderVk implements MailSandler { this.groupActor = vkConnect.getGroupActor(); } + public void setIdRecipient(Integer idRecipient) { + this.idRecipient = idRecipient; + } + public void setPerson(Person person) { - this.person = person; + idRecipient = person.getId(); + } + + @Override + public void send(String text, String keyBoard) { + try { + vkApiClient.messages().send(groupActor).peerId(idRecipient).keyboard(keyBoard).message(text).execute(); + } catch (ApiException | ClientException e) { + e.printStackTrace(); + } } @Override public void send(String text) { try { - vkApiClient.messages().send(groupActor).userId(person.getId()).message(text).execute(); + vkApiClient.messages().send(groupActor).userId(idRecipient).message(text).execute(); } catch (ApiException | ClientException e) { e.printStackTrace(); } diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java index 8d743b6..a7e569a 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java @@ -8,4 +8,6 @@ public interface MailSandler { void setPerson(Person person); + void send(String text, String keyBoard); + }