1
Fork 0
mirror of https://github.com/Steffo99/patched-porobot.git synced 2024-12-22 17:44:22 +00:00

Add a way to convert Card into InlineQueryResult

This commit is contained in:
Steffo 2022-08-07 17:50:35 +02:00
parent c945f7e6c5
commit b2a2535b93
Signed by: steffo
GPG key ID: 6965406171929D01
3 changed files with 44 additions and 1 deletions

View file

@ -20,7 +20,7 @@ use crate::data::setbundle::supertype::CardSupertype;
/// Render a [Card] in [Telegram Bot HTML].
///
/// [Telegram Bot HTML]: https://core.telegram.org/bots/api#html-style
pub fn display_card(card: &Card, globals: &LocalizedGlobalsIndexes) -> String {
pub fn display_card(globals: &LocalizedGlobalsIndexes, card: &Card) -> String {
let title = format!(
r#"<a href="{}"><b><i>{}</b></i></a>"#,
&card.main_art().expect("Card to have at least one illustration").card_png,

42
src/telegram/inline.rs Normal file
View file

@ -0,0 +1,42 @@
//! Module defining helper functions for returning [inline mode] results.
//!
//! [inline mode]: https://core.telegram.org/bots/api#inline-mode
use teloxide::types::{InlineQueryResult, InlineQueryResultPhoto, InputMessageContent, InputMessageContentText, ParseMode};
use crate::data::corebundle::globals::LocalizedGlobalsIndexes;
use crate::data::setbundle::card::Card;
use crate::telegram::display::display_card;
/// Converts a [Card] into a [InlineQueryResult].
pub fn card_to_inlinequeryresult(globals: &LocalizedGlobalsIndexes, card: &Card) -> InlineQueryResult {
InlineQueryResult::Photo(InlineQueryResultPhoto {
id: card.code.to_owned(),
title: Some(card.name.to_owned()),
photo_url: card
.main_art()
.expect("Card to have at least one illustration")
.card_jpg().parse()
.expect("Card to have a valid card_jpg URL"),
thumb_url: card
.main_art()
.expect("Card to have at least one illustration")
.card_jpg().parse()
.expect("Card to have a valid card_jpg URL"),
photo_width: Some(680),
photo_height: Some(1024),
input_message_content: Some(InputMessageContent::Text(InputMessageContentText {
message_text: display_card(&globals, &card),
parse_mode: Some(ParseMode::Html),
entities: None,
disable_web_page_preview: Some(true)
})),
description: None,
caption: None,
parse_mode: None,
caption_entities: None,
reply_markup: None,
})
}

View file

@ -3,3 +3,4 @@
//! Remember while adding new features to this module that binaries [can only access the public API of the crate](https://doc.rust-lang.org/cargo/reference/cargo-targets.html#binaries).
pub mod display;
pub mod inline;