diff --git a/pom.xml b/pom.xml index 3f9f473..6233e8a 100644 --- a/pom.xml +++ b/pom.xml @@ -11,15 +11,32 @@ UTF-8 UTF-8 - 4.5.3 - 4.0.1 - 20160810 - 1.10.2 - 6.0.6 - 2.5 + 4.5.13 + 5.0.1.1 + 20201115 + 1.13.1 + 8.0.23 + 2.8.0 + 1.18.16 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.12.1 + + + + + + org.projectlombok + lombok + ${lombok.version} + provided + org.telegram telegrambots @@ -146,24 +163,6 @@ - - org.apache.maven.plugins - maven-enforcer-plugin - 1.4.1 - - - enforce - - enforce - - - - - - - - - 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..0ea1aa2 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.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.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.telegrambots.updatesreceivers.DefaultBotSession; +import org.telegram.telegrambots.updatesreceivers.DefaultWebhook; +import org.telegram.updateshandlers.WeatherHandlers; +import org.telegram.updateshandlers.WebHookExampleHandlers; /** * @author Ruben Bermudez @@ -17,36 +14,26 @@ import java.util.logging.Level; * @brief Main class to create all bots * @date 20 of June of 2015 */ +@Slf4j public class Main { - private static final String LOGTAG = "MAIN"; - 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); } } @@ -58,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; } @@ -71,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); } /** @@ -83,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()); } /** @@ -99,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 508a678..7c8909d 100644 --- a/src/main/java/org/telegram/commands/HelloCommand.java +++ b/src/main/java/org/telegram/commands/HelloCommand.java @@ -1,5 +1,6 @@ package org.telegram.commands; +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; @@ -7,7 +8,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 @@ -15,10 +15,8 @@ import org.telegram.telegrambots.meta.logging.BotLogger; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class HelloCommand extends BotCommand { - - private static final String LOGTAG = "HELLOCOMMAND"; - public HelloCommand() { super("hello", "Say hallo to this bot"); } @@ -49,7 +47,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..1ca888a 100644 --- a/src/main/java/org/telegram/commands/HelpCommand.java +++ b/src/main/java/org/telegram/commands/HelpCommand.java @@ -1,5 +1,6 @@ package org.telegram.commands; +import lombok.extern.slf4j.Slf4j; import org.telegram.database.DatabaseManager; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand; @@ -9,17 +10,14 @@ 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 * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class HelpCommand extends BotCommand { - - private static final String LOGTAG = "HELPCOMMAND"; - private final ICommandRegistry commandRegistry; public HelpCommand(ICommandRegistry commandRegistry) { @@ -49,7 +47,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..84946c7 100644 --- a/src/main/java/org/telegram/commands/StartCommand.java +++ b/src/main/java/org/telegram/commands/StartCommand.java @@ -1,5 +1,6 @@ package org.telegram.commands; +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; @@ -7,17 +8,14 @@ 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 * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class StartCommand extends BotCommand { - - public static final String LOGTAG = "STARTCOMMAND"; - public StartCommand() { super("start", "With this command you can start the Bot"); } @@ -45,7 +43,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..6177eda 100644 --- a/src/main/java/org/telegram/commands/StopCommand.java +++ b/src/main/java/org/telegram/commands/StopCommand.java @@ -1,5 +1,6 @@ package org.telegram.commands; +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; @@ -7,7 +8,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. @@ -15,10 +15,9 @@ import org.telegram.telegrambots.meta.logging.BotLogger; * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class StopCommand extends BotCommand { - public static final String LOGTAG = "STOPCOMMAND"; - /** * Construct */ @@ -41,7 +40,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..684d125 100644 --- a/src/main/java/org/telegram/database/ConectionDB.java +++ b/src/main/java/org/telegram/database/ConectionDB.java @@ -7,18 +7,24 @@ */ package org.telegram.database; +import lombok.extern.slf4j.Slf4j; 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 * @version 2.0 * Connector to database */ +@Slf4j public class ConectionDB { - private static final String LOGTAG = "CONNECTIONDB"; private Connection currentConection; public ConectionDB() { @@ -31,7 +37,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 +47,7 @@ public class ConectionDB { try { this.currentConection.close(); } catch (SQLException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -80,7 +86,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 1600f84..b2a5058 100644 --- a/src/main/java/org/telegram/database/DatabaseManager.java +++ b/src/main/java/org/telegram/database/DatabaseManager.java @@ -7,8 +7,8 @@ */ package org.telegram.database; +import lombok.extern.slf4j.Slf4j; import org.telegram.structure.WeatherAlert; -import org.telegram.telegrambots.meta.logging.BotLogger; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -21,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 String LOGTAG = "DATABASEMANAGER"; - private static volatile DatabaseManager instance; private static volatile ConectionDB connetion; @@ -36,7 +34,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 +92,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..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; @@ -12,7 +13,6 @@ 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; @@ -26,9 +26,8 @@ import java.util.List; * @brief Weather service * @date 20 of June of 2015 */ +@Slf4j public class DirectionsService { - private static final String LOGTAG = "DIRECTIONSSERVICE"; - 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"; @@ -98,7 +97,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..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; @@ -12,7 +13,6 @@ 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; @@ -27,9 +27,8 @@ import java.util.Map; * @brief Rae service * @date 20 of June of 2015 */ +@Slf4j public class RaeService { - private static final String LOGTAG = "RAESERVICE"; - 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="; @@ -66,7 +65,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 +102,7 @@ public class RaeService { } } } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return results; @@ -137,7 +136,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..571e14c 100644 --- a/src/main/java/org/telegram/services/TimerExecutor.java +++ b/src/main/java/org/telegram/services/TimerExecutor.java @@ -1,6 +1,6 @@ package org.telegram.services; -import org.telegram.telegrambots.meta.logging.BotLogger; +import lombok.extern.slf4j.Slf4j; import java.time.Clock; import java.time.Duration; @@ -14,8 +14,8 @@ import java.util.concurrent.TimeUnit; * @version 2.0 * Execute a task periodically */ +@Slf4j public class TimerExecutor { - private static final String LOGTAG = "TIMEREXECUTOR"; private static volatile TimerExecutor instance; ///< Instance private static final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); ///< Thread to execute operations @@ -55,14 +55,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.error("Bot threw an unexpected exception at TimerExecutor", e); } }; if (task.getTimes() != 0) { @@ -103,9 +103,9 @@ public class TimerExecutor { try { executorService.awaitTermination(1, TimeUnit.DAYS); } catch (InterruptedException ex) { - BotLogger.severe(LOGTAG, ex); + log.error(ex.getLocalizedMessage(), ex); } catch (Exception e) { - BotLogger.severe(LOGTAG, "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 7d834a3..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; @@ -9,7 +10,7 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.telegram.BuildVars; import org.telegram.telegrambots.meta.api.methods.send.SendDocument; -import org.telegram.telegrambots.meta.logging.BotLogger; +import org.telegram.telegrambots.meta.api.objects.InputFile; import java.io.*; @@ -19,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 String LOGTAG = "TRANSIFEXSERVICE"; - 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 @@ -77,7 +77,7 @@ public class TransifexService { result = responseString; } } catch (IOException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } return result; } @@ -90,7 +90,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 +103,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 +116,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 +129,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 +142,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 +155,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; } @@ -193,13 +193,13 @@ public class TransifexService { localFile.close(); File fileToUpload = new File(fileName); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(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; } @@ -220,13 +220,13 @@ public class TransifexService { localFile.close(); File fileToUpload = new File(fileName); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(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; } @@ -248,13 +248,13 @@ public class TransifexService { IOUtils.write(file, output); output.close(); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(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; } @@ -275,13 +275,13 @@ public class TransifexService { IOUtils.write(file, output); output.close(); sendDocument = new SendDocument(); - sendDocument.setDocument(fileToUpload); + sendDocument.setDocument(new InputFile(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; } @@ -303,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(); @@ -332,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(); @@ -361,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 b7df256..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; @@ -11,7 +12,6 @@ import org.apache.http.util.EntityUtils; 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; @@ -26,9 +26,8 @@ import java.time.format.DateTimeFormatter; * @brief Weather service * @date 20 of June of 2015 */ +@Slf4j public class WeatherService { - private static final String LOGTAG = "WEATHERSERVICE"; - public static final String METRICSYSTEM = "metric"; public static final String IMPERIALSYSTEM = "imperial"; @@ -91,7 +90,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 +98,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 +131,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 +139,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; @@ -156,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 { @@ -179,11 +178,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 +219,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; @@ -236,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 { @@ -259,11 +258,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..026ce5f 100644 --- a/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/ChannelHandlers.java @@ -1,5 +1,6 @@ package org.telegram.updateshandlers; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.meta.api.methods.send.SendMessage; @@ -8,7 +9,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; @@ -20,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 String LOGTAG = "CHANNELHANDLERS"; - private static final int WAITINGCHANNEL = 1; private static final String HELP_TEXT = "Send me the channel username where you added me as admin."; @@ -42,11 +41,11 @@ public class ChannelHandlers extends TelegramLongPollingBot { try { handleIncomingMessage(message); } catch (InvalidObjectException e) { - BotLogger.severe(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -92,7 +91,7 @@ public class ChannelHandlers extends TelegramLongPollingBot { } } } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -114,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("\"", "\\\""))); @@ -123,14 +122,14 @@ public class ChannelHandlers extends TelegramLongPollingBot { try { execute(sendMessage); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } 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(); @@ -145,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); @@ -155,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); @@ -165,7 +164,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..9efa9cc 100644 --- a/src/main/java/org/telegram/updateshandlers/CommandsHandler.java +++ b/src/main/java/org/telegram/updateshandlers/CommandsHandler.java @@ -1,5 +1,6 @@ package org.telegram.updateshandlers; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.commands.HelloCommand; import org.telegram.commands.HelpCommand; @@ -12,23 +13,23 @@ 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 * * @author Timo Schulz (Mit0x2) */ +@Slf4j public class CommandsHandler extends TelegramLongPollingCommandBot { - public static final String LOGTAG = "COMMANDSHANDLER"; + 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,17 +38,22 @@ 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); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } helpCommand.execute(absSender, message.getFrom(), message.getChat(), new String[] {}); }); } + @Override + public String getBotUsername() { + return botUsername; + } + @Override public void processNonCommandUpdate(Update update) { @@ -60,13 +66,13 @@ 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 { 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..29560f9 100644 --- a/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java @@ -1,5 +1,6 @@ package org.telegram.updateshandlers; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -16,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 org.telegram.telegrambots.meta.updateshandlers.SentCallback; import java.io.InvalidObjectException; @@ -30,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 String LOGTAG = "DIRECTIONSHANDLERS"; - private static final int WATING_ORIGIN_STATUS = 0; private static final int WATING_DESTINY_STATUS = 1; private final ConcurrentLinkedQueue languageMessages = new ConcurrentLinkedQueue<>(); @@ -48,7 +47,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { try { handleDirections(update); } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -88,11 +87,11 @@ 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) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } @@ -106,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); @@ -131,7 +130,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } }); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -139,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); @@ -165,7 +164,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } }); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -176,17 +175,17 @@ 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) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } 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); @@ -212,14 +211,14 @@ public class DirectionsHandlers extends TelegramLongPollingBot { } }); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } 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<>(); @@ -238,14 +237,14 @@ public class DirectionsHandlers extends TelegramLongPollingBot { execute(sendMessageRequest); languageMessages.add(message.getFrom().getId()); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } 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())); @@ -260,7 +259,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/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 e164916..ed21f77 100644 --- a/src/main/java/org/telegram/updateshandlers/FilesHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/FilesHandlers.java @@ -1,5 +1,6 @@ package org.telegram.updateshandlers; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -8,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; @@ -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; @@ -27,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 String LOGTAG = "FILESHANDLERS"; private static final int INITIAL_UPLOAD_STATUS = 0; private static final int DELETE_UPLOADED_STATUS = 1; @@ -48,7 +48,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(Long.toString(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 +61,11 @@ public class FilesHandlers extends TelegramLongPollingBot { } } } catch (Exception e) { - BotLogger.severe(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -108,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); } } @@ -126,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); } @@ -144,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) { @@ -172,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()); @@ -183,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); } @@ -191,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); } @@ -202,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<>(); @@ -244,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 822af0c..9c91e52 100644 --- a/src/main/java/org/telegram/updateshandlers/RaeHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/RaeHandlers.java @@ -1,9 +1,11 @@ package org.telegram.updateshandlers; +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; @@ -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; @@ -23,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 String LOGTAG = "RAEHANDLERS"; - private static final Integer CACHETIME = 86400; private final RaeService raeService = new RaeService(); private static final String THUMBNAILBLUE = "https://lh5.ggpht.com/-kSFHGvQkFivERzyCNgKPIECtIOELfPNWAQdXqQ7uqv2xztxqll4bVibI0oHJYAuAas=w300"; @@ -50,11 +50,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 +69,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 +78,7 @@ public class RaeHandlers extends TelegramLongPollingBot { execute(converteResultsToResponse(inlineQuery, new ArrayList<>())); } } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -107,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); @@ -129,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 1b6d263..b265142 100644 --- a/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/TransifexHandlers.java @@ -1,5 +1,6 @@ package org.telegram.updateshandlers; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.BuildVars; import org.telegram.Commands; @@ -14,7 +15,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; @@ -26,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 String LOGTAG = "TRANSIFEXHANDLERS"; - @Override public String getBotToken() { return BotConfig.TRANSIFEX_TOKEN; @@ -39,7 +38,7 @@ public class TransifexHandlers extends TelegramLongPollingBot { try { handleUpdate(update); } catch (Throwable e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -87,20 +86,20 @@ 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) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } if (sendDocument != null) { - sendDocument.setChatId(message.getChatId()); + sendDocument.setChatId(Long.toString(message.getChatId())); try { execute(sendDocument); } catch (TelegramApiException e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } else if (parts[0].startsWith(Commands.help) || @@ -112,11 +111,11 @@ 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) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } } @@ -124,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 38eb781..48faeb6 100644 --- a/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java +++ b/src/main/java/org/telegram/updateshandlers/WeatherHandlers.java @@ -1,5 +1,6 @@ package org.telegram.updateshandlers; +import lombok.extern.slf4j.Slf4j; import org.telegram.BotConfig; import org.telegram.Commands; import org.telegram.database.DatabaseManager; @@ -16,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.util.ArrayList; import java.util.List; @@ -28,9 +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 String LOGTAG = "WEATHERHANDLERS"; - private static final int STARTSTATE = 0; private static final int MAINMENU = 1; private static final int CURRENTWEATHER = 2; @@ -66,7 +65,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { } } } catch (Exception e) { - BotLogger.error(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } @@ -98,7 +97,7 @@ public class WeatherHandlers extends TelegramLongPollingBot { try { Thread.currentThread().wait(35); } catch (InterruptedException e) { - BotLogger.severe(LOGTAG, e); + log.error(e.getLocalizedMessage(), e); } } String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId()); @@ -111,12 +110,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.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