Browse Source

初次提交

master
La123123 3 weeks ago
parent
commit
8afe56bf4f
  1. 6
      pom.xml
  2. 4
      src/main/java/org/telegram/BotConfig.java
  3. 6
      src/main/java/org/telegram/BuildVars.java
  4. 23
      src/main/java/org/telegram/Main.java
  5. 5
      src/main/java/org/telegram/commands/HelloCommand.java
  6. 5
      src/main/java/org/telegram/commands/HelpCommand.java
  7. 5
      src/main/java/org/telegram/commands/StartCommand.java
  8. 5
      src/main/java/org/telegram/commands/StopCommand.java
  9. 43
      src/main/java/org/telegram/commands/SuccessCommand.java
  10. 14
      src/main/java/org/telegram/database/ConnectionDB.java
  11. 80
      src/main/java/org/telegram/database/DatabaseManager.java
  12. 5
      src/main/java/org/telegram/services/DirectionsService.java
  13. 11
      src/main/java/org/telegram/services/RaeService.java
  14. 15
      src/main/java/org/telegram/services/TimerExecutor.java
  15. 27
      src/main/java/org/telegram/services/WeatherService.java
  16. 17
      src/main/java/org/telegram/updateshandlers/ChannelHandlers.java
  17. 10
      src/main/java/org/telegram/updateshandlers/CommandsHandler.java
  18. 25
      src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java
  19. 14
      src/main/java/org/telegram/updateshandlers/ElektrollArtFanHandler.java
  20. 8
      src/main/java/org/telegram/updateshandlers/FilesHandlers.java
  21. 14
      src/main/java/org/telegram/updateshandlers/RaeHandlers.java
  22. 14
      src/main/java/org/telegram/updateshandlers/WeatherHandlers.java
  23. 8
      src/main/java/org/telegram/updateshandlers/WebHookExampleHandlers.java

6
pom.xml

@ -24,7 +24,6 @@
<commonsio.version>2.15.1</commonsio.version> <commonsio.version>2.15.1</commonsio.version>
<lombok.version>1.18.30</lombok.version> <lombok.version>1.18.30</lombok.version>
<okhttp.version>4.12.0</okhttp.version> <okhttp.version>4.12.0</okhttp.version>
<slf4j.version>2.0.12</slf4j.version>
</properties> </properties>
<dependencyManagement> <dependencyManagement>
@ -44,11 +43,6 @@
<artifactId>jetty-util</artifactId> <artifactId>jetty-util</artifactId>
<version>11.0.19</version> <version>11.0.19</version>
</dependency> </dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
</dependencies> </dependencies>
</dependencyManagement> </dependencyManagement>

4
src/main/java/org/telegram/BotConfig.java

@ -25,10 +25,10 @@ public class BotConfig {
public static final String RAE_TOKEN = "<token>"; public static final String RAE_TOKEN = "<token>";
public static final String RAE_USER = "raebot"; public static final String RAE_USER = "raebot";
public static final String WEBHOOK_TOKEN = "<token>"; public static final String WEBHOOK_TOKEN = "8660825573:AAH2wWz_3ArDL_iNoAbSxnDCs_W5brEEJ8I";
public static final String WEBHOOK_USER = "webhooksamplebot"; public static final String WEBHOOK_USER = "webhooksamplebot";
public static final String COMMANDS_TOKEN = "<token>"; public static final String COMMANDS_TOKEN = "8660825573:AAH2wWz_3ArDL_iNoAbSxnDCs_W5brEEJ8I";
public static final String COMMANDS_USER = "MyCommandsBot"; public static final String COMMANDS_USER = "MyCommandsBot";
public static final String ELEKTROLLART_TOKEN = "<token>"; public static final String ELEKTROLLART_TOKEN = "<token>";

6
src/main/java/org/telegram/BuildVars.java

@ -30,10 +30,10 @@ public class BuildVars {
public static final String pathToLogs = "./"; public static final String pathToLogs = "./";
public static final String linkDB = "jdbc:mysql://localhost:3306/YOURDATABSENAME?useUnicode=true&characterEncoding=UTF-8"; public static final String linkDB = "jdbc:mysql://localhost:3306/tel_example?useUnicode=true&characterEncoding=UTF-8";
public static final String controllerDB = "com.mysql.cj.jdbc.Driver"; public static final String controllerDB = "com.mysql.cj.jdbc.Driver";
public static final String userDB = "<your-database-user>"; public static final String userDB = "root";
public static final String password = "<your-databas-user-password>"; public static final String password = "JtnA5H6PfGHzkfzx";
static { static {
// Add elements to ADMIN array here // Add elements to ADMIN array here

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

@ -1,6 +1,5 @@
package org.telegram; package org.telegram;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.longpolling.TelegramBotsLongPollingApplication; import org.telegram.telegrambots.longpolling.TelegramBotsLongPollingApplication;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.webhook.TelegramBotsWebhookApplication; import org.telegram.telegrambots.webhook.TelegramBotsWebhookApplication;
@ -19,25 +18,27 @@ import org.telegram.updateshandlers.WebHookExampleHandlers;
* @version 1.0 * @version 1.0
* Main class to create all bots * Main class to create all bots
*/ */
@Slf4j
public class Main { public class Main {
public static void main(String[] args) { public static void main(String[] args) {
try (TelegramBotsWebhookApplication webhookApplication = new TelegramBotsWebhookApplication(WebhookOptions.builder().enableRequestLogging(true).build())) { try (TelegramBotsWebhookApplication webhookApplication = new TelegramBotsWebhookApplication(WebhookOptions.builder().enableRequestLogging(true).build())) {
webhookApplication.registerBot(new WebHookExampleHandlers(BotConfig.WEBHOOK_TOKEN)); // webhookApplication.registerBot(new WebHookExampleHandlers(BotConfig.WEBHOOK_TOKEN));
try (TelegramBotsLongPollingApplication botsApplication = new TelegramBotsLongPollingApplication()) { try (TelegramBotsLongPollingApplication botsApplication = new TelegramBotsLongPollingApplication()) {
botsApplication.registerBot(BotConfig.WEATHER_TOKEN, new WeatherHandlers(BotConfig.WEATHER_TOKEN)); // botsApplication.registerBot(BotConfig.WEATHER_TOKEN, new WeatherHandlers(BotConfig.WEATHER_TOKEN));
botsApplication.registerBot(BotConfig.CHANNEL_TOKEN, new ChannelHandlers(BotConfig.CHANNEL_TOKEN)); // botsApplication.registerBot(BotConfig.CHANNEL_TOKEN, new ChannelHandlers(BotConfig.CHANNEL_TOKEN));
botsApplication.registerBot(BotConfig.COMMANDS_TOKEN, new CommandsHandler(BotConfig.COMMANDS_TOKEN, BotConfig.COMMANDS_USER)); botsApplication.registerBot(BotConfig.COMMANDS_TOKEN, new CommandsHandler(BotConfig.COMMANDS_TOKEN, BotConfig.COMMANDS_USER));
botsApplication.registerBot(BotConfig.DIRECTIONS_TOKEN, new DirectionsHandlers(BotConfig.DIRECTIONS_TOKEN)); // botsApplication.registerBot(BotConfig.DIRECTIONS_TOKEN, new DirectionsHandlers(BotConfig.DIRECTIONS_TOKEN));
botsApplication.registerBot(BotConfig.ELEKTROLLART_TOKEN, new ElektrollArtFanHandler(BotConfig.ELEKTROLLART_TOKEN)); // botsApplication.registerBot(BotConfig.ELEKTROLLART_TOKEN, new ElektrollArtFanHandler(BotConfig.ELEKTROLLART_TOKEN));
botsApplication.registerBot(BotConfig.FILES_TOKEN, new FilesHandlers(BotConfig.FILES_TOKEN)); // botsApplication.registerBot(BotConfig.FILES_TOKEN, new FilesHandlers(BotConfig.FILES_TOKEN));
botsApplication.registerBot(BotConfig.RAE_TOKEN, new RaeHandlers(BotConfig.RAE_TOKEN)); // botsApplication.registerBot(BotConfig.RAE_TOKEN, new RaeHandlers(BotConfig.RAE_TOKEN));
Thread.currentThread().join(); Thread.currentThread().join();
} catch (Exception e) { } catch (Exception e) {
log.error("Error registering bot", e); // log.error("Error registering bot", e);
System.out.println("Error registering bot" + e);
} }
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error registering bot", e); // log.error("Error registering bot", e);
System.out.println("Error registering bot" + e);
} }
System.out.println("example bot 启动成功!");
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.commands; package org.telegram.commands;
import lombok.extern.slf4j.Slf4j;
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;
@ -15,7 +14,6 @@ import org.telegram.telegrambots.meta.generics.TelegramClient;
* *
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
@Slf4j
public class HelloCommand extends BotCommand { public class HelloCommand extends BotCommand {
private static final String LOGTAG = "HELLOCOMMAND"; private static final String LOGTAG = "HELLOCOMMAND";
@ -48,7 +46,8 @@ public class HelloCommand extends BotCommand {
try { try {
telegramClient.execute(answer); telegramClient.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error", e); // log.error("Error", e);
System.out.println(e);
} }
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.commands; package org.telegram.commands;
import lombok.extern.slf4j.Slf4j;
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.extensions.bots.commandbot.commands.IBotCommand; import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
@ -16,7 +15,6 @@ import org.telegram.telegrambots.meta.generics.TelegramClient;
* *
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
@Slf4j
public class HelpCommand extends BotCommand { public class HelpCommand extends BotCommand {
private static final String LOGTAG = "HELPCOMMAND"; private static final String LOGTAG = "HELPCOMMAND";
@ -48,7 +46,8 @@ public class HelpCommand extends BotCommand {
try { try {
telegramClient.execute(helpMessage); telegramClient.execute(helpMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error", e); // log.error("Error", e);
System.out.println(e);
} }
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.commands; package org.telegram.commands;
import lombok.extern.slf4j.Slf4j;
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;
@ -14,7 +13,6 @@ import org.telegram.telegrambots.meta.generics.TelegramClient;
* *
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
@Slf4j
public class StartCommand extends BotCommand { public class StartCommand extends BotCommand {
public StartCommand() { public StartCommand() {
super("start", "With this command you can start the Bot"); super("start", "With this command you can start the Bot");
@ -41,7 +39,8 @@ public class StartCommand extends BotCommand {
try { try {
telegramClient.execute(answer); telegramClient.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error", e); // log.error("Error", e);
System.out.println(e);
} }
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.commands; package org.telegram.commands;
import lombok.extern.slf4j.Slf4j;
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;
@ -15,7 +14,6 @@ import org.telegram.telegrambots.meta.generics.TelegramClient;
* *
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
@Slf4j
public class StopCommand extends BotCommand { public class StopCommand extends BotCommand {
public static final String LOGTAG = "STOPCOMMAND"; public static final String LOGTAG = "STOPCOMMAND";
@ -40,7 +38,8 @@ public class StopCommand extends BotCommand {
try { try {
telegramClient.execute(answer); telegramClient.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error", e); // log.error("Error", e);
System.out.println("Error" + e);
} }
} }
} }

43
src/main/java/org/telegram/commands/SuccessCommand.java

@ -0,0 +1,43 @@
package org.telegram.commands;
import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.generics.TelegramClient;
/**
* This command returns the username + success message
*
* @author Your Name
*/
public class SuccessCommand extends BotCommand {
private static final String LOGTAG = "SUCCESSCOMMAND";
public SuccessCommand() {
super("success", "Get your success message");
}
@Override
public void execute(TelegramClient telegramClient, User user, Chat chat, String[] arguments) {
if (!DatabaseManager.getInstance().getUserStateForCommandsBot(user.getId())) {
return;
}
String userName = user.getFirstName() + " " + user.getLastName();
String messageText = userName + " success";
SendMessage answer = new SendMessage(chat.getId().toString(), messageText);
try {
telegramClient.execute(answer);
} catch (TelegramApiException e) {
// log.error("Error", e);
System.out.println(e);
}
}
}

14
src/main/java/org/telegram/database/ConnectionDB.java

@ -7,7 +7,6 @@
*/ */
package org.telegram.database; package org.telegram.database;
import lombok.extern.slf4j.Slf4j;
import org.telegram.BuildVars; import org.telegram.BuildVars;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -24,7 +23,6 @@ import java.sql.Statement;
* @version 2.0 * @version 2.0
* Connector to database * Connector to database
*/ */
@Slf4j
public class ConnectionDB { public class ConnectionDB {
private final Connection currentConection; private final Connection currentConection;
@ -39,7 +37,8 @@ public class ConnectionDB {
connection = DriverManager.getConnection(BuildVars.linkDB, BuildVars.userDB, BuildVars.password); connection = DriverManager.getConnection(BuildVars.linkDB, BuildVars.userDB, BuildVars.password);
} catch (SQLException | ClassNotFoundException | IllegalAccessException | InstantiationException | } catch (SQLException | ClassNotFoundException | IllegalAccessException | InstantiationException |
NoSuchMethodException | InvocationTargetException e) { NoSuchMethodException | InvocationTargetException e) {
log.error("Error opening connection", e); // log.error("Error opening connection", e);
System.out.println("Error opening connection" + e);
} }
return connection; return connection;
@ -49,7 +48,8 @@ public class ConnectionDB {
try { try {
this.currentConection.close(); this.currentConection.close();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error closing the connection", e); // log.error("Error closing the connection", e);
System.out.println("Error closing the connection" + e);
} }
} }
@ -89,7 +89,8 @@ public class ConnectionDB {
} }
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error checking version", e); // log.error("Error checking version", e);
System.out.println("Error checking version" + e);
} }
return max; return max;
} }
@ -122,7 +123,8 @@ public class ConnectionDB {
try { try {
this.currentConection.rollback(); this.currentConection.rollback();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error rolling back the transaction", e); // log.error("Error rolling back the transaction", e);
System.out.println("Error rolling back the transaction" + e);
} finally { } finally {
this.currentConection.setAutoCommit(true); this.currentConection.setAutoCommit(true);
} }

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

@ -7,7 +7,6 @@
*/ */
package org.telegram.database; package org.telegram.database;
import lombok.extern.slf4j.Slf4j;
import org.telegram.structure.WeatherAlert; import org.telegram.structure.WeatherAlert;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
@ -23,7 +22,6 @@ import java.util.List;
* @version 2.0 * @version 2.0
* Database Manager to perform database operations * Database Manager to perform database operations
*/ */
@Slf4j
public class DatabaseManager { public class DatabaseManager {
private static volatile DatabaseManager instance; private static volatile DatabaseManager instance;
private static volatile ConnectionDB connetion; private static volatile ConnectionDB connetion;
@ -34,7 +32,8 @@ public class DatabaseManager {
private DatabaseManager() { private DatabaseManager() {
connetion = new ConnectionDB(); connetion = new ConnectionDB();
final int currentVersion = connetion.checkVersion(); final int currentVersion = connetion.checkVersion();
log.info("Current db version: " + currentVersion); // log.info("Current db version: " + currentVersion);
System.out.println("Current db version: " + currentVersion);
if (currentVersion < CreationStrings.version) { if (currentVersion < CreationStrings.version) {
recreateTable(currentVersion); recreateTable(currentVersion);
} }
@ -95,11 +94,13 @@ public class DatabaseManager {
} }
connetion.commitTransaction(); connetion.commitTransaction();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error updating DB", e); // log.error("Error updating DB", e);
System.out.println("Error updating DB" + e);
try { try {
connetion.rollbackTransaction(); connetion.rollbackTransaction();
} catch (SQLException ex) { } catch (SQLException ex) {
log.error("Error rollingback the transaction", ex); // log.error("Error rollingback the transaction", ex);
System.out.println("Error rollingback the transaction" + ex);
} }
} }
} }
@ -187,7 +188,8 @@ public class DatabaseManager {
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error setting user state for commands bot", e); // log.error("Error setting user state for commands bot", e);
System.out.println("Error setting user state for commands bot" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -202,7 +204,8 @@ public class DatabaseManager {
status = result.getInt("status"); status = result.getInt("status");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting user state for command bot", e); // log.error("Error getting user state for command bot", e);
System.out.println("Error getting user state for command bot" + e);
} }
return status == 1; return status == 1;
} }
@ -217,7 +220,8 @@ public class DatabaseManager {
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting file", e); // log.error("Error getting file", e);
System.out.println("Error getting file" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -233,7 +237,7 @@ public class DatabaseManager {
} }
result.close(); result.close();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting files for user", e); System.out.println("Error getting files for user" + e);
} }
return files; return files;
} }
@ -246,7 +250,7 @@ public class DatabaseManager {
preparedStatement.setInt(2, status); preparedStatement.setInt(2, status);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting user for file", e); System.out.println("Error getting user for file" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -259,7 +263,7 @@ public class DatabaseManager {
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error deleting user file", e); System.out.println("Error deleting user file" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -274,7 +278,7 @@ public class DatabaseManager {
status = result.getInt("status"); status = result.getInt("status");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting user status", e); System.out.println("Error getting user status" + e);
} }
return status; return status;
} }
@ -287,7 +291,7 @@ public class DatabaseManager {
final ResultSet result = preparedStatement.executeQuery(); final ResultSet result = preparedStatement.executeQuery();
exists = result.next(); exists = result.next();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error checking file", e); System.out.println("Error checking file" + e);
} }
return exists; return exists;
} }
@ -300,7 +304,7 @@ public class DatabaseManager {
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error deleting files", e); System.out.println("Error deleting files" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -314,7 +318,7 @@ public class DatabaseManager {
preparedStatement.setString(3, cityName); preparedStatement.setString(3, cityName);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error adding recent weather", e); System.out.println("Error adding recent weather" + e);
} }
cleanUpRecent(userId); cleanUpRecent(userId);
return updatedRows > 0; return updatedRows > 0;
@ -330,7 +334,7 @@ public class DatabaseManager {
recentWeather.add(result.getString("cityName")); recentWeather.add(result.getString("cityName"));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting recent weather", e); System.out.println("Error getting recent weather" + e);
} }
return recentWeather; return recentWeather;
@ -343,7 +347,7 @@ public class DatabaseManager {
preparedStatement.setLong(2, userId); preparedStatement.setLong(2, userId);
preparedStatement.executeUpdate(); preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error cleaning up recent user", e); System.out.println("Error cleaning up recent user" + e);
} }
} }
@ -361,7 +365,7 @@ public class DatabaseManager {
} }
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error adding user for direction", e); System.out.println("Error adding user for direction" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -376,7 +380,7 @@ public class DatabaseManager {
status = result.getInt("status"); status = result.getInt("status");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting user destination status", e); System.out.println("Error getting user destination status" + e);
} }
return status; return status;
} }
@ -391,7 +395,7 @@ public class DatabaseManager {
messageId = result.getInt("messageId"); messageId = result.getInt("messageId");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting user destination message id", e); System.out.println("Error getting user destination message id" + e);
} }
return messageId; return messageId;
} }
@ -406,7 +410,7 @@ public class DatabaseManager {
origin = result.getString("origin"); origin = result.getString("origin");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error get user origin", e); System.out.println("Error get user origin" + e);
} }
return origin; return origin;
} }
@ -419,7 +423,7 @@ public class DatabaseManager {
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error deleting user directions", e); System.out.println("Error deleting user directions" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -432,7 +436,7 @@ public class DatabaseManager {
preparedStatement.setInt(2, updateId); preparedStatement.setInt(2, updateId);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error adding last update", e); System.out.println("Error adding last update" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -447,7 +451,7 @@ public class DatabaseManager {
updateId = result.getInt("updateId"); updateId = result.getInt("updateId");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting last update", e); System.out.println("Error getting last update" + e);
} }
return updateId; return updateId;
} }
@ -462,7 +466,7 @@ public class DatabaseManager {
languageCode = result.getString("languageCode"); languageCode = result.getString("languageCode");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting user language", e); System.out.println("Error getting user language" + e);
} }
return languageCode; return languageCode;
} }
@ -475,7 +479,7 @@ public class DatabaseManager {
preparedStatement.setString(2, language); preparedStatement.setString(2, language);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error updating user language", e); System.out.println("Error updating user language" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -491,7 +495,7 @@ public class DatabaseManager {
state = result.getInt("state"); state = result.getInt("state");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting weather state", e); System.out.println("Error getting weather state" + e);
} }
return state; return state;
} }
@ -505,7 +509,7 @@ public class DatabaseManager {
preparedStatement.setInt(3, state); preparedStatement.setInt(3, state);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error insert weather state", e); System.out.println("Error insert weather state" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -521,7 +525,7 @@ public class DatabaseManager {
cityId = result.getInt("cityId"); cityId = result.getInt("cityId");
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting recent weather by city", e); System.out.println("Error getting recent weather by city" + e);
} }
return cityId; return cityId;
@ -540,7 +544,7 @@ public class DatabaseManager {
addNewUserWeatherOptions(userId); addNewUserWeatherOptions(userId);
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting wether options", e); System.out.println("Error getting wether options" + e);
} }
return options; return options;
} }
@ -552,7 +556,7 @@ public class DatabaseManager {
preparedStatement.setLong(1, userId); preparedStatement.setLong(1, userId);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error adding new user weather options", e); System.out.println("Error adding new user weather options" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -565,7 +569,7 @@ public class DatabaseManager {
preparedStatement.setLong(2, userId); preparedStatement.setLong(2, userId);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error updating weather language options", e); System.out.println("Error updating weather language options" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -578,7 +582,7 @@ public class DatabaseManager {
preparedStatement.setLong(2, userId); preparedStatement.setLong(2, userId);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error adding weather unit option", e); System.out.println("Error adding weather unit option" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -592,7 +596,7 @@ public class DatabaseManager {
preparedStatement.setString(3, cityName); preparedStatement.setString(3, cityName);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error creating weather alert", e); System.out.println("Error creating weather alert" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -607,7 +611,7 @@ public class DatabaseManager {
alertCitiesNames.add(result.getString("cityName")); alertCitiesNames.add(result.getString("cityName"));
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting alerts by user", e); System.out.println("Error getting alerts by user" + e);
} }
return alertCitiesNames; return alertCitiesNames;
@ -621,7 +625,7 @@ public class DatabaseManager {
preparedStatement.setString(2, cityName); preparedStatement.setString(2, cityName);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error delete city alert", e); System.out.println("Error delete city alert" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -633,7 +637,7 @@ public class DatabaseManager {
preparedStatement.setLong(1, userId); preparedStatement.setLong(1, userId);
updatedRows = preparedStatement.executeUpdate(); updatedRows = preparedStatement.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error deleting alerts for user", e); System.out.println("Error deleting alerts for user" + e);
} }
return updatedRows > 0; return updatedRows > 0;
} }
@ -652,7 +656,7 @@ public class DatabaseManager {
allAlerts.add(weatherAlert); allAlerts.add(weatherAlert);
} }
} catch (SQLException e) { } catch (SQLException e) {
log.error("Error getting all alerts", e); System.out.println("Error getting all alerts" + e);
} }
return allAlerts; return allAlerts;

5
src/main/java/org/telegram/services/DirectionsService.java

@ -1,6 +1,5 @@
package org.telegram.services; package org.telegram.services;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
@ -22,7 +21,6 @@ import java.util.List;
* @version 1.0 * @version 1.0
* Weather service * Weather service
*/ */
@Slf4j
public class DirectionsService { public class DirectionsService {
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;
@ -101,7 +99,8 @@ public class DirectionsService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.warn("Error getting directions", e); // log.warn("Error getting directions", e);
System.out.println("Error getting directions" + 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

@ -1,6 +1,5 @@
package org.telegram.services; package org.telegram.services;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
@ -24,7 +23,6 @@ import java.util.Objects;
* @version 1.0 * @version 1.0
* Rae service * Rae service
*/ */
@Slf4j
public class RaeService { public class RaeService {
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=";
@ -69,7 +67,8 @@ public class RaeService {
} }
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Error getting RAE results", e); // log.error("Error getting RAE results", e);
System.out.println("Error getting RAE results" + e);
} }
return results; return results;
@ -111,7 +110,8 @@ public class RaeService {
} }
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Error getting results from search", e); // log.error("Error getting results from search", e);
System.out.println("Error getting results from search" + e);
} }
return results; return results;
@ -150,7 +150,8 @@ public class RaeService {
} }
} }
} catch (IOException e) { } catch (IOException e) {
log.error("Fetching words", e); // log.error("Fetching words", e);
System.out.println("Fetching words" + e);
} }
return results; return results;

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

@ -1,7 +1,5 @@
package org.telegram.services; package org.telegram.services;
import lombok.extern.slf4j.Slf4j;
import java.time.Clock; import java.time.Clock;
import java.time.Duration; import java.time.Duration;
import java.time.LocalDateTime; import java.time.LocalDateTime;
@ -14,7 +12,6 @@ import java.util.concurrent.TimeUnit;
* @version 2.0 * @version 2.0
* Execute a task periodically * Execute a task periodically
*/ */
@Slf4j
public class TimerExecutor { public class TimerExecutor {
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 +52,16 @@ 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) {
log.warn("Posting new task {}", task.getTaskName()); // log.warn("Posting new task {}", task.getTaskName());
System.out.println("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) {
log.error("Bot threw an unexpected exception at TimerExecutor", e); // log.error("Bot threw an unexpected exception at TimerExecutor", e);
System.out.println("Bot threw an unexpected exception at TimerExecutor" + e);
} }
}; };
if (task.getTimes() != 0) { if (task.getTimes() != 0) {
@ -103,9 +102,11 @@ public class TimerExecutor {
try { try {
executorService.awaitTermination(1, TimeUnit.DAYS); executorService.awaitTermination(1, TimeUnit.DAYS);
} catch (InterruptedException ex) { } catch (InterruptedException ex) {
log.error("Task interrupted", ex); // log.error("Task interrupted", ex);
System.out.println("Task interrupted" + ex);
} catch (Exception e) { } catch (Exception e) {
log.error("Bot threw an unexpected exception at TimerExecutor", e); // log.error("Bot threw an unexpected exception at TimerExecutor", e);
System.out.println("Bot threw an unexpected exception at TimerExecutor" + e);
} }
} }
} }

27
src/main/java/org/telegram/services/WeatherService.java

@ -1,6 +1,5 @@
package org.telegram.services; package org.telegram.services;
import lombok.extern.slf4j.Slf4j;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
@ -22,7 +21,6 @@ import java.time.format.DateTimeFormatter;
* @version 1.0 * @version 1.0
* Weather service * Weather service
*/ */
@Slf4j
public class WeatherService { public class WeatherService {
public static final String METRICSYSTEM = "metric"; public static final String METRICSYSTEM = "metric";
public static final String IMPERIALSYSTEM = "imperial"; public static final String IMPERIALSYSTEM = "imperial";
@ -89,7 +87,8 @@ public class WeatherService {
try (ResponseBody body = response.body()) { try (ResponseBody body = response.body()) {
if (body != null) { if (body != null) {
JSONObject jsonObject = new JSONObject(body.string()); JSONObject jsonObject = new JSONObject(body.string());
log.info("Alert fetched: {}", jsonObject); // log.info("Alert fetched: {}", jsonObject);
System.out.println("Alert fetched: " + jsonObject);
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") + ")";
@ -97,7 +96,7 @@ 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 {
log.warn("Unable to read alerts fetched {}", jsonObject); System.out.println("Unable to read alerts fetched " + jsonObject);
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} else { } else {
@ -109,7 +108,7 @@ public class WeatherService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error fetching alerts", e); System.out.println("Error fetching alerts" + e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -139,7 +138,7 @@ public class WeatherService {
try (ResponseBody body = response.body()) { try (ResponseBody body = response.body()) {
if (body != null) { if (body != null) {
JSONObject jsonObject = new JSONObject(body.string()); JSONObject jsonObject = new JSONObject(body.string());
log.info("Fetched weather forecast {}", jsonObject); System.out.println("Fetched weather forecast " + jsonObject);
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") + ")";
@ -147,7 +146,7 @@ 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 {
log.warn("City forecast not found {}", jsonObject); System.out.println("City forecast not found " + jsonObject);
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} else { } else {
@ -159,7 +158,7 @@ public class WeatherService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error fetching city forecast", e); System.out.println("Error fetching city forecast" + e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -196,7 +195,7 @@ 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 {
log.warn("No forecast for location found {}", jsonObject); System.out.println("No forecast for location found " + jsonObject);
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} else { } else {
@ -208,7 +207,7 @@ public class WeatherService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error fetching location forecast", e); System.out.println("Error fetching location forecast" + e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -247,7 +246,7 @@ 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 {
log.warn("No current weather found {}", jsonObject); System.out.println("No current weather found " + jsonObject);
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} else { } else {
@ -259,7 +258,7 @@ public class WeatherService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error fetching current weather", e); System.out.println("Error fetching current weather" + e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;
@ -296,7 +295,7 @@ 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 {
log.warn("No weather found for location {}", jsonObject); System.out.println("No weather found for location " + jsonObject);
responseToUser = LocalisationService.getString("cityNotFound", language); responseToUser = LocalisationService.getString("cityNotFound", language);
} }
} else { } else {
@ -308,7 +307,7 @@ public class WeatherService {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error fetching weather for location", e); System.out.println("Error fetching weather for location" + e);
responseToUser = LocalisationService.getString("errorFetchingWeather", language); responseToUser = LocalisationService.getString("errorFetchingWeather", language);
} }
return responseToUser; return responseToUser;

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

@ -1,6 +1,5 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer; import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
@ -20,7 +19,6 @@ import java.util.concurrent.ConcurrentHashMap;
* Handler for updates to channel updates bot * Handler for updates to channel updates bot
* This is a use case that will send a message to a channel if it is added as an admin to it. * This is a use case that will send a message to a channel if it is added as an admin to it.
*/ */
@Slf4j
public class ChannelHandlers implements LongPollingSingleThreadUpdateConsumer { public class ChannelHandlers implements LongPollingSingleThreadUpdateConsumer {
private static final int WAITINGCHANNEL = 1; private static final int WAITINGCHANNEL = 1;
@ -46,11 +44,13 @@ public class ChannelHandlers implements LongPollingSingleThreadUpdateConsumer {
try { try {
handleIncomingMessage(message); handleIncomingMessage(message);
} catch (InvalidObjectException e) { } catch (InvalidObjectException e) {
log.error("Channel Handler Error", e); // log.error("Channel Handler Error", e);
System.out.println("Channel Handler Error" + e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error handling channel message", e); // log.error("Error handling channel message", e);
System.out.println("Error handling channel message" + e);
} }
} }
@ -84,7 +84,8 @@ public class ChannelHandlers implements LongPollingSingleThreadUpdateConsumer {
} }
} }
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error waiting channel message", e); // log.error("Error waiting channel message", e);
System.out.println("Error waiting channel message" + e);
} }
} }
@ -108,7 +109,8 @@ public class ChannelHandlers implements LongPollingSingleThreadUpdateConsumer {
try { try {
telegramClient.execute(sendMessage); telegramClient.execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error sending error message", e); // log.error("Error sending error message", e);
System.out.println("Error sending error message" + e);
} }
} }
@ -142,7 +144,8 @@ public class ChannelHandlers implements LongPollingSingleThreadUpdateConsumer {
try { try {
telegramClient.execute(sendMessage); telegramClient.execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error sending help message", e); // log.error("Error sending help message", e);
System.out.println("Error sending help message" + e);
} }
} }
} }

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

@ -1,10 +1,10 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.commands.HelloCommand; import org.telegram.commands.HelloCommand;
import org.telegram.commands.HelpCommand; import org.telegram.commands.HelpCommand;
import org.telegram.commands.StartCommand; import org.telegram.commands.StartCommand;
import org.telegram.commands.StopCommand; import org.telegram.commands.StopCommand;
import org.telegram.commands.SuccessCommand;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.Emoji; import org.telegram.services.Emoji;
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
@ -19,7 +19,6 @@ import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
* *
* @author Timo Schulz (Mit0x2) * @author Timo Schulz (Mit0x2)
*/ */
@Slf4j
public class CommandsHandler extends CommandLongPollingTelegramBot { public class CommandsHandler extends CommandLongPollingTelegramBot {
/** /**
* Constructor. * Constructor.
@ -29,6 +28,7 @@ public class CommandsHandler extends CommandLongPollingTelegramBot {
register(new HelloCommand()); register(new HelloCommand());
register(new StartCommand()); register(new StartCommand());
register(new StopCommand()); register(new StopCommand());
register(new SuccessCommand());
HelpCommand helpCommand = new HelpCommand(this); HelpCommand helpCommand = new HelpCommand(this);
register(helpCommand); register(helpCommand);
@ -38,7 +38,8 @@ public class CommandsHandler extends CommandLongPollingTelegramBot {
try { try {
telegramClient.execute(commandUnknownMessage); telegramClient.execute(commandUnknownMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error sending message in commands bot", e); // log.error("Error sending message in commands bot", e);
System.out.println("Error sending message in commands bot" + e);
} }
helpCommand.execute(telegramClient, message.getFrom(), message.getChat(), new String[] {}); helpCommand.execute(telegramClient, message.getFrom(), message.getChat(), new String[] {});
}); });
@ -58,7 +59,8 @@ public class CommandsHandler extends CommandLongPollingTelegramBot {
try { try {
telegramClient.execute(echoMessage); telegramClient.execute(echoMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error processing non-command update", e); // log.error("Error processing non-command update", e);
System.out.println("Error processing non-command update" + e);
} }
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.Commands; import org.telegram.Commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.DirectionsService; import org.telegram.services.DirectionsService;
@ -27,7 +26,6 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* @version 1.0 * @version 1.0
* Handler for updates to Directions Bot * Handler for updates to Directions Bot
*/ */
@Slf4j
public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer { public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer {
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;
@ -43,7 +41,8 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
try { try {
handleDirections(update); handleDirections(update);
} catch (Exception e) { } catch (Exception e) {
log.error("Error processing update in directions bot", e); // log.error("Error processing update in directions bot", e);
System.out.println("Error processing update in directions bot" + e);
} }
} }
@ -80,7 +79,7 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
try { try {
telegramClient.execute(sendMessageRequest); telegramClient.execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error handling directions", e); System.out.println("Error handling directions" + e);
} }
} }
} }
@ -105,9 +104,9 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
if (sentMessage != null) { if (sentMessage != null) {
DatabaseManager.getInstance().deleteUserForDirections(message.getFrom().getId()); DatabaseManager.getInstance().deleteUserForDirections(message.getFrom().getId());
} }
}).thenAccept(unused -> log.info("Sent destination received")); }).thenAccept(unused -> System.out.println("Sent destination received"));
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error on destination received", e); System.out.println("Error on destination received" + e);
} }
} }
@ -126,9 +125,9 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
DatabaseManager.getInstance().addUserForDirection(message.getFrom().getId(), WATING_DESTINY_STATUS, DatabaseManager.getInstance().addUserForDirection(message.getFrom().getId(), WATING_DESTINY_STATUS,
sentMessage.getMessageId(), message.getText()); sentMessage.getMessageId(), message.getText());
} }
}).thenAccept(unused -> log.info("Sent origin received")); }).thenAccept(unused -> System.out.println("Sent origin received"));
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error on origin received", e); System.out.println("Error on origin received" + e);
} }
} }
@ -140,7 +139,7 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
try { try {
telegramClient.execute(sendMessageRequest); telegramClient.execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error sending help", e); System.out.println("Error sending help" + e);
} }
} }
@ -156,9 +155,9 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
DatabaseManager.getInstance().addUserForDirection(message.getFrom().getId(), WATING_ORIGIN_STATUS, DatabaseManager.getInstance().addUserForDirection(message.getFrom().getId(), WATING_ORIGIN_STATUS,
sentMessage.getMessageId(), null); sentMessage.getMessageId(), null);
} }
}).thenAccept(unused -> log.info("Sent start directions")); }).thenAccept(unused -> System.out.println("Sent start directions"));
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error on start directions", e); System.out.println("Error on start directions" + e);
} }
} }
@ -181,7 +180,7 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
telegramClient.execute(sendMessageRequest); telegramClient.execute(sendMessageRequest);
languageMessages.add(message.getFrom().getId()); languageMessages.add(message.getFrom().getId());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error setting language", e); System.out.println("Error setting language" + e);
} }
} }
@ -202,7 +201,7 @@ public class DirectionsHandlers implements LongPollingSingleThreadUpdateConsumer
telegramClient.execute(sendMessageRequestBuilder.build()); telegramClient.execute(sendMessageRequestBuilder.build());
languageMessages.remove(message.getFrom().getId()); languageMessages.remove(message.getFrom().getId());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error on lanaguage selected", e); System.out.println("Error on lanaguage selected" + e);
} }
} }
} }

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

@ -1,7 +1,6 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer; import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer;
import org.telegram.telegrambots.meta.api.methods.AnswerCallbackQuery; import org.telegram.telegrambots.meta.api.methods.AnswerCallbackQuery;
@ -26,7 +25,6 @@ import java.util.ArrayList;
* This bot is an example for using inline buttons, here to make a gallery. * This bot is an example for using inline buttons, here to make a gallery.
* Bot contains some images from ElektrollArt that are all licensed under creative commons * Bot contains some images from ElektrollArt that are all licensed under creative commons
*/ */
@Slf4j
public class ElektrollArtFanHandler implements LongPollingSingleThreadUpdateConsumer { public class ElektrollArtFanHandler implements LongPollingSingleThreadUpdateConsumer {
private final ArrayList<String[]> urls; private final ArrayList<String[]> urls;
@ -90,7 +88,8 @@ public class ElektrollArtFanHandler implements LongPollingSingleThreadUpdateCons
try { try {
telegramClient.execute(sendMessagerequest); telegramClient.execute(sendMessagerequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error sending start message", e); // log.error("Error sending start message", e);
System.out.println("Error sending start message" + e);
} }
} }
} }
@ -117,7 +116,8 @@ public class ElektrollArtFanHandler implements LongPollingSingleThreadUpdateCons
try { try {
this.sendAnswerCallbackQuery("Please use one of the given actions below, instead.", false, callbackquery); this.sendAnswerCallbackQuery("Please use one of the given actions below, instead.", false, callbackquery);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Send text response", e); // log.error("Send text response", e);
System.out.println("Send text response" + e);
} }
} }
@ -125,7 +125,8 @@ public class ElektrollArtFanHandler implements LongPollingSingleThreadUpdateCons
try { try {
this.sendAnswerCallbackQuery(INDEX_OUT_OF_RANGE, false, callbackquery); this.sendAnswerCallbackQuery(INDEX_OUT_OF_RANGE, false, callbackquery);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Send index out of range response", e); // log.error("Send index out of range response", e);
System.out.println("Send index out of range response" + e);
} }
} else { } else {
@ -138,7 +139,8 @@ public class ElektrollArtFanHandler implements LongPollingSingleThreadUpdateCons
try { try {
telegramClient.execute(editMarkup); telegramClient.execute(editMarkup);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error updating markup", e); // log.error("Error updating markup", e);
System.out.println("Error updating markup" + e);
} }
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.Commands; import org.telegram.Commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.Emoji; import org.telegram.services.Emoji;
@ -32,7 +31,6 @@ import java.util.concurrent.ConcurrentLinkedQueue;
* Handler for updates to Files Bot * Handler for updates to Files Bot
* This bot is an example for the use of sendMessage asynchronously * This bot is an example for the use of sendMessage asynchronously
*/ */
@Slf4j
public class FilesHandlers implements LongPollingSingleThreadUpdateConsumer { public class FilesHandlers implements LongPollingSingleThreadUpdateConsumer {
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;
@ -56,11 +54,13 @@ public class FilesHandlers implements LongPollingSingleThreadUpdateConsumer {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Error handling file update", e); // log.error("Error handling file update", e);
System.out.println("Error handling file update" + e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Unknown exception", e); // log.error("Unknown exception", e);
System.out.println("Unknown exception" + e);
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.services.RaeService; import org.telegram.services.RaeService;
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer; import org.telegram.telegrambots.longpolling.util.LongPollingSingleThreadUpdateConsumer;
@ -24,7 +23,6 @@ import java.util.List;
* @version 1.0 * @version 1.0
* Handler for inline queries in Raebot * Handler for inline queries in Raebot
*/ */
@Slf4j
public class RaeHandlers implements LongPollingSingleThreadUpdateConsumer { public class RaeHandlers implements LongPollingSingleThreadUpdateConsumer {
private static final Integer CACHETIME = 86400; private static final Integer CACHETIME = 86400;
private final RaeService raeService = new RaeService(); private final RaeService raeService = new RaeService();
@ -51,11 +49,13 @@ public class RaeHandlers implements LongPollingSingleThreadUpdateConsumer {
try { try {
telegramClient.execute(getHelpMessage(update.getMessage())); telegramClient.execute(getHelpMessage(update.getMessage()));
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error", e); // log.error("Error", e);
System.out.println("Error" + e);
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Unknown exception", e); // log.error("Unknown exception", e);
System.out.println("Error" + e);
} }
} }
@ -65,7 +65,8 @@ public class RaeHandlers implements LongPollingSingleThreadUpdateConsumer {
*/ */
private void handleIncomingInlineQuery(InlineQuery inlineQuery) { private void handleIncomingInlineQuery(InlineQuery inlineQuery) {
String query = inlineQuery.getQuery(); String query = inlineQuery.getQuery();
log.debug("Searching: {}", query); // log.debug("Searching: {}", query);
System.out.println("Searching: " + query);
try { try {
if (!query.isEmpty()) { if (!query.isEmpty()) {
List<RaeService.RaeResult> results = raeService.getResults(query); List<RaeService.RaeResult> results = raeService.getResults(query);
@ -74,7 +75,8 @@ public class RaeHandlers implements LongPollingSingleThreadUpdateConsumer {
telegramClient.execute(converteResultsToResponse(inlineQuery, new ArrayList<>())); telegramClient.execute(converteResultsToResponse(inlineQuery, new ArrayList<>()));
} }
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.error("Error handing inline query", e); // log.error("Error handing inline query", e);
System.out.println("Error handing inline query" + e);
} }
} }

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

@ -1,6 +1,5 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.Commands; import org.telegram.Commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.CustomTimerTask; import org.telegram.services.CustomTimerTask;
@ -32,7 +31,6 @@ import java.util.List;
* @version 1.0 * @version 1.0
* Handler for updates to Weather Bot * Handler for updates to Weather Bot
*/ */
@Slf4j
public class WeatherHandlers implements LongPollingSingleThreadUpdateConsumer { public class WeatherHandlers implements LongPollingSingleThreadUpdateConsumer {
private static final int STARTSTATE = 0; private static final int STARTSTATE = 0;
private static final int MAINMENU = 1; private static final int MAINMENU = 1;
@ -66,7 +64,8 @@ public class WeatherHandlers implements LongPollingSingleThreadUpdateConsumer {
} }
} }
} catch (Exception e) { } catch (Exception e) {
log.error("Weather Handler error", e); // log.error("Weather Handler error", e);
System.out.println("Weather Handler error" + e);
} }
} }
@ -93,7 +92,8 @@ public class WeatherHandlers implements LongPollingSingleThreadUpdateConsumer {
try { try {
Thread.currentThread().wait(35); Thread.currentThread().wait(35);
} catch (InterruptedException e) { } catch (InterruptedException e) {
log.error("Error sleeping for alerts", e); // log.error("Error sleeping for alerts", e);
System.out.println("Error sleeping for alerts" + e);
} }
} }
String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId()); String[] userOptions = DatabaseManager.getInstance().getUserWeatherOptions(weatherAlert.getUserId());
@ -104,12 +104,14 @@ public class WeatherHandlers implements LongPollingSingleThreadUpdateConsumer {
try { try {
telegramClient.execute(sendMessage); telegramClient.execute(sendMessage);
} catch (TelegramApiRequestException e) { } catch (TelegramApiRequestException e) {
log.warn("Error sending alerts", e); // log.warn("Error sending alerts", e);
System.out.println("Error sending alerts" + 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) {
log.error("Unknown error sending alerts", e); // log.error("Unknown error sending alerts", e);
System.out.println("Unknown error sending alerts" + e);
} }
} }
} }

8
src/main/java/org/telegram/updateshandlers/WebHookExampleHandlers.java

@ -1,6 +1,5 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import lombok.extern.slf4j.Slf4j;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.BuildVars; import org.telegram.BuildVars;
import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient; import org.telegram.telegrambots.client.okhttp.OkHttpTelegramClient;
@ -18,7 +17,6 @@ import org.telegram.telegrambots.webhook.TelegramWebhookBot;
* @version 1.0 * @version 1.0
* Simple Webhook example * Simple Webhook example
*/ */
@Slf4j
public class WebHookExampleHandlers implements TelegramWebhookBot { public class WebHookExampleHandlers implements TelegramWebhookBot {
private final TelegramClient telegramClient; private final TelegramClient telegramClient;
@ -44,7 +42,8 @@ public class WebHookExampleHandlers implements TelegramWebhookBot {
try { try {
telegramClient.execute(new DeleteWebhook()); telegramClient.execute(new DeleteWebhook());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.info("Error deleting webhook"); // log.info("Error deleting webhook");
System.out.println("Error deleting webhook" + e);
} }
} }
@ -56,7 +55,8 @@ public class WebHookExampleHandlers implements TelegramWebhookBot {
.url(BuildVars.EXTERNALWEBHOOKURL + getBotPath()) .url(BuildVars.EXTERNALWEBHOOKURL + getBotPath())
.build()); .build());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
log.info("Error setting webhook"); // log.info("Error setting webhook");
System.out.println("Error setting webhook" + e);
} }
} }

Loading…
Cancel
Save