Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support author in templates #294

Merged
merged 2 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/bot/commands/help_command_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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\
Expand Down
7 changes: 4 additions & 3 deletions src/deliver/deliver_chat_updates_job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
11 changes: 8 additions & 3 deletions src/deliver/render_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -52,6 +53,8 @@ pub struct MessageRenderer {
#[builder(setter(into), default)]
bot_item_description: Option<String>,
#[builder(setter(into), default)]
bot_item_author: Option<String>,
#[builder(setter(into), default)]
template: Option<String>,
#[builder(setter(into), default)]
offset: Option<i32>,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -154,6 +158,7 @@ pub fn render_template_example(template: &str) -> Result<String, String> {
.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();

Expand Down