Browse Source

Update version 4.4.0.1

master
Ruben Bermudez 6 years ago
parent
commit
2ca9bc3e1f
  1. 22
      pom.xml
  2. 2
      src/main/java/org/telegram/Commands.java
  3. 39
      src/main/java/org/telegram/Main.java
  4. 8
      src/main/java/org/telegram/commands/HelloCommand.java
  5. 9
      src/main/java/org/telegram/commands/HelpCommand.java
  6. 8
      src/main/java/org/telegram/commands/StartCommand.java
  7. 8
      src/main/java/org/telegram/commands/StopCommand.java
  8. 20
      src/main/java/org/telegram/database/ConectionDB.java
  9. 9
      src/main/java/org/telegram/database/DatabaseManager.java
  10. 7
      src/main/java/org/telegram/services/DirectionsService.java
  11. 11
      src/main/java/org/telegram/services/RaeService.java
  12. 13
      src/main/java/org/telegram/services/TimerExecutor.java
  13. 35
      src/main/java/org/telegram/services/TransifexService.java
  14. 29
      src/main/java/org/telegram/services/WeatherService.java
  15. 15
      src/main/java/org/telegram/updateshandlers/ChannelHandlers.java
  16. 10
      src/main/java/org/telegram/updateshandlers/CommandsHandler.java
  17. 21
      src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java
  18. 16
      src/main/java/org/telegram/updateshandlers/FilesHandlers.java
  19. 13
      src/main/java/org/telegram/updateshandlers/RaeHandlers.java
  20. 13
      src/main/java/org/telegram/updateshandlers/TransifexHandlers.java
  21. 14
      src/main/java/org/telegram/updateshandlers/WeatherHandlers.java

22
pom.xml

@ -11,14 +11,24 @@
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<httpcompontents.version>4.5.3</httpcompontents.version> <httpcompontents.version>4.5.9</httpcompontents.version>
<telegrambots.version>4.0.1</telegrambots.version> <telegrambots.version>4.4.0.1</telegrambots.version>
<json.version>20160810</json.version> <json.version>20180813</json.version>
<jsoup.version>1.10.2</jsoup.version> <jsoup.version>1.12.1</jsoup.version>
<mysql.version>6.0.6</mysql.version> <mysql.version>8.0.17</mysql.version>
<commonsio.version>2.5</commonsio.version> <commonsio.version>2.6</commonsio.version>
</properties> </properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.9.9</version>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>org.telegram</groupId> <groupId>org.telegram</groupId>

2
src/main/java/org/telegram/Commands.java

@ -26,6 +26,8 @@ public class Commands {
public static final String help = commandInitChar + "help"; public static final String help = commandInitChar + "help";
/// Upload command /// Upload command
public static final String uploadCommand = commandInitChar + "upload"; public static final String uploadCommand = commandInitChar + "upload";
/// Report command
public static final String reportCommand = commandInitChar + "report";
/// Start command /// Start command
public static final String startCommand = commandInitChar + "start"; public static final String startCommand = commandInitChar + "start";
/// Cancel command /// Cancel command

39
src/main/java/org/telegram/Main.java

@ -1,15 +1,12 @@
package org.telegram; package org.telegram;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.telegrambots.ApiContextInitializer; import org.telegram.telegrambots.ApiContextInitializer;
import org.telegram.telegrambots.meta.TelegramBotsApi; import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger; import org.telegram.updateshandlers.WeatherHandlers;
import org.telegram.telegrambots.meta.logging.BotsFileHandler; import org.telegram.updateshandlers.WebHookExampleHandlers;
import org.telegram.updateshandlers.*;
import java.io.IOException;
import java.util.logging.ConsoleHandler;
import java.util.logging.Level;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
@ -18,35 +15,27 @@ import java.util.logging.Level;
* @date 20 of June of 2015 * @date 20 of June of 2015
*/ */
public class Main { public class Main {
private static final String LOGTAG = "MAIN"; private static final Logger log = LogManager.getLogger(Main.class);
public static void main(String[] args) { 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 { try {
ApiContextInitializer.init(); ApiContextInitializer.init();
TelegramBotsApi telegramBotsApi = createTelegramBotsApi(); TelegramBotsApi telegramBotsApi = createTelegramBotsApi();
try { try {
// Register long polling bots. They work regardless type of TelegramBotsApi we are creating // Register long polling bots. They work regardless type of TelegramBotsApi we are creating
telegramBotsApi.registerBot(new ChannelHandlers()); // telegramBotsApi.registerBot(new ChannelHandlers());
telegramBotsApi.registerBot(new DirectionsHandlers()); // telegramBotsApi.registerBot(new DirectionsHandlers());
telegramBotsApi.registerBot(new RaeHandlers()); // telegramBotsApi.registerBot(new RaeHandlers());
telegramBotsApi.registerBot(new WeatherHandlers()); telegramBotsApi.registerBot(new WeatherHandlers());
telegramBotsApi.registerBot(new TransifexHandlers()); // telegramBotsApi.registerBot(new TransifexHandlers());
telegramBotsApi.registerBot(new FilesHandlers()); // telegramBotsApi.registerBot(new FilesHandlers());
telegramBotsApi.registerBot(new CommandsHandler(BotConfig.COMMANDS_USER)); // telegramBotsApi.registerBot(new CommandsHandler(BotConfig.COMMANDS_USER));
telegramBotsApi.registerBot(new ElektrollArtFanHandler()); // telegramBotsApi.registerBot(new ElektrollArtFanHandler());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }

8
src/main/java/org/telegram/commands/HelloCommand.java

@ -1,5 +1,7 @@
package org.telegram.commands; package org.telegram.commands;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; 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.api.objects.User;
import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; 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 * 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) * @author Timo Schulz (Mit0x2)
*/ */
public class HelloCommand extends BotCommand { public class HelloCommand extends BotCommand {
private static final Logger log = LogManager.getLogger(HelloCommand.class);
private static final String LOGTAG = "HELLOCOMMAND";
public HelloCommand() { public HelloCommand() {
super("hello", "Say hallo to this bot"); super("hello", "Say hallo to this bot");
@ -49,7 +49,7 @@ public class HelloCommand extends BotCommand {
try { try {
absSender.execute(answer); absSender.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

9
src/main/java/org/telegram/commands/HelpCommand.java

@ -1,6 +1,9 @@
package org.telegram.commands; package org.telegram.commands;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.database.DatabaseManager; 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.BotCommand;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry; 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.api.objects.User;
import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; 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 * 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) * @author Timo Schulz (Mit0x2)
*/ */
public class HelpCommand extends BotCommand { public class HelpCommand extends BotCommand {
private static final Logger log = LogManager.getLogger(RaeService.class);
private static final String LOGTAG = "HELPCOMMAND";
private final ICommandRegistry commandRegistry; private final ICommandRegistry commandRegistry;
@ -49,7 +50,7 @@ public class HelpCommand extends BotCommand {
try { try {
absSender.execute(helpMessage); absSender.execute(helpMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

8
src/main/java/org/telegram/commands/StartCommand.java

@ -1,5 +1,7 @@
package org.telegram.commands; package org.telegram.commands;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; 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.api.objects.User;
import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
/** /**
* This commands starts the conversation with the bot * This commands starts the conversation with the bot
@ -15,8 +16,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger;
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
public class StartCommand extends BotCommand { public class StartCommand extends BotCommand {
private static final Logger log = LogManager.getLogger(StartCommand.class);
public static final String LOGTAG = "STARTCOMMAND";
public StartCommand() { public StartCommand() {
super("start", "With this command you can start the Bot"); super("start", "With this command you can start the Bot");
@ -45,7 +45,7 @@ public class StartCommand extends BotCommand {
try { try {
absSender.execute(answer); absSender.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

8
src/main/java/org/telegram/commands/StopCommand.java

@ -1,5 +1,7 @@
package org.telegram.commands; package org.telegram.commands;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; 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.api.objects.User;
import org.telegram.telegrambots.meta.bots.AbsSender; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
/** /**
* This commands stops the conversation with the bot. * This commands stops the conversation with the bot.
@ -16,8 +17,7 @@ import org.telegram.telegrambots.meta.logging.BotLogger;
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
public class StopCommand extends BotCommand { public class StopCommand extends BotCommand {
private static final Logger log = LogManager.getLogger(StopCommand.class);
public static final String LOGTAG = "STOPCOMMAND";
/** /**
* Construct * Construct
@ -41,7 +41,7 @@ public class StopCommand extends BotCommand {
try { try {
absSender.execute(answer); absSender.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

20
src/main/java/org/telegram/database/ConectionDB.java

@ -7,10 +7,17 @@
*/ */
package org.telegram.database; package org.telegram.database;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BuildVars; 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 * @author Ruben Bermudez
@ -18,7 +25,8 @@ import java.sql.*;
* Connector to database * Connector to database
*/ */
public class ConectionDB { public class ConectionDB {
private static final String LOGTAG = "CONNECTIONDB"; private static final Logger log = LogManager.getLogger(ConectionDB.class);
private Connection currentConection; private Connection currentConection;
public ConectionDB() { public ConectionDB() {
@ -31,7 +39,7 @@ public class ConectionDB {
Class.forName(BuildVars.controllerDB).newInstance(); Class.forName(BuildVars.controllerDB).newInstance();
connection = DriverManager.getConnection(BuildVars.linkDB, BuildVars.userDB, BuildVars.password); connection = DriverManager.getConnection(BuildVars.linkDB, BuildVars.userDB, BuildVars.password);
} catch (SQLException | ClassNotFoundException | IllegalAccessException | InstantiationException e) { } catch (SQLException | ClassNotFoundException | IllegalAccessException | InstantiationException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return connection; return connection;
@ -41,7 +49,7 @@ public class ConectionDB {
try { try {
this.currentConection.close(); this.currentConection.close();
} catch (SQLException e) { } catch (SQLException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -80,7 +88,7 @@ public class ConectionDB {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return max; return max;
} }

9
src/main/java/org/telegram/database/DatabaseManager.java

@ -7,8 +7,9 @@
*/ */
package org.telegram.database; package org.telegram.database;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.structure.WeatherAlert; import org.telegram.structure.WeatherAlert;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
@ -25,7 +26,7 @@ import java.util.List;
* @date 3/12/14 * @date 3/12/14
*/ */
public class DatabaseManager { 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 DatabaseManager instance;
private static volatile ConectionDB connetion; private static volatile ConectionDB connetion;
@ -36,7 +37,7 @@ public class DatabaseManager {
private DatabaseManager() { private DatabaseManager() {
connetion = new ConectionDB(); connetion = new ConectionDB();
final int currentVersion = connetion.checkVersion(); final int currentVersion = connetion.checkVersion();
BotLogger.info(LOGTAG, "Current db version: " + currentVersion); log.info("Current db version: " + currentVersion);
if (currentVersion < CreationStrings.version) { if (currentVersion < CreationStrings.version) {
recreateTable(currentVersion); recreateTable(currentVersion);
} }
@ -94,7 +95,7 @@ public class DatabaseManager {
} }
connetion.commitTransaction(); connetion.commitTransaction();
} catch (SQLException e) { } catch (SQLException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }

7
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.entity.BufferedHttpEntity;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; 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.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import org.jsoup.Jsoup; import org.jsoup.Jsoup;
import org.telegram.BuildVars; import org.telegram.BuildVars;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -27,7 +28,7 @@ import java.util.List;
* @date 20 of June of 2015 * @date 20 of June of 2015
*/ */
public class DirectionsService { 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 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 APIIDEND = "&key=" + BuildVars.DirectionsApiKey;
@ -98,7 +99,7 @@ public class DirectionsService {
responseToUser.add(LocalisationService.getString("directionsNotFound", language)); responseToUser.add(LocalisationService.getString("directionsNotFound", language));
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.warn(LOGTAG, e); log.warn(e.getLocalizedMessage(), e);
responseToUser.add(LocalisationService.getString("errorFetchingDirections", language)); responseToUser.add(LocalisationService.getString("errorFetchingDirections", language));
} }
return responseToUser; return responseToUser;

11
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.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; 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.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -28,7 +29,7 @@ import java.util.Map;
* @date 20 of June of 2015 * @date 20 of June of 2015
*/ */
public class RaeService { 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 BASEURL = "http://dle.rae.es/srv/"; ///< Base url for REST
private static final String SEARCHEXACTURL = "search?m=30&w="; private static final String SEARCHEXACTURL = "search?m=30&w=";
@ -66,7 +67,7 @@ public class RaeService {
results = getResultsFromExactMatch(elements, query, articleId); results = getResultsFromExactMatch(elements, query, articleId);
} }
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return results; return results;
@ -103,7 +104,7 @@ public class RaeService {
} }
} }
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return results; return results;
@ -137,7 +138,7 @@ public class RaeService {
results = getResultsFromExactMatch(elements, word, articleId); results = getResultsFromExactMatch(elements, word, articleId);
} }
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return results; return results;

13
src/main/java/org/telegram/services/TimerExecutor.java

@ -1,6 +1,7 @@
package org.telegram.services; 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.Clock;
import java.time.Duration; import java.time.Duration;
@ -15,7 +16,7 @@ import java.util.concurrent.TimeUnit;
* Execute a task periodically * Execute a task periodically
*/ */
public class TimerExecutor { 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 volatile TimerExecutor instance; ///< Instance
private static final ScheduledExecutorService executorService = Executors.newScheduledThreadPool(1); ///< Thread to execute operations 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 * @param targetSec Second to execute it
*/ */
public void startExecutionEveryDayAt(CustomTimerTask task, int targetHour, int targetMin, int targetSec) { 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 = () -> { final Runnable taskWrapper = () -> {
try { try {
task.execute(); task.execute();
task.reduceTimes(); task.reduceTimes();
startExecutionEveryDayAt(task, targetHour, targetMin, targetSec); startExecutionEveryDayAt(task, targetHour, targetMin, targetSec);
} catch (Exception e) { } 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) { if (task.getTimes() != 0) {
@ -103,9 +104,9 @@ public class TimerExecutor {
try { try {
executorService.awaitTermination(1, TimeUnit.DAYS); executorService.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
BotLogger.severe(LOGTAG, ex); log.fatal(ex.getLocalizedMessage(), ex);
} catch (Exception e) { } 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);
} }
} }
} }

35
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.conn.ssl.NoopHostnameVerifier;
import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; 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.BuildVars;
import org.telegram.telegrambots.meta.api.methods.send.SendDocument; import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.*; import java.io.*;
@ -20,7 +21,7 @@ import java.io.*;
* @date 21 of June of 2015 * @date 21 of June of 2015
*/ */
public class TransifexService { 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 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 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; result = responseString;
} }
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -90,7 +91,7 @@ public class TransifexService {
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE");
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -103,7 +104,7 @@ public class TransifexService {
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE");
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -116,7 +117,7 @@ public class TransifexService {
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE");
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -129,7 +130,7 @@ public class TransifexService {
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-8"), "UTF-8"); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-8"), "UTF-8");
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -142,7 +143,7 @@ public class TransifexService {
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE");
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -155,7 +156,7 @@ public class TransifexService {
HttpResponse response = client.execute(request); HttpResponse response = client.execute(request);
result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE"); result = IOUtils.toByteArray(new InputStreamReader(response.getEntity().getContent(), "UTF-16LE"), "UTF-16LE");
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return result; return result;
} }
@ -195,11 +196,11 @@ public class TransifexService {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setDocument(fileToUpload); sendDocument.setDocument(fileToUpload);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return sendDocument; return sendDocument;
} }
@ -222,11 +223,11 @@ public class TransifexService {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setDocument(fileToUpload); sendDocument.setDocument(fileToUpload);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return sendDocument; return sendDocument;
} }
@ -250,11 +251,11 @@ public class TransifexService {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setDocument(fileToUpload); sendDocument.setDocument(fileToUpload);
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return sendDocument; return sendDocument;
} }
@ -277,11 +278,11 @@ public class TransifexService {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setDocument(fileToUpload); sendDocument.setDocument(fileToUpload);
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
return sendDocument; return sendDocument;
} }

29
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.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.util.EntityUtils; import org.apache.http.util.EntityUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.json.JSONObject; import org.json.JSONObject;
import org.telegram.BuildVars; import org.telegram.BuildVars;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -27,7 +28,7 @@ import java.time.format.DateTimeFormatter;
* @date 20 of June of 2015 * @date 20 of June of 2015
*/ */
public class WeatherService { 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 METRICSYSTEM = "metric";
public static final String IMPERIALSYSTEM = "imperial"; public static final String IMPERIALSYSTEM = "imperial";
@ -91,7 +92,7 @@ public class WeatherService {
String responseString = EntityUtils.toString(buf, "UTF-8"); String responseString = EntityUtils.toString(buf, "UTF-8");
JSONObject jsonObject = new JSONObject(responseString); JSONObject jsonObject = new JSONObject(responseString);
BotLogger.info(LOGTAG, jsonObject.toString()); log.info(jsonObject.toString());
if (jsonObject.getInt("cod") == 200) { if (jsonObject.getInt("cod") == 200) {
cityFound = jsonObject.getJSONObject("city").getString("name") + " (" + cityFound = jsonObject.getJSONObject("city").getString("name") + " (" +
jsonObject.getJSONObject("city").getString("country") + ")"; jsonObject.getJSONObject("city").getString("country") + ")";
@ -99,11 +100,11 @@ public class WeatherService {
responseToUser = String.format(LocalisationService.getString("weatherAlert", language), responseToUser = String.format(LocalisationService.getString("weatherAlert", language),
cityFound, convertListOfForecastToString(jsonObject, language, units, false)); cityFound, convertListOfForecastToString(jsonObject, language, units, false));
} else { } else {
BotLogger.warn(LOGTAG, jsonObject.toString()); log.warn(jsonObject.toString());
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -132,7 +133,7 @@ public class WeatherService {
String responseString = EntityUtils.toString(buf, "UTF-8"); String responseString = EntityUtils.toString(buf, "UTF-8");
JSONObject jsonObject = new JSONObject(responseString); JSONObject jsonObject = new JSONObject(responseString);
BotLogger.info(LOGTAG, jsonObject.toString()); log.info(jsonObject.toString());
if (jsonObject.getInt("cod") == 200) { if (jsonObject.getInt("cod") == 200) {
cityFound = jsonObject.getJSONObject("city").getString("name") + " (" + cityFound = jsonObject.getJSONObject("city").getString("name") + " (" +
jsonObject.getJSONObject("city").getString("country") + ")"; jsonObject.getJSONObject("city").getString("country") + ")";
@ -140,11 +141,11 @@ public class WeatherService {
responseToUser = String.format(LocalisationService.getString("weatherForcast", language), responseToUser = String.format(LocalisationService.getString("weatherForcast", language),
cityFound, convertListOfForecastToString(jsonObject, language, units, true)); cityFound, convertListOfForecastToString(jsonObject, language, units, true));
} else { } else {
BotLogger.warn(LOGTAG, jsonObject.toString()); log.warn(jsonObject.toString());
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -179,11 +180,11 @@ public class WeatherService {
responseToUser = String.format(LocalisationService.getString("weatherForcast", language), responseToUser = String.format(LocalisationService.getString("weatherForcast", language),
cityFound, convertListOfForecastToString(jsonObject, language, units, true)); cityFound, convertListOfForecastToString(jsonObject, language, units, true));
} else { } else {
BotLogger.warn(LOGTAG, jsonObject.toString()); log.warn(jsonObject.toString());
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -220,11 +221,11 @@ public class WeatherService {
responseToUser = String.format(LocalisationService.getString("weatherCurrent", language), responseToUser = String.format(LocalisationService.getString("weatherCurrent", language),
cityFound, convertCurrentWeatherToString(jsonObject, language, units, emoji)); cityFound, convertCurrentWeatherToString(jsonObject, language, units, emoji));
} else { } else {
BotLogger.warn(LOGTAG, jsonObject.toString()); log.warn(jsonObject.toString());
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -259,11 +260,11 @@ public class WeatherService {
responseToUser = String.format(LocalisationService.getString("weatherCurrent", language), responseToUser = String.format(LocalisationService.getString("weatherCurrent", language),
cityFound, convertCurrentWeatherToString(jsonObject, language, units, null)); cityFound, convertCurrentWeatherToString(jsonObject, language, units, null));
} else { } else {
BotLogger.warn(LOGTAG, jsonObject.toString()); log.warn(jsonObject.toString());
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;

15
src/main/java/org/telegram/updateshandlers/ChannelHandlers.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; 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.ForceReplyKeyboard;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup; import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -21,7 +22,7 @@ import java.util.concurrent.ConcurrentHashMap;
* @date 24 of June of 2015 * @date 24 of June of 2015
*/ */
public class ChannelHandlers extends TelegramLongPollingBot { 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; private static final int WAITINGCHANNEL = 1;
@ -42,11 +43,11 @@ public class ChannelHandlers extends TelegramLongPollingBot {
try { try {
handleIncomingMessage(message); handleIncomingMessage(message);
} catch (InvalidObjectException e) { } catch (InvalidObjectException e) {
BotLogger.severe(LOGTAG, e); log.fatal(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception 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) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -123,7 +124,7 @@ public class ChannelHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessage); execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -165,7 +166,7 @@ public class ChannelHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessage); execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

10
src/main/java/org/telegram/updateshandlers/CommandsHandler.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.commands.HelloCommand; import org.telegram.commands.HelloCommand;
import org.telegram.commands.HelpCommand; 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.Message;
import org.telegram.telegrambots.meta.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; 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 * 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 class CommandsHandler extends TelegramLongPollingCommandBot {
public static final String LOGTAG = "COMMANDSHANDLER"; private static final Logger log = LogManager.getLogger(CommandsHandler.class);
/** /**
* Constructor. * Constructor.
*/ */
@ -42,7 +42,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot {
try { try {
absSender.execute(commandUnknownMessage); absSender.execute(commandUnknownMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
helpCommand.execute(absSender, message.getFrom(), message.getChat(), new String[] {}); helpCommand.execute(absSender, message.getFrom(), message.getChat(), new String[] {});
}); });
@ -66,7 +66,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot {
try { try {
execute(echoMessage); execute(echoMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

21
src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.Commands; import org.telegram.Commands;
import org.telegram.database.DatabaseManager; 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.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import org.telegram.telegrambots.meta.updateshandlers.SentCallback; import org.telegram.telegrambots.meta.updateshandlers.SentCallback;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
@ -31,7 +32,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* @date 24 of June of 2015 * @date 24 of June of 2015
*/ */
public class DirectionsHandlers extends TelegramLongPollingBot { 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_ORIGIN_STATUS = 0;
private static final int WATING_DESTINY_STATUS = 1; private static final int WATING_DESTINY_STATUS = 1;
@ -48,7 +49,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
try { try {
handleDirections(update); handleDirections(update);
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -92,7 +93,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }
@ -131,7 +132,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
} }
}); });
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -165,7 +166,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
} }
}); });
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -180,7 +181,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -212,7 +213,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
} }
}); });
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -238,7 +239,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
execute(sendMessageRequest); execute(sendMessageRequest);
languageMessages.add(message.getFrom().getId()); languageMessages.add(message.getFrom().getId());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -260,7 +261,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
execute(sendMessageRequest); execute(sendMessageRequest);
languageMessages.remove(message.getFrom().getId()); languageMessages.remove(message.getFrom().getId());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

16
src/main/java/org/telegram/updateshandlers/FilesHandlers.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.Commands; import org.telegram.Commands;
import org.telegram.database.DatabaseManager; 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.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.ArrayList; import java.util.ArrayList;
@ -32,7 +33,7 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* @date 24 of June of 2015 * @date 24 of June of 2015
*/ */
public class FilesHandlers extends TelegramLongPollingBot { 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 INITIAL_UPLOAD_STATUS = 0;
private static final int DELETE_UPLOADED_STATUS = 1; private static final int DELETE_UPLOADED_STATUS = 1;
@ -48,7 +49,12 @@ public class FilesHandlers extends TelegramLongPollingBot {
try { try {
if (update.hasMessage()) { if (update.hasMessage()) {
try { 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) { } catch (TelegramApiRequestException e) {
if (e.getApiResponse().contains("Bot was blocked by the user")) { if (e.getApiResponse().contains("Bot was blocked by the user")) {
if (update.getMessage().getFrom() != null) { if (update.getMessage().getFrom() != null) {
@ -56,11 +62,11 @@ public class FilesHandlers extends TelegramLongPollingBot {
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.severe(LOGTAG, e); log.fatal(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }

13
src/main/java/org/telegram/updateshandlers/RaeHandlers.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.services.RaeService; import org.telegram.services.RaeService;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; 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.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResultArticle; import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResultArticle;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -24,7 +25,7 @@ import java.util.List;
* @date 24 of June of 2015 * @date 24 of June of 2015
*/ */
public class RaeHandlers extends TelegramLongPollingBot { 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 static final Integer CACHETIME = 86400;
private final RaeService raeService = new RaeService(); private final RaeService raeService = new RaeService();
@ -50,11 +51,11 @@ public class RaeHandlers extends TelegramLongPollingBot {
try { try {
execute(getHelpMessage(update.getMessage())); execute(getHelpMessage(update.getMessage()));
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} catch (Exception 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) { private void handleIncomingInlineQuery(InlineQuery inlineQuery) {
String query = inlineQuery.getQuery(); String query = inlineQuery.getQuery();
BotLogger.debug(LOGTAG, "Searching: " + query); log.debug("Searching: " + query);
try { try {
if (!query.isEmpty()) { if (!query.isEmpty()) {
List<RaeService.RaeResult> results = raeService.getResults(query); List<RaeService.RaeResult> results = raeService.getResults(query);
@ -78,7 +79,7 @@ public class RaeHandlers extends TelegramLongPollingBot {
execute(converteResultsToResponse(inlineQuery, new ArrayList<>())); execute(converteResultsToResponse(inlineQuery, new ArrayList<>()));
} }
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }

13
src/main/java/org/telegram/updateshandlers/TransifexHandlers.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.BuildVars; import org.telegram.BuildVars;
import org.telegram.Commands; 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.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton; import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.ArrayList; import java.util.ArrayList;
@ -27,7 +28,7 @@ import java.util.List;
* @date 24 of June of 2015 * @date 24 of June of 2015
*/ */
public class TransifexHandlers extends TelegramLongPollingBot { public class TransifexHandlers extends TelegramLongPollingBot {
private static final String LOGTAG = "TRANSIFEXHANDLERS"; private static final Logger log = LogManager.getLogger(TransifexHandlers.class);
@Override @Override
public String getBotToken() { public String getBotToken() {
@ -39,7 +40,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
try { try {
handleUpdate(update); handleUpdate(update);
} catch (Throwable e) { } catch (Throwable e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -91,7 +92,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -100,7 +101,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
try { try {
execute(sendDocument); execute(sendDocument);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} else if (parts[0].startsWith(Commands.help) || } else if (parts[0].startsWith(Commands.help) ||
@ -116,7 +117,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
} }

14
src/main/java/org/telegram/updateshandlers/WeatherHandlers.java

@ -1,5 +1,7 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.Commands; import org.telegram.Commands;
import org.telegram.database.DatabaseManager; 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.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -29,8 +30,7 @@ import java.util.stream.Collectors;
* @date 24 of June of 2015 * @date 24 of June of 2015
*/ */
public class WeatherHandlers extends TelegramLongPollingBot { 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 STARTSTATE = 0;
private static final int MAINMENU = 1; private static final int MAINMENU = 1;
private static final int CURRENTWEATHER = 2; private static final int CURRENTWEATHER = 2;
@ -66,7 +66,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
} }
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.error(LOGTAG, e); log.error(e.getLocalizedMessage(), e);
} }
} }
@ -98,7 +98,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
try { try {
Thread.currentThread().wait(35); Thread.currentThread().wait(35);
} catch (InterruptedException e) { } catch (InterruptedException e) {
BotLogger.severe(LOGTAG, e); log.fatal(e.getLocalizedMessage(), e);
} }
} }
String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId()); String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId());
@ -111,12 +111,12 @@ public class WeatherHandlers extends TelegramLongPollingBot {
try { try {
execute(sendMessage); execute(sendMessage);
} catch (TelegramApiRequestException e) { } 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")) { if (e.getApiResponse().contains("Can't access the chat") || e.getApiResponse().contains("Bot was blocked by the user")) {
DatabaseManager.getInstance().deleteAlertsForUser(weatherAlert.getUserId()); DatabaseManager.getInstance().deleteAlertsForUser(weatherAlert.getUserId());
} }
} catch (Exception e) { } catch (Exception e) {
BotLogger.severe(LOGTAG, e); log.fatal(e.getLocalizedMessage(), e);
} }
} }
} }

Loading…
Cancel
Save