diff --git a/.idea/dictionaries/jude.xml b/.idea/dictionaries/jude.xml index ac7ff8c..eada3dc 100644 --- a/.idea/dictionaries/jude.xml +++ b/.idea/dictionaries/jude.xml @@ -2,6 +2,7 @@ reqwest + subcommand todos webhook webhooks diff --git a/src/commands/reminder_cmds.rs b/src/commands/reminder_cmds.rs index 226ab5c..8f0e874 100644 --- a/src/commands/reminder_cmds.rs +++ b/src/commands/reminder_cmds.rs @@ -1034,7 +1034,7 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult { if let (Some(time_crop), Some(msg_crop)) = (time_crop_opt, msg_crop_opt) { let python_call = Command::new(&*PYTHON_LOCATION) .arg("-c") - .arg(include_str!("../../dp.py")) + .arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py"))) .arg(time_crop) .arg(&user_data.timezone) .arg(&*LOCAL_TIMEZONE) @@ -1094,7 +1094,7 @@ async fn natural(ctx: &Context, msg: &Message, args: String) -> CommandResult { let python_call = Command::new(&*PYTHON_LOCATION) .arg("-c") - .arg(include_str!("../../dp.py")) + .arg(include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/dp.py"))) .arg(&format!("1 {}", interval_str)) .arg(&*LOCAL_TIMEZONE) .arg(&*LOCAL_TIMEZONE) diff --git a/src/commands/todo_cmds.rs b/src/commands/todo_cmds.rs index ebfb769..ea8287d 100644 --- a/src/commands/todo_cmds.rs +++ b/src/commands/todo_cmds.rs @@ -17,6 +17,7 @@ use crate::{ SQLPool, }; use sqlx::MySqlPool; +use std::convert::TryFrom; #[derive(Debug)] struct TodoNotFound; @@ -240,6 +241,24 @@ enum SubCommand { Clear, } +impl TryFrom> for SubCommand { + type Error = (); + + fn try_from(value: Option<&str>) -> Result { + match value { + Some("add") => Ok(SubCommand::Add), + + Some("remove") => Ok(SubCommand::Remove), + + Some("clear") => Ok(SubCommand::Clear), + + None => Ok(SubCommand::View), + + Some(_unrecognised) => Err(()), + } + } +} + impl ToString for SubCommand { fn to_string(&self) -> String { match self { @@ -252,6 +271,35 @@ impl ToString for SubCommand { } } +#[command] +#[permission_level(Managed)] +async fn todo_user(ctx: &Context, msg: &Message, args: String) -> CommandResult { + let mut split = args.split(' '); + + let target = TodoTarget { + user: msg.author.id, + guild: None, + channel: None, + }; + + let subcommand_opt = SubCommand::try_from(split.next()); + + if let Ok(subcommand) = subcommand_opt { + todo( + ctx, + msg, + target, + subcommand, + split.collect::>().join(" "), + ) + .await; + } else { + show_help(&ctx, msg, Some(target)).await; + } + + Ok(()) +} + #[command] #[permission_level(Managed)] async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult { @@ -293,19 +341,9 @@ async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult }; if let Some(target) = target_opt { - let subcommand_opt = match split.next() { - Some("add") => Some(SubCommand::Add), + let subcommand_opt = SubCommand::try_from(split.next()); - Some("remove") => Some(SubCommand::Remove), - - Some("clear") => Some(SubCommand::Clear), - - None => Some(SubCommand::View), - - Some(_unrecognised) => None, - }; - - if let Some(subcommand) = subcommand_opt { + if let Ok(subcommand) = subcommand_opt { todo( ctx, msg,