pub use ext::framework::command::{Command, CommandType, CommandGroup};
pub(crate) use ext::framework::command::CommandOrAlias;
pub use ext::framework::create_command::CreateCommand;
use std::default::Default;
use std::sync::Arc;
use ::client::Context;
use ::model::Message;
#[derive(Default)]
pub struct CreateGroup(pub CommandGroup);
impl CreateGroup {
pub fn command<F>(mut self, command_name: &str, f: F) -> Self
where F: FnOnce(CreateCommand) -> CreateCommand {
let cmd = f(CreateCommand(Command::default())).0;
for n in &cmd.aliases {
if let Some(ref prefix) = self.0.prefix {
self.0.commands.insert(format!("{} {}", prefix, n.to_owned()), CommandOrAlias::Alias(format!("{} {}", prefix, command_name.to_string())));
} else {
self.0.commands.insert(n.to_owned(), CommandOrAlias::Alias(command_name.to_string()));
}
}
self.0.commands.insert(command_name.to_owned(), CommandOrAlias::Command(Arc::new(cmd)));
self
}
pub fn on<F>(mut self, command_name: &str, f: F) -> Self
where F: Fn(&mut Context, &Message, Vec<String>) -> Result<(), String> + Send + Sync + 'static {
let cmd = Arc::new(Command::new(f));
self.0.commands.insert(command_name.to_owned(), CommandOrAlias::Command(cmd));
self
}
pub fn prefix(mut self, desc: &str) -> Self {
self.0.prefix = Some(desc.to_owned());
self
}
}