From 0a54a13238dac3b8e631f80a8d359e45d1415478 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Sat, 21 Jan 2023 05:28:01 +0200 Subject: [PATCH 1/2] support `author` in templates --- Cargo.lock | 24 ++++++++++++------------ src/deliver/deliver_chat_updates_job.rs | 7 ++++--- src/deliver/render_message.rs | 11 ++++++++--- 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2eaf3ed1..7d1f94eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -88,9 +88,9 @@ dependencies = [ [[package]] name = "bumpalo" -version = "3.11.1" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572f695136211188308f16ad2ca5c851a712c464060ae6974944458eb83880ba" +checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" [[package]] name = "byteorder" @@ -289,9 +289,9 @@ dependencies = [ [[package]] name = "cxx" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51d1075c37807dcf850c379432f0df05ba52cc30f279c5cfc43cc221ce7f8579" +checksum = "b61a7545f753a88bcbe0a70de1fcc0221e10bfc752f576754fa91e663db1622e" dependencies = [ "cc", "cxxbridge-flags", @@ -301,9 +301,9 @@ dependencies = [ [[package]] name = "cxx-build" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5044281f61b27bc598f2f6647d480aed48d2bf52d6eb0b627d84c0361b17aa70" +checksum = "f464457d494b5ed6905c63b0c4704842aba319084a0a3561cdc1359536b53200" dependencies = [ "cc", "codespan-reporting", @@ -316,15 +316,15 @@ dependencies = [ [[package]] name = "cxxbridge-flags" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b50bc93ba22c27b0d31128d2d130a0a6b3d267ae27ef7e4fae2167dfe8781c" +checksum = "43c7119ce3a3701ed81aca8410b9acf6fc399d2629d057b87e2efa4e63a3aaea" [[package]] name = "cxxbridge-macro" -version = "1.0.86" +version = "1.0.87" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "39e61fda7e62115119469c7b3591fd913ecca96fb766cfd3f2e2502ab7bc87a5" +checksum = "65e07508b90551e610910fa648a1878991d367064997a596135b86df30daf07e" dependencies = [ "proc-macro2", "quote", @@ -1664,9 +1664,9 @@ checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81" [[package]] name = "unicode-bidi" -version = "0.3.8" +version = "0.3.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "099b7128301d285f79ddd55b9a83d5e6b9e97c92e0ea0daebee7263e932de992" +checksum = "d54675592c1dbefd78cbd98db9bacd89886e1ca50692a0692baefffdeb92dd58" [[package]] name = "unicode-ident" diff --git a/src/deliver/deliver_chat_updates_job.rs b/src/deliver/deliver_chat_updates_job.rs index 57bc9bb1..7efd2886 100644 --- a/src/deliver/deliver_chat_updates_job.rs +++ b/src/deliver/deliver_chat_updates_job.rs @@ -352,10 +352,11 @@ fn format_messages( .map(|item| { let message_renderer = message_renderer_builder .clone() - .bot_date(Some(item.publication_date)) - .bot_item_name(Some(item.title.clone())) - .bot_item_link(Some(item.link.clone())) + .bot_date(item.publication_date) + .bot_item_name(item.title.clone()) + .bot_item_link(item.link.clone()) .bot_item_description(item.description.clone()) + .bot_item_author(item.author.clone()) .build(); match message_renderer.render() { diff --git a/src/deliver/render_message.rs b/src/deliver/render_message.rs index 2d40b857..377ea431 100644 --- a/src/deliver/render_message.rs +++ b/src/deliver/render_message.rs @@ -12,12 +12,13 @@ use htmlescape::decode_html; use serde_json::value::Map; use typed_builder::TypedBuilder; -const BOT_FEED_NAME: &str = "bot_feed_name"; -const BOT_ITEM_NAME: &str = "bot_item_name"; const BOT_DATE: &str = "bot_date"; const BOT_FEED_LINK: &str = "bot_feed_link"; -const BOT_ITEM_LINK: &str = "bot_item_link"; +const BOT_FEED_NAME: &str = "bot_feed_name"; +const BOT_ITEM_AUTHOR: &str = "bot_item_author"; const BOT_ITEM_DESCRIPTION: &str = "bot_item_description"; +const BOT_ITEM_LINK: &str = "bot_item_link"; +const BOT_ITEM_NAME: &str = "bot_item_name"; const SUBSTRING_HELPER: &str = "substring"; const CREATE_LINK_HELPER: &str = "create_link"; @@ -52,6 +53,8 @@ pub struct MessageRenderer { #[builder(setter(into), default)] bot_item_description: Option, #[builder(setter(into), default)] + bot_item_author: Option, + #[builder(setter(into), default)] template: Option, #[builder(setter(into), default)] offset: Option, @@ -79,6 +82,7 @@ impl MessageRenderer { self.maybe_set_value(&mut data, BOT_DATE, &self.date()); self.maybe_set_value(&mut data, BOT_FEED_LINK, &self.bot_feed_link); self.maybe_set_value(&mut data, BOT_ITEM_LINK, &self.bot_item_link); + self.maybe_set_value(&mut data, BOT_ITEM_AUTHOR, &self.bot_item_author); self.maybe_set_value( &mut data, BOT_ITEM_DESCRIPTION, @@ -154,6 +158,7 @@ pub fn render_template_example(template: &str) -> Result { .bot_feed_link(Some("https://www.badykov.com/feed.xml".to_string())) .bot_item_link(Some("https://www.badykov.com/".to_string())) .bot_item_description(Some("item_description".to_string())) + .bot_item_author(Some("Airat".to_string())) .template(Some(template.to_string())) .build(); From d6b9596d188b506a5f477b580f14ffbe2e80ff02 Mon Sep 17 00:00:00 2001 From: Ayrat Badykov Date: Sat, 21 Jan 2023 05:44:08 +0200 Subject: [PATCH 2/2] update template info --- src/bot/commands/help_command_info.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bot/commands/help_command_info.rs b/src/bot/commands/help_command_info.rs index a0a8e6c6..512a1770 100644 --- a/src/bot/commands/help_command_info.rs +++ b/src/bot/commands/help_command_info.rs @@ -26,6 +26,7 @@ static SET_TEMPLATE: &str = - bot_item_name - name of the item\n\ - bot_item_link - url of the item\n\ - bot_item_description - description of the item\n\ + - bot_item_author - author of the item\n\ - bot_date - publication date of the feed\n\ Example: /set_template https://www.badykov.com/feed.xml {{bot_feed_name}}\n\n\n{{bot_item_name}}\n\n\n{{bot_date}}\n\n\n{{bot_item_link}}\n\n\ Also, there are some helpers for templates:\n\n\