Add option types for top-level commands

This commit is contained in:
jude
2024-02-18 11:04:43 +00:00
parent c1305cfb36
commit 5e39e16060
22 changed files with 395 additions and 268 deletions

View File

@ -4,11 +4,11 @@ use serde::{Deserialize, Serialize};
use crate::{
commands::autocomplete::{time_hint_autocomplete, timezone_autocomplete},
models::reminder::create_reminder,
utils::{extract_arg, Extract},
ApplicationContext, Context, Error,
utils::Extract,
Context, Error,
};
#[derive(Serialize, Deserialize)]
#[derive(Serialize, Deserialize, Extract)]
pub struct Options {
time: String,
content: String,
@ -19,20 +19,6 @@ pub struct Options {
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();
@ -50,11 +36,7 @@ pub async fn remind(ctx: Context<'_>, options: Options) -> Result<(), Error> {
}
/// Create a reminder. Press "+4 more" for other options. Use "/multiline" for multiline content.
#[poise::command(
slash_command,
identifying_name = "remind",
default_member_permissions = "MANAGE_GUILD"
)]
#[poise::command(slash_command, rename = "remind", default_member_permissions = "MANAGE_GUILD")]
pub async fn command(
ctx: Context<'_>,
#[description = "The time (and optionally date) to set the reminder for"]