mod autoproxy; mod edit; // mod ghost; mod prefixes; // mod reproxy; use std::{collections::HashMap, sync::Arc}; use async_trait::async_trait; use edit::Edit; use twilight_model::{channel::Message, id::{marker::ChannelMarker, Id}}; use super::log::Logger; use crate::system::types::{System, Response}; pub use prefixes::ProxyPrefixes; pub use autoproxy::Autoproxy; #[derive(Copy, Clone, Debug)] pub enum PluginCommand { Word(&'static str), Char(&'static str), } #[async_trait] pub trait SeancePlugin<'system> { fn get_commands(&self) -> Vec; 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, response: &'message Response); } pub fn get_plugins<'system>() -> (Vec>>>, HashMap<&'static str, (PluginCommand, Arc>>)>) { let all_plugins : Vec>>> = vec![ 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| { match command { PluginCommand::Word(command_word) => (command_word, (command, plugin.clone())), PluginCommand::Char(command_char) => (command_char, (command, plugin.clone())), } }) }) .flatten() .collect(); (all_plugins, by_commands) }