From 04a7e180b1c6ef55dda774a97b0a7d477bf1a5ce Mon Sep 17 00:00:00 2001 From: Mark Struchkov Date: Sun, 27 Jan 2019 16:16:10 +0300 Subject: [PATCH] =?UTF-8?q?Core:=20=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2=D0=BA?= =?UTF-8?q?=D0=B8=20=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D0=B9?= =?UTF-8?q?=20=D0=B2=20=D0=B2=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Исправил баг с сообщениями, которые приходили позже проверки (костыль) --- pom.xml | 2 +- .../vkbot/core/keyboard/ButtonKeyBoard.java | 2 +- .../vkbot/core/sender/MailSanderVk.java | 40 +++++--------- .../vkbot/core/sender/MailSandler.java | 8 +-- .../sadtech/vkbot/core/sender/MailSend.java | 54 +++++++++++++++++++ 5 files changed, 69 insertions(+), 37 deletions(-) create mode 100644 src/main/java/org/sadtech/vkbot/core/sender/MailSend.java diff --git a/pom.xml b/pom.xml index aafdd40..c03d021 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ org.sadtech.vkbot core - 0.3-RELEASE + 0.4-SNAPSHOT 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 350328e..d33d139 100644 --- a/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java +++ b/src/main/java/org/sadtech/vkbot/core/keyboard/ButtonKeyBoard.java @@ -7,7 +7,7 @@ public class ButtonKeyBoard { private String type = "text"; private String payload; private String label; - private ColorButton color = ColorButton.DEFAULT; + private ColorButton color = ColorButton.PRIMARY; public ButtonKeyBoard() { 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 1358b7d..82306ad 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSanderVk.java @@ -4,14 +4,11 @@ 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.queries.messages.MessagesSendQuery; import org.sadtech.vkbot.core.VkConnect; -import org.sadtech.vkbot.core.entity.Person; public class MailSanderVk implements MailSandler { - private Person person; - - private Integer idRecipient; private VkApiClient vkApiClient; private GroupActor groupActor; @@ -19,34 +16,21 @@ public class MailSanderVk implements MailSandler { this.vkApiClient = vkConnect.getVkApiClient(); this.groupActor = vkConnect.getGroupActor(); } - - public MailSanderVk(Person person, VkConnect vkConnect) { - this.person = person; - this.vkApiClient = vkConnect.getVkApiClient(); - this.groupActor = vkConnect.getGroupActor(); - } - - public void setIdRecipient(Integer idRecipient) { - this.idRecipient = idRecipient; - } - - public void setPerson(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(); + public void send(MailSend mailSend) { + MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(mailSend.getIdRecipient()); + if (mailSend.getMessage()!=null) { + messages.message(mailSend.getMessage()); + } + if (mailSend.getKeyboard()!=null) { + messages.keyboard(mailSend.getKeyboard()); + } + if (mailSend.getLat()!=null && mailSend.getaLong()!=null) { + messages.lat(mailSend.getLat()).lng(mailSend.getaLong()); } - } - @Override - public void send(String text) { try { - vkApiClient.messages().send(groupActor).userId(idRecipient).message(text).execute(); + messages.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 a7e569a..54989e0 100644 --- a/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSandler.java @@ -1,13 +1,7 @@ package org.sadtech.vkbot.core.sender; -import org.sadtech.vkbot.core.entity.Person; - public interface MailSandler { - void send(String text); - - void setPerson(Person person); - - void send(String text, String keyBoard); + void send(MailSend mailSend); } diff --git a/src/main/java/org/sadtech/vkbot/core/sender/MailSend.java b/src/main/java/org/sadtech/vkbot/core/sender/MailSend.java new file mode 100644 index 0000000..aa98d1c --- /dev/null +++ b/src/main/java/org/sadtech/vkbot/core/sender/MailSend.java @@ -0,0 +1,54 @@ +package org.sadtech.vkbot.core.sender; + +public class MailSend { + + private String message; + private String keyboard; + private Integer idRecipient; + private Float lat; + private Float aLong; + + public MailSend() { + + } + + public String getKeyboard() { + return keyboard; + } + + public void setKeyboard(String keyboard) { + this.keyboard = keyboard; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public Integer getIdRecipient() { + return idRecipient; + } + + public void setIdRecipient(Integer idRecipient) { + this.idRecipient = idRecipient; + } + + public Float getLat() { + return lat; + } + + public void setLat(Float lat) { + this.lat = lat; + } + + public Float getaLong() { + return aLong; + } + + public void setaLong(Float aLong) { + this.aLong = aLong; + } +}