2024-02-17 18:55:16 +00:00
|
|
|
use crate::{consts::MINUTE, models::CtxData, Context, Error};
|
|
|
|
|
2024-02-17 20:24:30 +00:00
|
|
|
pub struct Options {
|
|
|
|
minutes: Option<isize>,
|
|
|
|
seconds: Option<isize>,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn nudge(ctx: Context<'_>, options: Options) -> Result<(), Error> {
|
|
|
|
let combined_time =
|
|
|
|
options.minutes.map_or(0, |m| m * MINUTE as isize) + options.seconds.map_or(0, |s| s);
|
2024-02-17 18:55:16 +00:00
|
|
|
|
|
|
|
if combined_time < i16::MIN as isize || combined_time > i16::MAX as isize {
|
|
|
|
ctx.say("Nudge times must be less than 500 minutes").await?;
|
|
|
|
} else {
|
|
|
|
let mut channel_data = ctx.channel_data().await.unwrap();
|
|
|
|
|
|
|
|
channel_data.nudge = combined_time as i16;
|
|
|
|
channel_data.commit_changes(&ctx.data().database).await;
|
|
|
|
|
|
|
|
ctx.say(format!("Future reminders will be nudged by {} seconds", combined_time)).await?;
|
|
|
|
}
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
}
|
2024-02-17 20:24:30 +00:00
|
|
|
|
|
|
|
/// Nudge all future reminders on this channel by a certain amount (don't use for DST! See `/offset`)
|
|
|
|
#[poise::command(
|
|
|
|
slash_command,
|
|
|
|
identifying_name = "nudge",
|
|
|
|
default_member_permissions = "MANAGE_GUILD"
|
|
|
|
)]
|
|
|
|
pub async fn command(
|
|
|
|
ctx: Context<'_>,
|
|
|
|
#[description = "Number of minutes to nudge new reminders by"] minutes: Option<isize>,
|
|
|
|
#[description = "Number of seconds to nudge new reminders by"] seconds: Option<isize>,
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
nudge(ctx, Options { minutes, seconds }).await
|
|
|
|
}
|