1
0
mirror of https://gitlab.com/Anson-Projects/wiki-location-bot.git synced 2025-08-03 03:51:27 +00:00

deployable state

This commit is contained in:
2023-07-08 00:17:31 +00:00
parent 6b6e93234f
commit e92f593c80

View File

@@ -44,8 +44,7 @@ async fn main() {
pretty_env_logger::init(); pretty_env_logger::init();
log::info!("Starting Wiki Locations Bot"); log::info!("Starting Wiki Locations Bot");
// let bot = Bot::from_env(); let bot = Bot::from_env();
let bot = Bot::new("6377516418:AAFnOnkLwbqpQARVoe0fikawtGqlZfuIgLM");
teloxide::repl(bot, |bot: Bot, msg: Message| async move { teloxide::repl(bot, |bot: Bot, msg: Message| async move {
log::info!("Message recieved."); log::info!("Message recieved.");
@@ -53,6 +52,7 @@ async fn main() {
match msg.location() { match msg.location() {
Some(user_location) => { Some(user_location) => {
log::info!("Location received."); log::info!("Location received.");
bot.send_message(msg.chat.id, "Searching for nearby locations...");
let nearby_locations = let nearby_locations =
ureq::get(&format!("https://en.wikipedia.org/w/api.php?action=query&format=json&list=geosearch&formatversion=2&gscoord={}|{}&gsradius=10000&gslimit=5",user_location.latitude,user_location.longitude)) ureq::get(&format!("https://en.wikipedia.org/w/api.php?action=query&format=json&list=geosearch&formatversion=2&gscoord={}|{}&gsradius=10000&gslimit=5",user_location.latitude,user_location.longitude))
@@ -60,19 +60,25 @@ async fn main() {
.unwrap() .unwrap()
.into_json::<Root>().unwrap().query.geosearch.unwrap(); .into_json::<Root>().unwrap().query.geosearch.unwrap();
// Not working, and also the wikipedia API is so fast its not necessary.
// bot.send_chat_action(msg.chat.id,teloxide::types::ChatAction::FindLocation).await?;
for location in nearby_locations { for location in nearby_locations {
bot.send_message(msg.chat.id, format!("http://en.wikipedia.org/?curid={}",location.pageid)).await?;
bot.send_location(msg.chat.id,location.lat.unwrap(),location.lon.unwrap()).await?;
let url = teloxide::utils::markdown::link(&format!("http://en.wikipedia.org/?curid={}",location.pageid),&location.title);
let bold_url = teloxide::utils::markdown::bold(&url);
bot.send_message(msg.chat.id, bold_url).parse_mode(teloxide::types::ParseMode::MarkdownV2).await?;
} }
// bot.send_message(msg.chat.id, format!("{:#?}", resp))
// .await?;
// bot.send_message(msg.chat.id, resp.get("key").unwrap())
// .await?;
} }
None => { None => {
log::info!("Something other than a location recived."); log::info!("Something other than a location recived.");
bot.send_message(msg.chat.id, "send a location").await?; bot.send_message(msg.chat.id, "Send a location to see nearby places that have a wikipedia page!").await?;
} }
}; };