diff --git a/src/lib.rs b/src/lib.rs index d6e76da..8ac1ec0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -6,13 +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}; +use modules::{bully, lenny, join_rude, grass, noemo, ttb, help}; type ModuleFunc = fn(regex::Captures, &Message, &VecDeque)->String; -const NUM_MODS:usize = 5; +const NUM_MODS:usize = 6; -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)]; +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)]; +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)]; pub fn build_modules() -> Result, regex::Error> { let mut regex_array: Vec<(Regex, ModuleFunc)> = Vec::with_capacity(NUM_MODS); diff --git a/src/modules/bully.rs b/src/modules/bully.rs index e222758..05436c8 100644 --- a/src/modules/bully.rs +++ b/src/modules/bully.rs @@ -3,15 +3,14 @@ use irc::proto::Message; use rand::prelude::Rng; -const USAGE: &str = "Usage: !bully -This bullies the user identified by nick. +pub const USAGE: &str = "Usage: $bully \r\nThis bullies the user identified by nick. "; +pub const NAME: &str = "bully"; -const BULLY_PHRASES:[&str;12] = [ +const BULLY_PHRASES:[&str;11] = [ "'s day has been ruined by your message, ", " wants to return to monke, but not if you're coming, too, ", " knows how much of a duck-banging degenerate you are, ", - " hopes you order pizza from Modern Market, but then you realize you have an interview to go to that you're about to be late to, so you frantically rush to it before realizing it's over Zoom, so you pull out your laptop and search through your email, but can't find the link, before finally discovering it 2 whole minutes later, making you late to your interview, which you fail by the way, after which you remember you ordered pizza which, even though cold, would still be enough to lift your spirits up a little, except you find it was taken by someone else, Modern Market has closed, and you are left with nothing but dread, disgust, and misery, ", " believes you're too incompetent to know that you're being bullied, ", " doesn't care about your race, sex, or age... or anything about you really, ", " has more maidens than you, ", diff --git a/src/modules/grass.rs b/src/modules/grass.rs index e7e2706..47daa69 100644 --- a/src/modules/grass.rs +++ b/src/modules/grass.rs @@ -1,7 +1,9 @@ use irc::proto::Message; use std::collections::VecDeque; -pub const PATTERN: &str = "\\$grass (?P[^\\s]+)"; +pub const PATTERN: &str = "^\\$grass (?P[^\\s]+)"; +pub const NAME: &str = "grass"; +pub const USAGE: &str = "Usage: $grass \r\nThis tells the user identified by nick to touch grass"; pub fn touch_grass(captures: regex::Captures, message: &Message, _: &VecDeque) -> String { diff --git a/src/modules/help.rs b/src/modules/help.rs new file mode 100644 index 0000000..86e4ddb --- /dev/null +++ b/src/modules/help.rs @@ -0,0 +1,32 @@ +use irc::proto::Message; +use std::collections::VecDeque; + +pub const PATTERN: &str = "\\$help(?: (.*))?"; +pub const NAME: &str = "help"; +pub const USAGE: &str = "You just used it"; + + +pub fn help(captures: regex::Captures, _: &Message, _: &VecDeque) -> String { + + if let Some(command) = captures.get(1) { + let command_str = command.as_str(); + + for (name, usage_str) in super::super::MODULE_USAGE { + if command_str == name { + return usage_str.to_string(); + } + } + + format!("Unknown command: {}", command_str) + + } + else { + let mut commands = String::new(); + for (command, _) in super::super::MODULE_USAGE { + commands += format!("{}, ", command).as_str(); + } + commands.pop(); + + commands + } +} diff --git a/src/modules/join_rude.rs b/src/modules/join_rude.rs index 134e882..9fcf626 100644 --- a/src/modules/join_rude.rs +++ b/src/modules/join_rude.rs @@ -1,6 +1,6 @@ use rand::prelude::Rng; -const PHRASES:[&str;25] = [ +const PHRASES:[&str;24] = [ "Go back to your cronjobs", "Don't you have a student machine to fork bomb?", "If your poor excuse for a bot is GPT4 then I'm Alan Turing", @@ -16,7 +16,6 @@ const PHRASES:[&str;25] = [ "You definitely leave zombie processes when you exit VSCode", "It's the honor code not the honor suggestion", "Wow another bot that responds when you say hello, how unique", - "The extra curly bracket is over by the fucks I have to give, go find it", "Zahm may be closed, but you still give off Zahm vibes", "They really let anyone in here huh?", "You're the tech bro who doesn't actually know how to code", @@ -29,7 +28,7 @@ const PHRASES:[&str;25] = [ ]; pub fn join_rude(nick: &str, channel: &str) -> Option<(String,String)> { - + let rude_message: &str = PHRASES[rand::thread_rng().gen_range(0..PHRASES.len())]; let complete_message: String = nick.to_string() + ": " + rude_message; diff --git a/src/modules/lenny.rs b/src/modules/lenny.rs index e2ba9bd..f26c97f 100644 --- a/src/modules/lenny.rs +++ b/src/modules/lenny.rs @@ -4,8 +4,8 @@ use rand::prelude::Rng; const LENNYS:[&str;12] = ["( ͡° ͜ʖ ͡°)","( ͠° ͟ʖ ͡°)","ᕦ( ͡° ͜ʖ ͡°)ᕤ","( ͡° ͜ʖ ͡°)","( ͡~ ͜ʖ ͡°)","( ͡o ͜ʖ ͡o)","͡° ͜ʖ ͡ -","( ͡͡ ° ͜ ʖ ͡ °)","( ͡ ͡° ͡° ʖ ͡° ͡°)","(ง ͠° ͟ل͜ ͡°)ง","( ͡° ͜ʖ ͡ °)","( ͡°╭͜ʖ╮͡° )"]; pub const PATTERN: &str = "^\\$[Ll]enny\\s*(?P.*)$"; -const USAGE: &str = "Usage: ![Ll]enny -Displays a Lenny face ( ͡° ͜ʖ ͡°)"; +pub const USAGE: &str = "Usage: $[Ll]enny\r\nDisplays a Lenny face ( ͡° ͜ʖ ͡°)"; +pub const NAME: &str = "lenny"; pub fn mod_message(captures: regex::Captures, message: &Message, _message_buf: &VecDeque) -> String { let lenny = LENNYS[rand::thread_rng().gen_range(0..LENNYS.len())].to_string(); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index 967a619..f5762cc 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -4,4 +4,4 @@ pub mod join_rude; pub mod grass; pub mod ttb; pub mod noemo; - +pub mod help; diff --git a/src/modules/noemo.rs b/src/modules/noemo.rs index 4cd9871..9b625fd 100644 --- a/src/modules/noemo.rs +++ b/src/modules/noemo.rs @@ -1,7 +1,9 @@ use irc::proto::Message; use std::collections::VecDeque; -pub const PATTERN: &str = "\\$noemo (?P[^\\s]+)"; +pub const PATTERN: &str = "^\\$noemo (?P[^\\s]+)"; +pub const NAME: &str = "noemo"; +pub const USAGE: &str = "Usage: $noemo \r\nThis tells the user identified by nick to not be emo"; pub fn no_emo(captures: regex::Captures, message: &Message, _: &VecDeque) -> String { let emo_person = captures.get(1).unwrap().as_str(); diff --git a/src/modules/ttb.rs b/src/modules/ttb.rs index 9d5ceeb..3294ba8 100644 --- a/src/modules/ttb.rs +++ b/src/modules/ttb.rs @@ -3,9 +3,11 @@ use std::collections::VecDeque; use chrono::{prelude::*, TimeDelta}; pub const PATTERN: &str = "^\\$ttb\\s*$"; +pub const NAME: &str = "ttb"; +pub const USAGE: &str = "Usage $ttb\r\nThis prints the number of days until pnutz's baby is due"; -pub fn time_to_baby(_: regex::Captures, message: &Message, _: &VecDeque) -> String { +pub fn time_to_baby(_: regex::Captures, _: &Message, _: &VecDeque) -> String { let local_time: DateTime = Local::now(); let birth_time: DateTime = Local.with_ymd_and_hms(2024, 10, 17, 00, 00, 00).unwrap();