From fbabc1302c60845de31bff1e1b177f273f7eed6c Mon Sep 17 00:00:00 2001 From: Colin McKechney Date: Mon, 17 Apr 2023 23:32:39 -0400 Subject: [PATCH] rude now --- src/module.rs | 23 ++++++++++-------- src/module/bully.rs | 52 +++++++++++++++++++++++++++++++++++++++++ src/module/config.toml | 6 +++++ src/module/join_rude.rs | 39 +++++++++++++++++++++++++++++++ src/module/lenny.rs | 6 ++--- 5 files changed, 113 insertions(+), 13 deletions(-) create mode 100644 src/module/bully.rs create mode 100644 src/module/config.toml create mode 100644 src/module/join_rude.rs diff --git a/src/module.rs b/src/module.rs index e4dedbd..509e02d 100644 --- a/src/module.rs +++ b/src/module.rs @@ -3,22 +3,25 @@ use irc::proto::{Message, Command::*}; //list of available modules, add mod [MODULE_NAME]; when you complete a new module mod lenny; - +mod bully; +mod join_rude; type ModuleFunc = fn(&Message, &VecDeque)->Option<(String, String)>; -const NUM_MODS:usize = 1; +const NUM_MODS:usize = 2; -const MOD_FUNCS: [ModuleFunc;NUM_MODS] = [lenny::Lenny::mod_message]; +const MOD_FUNCS: [ModuleFunc;NUM_MODS] = [lenny::Lenny::mod_message, bully::Bully::mod_message]; pub fn handle(message: &Message, message_buf: &VecDeque) -> Option<(String,String)> { - if let PRIVMSG(_,_) = message.command.clone() { - for function in MOD_FUNCS{ - let response = function(message, message_buf); - if response.is_some() { - return response; - } - } + match message.command { + PRIVMSG(_,_) => for function in MOD_FUNCS{ + let response = function(message, message_buf); + if response.is_some() { + return response; + } + }, + JOIN(ref channel,_,_) => return join_rude::join_rude(message.source_nickname().unwrap_or("unknown user"), channel.as_str()), + _ => () } diff --git a/src/module/bully.rs b/src/module/bully.rs new file mode 100644 index 0000000..6916e65 --- /dev/null +++ b/src/module/bully.rs @@ -0,0 +1,52 @@ +use std::collections::VecDeque; +use irc::proto::{Message, Command::PRIVMSG}; +use regex::Regex; +use rand::prelude::Rng; + + +const USAGE: &str = "Usage: !bully +This bullies the user identified by nick. +"; + +const BULLY_PHRASES:[&str;12] = [ + "'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, ", + "'s faith in society has plummeted since meeting you, ", + " think you're about as good as the dining hall food, ", + " gives eMoTiOnAL dAmAgE to ", + " has a confession to make. You're ugly, ", + " thinks you were probably the pilot of Ever Given when it clogged the Suez Canal, " +]; + +const PATTERN: &str = "^!bully (?P[^\\s]+)"; + + + +pub struct Bully{} + +impl Bully { + pub fn mod_message(message: &Message, message_buf: &VecDeque) -> Option<(String,String)> { + let regex: Regex = Regex::new(PATTERN).expect("Error creating regex"); + + if let PRIVMSG(_,msg) = message.command.clone() { + if let Some(capture) = regex.captures(msg.as_str()) { + let bully_message: String = BULLY_PHRASES[rand::thread_rng().gen_range(0..BULLY_PHRASES.len())].to_string(); + let to_be_bullied = capture.get(1).unwrap().as_str(); + + let complete_message = message.source_nickname().unwrap_or("unknown_nick").to_string() + bully_message.as_str() + to_be_bullied; + + return Some((message.response_target().unwrap_or("#lug").to_string(), complete_message)); + } + } + None + } + + pub fn usage(message: &Message) -> (String, String) { + (message.response_target().unwrap_or("#lug").to_string(), USAGE.to_string()) + } +} diff --git a/src/module/config.toml b/src/module/config.toml new file mode 100644 index 0000000..581713a --- /dev/null +++ b/src/module/config.toml @@ -0,0 +1,6 @@ +nickname = "robbit" +username = "robbit" +realname = "robbit" +server = "chat.ndlug.org" +port = 6697 +channels = ["#bots"] \ No newline at end of file diff --git a/src/module/join_rude.rs b/src/module/join_rude.rs new file mode 100644 index 0000000..134e882 --- /dev/null +++ b/src/module/join_rude.rs @@ -0,0 +1,39 @@ +use rand::prelude::Rng; + +const PHRASES:[&str;25] = [ + "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", + "You put semicolons in your python code", + "You put your curly brackets on a separate line", + "Just stop now, you're not getting the guru point", + "OS is going to eat you alive", + "L + Ratio", + "You probably think it makes more sense to index at 1", + "Matlab user", + "The one extra point isn't gonna save your grade", + "Jupyter Notebooks user", + "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", + "You wear a sweater when it's 70 outside", + "Go take a shower I can smell you through the screen", + "Don't try to hard you'll hurt yourself", + "I know fish with better coding skills than you", + "Nepo baby", + "this student uses LIGHT MODE in vscode" +]; + +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; + + Some((channel.to_string(), complete_message)) +} + + diff --git a/src/module/lenny.rs b/src/module/lenny.rs index 07b645d..84e8361 100644 --- a/src/module/lenny.rs +++ b/src/module/lenny.rs @@ -10,8 +10,8 @@ Displays a Lenny face ( ͡° ͜ʖ ͡°)"; pub struct Lenny {} #[allow(unused_variables)] -impl super::Module for Lenny { - fn mod_message(message: &Message, message_buf: &VecDeque) -> Option<(String,String)> { +impl Lenny { + pub fn mod_message(message: &Message, message_buf: &VecDeque) -> Option<(String,String)> { let regex: Regex = Regex::new(PATTERN).expect("Error creating regex"); //checks if it was a PRIVMSG @@ -29,7 +29,7 @@ impl super::Module for Lenny { None } - fn usage(message: &Message) -> (String,String) { + pub fn usage(message: &Message) -> (String,String) { //prints a usage, not sure when I'm gonna use this but let's see (message.response_target().unwrap_or("#lug").to_string(),USAGE.to_string()) }