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

Fix some issues in the telegram module

This commit is contained in:
Steffo 2022-08-07 17:24:03 +02:00
parent c6e95322ce
commit fb34162fef
Signed by: steffo
GPG key ID: 6965406171929D01
2 changed files with 11 additions and 8 deletions

View file

@ -2,7 +2,6 @@
//! //!
//! [Telegram Bot HTML]: https://core.telegram.org/bots/api#html-style //! [Telegram Bot HTML]: https://core.telegram.org/bots/api#html-style
use std::collections::HashMap;
use itertools::Itertools; use itertools::Itertools;
use teloxide::utils::html::escape; use teloxide::utils::html::escape;
use crate::data::setbundle::card::Card; use crate::data::setbundle::card::Card;
@ -24,7 +23,7 @@ use crate::data::setbundle::supertype::CardSupertype;
pub fn display_card(card: &Card, globals: &LocalizedGlobalsIndexes) -> String { pub fn display_card(card: &Card, globals: &LocalizedGlobalsIndexes) -> String {
let title = format!( let title = format!(
r#"<a href="{}"><b><i>{}</b></i></a>"#, r#"<a href="{}"><b><i>{}</b></i></a>"#,
&card.main_art().card_png, &card.main_art().expect("Card to have at least one illustration").card_png,
escape(&card.name), escape(&card.name),
); );
@ -52,6 +51,8 @@ pub fn display_card(card: &Card, globals: &LocalizedGlobalsIndexes) -> String {
let breadcrumbs = format!("{} {} {}", &set, &regions, &r#type); let breadcrumbs = format!("{} {} {}", &set, &regions, &r#type);
let keywords = display_keywords(&card.keywords, &globals.keywords);
let description = escape(&card.localized_description_text); let description = escape(&card.localized_description_text);
let flavor = format!( let flavor = format!(
@ -61,7 +62,7 @@ pub fn display_card(card: &Card, globals: &LocalizedGlobalsIndexes) -> String {
let artist = format!( let artist = format!(
r#"<a href="{}">Illustration by {}</a>"#, r#"<a href="{}">Illustration by {}</a>"#,
&card.main_art().full_png, &card.main_art().expect("Card to have at least one illustration").full_png,
escape(&card.artist_name) escape(&card.artist_name)
); );
@ -70,6 +71,7 @@ pub fn display_card(card: &Card, globals: &LocalizedGlobalsIndexes) -> String {
title=title, title=title,
stats=stats, stats=stats,
breadcrumbs=breadcrumbs, breadcrumbs=breadcrumbs,
keywords=keywords,
description=description, description=description,
flavor=flavor, flavor=flavor,
artist=artist, artist=artist,
@ -121,7 +123,7 @@ fn display_types(r#type: &CardType, supertype: &CardSupertype, subtypes: &[CardS
result.push_str(&*format!( result.push_str(&*format!(
"<i>{}</i>", "<i>{}</i>",
escape(&String::from(r#type)), escape(&*String::from(r#type)),
)); ));
if subtypes.len() > 0 { if subtypes.len() > 0 {
@ -129,10 +131,7 @@ fn display_types(r#type: &CardType, supertype: &CardSupertype, subtypes: &[CardS
&*format!( &*format!(
" {}", " {}",
subtypes.iter() subtypes.iter()
.map(|subtype| subtype .map(|subtype| format!("<i>{}</i>", escape(&subtype)))
.map(|o| format!("<i>{}</i>", escape(&o)))
.unwrap_or_else(|| "Unknown".to_string())
)
.join(", ") .join(", ")
) )
) )

View file

@ -1 +1,5 @@
//! Module providing utilities to be used in the [crate::bin::telegrambot].
//!
//! 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 display;