use super::standard::default_commands;
use super::traits::SlashCommand;
pub struct CommandRegistry {
commands: Vec<Box<dyn SlashCommand>>,
}
impl CommandRegistry {
pub fn new() -> Self {
Self {
commands: Vec::new(),
}
}
pub fn with_defaults() -> Self {
Self {
commands: default_commands(),
}
}
pub fn add<C: SlashCommand + 'static>(mut self, command: C) -> Self {
self.commands.push(Box::new(command));
self
}
pub fn add_boxed(mut self, command: Box<dyn SlashCommand>) -> Self {
self.commands.push(command);
self
}
pub fn remove(mut self, name: &str) -> Self {
self.commands.retain(|c| c.name() != name);
self
}
pub fn build(self) -> Vec<Box<dyn SlashCommand>> {
self.commands
}
pub fn commands(&self) -> &[Box<dyn SlashCommand>] {
&self.commands
}
}
impl Default for CommandRegistry {
fn default() -> Self {
Self::with_defaults()
}
}