summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/main.rs b/src/main.rs
index 9a96791..cb4e384 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -6,9 +6,16 @@ extern crate glob;
extern crate irc;
extern crate time;
+#[cfg(feature = "mysql")]
+#[macro_use]
+extern crate diesel_migrations;
+#[cfg(feature = "mysql")]
+extern crate diesel;
+
#[macro_use]
extern crate log;
+use std::collections::HashMap;
use log::{Level, LevelFilter, Metadata, Record};
use irc::client::reactor::IrcReactor;
@@ -17,6 +24,9 @@ use glob::glob;
use frippy::plugins;
use frippy::Config;
+#[cfg(feature = "mysql")]
+embed_migrations!();
+
struct Logger;
impl log::Log for Logger {
@@ -86,10 +96,16 @@ fn main() {
// Open a connection and add work for each config
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.split(',').map(|p| p.trim()).collect::<Vec<_>>());
+ disabled_plugins = Some(disabled
+ .split(",")
+ .map(|p| p.trim())
+ .collect::<Vec<_>>());
}
+
+ mysql_url = options.get("mysql_url");
}
let mut bot = frippy::Bot::new();
@@ -100,6 +116,39 @@ fn main() {
bot.add_plugin(plugins::KeepNick::new());
bot.add_plugin(plugins::Tell::new());
+ #[cfg(feature = "mysql")]
+ {
+ if let Some(url) = mysql_url {
+ use diesel;
+ use diesel::Connection;
+ match diesel::mysql::MysqlConnection::establish(url) {
+ Ok(conn) => {
+ match embedded_migrations::run(&conn) {
+ Ok(_) => {
+ bot.add_plugin(plugins::Factoids::new(conn));
+ info!("Connected to MySQL server")
+ }
+ Err(e) => {
+ bot.add_plugin(plugins::Factoids::new(HashMap::new()));
+ error!("Failed to run migrations: {}", e);
+ }
+ }
+ }
+ Err(e) => error!("Failed to connect to database: {}", e),
+ }
+ } else {
+ bot.add_plugin(plugins::Factoids::new(HashMap::new()));
+ }
+ }
+ #[cfg(not(feature = "mysql"))]
+ {
+ 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 {
for name in disabled_plugins {
if bot.remove_plugin(name).is_none() {