Commit 3cc6a9c0 authored by Delorus's avatar Delorus
Browse files

Feature #30 Обновить версию telegrambots до 5.2.0

parent 3bc0a018
# Требования к API
* Безопасное сохранение различных паролей, ключей и т.д. (шифровать их в бд с помощью случайного ключа, который будет храниться как переменная среды в ci)
* Доступ к персистентному хранилищу (только для stateful плагинов)
* Разделение на stateful и stateless плагины, где:
* Stateful имеют доступ к бд, к сообщениям пользователей, запускаются по одному инстансу для каждой группы и не пересекаются
* Stateless глобальные для всех групп, имеют доступ только к командам
# Требование к плагинам
* Каждый плагин декларирует свой id, версию апи, свой тип и какие права ему нужны
......@@ -4,5 +4,5 @@ plugins {
dependencies {
// https://github.com/rubenlagus/TelegramBots
implementation "org.telegram:telegrambots-meta:4.8.1"
implementation "org.telegram:telegrambots-meta:5.2.0"
}
package page.devnet.telegrambot;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Message;
......@@ -12,11 +13,11 @@ import java.io.IOException;
import java.util.Collections;
import java.util.List;
public class AdministrationPlugin implements Plugin<Update, List<PartialBotApiMethod>> {
public class AdministrationPlugin implements Plugin<Update, List<PartialBotApiMethod<?>>> {
private final PluginManager pluginManager;
public AdministrationPlugin(PluginManager<Update, List<PartialBotApiMethod>> pluginManager) {
public AdministrationPlugin(PluginManager<Update, List<PartialBotApiMethod<?>>> pluginManager) {
this.pluginManager = pluginManager;
}
......@@ -26,7 +27,7 @@ public class AdministrationPlugin implements Plugin<Update, List<PartialBotApiMe
}
@Override
public List<PartialBotApiMethod> onEvent(Update event) {
public List<PartialBotApiMethod<?>> onEvent(Update event) {
if (!event.hasMessage() || !event.getMessage().hasText()) {
return Collections.emptyList();
}
......@@ -43,32 +44,49 @@ public class AdministrationPlugin implements Plugin<Update, List<PartialBotApiMe
return Collections.emptyList();
}
private List<PartialBotApiMethod> executeCommand(Message message) throws IOException {
private List<PartialBotApiMethod<?>> executeCommand(Message message) throws IOException {
ParserMessage parserMessage = new ParserMessage();
var parsedCommand = parserMessage.getCommandFromMessage(message.getText());
var commandParameter = parserMessage.getCommandParameterFromMessage(message.getText());
var chatId = String.valueOf(message.getChatId());
switch (parsedCommand) {
case ENABLE:
if (commandParameter.equals("")) {
return List.of(new SendMessage(message.getChatId(), "please input pluginId as second parameter, example: '/enable limitPlug' " + pluginManager.getAllPlugins()).enableMarkdown(true));
return List.of(SendMessage.builder()
.chatId(chatId)
.text("please input pluginId as second parameter, example: '/enable limitPlug' " + pluginManager.getAllPlugins())
.parseMode(ParseMode.MARKDOWN)
.build());
}
var pluginToEnable = pluginManager.getPluginById(commandParameter);
pluginManager.enablePlugin(commandParameter);
return List.of(new SendMessage(message.getChatId(), "Enable plugin " + pluginToEnable.getPluginId()).enableMarkdown(true));
return List.of(SendMessage.builder()
.chatId(chatId)
.text("Enable plugin " + pluginToEnable.getPluginId())
.parseMode(ParseMode.MARKDOWN)
.build());
case DISABLE:
if (commandParameter.equals("")) {
return List.of(new SendMessage(message.getChatId(), "please input pluginId as second parametr, example: '/disable limitPlug' " + pluginManager.getAllPlugins()).enableMarkdown(true));
return List.of(SendMessage.builder()
.chatId(chatId)
.text("please input pluginId as second parameter, example: '/disable limitPlug' " + pluginManager.getAllPlugins())
.parseMode(ParseMode.MARKDOWN)
.build());
}
if (commandParameter.equals("adminPlug")) {
return List.of(new SendMessage(message.getChatId(),"please input pluginId, adminPlug - prohibited ").enableMarkdown(true));
return List.of(SendMessage.builder()
.chatId(chatId)
.text("please input pluginId, adminPlug - prohibited")
.parseMode(ParseMode.MARKDOWN)
.build());
}
pluginManager.disablePlugin(commandParameter);
return List.of(new SendMessage(message.getChatId(), "Disable plugin " + commandParameter).enableMarkdown(true));
return List.of(new SendMessage(chatId, "Disable plugin " + commandParameter));
case WORKPLUG:
return List.of(new SendMessage(message.getChatId(),pluginManager.getWorkPluginsName().toString()).enableMarkdown(true));
return List.of(new SendMessage(chatId,pluginManager.getWorkPluginsName().toString()));
case ALLPLUG:
return List.of(new SendMessage(message.getChatId(),pluginManager.getAllPlugins()).enableMarkdown(true));
return List.of(new SendMessage(chatId,pluginManager.getAllPlugins()));
default:
return Collections.emptyList();
}
......
......@@ -16,19 +16,19 @@ import java.util.List;
* @author sherb
* @since 14.05.2021
*/
public class IgnoreMeFilter implements MessageSubscriber<Update, List<PartialBotApiMethod>> {
public class IgnoreMeFilter implements MessageSubscriber<Update, List<PartialBotApiMethod<?>>> {
private final MessageSubscriber<Update, List<PartialBotApiMethod>> subscriber;
private final MessageSubscriber<Update, List<PartialBotApiMethod<?>>> subscriber;
private final IgnoreMeRepository ignoreMeRepository;
private final CommandUtils commandUtils = new CommandUtils();
public IgnoreMeFilter(MessageSubscriber<Update, List<PartialBotApiMethod>> subscriber, IgnoreMeRepository ignoreMeRepository) {
public IgnoreMeFilter(MessageSubscriber<Update, List<PartialBotApiMethod<?>>> subscriber, IgnoreMeRepository ignoreMeRepository) {
this.subscriber = subscriber;
this.ignoreMeRepository = ignoreMeRepository;
}
@Override
public List<List<PartialBotApiMethod>> consume(Update event) {
public List<List<PartialBotApiMethod<?>>> consume(Update event) {
if (!event.hasMessage()) {
return subscriber.consume(event);
}
......@@ -42,7 +42,7 @@ public class IgnoreMeFilter implements MessageSubscriber<Update, List<PartialBot
}
}
Integer id = msg.getFrom().getId();
Integer id = msg.getFrom().getId().intValue();
if (ignoreMeRepository.contains(id)) {
return Collections.emptyList();
}
......@@ -61,20 +61,22 @@ public class IgnoreMeFilter implements MessageSubscriber<Update, List<PartialBot
}
}
private List<PartialBotApiMethod> execCmd(Message cmd) {
private List<PartialBotApiMethod<?>> execCmd(Message cmd) {
var id = cmd.getFrom().getId().intValue();
var chatId = String.valueOf(cmd.getChatId());
switch (commandUtils.normalizeCmdMsg(cmd.getText())) {
case "ignoremeplease":
var added = ignoreMeRepository.add(cmd.getFrom().getId());
var added = ignoreMeRepository.add(id);
if (!added) {
return List.of(new SendMessage(cmd.getChatId(), i18n("TGEtbGEtbGEsIGkgZG9uJ3QgbGlzdGVuIHRvIHlvdSwgeW91J3JlIGlnbm9yZWQ=")));
return List.of(new SendMessage(chatId, i18n("TGEtbGEtbGEsIGkgZG9uJ3QgbGlzdGVuIHRvIHlvdSwgeW91J3JlIGlnbm9yZWQ=")));
}
return List.of(new SendMessage(cmd.getChatId(), i18n("QXMgeW91ciB3aXNo")));
return List.of(new SendMessage(chatId, i18n("QXMgeW91ciB3aXNo")));
case "dontignoreme":
var removed = ignoreMeRepository.remove(cmd.getFrom().getId());
var removed = ignoreMeRepository.remove(id);
if (!removed) {
return List.of(new SendMessage(cmd.getChatId(), i18n("SSBuZXZlciBpZ25vcmVkIHlvdSwgdGhlcmUgbXVzdCBiZSBzb21lIG1pc3Rha2U=")));
return List.of(new SendMessage(chatId, i18n("SSBuZXZlciBpZ25vcmVkIHlvdSwgdGhlcmUgbXVzdCBiZSBzb21lIG1pc3Rha2U=")));
}
return List.of(new SendMessage(cmd.getChatId(), i18n("SSB3aWxsIG5vdCBpZ25vcmUgeW91IGFueW1vcmU=")));
return List.of(new SendMessage(chatId, i18n("SSB3aWxsIG5vdCBpZ25vcmUgeW91IGFueW1vcmU=")));
default:
throw new IllegalStateException("it can't happen");
}
......
......@@ -8,6 +8,7 @@ import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
......@@ -15,7 +16,6 @@ import org.telegram.telegrambots.meta.generics.BotOptions;
import org.telegram.telegrambots.meta.generics.LongPollingBot;
import org.telegram.telegrambots.meta.generics.WebhookBot;
import page.devnet.pluginmanager.MessageSubscriber;
import page.devnet.vertxtgbot.tgapi.SetupWebhookAction;
import page.devnet.vertxtgbot.tgapi.TelegramSender;
import java.time.Instant;
......@@ -41,11 +41,11 @@ class TelegramBot {
private final String name;
private final String token;
private final String path;
private final MessageSubscriber<Update, List<PartialBotApiMethod>> eventSubscriber;
private final MessageSubscriber<Update, List<PartialBotApiMethod<?>>> eventSubscriber;
private final TelegramSender telegramSender;
private final Instant startTime;
public TelegramBot(Vertx vertx, Setting setting, MessageSubscriber<Update, List<PartialBotApiMethod>> subscriber) {
public TelegramBot(Vertx vertx, Setting setting, MessageSubscriber<Update, List<PartialBotApiMethod<?>>> subscriber) {
this.name = setting.name;
this.token = setting.token;
this.path = setting.path;
......@@ -70,7 +70,7 @@ class TelegramBot {
private class ProdBotManager implements WebhookBot {
@Override
public BotApiMethod onWebhookUpdateReceived(Update update) {
public BotApiMethod<?> onWebhookUpdateReceived(Update update) {
if (update.hasMessage() && isBeforeStart(update.getMessage())) {
log.warn("skip message: [{}], that got before starting: [start: {}, got: {}]", update.getMessage().getText(), startTime, Instant.ofEpochMilli(update.getMessage().getDate()).atZone(ZoneOffset.UTC));
return null;
......@@ -82,12 +82,18 @@ class TelegramBot {
.forEach(telegramSender::send);
} catch (Exception e) {
log.error(e.getMessage(), e);
telegramSender.send(new SendMessage(update.getMessage().getChatId(), e.toString()));
var chatId = update.getMessage().getChatId();
telegramSender.send(new SendMessage(String.valueOf(chatId), e.toString()));
}
return null;
}
@Override
public void setWebhook(SetWebhook setWebhook) {
telegramSender.send(setWebhook);
}
private boolean isBeforeStart(Message message) {
return Instant.ofEpochSecond(message.getDate()).isBefore(startTime);
}
......@@ -102,11 +108,6 @@ class TelegramBot {
return token;
}
@Override
public void setWebhook(String url, String publicCertificatePath) {
telegramSender.send(new SetupWebhookAction(token, url, publicCertificatePath));
}
@Override
public String getBotPath() {
return path;
......@@ -128,7 +129,8 @@ class TelegramBot {
.forEach(telegramSender::send);
} catch (Exception e) {
log.error(e.getMessage(), e);
telegramSender.send(new SendMessage(update.getMessage().getChatId(), e.toString()));
var chatId = update.getMessage().getChatId();
telegramSender.send(new SendMessage(String.valueOf(chatId), e.toString()));
}
}
......@@ -153,7 +155,7 @@ class TelegramBot {
@Override
public void clearWebhook() throws TelegramApiRequestException {
//todo wtf?
//no webhook on long pooling bot
}
}
}
......@@ -4,10 +4,12 @@ import io.vertx.core.Vertx;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.updates.SetWebhook;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import page.devnet.pluginmanager.MessageSubscriber;
import page.devnet.vertxtgbot.ApiContextInitializer;
import page.devnet.vertxtgbot.VertxBotSession;
import page.devnet.vertxtgbot.VertxWebhook;
import java.util.List;
......@@ -34,18 +36,18 @@ public final class TelegramBotExecutor {
this.vertx = vertx;
}
public void runBotWith(MessageSubscriber<Update, List<PartialBotApiMethod>> subscriber) {
public void runBotWith(MessageSubscriber<Update, List<PartialBotApiMethod<?>>> subscriber) {
var telegramBot = createTelegramBot(subscriber);
try {
initTelegramConnection(telegramBot, isProd);
} catch (TelegramApiRequestException e) {
} catch (TelegramApiException e) {
log.error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
private TelegramBot createTelegramBot(MessageSubscriber<Update, List<PartialBotApiMethod>> subscriber) {
private TelegramBot createTelegramBot(MessageSubscriber<Update, List<PartialBotApiMethod<?>>> subscriber) {
TelegramBot.Setting setting = TelegramBot.Setting.builder()
.name(System.getenv("TG_BOT_NAME"))
.token(System.getenv("TG_BOT_TOKEN"))
......@@ -55,18 +57,20 @@ public final class TelegramBotExecutor {
return new TelegramBot(vertx, setting, subscriber);
}
private void initTelegramConnection(TelegramBot bot, boolean isProdEnv) throws TelegramApiRequestException {
ApiContextInitializer.init(isProdEnv);
private void initTelegramConnection(TelegramBot bot, boolean isProdEnv) throws TelegramApiException {
TelegramBotsApi api;
if (isProdEnv) {
api = new TelegramBotsApi(System.getenv("EXTERNAL_URI"), "http://0.0.0.0:" + System.getenv("PORT") + "/");
var webhook = new VertxWebhook(vertx);
webhook.setInternalUrl("http://0.0.0.0:" + System.getenv("PORT") + "/");
api = new TelegramBotsApi(VertxBotSession.class, webhook);
} else {
api = new TelegramBotsApi();
api = new TelegramBotsApi(VertxBotSession.class);
}
if (isProdEnv) {
api.registerBot(bot.atProductionBotManager());
var setWebhook = new SetWebhook(System.getenv("EXTERNAL_URI"));
api.registerBot(bot.atProductionBotManager(), setWebhook);
} else {
api.registerBot(bot.atDevBotManager());
}
......
......@@ -3,12 +3,12 @@ package page.devnet.telegrambot;
import lombok.Setter;
import lombok.Value;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
import page.devnet.database.repository.CRUDRepository;
import page.devnet.database.repository.UnsubscribeRepository;
import page.devnet.pluginmanager.Plugin;
import page.devnet.telegrambot.util.CommandUtils;
......@@ -28,7 +28,7 @@ import java.util.regex.Pattern;
* @since 14.05.2020
*/
@Slf4j
public class WordLimiterPlugin implements Plugin<Update, List<PartialBotApiMethod>> {
public class WordLimiterPlugin implements Plugin<Update, List<PartialBotApiMethod<?>>> {
private final String nameWordLimiterPlugin = "limitPlug";
......@@ -51,7 +51,7 @@ public class WordLimiterPlugin implements Plugin<Update, List<PartialBotApiMetho
private CommandUtils commandUtils = new CommandUtils();
@Override
public List<PartialBotApiMethod> onEvent(Update event) {
public List<PartialBotApiMethod<?>> onEvent(Update event) {
if (!event.hasMessage() || !event.getMessage().hasText()) {
return Collections.emptyList();
}
......@@ -62,7 +62,7 @@ public class WordLimiterPlugin implements Plugin<Update, List<PartialBotApiMetho
}
Message message = event.getMessage();
if (unsubscribeRepository.find(message.getFrom().getId()).isPresent()) {
if (unsubscribeRepository.find(message.getFrom().getId().intValue()).isPresent()) {
return Collections.emptyList();
}
......@@ -97,18 +97,23 @@ public class WordLimiterPlugin implements Plugin<Update, List<PartialBotApiMetho
}
msg = String.join(", ", formattedUserName, new String(Base64.getDecoder().decode(msg)));
return List.of(new SendMessage(message.getChatId(), msg).enableMarkdown(true));
var chatId = message.getChatId();
return List.of(SendMessage.builder()
.chatId(String.valueOf(chatId))
.text(msg)
.parseMode(ParseMode.MARKDOWN)
.build());
}
private void executeCommand(Message message) {
var command = commandUtils.normalizeCmdMsg(message.getText());
switch (command) {
case "unsubscribe": {
unsubscribeRepository.createOrUpdate(message.getFrom().getId(), message.getFrom().getId());
unsubscribeRepository.createOrUpdate(message.getFrom().getId().intValue(), message.getFrom().getId().intValue());
break;
}
case "subscribe": {
unsubscribeRepository.delete(message.getFrom().getId());
unsubscribeRepository.delete(message.getFrom().getId().intValue());
break;
}
}
......@@ -117,7 +122,7 @@ public class WordLimiterPlugin implements Plugin<Update, List<PartialBotApiMetho
// copy-paste
private String formatUserName(User user) {
String name = user.getUserName();
if (user.getFirstName() != null && !user.getFirstName().isEmpty()) {
if (!user.getFirstName().isEmpty()) {
name = user.getFirstName();
if (user.getLastName() != null && !user.getLastName().isEmpty()) {
......
......@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.methods.send.SendPhoto;
import org.telegram.telegrambots.meta.api.objects.InputFile;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.User;
......@@ -31,7 +32,7 @@ import java.util.Optional;
* @since 19.11.2019
*/
@Slf4j
public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMethod>> {
public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMethod<?>>> {
@Override
public String getPluginId() {
......@@ -52,7 +53,7 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
}
@Override
public List<PartialBotApiMethod> onEvent(Update event) {
public List<PartialBotApiMethod<?>> onEvent(Update event) {
if (!event.hasMessage()) {
return Collections.emptyList();
}
......@@ -62,8 +63,8 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
return executeCommand(event.getMessage());
} catch (IOException e) {
log.error(e.getMessage(), e);
return List.of(new SendMessage(event.getMessage()
.getChatId(), "Sorry, something wrong with send chart: " + e.getMessage()));
var chatId = String.valueOf(event.getMessage().getChatId());
return List.of(new SendMessage(chatId, "Sorry, something wrong with send chart: " + e.getMessage()));
}
}
......@@ -72,7 +73,7 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
}
var message = event.getMessage();
var user = userRepository.find(message.getFrom().getId());
var user = userRepository.find(message.getFrom().getId().intValue());
if (user.isEmpty()) {
user = createUser(message.getFrom());
}
......@@ -83,39 +84,40 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
return Collections.emptyList();
}
private List<PartialBotApiMethod> executeCommand(Message message) throws IOException {
private List<PartialBotApiMethod<?>> executeCommand(Message message) throws IOException {
var text = commandUtils.normalizeCmdMsg(message.getText());
var chatId = String.valueOf(message.getChatId());
switch (text) {
case "statf":
var fromLastDay = ZonedDateTime.now().minusDays(1);
try {
Chart top10UsedWordsFromLastDay = statistics.getTop10UsedWordsFrom(fromLastDay.toInstant());
SendPhoto sendPhoto = wrapToSendPhoto(top10UsedWordsFromLastDay, message.getChatId());
SendPhoto sendPhoto = wrapToSendPhoto(top10UsedWordsFromLastDay, chatId);
return List.of(sendPhoto);
} catch (IllegalArgumentException e) {
return List.of(new SendMessage(message.getChatId(), e.getMessage()).enableMarkdown(true));
return List.of(new SendMessage(chatId, e.getMessage()));
}
case "state":
fromLastDay = ZonedDateTime.now().minusDays(1);
try {
List<Chart> top10WordsFromEachUserFromLastDay = statistics.getTop10UsedWordsFromEachUser(fromLastDay.toInstant());
List<PartialBotApiMethod> result = new ArrayList<>();
List<PartialBotApiMethod<?>> result = new ArrayList<>();
for (Chart chart : top10WordsFromEachUserFromLastDay) {
SendPhoto sendPhoto = wrapToSendPhoto(chart, message.getChatId());
SendPhoto sendPhoto = wrapToSendPhoto(chart, chatId);
result.add(sendPhoto);
}
return result;
} catch (IllegalArgumentException e) {
return List.of(new SendMessage(message.getChatId(), e.getMessage()).enableMarkdown(true));
return List.of(new SendMessage(chatId, e.getMessage()));
}
case "statu":
fromLastDay = ZonedDateTime.now().minusDays(1);
try {
Chart top10WordsFromLastDayByUser = statistics.getWordsCountByUserFrom(fromLastDay.toInstant());
SendPhoto sendPhoto = wrapToSendPhoto(top10WordsFromLastDayByUser, message.getChatId());
SendPhoto sendPhoto = wrapToSendPhoto(top10WordsFromLastDayByUser, chatId);
return List.of(sendPhoto);
} catch (IllegalArgumentException e) {
return List.of(new SendMessage(message.getChatId(), e.getMessage()).enableMarkdown(true));
return List.of(new SendMessage(chatId, e.getMessage()));
}
default:
......@@ -123,7 +125,7 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
}
}
private SendPhoto wrapToSendPhoto(Chart chart, Long chatId) throws IOException {
private SendPhoto wrapToSendPhoto(Chart chart, String chatId) throws IOException {
SendPhoto sendPhoto = new SendPhoto();
sendPhoto.setChatId(chatId);
......@@ -131,7 +133,7 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
try (InputStream in = chart.toInputStream()) {
Files.copy(in, file, StandardCopyOption.REPLACE_EXISTING);
}
sendPhoto.setPhoto(file.toFile());
sendPhoto.setPhoto(new InputFile(file.toFile()));
log.info("Send new chart {} with size: {}bytes", file.toFile().getName(), file.toFile().length());
return sendPhoto;
}
......@@ -143,7 +145,7 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
user.setUserName(tgUser.getUserName());
}
if (tgUser.getFirstName() != null && !tgUser.getFirstName().isEmpty()) {
if (!tgUser.getFirstName().isEmpty()) {
user.setFirstName(tgUser.getFirstName());
}
......@@ -151,6 +153,6 @@ public class WordStatisticPlugin implements Plugin<Update, List<PartialBotApiMet
user.setLastName(tgUser.getLastName());
}
return Optional.of(userRepository.createOrUpdate(tgUser.getId(), user));
return Optional.of(userRepository.createOrUpdate(tgUser.getId().intValue(), user));
}
}
......@@ -2,6 +2,7 @@ package page.devnet.telegrambot.translate;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.meta.api.methods.ParseMode;
import org.telegram.telegrambots.meta.api.methods.PartialBotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.DeleteMessage;
......@@ -22,7 +23,7 @@ import java.util.List;
* @since 23.03.19
*/
@Slf4j
public final class TranslateBotPlugin implements Plugin<Update, List<PartialBotApiMethod>> {
public final class TranslateBotPlugin implements Plugin<Update, List<PartialBotApiMethod<?>>> {
//todo it's not thread safe
private boolean stop = false;
......@@ -47,7 +48,7 @@ public final class TranslateBotPlugin implements Plugin<Update, List<PartialBotA
}
@Override
public List<PartialBotApiMethod> onEvent(Update update) {
public List<PartialBotApiMethod<?>> onEvent(Update update) {
if (!update.hasMessage() || !update.getMessage().hasText()) {
return Collections.emptyList();
}
......@@ -55,7 +56,7 @@ public final class TranslateBotPlugin implements Plugin<Update, List<PartialBotA
return dispatch(update);
}
private List<PartialBotApiMethod> dispatch(Update update) {
private List<PartialBotApiMethod<?>> dispatch(Update update) {
if (update.getMessage().isCommand()) {
return executeCommand(update.getMessage());
}
......@@ -67,7 +68,7 @@ public final class TranslateBotPlugin implements Plugin<Update, List<PartialBotA
return translate(update);
}
private List<PartialBotApiMethod> executeCommand(Message message) {
private List<PartialBotApiMethod<?>> executeCommand(Message message) {
String command = commandUtils.normalizeCmdMsg(message.getText());
switch (command) {
case "stoptrans":
......@@ -80,31 +81,30 @@ public final class TranslateBotPlugin implements Plugin<Update, List<PartialBotA
return Collections.emptyList();
}