Новый тип юнитов - таймеры
Таймер срабатывает не сразу а через какое-то время, заставляет сработать любой другой тип юнита
This commit is contained in:
parent
3027f7d5cf
commit
ccdc44d689
@ -51,4 +51,16 @@ public class VkApi {
|
||||
}
|
||||
return temp != null ? temp.get(0).getUniversities().get(0).getName() : null;
|
||||
}
|
||||
|
||||
public String getUserCity(Integer id) {
|
||||
List<UserXtrCounters> temp = null;
|
||||
try {
|
||||
temp = vk.users().get(actor).userIds(String.valueOf(id)).fields(UserField.CITY).execute();
|
||||
} catch (ApiException | ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return temp != null ? temp.get(0).getCity().getTitle() : null;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,29 +1,38 @@
|
||||
package org.sadtech.vkbot.core;
|
||||
|
||||
import org.sadtech.vkbot.core.entity.MailSend;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class VkInsertData {
|
||||
|
||||
private VkApi vkApi;
|
||||
private Integer userId;
|
||||
|
||||
public VkInsertData(VkConnect vkConnect) {
|
||||
this.vkApi = new VkApi(vkConnect);
|
||||
}
|
||||
|
||||
public Integer getUserId() {
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(Integer userId) {
|
||||
this.userId = userId;
|
||||
}
|
||||
|
||||
public String insert(String key) {
|
||||
String string = "";
|
||||
if (key.toLowerCase().equals("%firstname%")) {
|
||||
string = vkApi.getUserMini(userId).getFirstName();
|
||||
public String insertWords(MailSend mailSend, Integer idUser) {
|
||||
Pattern pattern = Pattern.compile("%(\\w+)%");
|
||||
Matcher m = pattern.matcher(mailSend.getMessage());
|
||||
StringBuffer result = new StringBuffer();
|
||||
while (m.find()) {
|
||||
m.appendReplacement(result, insert(m.group(0), idUser));
|
||||
}
|
||||
if (key.toLowerCase().equals("%lastname%")) {
|
||||
string = vkApi.getUserMini(userId).getLastName();
|
||||
m.appendTail(result);
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
private String insert(String key, Integer userId) {
|
||||
String string = "";
|
||||
switch (key) {
|
||||
case "%firstname%":
|
||||
string = vkApi.getUserMini(userId).getFirstName();
|
||||
break;
|
||||
case "%lastname%":
|
||||
string = vkApi.getUserMini(userId).getLastName();
|
||||
break;
|
||||
}
|
||||
return string;
|
||||
}
|
||||
|
@ -4,7 +4,6 @@ public class MailSend {
|
||||
|
||||
private String message;
|
||||
private String keyboard;
|
||||
private Integer idRecipient;
|
||||
private Float lat;
|
||||
private Float aLong;
|
||||
private Integer stickerId;
|
||||
@ -29,14 +28,6 @@ public class MailSend {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
public Integer getIdRecipient() {
|
||||
return idRecipient;
|
||||
}
|
||||
|
||||
public void setIdRecipient(Integer idRecipient) {
|
||||
this.idRecipient = idRecipient;
|
||||
}
|
||||
|
||||
public Float getLat() {
|
||||
return lat;
|
||||
}
|
||||
@ -66,7 +57,6 @@ public class MailSend {
|
||||
return "MailSend{" +
|
||||
"message='" + message + '\'' +
|
||||
", keyboard='" + keyboard + '\'' +
|
||||
", idRecipient=" + idRecipient +
|
||||
", lat=" + lat +
|
||||
", aLong=" + aLong +
|
||||
", stickerId=" + stickerId +
|
||||
|
@ -1,7 +0,0 @@
|
||||
package org.sadtech.vkbot.core.keyboard;
|
||||
|
||||
public interface ButtonKeyBoardService {
|
||||
|
||||
|
||||
|
||||
}
|
@ -9,6 +9,7 @@ public class KeyBoardService {
|
||||
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();
|
||||
keyBoard.setOneTime(true);
|
||||
return keyBoard;
|
||||
}
|
||||
|
||||
@ -18,6 +19,7 @@ public class KeyBoardService {
|
||||
ButtonKeyBoard buttonKeyBoard = ButtonKeyBoard.builder().setLabel(labelButton).setType("text").setPayload("{\"button\": \"" + labelButton + "\"}").build();
|
||||
keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build());
|
||||
}
|
||||
keyBoard.setOneTime(true);
|
||||
return keyBoard;
|
||||
}
|
||||
|
||||
@ -26,6 +28,7 @@ public class KeyBoardService {
|
||||
for (ButtonKeyBoard buttonKeyBoard : buttonKeyBoards) {
|
||||
keyBoard.addLine(LineKeyBoard.builder().setButtonKeyBoard(buttonKeyBoard).build());
|
||||
}
|
||||
keyBoard.setOneTime(true);
|
||||
return keyBoard;
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +0,0 @@
|
||||
package org.sadtech.vkbot.core.keyboard;
|
||||
|
||||
public interface LineKeyBoardService {
|
||||
}
|
@ -9,9 +9,9 @@ import org.apache.log4j.Logger;
|
||||
import org.sadtech.vkbot.core.VkConnect;
|
||||
import org.sadtech.vkbot.core.VkInsertData;
|
||||
import org.sadtech.vkbot.core.entity.MailSend;
|
||||
import org.sadtech.vkbot.core.insert.InsertWords;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.List;
|
||||
|
||||
public class MailSanderVk implements MailSandler {
|
||||
|
||||
@ -28,12 +28,8 @@ public class MailSanderVk implements MailSandler {
|
||||
this.vkInsertData = new VkInsertData(vkConnect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MailSend mailSend) {
|
||||
MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(mailSend.getIdRecipient());
|
||||
if (mailSend.getMessage() != null) {
|
||||
messages.message(insertWords(mailSend));
|
||||
}
|
||||
private MessagesSendQuery createMessage (MailSend mailSend, Integer idUser) {
|
||||
MessagesSendQuery messages = vkApiClient.messages().send(groupActor).peerId(idUser);
|
||||
if (mailSend.getKeyboard() != null) {
|
||||
messages.keyboard(mailSend.getKeyboard());
|
||||
} else {
|
||||
@ -44,30 +40,39 @@ public class MailSanderVk implements MailSandler {
|
||||
}
|
||||
if (mailSend.getStickerId() != null) {
|
||||
try {
|
||||
vkApiClient.messages().send(groupActor).peerId(mailSend.getIdRecipient()).stickerId(mailSend.getStickerId()).execute();
|
||||
vkApiClient.messages().send(groupActor).peerId(idUser).stickerId(mailSend.getStickerId()).execute();
|
||||
} catch (ApiException | ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void send(MailSend mailSend, Integer idUser) {
|
||||
MessagesSendQuery messages = createMessage(mailSend, idUser);
|
||||
if (mailSend.getMessage() != null) {
|
||||
messages.message(vkInsertData.insertWords(mailSend, idUser));
|
||||
}
|
||||
sendMessage(messages);
|
||||
}
|
||||
|
||||
public void send(MailSend mailSend, Integer idUser, List<String> insertWords) {
|
||||
MessagesSendQuery messages = createMessage(mailSend, idUser);
|
||||
if (mailSend.getMessage() != null) {
|
||||
InsertWords insert = new InsertWords();
|
||||
insert.setInText(vkInsertData.insertWords(mailSend, idUser));
|
||||
insert.insert(insertWords);
|
||||
messages.message(insert.getOutText());
|
||||
}
|
||||
sendMessage(messages);
|
||||
}
|
||||
|
||||
private void sendMessage(MessagesSendQuery messages) {
|
||||
try {
|
||||
log.info(mailSend);
|
||||
messages.execute();
|
||||
} catch (ApiException | ClientException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private String insertWords(MailSend mailSend) {
|
||||
vkInsertData.setUserId(mailSend.getIdRecipient());
|
||||
|
||||
Pattern pattern = Pattern.compile("\\%(\\w+)%");
|
||||
Matcher m = pattern.matcher(mailSend.getMessage());
|
||||
StringBuffer result = new StringBuffer();
|
||||
while (m.find()) {
|
||||
m.appendReplacement(result, vkInsertData.insert(m.group(0)));
|
||||
}
|
||||
m.appendTail(result);
|
||||
return result.toString();
|
||||
}
|
||||
}
|
||||
|
@ -2,8 +2,12 @@ package org.sadtech.vkbot.core.sender;
|
||||
|
||||
import org.sadtech.vkbot.core.entity.MailSend;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface MailSandler {
|
||||
|
||||
void send(MailSend mailSend);
|
||||
void send(MailSend mailSend, Integer idUser);
|
||||
|
||||
void send(MailSend mailSend, Integer idUser, List<String> insertWords);
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user