Browse Source

Update version 4.0.1

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

7
pom.xml

@ -12,7 +12,7 @@
<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.3</httpcompontents.version>
<telegrambots.version>3.0</telegrambots.version> <telegrambots.version>4.0.1</telegrambots.version>
<json.version>20160810</json.version> <json.version>20160810</json.version>
<jsoup.version>1.10.2</jsoup.version> <jsoup.version>1.10.2</jsoup.version>
<mysql.version>6.0.6</mysql.version> <mysql.version>6.0.6</mysql.version>
@ -25,6 +25,11 @@
<artifactId>telegrambots</artifactId> <artifactId>telegrambots</artifactId>
<version>${telegrambots.version}</version> <version>${telegrambots.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.telegram</groupId>
<artifactId>telegrambotsextensions</artifactId>
<version>${telegrambots.version}</version>
</dependency>
<dependency> <dependency>
<groupId>org.json</groupId> <groupId>org.json</groupId>
<artifactId>json</artifactId> <artifactId>json</artifactId>

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

@ -1,19 +1,11 @@
package org.telegram; package org.telegram;
import org.telegram.telegrambots.ApiContextInitializer; import org.telegram.telegrambots.ApiContextInitializer;
import org.telegram.telegrambots.TelegramBotsApi; import org.telegram.telegrambots.meta.TelegramBotsApi;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import org.telegram.telegrambots.logging.BotsFileHandler; import org.telegram.telegrambots.meta.logging.BotsFileHandler;
import org.telegram.updateshandlers.ChannelHandlers; import org.telegram.updateshandlers.*;
import org.telegram.updateshandlers.CommandsHandler;
import org.telegram.updateshandlers.DirectionsHandlers;
import org.telegram.updateshandlers.ElektrollArtFanHandler;
import org.telegram.updateshandlers.FilesHandlers;
import org.telegram.updateshandlers.RaeHandlers;
import org.telegram.updateshandlers.TransifexHandlers;
import org.telegram.updateshandlers.WeatherHandlers;
import org.telegram.updateshandlers.WebHookExampleHandlers;
import java.io.IOException; import java.io.IOException;
import java.util.logging.ConsoleHandler; import java.util.logging.ConsoleHandler;
@ -48,7 +40,7 @@ public class Main {
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()); 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); BotLogger.error(LOGTAG, e);

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

@ -1,13 +1,13 @@
package org.telegram.commands; package org.telegram.commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.api.objects.Chat; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.User; import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.bots.AbsSender; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.bots.commands.BotCommand; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.logging.BotLogger; 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
@ -47,7 +47,7 @@ public class HelloCommand extends BotCommand {
answer.setText(messageTextBuilder.toString()); answer.setText(messageTextBuilder.toString());
try { try {
absSender.sendMessage(answer); absSender.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }

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

@ -1,14 +1,15 @@
package org.telegram.commands; package org.telegram.commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.api.objects.Chat; import org.telegram.telegrambots.extensions.bots.commandbot.commands.IBotCommand;
import org.telegram.telegrambots.api.objects.User; import org.telegram.telegrambots.extensions.bots.commandbot.commands.ICommandRegistry;
import org.telegram.telegrambots.bots.AbsSender; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.bots.commands.BotCommand; import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.bots.commands.ICommandRegistry; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.logging.BotLogger; 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
@ -36,7 +37,7 @@ public class HelpCommand extends BotCommand {
StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n"); StringBuilder helpMessageBuilder = new StringBuilder("<b>Help</b>\n");
helpMessageBuilder.append("These are the registered commands for this Bot:\n\n"); helpMessageBuilder.append("These are the registered commands for this Bot:\n\n");
for (BotCommand botCommand : commandRegistry.getRegisteredCommands()) { for (IBotCommand botCommand : commandRegistry.getRegisteredCommands()) {
helpMessageBuilder.append(botCommand.toString()).append("\n\n"); helpMessageBuilder.append(botCommand.toString()).append("\n\n");
} }
@ -46,7 +47,7 @@ public class HelpCommand extends BotCommand {
helpMessage.setText(helpMessageBuilder.toString()); helpMessage.setText(helpMessageBuilder.toString());
try { try {
absSender.sendMessage(helpMessage); absSender.execute(helpMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }

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

@ -1,13 +1,13 @@
package org.telegram.commands; package org.telegram.commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.api.objects.Chat; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.User; import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.bots.AbsSender; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.bots.commands.BotCommand; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
/** /**
* This commands starts the conversation with the bot * This commands starts the conversation with the bot
@ -43,7 +43,7 @@ public class StartCommand extends BotCommand {
answer.setText(messageBuilder.toString()); answer.setText(messageBuilder.toString());
try { try {
absSender.sendMessage(answer); absSender.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }

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

@ -1,13 +1,13 @@
package org.telegram.commands; package org.telegram.commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.extensions.bots.commandbot.commands.BotCommand;
import org.telegram.telegrambots.api.objects.Chat; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.User; import org.telegram.telegrambots.meta.api.objects.Chat;
import org.telegram.telegrambots.bots.AbsSender; import org.telegram.telegrambots.meta.api.objects.User;
import org.telegram.telegrambots.bots.commands.BotCommand; import org.telegram.telegrambots.meta.bots.AbsSender;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
/** /**
* This commands stops the conversation with the bot. * This commands stops the conversation with the bot.
@ -39,7 +39,7 @@ public class StopCommand extends BotCommand {
answer.setText("Good bye " + userName + "\n" + "Hope to see you soon!"); answer.setText("Good bye " + userName + "\n" + "Hope to see you soon!");
try { try {
absSender.sendMessage(answer); absSender.execute(answer);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }

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

@ -8,21 +8,14 @@
package org.telegram.database; package org.telegram.database;
import org.telegram.BuildVars; import org.telegram.BuildVars;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.sql.Connection; import java.sql.*;
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
* @version 2.0 * @version 2.0
* @brief Connector to database * Connector to database
* @date 3/12/14
*/ */
public class ConectionDB { public class ConectionDB {
private static final String LOGTAG = "CONNECTIONDB"; private static final String LOGTAG = "CONNECTIONDB";

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

@ -8,7 +8,7 @@
package org.telegram.database; package org.telegram.database;
import org.telegram.structure.WeatherAlert; import org.telegram.structure.WeatherAlert;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;

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

@ -12,7 +12,7 @@ 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.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;

2
src/main/java/org/telegram/services/RaeService.java

@ -12,7 +12,7 @@ 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.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.IOException; import java.io.IOException;
import java.net.URLEncoder; import java.net.URLEncoder;

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

@ -1,6 +1,6 @@
package org.telegram.services; package org.telegram.services;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.time.Clock; import java.time.Clock;
import java.time.Duration; import java.time.Duration;
@ -12,8 +12,7 @@ import java.util.concurrent.TimeUnit;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
* @version 2.0 * @version 2.0
* @brief Exectue a task periodically * Execute a task periodically
* @date 27/01/25
*/ */
public class TimerExecutor { public class TimerExecutor {
private static final String LOGTAG = "TIMEREXECUTOR"; private static final String LOGTAG = "TIMEREXECUTOR";
@ -99,7 +98,7 @@ public class TimerExecutor {
/** /**
* Stop the thread * Stop the thread
*/ */
public void stop() { private void stop() {
executorService.shutdown(); executorService.shutdown();
try { try {
executorService.awaitTermination(1, TimeUnit.DAYS); executorService.awaitTermination(1, TimeUnit.DAYS);

26
src/main/java/org/telegram/services/TransifexService.java

@ -8,16 +8,10 @@ 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.telegram.BuildVars; import org.telegram.BuildVars;
import org.telegram.telegrambots.api.methods.send.SendDocument; import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.BufferedReader; import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
/** /**
* @author Ruben Bermudez * @author Ruben Bermudez
@ -199,7 +193,7 @@ public class TransifexService {
localFile.close(); localFile.close();
File fileToUpload = new File(fileName); File fileToUpload = new File(fileName);
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -226,7 +220,7 @@ public class TransifexService {
localFile.close(); localFile.close();
File fileToUpload = new File(fileName); File fileToUpload = new File(fileName);
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -254,7 +248,7 @@ public class TransifexService {
IOUtils.write(file, output); IOUtils.write(file, output);
output.close(); output.close();
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -281,7 +275,7 @@ public class TransifexService {
IOUtils.write(file, output); IOUtils.write(file, output);
output.close(); output.close();
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} catch (IOException e) { } catch (IOException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -309,7 +303,7 @@ public class TransifexService {
output.close(); output.close();
if (fileToUpload.exists()) { if (fileToUpload.exists()) {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -338,7 +332,7 @@ public class TransifexService {
output.close(); output.close();
if (fileToUpload.exists()) { if (fileToUpload.exists()) {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
@ -367,7 +361,7 @@ public class TransifexService {
output.close(); output.close();
if (fileToUpload.exists()) { if (fileToUpload.exists()) {
sendDocument = new SendDocument(); sendDocument = new SendDocument();
sendDocument.setNewDocument(fileToUpload.getAbsoluteFile()); sendDocument.setDocument(fileToUpload);
} }
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

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

@ -11,7 +11,7 @@ import org.apache.http.util.EntityUtils;
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.logging.BotLogger; import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
@ -162,7 +162,7 @@ public class WeatherService {
try { try {
String completURL = BASEURL + FORECASTPATH + "?lat=" + URLEncoder.encode(latitude + "", "UTF-8") + "&lon=" String completURL = BASEURL + FORECASTPATH + "?lat=" + URLEncoder.encode(latitude + "", "UTF-8") + "&lon="
+ URLEncoder.encode(longitude + "", "UTF-8") + + URLEncoder.encode(longitude + "", "UTF-8") +
FORECASTPARAMS.replace("@language@", language).replace("@units@", units) + APIIDEND;; FORECASTPARAMS.replace("@language@", language).replace("@units@", units) + APIIDEND;
CloseableHttpClient client = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); CloseableHttpClient client = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
HttpGet request = new HttpGet(completURL); HttpGet request = new HttpGet(completURL);
CloseableHttpResponse response = client.execute(request); CloseableHttpResponse response = client.execute(request);
@ -242,7 +242,7 @@ public class WeatherService {
try { try {
String completURL = BASEURL + CURRENTPATH + "?lat=" + URLEncoder.encode(latitude + "", "UTF-8") + "&lon=" String completURL = BASEURL + CURRENTPATH + "?lat=" + URLEncoder.encode(latitude + "", "UTF-8") + "&lon="
+ URLEncoder.encode(longitude + "", "UTF-8") + + URLEncoder.encode(longitude + "", "UTF-8") +
CURRENTPARAMS.replace("@language@", language).replace("@units@", units) + APIIDEND;; CURRENTPARAMS.replace("@language@", language).replace("@units@", units) + APIIDEND;
CloseableHttpClient client = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); CloseableHttpClient client = HttpClientBuilder.create().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();
HttpGet request = new HttpGet(completURL); HttpGet request = new HttpGet(completURL);
CloseableHttpResponse response = client.execute(request); CloseableHttpResponse response = client.execute(request);

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

@ -1,14 +1,14 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
@ -84,11 +84,11 @@ public class ChannelHandlers extends TelegramLongPollingBot {
sendHelpMessage(message.getChatId(), message.getMessageId(), null); sendHelpMessage(message.getChatId(), message.getMessageId(), null);
} else { } else {
if (message.getText().startsWith("@") && !message.getText().trim().contains(" ")) { if (message.getText().startsWith("@") && !message.getText().trim().contains(" ")) {
sendMessage(getMessageToChannelSent(message)); execute(getMessageToChannelSent(message));
sendMessageToChannel(message.getText(), message); sendMessageToChannel(message.getText(), message);
userState.remove(message.getFrom().getId()); userState.remove(message.getFrom().getId());
} else { } else {
sendMessage(getWrongUsernameMessage(message)); execute(getWrongUsernameMessage(message));
} }
} }
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
@ -105,7 +105,7 @@ public class ChannelHandlers extends TelegramLongPollingBot {
sendMessage.enableMarkdown(true); sendMessage.enableMarkdown(true);
try { try {
sendMessage(sendMessage); execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
sendErrorMessage(message, e.getMessage()); sendErrorMessage(message, e.getMessage());
} }
@ -121,7 +121,7 @@ public class ChannelHandlers extends TelegramLongPollingBot {
sendMessage.enableMarkdown(true); sendMessage.enableMarkdown(true);
try { try {
sendMessage(sendMessage); execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -163,7 +163,7 @@ public class ChannelHandlers extends TelegramLongPollingBot {
sendMessage.setText(HELP_TEXT); sendMessage.setText(HELP_TEXT);
try { try {
sendMessage(sendMessage); execute(sendMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }

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

@ -7,12 +7,12 @@ import org.telegram.commands.StartCommand;
import org.telegram.commands.StopCommand; import org.telegram.commands.StopCommand;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.Emoji; import org.telegram.services.Emoji;
import org.telegram.telegrambots.api.methods.send.SendMessage; import org.telegram.telegrambots.extensions.bots.commandbot.TelegramLongPollingCommandBot;
import org.telegram.telegrambots.api.objects.Message; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.bots.TelegramLongPollingCommandBot; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.logging.BotLogger; 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
@ -26,7 +26,9 @@ public class CommandsHandler extends TelegramLongPollingCommandBot {
/** /**
* Constructor. * Constructor.
*/ */
public CommandsHandler() { public CommandsHandler(String botUsername) {
super(botUsername);
register(new HelloCommand()); register(new HelloCommand());
register(new StartCommand()); register(new StartCommand());
register(new StopCommand()); register(new StopCommand());
@ -38,7 +40,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot {
commandUnknownMessage.setChatId(message.getChatId()); commandUnknownMessage.setChatId(message.getChatId());
commandUnknownMessage.setText("The command '" + message.getText() + "' is not known by this bot. Here comes some help " + Emoji.AMBULANCE); commandUnknownMessage.setText("The command '" + message.getText() + "' is not known by this bot. Here comes some help " + Emoji.AMBULANCE);
try { try {
absSender.sendMessage(commandUnknownMessage); absSender.execute(commandUnknownMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -62,7 +64,7 @@ public class CommandsHandler extends TelegramLongPollingCommandBot {
echoMessage.setText("Hey heres your message:\n" + message.getText()); echoMessage.setText("Hey heres your message:\n" + message.getText());
try { try {
sendMessage(echoMessage); execute(echoMessage);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -70,11 +72,6 @@ public class CommandsHandler extends TelegramLongPollingCommandBot {
} }
} }
@Override
public String getBotUsername() {
return BotConfig.COMMANDS_USER;
}
@Override @Override
public String getBotToken() { public String getBotToken() {
return BotConfig.COMMANDS_TOKEN; return BotConfig.COMMANDS_TOKEN;

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

@ -5,19 +5,19 @@ import org.telegram.Commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.DirectionsService; import org.telegram.services.DirectionsService;
import org.telegram.services.LocalisationService; import org.telegram.services.LocalisationService;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardRemove;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.updateshandlers.SentCallback; import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardRemove;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import org.telegram.telegrambots.meta.updateshandlers.SentCallback;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.ArrayList; import java.util.ArrayList;
@ -90,7 +90,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(LocalisationService.getString("youNeedReplyDirections", language)); sendMessageRequest.setText(LocalisationService.getString("youNeedReplyDirections", language));
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
try { try {
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -114,7 +114,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
for (String direction : directions) { for (String direction : directions) {
sendMessageRequest.setText(direction); sendMessageRequest.setText(direction);
try { try {
sendMessageAsync(sendMessageRequest, new SentCallback<Message>() { executeAsync(sendMessageRequest, new SentCallback<Message>() {
@Override @Override
public void onResult(BotApiMethod<Message> botApiMethod, Message sentMessage) { public void onResult(BotApiMethod<Message> botApiMethod, Message sentMessage) {
if (sentMessage != null) { if (sentMessage != null) {
@ -147,7 +147,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(LocalisationService.getString("sendDestination", language)); sendMessageRequest.setText(LocalisationService.getString("sendDestination", language));
try { try {
sendMessageAsync(sendMessageRequest, new SentCallback<Message>() { executeAsync(sendMessageRequest, new SentCallback<Message>() {
@Override @Override
public void onResult(BotApiMethod<Message> method, Message sentMessage) { public void onResult(BotApiMethod<Message> method, Message sentMessage) {
if (sentMessage != null) { if (sentMessage != null) {
@ -178,7 +178,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(helpDirectionsFormated); sendMessageRequest.setText(helpDirectionsFormated);
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
try { try {
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -194,7 +194,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(LocalisationService.getString("initDirections", language)); sendMessageRequest.setText(LocalisationService.getString("initDirections", language));
try { try {
sendMessageAsync(sendMessageRequest, new SentCallback<Message>() { executeAsync(sendMessageRequest, new SentCallback<Message>() {
@Override @Override
public void onResult(BotApiMethod<Message> method, Message sentMessage) { public void onResult(BotApiMethod<Message> method, Message sentMessage) {
if (sentMessage != null) { if (sentMessage != null) {
@ -235,7 +235,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup); sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language)); sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
try { try {
sendMessage(sendMessageRequest); execute(sendMessageRequest);
languageMessages.add(message.getFrom().getId()); languageMessages.add(message.getFrom().getId());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
@ -257,7 +257,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
replyKeyboardRemove.setSelective(true); replyKeyboardRemove.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardRemove); sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
try { try {
sendMessage(sendMessageRequest); execute(sendMessageRequest);
languageMessages.remove(message.getFrom().getId()); languageMessages.remove(message.getFrom().getId());
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);

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

@ -1,20 +1,20 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import java.util.ArrayList;
import java.util.List;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.telegrambots.api.methods.AnswerCallbackQuery;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.api.objects.CallbackQuery;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.AnswerCallbackQuery;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.meta.api.objects.CallbackQuery;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import java.util.ArrayList;
import java.util.List;
/** /**
@ -90,7 +90,7 @@ public class ElektrollArtFanHandler extends TelegramLongPollingBot {
try { try {
sendMessage(sendMessagerequest); execute(sendMessagerequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -140,7 +140,7 @@ public class ElektrollArtFanHandler extends TelegramLongPollingBot {
editMarkup.setMessageId(callbackquery.getMessage().getMessageId()); editMarkup.setMessageId(callbackquery.getMessage().getMessageId());
editMarkup.setReplyMarkup(markup); editMarkup.setReplyMarkup(markup);
try { try {
editMessageText(editMarkup); execute(editMarkup);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -164,7 +164,7 @@ public class ElektrollArtFanHandler extends TelegramLongPollingBot {
answerCallbackQuery.setCallbackQueryId(callbackquery.getId()); answerCallbackQuery.setCallbackQueryId(callbackquery.getId());
answerCallbackQuery.setShowAlert(alert); answerCallbackQuery.setShowAlert(alert);
answerCallbackQuery.setText(text); answerCallbackQuery.setText(text);
answerCallbackQuery(answerCallbackQuery); execute(answerCallbackQuery);
} }
/** /**

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

@ -5,17 +5,17 @@ import org.telegram.Commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.Emoji; import org.telegram.services.Emoji;
import org.telegram.services.LocalisationService; import org.telegram.services.LocalisationService;
import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardRemove;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardRemove;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.ArrayList; import java.util.ArrayList;
@ -109,7 +109,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(LocalisationService.getString("fileUploaded", language) + sendMessageRequest.setText(LocalisationService.getString("fileUploaded", language) +
LocalisationService.getString("uploadedFileURL", language) + message.getDocument().getFileId()); LocalisationService.getString("uploadedFileURL", language) + message.getDocument().getFileId());
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
} }
@ -128,7 +128,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
} }
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessageRequest.setReplyMarkup(new ReplyKeyboardRemove()); sendMessageRequest.setReplyMarkup(new ReplyKeyboardRemove());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
private void onDeleteCommand(Message message, String language, String[] parts) throws InvalidObjectException, TelegramApiException { private void onDeleteCommand(Message message, String language, String[] parts) throws InvalidObjectException, TelegramApiException {
@ -160,7 +160,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
replyKeyboardMarkup.setKeyboard(commands); replyKeyboardMarkup.setKeyboard(commands);
} }
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup); sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
private void onDeleteCommandWithParameters(Message message, String language, String part) throws InvalidObjectException, TelegramApiException { private void onDeleteCommandWithParameters(Message message, String language, String part) throws InvalidObjectException, TelegramApiException {
@ -174,7 +174,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
} }
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
DatabaseManager.getInstance().deleteUserForFile(message.getFrom().getId()); DatabaseManager.getInstance().deleteUserForFile(message.getFrom().getId());
} }
@ -184,7 +184,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
SendMessage sendMessageRequest = new SendMessage(); SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getString("processFinished", language)); sendMessageRequest.setText(LocalisationService.getString("processFinished", language));
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
private void onUploadCommand(Message message, String language) throws InvalidObjectException, TelegramApiException { private void onUploadCommand(Message message, String language) throws InvalidObjectException, TelegramApiException {
@ -192,7 +192,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
SendMessage sendMessageRequest = new SendMessage(); SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getString("sendFileToUpload", language)); sendMessageRequest.setText(LocalisationService.getString("sendFileToUpload", language));
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
private void sendHelpMessage(Message message, String language) throws InvalidObjectException, TelegramApiException { private void sendHelpMessage(Message message, String language) throws InvalidObjectException, TelegramApiException {
@ -203,7 +203,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
Commands.listCommand); Commands.listCommand);
sendMessageRequest.setText(formatedString); sendMessageRequest.setText(formatedString);
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
private void onStartWithParameters(Message message, String language, String part) throws InvalidObjectException, TelegramApiException { private void onStartWithParameters(Message message, String language, String part) throws InvalidObjectException, TelegramApiException {
@ -211,12 +211,12 @@ public class FilesHandlers extends TelegramLongPollingBot {
SendDocument sendDocumentRequest = new SendDocument(); SendDocument sendDocumentRequest = new SendDocument();
sendDocumentRequest.setDocument(part.trim()); sendDocumentRequest.setDocument(part.trim());
sendDocumentRequest.setChatId(message.getChatId()); sendDocumentRequest.setChatId(message.getChatId());
sendDocument(sendDocumentRequest); execute(sendDocumentRequest);
} else { } else {
SendMessage sendMessageRequest = new SendMessage(); SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language)); sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language));
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
} }
@ -237,7 +237,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
replyKeyboardMarkup.setSelective(true); replyKeyboardMarkup.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup); sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language)); sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
sendMessage(sendMessageRequest); execute(sendMessageRequest);
languageMessages.add(message.getFrom().getId()); languageMessages.add(message.getFrom().getId());
} }
@ -255,7 +255,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove(); ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
replyKeyboardRemove.setSelective(true); replyKeyboardRemove.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardRemove); sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
sendMessage(sendMessageRequest); execute(sendMessageRequest);
languageMessages.remove(message.getFrom().getId()); languageMessages.remove(message.getFrom().getId());
} }
} }

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

@ -2,17 +2,17 @@ package org.telegram.updateshandlers;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.services.RaeService; import org.telegram.services.RaeService;
import org.telegram.telegrambots.api.methods.AnswerInlineQuery;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.inlinequery.InlineQuery;
import org.telegram.telegrambots.api.objects.inlinequery.inputmessagecontent.InputTextMessageContent;
import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.api.objects.inlinequery.result.InlineQueryResultArticle;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.AnswerInlineQuery;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.inlinequery.InlineQuery;
import org.telegram.telegrambots.meta.api.objects.inlinequery.inputmessagecontent.InputTextMessageContent;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResult;
import org.telegram.telegrambots.meta.api.objects.inlinequery.result.InlineQueryResultArticle;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -48,7 +48,7 @@ public class RaeHandlers extends TelegramLongPollingBot {
handleIncomingInlineQuery(update.getInlineQuery()); handleIncomingInlineQuery(update.getInlineQuery());
} else if (update.hasMessage() && update.getMessage().isUserMessage()) { } else if (update.hasMessage() && update.getMessage().isUserMessage()) {
try { try {
sendMessage(getHelpMessage(update.getMessage())); execute(getHelpMessage(update.getMessage()));
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -73,9 +73,9 @@ public class RaeHandlers extends TelegramLongPollingBot {
try { try {
if (!query.isEmpty()) { if (!query.isEmpty()) {
List<RaeService.RaeResult> results = raeService.getResults(query); List<RaeService.RaeResult> results = raeService.getResults(query);
answerInlineQuery(converteResultsToResponse(inlineQuery, results)); execute(converteResultsToResponse(inlineQuery, results));
} else { } else {
answerInlineQuery(converteResultsToResponse(inlineQuery, new ArrayList<>())); execute(converteResultsToResponse(inlineQuery, new ArrayList<>()));
} }
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);

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

@ -6,15 +6,15 @@ import org.telegram.Commands;
import org.telegram.database.DatabaseManager; import org.telegram.database.DatabaseManager;
import org.telegram.services.LocalisationService; import org.telegram.services.LocalisationService;
import org.telegram.services.TransifexService; import org.telegram.services.TransifexService;
import org.telegram.telegrambots.api.methods.send.SendDocument;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.send.SendDocument;
import org.telegram.telegrambots.logging.BotLogger; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.InlineKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.InlineKeyboardButton;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.io.InvalidObjectException; import java.io.InvalidObjectException;
import java.util.ArrayList; import java.util.ArrayList;
@ -89,7 +89,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(helpFormated); sendMessageRequest.setText(helpFormated);
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
try { try {
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -98,7 +98,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
if (sendDocument != null) { if (sendDocument != null) {
sendDocument.setChatId(message.getChatId()); sendDocument.setChatId(message.getChatId());
try { try {
sendDocument(sendDocument); execute(sendDocument);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -114,7 +114,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
sendMessageRequest.setText(helpFormated); sendMessageRequest.setText(helpFormated);
sendMessageRequest.setChatId(message.getChatId()); sendMessageRequest.setChatId(message.getChatId());
try { try {
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} catch (TelegramApiException e) { } catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e); BotLogger.error(LOGTAG, e);
} }
@ -137,6 +137,6 @@ public class TransifexHandlers extends TelegramLongPollingBot {
rows.add(row); rows.add(row);
inlineKeyboardMarkup.setKeyboard(rows); inlineKeyboardMarkup.setKeyboard(rows);
answer.setReplyMarkup(inlineKeyboardMarkup); answer.setReplyMarkup(inlineKeyboardMarkup);
sendMessage(answer); execute(answer);
} }
} }

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

@ -3,24 +3,20 @@ package org.telegram.updateshandlers;
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;
import org.telegram.services.CustomTimerTask; import org.telegram.services.*;
import org.telegram.services.Emoji;
import org.telegram.services.LocalisationService;
import org.telegram.services.TimerExecutor;
import org.telegram.services.WeatherService;
import org.telegram.structure.WeatherAlert; import org.telegram.structure.WeatherAlert;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.ForceReplyKeyboard;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboard;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.api.objects.replykeyboard.ReplyKeyboardRemove;
import org.telegram.telegrambots.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.bots.TelegramLongPollingBot; import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import org.telegram.telegrambots.exceptions.TelegramApiException; import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.exceptions.TelegramApiRequestException; import org.telegram.telegrambots.meta.api.objects.Message;
import org.telegram.telegrambots.logging.BotLogger; 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.ReplyKeyboard;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardMarkup;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.ReplyKeyboardRemove;
import org.telegram.telegrambots.meta.api.objects.replykeyboard.buttons.KeyboardRow;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.meta.exceptions.TelegramApiRequestException;
import org.telegram.telegrambots.meta.logging.BotLogger;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -113,7 +109,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(String.valueOf(weatherAlert.getUserId())); sendMessage.setChatId(String.valueOf(weatherAlert.getUserId()));
sendMessage.setText(weather); sendMessage.setText(weather);
try { try {
sendMessage(sendMessage); execute(sendMessage);
} catch (TelegramApiRequestException e) { } catch (TelegramApiRequestException e) {
BotLogger.warn(LOGTAG, e); BotLogger.warn(LOGTAG, 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")) {
@ -184,7 +180,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
break; break;
} }
sendMessage(sendMessageRequest); execute(sendMessageRequest);
} }
private void sendHideKeyboard(Integer userId, Long chatId, Integer messageId) throws TelegramApiException { private void sendHideKeyboard(Integer userId, Long chatId, Integer messageId) throws TelegramApiException {
@ -198,7 +194,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
replyKeyboardRemove.setSelective(true); replyKeyboardRemove.setSelective(true);
sendMessage.setReplyMarkup(replyKeyboardRemove); sendMessage.setReplyMarkup(replyKeyboardRemove);
sendMessage(sendMessage); execute(sendMessage);
DatabaseManager.getInstance().insertWeatherState(userId, chatId, STARTSTATE); DatabaseManager.getInstance().insertWeatherState(userId, chatId, STARTSTATE);
} }

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

@ -1,16 +1,15 @@
package org.telegram.updateshandlers; package org.telegram.updateshandlers;
import org.telegram.BotConfig; import org.telegram.BotConfig;
import org.telegram.telegrambots.api.methods.BotApiMethod;
import org.telegram.telegrambots.api.methods.send.SendMessage;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramWebhookBot; import org.telegram.telegrambots.bots.TelegramWebhookBot;
import org.telegram.telegrambots.meta.api.methods.BotApiMethod;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
/** /**
* @author pithera * @author pithera
* @version 1.0 * @version 1.0
* @brief Simple Webhook example * Simple Webhook example
* @date 31 of May of 2016
*/ */
public class WebHookExampleHandlers extends TelegramWebhookBot { public class WebHookExampleHandlers extends TelegramWebhookBot {
@Override @Override

Loading…
Cancel
Save