From 48deaf177633e062582b7733f633a37b296cac95 Mon Sep 17 00:00:00 2001 From: R0flcopt3r <12752060+R0flcopt3r@users.noreply.github.com> Date: Sat, 5 Jun 2021 22:42:56 +0200 Subject: feat: adds pet command. When petting the cat it will reply with some random action. --- src/hooks/mod.rs | 3 +++ src/hooks/pet.rs | 33 +++++++++++++++++++++++++++++++++ src/main.rs | 5 +++++ 3 files changed, 41 insertions(+) create mode 100644 src/hooks/pet.rs (limited to 'src') diff --git a/src/hooks/mod.rs b/src/hooks/mod.rs index 49ec0ab..ee64643 100644 --- a/src/hooks/mod.rs +++ b/src/hooks/mod.rs @@ -1,9 +1,12 @@ +extern crate rand; + use anyhow::Result; use irc::client::prelude::*; pub mod sed; pub mod intensify; pub mod shifty_eyes; +pub mod pet; pub use shifty_eyes::shifty_eyes; pub use intensify::intensify; diff --git a/src/hooks/pet.rs b/src/hooks/pet.rs new file mode 100644 index 0000000..dcd8148 --- /dev/null +++ b/src/hooks/pet.rs @@ -0,0 +1,33 @@ +use std::str; + +use anyhow::Result; +use irc::client::prelude::*; +use macros::privmsg; + +use rand::thread_rng; +use rand::seq::SliceRandom; + +const PET_RESPONSE: [&str; 5] = [ + "purrs", + "moews loudly", + "walks away", + "snuggles back", + "strikes you with it's sharp claws", +]; + +/// Pet cat +/// +/// Sends some random action when petted. +/// +/// # See also +/// +/// - [`Bot::send_action`] +/// - RESPONSE +pub fn pet(bot: &crate::Bot, msg: Message) -> Result<()> { + let mut rng = thread_rng(); + let choice = PET_RESPONSE.choose(&mut rng); + + privmsg!(msg, { + bot.send_action(msg.response_target().unwrap(), choice.unwrap())?; + }) +} diff --git a/src/main.rs b/src/main.rs index 3213d50..21a1ba1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -40,5 +40,10 @@ async fn main() { r"^\[.*?\]$", catinator::hooks::intensify ), + command( + "pet", + "Pet the cat, cats generally like pets.", + catinator::hooks::pet::pet + ), ]; } -- cgit v1.2.3