1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
mod autoproxy;
// mod edit;
// mod ghost;
mod prefixes;
// mod reproxy;
use std::{collections::HashMap, sync::Arc};
use async_trait::async_trait;
use twilight_model::{channel::{Channel, Message}, id::{marker::ChannelMarker, Id}};
use super::log::Logger;
use crate::system::types::{System, Response};
pub use prefixes::ProxyPrefixes;
pub use autoproxy::Autoproxy;
#[async_trait]
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<'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>>>>) {
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)
}
|