working on todo command

This commit is contained in:
jude 2020-08-11 00:26:39 +01:00
parent f37bf23d9f
commit 868e29c53a

View File

@ -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<Self> {
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(())
}