Skip to content

Commit

Permalink
fix: Circle Back confirmation
Browse files Browse the repository at this point in the history
  • Loading branch information
Fyko committed Sep 6, 2023
1 parent 2313d3b commit dd592df
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion chuckle-github/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ mod test {
assert!(file.is_ok());
let file = file.unwrap();

assert!(file.len() > 0);
assert!(!file.is_empty());
}
}
2 changes: 1 addition & 1 deletion chuckle-github/src/pull_request_review_comment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
));
Expand Down
20 changes: 20 additions & 0 deletions chuckle-interactions/src/commands/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
6 changes: 3 additions & 3 deletions chuckle-interactions/src/context_menu/circle_back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -43,7 +43,7 @@ pub async fn circle_back(ctx: &SlashContext<ChuckleState>) -> 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,
Expand All @@ -62,7 +62,7 @@ pub async fn circle_back(ctx: &SlashContext<ChuckleState>) -> 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,
Expand Down
5 changes: 2 additions & 3 deletions chuckle-jobs/src/circle_back.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,14 @@ 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::<UserMarker>::new(row.user_id as u64))
.await?
.model()
.await?;

let _ = state
state
.http_client
.create_message(dm_channel.id)
.content(
Expand All @@ -34,7 +33,7 @@ pub async fn run(state: &ChuckleState) -> anyhow::Result<()> {
)
.as_str(),
)?
.await;
.await?;
}

Ok(())
Expand Down

0 comments on commit dd592df

Please sign in to comment.