diff options
Diffstat (limited to 'src/system/plugin.rs')
-rw-r--r-- | src/system/plugin.rs | 36 |
1 files changed, 28 insertions, 8 deletions
diff --git a/src/system/plugin.rs b/src/system/plugin.rs index d3c6764..4419955 100644 --- a/src/system/plugin.rs +++ b/src/system/plugin.rs @@ -1,5 +1,10 @@ mod autoproxy; +// mod edit; +// mod ghost; mod prefixes; +// mod reproxy; + +use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; @@ -12,16 +17,31 @@ pub use prefixes::ProxyPrefixes; pub use autoproxy::Autoproxy; #[async_trait] -pub trait SeancePlugin { - async fn handle_command(&self, logger: &Logger, system: &System, message: &Message) -> CommandOutcome; +pub trait SeancePlugin<'system> { + fn get_commands(&self) -> Vec<&'static str>; + + async fn handle_command<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, args: Vec<&'message str>); - async fn handle_message(&self, logger: &Logger, system: &System, message: &Message, response: &mut Response); + async fn handle_message<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, response: &'message mut Response); - async fn post_response(&self, logger: &Logger, system: &System, message: &Message, channel: Id<ChannelMarker>, response: &Response); + async fn post_response<'message>(&self, logger: &'system Logger, system: &'system System, message: &'message Message, channel: Id<ChannelMarker>, response: &'message Response); } -pub enum CommandOutcome { - Skipped, - Handled, - Errored {message: String}, +pub fn get_plugins<'system>() -> (Vec<Arc<Box<dyn SeancePlugin<'system>>>>, HashMap<&'static str, Arc<Box<dyn SeancePlugin<'system>>>>) { + let all_plugins : Vec<Arc<Box<dyn SeancePlugin<'system>>>> = vec![ + Arc::new(Box::new(ProxyPrefixes)), + Arc::new(Box::new(Autoproxy::new())), + ]; + + let by_commands = all_plugins.iter() + .map(|plugin| { + let commands = plugin.get_commands(); + commands.into_iter().map(|command| { + (command, plugin.clone()) + }) + }) + .flatten() + .collect(); + + (all_plugins, by_commands) } |