Link all top-level commands with macro recording/replaying logic
This commit is contained in:
@ -6,7 +6,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,
|
||||
};
|
||||
|
||||
@ -30,49 +30,58 @@ pub struct Options {
|
||||
timezone: Option<String>,
|
||||
}
|
||||
|
||||
pub async fn multiline(ctx: Context<'_>, options: Options) -> Result<(), Error> {
|
||||
match ctx {
|
||||
Context::Application(app_ctx) => {
|
||||
let tz = options.timezone.map(|t| t.parse::<Tz>().ok()).flatten();
|
||||
let data_opt = ContentModal::execute(app_ctx).await?;
|
||||
impl Recordable for Options {
|
||||
async fn run(self, ctx: Context<'_>) -> Result<(), Error> {
|
||||
match ctx {
|
||||
Context::Application(app_ctx) => {
|
||||
let tz = self.timezone.map(|t| t.parse::<Tz>().ok()).flatten();
|
||||
let data_opt = ContentModal::execute(app_ctx).await?;
|
||||
|
||||
match data_opt {
|
||||
Some(data) => {
|
||||
create_reminder(
|
||||
ctx,
|
||||
options.time,
|
||||
data.content,
|
||||
options.channels,
|
||||
options.interval,
|
||||
options.expires,
|
||||
options.tts,
|
||||
tz,
|
||||
)
|
||||
.await
|
||||
}
|
||||
|
||||
None => {
|
||||
warn!("Unexpected None encountered in /multiline");
|
||||
Ok(ctx
|
||||
.send(CreateReply::default().content("Unexpected error.").ephemeral(true))
|
||||
match data_opt {
|
||||
Some(data) => {
|
||||
create_reminder(
|
||||
ctx,
|
||||
self.time,
|
||||
data.content,
|
||||
self.channels,
|
||||
self.interval,
|
||||
self.expires,
|
||||
self.tts,
|
||||
tz,
|
||||
)
|
||||
.await
|
||||
.map(|_| ())?)
|
||||
}
|
||||
|
||||
None => {
|
||||
warn!("Unexpected None encountered in /multiline");
|
||||
Ok(ctx
|
||||
.send(
|
||||
CreateReply::default().content("Unexpected error.").ephemeral(true),
|
||||
)
|
||||
.await
|
||||
.map(|_| ())?)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_ => {
|
||||
warn!("Shouldn't be here");
|
||||
Ok(ctx
|
||||
.send(CreateReply::default().content("Unexpected error.").ephemeral(true))
|
||||
.await
|
||||
.map(|_| ())?)
|
||||
_ => {
|
||||
warn!("Shouldn't be here");
|
||||
Ok(ctx
|
||||
.send(CreateReply::default().content("Unexpected error.").ephemeral(true))
|
||||
.await
|
||||
.map(|_| ())?)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Create a reminder with multi-line content. Press "+4 more" for other options.
|
||||
#[poise::command(slash_command, rename = "multiline", default_member_permissions = "MANAGE_GUILD")]
|
||||
#[poise::command(
|
||||
slash_command,
|
||||
rename = "multiline",
|
||||
identifying_name = "multiline",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn command(
|
||||
ctx: Context<'_>,
|
||||
#[description = "A description of the time to set the reminder for"]
|
||||
@ -89,5 +98,5 @@ pub async fn command(
|
||||
#[autocomplete = "timezone_autocomplete"]
|
||||
timezone: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
multiline(ctx, Options { time, channels, interval, expires, tts, timezone }).await
|
||||
(Options { time, channels, interval, expires, tts, timezone }).run(ctx).await
|
||||
}
|
||||
|
Reference in New Issue
Block a user