better message formatting
This commit is contained in:
parent
a1b1bffce9
commit
07ae653d49
1 changed files with 13 additions and 8 deletions
21
src/lib.rs
21
src/lib.rs
|
|
@ -125,22 +125,27 @@ impl BlogdorTheAggregator {
|
||||||
Ok(feed_results)
|
Ok(feed_results)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// will also update the successful_runs table if it posts to zulip
|
||||||
pub async fn post_entries(&self, posts: &[FeedEntry]) {
|
pub async fn post_entries(&self, posts: &[FeedEntry]) {
|
||||||
let FeedEntry {
|
let FeedEntry {
|
||||||
feed_id, received, ..
|
feed_id, received, ..
|
||||||
} = posts.last().unwrap();
|
} = posts.last().unwrap();
|
||||||
let mut success = true;
|
let mut success = true;
|
||||||
for post in posts.iter() {
|
for post in posts.iter() {
|
||||||
let body = post
|
let body = post.body.as_deref().unwrap_or("Blogdor Says: NO BODY!");
|
||||||
.body
|
|
||||||
.iter()
|
let tail = if body.len() < ZULIP_MESSAGE_CUTOFF {
|
||||||
.next()
|
""
|
||||||
.cloned()
|
} else {
|
||||||
.unwrap_or("Blogdor Says: NO BODY!".to_string());
|
"..."
|
||||||
|
};
|
||||||
|
|
||||||
let content = format!(
|
let content = format!(
|
||||||
"{body} ...\n\n---\noriginally posted to {}, on {}",
|
"{body}{tail}\n\n---\noriginally published on [{}]({})",
|
||||||
post.post_url, post.published
|
post.published.format("%B %e, %Y"),
|
||||||
|
post.post_url
|
||||||
);
|
);
|
||||||
|
|
||||||
let msg = ZulipMessage {
|
let msg = ZulipMessage {
|
||||||
to: self.channel_id,
|
to: self.channel_id,
|
||||||
typ: "stream",
|
typ: "stream",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue