feat: add comic id and title to msg
This commit is contained in:
parent
3790fab0bc
commit
afd5ad906e
2 changed files with 11 additions and 4 deletions
10
src/main.rs
10
src/main.rs
|
@ -151,7 +151,7 @@ async fn handler(cfg: &Config, s: &mut State) -> Result<(), reqwest::Error> {
|
||||||
async fn send_comic(cfg: Config, ctx: SenderCtx) -> Result<(), reqwest::Error> {
|
async fn send_comic(cfg: Config, ctx: SenderCtx) -> Result<(), reqwest::Error> {
|
||||||
let info = cfg
|
let info = cfg
|
||||||
.client
|
.client
|
||||||
.get(ctx.url)
|
.get(ctx.url.clone())
|
||||||
.send()
|
.send()
|
||||||
.await?
|
.await?
|
||||||
.error_for_status()?
|
.error_for_status()?
|
||||||
|
@ -170,7 +170,13 @@ async fn send_comic(cfg: Config, ctx: SenderCtx) -> Result<(), reqwest::Error> {
|
||||||
.unwrap_or("null".to_owned()),
|
.unwrap_or("null".to_owned()),
|
||||||
),
|
),
|
||||||
("photo", info.img),
|
("photo", info.img),
|
||||||
("caption", info.alt),
|
(
|
||||||
|
"caption",
|
||||||
|
format!(
|
||||||
|
"*{}. [{}]({})*\n\n{}",
|
||||||
|
ctx.comic_id, info.title, ctx.url, info.alt,
|
||||||
|
),
|
||||||
|
),
|
||||||
])
|
])
|
||||||
.send()
|
.send()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
|
@ -60,8 +60,9 @@ pub struct TgChat {
|
||||||
/// XKCD API comic info schema
|
/// XKCD API comic info schema
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct XkcdInfo {
|
pub struct XkcdInfo {
|
||||||
#[serde(alias = "text")] // xkcd.ru
|
pub title: String,
|
||||||
pub alt: String, // xkcd.com
|
|
||||||
#[serde(alias = "image")] // xkcd.ru
|
#[serde(alias = "image")] // xkcd.ru
|
||||||
pub img: String, // xkcd.com
|
pub img: String, // xkcd.com
|
||||||
|
#[serde(alias = "text")] // xkcd.ru
|
||||||
|
pub alt: String, // xkcd.com
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue