diff options
Diffstat (limited to 'src/system/plugin.rs')
-rw-r--r-- | src/system/plugin.rs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/src/system/plugin.rs b/src/system/plugin.rs index 4419955..379606d 100644 --- a/src/system/plugin.rs +++ b/src/system/plugin.rs @@ -1,5 +1,5 @@ mod autoproxy; -// mod edit; +mod edit; // mod ghost; mod prefixes; // mod reproxy; @@ -8,6 +8,7 @@ use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; +use edit::Edit; use twilight_model::{channel::{Channel, Message}, id::{marker::ChannelMarker, Id}}; use super::log::Logger; @@ -16,28 +17,38 @@ use crate::system::types::{System, Response}; pub use prefixes::ProxyPrefixes; pub use autoproxy::Autoproxy; +#[derive(Copy, Clone, Debug)] +pub enum PluginCommand { + Long(&'static str), + Short(&'static str), +} + #[async_trait] pub trait SeancePlugin<'system> { - fn get_commands(&self) -> Vec<&'static str>; + fn get_commands(&self) -> Vec<PluginCommand>; - async fn handle_command<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, args: Vec<&'message str>); + async fn handle_command<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, command: PluginCommand, args: Vec<&'message str>); async fn handle_message<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, response: &'message mut Response); async fn post_response<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, channel: Id<ChannelMarker>, response: &'message Response); } -pub fn get_plugins<'system>() -> (Vec<Arc<Box<dyn SeancePlugin<'system>>>>, HashMap<&'static str, Arc<Box<dyn SeancePlugin<'system>>>>) { +pub fn get_plugins<'system>() -> (Vec<Arc<Box<dyn SeancePlugin<'system>>>>, HashMap<&'static str, (PluginCommand, Arc<Box<dyn SeancePlugin<'system>>>)>) { let all_plugins : Vec<Arc<Box<dyn SeancePlugin<'system>>>> = vec![ - Arc::new(Box::new(ProxyPrefixes)), + Arc::new(Box::new(ProxyPrefixes::new())), Arc::new(Box::new(Autoproxy::new())), + Arc::new(Box::new(Edit::new())), ]; let by_commands = all_plugins.iter() .map(|plugin| { let commands = plugin.get_commands(); commands.into_iter().map(|command| { - (command, plugin.clone()) + match command { + PluginCommand::Long(command_word) => (command_word, (command, plugin.clone())), + PluginCommand::Short(command_char) => (command_char, (command, plugin.clone())), + } }) }) .flatten() |