diff --git a/Cargo.toml b/Cargo.toml index 3b415eb..cfadf6d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "moo" -version = "0.0.16" +version = "0.0.17" edition = "2021" authors = ["hinto-janai"] repository = "https://github.com/Cuprate/moo" diff --git a/src/command/handle.rs b/src/command/handle.rs index 9862fb8..cb899fd 100644 --- a/src/command/handle.rs +++ b/src/command/handle.rs @@ -404,14 +404,14 @@ impl Command { let mut msg = "Canceled meeting(s):\n\n".to_string(); let mut next_meeting = String::new(); - for _ in 0..count.get() { - match crate::github::cancel_cuprate_meeting(reason.as_deref()).await { - Ok((canceled_url, next)) => { - msg.push_str(&format!("- {canceled_url}\n")); - next_meeting = next; + match crate::github::cancel_cuprate_meeting(count, reason.as_deref()).await { + Ok((canceled_urls, next)) => { + for url in canceled_urls { + msg.push_str(&format!("- {url}\n")); } - Err(e) => return RoomMessageEventContent::text_plain(e.to_string()), + next_meeting = next; } + Err(e) => return RoomMessageEventContent::text_plain(e.to_string()), } msg.push_str(&format!("\nNext meeting: {next_meeting}")); diff --git a/src/github.rs b/src/github.rs index a8e4e55..8deda33 100644 --- a/src/github.rs +++ b/src/github.rs @@ -1,5 +1,7 @@ //! TODO +use std::num::NonZero; + //---------------------------------------------------------------------------------------------------- Use use anyhow::anyhow; use reqwest::{Client, RequestBuilder}; @@ -121,8 +123,8 @@ pub async fn finish_cuprate_meeting( let client = build_client(); let (issue, title) = find_cuprate_meeting_issue(&client, false).await?; - let logs = post_comment_in_issue(&client, issue, meeting_logs).await?; - let next_meeting = post_cuprate_meeting_issue(&client, title, issue).await?; + let logs = post_comment_in_issue(&client, issue, &meeting_logs).await?; + let next_meeting = post_cuprate_meeting_issue(&client, title, issue, None).await?; close_issue(&client, issue).await?; Ok((logs, next_meeting)) @@ -135,20 +137,36 @@ pub async fn finish_cuprate_meeting( #[instrument] #[inline] pub async fn cancel_cuprate_meeting( + count: NonZero, reason: Option<&str>, -) -> Result<(String, String), anyhow::Error> { +) -> Result<(Vec, String), anyhow::Error> { let client = build_client(); - let reason = reason.unwrap_or("Unknown"); - let comment = format!("This meeting was canceled, reason: `{reason}`"); - let (issue, title) = find_cuprate_meeting_issue(&client, false).await?; - post_comment_in_issue(&client, issue, comment).await?; - let next_meeting = post_cuprate_meeting_issue(&client, title, issue).await?; - close_issue(&client, issue).await?; + let mut canceled_meetings = vec![]; + let mut next_meeting = String::new(); + + for week_multiplier in 1..=count.get() { + let (issue, title) = find_cuprate_meeting_issue(&client, false).await?; + + post_comment_in_issue(&client, issue, &comment).await?; - Ok((format!("{MONERO_META_GITHUB_ISSUE}/{issue}"), next_meeting)) + let next = post_cuprate_meeting_issue( + &client, + title, + issue, + NonZero::new(u64::from(week_multiplier)), + ) + .await?; + + close_issue(&client, issue).await?; + + canceled_meetings.push(format!("{MONERO_META_GITHUB_ISSUE}/{issue}")); + next_meeting = next; + } + + Ok((canceled_meetings, next_meeting)) } /// TODO @@ -223,6 +241,7 @@ pub async fn post_cuprate_meeting_issue( client: &Client, previous_meeting_title: String, last_issue: u64, + week_multiplier: Option>, ) -> Result { trace!("Posting Cuprate meeting issue on: {MONERO_META_GITHUB_ISSUE_API}"); @@ -234,7 +253,12 @@ pub async fn post_cuprate_meeting_issue( today = today - Days::new(1); } - let next = today + Days::new(7); + let next = if let Some(multiplier) = week_multiplier { + today + Days::new(7 * multiplier.get()) + } else { + today + Days::new(7) + }; + next.format("%Y-%m-%d").to_string() }; @@ -316,7 +340,7 @@ pub async fn post_cuprate_meeting_issue( pub async fn post_comment_in_issue( client: &Client, issue: u64, - comment: String, + comment: &str, ) -> Result { let url = format!("{MONERO_META_GITHUB_ISSUE_API}/{issue}/comments");