summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2017-12-11 01:49:09 +0100
committerJokler <jokler.contact@gmail.com>2017-12-11 01:49:09 +0100
commitab70f0e6dff916638edfc95d406922b3fd15df7d (patch)
tree26ab4e7d00427f5743f19ba113bb18afab8b252e /bin
parent6ba6651cdda7528e39a94c596b5137ec4f8d32e6 (diff)
downloadfrippy-ab70f0e6dff916638edfc95d406922b3fd15df7d.tar.gz
frippy-ab70f0e6dff916638edfc95d406922b3fd15df7d.zip
Move Config logic out of the library
Diffstat (limited to 'bin')
-rw-r--r--bin/main.rs53
1 files changed, 46 insertions, 7 deletions
diff --git a/bin/main.rs b/bin/main.rs
index 614bffe..b220b0c 100644
--- a/bin/main.rs
+++ b/bin/main.rs
@@ -1,10 +1,20 @@
extern crate frippy;
-extern crate log;
extern crate time;
+extern crate tokio_core;
+extern crate glob;
+extern crate futures;
+
+#[macro_use]
+extern crate log;
use log::{LogRecord, LogLevel, LogLevelFilter, LogMetadata};
+use tokio_core::reactor::Core;
+use futures::future;
+use glob::glob;
+
use frippy::plugins;
+use frippy::Config;
struct Logger;
@@ -45,12 +55,41 @@ fn main() {
})
.unwrap();
- let mut bot = frippy::Bot::new();
+ // Load all toml files in the configs directory
+ let mut configs = Vec::new();
+ for toml in glob("configs/*.toml").unwrap() {
+ match toml {
+ Ok(path) => {
+ info!("Loading {}", path.to_str().unwrap());
+ match Config::load(path) {
+ Ok(v) => configs.push(v),
+ Err(e) => error!("Incorrect config file {}", e),
+ }
+ }
+ Err(e) => error!("Failed to read path {}", e),
+ }
+ }
+
+ // Without configs the bot would just idle
+ if configs.is_empty() {
+ error!("No config file found");
+ return;
+ }
+
+ // Create an event loop to run the connections on.
+ let mut reactor = Core::new().unwrap();
+
+ // Open a connection and add work for each config
+ for config in configs {
+ let mut bot = frippy::Bot::new();
+ bot.add_plugin(plugins::Help::new());
+ bot.add_plugin(plugins::Emoji::new());
+ bot.add_plugin(plugins::Currency::new());
+ bot.add_plugin(plugins::KeepNick::new());
- bot.add_plugin(plugins::Help::new());
- bot.add_plugin(plugins::Emoji::new());
- bot.add_plugin(plugins::Currency::new());
- bot.add_plugin(plugins::KeepNick::new());
+ bot.connect(&mut reactor, &config);
+ }
- bot.run();
+ // Run the main loop forever
+ reactor.run(future::empty::<(), ()>()).unwrap();
}