1
0
mirror of https://gitlab.com/Anson-Projects/wiki-location-bot.git synced 2025-06-15 14:46:39 +00:00

code cleanup

This commit is contained in:
Anson Biggs 2024-03-24 04:43:56 +00:00
parent bc1f45895e
commit 6910d21035
3 changed files with 4 additions and 2 deletions

View File

@ -50,6 +50,7 @@ async fn main() {
if text.contains("/help") || text.contains("/start") {
bot.send_message(msg.chat.id, help_text())
.parse_mode(teloxide::types::ParseMode::MarkdownV2)
.reply_markup(location_button_markup)
.await?;
} else {
match openstreetmap::geocode_text(text) {
@ -60,7 +61,7 @@ async fn main() {
wikipedia::send_wikipedia_pages(location.lat, location.lon, bot, msg).await;
}
Err(error) => {
println!("Geocoding failed: {}", error);
log::warn!("Geocoding failed: {}", error);
bot.send_message(
msg.chat.id,
format!("Location query returned no matches:\n\t{}\nTry /help", text),
@ -73,6 +74,7 @@ async fn main() {
_ => {}
},
_ => {
log::warn!("Unsupported message type recieved");
bot.send_message(
msg.chat.id,
"Send a location or address to see nearby places that have a wikipedia page!",

View File

@ -27,7 +27,6 @@ pub struct Location {
}
pub fn geocode_text(search_query: &str) -> Result<Location, &str> {
// "https://nominatim.openstreetmap.org/search.php?q=1650+wewatta+world&format=jsonv2&limit=1"
let base_url = "https://nominatim.openstreetmap.org/search.php";
let url = Url::parse_with_params(base_url, &[("q", search_query), ("format", "jsonv2"), ("limit", "1")])

View File

@ -41,6 +41,7 @@ pub struct Root {
}
fn escape_markdown_v2(text: String) -> String {
// https://core.telegram.org/bots/api#markdownv2-style
text.chars().fold(String::new(), |mut acc, c| {
match c {
'_' | '*' | '[' | ']' | '(' | ')' | '~' | '`' | '>' | '#' | '+' | '-' | '=' | '|' | '{' | '}' | '.' | '!' => {