2022-06-04 11:58:21 +00:00
|
|
|
use std::{any::Any, sync::Arc};
|
|
|
|
|
|
|
|
use async_trait::async_trait;
|
|
|
|
|
2022-06-04 18:10:21 +00:00
|
|
|
use crate::Client;
|
2022-06-04 11:58:21 +00:00
|
|
|
|
|
|
|
#[async_trait]
|
|
|
|
pub trait Command: Any + Send + Sync {
|
|
|
|
/// Command name
|
|
|
|
fn name(&self) -> &'static str;
|
2022-06-04 18:10:21 +00:00
|
|
|
/// Help message of this command
|
2022-06-04 11:58:21 +00:00
|
|
|
fn help(&self) -> &'static str;
|
|
|
|
/// Command function
|
2022-06-04 18:10:21 +00:00
|
|
|
async fn execute(&self, client: &mut Client, args: Vec<&str>, commands: &CommandManagerType);
|
2022-06-04 11:58:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CommandManager {
|
|
|
|
/// Vector with plugins
|
|
|
|
pub commands: Vec<Box<dyn Command>>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl CommandManager {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
Self {
|
|
|
|
commands: Vec::new(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for CommandManager {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-04 18:10:21 +00:00
|
|
|
pub type CommandManagerType = Arc<Vec<Box<dyn Command>>>;
|