60 lines
1.5 KiB
Rust

pub mod lua;
pub mod discord;
pub mod stdin;
pub mod echo;
pub mod random;
pub mod pvn;
pub mod echobox;
pub mod autolink;
pub mod logger;
pub mod loader;
use event::{Event, Envelope};
use std::sync::Arc;
use std::sync::mpsc::Receiver;
use transformable_channels::mpsc::ExtSender;
use toml::value::Table;
pub struct Module {
event_loop: Box<EventLoop>,
module_type: String,
pub config: Table,
}
impl Module {
pub fn run (&self, sender: Box<ExtSender<Event>>, receiver: Receiver<Arc<Envelope>>) {
self.event_loop.run(sender, receiver);
}
pub fn parents (&self) -> Vec<String> {
self.config.get("parents")
.and_then(|value| value.as_array())
.map(|value| value.to_vec())
.unwrap_or(vec![])
.iter()
.map(|value| value.as_str())
.filter(|value| value.is_some())
.map(|value| value.unwrap().to_owned())
.collect()
}
pub fn children (&self) -> Vec<String> {
self.config.get("children")
.and_then(|value| value.as_array())
.map(|value| value.to_vec())
.unwrap_or(vec![])
.iter()
.map(|value| value.as_str())
.filter(|value| value.is_some())
.map(|value| value.unwrap().to_owned())
.collect()
}
}
pub trait EventLoop : Sync {
fn run (&self, _: Box<ExtSender<Event>>, _: Receiver<Arc<Envelope>>) {}
}