Added rtfm module

This commit is contained in:
2024-03-30 09:07:32 -07:00
parent 6d73d7af0c
commit 685840eaff
3 changed files with 23 additions and 4 deletions

View File

@@ -6,14 +6,14 @@ use regex::Regex;
//is this the best way to do this? probably not //is this the best way to do this? probably not
mod modules; mod modules;
use modules::{bully, lenny, join_rude, grass, noemo, ttb, help, repo}; use modules::{bully, lenny, join_rude, grass, noemo, ttb, help, repo,rtfm};
type ModuleFunc = fn(regex::Captures, &Message, &VecDeque<Message>)->String; type ModuleFunc = fn(regex::Captures, &Message, &VecDeque<Message>)->String;
const NUM_MODS:usize = 7; const NUM_MODS:usize = 8;
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)]; 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)];
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)]; 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)];
pub fn build_modules() -> Result<Vec<(Regex, ModuleFunc)>, regex::Error> { pub fn build_modules() -> Result<Vec<(Regex, ModuleFunc)>, regex::Error> {
let mut regex_array: Vec<(Regex, ModuleFunc)> = Vec::with_capacity(NUM_MODS); let mut regex_array: Vec<(Regex, ModuleFunc)> = Vec::with_capacity(NUM_MODS);

View File

@@ -6,3 +6,5 @@ pub mod ttb;
pub mod noemo; pub mod noemo;
pub mod help; pub mod help;
pub mod repo; pub mod repo;
pub mod rtfm;

17
src/modules/rtfm.rs Normal file
View File

@@ -0,0 +1,17 @@
use irc::proto::Message;
use std::collections::VecDeque;
pub const PATTERN: &str = "^\\$rtf([cm])$";
pub const NAME: &str = "rtfm";
pub const USAGE: &str = "Usage: $rtf[cm]\r\nThis tells you read the f-ing manual or chat, whichever is chosen";
pub fn rtfm(captures: regex::Captures, _: &Message, _: &VecDeque<Message>) -> String {
let c_or_m = captures.get(1).unwrap().as_str();
if c_or_m == "c" {
"Read the f-ing chat".to_string()
}
else {
"Read the f-ing manual".to_string()
}
}