summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs108
1 files changed, 46 insertions, 62 deletions
diff --git a/src/main.rs b/src/main.rs
index b9a4b8f..ef24e4d 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -4,6 +4,7 @@
extern crate frippy;
extern crate glob;
extern crate irc;
+extern crate log4rs;
extern crate time;
#[cfg(feature = "mysql")]
@@ -21,80 +22,50 @@ extern crate failure;
#[macro_use]
extern crate log;
+use std::collections::HashMap;
#[cfg(feature = "mysql")]
use std::sync::Arc;
-use std::collections::HashMap;
-use log::{Level, LevelFilter, Metadata, Record};
-use irc::client::reactor::IrcReactor;
use glob::glob;
+use irc::client::reactor::IrcReactor;
-pub use frippy::plugins::help::Help;
-pub use frippy::plugins::url::Url;
-pub use frippy::plugins::emoji::Emoji;
-pub use frippy::plugins::tell::Tell;
-pub use frippy::plugins::currency::Currency;
-pub use frippy::plugins::keepnick::KeepNick;
-pub use frippy::plugins::factoids::Factoids;
+use frippy::plugins::unicode::Unicode;
+use frippy::plugins::factoid::Factoid;
+use frippy::plugins::help::Help;
+use frippy::plugins::keepnick::KeepNick;
+use frippy::plugins::quote::Quote;
+use frippy::plugins::remind::Remind;
+use frippy::plugins::sed::Sed;
+use frippy::plugins::tell::Tell;
+use frippy::plugins::url::UrlTitles;
-use frippy::Config;
use failure::Error;
+use frippy::Config;
#[cfg(feature = "mysql")]
embed_migrations!();
-struct Logger;
-
-impl log::Log for Logger {
- fn enabled(&self, metadata: &Metadata) -> bool {
- metadata.target().contains("frippy")
- }
-
- fn log(&self, record: &Record) {
- if self.enabled(record.metadata()) {
- if record.metadata().level() >= Level::Debug {
- println!(
- "[{}]({}) {} -> {}",
- time::now().rfc822(),
- record.level(),
- record.target(),
- record.args()
- );
- } else {
- println!(
- "[{}]({}) {}",
- time::now().rfc822(),
- record.level(),
- record.args()
- );
- }
+fn main() {
+ if let Err(e) = log4rs::init_file("log.yml", Default::default()) {
+ use log4rs::Error;
+ match e {
+ Error::Log(e) => eprintln!("Log4rs error: {}", e),
+ Error::Log4rs(e) => eprintln!("Failed to parse \"log.yml\" as log4rs config: {}", e),
}
- }
- fn flush(&self) {}
-}
-
-static LOGGER: Logger = Logger;
+ return;
+ }
-fn main() {
// Print any errors that caused frippy to shut down
if let Err(e) = run() {
- let text = e.causes()
- .skip(1)
+ let text = e
+ .iter_causes()
.fold(format!("{}", e), |acc, err| format!("{}: {}", acc, err));
error!("{}", text);
- };
+ }
}
fn run() -> Result<(), Error> {
- log::set_max_level(if cfg!(debug_assertions) {
- LevelFilter::Debug
- } else {
- LevelFilter::Info
- });
-
- log::set_logger(&LOGGER).unwrap();
-
// Load all toml files in the configs directory
let mut configs = Vec::new();
for toml in glob("configs/*.toml").unwrap() {
@@ -120,21 +91,24 @@ fn run() -> Result<(), Error> {
// Open a connection and add work for each config
for config in configs {
+ let mut prefix = None;
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<_>>());
}
+ prefix = options.get("prefix");
mysql_url = options.get("mysql_url");
}
+ let prefix = prefix.cloned().unwrap_or_else(|| String::from("."));
- let mut bot = frippy::Bot::new();
+ let mut bot = frippy::Bot::new(&prefix);
bot.add_plugin(Help::new());
- bot.add_plugin(Url::new(1024));
- bot.add_plugin(Emoji::new());
- bot.add_plugin(Currency::new());
+ bot.add_plugin(UrlTitles::new(1024));
+ bot.add_plugin(Sed::new(60));
+ bot.add_plugin(Unicode::new());
bot.add_plugin(KeepNick::new());
#[cfg(feature = "mysql")]
@@ -149,21 +123,27 @@ fn run() -> Result<(), Error> {
Ok(pool) => match embedded_migrations::run(&*pool.get()?) {
Ok(_) => {
let pool = Arc::new(pool);
- bot.add_plugin(Factoids::new(pool.clone()));
+ bot.add_plugin(Factoid::new(pool.clone()));
+ bot.add_plugin(Quote::new(pool.clone()));
bot.add_plugin(Tell::new(pool.clone()));
+ bot.add_plugin(Remind::new(pool.clone()));
info!("Connected to MySQL server")
}
Err(e) => {
- bot.add_plugin(Factoids::new(HashMap::new()));
+ bot.add_plugin(Factoid::new(HashMap::new()));
+ bot.add_plugin(Quote::new(HashMap::new()));
bot.add_plugin(Tell::new(HashMap::new()));
+ bot.add_plugin(Remind::new(HashMap::new()));
error!("Failed to run migrations: {}", e);
}
},
Err(e) => error!("Failed to connect to database: {}", e),
}
} else {
- bot.add_plugin(Factoids::new(HashMap::new()));
+ bot.add_plugin(Factoid::new(HashMap::new()));
+ bot.add_plugin(Quote::new(HashMap::new()));
bot.add_plugin(Tell::new(HashMap::new()));
+ bot.add_plugin(Remind::new(HashMap::new()));
}
}
#[cfg(not(feature = "mysql"))]
@@ -171,8 +151,10 @@ fn run() -> Result<(), Error> {
if mysql_url.is_some() {
error!("frippy was not built with the mysql feature")
}
- bot.add_plugin(Factoids::new(HashMap::new()));
+ bot.add_plugin(Factoid::new(HashMap::new()));
+ bot.add_plugin(Quote::new(HashMap::new()));
bot.add_plugin(Tell::new(HashMap::new()));
+ bot.add_plugin(Remind::new(HashMap::new()));
}
if let Some(disabled_plugins) = disabled_plugins {
@@ -187,5 +169,7 @@ fn run() -> Result<(), Error> {
}
// Run the bots until they throw an error - an error could be loss of connection
- Ok(reactor.run()?)
+ reactor.run()?;
+
+ Ok(())
}