2017-02-08 03:25:03 -06:00
|
|
|
pub mod lua;
|
|
|
|
pub mod discord;
|
2017-02-13 00:22:06 -06:00
|
|
|
pub mod stdin;
|
|
|
|
pub mod echo;
|
2017-02-16 02:00:38 -06:00
|
|
|
pub mod random;
|
2017-02-19 04:49:06 -06:00
|
|
|
pub mod pvn;
|
2017-02-22 23:40:30 -06:00
|
|
|
pub mod echobox;
|
2017-02-26 17:17:22 -06:00
|
|
|
pub mod autolink;
|
2017-05-09 23:36:56 -05:00
|
|
|
pub mod logger;
|
2017-02-08 03:25:03 -06:00
|
|
|
|
|
|
|
pub mod loader;
|
|
|
|
|
2018-02-22 02:40:22 -06:00
|
|
|
use event::{Event, Envelope};
|
2017-02-08 03:25:03 -06:00
|
|
|
|
2017-02-19 02:55:30 -06:00
|
|
|
use std::sync::Arc;
|
2017-02-25 21:11:25 -06:00
|
|
|
use std::sync::mpsc::Receiver;
|
|
|
|
use transformable_channels::mpsc::ExtSender;
|
2017-02-13 00:22:06 -06:00
|
|
|
|
2018-02-18 16:29:30 -06:00
|
|
|
use toml::value::Table;
|
2017-05-09 22:44:33 -05:00
|
|
|
|
|
|
|
pub struct Module {
|
|
|
|
event_loop: Box<EventLoop>,
|
|
|
|
module_type: String,
|
2018-02-22 01:09:39 -06:00
|
|
|
pub config: Table,
|
2017-05-09 22:44:33 -05:00
|
|
|
}
|
|
|
|
|
2017-05-09 22:48:04 -05:00
|
|
|
impl Module {
|
2018-02-22 02:40:22 -06:00
|
|
|
pub fn run (&self, sender: Box<ExtSender<Event>>, receiver: Receiver<Arc<Envelope>>) {
|
2017-05-09 22:48:04 -05:00
|
|
|
self.event_loop.run(sender, receiver);
|
|
|
|
}
|
2018-02-22 01:09:39 -06:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|
2017-05-09 22:48:04 -05:00
|
|
|
}
|
|
|
|
|
2017-05-09 22:44:33 -05:00
|
|
|
pub trait EventLoop : Sync {
|
2018-02-22 02:40:22 -06:00
|
|
|
fn run (&self, _: Box<ExtSender<Event>>, _: Receiver<Arc<Envelope>>) {}
|
2017-02-08 03:25:03 -06:00
|
|
|
}
|