diff options
| author | Jokler <jokler.contact@gmail.com> | 2017-12-24 14:46:48 +0100 |
|---|---|---|
| committer | Jokler <jokler.contact@gmail.com> | 2017-12-24 14:46:48 +0100 |
| commit | b98d1ce014eb6b502601547d46fc522ed6a4b416 (patch) | |
| tree | 3c66153cbc601312853a4c0acee94433917f447e /bin/main.rs | |
| parent | 5fdb7198bc73035cf5621ded8183000c3fcbbe29 (diff) | |
| download | frippy-b98d1ce014eb6b502601547d46fc522ed6a4b416.tar.gz frippy-b98d1ce014eb6b502601547d46fc522ed6a4b416.zip | |
Add mysql_url option to the toml files
Diffstat (limited to 'bin/main.rs')
| -rw-r--r-- | bin/main.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/bin/main.rs b/bin/main.rs index 7869548..8f1877a 100644 --- a/bin/main.rs +++ b/bin/main.rs @@ -13,7 +13,6 @@ extern crate diesel; #[macro_use] extern crate log; -#[cfg(not(feature = "mysql"))] use std::collections::HashMap; use log::{LogRecord, LogLevel, LogLevelFilter, LogMetadata}; @@ -94,6 +93,7 @@ fn main() { for config in configs { let mut disabled_plugins = None; + let mut mysql_url = None; if let &Some(ref options) = &config.options { if let Some(disabled) = options.get("disabled_plugins") { disabled_plugins = Some(disabled @@ -101,6 +101,8 @@ fn main() { .map(|p| p.trim()) .collect::<Vec<_>>()); } + + mysql_url = options.get("mysql_url"); } let mut bot = frippy::Bot::new(); @@ -111,18 +113,27 @@ fn main() { bot.add_plugin(plugins::KeepNick::new()); #[cfg(feature = "mysql")] { - use diesel; - use diesel::Connection; - match diesel::mysql::MysqlConnection::establish("mysql://user:password@address/db") { - Ok(conn) => { - embedded_migrations::run(&conn).unwrap(); - bot.add_plugin(plugins::Factoids::new(conn)); + if let Some(url) = mysql_url { + use diesel; + use diesel::Connection; + match diesel::mysql::MysqlConnection::establish(url) { + Ok(conn) => { + embedded_migrations::run(&conn).unwrap(); + bot.add_plugin(plugins::Factoids::new(conn)); + } + Err(e) => error!("Failed to connect to database: {}", e), } - Err(e) => error!("Failed to connect to database: {}", e), + } else { + bot.add_plugin(plugins::Factoids::new(HashMap::new())); } } #[cfg(not(feature = "mysql"))] - bot.add_plugin(plugins::Factoids::new(HashMap::new())); + { + if let Some(_) = mysql_url { + error!("frippy was not built with the mysql feature") + } + bot.add_plugin(plugins::Factoids::new(HashMap::new())); + } if let Some(disabled_plugins) = disabled_plugins { |
