use chrono::NaiveDate;
use commands::Command;
use controller::Tri;
use errors::Result;
use priority::Priority;
#[derive(Debug, PartialEq)]
pub struct AddTask {
pub due_date: Option<NaiveDate>,
pub name: String,
pub priority: Priority,
pub user_slack_id: String,
}
impl Command for AddTask {
fn examples(user: &str) -> Vec<String> {
vec![
format!(
"add extreme priority task due 2001-02-03 to <@{}> buy more snacks",
user
),
format!(
"add minimal priority task to <@{}> fix Minnehack registration",
user
),
]
}
fn run(&self, tri: &Tri, user: &str) -> Result<String> {
let assignee = tri.must_find_user(&self.user_slack_id)?;
let task = tri.add_task(
&assignee,
&self.name,
self.priority,
self.due_date,
)?;
if assignee.slack_id != user {
let msg = format!(
"You were just assigned a task (#{}) by <@{}>.",
task.id,
user
);
tri.message_user(&assignee, &msg)?;
}
Ok(format!("Added as #{}.", task.id))
}
}