diff --git a/src/commands/todo_cmds.rs b/src/commands/todo_cmds.rs index 92d4dfc..154553c 100644 --- a/src/commands/todo_cmds.rs +++ b/src/commands/todo_cmds.rs @@ -3,6 +3,9 @@ use regex_command_attr::command; use serenity::{ client::Context, model::{ + id::{ + UserId, GuildId, ChannelId, + }, channel::{ Message, }, @@ -11,23 +14,9 @@ use serenity::{ }; enum TodoTarget { - User, - Channel, - Guild, -} - -impl TodoTarget { - fn from_str(string: &str) -> Option { - match string { - "user" => Some(Self::User), - - "channel" => Some(Self::Channel), - - "server" | "guild" => Some(Self::Guild), - - _ => None - } - } + User(UserId), + Channel(ChannelId), + Guild(GuildId), } enum SubCommand { @@ -39,6 +28,63 @@ enum SubCommand { #[command] async fn todo_parse(ctx: &Context, msg: &Message, args: String) -> CommandResult { + + let mut split = args.split(" "); + + if let Some(target) = split.next() { + target_opt = match target { + "user" => + TodoTarget::User(msg.author.id), + + "channel" => + TodoTarget::Channel(msg.channel_id), + + "server" | "guild" => { + if let Some(gid) = msg.guild_id { + TodoTarget::Guild(gid) + } + else { + None + } + }, + + _ => { + None + }, + }; + + if let Some(target) = target_opt { + + let subcommand_opt = match split.next() { + + Some("add") => Some(SubCommand::Add), + + Some("remove") => Some(SubCommand::Remove), + + Some("clear") => Some(SubCommand::Clear), + + None => Some(SubCommand::View), + + Some(_unrecognised) => None, + }; + + if let Some(subcommand) = subcommand_opt { + todo(ctx, target, subcommand).await; + } + else { + let _ = msg.channel_id.say(&ctx, "Todo help").await; + } + + } + else { + let _ = msg.channel_id.say(&ctx, "Todo help").await; + } + + } + else { + let _ = msg.channel_id.say(&ctx, "Todo help").await; + } + Ok(()) }