Browse Source

Merge pull request #36 from rubenlagus/dev

Dev
master
Ruben Bermudez 9 years ago
committed by GitHub
parent
commit
0f59ff21c8
  1. 30
      pom.xml
  2. 3
      src/main/java/org/telegram/BotConfig.java
  3. 2
      src/main/java/org/telegram/BuildVars.java
  4. 2
      src/main/java/org/telegram/Main.java
  5. 8
      src/main/java/org/telegram/services/DirectionsService.java
  6. 292
      src/main/java/org/telegram/services/LocalisationService.java
  7. 46
      src/main/java/org/telegram/services/WeatherService.java
  8. 40
      src/main/java/org/telegram/updateshandlers/DirectionsHandlers.java
  9. 226
      src/main/java/org/telegram/updateshandlers/ElektrollArtFanHandler.java
  10. 53
      src/main/java/org/telegram/updateshandlers/FilesHandlers.java
  11. 57
      src/main/java/org/telegram/updateshandlers/TransifexHandlers.java
  12. 124
      src/main/java/org/telegram/updateshandlers/WeatherHandlers.java
  13. 0
      src/main/resources/strings.properties
  14. 0
      src/main/resources/strings_eo.properties
  15. 0
      src/main/resources/strings_es.properties
  16. 0
      src/main/resources/strings_it.properties
  17. 0
      src/main/resources/strings_nl.properties
  18. 0
      src/main/resources/strings_pt.properties

30
pom.xml

@ -11,10 +11,12 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<httpcompontents.version>4.5.2</httpcompontents.version>
<telegrambots.version>2.4.2</telegrambots.version>
<httpcompontents.version>4.5.3</httpcompontents.version>
<telegrambots.version>3.0</telegrambots.version>
<json.version>20160810</json.version>
<mysql.version>6.0.4</mysql.version>
<jsoup.version>1.10.2</jsoup.version>
<mysql.version>6.0.6</mysql.version>
<commonsio.version>2.5</commonsio.version>
</properties>
<dependencies>
@ -31,7 +33,7 @@
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
<version>${commonsio.version}</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
@ -51,7 +53,7 @@
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.9.2</version>
<version>${jsoup.version}</version>
</dependency>
</dependencies>
@ -139,6 +141,24 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-enforcer-plugin</artifactId>
<version>1.4.1</version>
<executions>
<execution>
<id>enforce</id>
<goals>
<goal>enforce</goal>
</goals>
</execution>
</executions>
<configuration>
<rules>
<DependencyConvergence />
</rules>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>

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

@ -30,4 +30,7 @@ public class BotConfig {
public static final String COMMANDS_TOKEN = "<token>";
public static final String COMMANDS_USER = "MyCommandsBot";
public static final String ELEKTROLLART_TOKEN = "<token>";
public static final String ELEKTROLLART_USER = "ElektrollArtFanBot";
}

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

@ -31,7 +31,7 @@ public class BuildVars {
public static final String pathToLogs = "./";
public static final String linkDB = "jdbc:mysql://localhost:3306/YOURDATABSENAME?useUnicode=true&characterEncoding=UTF-8";
public static final String controllerDB = "com.mysql.jdbc.Driver";
public static final String controllerDB = "com.mysql.cj.jdbc.Driver";
public static final String userDB = "<your-database-user>";
public static final String password = "<your-databas-user-password>";

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

@ -8,6 +8,7 @@ import org.telegram.telegrambots.logging.BotsFileHandler;
import org.telegram.updateshandlers.ChannelHandlers;
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;
@ -48,6 +49,7 @@ public class Main {
telegramBotsApi.registerBot(new TransifexHandlers());
telegramBotsApi.registerBot(new FilesHandlers());
telegramBotsApi.registerBot(new CommandsHandler());
telegramBotsApi.registerBot(new ElektrollArtFanHandler());
} catch (TelegramApiException e) {
BotLogger.error(LOGTAG, e);
}

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

@ -84,7 +84,7 @@ public class DirectionsService {
JSONObject jsonObject = new JSONObject(responseContent);
if (jsonObject.getString("status").equals("OK")) {
JSONObject route = jsonObject.getJSONArray("routes").getJSONObject(0);
String startOfAddress = LocalisationService.getInstance().getString("directionsInit", language);
String startOfAddress = LocalisationService.getString("directionsInit", language);
String partialResponseToUser = String.format(startOfAddress,
route.getJSONArray("legs").getJSONObject(0).getString("start_address"),
route.getJSONArray("legs").getJSONObject(0).getJSONObject("distance").getString("text"),
@ -95,11 +95,11 @@ public class DirectionsService {
responseToUser.addAll(getDirectionsSteps(
route.getJSONArray("legs").getJSONObject(0).getJSONArray("steps"), language));
} else {
responseToUser.add(LocalisationService.getInstance().getString("directionsNotFound", language));
responseToUser.add(LocalisationService.getString("directionsNotFound", language));
}
} catch (Exception e) {
BotLogger.warn(LOGTAG, e);
responseToUser.add(LocalisationService.getInstance().getString("errorFetchingDirections", language));
responseToUser.add(LocalisationService.getString("errorFetchingDirections", language));
}
return responseToUser;
}
@ -126,7 +126,7 @@ public class DirectionsService {
}
private String getDirectionForStep(JSONObject jsonObject, String language) {
String direction = LocalisationService.getInstance().getString("directionsStep", language);
String direction = LocalisationService.getString("directionsStep", language);
String htmlIntructions = Jsoup.parse(jsonObject.getString("html_instructions")).text();
String duration = jsonObject.getJSONObject("duration").getString("text");
String distance = jsonObject.getJSONObject("distance").getString("text");

292
src/main/java/org/telegram/services/LocalisationService.java

@ -1,134 +1,61 @@
package org.telegram.services;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.MissingResourceException;
import java.util.PropertyResourceBundle;
import java.util.ResourceBundle;
/**
* @author Ruben Bermudez
* @version 1.0
* @brief Localisation
* @date 25/01/15
*/
public class LocalisationService {
private static LocalisationService instance = null;
private final HashMap<String, String> supportedLanguages = new HashMap<>();
private ResourceBundle english;
private ResourceBundle spanish;
private ResourceBundle dutch;
private ResourceBundle german;
private ResourceBundle italian;
private ResourceBundle french;
private ResourceBundle malayalam;
private ResourceBundle hindi;
private ResourceBundle portuguese;
private ResourceBundle portuguesebr;
private ResourceBundle russian;
private ResourceBundle arabic;
private ResourceBundle catalan;
private ResourceBundle galician;
private ResourceBundle persian;
private ResourceBundle turkish;
private ResourceBundle esperanto;
private class CustomClassLoader extends ClassLoader {
public CustomClassLoader(ClassLoader parent) {
super(parent);
private static final String STRINGS_FILE = "strings";
private static final Object lock = new Object();
}
private static final List<Language> supportedLanguages = new ArrayList<>();
private static final Utf8ResourceBundle defaultLanguage;
private static final Utf8ResourceBundle spanish;
private static final Utf8ResourceBundle dutch;
private static final Utf8ResourceBundle italian;
private static final Utf8ResourceBundle portuguese;
private static final Utf8ResourceBundle esperanto;
public InputStream getResourceAsStream(String name) {
InputStream utf8in = getParent().getResourceAsStream(name);
if (utf8in != null) {
try {
byte[] utf8Bytes = new byte[utf8in.available()];
utf8in.read(utf8Bytes, 0, utf8Bytes.length);
byte[] iso8859Bytes = new String(utf8Bytes, "UTF-8").getBytes("ISO-8859-1");
return new ByteArrayInputStream(iso8859Bytes);
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
utf8in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
static {
synchronized (lock) {
defaultLanguage = new Utf8ResourceBundle(STRINGS_FILE, Locale.ROOT);
supportedLanguages.add(new Language("en", "English"));
spanish = new Utf8ResourceBundle(STRINGS_FILE, new Locale("es", "ES"));
supportedLanguages.add(new Language("es", "Español"));
portuguese = new Utf8ResourceBundle(STRINGS_FILE, new Locale("pt", "PT"));
supportedLanguages.add(new Language("pt", "Português"));
dutch = new Utf8ResourceBundle(STRINGS_FILE, new Locale("nl", "NL"));
supportedLanguages.add(new Language("nl", "Nederlands"));
italian = new Utf8ResourceBundle(STRINGS_FILE, new Locale("it", "IT"));
supportedLanguages.add(new Language("it", "Italiano"));
esperanto = new Utf8ResourceBundle(STRINGS_FILE, new Locale("eo", "EO"));
supportedLanguages.add(new Language("eo", "Esperanto"));
}
}
/**
* Singleton
*
* @return Instance of localisation service
*/
public static LocalisationService getInstance() {
if (instance == null) {
synchronized (LocalisationService.class) {
if (instance == null) {
instance = new LocalisationService();
}
}
}
return instance;
}
/**
* Private constructor due to singleton
*/
private LocalisationService() {
CustomClassLoader loader = new CustomClassLoader(Thread.currentThread().getContextClassLoader());
english = ResourceBundle.getBundle("localisation.strings", new Locale("en", "US"), loader);
supportedLanguages.put("en", "English");
spanish = ResourceBundle.getBundle("localisation.strings", new Locale("es", "ES"), loader);
supportedLanguages.put("es", "Español");
portuguese = ResourceBundle.getBundle("localisation.strings", new Locale("pt", "PT"), loader);
supportedLanguages.put("pt", "Português");
dutch = ResourceBundle.getBundle("localisation.strings", new Locale("nl", "NL"), loader);
supportedLanguages.put("nl", "Nederlands");
italian = ResourceBundle.getBundle("localisation.strings", new Locale("it", "IT"), loader);
supportedLanguages.put("it", "Italiano");
esperanto = ResourceBundle.getBundle("localisation.strings", new Locale("eo", "EO"), loader);
supportedLanguages.put("eo", "Esperanto");
/*
german = ResourceBundle.getBundle("localisation.strings", new Locale("de", "DE"), loader);
supportedLanguages.put("de", "Deutsch");
italian = ResourceBundle.getBundle("localisation.strings", new Locale("it", "IT"), loader);
supportedLanguages.put("it", "Italian");
french = ResourceBundle.getBundle("localisation.strings", new Locale("fr", "FR"), loader);
supportedLanguages.put("fr", "French");
portuguesebr = ResourceBundle.getBundle("localisation.strings", new Locale("pt", "BR"), loader);
supportedLanguages.put("pt_br", "Portuguese BR");*/
/**
malayalam = ResourceBundle.getBundle("localisation.strings", new Locale("ml", "ML"), loader);
hindi = ResourceBundle.getBundle("localisation.strings", new Locale("hi", "HI"), loader);
russian = ResourceBundle.getBundle("localisation.strings", new Locale("ru", "RU"), loader);
arabic = ResourceBundle.getBundle("localisation.strings", new Locale("ar", "AR"), loader);
catalan = ResourceBundle.getBundle("localisation.strings", new Locale("ca", "CA"), loader);
galician = ResourceBundle.getBundle("localisation.strings", new Locale("gl", "ES"), loader);
persian = ResourceBundle.getBundle("localisation.strings", new Locale("fa", "FA"), loader);
turkish = ResourceBundle.getBundle("localisation.strings", new Locale("tr", "TR"), loader);
*/
}
/**
* Get a string in default language (en)
*
* @param key key of the resource to fetch
* @return fetched string or error message otherwise
*/
public String getString(String key) {
public static String getString(String key) {
String result;
try {
result = english.getString(key);
result = defaultLanguage.getString(key);
} catch (MissingResourceException e) {
result = "String not found";
}
@ -142,13 +69,10 @@ public class LocalisationService {
* @param key key of the resource to fetch
* @return fetched string or error message otherwise
*/
public String getString(String key, String language) {
public static String getString(String key, String language) {
String result;
try {
switch (language.toLowerCase()) {
case "en":
result = english.getString(key);
break;
case "es":
result = spanish.getString(key);
break;
@ -164,55 +88,127 @@ public class LocalisationService {
case "eo":
result = esperanto.getString(key);
break;
/*case "de":
result = german.getString(key);
break;
case "fr":
result = french.getString(key);
break;
case "ml":
result = malayalam.getString(key);
break;
case "hi":
result = hindi.getString(key);
break;
case "pt-BR":
result = portuguesebr.getString(key);
break;
case "ru":
result = russian.getString(key);
break;
case "ar":
result = arabic.getString(key);
break;
case "ca":
result = catalan.getString(key);
break;
case "gl":
result = galician.getString(key);
break;
case "fa":
result = persian.getString(key);
break;
case "tr":
result = turkish.getString(key);
break;*/
default:
result = english.getString(key);
result = defaultLanguage.getString(key);
break;
}
} catch (MissingResourceException e) {
result = english.getString(key);
result = defaultLanguage.getString(key);
}
return result;
}
public HashMap<String, String> getSupportedLanguages() {
public static List<Language> getSupportedLanguages() {
return supportedLanguages;
}
public String getLanguageCodeByName(String language) {
return supportedLanguages.entrySet().stream().filter(x -> x.getValue().equals(language)).findFirst().get().getKey();
public static Language getLanguageByCode(String languageCode) {
return supportedLanguages.stream().filter(x -> x.getCode().equals(languageCode)).findFirst().orElse(null);
}
public static Language getLanguageByName(String languageName) {
return supportedLanguages.stream().filter(x -> x.getName().equals(languageName)).findFirst().orElse(null);
}
public static String getLanguageCodeByName(String language) {
return supportedLanguages.stream().filter(x -> x.getName().equals(language))
.map(Language::getCode).findFirst().orElse(null);
}
public static class Language {
private String code;
private String name;
private String emoji;
public Language(String code, String name) {
this.code = code;
this.name = name;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmoji() {
return emoji;
}
public void setEmoji(String emoji) {
this.emoji = emoji;
}
@Override
public String toString() {
if (emoji == null || emoji.isEmpty()) {
return name;
} else {
return emoji + " " + name;
}
}
}
private static class Utf8ResourceBundle extends ResourceBundle {
private static final String BUNDLE_EXTENSION = "properties";
private static final String CHARSET = "UTF-8";
private static final ResourceBundle.Control UTF8_CONTROL = new UTF8Control();
Utf8ResourceBundle(String bundleName, Locale locale) {
setParent(ResourceBundle.getBundle(bundleName, locale, UTF8_CONTROL));
}
@Override
protected Object handleGetObject(String key) {
return parent.getObject(key);
}
@Override
public Enumeration<String> getKeys() {
return parent.getKeys();
}
private static class UTF8Control extends Control {
public ResourceBundle newBundle
(String baseName, Locale locale, String format, ClassLoader loader, boolean reload)
throws IllegalAccessException, InstantiationException, IOException {
String bundleName = toBundleName(baseName, locale);
String resourceName = toResourceName(bundleName, BUNDLE_EXTENSION);
ResourceBundle bundle = null;
InputStream stream = null;
if (reload) {
URL url = loader.getResource(resourceName);
if (url != null) {
URLConnection connection = url.openConnection();
if (connection != null) {
connection.setUseCaches(false);
stream = connection.getInputStream();
}
}
} else {
stream = loader.getResourceAsStream(resourceName);
}
if (stream != null) {
try {
bundle = new PropertyResourceBundle(new InputStreamReader(stream, CHARSET));
} finally {
stream.close();
}
}
return bundle;
}
}
}
}
}

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

@ -96,15 +96,15 @@ public class WeatherService {
cityFound = jsonObject.getJSONObject("city").getString("name") + " (" +
jsonObject.getJSONObject("city").getString("country") + ")";
saveRecentWeather(userId, cityFound, jsonObject.getJSONObject("city").getInt("id"));
responseToUser = String.format(LocalisationService.getInstance().getString("weatherAlert", language),
responseToUser = String.format(LocalisationService.getString("weatherAlert", language),
cityFound, convertListOfForecastToString(jsonObject, language, units, false));
} else {
BotLogger.warn(LOGTAG, jsonObject.toString());
responseToUser = LocalisationService.getInstance().getString("cityNotFound", language);
responseToUser = LocalisationService.getString("cityNotFound", language);
}
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
responseToUser = LocalisationService.getInstance().getString("errorFetchingWeather", language);
responseToUser = LocalisationService.getString("errorFetchingWeather", language);
}
return responseToUser;
}
@ -137,15 +137,15 @@ public class WeatherService {
cityFound = jsonObject.getJSONObject("city").getString("name") + " (" +
jsonObject.getJSONObject("city").getString("country") + ")";
saveRecentWeather(userId, cityFound, jsonObject.getJSONObject("city").getInt("id"));
responseToUser = String.format(LocalisationService.getInstance().getString("weatherForcast", language),
responseToUser = String.format(LocalisationService.getString("weatherForcast", language),
cityFound, convertListOfForecastToString(jsonObject, language, units, true));
} else {
BotLogger.warn(LOGTAG, jsonObject.toString());
responseToUser = LocalisationService.getInstance().getString("cityNotFound", language);
responseToUser = LocalisationService.getString("cityNotFound", language);
}
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
responseToUser = LocalisationService.getInstance().getString("errorFetchingWeather", language);
responseToUser = LocalisationService.getString("errorFetchingWeather", language);
}
return responseToUser;
}
@ -156,7 +156,7 @@ public class WeatherService {
* @return userHash to be send to use
* @note Forecast for the following 3 days
*/
public String fetchWeatherForecastByLocation(Double longitude, Double latitude, Integer userId, String language, String units) {
public String fetchWeatherForecastByLocation(Float longitude, Float latitude, Integer userId, String language, String units) {
String cityFound;
String responseToUser;
try {
@ -176,15 +176,15 @@ public class WeatherService {
cityFound = jsonObject.getJSONObject("city").getString("name") + " (" +
jsonObject.getJSONObject("city").getString("country") + ")";
saveRecentWeather(userId, cityFound, jsonObject.getJSONObject("city").getInt("id"));
responseToUser = String.format(LocalisationService.getInstance().getString("weatherForcast", language),
responseToUser = String.format(LocalisationService.getString("weatherForcast", language),
cityFound, convertListOfForecastToString(jsonObject, language, units, true));
} else {
BotLogger.warn(LOGTAG, jsonObject.toString());
responseToUser = LocalisationService.getInstance().getString("cityNotFound", language);
responseToUser = LocalisationService.getString("cityNotFound", language);
}
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
responseToUser = LocalisationService.getInstance().getString("errorFetchingWeather", language);
responseToUser = LocalisationService.getString("errorFetchingWeather", language);
}
return responseToUser;
}
@ -217,15 +217,15 @@ public class WeatherService {
jsonObject.getJSONObject("sys").getString("country") + ")";
saveRecentWeather(userId, cityFound, jsonObject.getInt("id"));
emoji = getEmojiForWeather(jsonObject.getJSONArray("weather").getJSONObject(0));
responseToUser = String.format(LocalisationService.getInstance().getString("weatherCurrent", language),
responseToUser = String.format(LocalisationService.getString("weatherCurrent", language),
cityFound, convertCurrentWeatherToString(jsonObject, language, units, emoji));
} else {
BotLogger.warn(LOGTAG, jsonObject.toString());
responseToUser = LocalisationService.getInstance().getString("cityNotFound", language);
responseToUser = LocalisationService.getString("cityNotFound", language);
}
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
responseToUser = LocalisationService.getInstance().getString("errorFetchingWeather", language);
responseToUser = LocalisationService.getString("errorFetchingWeather", language);
}
return responseToUser;
}
@ -236,7 +236,7 @@ public class WeatherService {
* @return userHash to be send to use
* @note Forecast for the following 3 days
*/
public String fetchWeatherCurrentByLocation(Double longitude, Double latitude, Integer userId, String language, String units) {
public String fetchWeatherCurrentByLocation(Float longitude, Float latitude, Integer userId, String language, String units) {
String cityFound;
String responseToUser;
try {
@ -256,15 +256,15 @@ public class WeatherService {
cityFound = jsonObject.getString("name") + " (" +
jsonObject.getJSONObject("sys").getString("country") + ")";
saveRecentWeather(userId, cityFound, jsonObject.getInt("id"));
responseToUser = String.format(LocalisationService.getInstance().getString("weatherCurrent", language),
responseToUser = String.format(LocalisationService.getString("weatherCurrent", language),
cityFound, convertCurrentWeatherToString(jsonObject, language, units, null));
} else {
BotLogger.warn(LOGTAG, jsonObject.toString());
responseToUser = LocalisationService.getInstance().getString("cityNotFound", language);
responseToUser = LocalisationService.getString("cityNotFound", language);
}
} catch (Exception e) {
BotLogger.error(LOGTAG, e);
responseToUser = LocalisationService.getInstance().getString("errorFetchingWeather", language);
responseToUser = LocalisationService.getString("errorFetchingWeather", language);
}
return responseToUser;
}
@ -276,9 +276,9 @@ public class WeatherService {
String responseToUser;
if (units.equals(METRICSYSTEM)) {
responseToUser = LocalisationService.getInstance().getString("currentWeatherPartMetric", language);
responseToUser = LocalisationService.getString("currentWeatherPartMetric", language);
} else {
responseToUser = LocalisationService.getInstance().getString("currentWeatherPartImperial", language);
responseToUser = LocalisationService.getString("currentWeatherPartImperial", language);
}
responseToUser = String.format(responseToUser, emoji == null ? weatherDesc : emoji.toString(), cloudiness, temp);
@ -321,15 +321,15 @@ public class WeatherService {
if (units.equals(METRICSYSTEM)) {
if (addDate) {
responseToUser = LocalisationService.getInstance().getString("forecastWeatherPartMetric", language);
responseToUser = LocalisationService.getString("forecastWeatherPartMetric", language);
} else {
responseToUser = LocalisationService.getInstance().getString("alertWeatherPartMetric", language);
responseToUser = LocalisationService.getString("alertWeatherPartMetric", language);
}
} else {
if (addDate) {
responseToUser = LocalisationService.getInstance().getString("forecastWeatherPartImperial", language);
responseToUser = LocalisationService.getString("forecastWeatherPartImperial", language);
} else {
responseToUser = LocalisationService.getInstance().getString("alertWeatherPartImperial", language);
responseToUser = LocalisationService.getString("alertWeatherPartImperial", language);
}
}
if (addDate) {

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

@ -10,8 +10,8 @@ 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.ReplyKeyboardHide;
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.exceptions.TelegramApiException;
@ -21,9 +21,7 @@ import org.telegram.telegrambots.updateshandlers.SentCallback;
import java.io.InvalidObjectException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentLinkedQueue;
/**
@ -89,7 +87,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
sendHelpMessage(message, language);
} else {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getInstance().getString("youNeedReplyDirections", language));
sendMessageRequest.setText(LocalisationService.getString("youNeedReplyDirections", language));
sendMessageRequest.setChatId(message.getChatId());
try {
sendMessage(sendMessageRequest);
@ -109,9 +107,9 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
List<String> directions = DirectionsService.getInstance().getDirections(origin, destiny, language);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide();
replyKeyboardHide.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardHide);
ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
replyKeyboardRemove.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
sendMessageRequest.setReplyToMessageId(message.getMessageId());
for (String direction : directions) {
sendMessageRequest.setText(direction);
@ -146,7 +144,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard();
forceReplyKeyboard.setSelective(true);
sendMessageRequest.setReplyMarkup(forceReplyKeyboard);
sendMessageRequest.setText(LocalisationService.getInstance().getString("sendDestination", language));
sendMessageRequest.setText(LocalisationService.getString("sendDestination", language));
try {
sendMessageAsync(sendMessageRequest, new SentCallback<Message>() {
@ -175,7 +173,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
private void sendHelpMessage(Message message, String language) throws InvalidObjectException {
SendMessage sendMessageRequest = new SendMessage();
String helpDirectionsFormated = String.format(
LocalisationService.getInstance().getString("helpDirections", language),
LocalisationService.getString("helpDirections", language),
Commands.startDirectionCommand);
sendMessageRequest.setText(helpDirectionsFormated);
sendMessageRequest.setChatId(message.getChatId());
@ -193,7 +191,7 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
ForceReplyKeyboard forceReplyKeyboard = new ForceReplyKeyboard();
forceReplyKeyboard.setSelective(true);
sendMessageRequest.setReplyMarkup(forceReplyKeyboard);
sendMessageRequest.setText(LocalisationService.getInstance().getString("initDirections", language));
sendMessageRequest.setText(LocalisationService.getString("initDirections", language));
try {
sendMessageAsync(sendMessageRequest, new SentCallback<Message>() {
@ -223,19 +221,19 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
HashMap<String, String> languages = LocalisationService.getInstance().getSupportedLanguages();
List<LocalisationService.Language> languages = LocalisationService.getSupportedLanguages();
List<KeyboardRow> commands = new ArrayList<>();
for (Map.Entry<String, String> entry : languages.entrySet()) {
for (LocalisationService.Language languageItem : languages) {
KeyboardRow commandRow = new KeyboardRow();
commandRow.add(entry.getKey() + " --> " + entry.getValue());
commandRow.add(languageItem.getCode() + " --> " + languageItem.getName());
commands.add(commandRow);
}
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
replyKeyboardMarkup.setKeyboard(commands);
replyKeyboardMarkup.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
sendMessageRequest.setText(LocalisationService.getInstance().getString("chooselanguage", language));
sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
try {
sendMessage(sendMessageRequest);
languageMessages.add(message.getFrom().getId());
@ -248,16 +246,16 @@ public class DirectionsHandlers extends TelegramLongPollingBot {
String[] parts = message.getText().split("-->", 2);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
if (LocalisationService.getInstance().getSupportedLanguages().containsKey(parts[0].trim())) {
if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) {
DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim());
sendMessageRequest.setText(LocalisationService.getInstance().getString("languageModified", parts[0].trim()));
sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim()));
} else {
sendMessageRequest.setText(LocalisationService.getInstance().getString("errorLanguage"));
sendMessageRequest.setText(LocalisationService.getString("errorLanguage"));
}
sendMessageRequest.setReplyToMessageId(message.getMessageId());
ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide();
replyKeyboardHide.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardHide);
ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
replyKeyboardRemove.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
try {
sendMessage(sendMessageRequest);
languageMessages.remove(message.getFrom().getId());

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

@ -0,0 +1,226 @@
package org.telegram.updateshandlers;
import java.util.ArrayList;
import java.util.List;
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.exceptions.TelegramApiException;
/**
* @author Clevero
* @version 1.0
* @brief Handler for updates to ElektrollArtFanBot
* 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
* @date 28 of October of 2016
*/
public class ElektrollArtFanHandler extends TelegramLongPollingBot {
private ArrayList<String[]> urls;
final private String BACK = "⬅️ Back";
final private String NEXT = "Next ➡️";
final private String INDEX_OUT_OF_RANGE = "Requested index is out of range!";
public ElektrollArtFanHandler() {
this.urls = new ArrayList<>();
this.addUrls();
}
@Override
public String getBotUsername() {
return BotConfig.ELEKTROLLART_USER;
}
private void addUrls(){
/*
* Just some sample links of my fav images from elektrollart.de
*/
this.urls.add(new String[]{"http://www.elektrollart.de/?p=2964", "http://www.elektrollart.de/wp-content/uploads/deer-724x1024.png", "Deer Nature (cc-by)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=2960", "http://www.elektrollart.de/wp-content/uploads/butterfly_wallpaper_by_elektroll-d424m9d-1024x576.png", "Butterfly Wallpaper (cc-by)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=2897", "http://www.elektrollart.de/wp-content/uploads/ilovefs_wallpaper-1024x576.png", "I Love Free Software – Wallpaper (CC0)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=3953", "http://www.elektrollart.de/wp-content/uploads/diaspora_wallpaper_by_elektroll-d4anyj4-1024x576.png", "diaspora Wallpaper (CC-BY-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=549", "http://www.elektrollart.de/wp-content/uploads/diaspora_flower-1024x576.png", "Diaspora Digital Wallpaper (CC-BY-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=534", "http://www.elektrollart.de/wp-content/uploads/debian-butterfly-1024x576.png", "Debian-Butterfly Wallpaper (CC-BY-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=531", "http://www.elektrollart.de/wp-content/uploads/cc-white-1920x1080-1024x576.png", "CC-Wallpaper (CC-BY-NC-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=526", "http://www.elektrollart.de/wp-content/uploads/debian-gal-1920x1080-1024x576.png", "Debian Wallpaper (CC-BY-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=523", "http://www.elektrollart.de/wp-content/uploads/Ubuntusplash-1920x1080-1024x576.png", "Ubuntu Wallpaper (CC-BY-NC-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=559", "http://www.elektrollart.de/wp-content/uploads/skullgirll_a-1024x576.png", "Skullgirl Wallpapers (CC-BY-NC-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=559", "http://www.elektrollart.de/wp-content/uploads/skullgirll_b-1024x576.png", "Skullgirl Wallpapers (CC-BY-NC-SA)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=847", "http://www.elektrollart.de/wp-content/uploads/archlinux_wallpaper-1024x576.png", "ArchLinux (CC0)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=1381", "http://www.elektrollart.de/wp-content/uploads/tuxxi-small-724x1024.png", "Piep (CC-BY)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=4264", "http://www.elektrollart.de/wp-content/uploads/Thngs_left_unsaid-724x1024.jpg", "Things Left Unsaid (CC-BY)"});
this.urls.add(new String[]{"http://www.elektrollart.de/?p=2334", "http://www.elektrollart.de/wp-content/uploads/redpanda-1024x826.png", "<3 mozilla (CC0)"});
}
@Override
public void onUpdateReceived(Update update) {
//check if the update has a message
if(update.hasMessage()){
Message message = update.getMessage();
//check if the message contains a text
if(message.hasText()){
String input = message.getText();
if(input.equals("/start")){
SendMessage sendMessagerequest = new SendMessage();
sendMessagerequest.setChatId(message.getChatId().toString());
/*
* we just add the first link from our array
*
* We use markdown to embedd the image
*/
sendMessagerequest.setText("[​](" + this.urls.get(0)[1] + ")");
sendMessagerequest.enableMarkdown(true);
sendMessagerequest.setReplyMarkup(this.getGalleryView(0, -1));
try {
sendMessage(sendMessagerequest);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
else if(update.hasCallbackQuery()){
CallbackQuery callbackquery = update.getCallbackQuery();
String[] data = callbackquery.getData().split(":");
int index = Integer.parseInt(data[2]);
if(data[0].equals("gallery")){
InlineKeyboardMarkup markup = null;
if(data[1].equals("back")){
markup = this.getGalleryView(Integer.parseInt(data[2]), 1);
if(index > 0){
index--;
}
}else if(data[1].equals("next")){
markup = this.getGalleryView(Integer.parseInt(data[2]), 2);
if(index < this.urls.size()-1){
index++;
}
}else if(data[1].equals("text")){
try {
this.sendAnswerCallbackQuery("Please use one of the given actions below, instead.", false, callbackquery);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
if(markup == null){
try {
this.sendAnswerCallbackQuery(INDEX_OUT_OF_RANGE, false, callbackquery);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}else{
EditMessageText editMarkup = new EditMessageText();
editMarkup.setChatId(callbackquery.getMessage().getChatId().toString());
editMarkup.setInlineMessageId(callbackquery.getInlineMessageId());
editMarkup.setText("[​](" + this.urls.get(index)[1] + ")");
editMarkup.enableMarkdown(true);
editMarkup.setMessageId(callbackquery.getMessage().getMessageId());
editMarkup.setReplyMarkup(markup);
try {
editMessageText(editMarkup);
} catch (TelegramApiException e) {
e.printStackTrace();
}
}
}
}
}
/**
*
* @param text The text that should be shown
* @param alert If the text should be shown as a alert or not
* @param callbackquery
* @throws TelegramApiException
*/
private void sendAnswerCallbackQuery(String text, boolean alert, CallbackQuery callbackquery) throws TelegramApiException{
AnswerCallbackQuery answerCallbackQuery = new AnswerCallbackQuery();
answerCallbackQuery.setCallbackQueryId(callbackquery.getId());
answerCallbackQuery.setShowAlert(alert);
answerCallbackQuery.setText(text);
answerCallbackQuery(answerCallbackQuery);
}
/**
*
* @param index Index of the current image
* @param action What button was clicked
* @return
*/
private InlineKeyboardMarkup getGalleryView(int index, int action){
/*
* action = 1 -> back
* action = 2 -> next
* action = -1 -> nothing
*/
if(action == 1 && index > 0){
index--;
}
else if((action == 1 && index == 0)){
return null;
}
else if(action == 2 && index >= this.urls.size()-1){
return null;
}
else if(action == 2){
index++;
}
InlineKeyboardMarkup markupInline = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> rowsInline = new ArrayList<>();
List<InlineKeyboardButton> rowInline = new ArrayList<>();
rowInline.add(new InlineKeyboardButton().setText(this.urls.get(index)[2]).setCallbackData("gallery:text:" + index));
List<InlineKeyboardButton> rowInline2 = new ArrayList<>();
rowInline2.add(new InlineKeyboardButton().setText(BACK).setCallbackData("gallery:back:" + index));
rowInline2.add(new InlineKeyboardButton().setText(NEXT).setCallbackData("gallery:next:" + index));
List<InlineKeyboardButton> rowInline3 = new ArrayList<>();
rowInline3.add(new InlineKeyboardButton().setText("Link").setUrl(this.urls.get(index)[0]));
rowsInline.add(rowInline);
rowsInline.add(rowInline3);
rowsInline.add(rowInline2);
markupInline.setKeyboard(rowsInline);
return markupInline;
}
@Override
public String getBotToken() {
return BotConfig.ELEKTROLLART_TOKEN;
}
}

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

@ -9,8 +9,8 @@ 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.ReplyKeyboardHide;
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.exceptions.TelegramApiException;
@ -106,8 +106,8 @@ public class FilesHandlers extends TelegramLongPollingBot {
String language = DatabaseManager.getInstance().getUserLanguage(update.getMessage().getFrom().getId());
DatabaseManager.getInstance().addFile(message.getDocument().getFileId(), message.getFrom().getId(), message.getDocument().getFileName());
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getInstance().getString("fileUploaded", language) +
LocalisationService.getInstance().getString("uploadedFileURL", language) + message.getDocument().getFileId());
sendMessageRequest.setText(LocalisationService.getString("fileUploaded", language) +
LocalisationService.getString("uploadedFileURL", language) + message.getDocument().getFileId());
sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest);
}
@ -117,18 +117,17 @@ public class FilesHandlers extends TelegramLongPollingBot {
HashMap<String, String> files = DatabaseManager.getInstance().getFilesByUser(message.getFrom().getId());
SendMessage sendMessageRequest = new SendMessage();
if (files.size() > 0) {
String text = LocalisationService.getInstance().getString("listOfFiles", language) + ":\n\n";
String text = LocalisationService.getString("listOfFiles", language) + ":\n\n";
for (Map.Entry<String, String> entry : files.entrySet()) {
text += LocalisationService.getInstance().getString("uploadedFileURL", language)
text += LocalisationService.getString("uploadedFileURL", language)
+ entry.getKey() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + entry.getValue() + "\n";
}
sendMessageRequest.setText(text);
} else {
sendMessageRequest.setText(LocalisationService.getInstance().getString("noFiles", language));
sendMessageRequest.setText(LocalisationService.getString("noFiles", language));
}
sendMessageRequest.setChatId(message.getChatId());
ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide();
sendMessageRequest.setReplyMarkup(replyKeyboardHide);
sendMessageRequest.setReplyMarkup(new ReplyKeyboardRemove());
sendMessage(sendMessageRequest);
}
@ -144,7 +143,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
private void onDeleteCommandWithoutParameters(Message message, String language) throws InvalidObjectException, TelegramApiException {
DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), DELETE_UPLOADED_STATUS);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getInstance().getString("deleteUploadedFile", language));
sendMessageRequest.setText(LocalisationService.getString("deleteUploadedFile", language));
sendMessageRequest.setChatId(message.getChatId());
HashMap<String, String> files = DatabaseManager.getInstance().getFilesByUser(message.getFrom().getId());
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
@ -157,7 +156,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
commands.add(commandRow);
}
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
replyKeyboardMarkup.setKeyboard(commands);
}
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
@ -169,9 +168,9 @@ public class FilesHandlers extends TelegramLongPollingBot {
boolean removed = DatabaseManager.getInstance().deleteFile(innerParts[0].trim());
SendMessage sendMessageRequest = new SendMessage();
if (removed) {
sendMessageRequest.setText(LocalisationService.getInstance().getString("fileDeleted", language));
sendMessageRequest.setText(LocalisationService.getString("fileDeleted", language));
} else {
sendMessageRequest.setText(LocalisationService.getInstance().getString("wrongFileId", language));
sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language));
}
sendMessageRequest.setChatId(message.getChatId());
@ -183,7 +182,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
private void onCancelCommand(Message message, String language) throws InvalidObjectException, TelegramApiException {
DatabaseManager.getInstance().deleteUserForFile(message.getFrom().getId());
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getInstance().getString("processFinished", language));
sendMessageRequest.setText(LocalisationService.getString("processFinished", language));
sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest);
}
@ -191,7 +190,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
private void onUploadCommand(Message message, String language) throws InvalidObjectException, TelegramApiException {
DatabaseManager.getInstance().addUserForFile(message.getFrom().getId(), INITIAL_UPLOAD_STATUS);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getInstance().getString("sendFileToUpload", language));
sendMessageRequest.setText(LocalisationService.getString("sendFileToUpload", language));
sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest);
}
@ -199,7 +198,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
private void sendHelpMessage(Message message, String language) throws InvalidObjectException, TelegramApiException {
SendMessage sendMessageRequest = new SendMessage();
String formatedString = String.format(
LocalisationService.getInstance().getString("helpFiles", language),
LocalisationService.getString("helpFiles", language),
Commands.startCommand, Commands.uploadCommand, Commands.deleteCommand,
Commands.listCommand);
sendMessageRequest.setText(formatedString);
@ -215,7 +214,7 @@ public class FilesHandlers extends TelegramLongPollingBot {
sendDocument(sendDocumentRequest);
} else {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setText(LocalisationService.getInstance().getString("wrongFileId", language));
sendMessageRequest.setText(LocalisationService.getString("wrongFileId", language));
sendMessageRequest.setChatId(message.getChatId());
sendMessage(sendMessageRequest);
}
@ -225,19 +224,19 @@ public class FilesHandlers extends TelegramLongPollingBot {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
HashMap<String, String> languages = LocalisationService.getInstance().getSupportedLanguages();
List<LocalisationService.Language> languages = LocalisationService.getSupportedLanguages();
List<KeyboardRow> commands = new ArrayList<>();
for (Map.Entry<String, String> entry : languages.entrySet()) {
for (LocalisationService.Language languageItem : languages) {
KeyboardRow commandRow = new KeyboardRow();
commandRow.add(entry.getKey() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + entry.getValue());
commandRow.add(languageItem.getCode() + " " + Emoji.LEFT_RIGHT_ARROW.toString() + " " + languageItem.getName());
commands.add(commandRow);
}
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
replyKeyboardMarkup.setKeyboard(commands);
replyKeyboardMarkup.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardMarkup);
sendMessageRequest.setText(LocalisationService.getInstance().getString("chooselanguage", language));
sendMessageRequest.setText(LocalisationService.getString("chooselanguage", language));
sendMessage(sendMessageRequest);
languageMessages.add(message.getFrom().getId());
}
@ -246,16 +245,16 @@ public class FilesHandlers extends TelegramLongPollingBot {
String[] parts = message.getText().split(Emoji.LEFT_RIGHT_ARROW.toString(), 2);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.setChatId(message.getChatId());
if (LocalisationService.getInstance().getSupportedLanguages().containsKey(parts[0].trim())) {
if (LocalisationService.getLanguageByCode(parts[0].trim()) != null) {
DatabaseManager.getInstance().putUserLanguage(message.getFrom().getId(), parts[0].trim());
sendMessageRequest.setText(LocalisationService.getInstance().getString("languageModified", parts[0].trim()));
sendMessageRequest.setText(LocalisationService.getString("languageModified", parts[0].trim()));
} else {
sendMessageRequest.setText(LocalisationService.getInstance().getString("errorLanguage"));
sendMessageRequest.setText(LocalisationService.getString("errorLanguage"));
}
sendMessageRequest.setReplyToMessageId(message.getMessageId());
ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide();
replyKeyboardHide.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardHide);
ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
replyKeyboardRemove.setSelective(true);
sendMessageRequest.setReplyMarkup(replyKeyboardRemove);
sendMessage(sendMessageRequest);
languageMessages.remove(message.getFrom().getId());
}

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

@ -8,7 +8,6 @@ import org.telegram.services.LocalisationService;
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.methods.updatingmessages.EditMessageText;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.api.objects.replykeyboard.InlineKeyboardMarkup;
@ -37,55 +36,11 @@ public class TransifexHandlers extends TelegramLongPollingBot {
@Override
public void onUpdateReceived(Update update) {
BotLogger.severe("TEST", update.toString());
if (update.hasMessage()) {
if (update.getMessage().getText().startsWith("/command")) {
SendMessage message = new SendMessage();
message.setText("Second message after clicking >" + update.getMessage().getText() + "<");
message.setChatId(update.getMessage().getChatId());
try {
sendMessage(message);
} catch (Throwable e) {
e.printStackTrace();
}
} else {
SendMessage message = new SendMessage();
message.setText("First message without command");
message.setChatId(update.getMessage().getChatId());
InlineKeyboardMarkup markup = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> keyboard = new ArrayList<>();
List<InlineKeyboardButton> row = new ArrayList<>();
InlineKeyboardButton button = new InlineKeyboardButton();
button.setText("Edit message");
button.setCallbackData("EDIT");
row.add(button);
keyboard.add(row);
markup.setKeyboard(keyboard);
message.setReplyMarkup(markup);
try {
sendMessage(message);
} catch (Throwable e) {
e.printStackTrace();
}
}
} else if (update.hasCallbackQuery()) {
EditMessageText editMessage = new EditMessageText();
editMessage.setChatId(update.getCallbackQuery().getMessage().getChatId());
editMessage.setMessageId(update.getCallbackQuery().getMessage().getMessageId());
editMessage.setText("First message with /command, /command1 and /command2");
try {
editMessageText(editMessage);
} catch (Throwable e) {
e.printStackTrace();
}
}
/*try {
try {
handleUpdate(update);
} catch (Throwable e) {
BotLogger.error(LOGTAG, e);
}*/
}
}
private void handleUpdate(Update update) throws InvalidObjectException, TelegramApiException {
@ -127,7 +82,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
} else if (parts[0].startsWith(Commands.help)) {
SendMessage sendMessageRequest = new SendMessage();
String helpFormated = String.format(
LocalisationService.getInstance().getString("helpTransifex", language),
LocalisationService.getString("helpTransifex", language),
Commands.transifexiOSCommand, Commands.transifexAndroidCommand, Commands.transifexWebogram,
Commands.transifexTDesktop, Commands.transifexOSX, Commands.transifexWP,
Commands.transifexAndroidSupportCommand);
@ -152,7 +107,7 @@ public class TransifexHandlers extends TelegramLongPollingBot {
(message.getText().startsWith(Commands.startCommand) || !message.isGroupMessage())) {
SendMessage sendMessageRequest = new SendMessage();
String helpFormated = String.format(
LocalisationService.getInstance().getString("helpTransifex", language),
LocalisationService.getString("helpTransifex", language),
Commands.transifexiOSCommand, Commands.transifexAndroidCommand, Commands.transifexWebogram,
Commands.transifexTDesktop, Commands.transifexOSX, Commands.transifexWP,
Commands.transifexAndroidSupportCommand);
@ -171,12 +126,12 @@ public class TransifexHandlers extends TelegramLongPollingBot {
SendMessage answer = new SendMessage();
answer.setChatId(message.getChatId());
answer.setReplyToMessageId(message.getMessageId());
answer.setText(LocalisationService.getInstance().getString("movedToLangBot", language));
answer.setText(LocalisationService.getString("movedToLangBot", language));
InlineKeyboardMarkup inlineKeyboardMarkup = new InlineKeyboardMarkup();
List<List<InlineKeyboardButton>> rows = new ArrayList<>();
List<InlineKeyboardButton> row = new ArrayList<>();
InlineKeyboardButton button = new InlineKeyboardButton();
button.setText(LocalisationService.getInstance().getString("checkLangBot", language));
button.setText(LocalisationService.getString("checkLangBot", language));
button.setUrl("https://telegram.me/langbot");
row.add(button);
rows.add(row);

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

@ -14,8 +14,8 @@ 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.ReplyKeyboardHide;
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.exceptions.TelegramApiException;
@ -24,6 +24,7 @@ import org.telegram.telegrambots.logging.BotLogger;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author Ruben Bermudez
@ -130,7 +131,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.enableMarkdown(true);
sendMessage.setReplyToMessageId(messageId);
sendMessage.setReplyMarkup(replyKeyboard);
sendMessage.setText(LocalisationService.getInstance().getString("backToMainMenu", language));
sendMessage.setText(LocalisationService.getString("backToMainMenu", language));
DatabaseManager.getInstance().insertWeatherState(userId, chatId, MAINMENU);
return sendMessage;
@ -193,9 +194,9 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setReplyToMessageId(messageId);
sendMessage.setText(Emoji.WAVING_HAND_SIGN.toString());
ReplyKeyboardHide replyKeyboardHide = new ReplyKeyboardHide();
replyKeyboardHide.setSelective(true);
sendMessage.setReplyMarkup(replyKeyboardHide);
ReplyKeyboardRemove replyKeyboardRemove = new ReplyKeyboardRemove();
replyKeyboardRemove.setSelective(true);
sendMessage.setReplyMarkup(replyKeyboardRemove);
sendMessage(sendMessage);
DatabaseManager.getInstance().insertWeatherState(userId, chatId, STARTSTATE);
@ -249,7 +250,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setChatId(message.getChatId());
sendMessage.setReplyMarkup(getAlertsKeyboard(language));
sendMessage.setText(LocalisationService.getInstance().getString("alertDeleted", language));
sendMessage.setText(LocalisationService.getString("alertDeleted", language));
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
return sendMessage;
@ -261,7 +262,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setChatId(message.getChatId());
sendMessage.setReplyMarkup(getAlertsKeyboard(language));
sendMessage.setText(LocalisationService.getInstance().getString("alertsMenuMessage", language));
sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language));
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
return sendMessage;
@ -276,7 +277,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(message.getChatId());
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setReplyMarkup(getAlertsKeyboard(language));
sendMessage.setText(LocalisationService.getInstance().getString("alertsMenuMessage", language));
sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language));
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
sendMessageRequest = sendMessage;
} else {
@ -361,11 +362,11 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = getAlertsListKeyboard(message.getFrom().getId(), language);
if (replyKeyboardMarkup != null) {
sendMessage.setReplyMarkup(replyKeyboardMarkup);
sendMessage.setText(LocalisationService.getInstance().getString("chooseNewAlertCity", language));
sendMessage.setText(LocalisationService.getString("chooseNewAlertCity", language));
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERTDELETE);
} else {
sendMessage.setReplyMarkup(getAlertsKeyboard(language));
sendMessage.setText(LocalisationService.getInstance().getString("noAlertList", language));
sendMessage.setText(LocalisationService.getString("noAlertList", language));
}
sendMessage.setReplyToMessageId(message.getMessageId());
@ -378,7 +379,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(message.getChatId());
sendMessage.setReplyMarkup(getRecentsKeyboard(message.getFrom().getId(), language, false));
sendMessage.setText(LocalisationService.getInstance().getString("chooseNewAlertCity", language));
sendMessage.setText(LocalisationService.getString("chooseNewAlertCity", language));
sendMessage.setReplyToMessageId(message.getMessageId());
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERTNEW);
@ -415,7 +416,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setChatId(message.getChatId());
sendMessage.setReplyMarkup(getAlertsKeyboard(language));
sendMessage.setText(LocalisationService.getInstance().getString("alertsMenuMessage", language));
sendMessage.setText(LocalisationService.getString("alertsMenuMessage", language));
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), ALERT);
return sendMessage;
@ -456,10 +457,10 @@ public class WeatherHandlers extends TelegramLongPollingBot {
if (message.hasText()) {
if (message.getText().trim().equals(getCancelCommand(language))) {
sendMessageRequest = onBackUnitsCommand(message, language);
} else if (message.getText().trim().equals(LocalisationService.getInstance().getString("metricSystem", language))) {
} else if (message.getText().trim().equals(LocalisationService.getString("metricSystem", language))) {
sendMessageRequest = onUnitsChosen(message.getFrom().getId(), message.getChatId(),
message.getMessageId(), WeatherService.METRICSYSTEM, language);
} else if (message.getText().trim().equals(LocalisationService.getInstance().getString("imperialSystem", language))) {
} else if (message.getText().trim().equals(LocalisationService.getString("imperialSystem", language))) {
sendMessageRequest = onUnitsChosen(message.getFrom().getId(), message.getChatId(),
message.getMessageId(), WeatherService.IMPERIALSYSTEM, language);
} else {
@ -488,7 +489,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessageRequest.enableMarkdown(true);
sendMessageRequest.setChatId(chatId.toString());
sendMessageRequest.setReplyMarkup(getUnitsKeyboard(language));
sendMessageRequest.setText(LocalisationService.getInstance().getString("errorUnitsNotFound", language));
sendMessageRequest.setText(LocalisationService.getString("errorUnitsNotFound", language));
sendMessageRequest.setReplyToMessageId(messageId);
return sendMessageRequest;
@ -500,7 +501,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.enableMarkdown(true);
sendMessageRequest.setChatId(chatId.toString());
sendMessageRequest.setText(LocalisationService.getInstance().getString("unitsUpdated", language));
sendMessageRequest.setText(LocalisationService.getString("unitsUpdated", language));
sendMessageRequest.setReplyToMessageId(messageId);
sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(language));
@ -517,7 +518,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
if (message.hasText()) {
if (message.getText().trim().equals(getCancelCommand(language))) {
sendMessageRequest = onBackLanguageCommand(message, language);
} else if (LocalisationService.getInstance().getSupportedLanguages().values().contains(message.getText().trim())) {
} else if (LocalisationService.getLanguageByName(message.getText().trim()) != null) {
sendMessageRequest = onLanguageChosen(message.getFrom().getId(), message.getChatId(),
message.getMessageId(), message.getText().trim());
} else {
@ -546,20 +547,20 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessageRequest.enableMarkdown(true);
sendMessageRequest.setChatId(chatId.toString());
sendMessageRequest.setReplyMarkup(getLanguagesKeyboard(language));
sendMessageRequest.setText(LocalisationService.getInstance().getString("errorLanguageNotFound", language));
sendMessageRequest.setText(LocalisationService.getString("errorLanguageNotFound", language));
sendMessageRequest.setReplyToMessageId(messageId);
return sendMessageRequest;
}
private static SendMessage onLanguageChosen(Integer userId, Long chatId, Integer messageId, String language) {
String languageCode = LocalisationService.getInstance().getLanguageCodeByName(language);
String languageCode = LocalisationService.getLanguageCodeByName(language);
DatabaseManager.getInstance().putUserWeatherLanguageOption(userId, languageCode);
SendMessage sendMessageRequest = new SendMessage();
sendMessageRequest.enableMarkdown(true);
sendMessageRequest.setChatId(chatId.toString());
sendMessageRequest.setText(LocalisationService.getInstance().getString("languageUpdated", languageCode));
sendMessageRequest.setText(LocalisationService.getString("languageUpdated", languageCode));
sendMessageRequest.setReplyToMessageId(messageId);
sendMessageRequest.setReplyMarkup(getMainMenuKeyboard(languageCode));
@ -640,7 +641,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(chatId.toString());
sendMessage.setReplyToMessageId(messageId);
sendMessage.setReplyMarkup(forceReplyKeyboard);
sendMessage.setText(LocalisationService.getInstance().getString("onWeatherLocationCommand", language));
sendMessage.setText(LocalisationService.getString("onWeatherLocationCommand", language));
DatabaseManager.getInstance().insertWeatherState(userId, chatId, FORECASTLOCATIONWEATHER);
return sendMessage;
@ -654,7 +655,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(chatId.toString());
sendMessage.setReplyToMessageId(messageId);
sendMessage.setReplyMarkup(forceReplyKeyboard);
sendMessage.setText(LocalisationService.getInstance().getString("onWeatherNewCommand", language));
sendMessage.setText(LocalisationService.getString("onWeatherNewCommand", language));
DatabaseManager.getInstance().insertWeatherState(userId, chatId, FORECASTNEWWEATHER);
return sendMessage;
@ -741,7 +742,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(chatId.toString());
sendMessage.setReplyToMessageId(messageId);
sendMessage.setReplyMarkup(forceReplyKeyboard);
sendMessage.setText(LocalisationService.getInstance().getString("onWeatherLocationCommand", language));
sendMessage.setText(LocalisationService.getString("onWeatherLocationCommand", language));
DatabaseManager.getInstance().insertWeatherState(userId, chatId, CURRENTLOCATIONWEATHER);
return sendMessage;
@ -755,7 +756,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(chatId.toString());
sendMessage.setReplyToMessageId(messageId);
sendMessage.setReplyMarkup(forceReplyKeyboard);
sendMessage.setText(LocalisationService.getInstance().getString("onWeatherNewCommand", language));
sendMessage.setText(LocalisationService.getString("onWeatherNewCommand", language));
DatabaseManager.getInstance().insertWeatherState(userId, chatId, CURRENTNEWWEATHER);
return sendMessage;
@ -819,9 +820,9 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setChatId(message.getChatId());
if (replyKeyboardMarkup.getKeyboard().size() > 3) {
sendMessage.setText(LocalisationService.getInstance().getString("onForecastCommandFromHistory", language));
sendMessage.setText(LocalisationService.getString("onForecastCommandFromHistory", language));
} else {
sendMessage.setText(LocalisationService.getInstance().getString("onForecastCommandWithoutHistory", language));
sendMessage.setText(LocalisationService.getString("onForecastCommandWithoutHistory", language));
}
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), FORECASTWEATHER);
@ -837,9 +838,9 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setReplyToMessageId(message.getMessageId());
sendMessage.setChatId(message.getChatId());
if (replyKeyboardMarkup.getKeyboard().size() > 3) {
sendMessage.setText(LocalisationService.getInstance().getString("onCurrentCommandFromHistory", language));
sendMessage.setText(LocalisationService.getString("onCurrentCommandFromHistory", language));
} else {
sendMessage.setText(LocalisationService.getInstance().getString("onCurrentCommandWithoutHistory", language));
sendMessage.setText(LocalisationService.getString("onCurrentCommandWithoutHistory", language));
}
DatabaseManager.getInstance().insertWeatherState(message.getFrom().getId(), message.getChatId(), CURRENTWEATHER);
@ -851,31 +852,31 @@ public class WeatherHandlers extends TelegramLongPollingBot {
// region Get Messages
private static String getSettingsMessage(String language) {
String baseString = LocalisationService.getInstance().getString("onSettingsCommand", language);
String baseString = LocalisationService.getString("onSettingsCommand", language);
return String.format(baseString, Emoji.GLOBE_WITH_MERIDIANS.toString(),
Emoji.STRAIGHT_RULER.toString(), Emoji.ALARM_CLOCK.toString(),
Emoji.BACK_WITH_LEFTWARDS_ARROW_ABOVE.toString());
}
private static String getHelpMessage(String language) {
String baseString = LocalisationService.getInstance().getString("helpWeatherMessage", language);
String baseString = LocalisationService.getString("helpWeatherMessage", language);
return String.format(baseString, Emoji.BLACK_RIGHT_POINTING_TRIANGLE.toString(),
Emoji.BLACK_RIGHT_POINTING_DOUBLE_TRIANGLE.toString(), Emoji.ALARM_CLOCK.toString(),
Emoji.EARTH_GLOBE_EUROPE_AFRICA.toString(), Emoji.STRAIGHT_RULER.toString());
}
private static String getLanguageMessage(String language) {
String baseString = LocalisationService.getInstance().getString("selectLanguage", language);
String baseString = LocalisationService.getString("selectLanguage", language);
return String.format(baseString, language);
}
private static String getUnitsMessage(Integer userId, String language) {
String baseString = LocalisationService.getInstance().getString("selectUnits", language);
String baseString = LocalisationService.getString("selectUnits", language);
return String.format(baseString, DatabaseManager.getInstance().getUserWeatherOptions(userId)[1]);
}
private static String getChooseNewAlertSetMessage(String city, String language) {
String baseString = LocalisationService.getInstance().getString("newAlertSaved", language);
String baseString = LocalisationService.getString("newAlertSaved", language);
return String.format(baseString, Emoji.THUMBS_UP_SIGN.toString(), city);
}
@ -884,15 +885,15 @@ public class WeatherHandlers extends TelegramLongPollingBot {
List<String> alertCities = DatabaseManager.getInstance().getAlertCitiesNameByUser(userId);
if (alertCities.size() > 0) {
String baseAlertListString = LocalisationService.getInstance().getString("initialAlertList", language);
String partialAlertListString = LocalisationService.getInstance().getString("partialAlertList", language);
String baseAlertListString = LocalisationService.getString("initialAlertList", language);
String partialAlertListString = LocalisationService.getString("partialAlertList", language);
String fullListOfAlerts = "";
for (String alertCity : alertCities) {
fullListOfAlerts += String.format(partialAlertListString, Emoji.ALARM_CLOCK.toString(), alertCity);
}
alertListMessage = String.format(baseAlertListString, alertCities.size(), fullListOfAlerts);
} else {
alertListMessage = LocalisationService.getInstance().getString("noAlertList", language);
alertListMessage = LocalisationService.getString("noAlertList", language);
}
return alertListMessage;
@ -907,7 +908,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(false);
replyKeyboardMarkup.setOneTimeKeyboard(false);
List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow keyboardFirstRow = new KeyboardRow();
@ -927,10 +928,11 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(false);
replyKeyboardMarkup.setOneTimeKeyboard(false);
List<KeyboardRow> keyboard = new ArrayList<>();
for (String languageName : LocalisationService.getInstance().getSupportedLanguages().values()) {
for (String languageName : LocalisationService.getSupportedLanguages().stream().map(
LocalisationService.Language::getName).collect(Collectors.toList())) {
KeyboardRow row = new KeyboardRow();
row.add(languageName);
keyboard.add(row);
@ -948,14 +950,14 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(false);
replyKeyboardMarkup.setOneTimeKeyboard(false);
List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow row = new KeyboardRow();
row.add(LocalisationService.getInstance().getString("metricSystem", language));
row.add(LocalisationService.getString("metricSystem", language));
keyboard.add(row);
row = new KeyboardRow();
row.add(LocalisationService.getInstance().getString("imperialSystem", language));
row.add(LocalisationService.getString("imperialSystem", language));
keyboard.add(row);
row = new KeyboardRow();
row.add(getCancelCommand(language));
@ -969,7 +971,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(false);
replyKeyboardMarkup.setOneTimeKeyboard(false);
List<KeyboardRow> keyboard = new ArrayList<>();
KeyboardRow keyboardFirstRow = new KeyboardRow();
@ -993,7 +995,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
List<KeyboardRow> keyboard = new ArrayList<>();
for (String recentWeather : DatabaseManager.getInstance().getRecentWeather(userId)) {
@ -1025,7 +1027,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
ReplyKeyboardMarkup replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
List<KeyboardRow> keyboard = new ArrayList<>();
@ -1052,7 +1054,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
replyKeyboardMarkup = new ReplyKeyboardMarkup();
replyKeyboardMarkup.setSelective(true);
replyKeyboardMarkup.setResizeKeyboard(true);
replyKeyboardMarkup.setOneTimeKeyboad(true);
replyKeyboardMarkup.setOneTimeKeyboard(true);
List<KeyboardRow> keyboard = new ArrayList<>();
for (String alertCityName: alertCitiesNames) {
@ -1081,67 +1083,67 @@ public class WeatherHandlers extends TelegramLongPollingBot {
// region getCommnads
private static String getRateCommand(String language) {
return String.format(LocalisationService.getInstance().getString("rateMe", language),
return String.format(LocalisationService.getString("rateMe", language),
Emoji.HUNDRED_POINTS_SYMBOL.toString());
}
private static String getListCommand(String language) {
return String.format(LocalisationService.getInstance().getString("showList", language),
return String.format(LocalisationService.getString("showList", language),
Emoji.CLIPBOARD.toString());
}
private static String getDeleteCommand(String language) {
return String.format(LocalisationService.getInstance().getString("delete", language),
return String.format(LocalisationService.getString("delete", language),
Emoji.HEAVY_MINUS_SIGN.toString());
}
private static String getLanguagesCommand(String language) {
return String.format(LocalisationService.getInstance().getString("languages", language),
return String.format(LocalisationService.getString("languages", language),
Emoji.GLOBE_WITH_MERIDIANS.toString());
}
private static String getUnitsCommand(String language) {
return String.format(LocalisationService.getInstance().getString("units", language),
return String.format(LocalisationService.getString("units", language),
Emoji.STRAIGHT_RULER.toString());
}
private static String getAlertsCommand(String language) {
return String.format(LocalisationService.getInstance().getString("alerts", language),
return String.format(LocalisationService.getString("alerts", language),
Emoji.ALARM_CLOCK.toString());
}
private static String getBackCommand(String language) {
return String.format(LocalisationService.getInstance().getString("back", language),
return String.format(LocalisationService.getString("back", language),
Emoji.BACK_WITH_LEFTWARDS_ARROW_ABOVE.toString());
}
private static String getNewCommand(String language) {
return String.format(LocalisationService.getInstance().getString("new", language),
return String.format(LocalisationService.getString("new", language),
Emoji.HEAVY_PLUS_SIGN.toString());
}
private static String getLocationCommand(String language) {
return String.format(LocalisationService.getInstance().getString("location", language),
return String.format(LocalisationService.getString("location", language),
Emoji.ROUND_PUSHPIN.toString());
}
private static String getSettingsCommand(String language) {
return String.format(LocalisationService.getInstance().getString("settings", language),
return String.format(LocalisationService.getString("settings", language),
Emoji.WRENCH.toString());
}
private static String getCurrentCommand(String language) {
return String.format(LocalisationService.getInstance().getString("current", language),
return String.format(LocalisationService.getString("current", language),
Emoji.BLACK_RIGHT_POINTING_TRIANGLE.toString());
}
private static String getForecastCommand(String language) {
return String.format(LocalisationService.getInstance().getString("forecast", language),
return String.format(LocalisationService.getString("forecast", language),
Emoji.BLACK_RIGHT_POINTING_DOUBLE_TRIANGLE.toString());
}
private static String getCancelCommand(String language) {
return String.format(LocalisationService.getInstance().getString("cancel", language),
return String.format(LocalisationService.getString("cancel", language),
Emoji.CROSS_MARK.toString());
}
// endregion getCommnads
@ -1161,7 +1163,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
sendMessage.setChatId(chatId.toString());
sendMessage.setReplyToMessageId(messageId);
sendMessage.setReplyMarkup(replyKeyboard);
sendMessage.setText(LocalisationService.getInstance().getString("chooseOption", language));
sendMessage.setText(LocalisationService.getString("chooseOption", language));
return sendMessage;
}
@ -1186,7 +1188,7 @@ public class WeatherHandlers extends TelegramLongPollingBot {
if (replyKeyboardMarkup != null) {
sendMessage.setReplyMarkup(replyKeyboardMarkup);
}
sendMessage.setText(LocalisationService.getInstance().getString("rateMeMessage", language));
sendMessage.setText(LocalisationService.getString("rateMeMessage", language));
return sendMessage;
}

0
src/main/resources/localisation/strings.properties → src/main/resources/strings.properties

0
src/main/resources/localisation/strings_eo.properties → src/main/resources/strings_eo.properties

0
src/main/resources/localisation/strings_es.properties → src/main/resources/strings_es.properties

0
src/main/resources/localisation/strings_it.properties → src/main/resources/strings_it.properties

0
src/main/resources/localisation/strings_nl.properties → src/main/resources/strings_nl.properties

0
src/main/resources/localisation/strings_pt.properties → src/main/resources/strings_pt.properties

Loading…
Cancel
Save