- Баллы
- 76
- Имя в Minecraft
- Solomka
Уважаемые, почему бот выводит по два раза сообщение, если моя ошибка на самом видном месте, то простите меня)))
P.S Я делаю через gradle, если это как-то поможет делу
Код:
Вывод в вконтакте:
P.S Я делаю через gradle, если это как-то поможет делу
Код:
Код:
private static final TransportClient transportClient = new HttpTransportClient();
private static final Random random = new Random();
private static final Keyboard keyboard = new Keyboard();
private static final List<List<KeyboardButton>> allKey = new ArrayList<>();
private static final List<KeyboardButton> line1 = new ArrayList<>();
private static final HashSet<Integer> cooldown = new HashSet<Integer>();
protected static final VkApiClient vk = new VkApiClient(transportClient);
private static final String[] help = {
"1.Привязать аккаунт\n",
"2.Отвязать аккаунт\n",
"3.Сменить пароль\n",
"4.Сбросить пароль\n",
};
public static void startBot() throws ClientException, ApiException, InterruptedException {
line1.add(new KeyboardButton().setAction(new KeyboardButtonAction().setLabel("Привязать аккаунт").setType(KeyboardButtonActionType.TEXT)).setColor(KeyboardButtonColor.POSITIVE));
line1.add(new KeyboardButton().setAction(new KeyboardButtonAction().setLabel("Отвязать аккаунт").setType(KeyboardButtonActionType.TEXT)).setColor(KeyboardButtonColor.POSITIVE));
line1.add(new KeyboardButton().setAction(new KeyboardButtonAction().setLabel("Сменить пароль").setType(KeyboardButtonActionType.TEXT)).setColor(KeyboardButtonColor.POSITIVE));
line1.add(new KeyboardButton().setAction(new KeyboardButtonAction().setLabel("Сбросить пароль").setType(KeyboardButtonActionType.TEXT)).setColor(KeyboardButtonColor.POSITIVE));
allKey.add(line1);
keyboard.setButtons(allKey);
GroupActor actor = new GroupActor(***,"***");
Integer ts = vk.messages().getLongPollServer(actor).execute().getTs();
while (true) {
MessagesGetLongPollHistoryQuery historyQuery = vk.messages().getLongPollHistory(actor).ts(ts);
List<Message> messages = historyQuery.execute().getMessages().getItems();
if (!messages.isEmpty()) {
messages.forEach(message -> {
try {
switch (message.getText()) {
case "Привязать аккаунт" -> {
vk.messages().send(actor).message("Тест").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
return;
}
case "Отвязать аккаунт" -> {
vk.messages().send(actor).message("Тест").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
break;
}
case "Сбросить пароль" -> {
vk.messages().send(actor).message("Тест").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
break;
}
case "Сменить пароль" -> {
vk.messages().send(actor).message("Тест").userId(message.getFromId()).randomId(random.nextInt(10000)).execute();
break;
}
default -> {
vk.messages().send(actor).message(buildString(help,actor,message,random,keyboard)).userId(message.getFromId()).randomId(random.nextInt(10000)).keyboard(keyboard).execute();
break;
}
}
} catch (ApiException | ClientException e) {
e.printStackTrace();
}
});
}
ts = vk.messages().getLongPollServer(actor).execute().getTs();
sleep(1000);
}
}
}
Вывод в вконтакте:
Код:
Тест
Тест
Последнее редактирование: