feat: add comic id and title to msg

This commit is contained in:
DarkCat09 2024-11-27 18:55:35 +04:00
parent 3790fab0bc
commit afd5ad906e
Signed by: DarkCat09
GPG key ID: BD3CE9B65916CD82
2 changed files with 11 additions and 4 deletions

View file

@ -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?;

View file

@ -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
} }