Extract trait
This commit is contained in:
@ -4,18 +4,49 @@ use serde::{Deserialize, Serialize};
|
||||
use crate::{
|
||||
commands::autocomplete::{time_hint_autocomplete, timezone_autocomplete},
|
||||
models::reminder::create_reminder,
|
||||
utils::{extract_arg, Extract},
|
||||
ApplicationContext, Context, Error,
|
||||
};
|
||||
|
||||
#[derive(Serialize, Deserialize, Default)]
|
||||
pub struct RemindOptions {
|
||||
pub time: String,
|
||||
pub content: String,
|
||||
pub channels: Option<String>,
|
||||
pub interval: Option<String>,
|
||||
pub expires: Option<String>,
|
||||
pub tts: Option<bool>,
|
||||
pub timezone: Option<Tz>,
|
||||
#[derive(Serialize, Deserialize)]
|
||||
pub struct Options {
|
||||
time: String,
|
||||
content: String,
|
||||
channels: Option<String>,
|
||||
interval: Option<String>,
|
||||
expires: Option<String>,
|
||||
tts: Option<bool>,
|
||||
timezone: Option<String>,
|
||||
}
|
||||
|
||||
impl Extract for Options {
|
||||
fn extract(ctx: ApplicationContext) -> Self {
|
||||
Self {
|
||||
time: extract_arg!(ctx, "time", String),
|
||||
content: extract_arg!(ctx, "content", String),
|
||||
channels: extract_arg!(ctx, "channels", Option<String>),
|
||||
interval: extract_arg!(ctx, "interval", Option<String>),
|
||||
expires: extract_arg!(ctx, "expires", Option<String>),
|
||||
tts: extract_arg!(ctx, "tts", Option<bool>),
|
||||
timezone: extract_arg!(ctx, "timezone", Option<String>),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn remind(ctx: Context<'_>, options: Options) -> Result<(), Error> {
|
||||
let tz = options.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 a reminder. Press "+4 more" for other options. Use "/multiline" for multiline content.
|
||||
@ -24,8 +55,8 @@ pub struct RemindOptions {
|
||||
identifying_name = "remind",
|
||||
default_member_permissions = "MANAGE_GUILD"
|
||||
)]
|
||||
pub async fn remind(
|
||||
ctx: ApplicationContext<'_>,
|
||||
pub async fn command(
|
||||
ctx: Context<'_>,
|
||||
#[description = "The time (and optionally date) to set the reminder for"]
|
||||
#[autocomplete = "time_hint_autocomplete"]
|
||||
time: String,
|
||||
@ -41,8 +72,5 @@ pub async fn remind(
|
||||
#[autocomplete = "timezone_autocomplete"]
|
||||
timezone: Option<String>,
|
||||
) -> Result<(), Error> {
|
||||
let tz = timezone.map(|t| t.parse::<Tz>().ok()).flatten();
|
||||
|
||||
create_reminder(Context::Application(ctx), time, content, channels, interval, expires, tts, tz)
|
||||
.await
|
||||
remind(ctx, Options { time, content, channels, interval, expires, tts, timezone }).await
|
||||
}
|
||||
|
Reference in New Issue
Block a user