[v0.3.8] /corn now embeds images rather than posting URLs
This commit is contained in:
parent
6e8e428636
commit
04459d1bb6
|
@ -1,3 +1,5 @@
|
|||
* 0.3.8
|
||||
+ Responses to =/corn= commands are now embedded rather than posted as a link
|
||||
* 0.3.7
|
||||
+ Added =/yasd=
|
||||
+ Automate deployments
|
||||
|
|
|
@ -4,7 +4,7 @@ version = 3
|
|||
|
||||
[[package]]
|
||||
name = "BeerHolderBot"
|
||||
version = "0.3.7"
|
||||
version = "0.3.8"
|
||||
dependencies = [
|
||||
"json",
|
||||
"lazy_static",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "BeerHolderBot"
|
||||
version = "0.3.7"
|
||||
version = "0.3.8"
|
||||
authors = ["Eric S. Londres <elondres@stevens.edu>"]
|
||||
edition = "2018"
|
||||
description = "A Telegram bot which holds your beer"
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -123,8 +123,12 @@ async fn harvest_corn() -> AsyncResult<String> {
|
|||
.await.unwrap().text().await.unwrap();
|
||||
// response format is some pretty nested json
|
||||
let parsed_response = json::parse(&response);
|
||||
let img_url = &parsed_response.unwrap()["urls"]["raw"];
|
||||
Ok(img_url.to_string())
|
||||
if let Ok(url) = parsed_response {
|
||||
let img_url = &url["urls"]["regular"];
|
||||
Ok(img_url.to_string())
|
||||
} else {
|
||||
Err("No corn to harvest.".into())
|
||||
}
|
||||
} else {
|
||||
Err("You don't have a farm.".into())
|
||||
}
|
||||
|
@ -217,7 +221,8 @@ async fn answer(cx: UpdateWithCx<AutoSend<Bot>, Message>, command: Command) -> R
|
|||
// harvest corn
|
||||
log::info!("Harvesting corn");
|
||||
if let Ok(corn) = harvest_corn().await {
|
||||
cx.reply_to(corn).await?
|
||||
cx.answer_photo(teloxide::types::InputFile::url(corn)).await?
|
||||
// cx.reply_to(format!("<img src=\"{}\"/>", corn)).parse_mode(teloxide::types::ParseMode::Html).await?
|
||||
} else {
|
||||
log::error!("An error occurred within harvest_corn()");
|
||||
cx.reply_to("You don't have a farm.").await?
|
||||
|
|
Loading…
Reference in New Issue