Support ephemeral reminder confirmations

This commit is contained in:
jude
2023-05-11 19:40:33 +01:00
parent 4b42966284
commit aa931328b0
8 changed files with 171 additions and 25 deletions

View File

@ -102,6 +102,78 @@ You may want to use one of the popular timezones below, otherwise click [here](h
Ok(())
}
/// Configure server settings
#[poise::command(
slash_command,
rename = "settings",
identifying_name = "settings",
guild_only = true
)]
pub async fn settings(_ctx: Context<'_>) -> Result<(), Error> {
Ok(())
}
/// Configure ephemeral setup
#[poise::command(
slash_command,
rename = "ephemeral",
identifying_name = "ephemeral_confirmations",
guild_only = true
)]
pub async fn ephemeral_confirmations(_ctx: Context<'_>) -> Result<(), Error> {
Ok(())
}
/// Set reminder confirmations to be sent "ephemerally" (private and cleared automatically)
#[poise::command(
slash_command,
rename = "on",
identifying_name = "set_ephemeral_confirmations",
guild_only = true
)]
pub async fn set_ephemeral_confirmations(ctx: Context<'_>) -> Result<(), Error> {
let mut guild_data = ctx.guild_data().await.unwrap()?;
guild_data.ephemeral_confirmations = true;
guild_data.commit_changes(&ctx.data().database).await;
ctx.send(|r| {
r.ephemeral(true).embed(|e| {
e.title("Confirmations ephemeral")
.description("Reminder confirmations will be sent privately, and removed when your client restarts.")
.color(*THEME_COLOR)
})
})
.await?;
Ok(())
}
/// Set reminder confirmations to persist indefinitely
#[poise::command(
slash_command,
rename = "off",
identifying_name = "unset_ephemeral_confirmations",
guild_only = true
)]
pub async fn unset_ephemeral_confirmations(ctx: Context<'_>) -> Result<(), Error> {
let mut guild_data = ctx.guild_data().await.unwrap()?;
guild_data.ephemeral_confirmations = false;
guild_data.commit_changes(&ctx.data().database).await;
ctx.send(|r| {
r.ephemeral(true).embed(|e| {
e.title("Confirmations public")
.description(
"Reminder confirmations will be sent as regular messages, and won't be removed automatically.",
)
.color(*THEME_COLOR)
})
})
.await?;
Ok(())
}
/// Configure whether other users can set reminders to your direct messages
#[poise::command(slash_command, rename = "dm", identifying_name = "allowed_dm")]
pub async fn allowed_dm(_ctx: Context<'_>) -> Result<(), Error> {
@ -109,7 +181,7 @@ pub async fn allowed_dm(_ctx: Context<'_>) -> Result<(), Error> {
}
/// Allow other users to set reminders in your direct messages
#[poise::command(slash_command, rename = "allow", identifying_name = "allowed_dm")]
#[poise::command(slash_command, rename = "allow", identifying_name = "set_allowed_dm")]
pub async fn set_allowed_dm(ctx: Context<'_>) -> Result<(), Error> {
let mut user_data = ctx.author_data().await?;
user_data.allowed_dm = true;
@ -128,7 +200,7 @@ pub async fn set_allowed_dm(ctx: Context<'_>) -> Result<(), Error> {
}
/// Block other users from setting reminders in your direct messages
#[poise::command(slash_command, rename = "block", identifying_name = "allowed_dm")]
#[poise::command(slash_command, rename = "block", identifying_name = "unset_allowed_dm")]
pub async fn unset_allowed_dm(ctx: Context<'_>) -> Result<(), Error> {
let mut user_data = ctx.author_data().await?;
user_data.allowed_dm = false;

View File

@ -645,7 +645,13 @@ async fn create_reminder(
return Ok(());
}
ctx.defer().await?;
let ephemeral =
ctx.guild_data().await.map_or(false, |gr| gr.map_or(false, |g| g.ephemeral_confirmations));
if ephemeral {
ctx.defer_ephemeral().await?;
} else {
ctx.defer().await?;
}
let user_data = ctx.author_data().await.unwrap();
let timezone = timezone.unwrap_or(ctx.timezone().await);
@ -692,9 +698,10 @@ async fn create_reminder(
},
)
} else {
ctx.say(
"`repeat` is only available to Patreon subscribers or self-hosted users",
)
ctx.send(|b| {
b.content(
"`repeat` is only available to Patreon subscribers or self-hosted users")
})
.await?;
return Ok(());
@ -704,13 +711,18 @@ async fn create_reminder(
};
if processed_interval.is_none() && interval.is_some() {
ctx.say(
"Repeat interval could not be processed. Try similar to `1 hour` or `4 days`",
)
ctx.send(|b| {
b.content(
"Repeat interval could not be processed. Try similar to `1 hour` or `4 days`")
})
.await?;
} else if processed_expires.is_none() && expires.is_some() {
ctx.say("Expiry time failed to process. Please make it as clear as possible")
.await?;
ctx.send(|b| {
b.ephemeral(true).content(
"Expiry time failed to process. Please make it as clear as possible",
)
})
.await?;
} else {
let mut builder = MultiReminderBuilder::new(&ctx, ctx.guild_id())
.author(user_data)