diff --git a/src/lib.rs b/src/lib.rs index 0ebd21b..fc0da30 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,14 +6,14 @@ use regex::Regex; //is this the best way to do this? probably not mod modules; -use modules::{bully, lenny, join_rude, grass, noemo, ttb, help, repo,rtfm, kick, history, time_to_date}; +use modules::{bully, lenny, join_rude, grass, noemo, ttb, help, repo,rtfm, kick, history, time_to_date, bonk}; type ModuleFunc = fn(regex::Captures, &Message, &VecDeque)->String; -const NUM_MODS:usize = 11; +const NUM_MODS:usize = 12; -const MODULES: [(&str, ModuleFunc);NUM_MODS] = [(lenny::PATTERN, lenny::mod_message), (bully::PATTERN, bully::mod_message), (grass::PATTERN, grass::touch_grass), (noemo::PATTERN, noemo::no_emo), (ttb::PATTERN, ttb::time_to_baby), (help::PATTERN, help::help), (repo::PATTERN, repo::link), (rtfm::PATTERN, rtfm::rtfm), (kick::PATTERN, kick::mod_message), (history::PATTERN, history::mod_message), (time_to_date::PATTERN, time_to_date::time_to_date)]; -const MODULE_USAGE: [(&str, &str); NUM_MODS] = [(lenny::NAME, lenny::USAGE), (bully::NAME, bully::USAGE), (grass::NAME, grass::USAGE), (noemo::NAME, noemo::USAGE), (ttb::NAME, ttb::USAGE), (help::NAME, help::USAGE), (repo::NAME, repo::USAGE),(rtfm::NAME, rtfm::USAGE), (kick::NAME, kick::USAGE), (history::NAME, history::USAGE), (time_to_date::NAME, time_to_date::USAGE)]; +const MODULES: [(&str, ModuleFunc);NUM_MODS] = [(lenny::PATTERN, lenny::mod_message), (bully::PATTERN, bully::mod_message), (grass::PATTERN, grass::touch_grass), (noemo::PATTERN, noemo::no_emo), (ttb::PATTERN, ttb::time_to_baby), (help::PATTERN, help::help), (repo::PATTERN, repo::link), (rtfm::PATTERN, rtfm::rtfm), (kick::PATTERN, kick::mod_message), (history::PATTERN, history::mod_message), (time_to_date::PATTERN, time_to_date::time_to_date), (bonk::PATTERN, bonk::bonk)]; +const MODULE_USAGE: [(&str, &str); NUM_MODS] = [(lenny::NAME, lenny::USAGE), (bully::NAME, bully::USAGE), (grass::NAME, grass::USAGE), (noemo::NAME, noemo::USAGE), (ttb::NAME, ttb::USAGE), (help::NAME, help::USAGE), (repo::NAME, repo::USAGE),(rtfm::NAME, rtfm::USAGE), (kick::NAME, kick::USAGE), (history::NAME, history::USAGE), (time_to_date::NAME, time_to_date::USAGE), (bonk::NAME, bonk::USAGE)]; pub fn build_modules() -> Result, regex::Error> { let mut regex_array: Vec<(Regex, ModuleFunc)> = Vec::with_capacity(NUM_MODS); diff --git a/src/modules/bonk.rs b/src/modules/bonk.rs new file mode 100644 index 0000000..a94c69e --- /dev/null +++ b/src/modules/bonk.rs @@ -0,0 +1,18 @@ +use std::collections::VecDeque; +use irc::proto::Message; + + +pub const USAGE: &str = "Usage: $bonk \r\nPut the person identified as nick in horny jail"; + +pub const NAME: &str = "bonk"; + +pub const PATTERN: &str = "^\\$bonk( (?P[^\\s]+))?$"; + +pub fn bonk(captures: regex::Captures, _message: &Message, _message_buf: &VecDeque) -> String { + if let Some(nick) = captures.get(2) { + format!("bonk! {} go to horny jail!", nick.as_str()) + } + else { + format!("bonk! go to horny jail!") + } +} diff --git a/src/modules/mod.rs b/src/modules/mod.rs index bc2a223..4713625 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -10,3 +10,4 @@ pub mod rtfm; pub mod kick; pub mod history; pub mod time_to_date; +pub mod bonk;