Core: Изменение отправки сообщений в вк
* Исправил баг с сообщениями, которые приходили позже проверки (костыль)
This commit is contained in:
parent
b66e1902eb
commit
04a7e180b1
2
pom.xml
2
pom.xml
@ -6,7 +6,7 @@
|
||||
|
||||
<groupId>org.sadtech.vkbot</groupId>
|
||||
<artifactId>core</artifactId>
|
||||
<version>0.3-RELEASE</version>
|
||||
<version>0.4-SNAPSHOT</version>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
|
@ -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() {
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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);
|
||||
|
||||
}
|
||||
|
54
src/main/java/org/sadtech/vkbot/core/sender/MailSend.java
Normal file
54
src/main/java/org/sadtech/vkbot/core/sender/MailSend.java
Normal file
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user