Pack logs into one message efficiently

This commit is contained in:
toast 2024-08-02 12:19:53 +10:00
parent f078eff53e
commit dd008c24b6

View File

@ -275,22 +275,17 @@ pub async fn rss(ctx: Arc<Context>) -> Result<(), Error> {
loop { loop {
interval.tick().await; interval.tick().await;
let mut log_msgs: Vec<String> = Vec::new();
match esxi_embed().await { match esxi_embed().await {
Ok(Some(embed)) => { Ok(Some(embed)) => {
ChannelId::new(BINARY_PROPERTIES.rss_channel).send_message(&ctx.http, CreateMessage::new().add_embed(embed)).await.unwrap(); ChannelId::new(BINARY_PROPERTIES.rss_channel).send_message(&ctx.http, CreateMessage::new().add_embed(embed)).await.unwrap();
}, },
Ok(None) => { Ok(None) => {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message( log_msgs.push("**[RSS:ESXi]:** Article returned no new content.".to_string());
&ctx.http, CreateMessage::new()
.content("**[RSS:ESXi]:** Article returned no new content.")
).await.unwrap();
}, },
Err(y) => { Err(y) => {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message( log_msgs.push(format!("**[RSS:ESXi:Error]:** Feed failed with the following error:```\n{}\n```", y));
&ctx.http, CreateMessage::new()
.content(format!("**[RSS:ESXi:Error]:** Feed failed with the following error:```\n{}\n```", y))
).await.unwrap();
task_err(&task_name, &y.to_string()) task_err(&task_name, &y.to_string())
} }
} }
@ -302,16 +297,10 @@ pub async fn rss(ctx: Arc<Context>) -> Result<(), Error> {
).await.unwrap(); ).await.unwrap();
}, },
Ok(None) => { Ok(None) => {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message( log_msgs.push("**[RSS:GPortal]:** Article returned no new content.".to_string());
&ctx.http, CreateMessage::new()
.content("**[RSS:GPortal]:** Article returned no new content.")
).await.unwrap();
}, },
Err(y) => { Err(y) => {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message( log_msgs.push(format!("**[RSS:GPortal:Error]:** Feed failed with the following error:```\n{}\n```", y));
&ctx.http, CreateMessage::new()
.content(format!("**[RSS:GPortal:Error]:** Feed failed with the following error:```\n{}\n```", y))
).await.unwrap();
task_err(&task_name, &y.to_string()) task_err(&task_name, &y.to_string())
} }
} }
@ -321,18 +310,18 @@ pub async fn rss(ctx: Arc<Context>) -> Result<(), Error> {
ChannelId::new(BINARY_PROPERTIES.rss_channel).send_message(&ctx.http, CreateMessage::new().content(content)).await.unwrap(); ChannelId::new(BINARY_PROPERTIES.rss_channel).send_message(&ctx.http, CreateMessage::new().content(content)).await.unwrap();
}, },
Ok(None) => { Ok(None) => {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message( log_msgs.push("**[RSS:RustBlog]:** Article returned no new content.".to_string());
&ctx.http, CreateMessage::new()
.content("**[RSS:RustBlog]:** Article returned no new content.")
).await.unwrap();
}, },
Err(y) => { Err(y) => {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message( log_msgs.push(format!("**[RSS:RustBlog:Error]:** Feed failed with the following error:```\n{}\n```", y));
&ctx.http, CreateMessage::new()
.content(format!("**[RSS:RustBlog:Error]:** Feed failed with the following error:```\n{}\n```", y))
).await.unwrap();
task_err(&task_name, &y.to_string()) task_err(&task_name, &y.to_string())
} }
} }
if !log_msgs.is_empty() {
ChannelId::new(BINARY_PROPERTIES.kon_logs).send_message(
&ctx.http, CreateMessage::new().content(log_msgs.join("\n"))
).await.unwrap();
}
} }
} }