Привел к новой версии SDK VK 1.0.2

This commit is contained in:
Mark Struchkov 2019-05-13 20:34:03 +03:00
parent 593e5f8c34
commit 0bab5fa93e
4 changed files with 14 additions and 11 deletions

View File

@ -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<UserXtrCounters> 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<UserXtrCounters> 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);
}

View File

@ -37,12 +37,14 @@ public class MailSubscriber implements EventSubscribe<JsonObject> {
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<JsonObject> {
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());

View File

@ -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");
}

View File

@ -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());