use crate::core::colours; use crate::core::consts::*; use crate::core::consts::DB as db; use crate::core::utils::*; use serenity::framework::standard::{ Args, Command, CommandError, CommandOptions }; use serenity::model::channel::Message; use serenity::model::Permissions; use serenity::prelude::Context; use std::sync::Arc; pub struct NoteAdd; impl Command for NoteAdd { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Of the forgetful kind? Add a note to someone!".to_string()), usage: Some(" ".to_string()), example: Some("@fun test note".to_string()), required_permissions: Permissions::MANAGE_MESSAGES, ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { match parse_user(args.single::().unwrap_or(String::new()), guild_id) { Some((user,_)) => { let note = args.rest().to_string(); let data = db.new_note(user.0 as i64, guild_id.0 as i64, note, message.author.id.0 as i64)?; message.channel_id.say(format!("Added note `{}`.", data.note))?; }, None => { message.channel_id.say("I couldn't find that user")?; } } } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct NoteRemove; impl Command for NoteRemove { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Oh, you remembered...".to_string()), usage: Some(" ".to_string()), example: Some("@fun 3".to_string()), aliases: vec!["del", "rm"].iter().map(|e| e.to_string()).collect(), required_permissions: Permissions::MANAGE_MESSAGES, ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { match parse_user(args.single::().unwrap_or(String::new()), guild_id) { Some((user,_)) => { let index = args.single::().unwrap_or(0); let data = db.del_note(index, user.0 as i64, guild_id.0 as i64)?; message.channel_id.say(format!("Deleted note `{}`.", data))?; }, None => { message.channel_id.say("I couldn't find that user")?; } } } else { failed!(GUILDID_FAIL); } Ok(()) } } pub struct NoteList; impl Command for NoteList { fn options(&self) -> Arc { let default = CommandOptions::default(); let options = CommandOptions { desc: Some("Checking in? See all the notes on someone.".to_string()), usage: Some("".to_string()), example: Some("@fun".to_string()), aliases: vec!["ls"].iter().map(|e| e.to_string()).collect(), required_permissions: Permissions::MANAGE_MESSAGES, ..default }; Arc::new(options) } fn execute(&self, _: &mut Context, message: &Message, mut args: Args) -> Result<(), CommandError> { if let Some(guild_id) = message.guild_id { match parse_user(args.single::().unwrap_or(String::new()), guild_id) { Some((user_id, member)) => { let notes = db.get_notes(user_id.0 as i64, guild_id.0 as i64)?; let notes_fmt = notes.iter().map(|n| n.to_string()).collect::>().join("\n\n"); message.channel_id.send_message(|m| m .embed(|e| e .colour(*colours::MAIN) .title(format!("Notes for {}", member.display_name().into_owned())) .description(notes_fmt) ))?; }, None => { message.channel_id.say("I couldn't find that user")?; } } } else { failed!(GUILDID_FAIL); } Ok(()) } }