added help module

This commit is contained in:
2024-03-27 21:45:58 -07:00
parent c234aa8fdd
commit 42adfaac0f
9 changed files with 53 additions and 16 deletions

View File

@@ -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<Message>)->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<Vec<(Regex, ModuleFunc)>, regex::Error> {
let mut regex_array: Vec<(Regex, ModuleFunc)> = Vec::with_capacity(NUM_MODS);

View File

@@ -3,15 +3,14 @@ use irc::proto::Message;
use rand::prelude::Rng;
const USAGE: &str = "Usage: !bully <nick>
This bullies the user identified by nick.
pub const USAGE: &str = "Usage: $bully <nick>\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, ",

View File

@@ -1,7 +1,9 @@
use irc::proto::Message;
use std::collections::VecDeque;
pub const PATTERN: &str = "\\$grass (?P<nick>[^\\s]+)";
pub const PATTERN: &str = "^\\$grass (?P<nick>[^\\s]+)";
pub const NAME: &str = "grass";
pub const USAGE: &str = "Usage: $grass <nick>\r\nThis tells the user identified by nick to touch grass";
pub fn touch_grass(captures: regex::Captures, message: &Message, _: &VecDeque<Message>) -> String {

32
src/modules/help.rs Normal file
View File

@@ -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<Message>) -> 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
}
}

View File

@@ -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",

View File

@@ -4,8 +4,8 @@ use rand::prelude::Rng;
const LENNYS:[&str;12] = ["( ͡° ͜ʖ ͡°)","( ͠° ͟ʖ ͡°)","ᕦ( ͡° ͜ʖ ͡°)ᕤ","( ͡° ͜ʖ ͡°)","( ͡~ ͜ʖ ͡°)","( ͡o ͜ʖ ͡o)","͡° ͜ʖ ͡ -","( ͡͡ ° ͜ ʖ ͡ °)","( ͡ ͡° ͡° ʖ ͡° ͡°)","(ง ͠° ͟ل͜ ͡°)ง","( ͡° ͜ʖ ͡ °)","( ͡°╭͜ʖ╮͡° )"];
pub const PATTERN: &str = "^\\$[Ll]enny\\s*(?P<text>.*)$";
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<Message>) -> String {
let lenny = LENNYS[rand::thread_rng().gen_range(0..LENNYS.len())].to_string();

View File

@@ -4,4 +4,4 @@ pub mod join_rude;
pub mod grass;
pub mod ttb;
pub mod noemo;
pub mod help;

View File

@@ -1,7 +1,9 @@
use irc::proto::Message;
use std::collections::VecDeque;
pub const PATTERN: &str = "\\$noemo (?P<nick>[^\\s]+)";
pub const PATTERN: &str = "^\\$noemo (?P<nick>[^\\s]+)";
pub const NAME: &str = "noemo";
pub const USAGE: &str = "Usage: $noemo <nick>\r\nThis tells the user identified by nick to not be emo";
pub fn no_emo(captures: regex::Captures, message: &Message, _: &VecDeque<Message>) -> String {
let emo_person = captures.get(1).unwrap().as_str();

View File

@@ -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<Message>) -> String {
pub fn time_to_baby(_: regex::Captures, _: &Message, _: &VecDeque<Message>) -> String {
let local_time: DateTime<Local> = Local::now();
let birth_time: DateTime<Local> = Local.with_ymd_and_hms(2024, 10, 17, 00, 00, 00).unwrap();