From 2ca9bc3e1fb6c3451bc049e8fe3c780dc21eefc6 Mon Sep 17 00:00:00 2001 From: Ruben Bermudez Date: Wed, 13 Nov 2019 22:10:30 +0000 Subject: [PATCH 1/3] Update version 4.4.0.1 --- pom.xml | 22 ++++++++--- src/main/java/org/telegram/Commands.java | 2 + src/main/java/org/telegram/Main.java | 39 +++++++------------ .../org/telegram/commands/HelloCommand.java | 8 ++-- .../org/telegram/commands/HelpCommand.java | 9 +++-- .../org/telegram/commands/StartCommand.java | 8 ++-- .../org/telegram/commands/StopCommand.java | 8 ++-- .../org/telegram/database/ConectionDB.java | 20 +++++++--- .../telegram/database/DatabaseManager.java | 9 +++-- .../telegram/services/DirectionsService.java | 7 ++-- .../org/telegram/services/RaeService.java | 11 +++--- .../org/telegram/services/TimerExecutor.java | 13 ++++--- .../telegram/services/TransifexService.java | 35 +++++++++-------- .../org/telegram/services/WeatherService.java | 29 +++++++------- .../updateshandlers/ChannelHandlers.java | 15 +++---- .../updateshandlers/CommandsHandler.java | 10 ++--- .../updateshandlers/DirectionsHandlers.java | 21 +++++----- .../updateshandlers/FilesHandlers.java | 16 +++++--- .../telegram/updateshandlers/RaeHandlers.java | 13 ++++--- .../updateshandlers/TransifexHandlers.java | 13 ++++--- .../updateshandlers/WeatherHandlers.java | 14 +++---- 21 files changed, 174 insertions(+), 148 deletions(-) diff --git a/pom.xml b/pom.xml index 3f9f473..22e44ed 100644 --- a/pom.xml +++ b/pom.xml @@ -11,14 +11,24 @@ UTF-8 UTF-8 - 4.5.3 - 4.0.1 - 20160810 - 1.10.2 - 6.0.6 - 2.5 + 4.5.9 + 4.4.0.1 + 20180813 + 1.12.1 + 8.0.17 + 2.6 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.9.9 + + + + org.telegram diff --git a/src/main/java/org/telegram/Commands.java b/src/main/java/org/telegram/Commands.java index ded6096..870c148 100644 --- a/src/main/java/org/telegram/Commands.java +++ b/src/main/java/org/telegram/Commands.java @@ -26,6 +26,8 @@ public class Commands { public static final String help = commandInitChar + "help"; /// Upload command public static final String uploadCommand = commandInitChar + "upload"; + /// Report command + public static final String reportCommand = commandInitChar + "report"; /// Start command public static final String startCommand = commandInitChar + "start"; /// Cancel command diff --git a/src/main/java/org/telegram/Main.java b/src/main/java/org/telegram/Main.java index 7fe44cf..54f41d5 100644 --- a/src/main/java/org/telegram/Main.java +++ b/src/main/java/org/telegram/Main.java @@ -1,15 +1,12 @@ package org.telegram; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.telegrambots.ApiContextInitializer; import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; -import org.telegram.telegrambots.meta.logging.BotsFileHandler; -import org.telegram.updateshandlers.*; - -import java.io.IOException; -import java.util.logging.ConsoleHandler; -import java.util.logging.Level; +import org.telegram.updateshandlers.WeatherHandlers; +import org.telegram.updateshandlers.WebHookExampleHandlers; /** * @author Ruben Bermudez @@ -18,35 +15,27 @@ import java.util.logging.Level; * @date 20 of June of 2015 */ public class Main { - private static final String LOGTAG = "MAIN"; + private static final Logger log = LogManager.getLogger(Main.class); public static void main(String[] args) { - BotLogger.setLevel(Level.ALL); - BotLogger.registerLogger(new ConsoleHandler()); - try { - BotLogger.registerLogger(new BotsFileHandler()); - } catch (IOException e) { - BotLogger.severe(LOGTAG, e); - } - try { ApiContextInitializer.init(); TelegramBotsApi telegramBotsApi = createTelegramBotsApi(); try { // Register long polling bots. They work regardless type of TelegramBotsApi we are creating - telegramBotsApi.registerBot(new ChannelHandlers()); - telegramBotsApi.registerBot(new DirectionsHandlers()); - telegramBotsApi.registerBot(new RaeHandlers()); + // telegramBotsApi.registerBot(new ChannelHandlers()); + // telegramBotsApi.registerBot(new DirectionsHandlers()); + // telegramBotsApi.registerBot(new RaeHandlers()); telegramBotsApi.registerBot(new WeatherHandlers()); - telegramBotsApi.registerBot(new TransifexHandlers()); - telegramBotsApi.registerBot(new FilesHandlers()); - telegramBotsApi.registerBot(new CommandsHandler(BotConfig.COMMANDS_USER)); - telegramBotsApi.registerBot(new ElektrollArtFanHandler()); + // telegramBotsApi.registerBot(new TransifexHandlers()); + // telegramBotsApi.registerBot(new FilesHandlers()); + // telegramBotsApi.registerBot(new CommandsHandler(BotConfig.COMMANDS_USER)); + // telegramBotsApi.registerBot(new ElektrollArtFanHandler()); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } diff --git a/src/main/java/org/telegram/commands/HelloCommand.java b/src/main/java/org/telegram/commands/HelloCommand.java index 508a678..3006880 100644 --- a/src/main/java/org/telegram/commands/HelloCommand.java +++ b/src/main/java/org/telegram/commands/HelloCommand.java @@ -1,5 +1,7 @@ package org.telegram.commands; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -7,7 +9,6 @@ import org.telegram.telegrambots.meta.api.objects.Chat; import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; /** * This command simply replies with a hello to the users command and @@ -16,8 +17,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger; * @author Timo Schulz (Mit0x2) */ public class HelloCommand extends BotCommand { - - private static final String LOGTAG = "HELLOCOMMAND"; + private static final Logger log = LogManager.getLogger(HelloCommand.class); public HelloCommand() { super("hello", "Say hallo to this bot"); @@ -49,7 +49,7 @@ public class HelloCommand extends BotCommand { try { absSender.execute(answer); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } \ No newline at end of file diff --git a/src/main/java/org/telegram/commands/HelpCommand.java b/src/main/java/org/telegram/commands/HelpCommand.java index eb99f77..8870bc9 100644 --- a/src/main/java/org/telegram/commands/HelpCommand.java +++ b/src/main/java/org/telegram/commands/HelpCommand.java @@ -1,6 +1,9 @@ package org.telegram.commands; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; 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; @@ -9,7 +12,6 @@ import org.telegram.telegrambots.meta.api.objects.Chat; import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; /** * This command helps the user to find the command they need @@ -17,8 +19,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger; * @author Timo Schulz (Mit0x2) */ public class HelpCommand extends BotCommand { - - private static final String LOGTAG = "HELPCOMMAND"; + private static final Logger log = LogManager.getLogger(RaeService.class); private final ICommandRegistry commandRegistry; @@ -49,7 +50,7 @@ public class HelpCommand extends BotCommand { try { absSender.execute(helpMessage); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/org/telegram/commands/StartCommand.java b/src/main/java/org/telegram/commands/StartCommand.java index 450d96f..123ae81 100644 --- a/src/main/java/org/telegram/commands/StartCommand.java +++ b/src/main/java/org/telegram/commands/StartCommand.java @@ -1,5 +1,7 @@ package org.telegram.commands; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -7,7 +9,6 @@ import org.telegram.telegrambots.meta.api.objects.Chat; import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; /** * This commands starts the conversation with the bot @@ -15,8 +16,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger; * @author Timo Schulz (Mit0x2) */ public class StartCommand extends BotCommand { - - public static final String LOGTAG = "STARTCOMMAND"; + private static final Logger log = LogManager.getLogger(StartCommand.class); public StartCommand() { super("start", "With this command you can start the Bot"); @@ -45,7 +45,7 @@ public class StartCommand extends BotCommand { try { absSender.execute(answer); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } \ No newline at end of file diff --git a/src/main/java/org/telegram/commands/StopCommand.java b/src/main/java/org/telegram/commands/StopCommand.java index 9079825..177f1dc 100644 --- a/src/main/java/org/telegram/commands/StopCommand.java +++ b/src/main/java/org/telegram/commands/StopCommand.java @@ -1,5 +1,7 @@ package org.telegram.commands; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -7,7 +9,6 @@ import org.telegram.telegrambots.meta.api.objects.Chat; import org.telegram.telegrambots.meta.api.objects.User; import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; /** * This commands stops the conversation with the bot. @@ -16,8 +17,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger; * @author Timo Schulz (Mit0x2) */ public class StopCommand extends BotCommand { - - public static final String LOGTAG = "STOPCOMMAND"; + private static final Logger log = LogManager.getLogger(StopCommand.class); /** * Construct @@ -41,7 +41,7 @@ public class StopCommand extends BotCommand { try { absSender.execute(answer); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/org/telegram/database/ConectionDB.java b/src/main/java/org/telegram/database/ConectionDB.java index c429628..e662efc 100644 --- a/src/main/java/org/telegram/database/ConectionDB.java +++ b/src/main/java/org/telegram/database/ConectionDB.java @@ -7,10 +7,17 @@ */ package org.telegram.database; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BuildVars; -import org.telegram.telegrambots.meta.logging.BotLogger; -import java.sql.*; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.DriverManager; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; /** * @author Ruben Bermudez @@ -18,7 +25,8 @@ import java.sql.*; * Connector to database */ public class ConectionDB { - private static final String LOGTAG = "CONNECTIONDB"; + private static final Logger log = LogManager.getLogger(ConectionDB.class); + private Connection currentConection; public ConectionDB() { @@ -31,7 +39,7 @@ public class ConectionDB { Class.forName(BuildVars.controllerDB).newInstance(); connection = DriverManager.getConnection(BuildVars.linkDB, BuildVars.userDB, BuildVars.password); } catch (SQLException | ClassNotFoundException | IllegalAccessException | InstantiationException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return connection; @@ -41,7 +49,7 @@ public class ConectionDB { try { this.currentConection.close(); } catch (SQLException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -80,7 +88,7 @@ public class ConectionDB { } } } catch (SQLException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return max; } diff --git a/src/main/java/org/telegram/database/DatabaseManager.java b/src/main/java/org/telegram/database/DatabaseManager.java index 2c56f9e..142590e 100644 --- a/src/main/java/org/telegram/database/DatabaseManager.java +++ b/src/main/java/org/telegram/database/DatabaseManager.java @@ -7,8 +7,9 @@ */ package org.telegram.database; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.structure.WeatherAlert; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -25,7 +26,7 @@ import java.util.List; * @date 3/12/14 */ public class DatabaseManager { - private static final String LOGTAG = "DATABASEMANAGER"; + private static final Logger log = LogManager.getLogger(DatabaseManager.class); private static volatile DatabaseManager instance; private static volatile ConectionDB connetion; @@ -36,7 +37,7 @@ public class DatabaseManager { private DatabaseManager() { connetion = new ConectionDB(); final int currentVersion = connetion.checkVersion(); - BotLogger.info(LOGTAG, "Current db version: " + currentVersion); + log.info("Current db version: " + currentVersion); if (currentVersion < CreationStrings.version) { recreateTable(currentVersion); } @@ -94,7 +95,7 @@ public class DatabaseManager { } connetion.commitTransaction(); } catch (SQLException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } diff --git a/src/main/java/org/telegram/services/DirectionsService.java b/src/main/java/org/telegram/services/DirectionsService.java index 6e67f30..d25c7f7 100644 --- a/src/main/java/org/telegram/services/DirectionsService.java +++ b/src/main/java/org/telegram/services/DirectionsService.java @@ -8,11 +8,12 @@ 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; import org.telegram.BuildVars; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -27,7 +28,7 @@ import java.util.List; * @date 20 of June of 2015 */ public class DirectionsService { - private static final String LOGTAG = "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; @@ -98,7 +99,7 @@ public class DirectionsService { responseToUser.add(LocalisationService.getString("directionsNotFound", language)); } } catch (Exception e) { - BotLogger.warn(LOGTAG, e); + log.warn(e.getLocalizedMessage(), e); responseToUser.add(LocalisationService.getString("errorFetchingDirections", language)); } return responseToUser; diff --git a/src/main/java/org/telegram/services/RaeService.java b/src/main/java/org/telegram/services/RaeService.java index 1d22ba4..f77c4ca 100644 --- a/src/main/java/org/telegram/services/RaeService.java +++ b/src/main/java/org/telegram/services/RaeService.java @@ -8,11 +8,12 @@ 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; import org.jsoup.select.Elements; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.IOException; import java.net.URLEncoder; @@ -28,7 +29,7 @@ import java.util.Map; * @date 20 of June of 2015 */ public class RaeService { - private static final String LOGTAG = "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="; @@ -66,7 +67,7 @@ public class RaeService { results = getResultsFromExactMatch(elements, query, articleId); } } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return results; @@ -103,7 +104,7 @@ public class RaeService { } } } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return results; @@ -137,7 +138,7 @@ public class RaeService { results = getResultsFromExactMatch(elements, word, articleId); } } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return results; diff --git a/src/main/java/org/telegram/services/TimerExecutor.java b/src/main/java/org/telegram/services/TimerExecutor.java index 4b3ce73..2295573 100644 --- a/src/main/java/org/telegram/services/TimerExecutor.java +++ b/src/main/java/org/telegram/services/TimerExecutor.java @@ -1,6 +1,7 @@ package org.telegram.services; -import org.telegram.telegrambots.meta.logging.BotLogger; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import java.time.Clock; import java.time.Duration; @@ -15,7 +16,7 @@ import java.util.concurrent.TimeUnit; * Execute a task periodically */ public class TimerExecutor { - private static final String LOGTAG = "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 @@ -55,14 +56,14 @@ public class TimerExecutor { * @param targetSec Second to execute it */ public void startExecutionEveryDayAt(CustomTimerTask task, int targetHour, int targetMin, int targetSec) { - BotLogger.warn(LOGTAG, "Posting new task" + task.getTaskName()); + log.warn("Posting new task" + task.getTaskName()); final Runnable taskWrapper = () -> { try { task.execute(); task.reduceTimes(); startExecutionEveryDayAt(task, targetHour, targetMin, targetSec); } catch (Exception e) { - BotLogger.severe(LOGTAG, "Bot threw an unexpected exception at TimerExecutor", e); + log.fatal("Bot threw an unexpected exception at TimerExecutor", e); } }; if (task.getTimes() != 0) { @@ -103,9 +104,9 @@ public class TimerExecutor { try { executorService.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException ex) { - BotLogger.severe(LOGTAG, ex); + log.fatal(ex.getLocalizedMessage(), ex); } catch (Exception e) { - BotLogger.severe(LOGTAG, "Bot threw an unexpected exception at TimerExecutor", e); + log.fatal(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 7d834a3..7abe2e6 100644 --- a/src/main/java/org/telegram/services/TransifexService.java +++ b/src/main/java/org/telegram/services/TransifexService.java @@ -7,9 +7,10 @@ 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.logging.BotLogger; import java.io.*; @@ -20,7 +21,7 @@ import java.io.*; * @date 21 of June of 2015 */ public class TransifexService { - private static final String LOGTAG = "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 @@ -77,7 +78,7 @@ public class TransifexService { result = responseString; } } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -90,7 +91,7 @@ public class TransifexService { HttpResponse response = client.execute(request); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -103,7 +104,7 @@ public class TransifexService { HttpResponse response = client.execute(request); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -116,7 +117,7 @@ public class TransifexService { HttpResponse response = client.execute(request); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -129,7 +130,7 @@ public class TransifexService { HttpResponse response = client.execute(request); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-8"), "UTF-8"); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -142,7 +143,7 @@ public class TransifexService { HttpResponse response = client.execute(request); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -155,7 +156,7 @@ public class TransifexService { HttpResponse response = client.execute(request); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -195,11 +196,11 @@ public class TransifexService { sendDocument = new SendDocument(); sendDocument.setDocument(fileToUpload); } catch (FileNotFoundException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return sendDocument; } @@ -222,11 +223,11 @@ public class TransifexService { sendDocument = new SendDocument(); sendDocument.setDocument(fileToUpload); } catch (FileNotFoundException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return sendDocument; } @@ -250,11 +251,11 @@ public class TransifexService { sendDocument = new SendDocument(); sendDocument.setDocument(fileToUpload); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return sendDocument; } @@ -277,11 +278,11 @@ public class TransifexService { sendDocument = new SendDocument(); sendDocument.setDocument(fileToUpload); } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return sendDocument; } diff --git a/src/main/java/org/telegram/services/WeatherService.java b/src/main/java/org/telegram/services/WeatherService.java index b7df256..61a8340 100644 --- a/src/main/java/org/telegram/services/WeatherService.java +++ b/src/main/java/org/telegram/services/WeatherService.java @@ -8,10 +8,11 @@ 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; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; @@ -27,7 +28,7 @@ import java.time.format.DateTimeFormatter; * @date 20 of June of 2015 */ public class WeatherService { - private static final String LOGTAG = "WEATHERSERVICE"; + private static final Logger log = LogManager.getLogger(WeatherService.class); public static final String METRICSYSTEM = "metric"; public static final String IMPERIALSYSTEM = "imperial"; @@ -91,7 +92,7 @@ public class WeatherService { String responseString = EntityUtils.toString(buf, "UTF-8"); JSONObject jsonObject = new JSONObject(responseString); - BotLogger.info(LOGTAG, jsonObject.toString()); + log.info(jsonObject.toString()); if (jsonObject.getInt("cod") == 200) { cityFound = jsonObject.getJSONObject("city").getString("name") + " (" + jsonObject.getJSONObject("city").getString("country") + ")"; @@ -99,11 +100,11 @@ public class WeatherService { responseToUser = String.format(LocalisationService.getString("weatherAlert", language), cityFound, convertListOfForecastToString(jsonObject, language, units, false)); } else { - BotLogger.warn(LOGTAG, jsonObject.toString()); + log.warn(jsonObject.toString()); responseToUser = LocalisationService.getString("cityNotFound", language); } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); responseToUser = LocalisationService.getString("errorFetchingWeather", language); } return responseToUser; @@ -132,7 +133,7 @@ public class WeatherService { String responseString = EntityUtils.toString(buf, "UTF-8"); JSONObject jsonObject = new JSONObject(responseString); - BotLogger.info(LOGTAG, jsonObject.toString()); + log.info(jsonObject.toString()); if (jsonObject.getInt("cod") == 200) { cityFound = jsonObject.getJSONObject("city").getString("name") + " (" + jsonObject.getJSONObject("city").getString("country") + ")"; @@ -140,11 +141,11 @@ public class WeatherService { responseToUser = String.format(LocalisationService.getString("weatherForcast", language), cityFound, convertListOfForecastToString(jsonObject, language, units, true)); } else { - BotLogger.warn(LOGTAG, jsonObject.toString()); + log.warn(jsonObject.toString()); responseToUser = LocalisationService.getString("cityNotFound", language); } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); responseToUser = LocalisationService.getString("errorFetchingWeather", language); } return responseToUser; @@ -179,11 +180,11 @@ public class WeatherService { responseToUser = String.format(LocalisationService.getString("weatherForcast", language), cityFound, convertListOfForecastToString(jsonObject, language, units, true)); } else { - BotLogger.warn(LOGTAG, jsonObject.toString()); + log.warn(jsonObject.toString()); responseToUser = LocalisationService.getString("cityNotFound", language); } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); responseToUser = LocalisationService.getString("errorFetchingWeather", language); } return responseToUser; @@ -220,11 +221,11 @@ public class WeatherService { responseToUser = String.format(LocalisationService.getString("weatherCurrent", language), cityFound, convertCurrentWeatherToString(jsonObject, language, units, emoji)); } else { - BotLogger.warn(LOGTAG, jsonObject.toString()); + log.warn(jsonObject.toString()); responseToUser = LocalisationService.getString("cityNotFound", language); } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); responseToUser = LocalisationService.getString("errorFetchingWeather", language); } return responseToUser; @@ -259,11 +260,11 @@ public class WeatherService { responseToUser = String.format(LocalisationService.getString("weatherCurrent", language), cityFound, convertCurrentWeatherToString(jsonObject, language, units, null)); } else { - BotLogger.warn(LOGTAG, jsonObject.toString()); + log.warn(jsonObject.toString()); responseToUser = LocalisationService.getString("cityNotFound", language); } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); responseToUser = LocalisationService.getString("errorFetchingWeather", language); } return responseToUser; diff --git a/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java b/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java index e1d5611..e237b2d 100644 --- a/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -8,7 +10,6 @@ import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ForceReplyKeyboard; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.InvalidObjectException; import java.util.concurrent.ConcurrentHashMap; @@ -21,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap; * @date 24 of June of 2015 */ public class ChannelHandlers extends TelegramLongPollingBot { - private static final String LOGTAG = "CHANNELHANDLERS"; + private static final Logger log = LogManager.getLogger(ChannelHandlers.class); private static final int WAITINGCHANNEL = 1; @@ -42,11 +43,11 @@ public class ChannelHandlers extends TelegramLongPollingBot { try { handleIncomingMessage(message); } catch (InvalidObjectException e) { - BotLogger.severe(LOGTAG, e); + log.fatal(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -92,7 +93,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { } } } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -123,7 +124,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { try { execute(sendMessage); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -165,7 +166,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { try { execute(sendMessage); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/org/telegram/updateshandlers/CommandsHandler.java b/src/main/java/org/telegram/updateshandlers/CommandsHandler.java index 584772f..59565d9 100644 --- a/src/main/java/org/telegram/updateshandlers/CommandsHandler.java +++ b/src/main/java/org/telegram/updateshandlers/CommandsHandler.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.commands.HelloCommand; import org.telegram.commands.HelpCommand; @@ -12,7 +14,6 @@ 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.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; /** * This handler mainly works with commands to demonstrate the Commands feature of the API @@ -21,8 +22,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger; */ public class CommandsHandler extends TelegramLongPollingCommandBot { - public static final String LOGTAG = "COMMANDSHANDLER"; - + private static final Logger log = LogManager.getLogger(CommandsHandler.class); /** * Constructor. */ @@ -42,7 +42,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot { try { absSender.execute(commandUnknownMessage); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } helpCommand.execute(absSender, message.getFrom(), message.getChat(), new String[] {}); }); @@ -66,7 +66,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot { try { execute(echoMessage); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java b/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java index 63cd6dc..5888494 100644 --- a/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -16,7 +18,6 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardRem import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.meta.logging.BotLogger; import org.telegram.telegrambots.meta.updateshandlers.SentCallback; import java.io.InvalidObjectException; @@ -31,7 +32,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; * @date 24 of June of 2015 */ public class DirectionsHandlers extends TelegramLongPollingBot { - private static final String LOGTAG = "DIRECTIONSHANDLERS"; + 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; @@ -48,7 +49,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { try { handleDirections(update); } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -92,7 +93,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { try { execute(sendMessageRequest); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } @@ -131,7 +132,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } }); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -165,7 +166,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } }); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -180,7 +181,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { try { execute(sendMessageRequest); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -212,7 +213,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } }); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -238,7 +239,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { execute(sendMessageRequest); languageMessages.add(message.getFrom().getId()); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -260,7 +261,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { execute(sendMessageRequest); languageMessages.remove(message.getFrom().getId()); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/org/telegram/updateshandlers/FilesHandlers.java b/src/main/java/org/telegram/updateshandlers/FilesHandlers.java index e164916..e7ca0cd 100644 --- a/src/main/java/org/telegram/updateshandlers/FilesHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/FilesHandlers.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -15,7 +17,6 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardRem import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.InvalidObjectException; import java.util.ArrayList; @@ -32,7 +33,7 @@ import java.util.concurrent.ConcurrentLinkedQueue; * @date 24 of June of 2015 */ public class FilesHandlers extends TelegramLongPollingBot { - private static final String LOGTAG = "FILESHANDLERS"; + 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; @@ -48,7 +49,12 @@ public class FilesHandlers extends TelegramLongPollingBot { try { if (update.hasMessage()) { try { - handleFileUpdate(update); + 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()); + execute(sendMessageRequest); + + //handleFileUpdate(update); } catch (TelegramApiRequestException e) { if (e.getApiResponse().contains("Bot was blocked by the user")) { if (update.getMessage().getFrom() != null) { @@ -56,11 +62,11 @@ public class FilesHandlers extends TelegramLongPollingBot { } } } catch (Exception e) { - BotLogger.severe(LOGTAG, e); + log.fatal(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } diff --git a/src/main/java/org/telegram/updateshandlers/RaeHandlers.java b/src/main/java/org/telegram/updateshandlers/RaeHandlers.java index 822af0c..17383d8 100644 --- a/src/main/java/org/telegram/updateshandlers/RaeHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/RaeHandlers.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.services.RaeService; import org.telegram.telegrambots.bots.TelegramLongPollingBot; @@ -12,7 +14,6 @@ import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessageconten import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult; import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResultArticle; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.util.ArrayList; import java.util.List; @@ -24,7 +25,7 @@ import java.util.List; * @date 24 of June of 2015 */ public class RaeHandlers extends TelegramLongPollingBot { - private static final String LOGTAG = "RAEHANDLERS"; + private static final Logger log = LogManager.getLogger(RaeHandlers.class); private static final Integer CACHETIME = 86400; private final RaeService raeService = new RaeService(); @@ -50,11 +51,11 @@ public class RaeHandlers extends TelegramLongPollingBot { try { execute(getHelpMessage(update.getMessage())); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -69,7 +70,7 @@ public class RaeHandlers extends TelegramLongPollingBot { */ private void handleIncomingInlineQuery(InlineQuery inlineQuery) { String query = inlineQuery.getQuery(); - BotLogger.debug(LOGTAG, "Searching: " + query); + log.debug("Searching: " + query); try { if (!query.isEmpty()) { List results = raeService.getResults(query); @@ -78,7 +79,7 @@ public class RaeHandlers extends TelegramLongPollingBot { execute(converteResultsToResponse(inlineQuery, new ArrayList<>())); } } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } diff --git a/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java b/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java index 1b6d263..318ea72 100644 --- a/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.BuildVars; import org.telegram.Commands; @@ -14,7 +16,6 @@ import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup; import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.io.InvalidObjectException; import java.util.ArrayList; @@ -27,7 +28,7 @@ import java.util.List; * @date 24 of June of 2015 */ public class TransifexHandlers extends TelegramLongPollingBot { - private static final String LOGTAG = "TRANSIFEXHANDLERS"; + private static final Logger log = LogManager.getLogger(TransifexHandlers.class); @Override public String getBotToken() { @@ -39,7 +40,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { try { handleUpdate(update); } catch (Throwable e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -91,7 +92,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { try { execute(sendMessageRequest); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -100,7 +101,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { try { execute(sendDocument); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } else if (parts[0].startsWith(Commands.help) || @@ -116,7 +117,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { try { execute(sendMessageRequest); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } diff --git a/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java b/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java index 38eb781..7a398be 100644 --- a/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java @@ -1,5 +1,7 @@ package org.telegram.updateshandlers; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -16,7 +18,6 @@ import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardRem import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow; import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.util.ArrayList; import java.util.List; @@ -29,8 +30,7 @@ import java.util.stream.Collectors; * @date 24 of June of 2015 */ public class WeatherHandlers extends TelegramLongPollingBot { - private static final String LOGTAG = "WEATHERHANDLERS"; - + 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; @@ -66,7 +66,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -98,7 +98,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { try { Thread.currentThread().wait(35); } catch (InterruptedException e) { - BotLogger.severe(LOGTAG, e); + log.fatal(e.getLocalizedMessage(), e); } } String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId()); @@ -111,12 +111,12 @@ public class WeatherHandlers extends TelegramLongPollingBot { try { execute(sendMessage); } catch (TelegramApiRequestException e) { - BotLogger.warn(LOGTAG, e); + log.warn(e.getLocalizedMessage(), e); if (e.getApiResponse().contains("Can't access the chat") || e.getApiResponse().contains("Bot was blocked by the user")) { DatabaseManager.getInstance().deleteAlertsForUser(weatherAlert.getUserId()); } } catch (Exception e) { - BotLogger.severe(LOGTAG, e); + log.fatal(e.getLocalizedMessage(), e); } } } From 05dad68c91e441d8e7c6760e76b0dc159c76540b Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Thu, 28 Jan 2021 20:46:30 +0000 Subject: [PATCH 2/3] 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 From 5559a515acc664991af0f3e69124520d87b759ea Mon Sep 17 00:00:00 2001 From: Rubenlagus Date: Thu, 28 Jan 2021 21:33:39 +0000 Subject: [PATCH 3/3] Update version 5.0.1 --- pom.xml | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pom.xml b/pom.xml index 62d6206..6233e8a 100644 --- a/pom.xml +++ b/pom.xml @@ -163,24 +163,6 @@ - - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - - - enforce - - enforce - - - - - - - - -