tracing error
This commit is contained in:
@ -154,14 +154,15 @@ public class TelegramBot extends TelegramLongPollingBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void buscarNoticiasYEnviar(String chatId, String query) {
|
private void buscarNoticiasYEnviar(String chatId, String query) {
|
||||||
|
sendMessage(chatId, "Analizando noticias...esto puede tardar un poco, ten paciencia...");
|
||||||
|
try{
|
||||||
List<NewsArticle> noticias = scrapper.searchNews(query);
|
List<NewsArticle> noticias = scrapper.searchNews(query);
|
||||||
|
|
||||||
if (noticias.isEmpty()) {
|
if (noticias.isEmpty()) {
|
||||||
sendMessage(chatId, "No encontré noticias sobre: *" + escapeMarkdown(query) + "*");
|
sendMessage(chatId, "No encontré noticias sobre: *" + escapeMarkdown(query) + "*");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(chatId, "Analizando noticias...esto puede tardar un poco, ten paciencia...");
|
|
||||||
StringBuilder mensaje = new StringBuilder("📰 *Noticias sobre " + escapeMarkdown(query) + "*:\n\n");
|
StringBuilder mensaje = new StringBuilder("📰 *Noticias sobre " + escapeMarkdown(query) + "*:\n\n");
|
||||||
for (NewsArticle noticia : noticias) {
|
for (NewsArticle noticia : noticias) {
|
||||||
mensaje.append("🔹 [")
|
mensaje.append("🔹 [")
|
||||||
@ -172,6 +173,10 @@ public class TelegramBot extends TelegramLongPollingBot {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sendMessage(chatId, mensaje.toString());
|
sendMessage(chatId, mensaje.toString());
|
||||||
|
} catch (Exception e) {
|
||||||
|
sendMessage(chatId, "Lo siento...se me ha licuado el cerebro...Mira los logs para saber más");
|
||||||
|
sendMessage(chatId, e.toString());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Método para escapar caracteres especiales en Markdown
|
// Método para escapar caracteres especiales en Markdown
|
||||||
@ -179,23 +184,6 @@ public class TelegramBot extends TelegramLongPollingBot {
|
|||||||
if (text == null) {
|
if (text == null) {
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
return text.replace("_", "\\_")
|
return text.replaceAll("([_*\\[\\]()~`>#+\\-=|{}.!])", "\\\\$1");
|
||||||
.replace("*", "\\*")
|
|
||||||
.replace("[", "\\[")
|
|
||||||
.replace("]", "\\]")
|
|
||||||
.replace("(", "\\(")
|
|
||||||
.replace(")", "\\)")
|
|
||||||
.replace("~", "\\~")
|
|
||||||
.replace("`", "\\`")
|
|
||||||
.replace(">", "\\>")
|
|
||||||
.replace("#", "\\#")
|
|
||||||
.replace("+", "\\+")
|
|
||||||
.replace("-", "\\-")
|
|
||||||
.replace("=", "\\=")
|
|
||||||
.replace("|", "\\|")
|
|
||||||
.replace("{", "\\{")
|
|
||||||
.replace("}", "\\}")
|
|
||||||
.replace(".", "\\.")
|
|
||||||
.replace("!", "\\!");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user