From dd592df24939443dc85fe13a727668b9e6dff17c Mon Sep 17 00:00:00 2001 From: Carter Himmel Date: Wed, 6 Sep 2023 12:30:06 -0600 Subject: [PATCH] fix: Circle Back confirmation --- chuckle-github/src/lib.rs | 2 +- .../src/pull_request_review_comment.rs | 2 +- chuckle-interactions/src/commands/mod.rs | 20 +++++++++++++++++++ .../src/context_menu/circle_back.rs | 6 +++--- chuckle-jobs/src/circle_back.rs | 5 ++--- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/chuckle-github/src/lib.rs b/chuckle-github/src/lib.rs index c856b12..f507c63 100644 --- a/chuckle-github/src/lib.rs +++ b/chuckle-github/src/lib.rs @@ -48,6 +48,6 @@ mod test { assert!(file.is_ok()); let file = file.unwrap(); - assert!(file.len() > 0); + assert!(!file.is_empty()); } } diff --git a/chuckle-github/src/pull_request_review_comment.rs b/chuckle-github/src/pull_request_review_comment.rs index 8d736d8..96be50b 100644 --- a/chuckle-github/src/pull_request_review_comment.rs +++ b/chuckle-github/src/pull_request_review_comment.rs @@ -273,7 +273,7 @@ mod tests { #[test] fn test_parse() { - static DATA: &'static [u8] = include_bytes!(concat!( + static DATA: &[u8] = include_bytes!(concat!( env!("CARGO_MANIFEST_DIR"), "/data/pull_request_review_comment.json" )); diff --git a/chuckle-interactions/src/commands/mod.rs b/chuckle-interactions/src/commands/mod.rs index 2592e96..94c6ea0 100644 --- a/chuckle-interactions/src/commands/mod.rs +++ b/chuckle-interactions/src/commands/mod.rs @@ -86,3 +86,23 @@ pub async fn text_response( Ok(()) } + +/// Shorthand to creating a text response to an interaction. +pub async fn create_followup( + ctx: &SlashContext<'_, ChuckleState>, + text: String, + ephemeral: bool, +) -> DefaultCommandResult { + let mut builder = ctx + .interaction_client + .create_followup(&ctx.interaction.token) + .content(&text)?; + + if ephemeral { + builder = builder.flags(MessageFlags::EPHEMERAL); + } + + builder.await?; + + Ok(()) +} diff --git a/chuckle-interactions/src/context_menu/circle_back.rs b/chuckle-interactions/src/context_menu/circle_back.rs index 5922b88..f8c3e97 100644 --- a/chuckle-interactions/src/context_menu/circle_back.rs +++ b/chuckle-interactions/src/context_menu/circle_back.rs @@ -4,7 +4,7 @@ use time::{Duration, OffsetDateTime}; use twilight_model::application::interaction::InteractionData; use zephyrus::prelude::*; -use crate::commands::{handle_generic_error, text_response, user_from_interaction}; +use crate::commands::{create_followup, handle_generic_error, user_from_interaction}; #[derive(Modal, Debug)] #[modal(title = "Circle Back")] @@ -43,7 +43,7 @@ pub async fn circle_back(ctx: &SlashContext) -> DefaultCommandResu let time = if let Some(time) = ms!(&output.til_notify) { time } else { - return text_response( + return create_followup( ctx, "The duration you provided was invalid. Please try again with something like [this](https://github.com/nesso99/ms-rust/blob/5a579c9f5b45851086ace2bfa506f541e49b3bbd/tests/main.rs#L6-L22)".to_string(), false, @@ -62,7 +62,7 @@ pub async fn circle_back(ctx: &SlashContext) -> DefaultCommandResu notify_at ).fetch_one(&ctx.data.db).await?; - text_response( + create_followup( ctx, format!("Sounds good! I'll remind you in {}.", ms!(time, true)), true, diff --git a/chuckle-jobs/src/circle_back.rs b/chuckle-jobs/src/circle_back.rs index ec190e2..494fe27 100644 --- a/chuckle-jobs/src/circle_back.rs +++ b/chuckle-jobs/src/circle_back.rs @@ -16,7 +16,6 @@ pub async fn run(state: &ChuckleState) -> anyhow::Result<()> { .execute(&state.db) .await?; - // TODO: send message let dm_channel = state .http_client .create_private_channel(Id::::new(row.user_id as u64)) @@ -24,7 +23,7 @@ pub async fn run(state: &ChuckleState) -> anyhow::Result<()> { .model() .await?; - let _ = state + state .http_client .create_message(dm_channel.id) .content( @@ -34,7 +33,7 @@ pub async fn run(state: &ChuckleState) -> anyhow::Result<()> { ) .as_str(), )? - .await; + .await?; } Ok(())