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;
|
|
|
|
|
2017-02-13 00:22:06 -06:00
|
|
|
use Tenquestionmarks;
|
2017-02-25 20:17:46 -06:00
|
|
|
use 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
|
|
|
|
2017-05-09 22:44:33 -05:00
|
|
|
use toml::Table;
|
|
|
|
|
2017-05-10 00:17:22 -05:00
|
|
|
use std::collections::btree_set::BTreeSet;
|
|
|
|
|
2017-05-09 22:44:33 -05:00
|
|
|
pub struct Module {
|
|
|
|
event_loop: Box<EventLoop>,
|
|
|
|
module_type: String,
|
|
|
|
config: Table
|
|
|
|
}
|
|
|
|
|
2017-05-09 22:48:04 -05:00
|
|
|
impl Module {
|
|
|
|
pub fn run (&self, sender: Box<ExtSender<Envelope>>, receiver: Receiver<Arc<Envelope>>) {
|
|
|
|
self.event_loop.run(sender, receiver);
|
|
|
|
}
|
2017-05-10 00:17:22 -05:00
|
|
|
|
|
|
|
pub fn can_handle_event (&self, envelope: &Envelope) -> bool {
|
|
|
|
let filters: BTreeSet<String> = self.config.get("filters")
|
|
|
|
.and_then(|value| value.as_slice())
|
|
|
|
.map(|value| value.to_vec())
|
|
|
|
.unwrap_or(vec![])
|
|
|
|
.into_iter()
|
|
|
|
.map(|value| { String::from(value.as_str().unwrap()) })
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
if filters.is_empty() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
filters.intersection(&envelope.tags).count() > 0
|
|
|
|
}
|
2017-05-09 22:48:04 -05:00
|
|
|
}
|
|
|
|
|
2017-05-09 22:44:33 -05:00
|
|
|
pub trait EventLoop : Sync {
|
2017-02-25 21:11:25 -06:00
|
|
|
fn run (&self, _: Box<ExtSender<Envelope>>, _: Receiver<Arc<Envelope>>) {}
|
2017-02-08 03:25:03 -06:00
|
|
|
}
|