Link all top-level commands with macro recording/replaying logic

This commit is contained in:
jude
2024-02-18 13:24:37 +00:00
parent 5e39e16060
commit 76a286076b
25 changed files with 619 additions and 410 deletions

View File

@ -4,7 +4,7 @@ use serde::{Deserialize, Serialize};
use crate::{
commands::autocomplete::{time_hint_autocomplete, timezone_autocomplete},
models::reminder::create_reminder,
utils::Extract,
utils::{Extract, Recordable},
Context, Error,
};
@ -19,24 +19,31 @@ pub struct Options {
timezone: Option<String>,
}
pub async fn remind(ctx: Context<'_>, options: Options) -> Result<(), Error> {
let tz = options.timezone.map(|t| t.parse::<Tz>().ok()).flatten();
impl Recordable for Options {
async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
let tz = self.timezone.map(|t| t.parse::<Tz>().ok()).flatten();
create_reminder(
ctx,
options.time,
options.content,
options.channels,
options.interval,
options.expires,
options.tts,
tz,
)
.await
create_reminder(
ctx,
self.time,
self.content,
self.channels,
self.interval,
self.expires,
self.tts,
tz,
)
.await
}
}
/// Create a reminder. Press "+4 more" for other options. Use "/multiline" for multiline content.
#[poise::command(slash_command, rename = "remind", default_member_permissions = "MANAGE_GUILD")]
#[poise::command(
slash_command,
rename = "remind",
default_member_permissions = "MANAGE_GUILD",
identifying_name = "remind"
)]
pub async fn command(
ctx: Context<'_>,
#[description = "The time (and optionally date) to set the reminder for"]
@ -54,5 +61,5 @@ pub async fn command(
#[autocomplete = "timezone_autocomplete"]
timezone: Option<String>,
) -> Result<(), Error> {
remind(ctx, Options { time, content, channels, interval, expires, tts, timezone }).await
(Options { time, content, channels, interval, expires, tts, timezone }).run(ctx).await
}