From 05dad68c91e441d8e7c6760e76b0dc159c76540b Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Thu, 28 Jan 2021 20:46:30 +0000 Subject: [PATCH] Update version 5.0.1 --- pom.xml | 21 +++++--- src/main/java/org/telegram/Main.java | 22 ++++----- .../org/telegram/commands/HelloCommand.java | 6 +-- .../org/telegram/commands/HelpCommand.java | 7 +-- .../org/telegram/commands/StartCommand.java | 6 +-- .../org/telegram/commands/StopCommand.java | 5 +- .../org/telegram/database/ConectionDB.java | 6 +-- .../telegram/database/DatabaseManager.java | 9 ++-- .../telegram/services/DirectionsService.java | 6 +-- .../org/telegram/services/RaeService.java | 6 +-- .../org/telegram/services/TimerExecutor.java | 11 ++--- .../telegram/services/TransifexService.java | 21 ++++---- .../org/telegram/services/WeatherService.java | 10 ++-- .../updateshandlers/ChannelHandlers.java | 16 +++--- .../updateshandlers/CommandsHandler.java | 20 +++++--- .../updateshandlers/DirectionsHandlers.java | 20 ++++---- .../ElektrollArtFanHandler.java | 8 +-- .../updateshandlers/FilesHandlers.java | 37 +++++++------- .../telegram/updateshandlers/RaeHandlers.java | 13 +++-- .../updateshandlers/TransifexHandlers.java | 14 +++--- .../updateshandlers/WeatherHandlers.java | 49 +++++++++---------- src/main/resources/strings.properties | 2 +- src/main/resources/strings_eo.properties | 2 +- src/main/resources/strings_es.properties | 2 +- src/main/resources/strings_it.properties | 2 +- src/main/resources/strings_nl.properties | 2 +- src/main/resources/strings_pt.properties | 2 +- 27 files changed, 153 insertions(+), 172 deletions(-) diff --git a/pom.xml b/pom.xml index 22e44ed..62d6206 100644 --- a/pom.xml +++ b/pom.xml @@ -11,12 +11,13 @@ UTF-8 UTF-8 - 4.5.9 - 4.4.0.1 - 20180813 - 1.12.1 - 8.0.17 - 2.6 + 4.5.13 + 5.0.1.1 + 20201115 + 1.13.1 + 8.0.23 + 2.8.0 + 1.18.16 @@ -24,12 +25,18 @@ com.fasterxml.jackson.core jackson-annotations - 2.9.9 + 2.12.1 + + org.projectlombok + lombok + ${lombok.version} + provided + org.telegram telegrambots diff --git a/src/main/java/org/telegram/Main.java b/src/main/java/org/telegram/Main.java index 54f41d5..0ea1aa2 100644 --- a/src/main/java/org/telegram/Main.java +++ b/src/main/java/org/telegram/Main.java @@ -1,10 +1,10 @@ package org.telegram; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.telegram.telegrambots.ApiContextInitializer; +import lombok.extern.slf4j.Slf4j; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; +import org.telegram.telegrambots.updatesreceivers.DefaultBotSession; +import org.telegram.telegrambots.updatesreceivers.DefaultWebhook; import org.telegram.updateshandlers.WeatherHandlers; import org.telegram.updateshandlers.WebHookExampleHandlers; @@ -14,12 +14,10 @@ import org.telegram.updateshandlers.WebHookExampleHandlers; * @brief Main class to create all bots * @date 20 of June of 2015 */ +@Slf4j public class Main { - private static final Logger log = LogManager.getLogger(Main.class); - public static void main(String[] args) { try { - ApiContextInitializer.init(); TelegramBotsApi telegramBotsApi = createTelegramBotsApi(); try { // Register long polling bots. They work regardless type of TelegramBotsApi we are creating @@ -47,11 +45,11 @@ public class Main { } else if (!BuildVars.pathToCertificatePublicKey.isEmpty()) { // Filled a path to a pem file ? looks like you're going for the self signed option then, invoke with store and pem file to supply. telegramBotsApi = createSelfSignedTelegramBotsApi(); - telegramBotsApi.registerBot(new WebHookExampleHandlers()); + telegramBotsApi.registerBot(new WebHookExampleHandlers(), null); } else { // Non self signed, make sure you've added private/public and if needed intermediate to your cert-store. telegramBotsApi = createNoSelfSignedTelegramBotsApi(); - telegramBotsApi.registerBot(new WebHookExampleHandlers()); + telegramBotsApi.registerBot(new WebHookExampleHandlers(), null); } return telegramBotsApi; } @@ -60,8 +58,8 @@ public class Main { * @brief Creates a Telegram Bots Api to use Long Polling (getUpdates) bots. * @return TelegramBotsApi to register the bots. */ - private static TelegramBotsApi createLongPollingTelegramBotsApi() { - return new TelegramBotsApi(); + private static TelegramBotsApi createLongPollingTelegramBotsApi() throws TelegramApiException { + return new TelegramBotsApi(DefaultBotSession.class); } /** @@ -72,7 +70,7 @@ public class Main { * @note Don't forget to split the pem bundle (begin/end), use only the public key as input! */ private static TelegramBotsApi createSelfSignedTelegramBotsApi() throws TelegramApiException { - return new TelegramBotsApi(BuildVars.pathToCertificateStore, BuildVars.certificateStorePassword, BuildVars.EXTERNALWEBHOOKURL, BuildVars.INTERNALWEBHOOKURL, BuildVars.pathToCertificatePublicKey); + return new TelegramBotsApi(DefaultBotSession.class, new DefaultWebhook()); } /** @@ -88,6 +86,6 @@ public class Main { * @endcode */ private static TelegramBotsApi createNoSelfSignedTelegramBotsApi() throws TelegramApiException { - return new TelegramBotsApi(BuildVars.pathToCertificateStore, BuildVars.certificateStorePassword, BuildVars.EXTERNALWEBHOOKURL, BuildVars.INTERNALWEBHOOKURL); + return new TelegramBotsApi(DefaultBotSession.class, new DefaultWebhook()); } } diff --git a/src/main/java/org/telegram/commands/HelloCommand.java b/src/main/java/org/telegram/commands/HelloCommand.java index 3006880..7c8909d 100644 --- a/src/main/java/org/telegram/commands/HelloCommand.java +++ b/src/main/java/org/telegram/commands/HelloCommand.java @@ -1,7 +1,6 @@ package org.telegram.commands; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -16,9 +15,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiException; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class HelloCommand extends BotCommand { - private static final Logger log = LogManager.getLogger(HelloCommand.class); - public HelloCommand() { super("hello", "Say hallo to this bot"); } diff --git a/src/main/java/org/telegram/commands/HelpCommand.java b/src/main/java/org/telegram/commands/HelpCommand.java index 8870bc9..1ca888a 100644 --- a/src/main/java/org/telegram/commands/HelpCommand.java +++ b/src/main/java/org/telegram/commands/HelpCommand.java @@ -1,9 +1,7 @@ package org.telegram.commands; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.database.DatabaseManager; -import org.telegram.services.RaeService; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry; @@ -18,9 +16,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiException; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class HelpCommand extends BotCommand { - private static final Logger log = LogManager.getLogger(RaeService.class); - private final ICommandRegistry commandRegistry; public HelpCommand(ICommandRegistry commandRegistry) { diff --git a/src/main/java/org/telegram/commands/StartCommand.java b/src/main/java/org/telegram/commands/StartCommand.java index 123ae81..84946c7 100644 --- a/src/main/java/org/telegram/commands/StartCommand.java +++ b/src/main/java/org/telegram/commands/StartCommand.java @@ -1,7 +1,6 @@ package org.telegram.commands; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -15,9 +14,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiException; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class StartCommand extends BotCommand { - private static final Logger log = LogManager.getLogger(StartCommand.class); - public StartCommand() { super("start", "With this command you can start the Bot"); } diff --git a/src/main/java/org/telegram/commands/StopCommand.java b/src/main/java/org/telegram/commands/StopCommand.java index 177f1dc..6177eda 100644 --- a/src/main/java/org/telegram/commands/StopCommand.java +++ b/src/main/java/org/telegram/commands/StopCommand.java @@ -1,7 +1,6 @@ package org.telegram.commands; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -16,8 +15,8 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiException; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class StopCommand extends BotCommand { - private static final Logger log = LogManager.getLogger(StopCommand.class); /** * Construct diff --git a/src/main/java/org/telegram/database/ConectionDB.java b/src/main/java/org/telegram/database/ConectionDB.java index e662efc..684d125 100644 --- a/src/main/java/org/telegram/database/ConectionDB.java +++ b/src/main/java/org/telegram/database/ConectionDB.java @@ -7,8 +7,7 @@ */ package org.telegram.database; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BuildVars; import java.sql.Connection; @@ -24,9 +23,8 @@ import java.sql.Statement; * @version 2.0 * Connector to database */ +@Slf4j public class ConectionDB { - private static final Logger log = LogManager.getLogger(ConectionDB.class); - private Connection currentConection; public ConectionDB() { diff --git a/src/main/java/org/telegram/database/DatabaseManager.java b/src/main/java/org/telegram/database/DatabaseManager.java index 142590e..6408b8d 100644 --- a/src/main/java/org/telegram/database/DatabaseManager.java +++ b/src/main/java/org/telegram/database/DatabaseManager.java @@ -7,8 +7,7 @@ */ package org.telegram.database; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.structure.WeatherAlert; import java.sql.PreparedStatement; @@ -22,12 +21,10 @@ import java.util.List; /** * @author Ruben Bermudez * @version 2.0 - * @brief Database Manager to perform database operations - * @date 3/12/14 + * Database Manager to perform database operations */ +@Slf4j public class DatabaseManager { - private static final Logger log = LogManager.getLogger(DatabaseManager.class); - private static volatile DatabaseManager instance; private static volatile ConectionDB connetion; diff --git a/src/main/java/org/telegram/services/DirectionsService.java b/src/main/java/org/telegram/services/DirectionsService.java index d25c7f7..5f4e074 100644 --- a/src/main/java/org/telegram/services/DirectionsService.java +++ b/src/main/java/org/telegram/services/DirectionsService.java @@ -1,5 +1,6 @@ package org.telegram.services; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -8,8 +9,6 @@ import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.json.JSONArray; import org.json.JSONObject; import org.jsoup.Jsoup; @@ -27,9 +26,8 @@ import java.util.List; * @brief Weather service * @date 20 of June of 2015 */ +@Slf4j public class DirectionsService { - private static final Logger log = LogManager.getLogger(DirectionsService.class); - private static final String BASEURL = "https://maps.googleapis.com/maps/api/directions/json"; ///< Base url for REST private static final String APIIDEND = "&key=" + BuildVars.DirectionsApiKey; private static final String PARAMS = "&language=@language@&units=metric"; diff --git a/src/main/java/org/telegram/services/RaeService.java b/src/main/java/org/telegram/services/RaeService.java index f77c4ca..e474bbc 100644 --- a/src/main/java/org/telegram/services/RaeService.java +++ b/src/main/java/org/telegram/services/RaeService.java @@ -1,5 +1,6 @@ package org.telegram.services; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -8,8 +9,6 @@ import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -28,9 +27,8 @@ import java.util.Map; * @brief Rae service * @date 20 of June of 2015 */ +@Slf4j public class RaeService { - private static final Logger log = LogManager.getLogger(RaeService.class); - private static final String BASEURL = "http://dle.rae.es/srv/"; ///< Base url for REST private static final String SEARCHEXACTURL = "search?m=30&w="; private static final String SEARCHWORDURL = "search?m=form&w="; diff --git a/src/main/java/org/telegram/services/TimerExecutor.java b/src/main/java/org/telegram/services/TimerExecutor.java index 2295573..571e14c 100644 --- a/src/main/java/org/telegram/services/TimerExecutor.java +++ b/src/main/java/org/telegram/services/TimerExecutor.java @@ -1,7 +1,6 @@ package org.telegram.services; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import java.time.Clock; import java.time.Duration; @@ -15,8 +14,8 @@ import java.util.concurrent.TimeUnit; * @version 2.0 * Execute a task periodically */ +@Slf4j public class TimerExecutor { - private static final Logger log = LogManager.getLogger(TimerExecutor.class); private static volatile TimerExecutor instance; ///< Instance private static final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); ///< Thread to execute operations @@ -63,7 +62,7 @@ public class TimerExecutor { task.reduceTimes(); startExecutionEveryDayAt(task, targetHour, targetMin, targetSec); } catch (Exception e) { - log.fatal("Bot threw an unexpected exception at TimerExecutor", e); + log.error("Bot threw an unexpected exception at TimerExecutor", e); } }; if (task.getTimes() != 0) { @@ -104,9 +103,9 @@ public class TimerExecutor { try { executorService.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException ex) { - log.fatal(ex.getLocalizedMessage(), ex); + log.error(ex.getLocalizedMessage(), ex); } catch (Exception e) { - log.fatal(e.getLocalizedMessage(), "Bot threw an unexpected exception at TimerExecutor", e); + log.error(e.getLocalizedMessage(), "Bot threw an unexpected exception at TimerExecutor", e); } } } diff --git a/src/main/java/org/telegram/services/TransifexService.java b/src/main/java/org/telegram/services/TransifexService.java index 7abe2e6..bb814d5 100644 --- a/src/main/java/org/telegram/services/TransifexService.java +++ b/src/main/java/org/telegram/services/TransifexService.java @@ -1,5 +1,6 @@ package org.telegram.services; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; @@ -7,10 +8,9 @@ import org.apache.http.client.methods.HttpGet; import org.apache.http.conn.ssl.NoopHostnameVerifier; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.telegram.BuildVars; import org.telegram.telegrambots.meta.api.methods.send.SendDocument; +import org.telegram.telegrambots.meta.api.objects.InputFile; import java.io.*; @@ -20,9 +20,8 @@ import java.io.*; * @brief Service that allow transifex files download * @date 21 of June of 2015 */ +@Slf4j public class TransifexService { - private static final Logger log = LogManager.getLogger(TransifexService.class); - private static final String BASEURLAndroid = "http://" + BuildVars.TRANSIFEXUSER + ":" + BuildVars.TRANSIFEXPASSWORD + "@www.transifex.com/api/2/project/telegram/resource/stringsxml-48/translation/@language?file"; ///< Base url for REST private static final String BASEURLiOS = "http://" + BuildVars.TRANSIFEXUSER + ":" + BuildVars.TRANSIFEXPASSWORD + "@www.transifex.com/api/2/project/iphone-1/resource/localizablestrings/translation/@language?file"; ///< Base url for REST private static final String BASEURLOSX = "http://" + BuildVars.TRANSIFEXUSER + ":" + BuildVars.TRANSIFEXPASSWORD + "@www.transifex.com/api/2/project/osx/resource/localizablestrings/translation/@language?file"; ///< Base url for REST @@ -194,7 +193,7 @@ public class TransifexService { localFile.close(); File fileToUpload = new File(fileName); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } catch (FileNotFoundException e) { log.error(e.getLocalizedMessage(), e); } @@ -221,7 +220,7 @@ public class TransifexService { localFile.close(); File fileToUpload = new File(fileName); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } catch (FileNotFoundException e) { log.error(e.getLocalizedMessage(), e); } @@ -249,7 +248,7 @@ public class TransifexService { IOUtils.write(file, output); output.close(); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } catch (IOException e) { log.error(e.getLocalizedMessage(), e); } @@ -276,7 +275,7 @@ public class TransifexService { IOUtils.write(file, output); output.close(); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } catch (IOException e) { log.error(e.getLocalizedMessage(), e); } @@ -304,7 +303,7 @@ public class TransifexService { output.close(); if (fileToUpload.exists()) { sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } } catch (IOException e) { e.printStackTrace(); @@ -333,7 +332,7 @@ public class TransifexService { output.close(); if (fileToUpload.exists()) { sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } } catch (IOException e) { e.printStackTrace(); @@ -362,7 +361,7 @@ public class TransifexService { output.close(); if (fileToUpload.exists()) { sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(fileToUpload)); } } catch (IOException e) { e.printStackTrace(); diff --git a/src/main/java/org/telegram/services/WeatherService.java b/src/main/java/org/telegram/services/WeatherService.java index 61a8340..95f9a4d 100644 --- a/src/main/java/org/telegram/services/WeatherService.java +++ b/src/main/java/org/telegram/services/WeatherService.java @@ -1,5 +1,6 @@ package org.telegram.services; +import lombok.extern.slf4j.Slf4j; import org.apache.http.HttpEntity; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; @@ -8,8 +9,6 @@ import org.apache.http.entity.BufferedHttpEntity; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.util.EntityUtils; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; import org.json.JSONObject; import org.telegram.BuildVars; import org.telegram.database.DatabaseManager; @@ -27,9 +26,8 @@ import java.time.format.DateTimeFormatter; * @brief Weather service * @date 20 of June of 2015 */ +@Slf4j public class WeatherService { - private static final Logger log = LogManager.getLogger(WeatherService.class); - public static final String METRICSYSTEM = "metric"; public static final String IMPERIALSYSTEM = "imperial"; @@ -157,7 +155,7 @@ public class WeatherService { * @return userHash to be send to use * @note Forecast for the following 3 days */ - public String fetchWeatherForecastByLocation(Float longitude, Float latitude, Integer userId, String language, String units) { + public String fetchWeatherForecastByLocation(Double longitude, Double latitude, Integer userId, String language, String units) { String cityFound; String responseToUser; try { @@ -237,7 +235,7 @@ public class WeatherService { * @return userHash to be send to use * @note Forecast for the following 3 days */ - public String fetchWeatherCurrentByLocation(Float longitude, Float latitude, Integer userId, String language, String units) { + public String fetchWeatherCurrentByLocation(Double longitude, Double latitude, Integer userId, String language, String units) { String cityFound; String responseToUser; try { diff --git a/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java b/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java index e237b2d..026ce5f 100644 --- a/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java @@ -1,7 +1,6 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -21,9 +20,8 @@ import java.util.concurrent.ConcurrentHashMap; * This is a use case that will send a message to a channel if it is added as an admin to it. * @date 24 of June of 2015 */ +@Slf4j public class ChannelHandlers extends TelegramLongPollingBot { - private static final Logger log = LogManager.getLogger(ChannelHandlers.class); - private static final int WAITINGCHANNEL = 1; private static final String HELP_TEXT = "Send me the channel username where you added me as admin."; @@ -43,7 +41,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { try { handleIncomingMessage(message); } catch (InvalidObjectException e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { @@ -115,7 +113,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { private void sendErrorMessage(Message message, String errorText) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyToMessageId(message.getMessageId()); sendMessage.setText(String.format(ERROR_MESSAGE_TEXT, message.getText().trim(), errorText.replace("\"", "\\\""))); @@ -131,7 +129,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { private static SendMessage getWrongUsernameMessage(Message message) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyToMessageId(message.getMessageId()); ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard(); @@ -146,7 +144,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { private static SendMessage getMessageToChannelSent(Message message) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyToMessageId(message.getMessageId()); sendMessage.setText(AFTER_CHANNEL_TEXT); @@ -156,7 +154,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { private void sendHelpMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(chatId); + sendMessage.setChatId(Long.toString(chatId)); sendMessage.setReplyToMessageId(messageId); if (replyKeyboardMarkup != null) { sendMessage.setReplyMarkup(replyKeyboardMarkup); diff --git a/src/main/java/org/telegram/updateshandlers/CommandsHandler.java b/src/main/java/org/telegram/updateshandlers/CommandsHandler.java index 59565d9..9efa9cc 100644 --- a/src/main/java/org/telegram/updateshandlers/CommandsHandler.java +++ b/src/main/java/org/telegram/updateshandlers/CommandsHandler.java @@ -1,7 +1,6 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.commands.HelloCommand; import org.telegram.commands.HelpCommand; @@ -20,15 +19,17 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiException; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class CommandsHandler extends TelegramLongPollingCommandBot { - private static final Logger log = LogManager.getLogger(CommandsHandler.class); + private final String botUsername; + /** * Constructor. */ public CommandsHandler(String botUsername) { - super(botUsername); - + super(); + this.botUsername = botUsername; register(new HelloCommand()); register(new StartCommand()); register(new StopCommand()); @@ -37,7 +38,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot { registerDefaultAction((absSender, message) -> { SendMessage commandUnknownMessage = new SendMessage(); - commandUnknownMessage.setChatId(message.getChatId()); + commandUnknownMessage.setChatId(Long.toString(message.getChatId())); commandUnknownMessage.setText("The command '" + message.getText() + "' is not known by this bot. Here comes some help " + Emoji.AMBULANCE); try { absSender.execute(commandUnknownMessage); @@ -48,6 +49,11 @@ public class CommandsHandler extends TelegramLongPollingCommandBot { }); } + @Override + public String getBotUsername() { + return botUsername; + } + @Override public void processNonCommandUpdate(Update update) { @@ -60,7 +66,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot { if (message.hasText()) { SendMessage echoMessage = new SendMessage(); - echoMessage.setChatId(message.getChatId()); + echoMessage.setChatId(Long.toString(message.getChatId())); echoMessage.setText("Hey heres your message:\n" + message.getText()); try { diff --git a/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java b/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java index 5888494..29560f9 100644 --- a/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java @@ -1,7 +1,6 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -31,9 +30,8 @@ import java.util.concurrent.ConcurrentLinkedQueue; * @brief Handler for updates to Directions Bot * @date 24 of June of 2015 */ +@Slf4j public class DirectionsHandlers extends TelegramLongPollingBot { - private static final Logger log = LogManager.getLogger(DirectionsHandlers.class); - private static final int WATING_ORIGIN_STATUS = 0; private static final int WATING_DESTINY_STATUS = 1; private final ConcurrentLinkedQueue languageMessages = new ConcurrentLinkedQueue<>(); @@ -89,7 +87,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } else { SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("youNeedReplyDirections", language)); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); try { execute(sendMessageRequest); } catch (TelegramApiException e) { @@ -107,7 +105,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { String destiny = message.getText(); List directions = DirectionsService.getInstance().getDirections(origin, destiny, language); SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove(); replyKeyboardRemove.setSelective(true); sendMessageRequest.setReplyMarkup(replyKeyboardRemove); @@ -140,7 +138,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { private void onOriginReceived(Message message, String language) { SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); sendMessageRequest.setReplyToMessageId(message.getMessageId()); ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard(); forceReplyKeyboard.setSelective(true); @@ -177,7 +175,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { LocalisationService.getString("helpDirections", language), Commands.startDirectionCommand); sendMessageRequest.setText(helpDirectionsFormated); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); try { execute(sendMessageRequest); } catch (TelegramApiException e) { @@ -187,7 +185,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { private void onStartdirectionsCommand(Message message, String language) { SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); sendMessageRequest.setReplyToMessageId(message.getMessageId()); ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard(); forceReplyKeyboard.setSelective(true); @@ -220,7 +218,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException { SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup(); List languages = LocalisationService.getSupportedLanguages(); List commands = new ArrayList<>(); @@ -246,7 +244,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { private void onLanguageSelected(Message message) throws InvalidObjectException { String[] parts = message.getText().split("-->", 2); SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) { DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim()); sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim())); diff --git a/src/main/java/org/telegram/updateshandlers/ElektrollArtFanHandler.java b/src/main/java/org/telegram/updateshandlers/ElektrollArtFanHandler.java index 7d5af90..0ae5b24 100644 --- a/src/main/java/org/telegram/updateshandlers/ElektrollArtFanHandler.java +++ b/src/main/java/org/telegram/updateshandlers/ElektrollArtFanHandler.java @@ -198,15 +198,15 @@ public class ElektrollArtFanHandler extends TelegramLongPollingBot { List> rowsInline = new ArrayList<>(); List rowInline = new ArrayList<>(); - rowInline.add(new InlineKeyboardButton().setText(this.urls.get(index)[2]).setCallbackData("gallery:text:" + index)); + rowInline.add(InlineKeyboardButton.builder().text(this.urls.get(index)[2]).callbackData("gallery:text:" + index).build()); List rowInline2 = new ArrayList<>(); - rowInline2.add(new InlineKeyboardButton().setText(BACK).setCallbackData("gallery:back:" + index)); - rowInline2.add(new InlineKeyboardButton().setText(NEXT).setCallbackData("gallery:next:" + index)); + rowInline2.add(InlineKeyboardButton.builder().text(BACK).callbackData("gallery:back:" + index).build()); + rowInline2.add(InlineKeyboardButton.builder().text(NEXT).callbackData("gallery:next:" + index).build()); List rowInline3 = new ArrayList<>(); - rowInline3.add(new InlineKeyboardButton().setText("Link").setUrl(this.urls.get(index)[0])); + rowInline3.add(InlineKeyboardButton.builder().text("Link").url(this.urls.get(index)[0]).build()); rowsInline.add(rowInline); diff --git a/src/main/java/org/telegram/updateshandlers/FilesHandlers.java b/src/main/java/org/telegram/updateshandlers/FilesHandlers.java index e7ca0cd..ed21f77 100644 --- a/src/main/java/org/telegram/updateshandlers/FilesHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/FilesHandlers.java @@ -1,7 +1,6 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -10,6 +9,7 @@ import org.telegram.services.LocalisationService; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.send.SendDocument; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; +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.replykeyboard.ReplyKeyboardMarkup; @@ -28,12 +28,11 @@ import java.util.concurrent.ConcurrentLinkedQueue; /** * @author Ruben Bermudez * @version 1.0 - * @brief Handler for updates to Files Bot + * Handler for updates to Files Bot * This bot is an example for the use of sendMessage asynchronously - * @date 24 of June of 2015 */ +@Slf4j public class FilesHandlers extends TelegramLongPollingBot { - private static final Logger log = LogManager.getLogger(FilesHandlers.class); private static final int INITIAL_UPLOAD_STATUS = 0; private static final int DELETE_UPLOADED_STATUS = 1; @@ -51,7 +50,7 @@ public class FilesHandlers extends TelegramLongPollingBot { try { SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText("Since this bot was used to spread copyrighted content, we had to disable its functionality until further announcement.\n\nSorry for the troubles, just blame those that used the bot for illegal purposes."); - sendMessageRequest.setChatId(update.getMessage().getChatId()); + sendMessageRequest.setChatId(Long.toString(update.getMessage().getChatId())); execute(sendMessageRequest); //handleFileUpdate(update); @@ -62,7 +61,7 @@ public class FilesHandlers extends TelegramLongPollingBot { } } } catch (Exception e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { @@ -114,7 +113,7 @@ public class FilesHandlers extends TelegramLongPollingBot { SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("fileUploaded", language) + LocalisationService.getString("uploadedFileURL", language) + message.getDocument().getFileId()); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); execute(sendMessageRequest); } } @@ -132,7 +131,7 @@ public class FilesHandlers extends TelegramLongPollingBot { } else { sendMessageRequest.setText(LocalisationService.getString("noFiles", language)); } - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); sendMessageRequest.setReplyMarkup(new ReplyKeyboardRemove()); execute(sendMessageRequest); } @@ -150,7 +149,7 @@ public class FilesHandlers extends TelegramLongPollingBot { DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), DELETE_UPLOADED_STATUS); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("deleteUploadedFile", language)); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); HashMap files = DatabaseManager.getInstance().getFilesByUser(message.getFrom().getId()); ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup(); if (files.size() > 0) { @@ -178,7 +177,7 @@ public class FilesHandlers extends TelegramLongPollingBot { } else { sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language)); } - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); execute(sendMessageRequest); DatabaseManager.getInstance().deleteUserForFile(message.getFrom().getId()); @@ -189,7 +188,7 @@ public class FilesHandlers extends TelegramLongPollingBot { DatabaseManager.getInstance().deleteUserForFile(message.getFrom().getId()); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("processFinished", language)); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); execute(sendMessageRequest); } @@ -197,7 +196,7 @@ public class FilesHandlers extends TelegramLongPollingBot { DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), INITIAL_UPLOAD_STATUS); SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("sendFileToUpload", language)); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); execute(sendMessageRequest); } @@ -208,27 +207,27 @@ public class FilesHandlers extends TelegramLongPollingBot { Commands.startCommand, Commands.uploadCommand, Commands.deleteCommand, Commands.listCommand); sendMessageRequest.setText(formatedString); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); execute(sendMessageRequest); } private void onStartWithParameters(Message message, String language, String part) throws InvalidObjectException, TelegramApiException { if (DatabaseManager.getInstance().doesFileExists(part.trim())) { SendDocument sendDocumentRequest = new SendDocument(); - sendDocumentRequest.setDocument(part.trim()); - sendDocumentRequest.setChatId(message.getChatId()); + sendDocumentRequest.setDocument(new InputFile(part.trim())); + sendDocumentRequest.setChatId(Long.toString(message.getChatId())); execute(sendDocumentRequest); } else { SendMessage sendMessageRequest = new SendMessage(); sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language)); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); execute(sendMessageRequest); } } private void onSetLanguageCommand(Message message, String language) throws InvalidObjectException, TelegramApiException { SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup(); List languages = LocalisationService.getSupportedLanguages(); List commands = new ArrayList<>(); @@ -250,7 +249,7 @@ public class FilesHandlers extends TelegramLongPollingBot { private void onLanguageReceived(Message message) throws InvalidObjectException, TelegramApiException { String[] parts = message.getText().split(Emoji.LEFT_RIGHT_ARROW.toString(), 2); SendMessage sendMessageRequest = new SendMessage(); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) { DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim()); sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim())); diff --git a/src/main/java/org/telegram/updateshandlers/RaeHandlers.java b/src/main/java/org/telegram/updateshandlers/RaeHandlers.java index 17383d8..9c91e52 100644 --- a/src/main/java/org/telegram/updateshandlers/RaeHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/RaeHandlers.java @@ -1,11 +1,11 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.services.RaeService; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.AnswerInlineQuery; +import org.telegram.telegrambots.meta.api.methods.ParseMode; 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; @@ -24,9 +24,8 @@ import java.util.List; * @brief Handler for inline queries in Raebot * @date 24 of June of 2015 */ +@Slf4j public class RaeHandlers extends TelegramLongPollingBot { - private static final Logger log = LogManager.getLogger(RaeHandlers.class); - private static final Integer CACHETIME = 86400; private final RaeService raeService = new RaeService(); private static final String THUMBNAILBLUE = "https://lh5.ggpht.com/-kSFHGvQkFivERzyCNgKPIECtIOELfPNWAQdXqQ7uqv2xztxqll4bVibI0oHJYAuAas=w300"; @@ -108,8 +107,8 @@ public class RaeHandlers extends TelegramLongPollingBot { for (int i = 0; i < raeResults.size(); i++) { RaeService.RaeResult raeResult = raeResults.get(i); InputTextMessageContent messageContent = new InputTextMessageContent(); - messageContent.disableWebPagePreview(); - messageContent.enableMarkdown(true); + messageContent.setDisableWebPagePreview(true); + messageContent.setParseMode(ParseMode.MARKDOWN); messageContent.setMessageText(raeResult.getDefinition()); InlineQueryResultArticle article = new InlineQueryResultArticle(); article.setInputMessageContent(messageContent); @@ -130,7 +129,7 @@ public class RaeHandlers extends TelegramLongPollingBot { */ private static SendMessage getHelpMessage(Message message) { SendMessage sendMessage = new SendMessage(); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.enableMarkdown(true); sendMessage.setText(helpMessage); return sendMessage; diff --git a/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java b/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java index 318ea72..b265142 100644 --- a/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java @@ -1,7 +1,6 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.BuildVars; import org.telegram.Commands; @@ -27,9 +26,8 @@ import java.util.List; * @brief Handler for updates to Transifex Bot * @date 24 of June of 2015 */ +@Slf4j public class TransifexHandlers extends TelegramLongPollingBot { - private static final Logger log = LogManager.getLogger(TransifexHandlers.class); - @Override public String getBotToken() { return BotConfig.TRANSIFEX_TOKEN; @@ -88,7 +86,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { Commands.transifexTDesktop, Commands.transifexOSX, Commands.transifexWP, Commands.transifexAndroidSupportCommand); sendMessageRequest.setText(helpFormated); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); try { execute(sendMessageRequest); } catch (TelegramApiException e) { @@ -97,7 +95,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { } if (sendDocument != null) { - sendDocument.setChatId(message.getChatId()); + sendDocument.setChatId(Long.toString(message.getChatId())); try { execute(sendDocument); } catch (TelegramApiException e) { @@ -113,7 +111,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { Commands.transifexTDesktop, Commands.transifexOSX, Commands.transifexWP, Commands.transifexAndroidSupportCommand); sendMessageRequest.setText(helpFormated); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); try { execute(sendMessageRequest); } catch (TelegramApiException e) { @@ -125,7 +123,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { private void sendMovedToMessage(Message message) throws InvalidObjectException, TelegramApiException { String language = DatabaseManager.getInstance().getUserLanguage(message.getFrom().getId()); SendMessage answer = new SendMessage(); - answer.setChatId(message.getChatId()); + answer.setChatId(Long.toString(message.getChatId())); answer.setReplyToMessageId(message.getMessageId()); answer.setText(LocalisationService.getString("movedToLangBot", language)); InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup(); diff --git a/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java b/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java index 7a398be..48faeb6 100644 --- a/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java @@ -1,7 +1,6 @@ package org.telegram.updateshandlers; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -29,8 +28,8 @@ import java.util.stream.Collectors; * @brief Handler for updates to Weather Bot * @date 24 of June of 2015 */ +@Slf4j public class WeatherHandlers extends TelegramLongPollingBot { - private static final Logger log = LogManager.getLogger(WeatherHandlers.class); private static final int STARTSTATE = 0; private static final int MAINMENU = 1; private static final int CURRENTWEATHER = 2; @@ -98,7 +97,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { try { Thread.currentThread().wait(35); } catch (InterruptedException e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } } String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId()); @@ -116,7 +115,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { DatabaseManager.getInstance().deleteAlertsForUser(weatherAlert.getUserId()); } } catch (Exception e) { - log.fatal(e.getLocalizedMessage(), e); + log.error(e.getLocalizedMessage(), e); } } } @@ -244,7 +243,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyMarkup(getAlertsKeyboard(language)); sendMessage.setText(LocalisationService.getString("alertDeleted", language)); @@ -256,7 +255,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyMarkup(getAlertsKeyboard(language)); sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language)); @@ -270,7 +269,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { if (message.getText().equals(getCancelCommand(language))) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyToMessageId(message.getMessageId()); sendMessage.setReplyMarkup(getAlertsKeyboard(language)); sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language)); @@ -293,7 +292,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { sendMessageRequest.setReplyMarkup(getAlertsKeyboard(language)); sendMessageRequest.setReplyToMessageId(message.getMessageId()); sendMessageRequest.setText(getChooseNewAlertSetMessage(message.getText(), language)); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); DatabaseManager.getInstance().insertWeatherState(userId, message.getChatId(), ALERT); return sendMessageRequest; @@ -329,7 +328,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { ReplyKeyboardMarkup replyKeyboardMarkup = getSettingsKeyboard(language); sendMessage.setReplyMarkup(replyKeyboardMarkup); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setText(getSettingsMessage(language)); DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), SETTINGS); @@ -340,7 +339,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyToMessageId(message.getMessageId()); sendMessage.setReplyMarkup(getAlertsKeyboard(language)); sendMessage.setText(getAlertListMessage(message.getFrom().getId(), language)); @@ -353,7 +352,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); ReplyKeyboardMarkup replyKeyboardMarkup = getAlertsListKeyboard(message.getFrom().getId(), language); if (replyKeyboardMarkup != null) { @@ -373,7 +372,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyMarkup(getRecentsKeyboard(message.getFrom().getId(), language, false)); sendMessage.setText(LocalisationService.getString("chooseNewAlertCity", language)); sendMessage.setReplyToMessageId(message.getMessageId()); @@ -410,7 +409,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { sendMessage.enableMarkdown(true); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyMarkup(getAlertsKeyboard(language)); sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language)); @@ -423,7 +422,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { sendMessage.enableMarkdown(true); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyMarkup(getUnitsKeyboard(language)); sendMessage.setText(getUnitsMessage(message.getFrom().getId(), language)); @@ -436,7 +435,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { sendMessage.enableMarkdown(true); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setReplyMarkup(getLanguagesKeyboard(language)); sendMessage.setText(getLanguageMessage(language)); @@ -473,7 +472,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { ReplyKeyboardMarkup replyKeyboardMarkup = getSettingsKeyboard(language); sendMessage.setReplyMarkup(replyKeyboardMarkup); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setText(getSettingsMessage(language)); DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), SETTINGS); @@ -531,7 +530,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { ReplyKeyboardMarkup replyKeyboardMarkup = getSettingsKeyboard(language); sendMessage.setReplyMarkup(replyKeyboardMarkup); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setText(getSettingsMessage(language)); DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), SETTINGS); @@ -800,7 +799,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { ReplyKeyboardMarkup replyKeyboardMarkup = getSettingsKeyboard(language); sendMessage.setReplyMarkup(replyKeyboardMarkup); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); sendMessage.setText(getSettingsMessage(language)); DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), SETTINGS); @@ -814,7 +813,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { ReplyKeyboardMarkup replyKeyboardMarkup = getRecentsKeyboard(message.getFrom().getId(), language); sendMessage.setReplyMarkup(replyKeyboardMarkup); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); if (replyKeyboardMarkup.getKeyboard().size() > 3) { sendMessage.setText(LocalisationService.getString("onForecastCommandFromHistory", language)); } else { @@ -832,7 +831,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { ReplyKeyboardMarkup replyKeyboardMarkup = getRecentsKeyboard(message.getFrom().getId(), language); sendMessage.setReplyMarkup(replyKeyboardMarkup); sendMessage.setReplyToMessageId(message.getMessageId()); - sendMessage.setChatId(message.getChatId()); + sendMessage.setChatId(Long.toString(message.getChatId())); if (replyKeyboardMarkup.getKeyboard().size() > 3) { sendMessage.setText(LocalisationService.getString("onCurrentCommandFromHistory", language)); } else { @@ -1167,7 +1166,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { private static SendMessage sendHelpMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup, String language) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(chatId); + sendMessage.setChatId(Long.toString(chatId)); sendMessage.setReplyToMessageId(messageId); if (replyKeyboardMarkup != null) { sendMessage.setReplyMarkup(replyKeyboardMarkup); @@ -1179,7 +1178,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { private static SendMessage sendRateMessage(Long chatId, Integer messageId, ReplyKeyboardMarkup replyKeyboardMarkup, String language) { SendMessage sendMessage = new SendMessage(); sendMessage.enableMarkdown(true); - sendMessage.setChatId(chatId); + sendMessage.setChatId(Long.toString(chatId)); sendMessage.setReplyToMessageId(messageId); if (replyKeyboardMarkup != null) { sendMessage.setReplyMarkup(replyKeyboardMarkup); @@ -1202,7 +1201,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language)); sendMessageRequest.setReplyToMessageId(message.getMessageId()); sendMessageRequest.setText(weather); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), MAINMENU); return sendMessageRequest; @@ -1231,7 +1230,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language)); sendMessageRequest.setReplyToMessageId(message.getMessageId()); sendMessageRequest.setText(weather); - sendMessageRequest.setChatId(message.getChatId()); + sendMessageRequest.setChatId(Long.toString(message.getChatId())); DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), MAINMENU); return sendMessageRequest; diff --git a/src/main/resources/strings.properties b/src/main/resources/strings.properties index 6771431..82b754b 100644 --- a/src/main/resources/strings.properties +++ b/src/main/resources/strings.properties @@ -83,4 +83,4 @@ noAlertList=I couldn't find any alert for you. alertDeleted=The selected alert has been deleted. cityNotFound= City not found errorFetchingWeather= We're sorry, there was an error fetching the weather. -rateMeMessage=If you like this bot, please rate it using [@storebot](https://telegram.me/storebot?start=weatherbot) \ No newline at end of file +rateMeMessage=If you like this bot, please rate it using [@findbot](https://telegram.me/findbot?start=weatherbot) \ No newline at end of file diff --git a/src/main/resources/strings_eo.properties b/src/main/resources/strings_eo.properties index f1428ca..6e183b9 100644 --- a/src/main/resources/strings_eo.properties +++ b/src/main/resources/strings_eo.properties @@ -72,4 +72,4 @@ noAlertList=Mi ne povas trovi ajnan averton por vi. alertDeleted=La elektita averto estas forigita. cityNotFound= Urbo ne estas trovita errorFetchingWeather= Mi beda\u016dras, eraro okazis dum ricevado de la vetero. -rateMeMessage=Se vi \u015datas \u0109i tiun roboton, bonvolu klasifikadi \u011din \u0109e https\://telegram.me/storebot?start\=weatherbot +rateMeMessage=Se vi \u015datas \u0109i tiun roboton, bonvolu klasifikadi \u011din \u0109e https\://telegram.me/findbot?start\=weatherbot diff --git a/src/main/resources/strings_es.properties b/src/main/resources/strings_es.properties index dfd90c3..c500ce8 100644 --- a/src/main/resources/strings_es.properties +++ b/src/main/resources/strings_es.properties @@ -72,4 +72,4 @@ noAlertList=No pude encontrar ninguna alerta. alertDeleted=La alerta seleccionada fue eliminada. cityNotFound= Ciudad no encontrada errorFetchingWeather= Lo sentimos, hubo un error solicitando el tiempo. -rateMeMessage=Si te gusta este bot, por favor, puntúalo en https\://telegram.me/storebot?start\=weatherbot +rateMeMessage=Si te gusta este bot, por favor, puntúalo en https\://telegram.me/findbot?start\=weatherbot diff --git a/src/main/resources/strings_it.properties b/src/main/resources/strings_it.properties index 0449046..bc64915 100644 --- a/src/main/resources/strings_it.properties +++ b/src/main/resources/strings_it.properties @@ -72,4 +72,4 @@ noAlertList=Non sono riuscito a trovare alcun allarme per te. alertDeleted=L'allarme selezionato è stato eliminato. cityNotFound= Città non trovata errorFetchingWeather= Siamo spiacenti, c'è stato un errore nel caricare le previsioni. -rateMeMessage=Se ti piace questo bot, per favore votalo su https\://telegram.me/storebot?start\=weatherbot +rateMeMessage=Se ti piace questo bot, per favore votalo su https\://telegram.me/findbot?start\=weatherbot diff --git a/src/main/resources/strings_nl.properties b/src/main/resources/strings_nl.properties index c7e517b..a869fe3 100644 --- a/src/main/resources/strings_nl.properties +++ b/src/main/resources/strings_nl.properties @@ -72,4 +72,4 @@ noAlertList=Geen waarschuwingen gevonden. alertDeleted=De geselecteerde waarschuwing is verwijderd. cityNotFound= Stad niet gevonden. errorFetchingWeather= Sorry, er is iets misgegaan bij het ophalen van het weer. -rateMeMessage=Als je deze bot leuk vindt dan kan je hem hier beoordelen https\://telegram.me/storebot?start\=weatherbot +rateMeMessage=Als je deze bot leuk vindt dan kan je hem hier beoordelen https\://telegram.me/findbot?start\=weatherbot diff --git a/src/main/resources/strings_pt.properties b/src/main/resources/strings_pt.properties index 09efd99..92e9679 100644 --- a/src/main/resources/strings_pt.properties +++ b/src/main/resources/strings_pt.properties @@ -72,4 +72,4 @@ noAlertList=Eu não consegui encontrar nenhum alerta para você. alertDeleted=O alerta selecionado foi apagado. cityNotFound= Cidade não encontrada errorFetchingWeather= Desculpe, houve um erro ao obter o clima. -rateMeMessage=Se você gosta deste bot, por favor nos avalie em https\://telegram.me/storebot?start\=weatherbot +rateMeMessage=Se você gosta deste bot, por favor nos avalie em https\://telegram.me/findbot?start\=weatherbot